Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no peer:connect event with autoDial #664

Closed
olivier-nerot opened this issue Jun 10, 2020 · 5 comments · Fixed by #665
Closed

no peer:connect event with autoDial #664

olivier-nerot opened this issue Jun 10, 2020 · 5 comments · Fixed by #665
Labels
dx Developer Experience exp/novice Someone with a little familiarity can pick up help wanted Seeking public contribution on this issue kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked

Comments

@olivier-nerot
Copy link

olivier-nerot commented Jun 10, 2020

With libp2p V0.28, peer:connect events seems not to be fired

const peerid = ...;
const libp2p = await Libp2p.create({
        peerId: peerid,
        addresses: {
          listen: ['/ip4/0.0.0.0/tcp/0'],
        },
        modules: {
          transport: [TCP],
          streamMuxer: [Mplex],
          peerDiscovery: [MulticastDNS],
        },
        config: {
          peerDiscovery: {
            autoDial: true,
            [MulticastDNS.tag]: { // or mdns: ?
              interval: 1000,
              enabled: true,
            },
          },
        },
      });

      libp2p.on('peer:discovery', (peerId) => {
        debug('Discovered: %O', peerId);
        // libp2p.dial(peerId);
      });

      libp2p.connectionManager.on('peer:connect', (connection) => { 
        debug('peer connected %O',connection);
      });

      libp2p.start();

With the same setup, if I launch libp2p.start() from another node, the peer:discovery is well logged, but not peer:connect. I thought the autoDial:true should make a peer dials other discovered peers automatically.
I've tried also to call libp2p.dial(peerId) into the peer:discovery event, but peerId has no multiaddrs value, and have not found how to dial a discovered peer.

The documentation is sometimes confusing with this discovery process (for example, some explains to use mdns, other tells to use [MulticastDNS.tag]in config)

@jacobheun
Copy link
Contributor

This is a usability bug. We should be throwing an error on Libp2p.create as you're not supplying any connection encryption, you need either libp2p-noise or libp2p-secio in your configuration https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#basic-setup.

If you're intentionally not using crypto for development/testing purposes you can use Plaintext, const Plaintext = require('libp2p/src/insecure/plaintext'), in place of Secio or Noise but this shouldn't be used outside of testing.

@jacobheun jacobheun added kind/bug A bug in existing code (including security flaws) exp/novice Someone with a little familiarity can pick up dx Developer Experience help wanted Seeking public contribution on this issue P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked labels Jun 10, 2020
@olivier-nerot
Copy link
Author

Thanks ! yes, an error thrown would help. I've not seen either that encryption was mandatory. This should be added in documentation.

Dealing with this setup, to better understand, does [MulticastDNS.tag] or mdns be used ? And If autoDial is false, how is it possible to dial a peer on peer:discovery event, as peerid has no multiaddrs whereas dial() requires them ?

@vasco-santos
Copy link
Member

@olivier-nerot I will have a look into the docs to see where we have these inconsistencies and also add the error and docs for the required encryption.

Dealing with this setup, to better understand, does [MulticastDNS.tag] or mdns be used ?

We aim to use MulticastDNS.tag to be specific on where the tags come from in the discovery modules

https://github.com/libp2p/js-libp2p-mdns/blob/master/src/index.js#L104

Its value is mdns and that's why it will work either way.

And If autoDial is false, how is it possible to dial a peer on peer:discovery event, as peerid has no multiaddrs whereas dial() requires them ?

When a peer:discovery event happens, the discovered peer data is stored in the PeerStore libp2p/js-libp2p/v0.28.0/src/index.js#L485-L493. libp2p.dial accepts a multiaddr and PeerId as a target to dial. If you provide a multiaddr, it will be used for the dial, while if you provide a PeerId, we will look into the PeerStore.AddressBook if we know any multiaddrs for the provided peer. If we do, we just try to dial using the known multiaddrs. You can read more about the PeerStore flows in libp2p/js-libp2p/v0.28.0/src/peer-store

@olivier-nerot
Copy link
Author

Thanks a lot. I understand it better. To help, you have MulticastDNS.tag in the Customizing Peer Discovery section of Configuration.md and mdns in the 2.js example
When I have gathered a working sample, I will push it here if it may help.

@vasco-santos
Copy link
Member

I created #665 that solves what was discussed here. I hope the visibility for the modules being required is better now.

Per #576 we have to get the configuration more obvious and easy for everyone, and not require users to read a bunch of documents for getting started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx Developer Experience exp/novice Someone with a little familiarity can pick up help wanted Seeking public contribution on this issue kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants