feat: connection handshake — Client::connect / Server::serve_handshaked - #8
Merged
Conversation
Before any calls, each end declares { ir_hash, wire_format, framing,
capabilities } and refuses on a mismatch -- catches "one end msgpack, one
end JSON" and two ends built from different schema versions.
- contract::Handshake -- lifetime-free, Copy. wire_format / framing are
carried as name_hash (FNV-1a) of a *name*, not a numeric id: a user's
add-on WireFormat picks a namespaced name and its hash won't collide
with a built-in, no central registry. Fixed 31-byte frame
([magic][ver][ir_hash u64][wire_format u64][framing u64][caps u32]).
Handshake::new(ir_hash, wire_format_name, framing_name, caps) hashes.
- WireFormat::name() -> &'static str (was going to be id() -> u16;
dropped). MsgPack -> "msgpack". contract::FRAMING_DATAGRAM.
- RuntimeError::Handshake (non_exhaustive, so additive).
- Client::connect(transport, format, local) -> Result<Self, _> and
Server::serve_handshaked(transport, local): send ours, read + check the
peer's, then proceed. Client::new / Server::serve are unchanged and
skip it entirely -- "misaligned mode", documented, for legacy peers.
- BufMut::put_u32_le.
tests/handshake_roundtrip.rs: matching handshakes connect + a call goes
through; a schema-hash mismatch is refused before any call (both ends);
misaligned mode skips it. Plus handshake.rs unit tests. All feature
configs green.
Generated code supplies IR_HASH and calls Client::connect -- a follow-up
codegen PR.
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.
Before any calls, each end declares
{ ir_hash, wire_format, framing, capabilities }and refuses on a mismatch — catches "one end MessagePack, one end JSON" and two ends built from different schema versions (§4.6).contract::HandshakeLifetime-free,
Copy.wire_format/framingare carried asname_hash(FNV-1a) of a name, not a numeric id — a user's add-onWireFormatpicks a namespaced name ("com.acme.myformat") and its hash won't collide with a built-in; no central id registry. Fixed 31-byte frame:[magic:2][ver:1][ir_hash:u64][wire_format:u64][framing:u64][caps:u32].Handshake::new(ir_hash, wire_format_name, framing_name, caps)does the hashing.WireFormat::name() -> &'static str(MsgPack→"msgpack");contract::FRAMING_DATAGRAM.RuntimeError::Handshake(the enum is#[non_exhaustive], so additive).The two modes
Client::connect(t, fmt, local) -> Result<Self, _>/Server::serve_handshaked(t, local)checkthe peer's, then proceedClient::new/Server::servecheckrefuses onir_hash/wire_format/framingdisagreement; capability bits may differ.Tests
tests/handshake_roundtrip.rs— matching handshakes connect and a call goes through; a schema-hash mismatch is refused before any call (both ends getRuntimeError::Handshake); misaligned mode skips it. Plushandshake.rsunit tests (encode/decode round-trip,name_hashdeterminism, truncated/foreign rejection). All feature configs green; no new clippy warnings.Next
A codegen PR: the generator emits
IR_HASH(from the frozen IR fingerprint) and a<Proto>Client::connect/<Proto>Dispatcherserve helper that fills in theHandshake.