Skip to content

Instantly share code, notes, and snippets.

@whyrusleeping
Created January 16, 2019 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whyrusleeping/15aea87ff1798b45d507df60719bd7f3 to your computer and use it in GitHub Desktop.
Save whyrusleeping/15aea87ff1798b45d507df60719bd7f3 to your computer and use it in GitHub Desktop.
Quick brain dump on how to libp2p

Libp2p spec notes

  1. connect your network transport
  2. Negotiate your crypto transport using multistream select
    1. To skip encryption, you can use /plaintext/1.0.0
    2. Multistream select protocol is described here: https://github.com/multiformats/multistream-select
    3. TLDR; send <Len>/multistream/1.0.0\n<Len>/plaintext/1.0.0\n where <Len> is the length of each string (including the new line) encoded as a variant
  3. Next, negotiate your stream multiplexer. This is another multistream negotiation.
    1. If implementing things from scratch, the most supported, and easiest to implement stream multiplexer is mplex. The protocol ID (for the negotiation) is /mplex/6.7.0
    2. The spec for mplex is at https://github.com/libp2p/specs/tree/master/mplex
  4. Now that you can multiplex, you can speak libp2p protocols. To ping a node, for example, open a new stream (via your multiplexer) and multistream negotiate /ipfs/ping/1.0.0, then run the ping protocol, which is simply:
    1. While true: Send 32 bytes, read back those 32 bytes, close the stream to end the protocol.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment