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.