libp2p / js-libp2p-kad-dht

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

Handle removing of peers #74

Open raduiliescu83 opened 5 years ago

raduiliescu83 commented 5 years ago

Not clear how I can handle this case.

Take following case:

  1. Add two nodes - node1 & node2.
  2. node2 provides resource via dht;
  3. kill node2;
  4. call findProviders(resource) on node1

This will generate following stack: Error: No available transports to dial peer QmTxbrLsEBWjHgeK4kfJoRmfXDMeL9m1pD4E7hEKueJTFa! at nextTransport (/home/radu/git/dcdn/p2p_service/node_modules/libp2p/node_modules/libp2p-switch/src/dial.js:369:27) at switch.transport.dial (/home/radu/git/dcdn/p2p_service/node_modules/libp2p/node_modules/libp2p-switch/src/dial.js:382:18) at dialer.dialMany (/home/radu/git/dcdn/p2p_service/node_modules/libp2p/node_modules/libp2p-switch/src/transport.js:69:16) at f (/home/radu/git/dcdn/p2p_service/node_modules/once/once.js:25:25) at map (/home/radu/git/dcdn/p2p_service/node_modules/libp2p/node_modules/libp2p-switch/src/limit-dialer/index.js:61:14) at /home/radu/git/dcdn/p2p_service/node_modules/async/internal/map.js:32:9 at /home/radu/git/dcdn/p2p_service/node_modules/async/internal/once.js:12:16 at iteratorCallback (/home/radu/git/dcdn/p2p_service/node_modules/async/eachOf.js:60:13) at /home/radu/git/dcdn/p2p_service/node_modules/async/internal/onlyOnce.js:12:16 at Object.callback (/home/radu/git/dcdn/p2p_service/node_modules/async/internal/map.js:29:13)

  1. After killing node2 delete node2 from node1 peerBook and dht.routingTable like bellow: node.on('peer:disconnect', (peerInfo) => { supernode._dht.routingTable.remove(peerInfo.id, (err) => { if (err) console.log(err); });

    supernode.peerBook.remove(peerInfo); <<<- Just calling this should be enough });

  2. Problem now is that if I call findProviders(resource) on node1, it won't crash but I will still get that there is someone providing the resource, but has no address.

vasco-santos commented 5 years ago

Thanks for reporting the issue @raduiliescu83

Would you like to submit a PR for that?