feat: use ipfs dht (#113)

* feat: use ipfs dht

* fix: use ipfs dht and with auto mode

---------

Co-authored-by: Daniel N <2color@users.noreply.github.com>
This commit is contained in:
Daniel Norman
2024-04-25 13:58:12 +02:00
committed by GitHub
parent 958e2755e9
commit 5a7f5421c3
3 changed files with 5 additions and 14 deletions

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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;