libp2p / js-libp2p-kad-dht

JavaScript implementation of the DHT for libp2p
https://libp2p.io
Other
141 stars 60 forks source link

Failed to provide - `libp2p.contentRouting.provide(cid)` #483

Closed vaibhavmuchandi closed 1 year ago

vaibhavmuchandi commented 1 year ago

Hello, Im using js-libp2p-kad-dht@9.3.8 with libp2p@0.45.9

Even though I have many nodes connected to my libp2p network, libp2p.contentRouting.provide(cid) fails and throws the error

CodeError: Failed to provide - no peers found
    at @libp2p/dual-kad-dht.provide (node_modules/.pnpm/@libp2p+kad-dht@9.3.8/node_modules/@libp2p/kad-dht/src/dual-kad-dht.ts:346:13)
    at node_modules/.pnpm/it-drain@3.0.2/node_modules/it-drain/src/index.ts:14:24
    at DHTContentRouting.provide (node_modules/.pnpm/@libp2p+kad-dht@9.3.8/node_modules/@libp2p/kad-dht/src/dual-kad-dht.ts:31:5)
    at node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/src/content-routing/index.ts:75:60
    at async Promise.all (index 0)
    at CompoundContentRouting.provide (node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/src/content-routing/index.ts:75:5)
    at Discovery.provideMeeting (src/index.ts:52:7) { code: 'ERR_PROVIDES_FAILED', props: {}

After connection, I have a delay of 2000ms after which I call the libp2p.contentRouting.provide method. <- 1000ms delay to sync the DHT and 1000ms extra to stay on a safer side

node.addEventListener("peer:connect", (_evt) => {
   if(peerConnectCount >=3) {
     if(!hasPublished){
        setTimeout(() => {
          this.node.contentRouting.provide(discovery.cid);
        }, 2000);
     }
  }
});
vaibhavmuchandi commented 1 year ago

Version mismatch