Skip to content

Commit 66bd027

Browse files
Feat/587-circuit-relay (#611)
* feat: implemented setup of circuit relay and test cases * chore: remove test files to be rewritten * added 1 test suite for protocol * added 1 test suite for discovery * fixed protocol timeouts and message types to handle reservations and stream operations. * Resolved merge conflict in libp2p/tools/utils.py by combining timeout approach with retry mechanism * fix: linting issues * docs: updated documentation with circuit-relay * chore: added enums, improved typing, security and examples * fix: created proper __init__ file to ensure importability * fix: replace transport_opt with listen_addrs in examples, fixed typing and improved code * fix type checking issues across relay module and test suite * regenerated circuit_pb2 file protobuf version 3 * fixed circuit relay example and moved imports to top in test_security_multistream * chore: moved imports to the top * chore: fixed linting of test_circuit_v2_transport.py --------- Co-authored-by: Manu Sheel Gupta <[email protected]>
1 parent 79094d7 commit 66bd027

25 files changed

+4432
-9
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ PB = libp2p/crypto/pb/crypto.proto \
5959
libp2p/security/noise/pb/noise.proto \
6060
libp2p/identity/identify/pb/identify.proto \
6161
libp2p/host/autonat/pb/autonat.proto \
62+
libp2p/relay/circuit_v2/pb/circuit.proto \
6263
libp2p/kad_dht/pb/kademlia.proto
6364

6465
PY = $(PB:.proto=_pb2.py)

docs/examples.circuit_relay.rst

Lines changed: 499 additions & 0 deletions
Large diffs are not rendered by default.

docs/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ Examples
1111
examples.echo
1212
examples.ping
1313
examples.pubsub
14+
examples.circuit_relay
1415
examples.kademlia

docs/index.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ The Python implementation of the libp2p networking stack
1212
getting_started
1313
release_notes
1414

15-
.. toctree::
16-
:maxdepth: 1
17-
:caption: Community
18-
1915
.. toctree::
2016
:maxdepth: 1
2117
:caption: py-libp2p

docs/libp2p.relay.circuit_v2.pb.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
libp2p.relay.circuit_v2.pb package
2+
==================================
3+
4+
Submodules
5+
----------
6+
7+
libp2p.relay.circuit_v2.pb.circuit_pb2 module
8+
---------------------------------------------
9+
10+
.. automodule:: libp2p.relay.circuit_v2.pb.circuit_pb2
11+
:members:
12+
:show-inheritance:
13+
:undoc-members:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: libp2p.relay.circuit_v2.pb
19+
:members:
20+
:show-inheritance:
21+
:undoc-members:
22+
:no-index:

docs/libp2p.relay.circuit_v2.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
libp2p.relay.circuit_v2 package
2+
===============================
3+
4+
Subpackages
5+
-----------
6+
7+
.. toctree::
8+
:maxdepth: 4
9+
10+
libp2p.relay.circuit_v2.pb
11+
12+
Submodules
13+
----------
14+
15+
libp2p.relay.circuit_v2.protocol module
16+
---------------------------------------
17+
18+
.. automodule:: libp2p.relay.circuit_v2.protocol
19+
:members:
20+
:show-inheritance:
21+
:undoc-members:
22+
23+
libp2p.relay.circuit_v2.transport module
24+
----------------------------------------
25+
26+
.. automodule:: libp2p.relay.circuit_v2.transport
27+
:members:
28+
:show-inheritance:
29+
:undoc-members:
30+
31+
libp2p.relay.circuit_v2.discovery module
32+
----------------------------------------
33+
34+
.. automodule:: libp2p.relay.circuit_v2.discovery
35+
:members:
36+
:show-inheritance:
37+
:undoc-members:
38+
39+
libp2p.relay.circuit_v2.resources module
40+
----------------------------------------
41+
42+
.. automodule:: libp2p.relay.circuit_v2.resources
43+
:members:
44+
:show-inheritance:
45+
:undoc-members:
46+
47+
libp2p.relay.circuit_v2.config module
48+
-------------------------------------
49+
50+
.. automodule:: libp2p.relay.circuit_v2.config
51+
:members:
52+
:show-inheritance:
53+
:undoc-members:
54+
55+
libp2p.relay.circuit_v2.protocol_buffer module
56+
----------------------------------------------
57+
58+
.. automodule:: libp2p.relay.circuit_v2.protocol_buffer
59+
:members:
60+
:show-inheritance:
61+
:undoc-members:
62+
63+
Module contents
64+
---------------
65+
66+
.. automodule:: libp2p.relay.circuit_v2
67+
:members:
68+
:show-inheritance:
69+
:undoc-members:
70+
:no-index:

docs/libp2p.relay.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
libp2p.relay package
2+
====================
3+
4+
Subpackages
5+
-----------
6+
7+
.. toctree::
8+
:maxdepth: 4
9+
10+
libp2p.relay.circuit_v2
11+
12+
Module contents
13+
---------------
14+
15+
.. automodule:: libp2p.relay
16+
:members:
17+
:show-inheritance:
18+
:undoc-members:
19+
:no-index:

docs/libp2p.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Subpackages
1616
libp2p.peer
1717
libp2p.protocol_muxer
1818
libp2p.pubsub
19+
libp2p.relay
1920
libp2p.security
2021
libp2p.stream_muxer
2122
libp2p.tools

libp2p/relay/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Relay module for libp2p.
3+
4+
This package includes implementations of circuit relay protocols
5+
for enabling connectivity between peers behind NATs or firewalls.
6+
"""
7+
8+
# Import the circuit_v2 module to make it accessible
9+
# through the relay package
10+
from libp2p.relay.circuit_v2 import (
11+
PROTOCOL_ID,
12+
CircuitV2Protocol,
13+
CircuitV2Transport,
14+
RelayDiscovery,
15+
RelayLimits,
16+
RelayResourceManager,
17+
Reservation,
18+
)
19+
20+
__all__ = [
21+
"CircuitV2Protocol",
22+
"CircuitV2Transport",
23+
"PROTOCOL_ID",
24+
"RelayDiscovery",
25+
"RelayLimits",
26+
"RelayResourceManager",
27+
"Reservation",
28+
]

libp2p/relay/circuit_v2/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Circuit Relay v2 implementation for libp2p.
3+
4+
This package implements the Circuit Relay v2 protocol as specified in:
5+
https://github.com/libp2p/specs/blob/master/relay/circuit-v2.md
6+
"""
7+
8+
from .discovery import (
9+
RelayDiscovery,
10+
)
11+
from .protocol import (
12+
PROTOCOL_ID,
13+
CircuitV2Protocol,
14+
)
15+
from .resources import (
16+
RelayLimits,
17+
RelayResourceManager,
18+
Reservation,
19+
)
20+
from .transport import (
21+
CircuitV2Transport,
22+
)
23+
24+
__all__ = [
25+
"CircuitV2Protocol",
26+
"PROTOCOL_ID",
27+
"RelayLimits",
28+
"Reservation",
29+
"RelayResourceManager",
30+
"CircuitV2Transport",
31+
"RelayDiscovery",
32+
]

0 commit comments

Comments
 (0)