Companion to FLOW-DESIGN.md, which records why this
protocol looks the way it does (transport choice, encoding choice, BYON,
no-relay). This document is the what: the normative contract two OpenLogi
agents implement. The authoritative message schema is
flow.v1.proto; this file
defines everything protobuf cannot express β framing, stream binding, state
machines, canonical byte forms, timeouts, and the evolution rules.
The schema lives under crates/openlogi-flow/proto/ so code generation and
the wire contract cannot drift apart. This normative specification remains in
docs/; edits to either are reviewed against the evolution rules at the
bottom.
- QUIC via
quinn+rustls, mutual authentication with pinned Ed25519 keys (design doc Β§Transport). ALPN:olf/1. The ALPN versions the envelope, not the message set β it changes only if the frame layout itself ever has to change, which the design intends never to happen. - One connection per peer pair. Either side may initiate; if two connections
race (simultaneous dial), the side with the lexicographically smaller
public key closes its outgoing connection and keeps the incoming one.
A dialer may race the TLS handshake to several addresses of one peer, but
sends
Helloon only the first that authenticates and closes the others, so the peer completes the same connection the dialer keeps. - Control stream: the connection initiator opens one bidirectional
stream immediately; each side writes exactly one
Helloframe and reads the peer's. This stream carries nothing else and stays open for the connection's lifetime (its closure is equivalent to connection close). - RPC: one bidirectional stream per request β open, write one request
frame, read one response, close. The stream is the correlation and the
cancellation token (reset = cancelled). Responses are the request's paired
response kind or
Error. - Notifications: one unidirectional stream per notification, one frame, FIN. QUIC makes short streams cheap; one-shot streams avoid inventing an ordering relationship between unrelated notices.
- Bulk data: rides the same bidirectional stream as the fetch that asked
for it (
ClipboardDatahead,Chunk*,ChunkEnd). - Datagrams:
Ping/Pongonly (RTT + application liveness; QUIC keepalive only proves the transport). Datagram loss is acceptable by definition; anything that must arrive rides a stream.
| Frame family | Carried on |
|---|---|
Hello, HelloReject |
control stream |
PairStartβPrompted, PairRevealβRevealed, PairConfirmβOutcome, GetPeerInfoβPeerInfo, HandoffRequestβAccept/Reject, ClipboardFetch/FileFetchβClipboardData+Chunk*+ChunkEnd |
one bi-stream per request |
PairAbort, AnnounceDevices, PeerState, HandoffResult, HandoffCancel, ClipboardAnnounce |
one uni-stream each |
Ping, Pong |
datagrams |
Error |
response position on any bi-stream |
Every stream payload and datagram is a sequence of frames:
ββββββββββββ¬ββββββββββββ¬βββββββββββ¬ββββββββββββββββββ
β kind u16 β flags u16 β len u32 β payload (len B) β
β LE β LE, =0 β LE β protobuf bytes β
ββββββββββββ΄ββββββββββββ΄βββββββββββ΄ββββββββββββββββββ
kind: aFrameKindvalue. The all-zero header is invalid by construction (Hellois 0x0001), so a zeroed buffer can never parse as a meaningful frame.flags: reserved, must be sent as 0. A receiver seeing unknown flag bits must not guess: drop the frame if it is a notification, answerError UNSUPPORTED_FLAGSif it is a request. (Future use: e.g. payload compression β a capability would gate sending it, the flag would mark the frame.)len: payload byte length. Caps: 1 MiB general, 64 KiB forChunk. Oversized: close the offending stream, answerError TOO_LARGEwhere a response is expected. The caps bound memory per frame; bulk payloads of any size are sequences of capped chunks.- Unknown
kind: on a uni-stream, skiplenbytes and ignore (this is what makes new notifications backward-deployable); as a request on a bi-stream, answerError UNSUPPORTED_KIND. Decode never desyncs: the envelope always says how much to skip. - Payloads are protobuf (
openlogi.flow.v1); a payload that fails to decode as its kind's message isError INVALID/ frame-drop by the same notification-vs-request rule.
dial βββΊ TLS (pinned-key verifier) βββΊ Hello exchange βββΊ trusted session
β β
β unknown key β version disjoint / key mismatch
βΌ βΌ
untrusted session HelloReject + close
(pairing family only)
- TLS: the verifier accepts a pinned peer key β session starts trusted;
accepts an unknown key only while pairing mode is active β session starts
untrusted. Only one untrusted connection at a time holds the pairing
slot. It claims the slot after the
Helloexchange succeeds and releases it when the connection closes, so a failed or abandoned dial never locks pairing out. Any other unknown peer is closed with application code 3 (pairing busy). - Both sides send
Hello.agreed = min(proto_max_A, proto_max_B); ifagreed < max(proto_min_A, proto_min_B)βHelloReject VERSION_DISJOINTand close (the GUI names which side is stale).Hello.public_keymust equal the TLS identity β elseHelloReject KEY_MISMATCH.Hello.session_nonceis 16 bytes from the OS CSPRNG, drawn fresh for every connection and never reused. It makes each connection'sHellotranscript unique, and pairing binds to that transcript. - On an untrusted session, only link-family and pairing-family frames
are legal; anything else is answered
Error NOT_PAIREDand ignored. - On becoming trusted (pinned key, or pairing just completed): each side
sends
AnnounceDevicesandPeerStateunsolicited. Reconnect repeats them β every state notification is the whole current state with a revision, so a lost notice heals on the next.
Send-gating: after Hello, a peer never sends a frame kind, field, or
semantic introduced later than agreed, and never sends a
capability-gated family the peer did not list. Decode tolerance (unknown
kinds/fields skipped) is the safety net, gating is the contract.
Trust ceremony (design doc Β§Transport chose pinned keys; this is how pins are created). Runs on an untrusted session. The ceremony is commit-then-reveal: A commits to its nonce before it sees B's nonce, and B picks its nonce before A reveals. Neither side can pick its nonce after it sees the other one.
A (initiator) B (responder)
β ββ PairStart{commit(nA)} βββββββΊ β B shows who is pairing, no code yet
β ββ PairPrompted{timeout, nB} βββ β B's deadline starts
β ββ PairReveal{nA} ββββββββββββββΊ β B checks nA against the commitment
β ββ PairRevealed ββββββββββββββββ β both sides show the code now
β (users compare the 6-digit code on both screens)
β ββββ PairConfirm βββββββββββββββΊ β
β ββββ PairOutcome{PENDING_LOCAL} ββ (B's user hasn't confirmed yet)
β ββββ PairConfirm βββββββββββββββ β (B confirms; roles are symmetric)
β ββββ PairOutcome{PAIRED} βββββββΊ β both persist the peer key; session
β β becomes trusted in place
- Nonces:
nAandnBare 16 bytes each from the OS CSPRNG, drawn fresh for each ceremony. They are separate from theHellosession nonces. - Commitment:
PairStart.nonce_commitment = SHA-256("openlogi-flow-pair-commit-v1" β pkA β pkB β nA)(32 bytes), withpkA= initiator key andpkB= responder key. B answers a commitment of any other length withError INVALID. IfPairReveal.noncedoes not open the commitment, B answersError INVALIDand aborts with reasonCODE_MISMATCH. - A side may show the code only after the reveal step: B after the
commitment check, A after
PairRevealed. APairConfirmthat reaches B before its commitment check is a protocol error. B'sPairConfirmmay reach A beforePairRevealed, because the two travel on different streams: A keeps it and answersPENDING_LOCAL, and still shows the code and confirms only afterPairRevealed. - Completion condition: a side considers pairing complete when it has both
sent and received a
PairConfirm; it persists the peer's key and answers/expectsPairOutcome{PAIRED}. - Code derivation (SAS): both sides compute
HKDF-SHA256(salt = hA β hB, ikm = pkA β pkB β nA β nB, info = "openlogi-flow-sas-v1"), take the first 4 output bytes as a big-endian integer,mod 1_000_000, and render the result as 6 digits.pk= the 32-byte Ed25519 keys,n= the pairing nonces, andh= SHA-256 of each side's encodedHellopayload on this connection. Every input is ordered by role (initiator first), never by byte value. - Why this authenticates: a man-in-the-middle terminates two distinct sessions. In each session it must fix its own nonce before it learns the honest peer's nonce. It therefore cannot steer the two codes to match; each attempt succeeds with probability 10β»βΆ. The human comparison is the authentication.
- Fixed test vector (keys
00..1f/20..3f, nonces00..0f/10..1f,h= SHA-256 of"initiator hello"/"responder hello"): commitment8d89a09a832cc87779e32053024ef40dbe98bacaacefb05ff934eda83902b31f, code469603. - Abort paths:
PairAbort{USER_CANCELLED | CODE_MISMATCH}from either side;PairOutcome{TIMEOUT}afterPairPrompted.timeout_ms(default 120 s), andPairAbort{TIMEOUT}from a side whose deadline passed, so the other side does not wait out its own;PairOutcome{REJECTED}if a user declines. All abort paths discard the pairing nonces and the code; retry starts a fresh connection with fresh nonces.
Two DeviceIdentity values denote the same physical device iff their
ids sets intersect on any entry (kind + canonical bytes equal). Canonical
byte forms:
IdentifierKind |
canonical value |
|---|---|
SERIAL |
the serial string's UTF-8 bytes, no padding/case folding |
UNIT_ID |
HID++ 0x0003 unitId, 4 bytes big-endian |
BLUETOOTH_ADDRESS |
6 bytes, transmission order (MSB first) |
A peer announces every identifier it can obtain for a device; correlation
strengthens as transports contribute more identifiers. Bluetooth-direct
devices may expose only UNIT_ID + BLUETOOTH_ADDRESS; receiver-paired
devices typically expose SERIAL + UNIT_ID. name, category, models
are presentation/diagnostics and never correlate.
State machine, sender view (receiver mirrors it):
IDLE ββedge triggerβββΊ REQUESTED ββAcceptβββΊ SWITCHING ββ0x41 at receiverβββΊ DONE
β β β²
β Reject/timeout β β HandoffResult
βΌ β β (uni, by transfer_id)
IDLE βββ set_current_host failed:
send HandoffCancel{SWITCH_FAILED}
- The sender never issues
set_current_hostbeforeHandoffAccept. After issuing it the sender is blind to the device (the radio has left); everything after that point is the receiver's to report. - The receiver arms an arrival watch on
Accept(HID++ 1.0 connection notification sub-ID 0x41, or the equivalent arrival evidence for Bluetooth-direct β open question in the design doc) and reportsHandoffResultper device:ARRIVED,PARTIAL,TIMEOUT. transfer_idis random per attempt and is the idempotency key: a duplicateHandoffRequest(sender retry after a lost response) is answered from the existing transfer's state, never double-armed.ALREADY_PENDINGrejects a different transfer while one is armed.- Multiple devices (keyboard-follow) ride one request; per-device outcomes
come back in
HandoffResult.arrivals. Partial arrival is reported, not rolled back β the devices that moved are usable, the UI says what stalled. - Defaults:
arm_timeout_ms3000; sender give-up = accept'sarm_timeout_ms+ 2000 of network slack. A sender that gives up late simply logs a staleHandoffResult. EntryPoint.sideis pre-translated to the receiver's frame by the sender's layout config;tis normalized 0..1 along the sender's exiting edge; the receiver maps proportionally onto its own exposed edge segments (per-display segments, not a union bounding rect) and clamps to the nearest valid point.
On a mouse with native scroll inversion, Windows can deliver wheel input as
soon as the radio reconnects. OpenLogi restores the receiving host's saved
direction through HID++ 0x2121. If you scroll immediately, the first
notch can go the opposite way before the mouse accepts that setting.
Flow keeps the setting per device and allows wheel input during this interval.
The Windows low-level mouse hook reports a wheel delta without a source mouse
identifier. Windows mouse hook event fields
For diagnosis, compare the receiving agent's Flow handoff armed timestamp
with the wheel-mode readback. With openlogi_device::write::hires_wheel=debug
enabled, wheel mode written and verified records the applied setting and
wheel mode already set records a matching read. HandoffResult reports
which devices arrived. Settings can finish applying afterward.
Lazy, pull-based: bytes move only on paste. Every target OS supports promised/delayed clipboard rendering (NSPasteboard promises, Windows delayed rendering, X11/Wayland are lazy by construction).
- On local clipboard change:
ClipboardAnnounce{sequence, formats}to every connected trusted peer that listedCLIPBOARD_TEXT.sequenceis a monotonic per-peer generation; announces for stale sequences are ignored, fetches quoting a superseded sequence are answeredError INVALID. - On paste at a peer:
ClipboardFetch{sequence, mime, offset}βClipboardData+Chunk* +ChunkEnd.offsetresumes an interrupted transfer;ChunkEnd.sha256(when present) covers the assembled bytes from the requested offset. - Files (
CLIPBOARD_FILES): the announce lists mimeapplication/x-openlogi-files; its fetched payload decodes asFileList; each file then streams viaFileFetch{sequence, file_index, offset}with the identical bulk shape.relative_pathmust be relative,/-separated, free of..β the receiver rejects violations and places files under its own download directory.
- Revisions: every state notification (
PeerInfo,AnnounceDevices,PeerState) carries a monotonic per-peerrevision; receivers drop anything older than what they have. Notifications are whole-state, never deltas β loss heals on the next send, reconnect resends current state. - Idempotency:
transfer_iddedupes handoffs;sequenceversions clipboard generations; pairing confirms are idempotent (re-receivedPairConfirmre-answers currentPairOutcome). - Timeouts are receiver-declared where one side waits on the other
(
PairPrompted.timeout_ms,HandoffAccept.arm_timeout_ms) so the two sides never disagree about who gave up first. - Local deadlines bound what a silent peer can hold. They are local
policy, not wire values. Defaults: TLS plus the
Helloexchange must finish in 10 s. Each inbound request or notification must deliver its frame and FIN within 10 s; otherwise the receiver resets the stream with application code 4. At most 16 inbound handshakes run at once; the receiver refuses further dials before TLS starts. - Wall-clock time is diagnostics-only (
sent_at_ms,modified_at_ms); no protocol decision compares clocks across machines. Durations are relative milliseconds. - Path-agnostic (BYON): nothing above assumes LAN β no broadcast, no MTU assumptions beyond QUIC's own, keepalive tolerant of high-RTT links, addresses are hints and identity is only ever the pinned key.
- Three-machine mesh: every exchange is strictly pairwise;
channel_to_meis relative to the announcing peer, so N peers form NΒ·(Nβ1)/2 independent sessions with no shared state.
- The envelope layout and the link family (kinds 0x0001β0x000F,
Hello's existing fields foremost) are frozen forever. New ALPN only if the envelope itself must change β intended never. - protobuf field numbers are never reused or renumbered; removal is
reserved N;.FrameKindvalues are never reused; new kinds go at the end of their family range, new families take a fresh 0x10-aligned range. - Every enum keeps
*_UNSPECIFIED = 0; receiving it (or an unknown value) where a decision is required isError INVALID, never a silent default. - New frame kinds, fields with new semantics, and behavioral changes are
introduced under a version bump (send-gated on
agreed) or under aCapability(send-gated on the peer's list). Purely additive informational fields may ride the existing version β old peers skip them. proto_minrises only as an explicit product decision, never casually.- Every kind and field carries a
since:note in the proto file from v2 onward; v1 is the baseline.