feat: add WhatAmI::Peer transport mode with simultaneous-open handling#8
Open
vlordier wants to merge 14 commits into
Open
feat: add WhatAmI::Peer transport mode with simultaneous-open handling#8vlordier wants to merge 14 commits into
vlordier wants to merge 14 commits into
Conversation
- 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
There was a problem hiding this comment.
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
WhatAmIthroughTransportBuilder/TransportLinkManagerand intoInitSyn/InitAckidentifiers. - Add simultaneous-open handling in the transport establishment state machine (
WaitingInitAckreceivingInitSyn). - Add peer-focused tests and a new
z_peerexample 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 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) |
- Fix indentation on InitAck identifier in establishment.rs - Remove redundant let _ = mine_whatami (unused-warning already suppressed by usage in sibling branch) - Fix read shims in peer tests to compute remaining bytes from borrow_mut.2 - borrow_mut.1 and return Ok(0) when exhausted
Author
|
All 4 Copilot comments addressed in subsequent commits:
|
- 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
Author
|
@copilot review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WhatAmI::Peertransport mode enabling direct peer-to-peer zenoh sessions without a routerWhatAmIis already inInitIdentifiercarried by everyInitSyn/InitAckChanges
zenoh-sansiowith_whatami()onTransportBuilder,mine_whatamiin state variants, simultaneous-open logic inState::poll(), fixedInitAckwhatami defaultzenoh-nostdwith_whatami()onTransportLinkManager, wired through all 4 connect/listen/bridge methodsexamples/z_peer.rsTest Plan
z_peerexample compiles with--features stdz_peerinstances (one LISTEN=1, one connecting) and verify pub/subDesign Doc
See
docs/superpowers/specs/2026-05-07-peer-transport-mode-design.md