Skip to content

Commit 038eb29

Browse files
Khwahish29pacrob
authored andcommitted
add quic related file to toctree
1 parent b18c728 commit 038eb29

File tree

3 files changed

+193
-6
lines changed

3 files changed

+193
-6
lines changed

docs/libp2p.transport.quic.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
libp2p.transport.quic package
2+
============================
3+
4+
Submodules
5+
----------
6+
7+
libp2p.transport.quic.transport module
8+
------------------------------------
9+
10+
.. automodule:: libp2p.transport.quic.transport
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: libp2p.transport.quic
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
.. toctree::
24+
:maxdepth: 2
25+
:caption: Contents:
26+
27+
existing_file1
28+
existing_file2
29+
quic_file_name # Add the new file here (without .rst extension)

libp2p/transport/quic/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
"""
2+
QUIC transport implementation for libp2p.
3+
4+
This module provides QUIC transport functionality for libp2p, enabling
5+
high-performance, secure communication between peers using the QUIC protocol.
6+
"""
7+
18
from libp2p.transport.quic.transport import (
29
Libp2pQuicProtocol,
310
QuicTransport,
411
)
512

613
__all__ = [
714
"QuicTransport",
8-
"QuicProtocol",
9-
"QuicRawConnection",
10-
"QuicError",
11-
"QuicStreamError",
12-
"QuicConnectionError",
13-
"QuicProtocolError",
1415
"Libp2pQuicProtocol",
1516
]

tests/transport/quic/test_interop.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import subprocess
2+
from typing import (
3+
Optional,
4+
)
5+
6+
import pytest
7+
import multiaddr
8+
9+
from libp2p.transport.quic.transport import (
10+
QuicTransport,
11+
)
12+
13+
14+
class ExternalLibp2pNode:
15+
"""Helper class to run external libp2p nodes for interop testing."""
16+
17+
def __init__(self, implementation: str):
18+
"""
19+
Initialize external node runner.
20+
implementation: One of 'go', 'js'
21+
"""
22+
self.implementation = implementation
23+
self.process: Optional[subprocess.Popen] = None
24+
self.multiaddr: Optional[multiaddr.Multiaddr] = None
25+
26+
async def start(self) -> multiaddr.Multiaddr:
27+
"""Start the external node and return its multiaddr."""
28+
if self.implementation == "go":
29+
cmd = ["go", "run", "./cmd/ping/main.go"]
30+
elif self.implementation == "js":
31+
cmd = ["node", "./examples/ping/index.js"]
32+
else:
33+
raise ValueError(f"Unknown implementation: {self.implementation}")
34+
35+
# Start process and wait for it to output its multiaddr
36+
self.process = subprocess.Popen(
37+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
38+
)
39+
40+
# Wait for multiaddr in output
41+
while True:
42+
line = self.process.stdout.readline()
43+
if "Listening on:" in line:
44+
self.multiaddr = multiaddr.Multiaddr(
45+
line.split("Listening on:")[1].strip()
46+
)
47+
break
48+
49+
# Check if process died
50+
if self.process.poll() is not None:
51+
raise RuntimeError(
52+
f"External node failed to start: {self.process.stderr.read()}"
53+
)
54+
55+
return self.multiaddr
56+
57+
async def stop(self):
58+
"""Stop the external node."""
59+
if self.process:
60+
self.process.terminate()
61+
try:
62+
self.process.wait(timeout=5)
63+
except subprocess.TimeoutExpired:
64+
self.process.kill()
65+
self.process = None
66+
self.multiaddr = None
67+
68+
69+
@pytest.mark.interop
70+
@pytest.mark.asyncio
71+
async def test_quic_go_interop():
72+
"""Test QUIC interoperability with go-libp2p."""
73+
# Start go-libp2p node
74+
go_node = ExternalLibp2pNode("go")
75+
go_addr = await go_node.start()
76+
77+
try:
78+
# Create py-libp2p client
79+
client = QuicTransport()
80+
81+
# Connect to go node
82+
protocol, peer_info = await client.dial(go_addr)
83+
84+
# Test data transfer
85+
stream = await protocol.open_stream()
86+
test_data = b"Hello from Python!"
87+
88+
await stream.write(test_data)
89+
response = await stream.read()
90+
91+
assert response == test_data
92+
93+
await stream.close()
94+
await client.close()
95+
96+
finally:
97+
await go_node.stop()
98+
99+
100+
@pytest.mark.interop
101+
@pytest.mark.asyncio
102+
async def test_quic_js_interop():
103+
"""Test QUIC interoperability with js-libp2p."""
104+
# Start js-libp2p node
105+
js_node = ExternalLibp2pNode("js")
106+
js_addr = await js_node.start()
107+
108+
try:
109+
# Create py-libp2p client
110+
client = QuicTransport()
111+
112+
# Connect to js node
113+
protocol, peer_info = await client.dial(js_addr)
114+
115+
# Test data transfer
116+
stream = await protocol.open_stream()
117+
test_data = b"Hello from Python!"
118+
119+
await stream.write(test_data)
120+
response = await stream.read()
121+
122+
assert response == test_data
123+
124+
await stream.close()
125+
await client.close()
126+
127+
finally:
128+
await js_node.stop()
129+
130+
131+
@pytest.mark.interop
132+
@pytest.mark.asyncio
133+
async def test_quic_py_server_interop():
134+
"""Test other libp2p implementations connecting to py-libp2p QUIC server."""
135+
# Start py-libp2p server
136+
server = QuicTransport(host="127.0.0.1", port=0)
137+
await server.listen()
138+
139+
multiaddr.Multiaddr(f"/ip4/127.0.0.1/udp/{server.port}/quic")
140+
141+
# Test with go client
142+
go_node = ExternalLibp2pNode("go")
143+
try:
144+
await go_node.start()
145+
# Connection test logic here
146+
finally:
147+
await go_node.stop()
148+
149+
# Test with js client
150+
js_node = ExternalLibp2pNode("js")
151+
try:
152+
await js_node.start()
153+
# Connection test logic here
154+
finally:
155+
await js_node.stop()
156+
157+
await server.close()

0 commit comments

Comments
 (0)