Skip to content

Commit f0b9017

Browse files
committed
py<->rust PING INTEROP successfull
1 parent b5b1375 commit f0b9017

File tree

8 files changed

+197
-146
lines changed

8 files changed

+197
-146
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
]
291291

292292
# Prevent autodoc from trying to import module from tests.factories
293-
autodoc_mock_imports = ["tests.factories"]
293+
autodoc_mock_imports = ["tests.factories", "redis"]
294294

295295
# Documents to append as an appendix to all manuals.
296296
# texinfo_appendices = []

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The Python implementation of the libp2p networking stack
1818

1919
Examples <examples>
2020
API <libp2p>
21+
Interop <interop>
2122

2223
.. toctree::
2324
:maxdepth: 1

docs/interop.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
interop package
2+
===============
3+
4+
Submodules
5+
----------
6+
7+
interop.arch module
8+
-------------------
9+
10+
.. automodule:: interop.arch
11+
:members:
12+
:show-inheritance:
13+
:undoc-members:
14+
15+
interop.lib module
16+
------------------
17+
18+
.. automodule:: interop.lib
19+
:members:
20+
:show-inheritance:
21+
:undoc-members:
22+
23+
Module contents
24+
---------------
25+
26+
.. automodule:: interop
27+
:members:
28+
:show-inheritance:
29+
:undoc-members:

examples/ping/ping.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import logging
23

34
import multiaddr
45
import trio
@@ -55,8 +56,8 @@ async def send_ping(stream: INetStream) -> None:
5556

5657

5758
async def run(port: int, destination: str) -> None:
58-
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
59-
host = new_host(listen_addrs=[listen_addr])
59+
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")
60+
host = new_host()
6061

6162
async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
6263
if not destination:
@@ -103,8 +104,20 @@ def main() -> None:
103104
type=str,
104105
help=f"destination multiaddr string, e.g. {example_maddr}",
105106
)
107+
parser.add_argument(
108+
"-v", "--verbose", action="store_true", help="enable verbose logging"
109+
)
110+
106111
args = parser.parse_args()
107112

113+
if args.verbose:
114+
# Enable even more detailed logging
115+
logging.getLogger("libp2p").setLevel(logging.DEBUG)
116+
logging.getLogger("libp2p.network").setLevel(logging.DEBUG)
117+
logging.getLogger("libp2p.transport").setLevel(logging.DEBUG)
118+
logging.getLogger("libp2p.security").setLevel(logging.DEBUG)
119+
logging.getLogger("libp2p.stream_muxer").setLevel(logging.DEBUG)
120+
108121
try:
109122
trio.run(run, *(args.port, args.destination))
110123
except KeyboardInterrupt:

libp2p/stream_muxer/yamux/yamux.py

Lines changed: 139 additions & 140 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies = [
3131
"trio-typing>=0.0.4",
3232
"trio>=0.26.0",
3333
"fastecdsa==2.3.2; sys_platform != 'win32'",
34+
"cryptography>=42.0.0; sys_platform == 'win32'", # Alternative for Windows
3435
"zeroconf (>=0.147.0,<0.148.0)",
3536
]
3637
classifiers = [
@@ -79,6 +80,7 @@ dev = [
7980
"factory-boy>=2.12.0,<3.0.0",
8081
"ruff>=0.11.10",
8182
"pyrefly (>=0.17.1,<0.18.0)",
83+
"pytest-timeout"
8284
]
8385
docs = [
8486
"sphinx>=6.0.0",
@@ -93,6 +95,7 @@ test = [
9395
"pytest-xdist>=2.4.0",
9496
"pytest-trio>=0.5.2",
9597
"factory-boy>=2.12.0,<3.0.0",
98+
"pytest-timeout",
9699
]
97100

98101
[tool.setuptools]

tests/core/stream_muxer/test_yamux.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ async def read(self, n: int | None = None) -> bytes:
5151
data = await self.receive_stream.receive_some(n)
5252
logging.debug(f"Read {len(data)} bytes")
5353
return data
54+
# Raise IncompleteReadError on timeout to simulate connection closed
55+
logging.debug("Read timed out after 2 seconds, raising IncompleteReadError")
56+
from libp2p.io.exceptions import IncompleteReadError
57+
58+
raise IncompleteReadError({"requested_count": n, "received_count": 0})
5459

5560
async def close(self) -> None:
5661
logging.debug("Closing stream")

tox.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ deps=
6363
wheel
6464
build[virtualenv]
6565
allowlist_externals=
66-
bash.exe
66+
cmd.exe
6767
commands=
6868
python --version
6969
python -m pip install --upgrade pip
70-
bash.exe -c "rm -rf build dist"
70+
cmd.exe /c "if exist build rd /s /q build"
71+
cmd.exe /c "if exist dist rd /s /q dist"
7172
python -m build
72-
bash.exe -c 'python -m pip install --upgrade "$(ls dist/libp2p-*-py3-none-any.whl)" --progress-bar off'
73+
cmd.exe /c "for %i in (dist\libp2p-*-py3-none-any.whl) do python -m pip install --upgrade "%i" --progress-bar off"
7374
python -c "import libp2p"
7475
skip_install=true
7576

0 commit comments

Comments
 (0)