ChainSafe / discv5

A Typescript implementation of the Discv5 protocol
Apache License 2.0
28 stars 15 forks source link

Add Documentation #8

Open Mikerah opened 5 years ago

Mikerah commented 5 years ago

Add documentation to the codebase and on how to use this module.

pipermerriam commented 3 years ago

I'm very curious to understand what this codebase is doing. What does DiscV5 over libp2p look like?

  1. Is it in any way compatible with the default DiscV5 protocol over UDP?
  2. Does it just implement the DHT messages over libp2p somehow?
wemeetagain commented 3 years ago

Hey Piper. This is just normal discv5 (over UDP) with a small wrapper that implements the libp2p peer discovery interface. This wrapper lets us plug the implementation into our libp2p instance w/o requiring any special handling.

Basically, peers (ENRs) discovered via discv5 are converted to {peerId: PeerId, multiaddrs: Multiaddr[]} and sent to libp2p to be stored in its "peer store".

pipermerriam commented 3 years ago

Would it be accurate to say that this isn't DiscV5 over libp2p but rather it's libp2p leveraging discv5 for peer discovery?

wemeetagain commented 3 years ago

Would it be accurate to say that this isn't DiscV5 over libp2p but rather it's libp2p leveraging discv5 for peer discovery?

Yup exactly

We're mostly just wrapping our vanilla discv5 implementation in this: https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/peer-discovery and initializing the wrapper with libp2p-friendly objects (multiaddr instead of host+port, keypair in format that js-libp2p accepts)

This does not implement discv5 using libp2p "stuff"?

We're not using libp2p transports/stream multiplexing/etc, but one wrinkle is that we are using multiaddrs to identify host+port throughout our implementation.

I think we were hoping to be able to some day swap the UDP server with some other transport (or something that might be more browser friendly). Using multiaddr lets us update the transport with minimal modifications elsewhere. We have this interface: https://github.com/ChainSafe/discv5/blob/master/src/transport/types.ts#L27 that our UDP server implements, and could in theory implement something else thats used to exchange discv5 packets (eg: a websocket connection to a rendezvous server).