Skip to content

hole-punch: add Python impl (v0.5)#45

Open
parth-soni07 wants to merge 6 commits intolibp2p:masterfrom
parth-soni07:hole-punch-python-interop
Open

hole-punch: add Python impl (v0.5)#45
parth-soni07 wants to merge 6 commits intolibp2p:masterfrom
parth-soni07:hole-punch-python-interop

Conversation

@parth-soni07
Copy link

@parth-soni07 parth-soni07 commented Feb 26, 2026

PR: Python hole-punch implementation

Summary

Adds a Python (py-libp2p v0.5) implementation for the hole-punch test harness and fixes interoperability so that py×py and py×rust (Python dialer, Rust listener) tests pass with both Rust and Python relays. Scope is limited to Python-related tests; Rust-only failures are out of scope.

Test results (full 32-test matrix)

Count
Passed 9
Failed 23

Passing (9)

  • Python-related (8):
    • py×py (4): tcp/ws × [Rust relay, Python relay] — all pass
    • py×rust (4): tcp/ws × [Rust relay, Python relay] — all pass
  • Rust-only (1): rust×rust (tcp, tls, mplex) [Rust relay]

Failing (23)

  • Step 2 – in scope (4): rust×py (Rust dialer, Python listener) — tcp/ws × both relays
  • Rust-only – out of scope (19): rust×rust (9), rust×py quic/webrtc (2), and other Rust-only combinations

Changes

New: Python implementation (hole-punch/images/python/v0.5/)

  • peer.py – Python peer (listener/dialer) with:
    • Rust relay support: varint-framed HOP/STOP, protocol IDs 0.2.0/hop and 0.2.0/stop, _dial_rust_relay, _handle_rust_stop_stream
    • WebSocket transport fix: listen_addrs=[listen_addr] in new_host() so WS is used for /ws addresses
    • Circuit address in peerstore only when using Rust relay (avoids deadlock with Python relay)
  • relay.py – Python relay with Rust compatibility:
    • Varint encode/decode, handlers for 0.2.0/hop and 0.2.0/stop
    • Custom HOP handler that processes RESERVE then CONNECT on the same stream and routes Python dialer → Rust listener via _open_rust_stop / _handle_py_connect_to_rust
  • Dockerfiles, run scripts, requirements for peer and relay images

Rust

  • relay.rsswarm.add_external_address(address) after listen so RESERVE OK includes the address (avoids NoAddressesInReservation for clients).
  • peer.rs – Listener only:
    • Break when my_observed_addr.is_some() (do not require Identify::Sent) so listener proceeds with Python relay
    • Publish listener_peer_id to Redis after 2s delay (Python relay wire format does not emit ReservationReqAccepted the same way)

Harness / config

  • images.yaml – Register Python implementation and relay.
  • generate-tests.sh / run-single-test.sh – Wiring for Python images and test matrix.

@parth-soni07
Copy link
Author

ccing @acul71 @seetadev @sumanjeet0012

currently working on the rust×py (Rust dialer, Python listener) — tcp/ws × both relays to fix the failing tests there

@dhuseby
Copy link
Contributor

dhuseby commented Feb 27, 2026

@parth-soni07 I just fixed the rust-v0.56 hole punch tests in #48

One of the bugs I discovered was a problem in the iptables configuration in the linux NAT/routers. So your tests won't work until #48 lands and you merge it into this branch.

@dhuseby
Copy link
Contributor

dhuseby commented Feb 27, 2026

BTW, websockets and webrtc-direct connections cannot hole-punch due to protocol incompatibilities. When you run your tests use --transport-ignore 'ws|webrtc-direct'

@parth-soni07
Copy link
Author

@parth-soni07 I just fixed the rust-v0.56 hole punch tests in #48

One of the bugs I discovered was a problem in the iptables configuration in the linux NAT/routers. So your tests won't work until #48 lands and you merge it into this branch.

ohh, yes i think this explains why even if the DCUtR handshake completes correctly between the Python listener and Rust dialer, the actual hole-punch would fail. Meanwhile till #48 lands, I'll have a look at the changes you made in it for my sake of understanding.

@parth-soni07
Copy link
Author

BTW, websockets and webrtc-direct connections cannot hole-punch due to protocol incompatibilities. When you run your tests use --transport-ignore 'ws|webrtc-direct'

Sure sure, thanks @dhuseby!!

@dhuseby
Copy link
Contributor

dhuseby commented Mar 9, 2026

@parth-soni07 it looks like you need to merge master into your branch and push again.

@parth-soni07
Copy link
Author

@parth-soni07 it looks like you need to merge master into your branch and push again.

ohh, yesyes, DONE!!, thanks @dhuseby!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants