SlideShare a Scribd company logo
libp2p
koganezawa@MoneyForward Financial
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
About libp2p
➢ libp2p...
○ modular network stack ( network framework ) for creating p2p apps
○ the modular P2P network stack by IPFS for better decentralized computing
➢ Adopters
About libp2p
Polkadot
Ethereum2.0
MetaMask
OpenBazaar
Filecoin
IPFS
About libp2p
➢ Languages
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
libp2p architecture
➢ Indentity
➢ multiaddr
➢ Peer Routing
➢ Swarm
➢ Distributed Record Store
➢ Discovery
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
○ allow multiple hash functions to coexist.
○ varint hash function code(tag: multihash)
■ https://github.com/multiformats/multicodec/blob/master/table.csv
➢ Indentity
○ ID for identifying distributed nodes
libp2p architecture
# Identity generation:
libp2p architecture
➢ multihash
# Format:
# Binary example (only 4 bytes for simplicity):
# Format:
➢ multiaddr
○ Multiple protocols are multiplexed using only one port
libp2p architecture
➢ 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
➢ 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
➢ 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
➢ 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
➢ 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
➢ 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
➢ 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 protocol
github.com/libp2p/go-libp2p-crypto utilities various cryptographic utilities
➢ About shared objects
Let's code a blockchain!
➢ BlockChain specific functions
Let's code a blockchain!
➢ BlockChain specific functions
Let's code a blockchain!
➢ BlockChain specific functions
Let's code a blockchain!
➢ Host to deal with incoming data steams
Let's code a blockchain!
➢ 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!
➢ Host to deal with incoming data steams
○ ReadBlockChain
Let's code a blockchain!
➢ Host to deal with incoming data steams
○ WriteBlockChain is broadcast
Let's code a blockchain!
➢ Host to deal with incoming data steams
○ WriteBlockChain is broadcast
Let's code a blockchain!
➢ BasicHost
○ Generate host
Let's code a blockchain!
➢ Host to deal with incoming data steams
○ main
Let's code a blockchain!
Demo!
Next Action
➢ demo devp2p!!
● libp2p-specs
● libp2p.io
● ÐΞVp2p
● code-a-simple-p2p-blockchain-in-go
● ethereum-wireshark-dissectors
● ethereum-swarm
References

More Related Content

PDF
HyperLedger Fabric V2.5.pdf
PDF
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
PDF
Operationalizing Multi Cluster Istio_ Lessons Learned and Developing Ambient ...
PDF
Webinar: PostgreSQL continuous backup and PITR with Barman
PDF
Unveiling etcd: Architecture and Source Code Deep Dive
PDF
Using ClickHouse for Experimentation
PPTX
Introduction to ELK
PDF
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
HyperLedger Fabric V2.5.pdf
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
Operationalizing Multi Cluster Istio_ Lessons Learned and Developing Ambient ...
Webinar: PostgreSQL continuous backup and PITR with Barman
Unveiling etcd: Architecture and Source Code Deep Dive
Using ClickHouse for Experimentation
Introduction to ELK
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...

What's hot (20)

PDF
Getting up to speed with Kafka Connect: from the basics to the latest feature...
PPTX
OpenvSwitch Deep Dive
PDF
Recent Progress in RNN and NLP
PDF
Introduction to Diffusion Models
PDF
Bridge to the Future: Migrating to KRaft
PDF
Mastering PostgreSQL Administration
 
PDF
[DockerCon 2019] Hardening Docker daemon with Rootless mode
PPTX
HDFS Erasure Coding in Action
PDF
Foreman Single Sign-On Made Easy with Keycloak
PDF
OpenVPN as a WAN - pfSense Hangout October 2016
PDF
Cloud Native Networking & Security with Cilium & eBPF
PDF
Understanding Open vSwitch
PDF
Method of NUMA-Aware Resource Management for Kubernetes 5G NFV Cluster
PPTX
Understanding DPDK algorithmics
PDF
Introducing Apache Airflow and how we are using it
PDF
A Brief Overview of 'Radical Markets'
PPTX
PDF
Common issues with Apache Kafka® Producer
PDF
Linux network stack
PDF
Will Lyon- Entity Resolution
Getting up to speed with Kafka Connect: from the basics to the latest feature...
OpenvSwitch Deep Dive
Recent Progress in RNN and NLP
Introduction to Diffusion Models
Bridge to the Future: Migrating to KRaft
Mastering PostgreSQL Administration
 
[DockerCon 2019] Hardening Docker daemon with Rootless mode
HDFS Erasure Coding in Action
Foreman Single Sign-On Made Easy with Keycloak
OpenVPN as a WAN - pfSense Hangout October 2016
Cloud Native Networking & Security with Cilium & eBPF
Understanding Open vSwitch
Method of NUMA-Aware Resource Management for Kubernetes 5G NFV Cluster
Understanding DPDK algorithmics
Introducing Apache Airflow and how we are using it
A Brief Overview of 'Radical Markets'
Common issues with Apache Kafka® Producer
Linux network stack
Will Lyon- Entity Resolution
Ad

Similar to Try to implement Blockchain using libp2p (20)

PDF
Encode club introduction_to_libp2p
PDF
Module: the modular p2 p networking stack
PDF
Building a sdn solution for the deployment of web application stacks in docker
PDF
What CloudStackers Need To Know About LINSTOR/DRBD
PPTX
Introduction to DPDK
ODP
Informix Expedition Through Connectivity
PDF
Strimzi - Where Apache Kafka meets OpenShift - OpenShift Spain MeetUp
PPTX
Open stackaustinmeetupsept21
PDF
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
PDF
Yechielthur1100red hat-cloud-infrastructure-networking-deep-dive-140417165107...
PPTX
osi model - communication system for connecting end-systems
PDF
LibCT и контейнеры на уровне приложений -- Александр Бурлука
PDF
Janus & docker: friends or foe
PDF
Let's Containerize New York with Docker!
PDF
Deep dive into highly available open stack architecture openstack summit va...
PPTX
Docker Networking - Current Status and goals of Experimental Networking
PDF
DevSecCon London 2019: A Kernel of Truth: Intrusion Detection and Attestation...
PPTX
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
PPTX
Open stack HA - Theory to Reality
PDF
Quest for a low powered home hub 120522
Encode club introduction_to_libp2p
Module: the modular p2 p networking stack
Building a sdn solution for the deployment of web application stacks in docker
What CloudStackers Need To Know About LINSTOR/DRBD
Introduction to DPDK
Informix Expedition Through Connectivity
Strimzi - Where Apache Kafka meets OpenShift - OpenShift Spain MeetUp
Open stackaustinmeetupsept21
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Yechielthur1100red hat-cloud-infrastructure-networking-deep-dive-140417165107...
osi model - communication system for connecting end-systems
LibCT и контейнеры на уровне приложений -- Александр Бурлука
Janus & docker: friends or foe
Let's Containerize New York with Docker!
Deep dive into highly available open stack architecture openstack summit va...
Docker Networking - Current Status and goals of Experimental Networking
DevSecCon London 2019: A Kernel of Truth: Intrusion Detection and Attestation...
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
Open stack HA - Theory to Reality
Quest for a low powered home hub 120522
Ad

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
cuic standard and advanced reporting.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectroscopy.pptx food analysis technology
Programs and apps: productivity, graphics, security and other tools
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Chapter 3 Spatial Domain Image Processing.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
gpt5_lecture_notes_comprehensive_20250812015547.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
sap open course for s4hana steps from ECC to s4
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Try to implement Blockchain using libp2p

  • 2. 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
  • 3. About libp2p ➢ libp2p... ○ modular network stack ( network framework ) for creating p2p apps ○ the modular P2P network stack by IPFS for better decentralized computing
  • 6. 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
  • 7. libp2p architecture ➢ Indentity ➢ multiaddr ➢ Peer Routing ➢ Swarm ➢ Distributed Record Store ➢ Discovery
  • 8. 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 ○ allow multiple hash functions to coexist. ○ varint hash function code(tag: multihash) ■ https://github.com/multiformats/multicodec/blob/master/table.csv
  • 9. ➢ Indentity ○ ID for identifying distributed nodes libp2p architecture # Identity generation:
  • 10. libp2p architecture ➢ multihash # Format: # Binary example (only 4 bytes for simplicity):
  • 11. # Format: ➢ multiaddr ○ Multiple protocols are multiplexed using only one port libp2p architecture
  • 12. ➢ 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
  • 13. ➢ 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
  • 14. ➢ 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
  • 15. ➢ 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
  • 16. ➢ 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
  • 17. ➢ 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
  • 18. ➢ 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 protocol github.com/libp2p/go-libp2p-crypto utilities various cryptographic utilities
  • 19. ➢ About shared objects Let's code a blockchain!
  • 20. ➢ BlockChain specific functions Let's code a blockchain!
  • 21. ➢ BlockChain specific functions Let's code a blockchain!
  • 22. ➢ BlockChain specific functions Let's code a blockchain!
  • 23. ➢ Host to deal with incoming data steams Let's code a blockchain!
  • 24. ➢ 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!
  • 25. ➢ Host to deal with incoming data steams ○ ReadBlockChain Let's code a blockchain!
  • 26. ➢ Host to deal with incoming data steams ○ WriteBlockChain is broadcast Let's code a blockchain!
  • 27. ➢ Host to deal with incoming data steams ○ WriteBlockChain is broadcast Let's code a blockchain!
  • 28. ➢ BasicHost ○ Generate host Let's code a blockchain!
  • 29. ➢ Host to deal with incoming data steams ○ main Let's code a blockchain!
  • 30. Demo!
  • 32. ● libp2p-specs ● libp2p.io ● ÐΞVp2p ● code-a-simple-p2p-blockchain-in-go ● ethereum-wireshark-dissectors ● ethereum-swarm References