11 Building a P2P node with async Rust

 

This chapter covers

  • Introducing peer-to-peer networks
  • Understanding the core architecture of libp2p networking
  • Exchanging ping commands between peer nodes
  • Discovering peers in a P2P network

In the previous chapter, we covered the basics of async programming and how to write async code with Rust. In this chapter, we’ll build a few simple examples of peer-to-peer (P2P) applications using a low-level P2P networking library and asynchronous programming using Rust.

Why learn about P2P? P2P is a networking technology that enables the sharing of various computing resources, such as CPU, network bandwidth, and storage, across different computers. P2P is a very commonly used method for sharing files (such as music, images, and other digital media) between users online. BitTorrent and Gnutella are examples of popular file-sharing P2P apps. They do not rely on a central server or an intermediary to connect multiple clients. And most importantly, they make use of users’ computers as both clients and servers, thus offloading computations from a central server.

How do P2P networks operate, and how are they different? Let’s delve into the foundational concepts behind peer-to-peer networks.

NOTE

This chapter draws heavily on material from the libp2p documentation at https://libp2p.io/. The code examples use the Rust implementation of the libp2p protocol, which can be found on GitHub: https://github.com/libp2p/rust-libp2p.

11.1 Introducing peer-to-peer networks

11.1.1 Transport

11.1.2 Peer identity

11.1.3 Security

11.1.4 Peer routing

11.1.5 Messaging

11.1.6 Stream multiplexing

11.2 Understanding the core architecture of libp2p networking

11.2.1 Peer IDs and key pairs

11.2.2 Multiaddresses

11.2.3 Swarm and network behavior

11.3 Exchanging ping commands between peer nodes