Upgrade to Pro — share decks privately, control downloads, hide ads and more …

p2p-libp2p.pdf

 p2p-libp2p.pdf

koganezawa

April 12, 2019
Tweet

More Decks by koganezawa

Other Decks in Programming

Transcript

  1. Agenda • About libp2p • libp2p architecture • Let's code

    a blockchain! ◦ About shared objects ◦ Required import packages for P2P ◦ BlockChain specific functions ◦ Host to deal with incoming data steams • Demo
  2. About libp2p ➢ libp2p... ◦ modular network stack ( network

    framework ) for creating p2p apps ◦ the modular P2P network stack by IPFS for better decentralized computing
  3. About libp2p ➢ P2P Application vs. Web Application: What's the

    Difference? ▪ client also acts as a server ▪ It is not fixed function like server client model • dial / listen both possible
  4. libp2p architecture ➢ Indentity ➢ multiaddr ➢ Peer Routing ➢

    Swarm ➢ Distributed Record Store ➢ Discovery
  5. libp2p architecture ➢ Indentity ◦ Upon first connecting, peers exchange

    public keys, ◦ check: multihash(other.PublicKey) equals other.NodeId. ◦ If not the connection is terminated. ➢ What is multihash? ◦ Multihash is a protocol for differentiating outputs from various well-established cryptographic hash functions, ◦ and allow multiple hash functions to coexist. ◦ varint hash function code(tag: multihash) ▪ https://github.com/multiformats/multicodec/blob/master/table.csv
  6. ➢ Peer Routing ◦ kad-routing ▪ kad-routing implements the Kademlia

    Routing table ▪ where each peer holds a set of k-buckets ▪ each of them containing several PeerInfo objects from other peers in the network. libp2p architecture
  7. ➢ Peer Routing ◦ What is Kademlia? ▪ Kademlia is

    a distributed hash table for decentralized peer-to-peer computer networks designed by Petar Maymounkov and David Mazières in 2002 • Kademlia stores values in nodes whose ids are “nearest” ◦ using XOR-distance to the key. • The ID uses the hash value of the IP address. • see: https://libp2p.github.io/js-libp2p-kad-dht/ libp2p architecture 001
  8. ➢ Peer Routing ◦ mDNS-routing ▪ mDNS-routing uses mDNS probes

    to identify if local area network peers have a given key or they are simply present. ◦ other-routing-mechanisms ▪ other Peer Routing mechanisms can be implemented libp2p architecture
  9. ➢ Swarm ◦ Conn-a connection to a single Peer ▪

    MultiConn-a set of connections to a single Peer ▪ SecureConn-an encrypted (tls-like) connection ◦ Swarm-holds connections to Peers ▪ multiplexes from / to each MultiConn ◦ Muxer-Multiples between Services and Swarm. Handles Request / Reply. ▪ Service-connects between an outside client service and Network. ▪ Handler-the client service part that handles requests libp2p architecture
  10. ➢ Distributed Record Store ◦ A system to store and

    distribute records. ◦ Records are small entries used by other systems for signaling, establishing links, announcing peers or content, and so on. They have a similar role to DNS in the broader Internet. libp2p architecture
  11. ➢ Discovery ◦ mDNS-discovery ▪ mDNS-discovery is a Discovery Protocol

    that uses mDNS over local area networks. ▪ It emits mDNS beacons to find if there are more peers available. ◦ Random-Walk ▪ Random-Walk is a Discovery Protocol for DHTs (and other protocols with routing tables). ▪ It makes random DHT queries in order to learn about a large number of peers quickly. ▪ at the expense of a small load at the very beginning. ◦ Bootstrap-List ▪ Bootstrap-List is a Discovery Protocol that uses local storage to cache the addresses of highly stable (and somewhat trusted) peers available in the network libp2p architecture
  12. ➢ Required import packages for go-libp2p Let's code a blockchain!

    library module description github.com/libp2p/go-libp2p libp2p dial / listen, network package github.com/libp2p/go-libp2p-net github.com/libp2p/go-libp2p-host swarm protocol/stream muxer github.com/libp2p/go-libp2p-peerstore distributed record store an object to manage peers, their addresses, and other metadata about them. github.com/libp2p/go-libp2p-peer utilities PKI-based identity management github.com/libp2p/go-libp2p-protocol utilities type for protoco github.com/libp2p/go-libp2p-crypto utilities various cryptographic utilities
  13. ➢ New Stream ◦ We have a peer ID and

    a target Addr so we add it to the peer store ◦ so libp2p knows how to contact it Let's code a blockchain!