|
| 1 | +# py-libp2p |
| 2 | + |
| 3 | +<h1 align="center"> |
| 4 | + <a href="https://libp2p.io/"><img width="250" src="https://github.com/libp2p/py-libp2p/blob/main/assets/py-libp2p-logo.png?raw=true" alt="py-libp2p hex logo" /></a> |
| 5 | +</h1> |
| 6 | + |
| 7 | +<p align="center"> |
| 8 | + <a href="https://filecoin.drips.network/app/projects/github/libp2p/py-libp2p" target="_blank"> |
| 9 | + <img src="https://filecoin.drips.network/api/embed/project/https%3A%2F%2Fgithub.com%2Flibp2p%2Fpy-libp2p/support.png?background=light&style=drips&text=Support&stat=support" |
| 10 | + alt="Support py-libp2p on drips.network" height="36"> |
| 11 | + </a> |
| 12 | +</p> |
| 13 | + |
| 14 | +<h3 align="center">The Python implementation of the libp2p networking stack.</h3> |
| 15 | + |
| 16 | +> py-libp2p has moved beyond its experimental roots and is progressing toward production readiness. Core modules are stable, with active work on performance, protocol coverage, and interop with other libp2p implementations. We welcome contributions and real-world usage feedback. |
| 17 | +
|
| 18 | +## Maintainers |
| 19 | + |
| 20 | +Maintained by [@pacrob](https://github.com/pacrob), [@seetadev](https://github.com/seetadev), and [@dhuseby](https://github.com/dhuseby). |
| 21 | + |
| 22 | +Questions or ideas? |
| 23 | +Start a discussion: https://github.com/libp2p/py-libp2p/discussions |
| 24 | +Join the Discord: https://discord.gg/d92MEugb (#py-libp2p) |
| 25 | + |
| 26 | +## Feature Breakdown |
| 27 | + |
| 28 | +✅ Stable · 🛠️ In Progress · 🌱 Prototype · ❌ Not Yet Implemented |
| 29 | + |
| 30 | +### Transports |
| 31 | + |
| 32 | +| Transport | Status | Source | |
| 33 | +| ---------------------------------- | :----: | :-----------------------------------------------------------------------: | |
| 34 | +| `libp2p-tcp` | ✅ | https://github.com/libp2p/py-libp2p/blob/main/libp2p/transport/tcp/tcp.py | |
| 35 | +| `libp2p-quic` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/transport/quic | |
| 36 | +| `libp2p-websocket` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/transport/websocket | |
| 37 | +| `libp2p-webrtc-browser-to-server` | 🌱 | — | |
| 38 | +| `libp2p-webrtc-private-to-private` | 🌱 | — | |
| 39 | + |
| 40 | +### NAT Traversal |
| 41 | + |
| 42 | +| NAT Traversal | Status | Source | |
| 43 | +| ------------------------- | :----: | :-------------------------------------------------------------------: | |
| 44 | +| `libp2p-circuit-relay-v2` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/relay/circuit_v2 | |
| 45 | +| `libp2p-autonat` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/host/autonat | |
| 46 | +| `libp2p-hole-punching` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/relay/circuit_v2 | |
| 47 | + |
| 48 | +### Secure Communication |
| 49 | + |
| 50 | +| Secure Channel | Status | Source | |
| 51 | +| -------------- | :----: | :-----------------------------------------------------------------: | |
| 52 | +| `libp2p-noise` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/security/noise | |
| 53 | +| `libp2p-tls` | ✅ | — | |
| 54 | + |
| 55 | +### Discovery |
| 56 | + |
| 57 | +| Discovery | Status | Source | |
| 58 | +| ---------------- | :----: | :------------------------------------------------------------------------: | |
| 59 | +| `bootstrap` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/bootstrap | |
| 60 | +| `random-walk` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/random_walk | |
| 61 | +| `mdns-discovery` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/mdns | |
| 62 | +| `rendezvous` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/rendezvous | |
| 63 | + |
| 64 | +### Peer Routing |
| 65 | + |
| 66 | +| Peer Routing | Status | Source | |
| 67 | +| ---------------- | :----: | :----------------------------------------------------------: | |
| 68 | +| `libp2p-kad-dht` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/kad_dht | |
| 69 | + |
| 70 | +### Publish/Subscribe |
| 71 | + |
| 72 | +| PubSub | Status | Source | |
| 73 | +| ------------------ | :----: | :----------------------------------------------------------------------: | |
| 74 | +| `libp2p-floodsub` | ✅ | https://github.com/libp2p/py-libp2p/blob/main/libp2p/pubsub/floodsub.py | |
| 75 | +| `libp2p-gossipsub` | ✅ | https://github.com/libp2p/py-libp2p/blob/main/libp2p/pubsub/gossipsub.py | |
| 76 | + |
| 77 | +### Stream Muxers |
| 78 | + |
| 79 | +| Muxer | Status | Source | |
| 80 | +| -------------- | :----: | :---------------------------------------------------------------------: | |
| 81 | +| `libp2p-yamux` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/stream_muxer/yamux | |
| 82 | +| `libp2p-mplex` | ✅ | https://github.com/libp2p/py-libp2p/tree/main/libp2p/stream_muxer/mplex | |
| 83 | + |
| 84 | +### Storage |
| 85 | + |
| 86 | +| **Storage** | **Status** | |
| 87 | +| ------------------- | :--------: | |
| 88 | +| **`libp2p-record`** | ✅ | |
| 89 | + |
| 90 | +### General Purpose Utilities & Datatypes |
| 91 | + |
| 92 | +| **Utility/Datatype** | **Status** | **Source** | |
| 93 | +| --------------------- | :--------: | :------------------------------------------------------------------------------------------: | |
| 94 | +| **`libp2p-ping`** | ✅ | [source](https://github.com/libp2p/py-libp2p/blob/main/libp2p/host/ping.py) | |
| 95 | +| **`libp2p-peer`** | ✅ | [source](https://github.com/libp2p/py-libp2p/tree/main/libp2p/peer) | |
| 96 | +| **`libp2p-identify`** | ✅ | [source](https://github.com/libp2p/py-libp2p/blob/main/libp2p/identity/identify/identify.py) | |
| 97 | + |
| 98 | +## Explanation of Basic Two Node Communication |
| 99 | + |
| 100 | +### Core Concepts |
| 101 | + |
| 102 | +_(non-normative, useful for team notes, not a reference)_ |
| 103 | + |
| 104 | +Several components of the libp2p stack take part when establishing a connection between two nodes: |
| 105 | + |
| 106 | +1. **Host**: a node in the libp2p network. |
| 107 | +1. **Connection**: the layer 3 connection between two nodes in a libp2p network. |
| 108 | +1. **Transport**: the component that creates a _Connection_, e.g. TCP, UDP, QUIC, etc. |
| 109 | +1. **Streams**: an abstraction on top of a _Connection_ representing parallel conversations about different matters, each of which is identified by a protocol ID. Multiple streams are layered on top of a _Connection_ via the _Multiplexer_. |
| 110 | +1. **Multiplexer**: a component that is responsible for wrapping messages sent on a stream with an envelope that identifies the stream they pertain to, normally via an ID. The multiplexer on the other unwraps the message and routes it internally based on the stream identification. |
| 111 | +1. **Secure channel**: optionally establishes a secure, encrypted, and authenticated channel over the _Connection_. |
| 112 | +1. **Upgrader**: a component that takes a raw layer 3 connection returned by the _Transport_, and performs the security and multiplexing negotiation to set up a secure, multiplexed channel on top of which _Streams_ can be opened. |
| 113 | + |
| 114 | +### Communication between two hosts X and Y |
| 115 | + |
| 116 | +_(non-normative, useful for team notes, not a reference)_ |
| 117 | + |
| 118 | +**Initiate the connection**: A host is simply a node in the libp2p network that is able to communicate with other nodes in the network. In order for X and Y to communicate with one another, one of the hosts must initiate the connection. Let's say that X is going to initiate the connection. X will first open a connection to Y. This connection is where all of the actual communication will take place. |
| 119 | + |
| 120 | +**Communication over one connection with multiple protocols**: X and Y can communicate over the same connection using different protocols and the multiplexer will appropriately route messages for a given protocol to a particular handler function for that protocol, which allows for each host to handle different protocols with separate functions. Furthermore, we can use multiple streams for a given protocol that allow for the same protocol and same underlying connection to be used for communication about separate topics between nodes X and Y. |
| 121 | + |
| 122 | +**Why use multiple streams?**: The purpose of using the same connection for multiple streams to communicate over is to avoid the overhead of having multiple connections between X and Y. In order for X and Y to differentiate between messages on different streams and different protocols, a multiplexer is used to encode the messages when a message will be sent and decode a message when a message is received. The multiplexer encodes the message by adding a header to the beginning of any message to be sent that contains the stream id (along with some other info). Then, the message is sent across the raw connection and the receiving host will use its multiplexer to decode the message, i.e. determine which stream id the message should be routed to. |
| 123 | + |
| 124 | +## Support |
| 125 | + |
| 126 | +If py-libp2p has been useful to your project or organization, please consider supporting ongoing development: |
| 127 | + |
| 128 | +<p> |
| 129 | + <a href="https://filecoin.drips.network/app/projects/github/libp2p/py-libp2p" target="_blank"> |
| 130 | + <img src="https://filecoin.drips.network/api/embed/project/https%3A%2F%2Fgithub.com%2Flibp2p%2Fpy-libp2p/support.png?background=light&style=drips&text=project&stat=support" height="32" alt="Support py-libp2p on drips.network"> |
| 131 | + </a> |
| 132 | +</p> |
0 commit comments