5 Using Libp2p to connect applications peer-to-peer

 

This chapter covers

  • Introduction to the Libp2p Javascript library
  • Using the Libp2p Javascript library to connect Web3 applications peer-to-peer
  • Replacing application DNS with peer IDs provided by Libp2p

In this chapter you will learn about the Libp2p Javascript library, and how to use it to allow your Web3 applications to communicate peer-to-peer. After replacing centralized storage and compute with client-side Javascript programming in previous chapters, allowing instances of the Code Radio demo application to communicate peer-to-peer is the final step in removing all centralized resources and delivering a product that can be certified as Web3.

5.1 Libp2p features

Libp2p is an open-source project initially developed by Protocol Labs, which refers to itself as a "modular network stack". As a network stack, Libp2p is designed to abstract away much of the complexities which come with programming network services, but a basic level of data networking is still required to make use of Libp2p in most application designs. At the time of writing, Libp2p is offered in several programming language implementations, including Go, Rust, Python, C++, and more. This chapter focuses on the Libp2p Javascript implementation which allows it to be seamlessly integrated with application running in a browser, such as Code Radio.

5.1.1 Multiple transports

5.1.2 Protocol muxing

5.1.3 Encrypted connections

5.1.4 Native roaming

5.2 Libp2p protocol support

5.3 Connectivity available to Libp2p browser instances

5.3.1 WebRTC

5.4 Connectivity available to Libp2p standalone instances

5.4.1 TCP protocol support

5.4.2 QUIC protocol support

5.4.3 Hole punching

5.5 Libp2p ping: code example

5.5.1 Libp2p ping: application dependencies

5.5.2 Sending messages using Libp2p

5.5.3 Receiving messages using Libp2p