libp2p
What is libp2p?
It is a suite of tools for peer to peer networking (p2p networks)
Why is libp2p useful to blockchain interactions?
Blockchain interactions are p2p
Provide proper abstractions for peer2peer comms, vs client server.
Transport mechanisms are complex
Provide simple interface https://github.com/libp2p/js-libp2p-interfaces
We need a notion of identity
Use public key to give each peer a globally uid. Retrieve public key for identified peer.
We need our communication to be secure
We can “upgrade” connections to become more secure.
- TLS 1.3
- Noise
We need to find a route to communicate
- Use PeerId
- Use knowledge of other peers to get peer id.
- Construct our own routing tables.
- We use distributed hash table + kademlia routing algo
How to use libp2p?
https://github.com/kwannoel/libp2p-tutorial-rust
What are our design principles?
transport layer transport agnostic - developer chooses which transport protocol to use. provides communication primitives - listening and dialing. multaddress - specify transport protocols, addresses, peerId. TBD - peer routing - do not have to use transport addresses. switch (previously swarm) - multiplexing, protocol negotation, secure comms.
Network Address Translation (NAT) traversal: https://libp2p.io/implementations/#nat-traversal
- Sending outgoing connections is no issue.
- Receiving incoming connection requires configuration, since we need to route the incoming packet to your machine. You have 2 options:
- manually configure :(
- Use UPnP / nat-pmp (must check if router supports)
- Hole-punching (STUN) Some Routers will observe your outgoing connections, and permit incoming connections to reuse the same port to get to you. We can generalize this and allow peers to inform each other about routing addresses.
- AutoNAT For Routers which don’t allow incoming connections on the same port as dialling out connections, peers can attempt to dial us at observed addresses. If this succeeds, we know other peers can dial us. WIP: https://github.com/libp2p/go-libp2p-autonat
- Circuit Relay (TURN) See: https://docs.libp2p.io/concepts/circuit-relay/ and: https://datatracker.ietf.org/doc/html/rfc5766 Unable to make themselves publicly accessible, communicate indirectly via a intermediary peer, which does the listening for them.
Libp2p Goodies
Libp2p protocols Libp2p peerid and peerinfo Libp2p multiaddress Libp2p security concerns Libp2p pubsub Libp2p stream multiplexing