mirror of
https://github.com/vacp2p/universal-connectivity.git
synced 2026-01-09 15:18:05 -05:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user