Skip to content

Commit 9e1976b

Browse files
committed
Fix: Initialize health_data in Swarm.__init__ instead of set_resource_manager
The health_data attribute was only being initialized in set_resource_manager, but it needs to be available immediately after Swarm creation for tests and other code that accesses it before set_resource_manager is called.
2 parents 8a5d898 + 702b98d commit 9e1976b

File tree

239 files changed

+34085
-1470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+34085
-1470
lines changed

.github/workflows/tox.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
python: ["3.10", "3.11", "3.12", "3.13"]
21-
toxenv: [core, interop, lint, wheel, demos]
21+
toxenv: [core, demos, interop, lint, utils, wheel]
2222
include:
2323
- python: "3.10"
2424
toxenv: docs
@@ -81,7 +81,7 @@ jobs:
8181
if [[ "${{ matrix.toxenv }}" == 'docs' ]]; then
8282
export TOXENV=docs
8383
else
84-
export TOXENV=py${{ matrix.python }}-${{ matrix.toxenv }}
84+
export TOXENV=$(echo "py${{ matrix.python }}-${{ matrix.toxenv }}" | tr -d '.')
8585
fi
8686
# Set PATH for nim commands during tox
8787
if [[ "${{ matrix.toxenv }}" == 'interop' ]]; then
@@ -95,7 +95,7 @@ jobs:
9595
strategy:
9696
matrix:
9797
python-version: ["3.11", "3.12", "3.13"]
98-
toxenv: [core, wheel]
98+
toxenv: [core, demos, utils, wheel]
9999
fail-fast: false
100100
steps:
101101
- uses: actions/checkout@v4

FUNDING.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"drips": {
3+
"filecoin": {
4+
"ownedBy": "0x856c29E91eb30b8D9154a74a543dcC8D970D5D15"
5+
}
6+
}
7+
}

Filecoin_Retro_PGF.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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>

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typecheck:
4646
pre-commit run mypy-local --all-files && pre-commit run pyrefly-local --all-files
4747

4848
test:
49-
python -m pytest tests -n auto --timeout=1200
49+
python -m pytest tests -n auto
5050

5151
pr: clean fix lint typecheck test
5252

@@ -62,7 +62,10 @@ PB = libp2p/crypto/pb/crypto.proto \
6262
libp2p/relay/circuit_v2/pb/circuit.proto \
6363
libp2p/relay/circuit_v2/pb/dcutr.proto \
6464
libp2p/kad_dht/pb/kademlia.proto \
65-
libp2p/discovery/rendezvous/pb/rendezvous.proto
65+
libp2p/discovery/rendezvous/pb/rendezvous.proto \
66+
libp2p/bitswap/pb/bitswap.proto \
67+
libp2p/bitswap/pb/dag_pb.proto \
68+
libp2p/bitswap/pb/unixfs.proto
6669

6770
PY = $(PB:.proto=_pb2.py)
6871
PYI = $(PB:.proto=_pb2.pyi)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[![Python versions](https://img.shields.io/pypi/pyversions/libp2p.svg)](https://pypi.python.org/pypi/libp2p)
1212
[![Build Status](https://img.shields.io/github/actions/workflow/status/libp2p/py-libp2p/tox.yml?branch=main&label=build%20status)](https://github.com/libp2p/py-libp2p/actions/workflows/tox.yml)
1313
[![Docs build](https://readthedocs.org/projects/py-libp2p/badge/?version=latest)](http://py-libp2p.readthedocs.io/en/latest/?badge=latest)
14+
<a href="https://filecoin.drips.network/app/projects/github/libp2p/py-libp2p" target="_blank"><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" alt="Support py-libp2p on drips.network" height="32"></a>
1415

1516
> py-libp2p has moved beyond its experimental roots and is steadily progressing toward production readiness. The core features are stable, and we’re focused on refining performance, expanding protocol support, and ensuring smooth interop with other libp2p implementations. We welcome contributions and real-world usage feedback to help us reach full production maturity.
1617
@@ -55,7 +56,7 @@ ______________________________________________________________________
5556
| **Secure Communication** | **Status** | **Source** |
5657
| ------------------------ | :--------: | :---------------------------------------------------------------------------: |
5758
| **`libp2p-noise`** || [source](https://github.com/libp2p/py-libp2p/tree/main/libp2p/security/noise) |
58-
| **`libp2p-tls`** | 🌱 | |
59+
| **`libp2p-tls`** | | |
5960

6061
______________________________________________________________________
6162

@@ -100,7 +101,7 @@ ______________________________________________________________________
100101

101102
| **Storage** | **Status** |
102103
| ------------------- | :--------: |
103-
| **`libp2p-record`** | 🌱 |
104+
| **`libp2p-record`** | |
104105

105106
______________________________________________________________________
106107

docs/conf.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import os
1919
import sys
2020

21-
sys.path.insert(0, os.path.abspath('..'))
21+
sys.path.insert(0, os.path.abspath(".."))
2222
from unittest.mock import MagicMock
2323

2424
try:
@@ -50,6 +50,21 @@
5050
"sphinx_rtd_theme",
5151
]
5252

53+
# Configure Python domain to prefer canonical imports
54+
# This helps resolve ambiguous references like ResourceManager
55+
python_use_unqualified_type_names = False
56+
57+
# Configure autodoc to prefer specific imports for ambiguous references
58+
autodoc_type_aliases = {
59+
"ResourceManager": "libp2p.rcmgr.ResourceManager",
60+
}
61+
62+
# Suppress specific warnings about ambiguous cross-references
63+
# Since ResourceManager is intentionally re-exported, both locations are valid
64+
suppress_warnings = [
65+
"ref.python", # Suppress ambiguous cross-reference warnings
66+
]
67+
5368
# Add any paths that contain templates here, relative to this directory.
5469
templates_path = ["_templates"]
5570

@@ -291,7 +306,12 @@
291306
]
292307

293308
# Prevent autodoc from trying to import module from tests.factories
294-
autodoc_mock_imports = ["tests.factories"]
309+
autodoc_mock_imports = [
310+
"tests.factories",
311+
# Mocked ONLY for Sphinx/autodoc: this module does not exist in the codebase
312+
# but some doc tools may try to import it. No real code references this import.
313+
"libp2p.relay.circuit_v2.lib"
314+
]
295315

296316
# Documents to append as an appendix to all manuals.
297317
# texinfo_appendices = []

docs/contributing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ To add a new example (e.g., identify):
261261
"echo-demo=examples.echo.echo:main",
262262
"ping-demo=examples.ping.ping:main",
263263
"identify-demo=examples.identify.identify:main",
264+
"circuit-relay-demo=examples.circuit_relay.relay_example:main"
264265
],
265266
}
266267

0 commit comments

Comments
 (0)