Skip to content

Commit

Permalink
feat: use ipfs dht (#113)
Browse files Browse the repository at this point in the history
* feat: use ipfs dht

* fix: use ipfs dht and with auto mode

---------

Co-authored-by: Daniel N <2color@users.noreply.github.com>
  • Loading branch information
2color and 2color committed Apr 25, 2024
1 parent 958e275 commit 5a7f542
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
14 changes: 4 additions & 10 deletions go-peer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ var SysMsgChan chan *ChatMessage
// NewDHT attempts to connect to a bunch of bootstrap peers and returns a new DHT.
// If you don't have any bootstrapPeers, you can use dht.DefaultBootstrapPeers or an empty list.
func NewDHT(ctx context.Context, host host.Host, bootstrapPeers []multiaddr.Multiaddr) (*dht.IpfsDHT, error) {
var options []dht.Option

// if no bootstrap peers give this peer act as a bootstraping node
// other peers can use this peers ipfs address for peer discovery via dht
if len(bootstrapPeers) == 0 {
options = append(options, dht.Mode(dht.ModeServer))
}

options = append(options, dht.ProtocolPrefix("/universal-connectivity/lan"))

kdht, err := dht.New(ctx, host, options...)
kdht, err := dht.New(ctx, host,
dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...),
dht.Mode(dht.ModeAuto),
)
if err != nil {
return nil, err
}
Expand Down
3 changes: 0 additions & 3 deletions js-peer/src/lib/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ export async function startLibp2p() {
ignoreDuplicatePublishError: true,
}),
dht: kadDHT({
protocol: "/universal-connectivity/kad/1.0.0",
maxInboundStreams: 5000,
maxOutboundStreams: 5000,
clientMode: true,
}),
identify: identify()
Expand Down
2 changes: 1 addition & 1 deletion rust-peer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::protocol::FileRequest;

const TICK_INTERVAL: Duration = Duration::from_secs(15);
const KADEMLIA_PROTOCOL_NAME: StreamProtocol =
StreamProtocol::new("/universal-connectivity/lan/kad/1.0.0");
StreamProtocol::new("/ipfs/kad/1.0.0");
const FILE_EXCHANGE_PROTOCOL: StreamProtocol =
StreamProtocol::new("/universal-connectivity-file/1");
const PORT_WEBRTC: u16 = 9090;
Expand Down

0 comments on commit 5a7f542

Please sign in to comment.