Skip to content

feat: add WhatAmI::Peer transport mode with simultaneous-open handling#8

Open
vlordier wants to merge 14 commits into
eclipse-zenoh:mainfrom
vlordier:feat/peer-transport-mode
Open

feat: add WhatAmI::Peer transport mode with simultaneous-open handling#8
vlordier wants to merge 14 commits into
eclipse-zenoh:mainfrom
vlordier:feat/peer-transport-mode

Conversation

@vlordier
Copy link
Copy Markdown

@vlordier vlordier commented May 7, 2026

Summary

  • Adds WhatAmI::Peer transport mode enabling direct peer-to-peer zenoh sessions without a router
  • Wire-level protocol compliant — WhatAmI is already in InitIdentifier carried by every InitSyn/InitAck
  • Handles simultaneous peer open via ZID comparison: lower ZID wins, higher yields

Changes

Crate What
zenoh-sansio with_whatami() on TransportBuilder, mine_whatami in state variants, simultaneous-open logic in State::poll(), fixed InitAck whatami default
zenoh-nostd with_whatami() on TransportLinkManager, wired through all 4 connect/listen/bridge methods
examples/z_peer.rs New example: two peers pub/sub directly without a router

Test Plan

  • 65 tests pass (58 zenoh-proto + 7 zenoh-sansio including 3 new peer tests)
  • Clippy clean on zenoh-sansio and zenoh-nostd
  • z_peer example compiles with --features std
  • Manual: run two z_peer instances (one LISTEN=1, one connecting) and verify pub/sub

Design Doc

See docs/superpowers/specs/2026-05-07-peer-transport-mode-design.md

- Add whatami field to TransportBuilder with with_whatami() builder
- Thread WhatAmI through InitIdentifier in connect/listen paths
- Add mine_whatami to establishment State variants (WaitingInitSyn,
  WaitingOpenSyn, WaitingInitAck), fix InitAck to use mine_whatami
- Add simultaneous-open handling: lower ZID wins, higher yields
  to acceptor role with InitAck; equal ZIDs error
- Wire whatami through TransportLinkManager to all 4 connect/listen
  bridge methods
- Add 7 sansio transport tests including peer handshake, simultaneous
  connect, and WhatAmI byte-level propagation
- Add z_peer example demonstrating peer-to-peer pub/sub without router
- Add design spec and implementation plan
Copilot AI review requested due to automatic review settings May 7, 2026 21:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a WhatAmI::Peer transport mode to allow direct peer-to-peer zenoh sessions (without a router), including establishment-state handling for simultaneous open using ZID comparison.

Changes:

  • Thread WhatAmI through TransportBuilder / TransportLinkManager and into InitSyn / InitAck identifiers.
  • Add simultaneous-open handling in the transport establishment state machine (WaitingInitAck receiving InitSyn).
  • Add peer-focused tests and a new z_peer example demonstrating direct peer pub/sub.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/lib.rs Exposes ExampleConfig.transports so examples can configure transport mode.
examples/z_peer.rs New example that configures WhatAmI::Peer and runs peer-to-peer pub/sub.
docs/superpowers/specs/2026-05-07-peer-transport-mode-design.md Design doc for peer mode + simultaneous-open behavior.
docs/superpowers/plans/2026-05-07-peer-transport-mode-plan.md Implementation plan/checklist for the feature work.
crates/zenoh-sansio/src/transport.rs Adds whatami to TransportBuilder and encodes it in InitSyn.
crates/zenoh-sansio/src/transport/establishment.rs Carries mine_whatami, fixes InitAck whatami, and implements simultaneous-open logic.
crates/zenoh-sansio/src/tests/transport.rs Adds peer handshake/simultaneous-open tests and validates InitSyn.whatami.
crates/zenoh-nostd/src/lib.rs Re-exports WhatAmI via the session module API surface.
crates/zenoh-nostd/src/io/transport.rs Adds whatami configuration and wires it into all connect/listen paths.
Cargo.toml Registers the new z_peer example target.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/zenoh-sansio/src/transport/establishment.rs Outdated
Comment thread crates/zenoh-sansio/src/transport/establishment.rs Outdated
Comment thread crates/zenoh-sansio/src/tests/transport.rs Outdated
Comment on lines +143 to +148
let mut borrow_mut = socket.borrow_mut();
let to_read = bytes.len().min(borrow_mut.2);
let slice = &borrow_mut.0[borrow_mut.1..(to_read + borrow_mut.1)];
bytes[..slice.len()].copy_from_slice(slice);
borrow_mut.1 += to_read;
Ok(to_read)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

@vlordier vlordier marked this pull request as draft May 7, 2026 21:17
@vlordier vlordier marked this pull request as ready for review May 7, 2026 22:41
@vlordier
Copy link
Copy Markdown
Author

vlordier commented May 8, 2026

All 4 Copilot comments addressed in subsequent commits:

  1. Indentation fixed on InitAck identifier
  2. Removed redundant let _ = mine_whatami
  3. Fixed read shim in peer_handshake test (bounded by remaining bytes)
  4. Fixed read shim in simultaneous_connect test (same fix)

These fixes are in commits 0138a0b, 718db17, 2c0f43f.

vlordier added 5 commits May 8, 2026 12:03
- MeshState: shared state managing multiple peer connections
- MeshEntry: holds a peer's ZID and Driver
- forward(): sends incoming messages to all peers except the sender
- Works with WhatAmI::Peer via TransportLinkManager config
- Alloc-only (BTreeMap), follows existing Broker patterns
Shows two peers exchanging data using WhatAmI::Peer mode.
- Peer A listens, subscribes
- Peer B connects, publishes
- Both use TransportLinkManager.with_whatami(WhatAmI::Peer)
- Demonstrates the peer mesh pattern for drone communication
Verifies 2119 code paths — lower ZID wins, higher ZID yields,
no panics for any legal synchronous-open input.
- Proptest: ZID comparison is deterministic (256 random pairs verified)
- Kani proof: 2119 paths verified — simultaneous-open state machine
- Doc: with_whatami() documented
- 12 tests pass, clippy clean
@vlordier
Copy link
Copy Markdown
Author

vlordier commented May 8, 2026

@copilot review

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