- connect your network transport
- Negotiate your crypto transport using multistream select
- To skip encryption, you can use
/plaintext/1.0.0
- Multistream select protocol is described here: https://github.com/multiformats/multistream-select
- 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
- To skip encryption, you can use
- Next, negotiate your stream multiplexer. This is another multistream negotiation.
- 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
- The spec for mplex is at https://github.com/libp2p/specs/tree/master/mplex
- If implementing things from scratch, the most supported, and easiest to implement stream multiplexer is mplex. The protocol ID (for the negotiation) is
- 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:- While true: Send 32 bytes, read back those 32 bytes, close the stream to end the protocol.
-
-
Save whyrusleeping/15aea87ff1798b45d507df60719bd7f3 to your computer and use it in GitHub Desktop.
Quick brain dump on how to libp2p
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment