Expand description
Establishing the channel: mutually-authenticated TLS 1.3 with an application-layer hybrid identity check.
A peer connection is a framed request/response exchange over a mutually-authenticated TLS 1.3 channel with no CA — the device keys are the trust anchor. TLS 1.3 has no ML-DSA certificate path, so the split the peering doc mandates is honored exactly:
- Classical, at the TLS layer. Each side presents a self-signed leaf ([
rcgen]) and the handshake proves possession of its classical private key. The certificates carry no trust of their own — the accept-any verifiers below deliberately accept every well-formed peer cert, because trust is decided one layer up. - Hybrid, above the channel. Once the handshake completes, each side derives the RFC 5705
TLS exporter keying material — a value cryptographically bound to this TLS session —
and signs it with its hybrid device key. The peer verifies that signature under the
key published for the claimed
device_idin the shared, IK-signed device directory. A MITM that re-terminated TLS would export different material and could not forge the victim’s hybrid signature over it, so the hybrid identity is bound to the channel. The directory is the trust anchor: a device not in it — revoked, or a foreign user entirely — cannot pass this check, and it runs before any payload byte.
Around that core the channel enforces the rest of the peering trust model:
- Version window. Each hello advertises a
[Min, Max]peering-protocol window and the pair speaks the highest common version; only disjoint windows end the connection, with a typedPeeringError::VersionDisjointnaming which device must update. - Directory anti-rollback. The highest
directory_versionthis device has verified is persisted behindDirectoryVersions; a pinned directory below it is refused (a stale directory cannot readmit a revoked device), and so is a peer presenting a lower version. - Handshake rate limit.
acceptadmits a source address only through aHandshakeLimiter, so the LAN cannot probe a device for membership. - Artifact secret. A second exporter label yields the per-session
ArtifactSecretthat seals a sync artifact: fresh per session, never stored, never a user passphrase. - Lower Effort marking. The channel carries bulk bytes (hand-offs, sync artifacts), so
both sides mark the socket with the Lower Effort DSCP before the handshake, best effort
(
crate::net::mark_lower_effort).
§After the handshake
accept and connect keep the verified TLS stream and return it as a PeerChannel,
bound to the VerifiedPeer the hybrid check proved. There is no other path to a payload
byte: nothing is ever sent outside the verified TLS session, and a failed check returns no
channel at all.
Over it the pair speaks small framed messages (Message): a one-byte tag, a big-endian
u32 length, and the payload — JSON for a control frame, raw bytes for a data frame. Every
length is checked against its ceiling before a byte of the payload is read
(MAX_FRAME, MAX_DATA_FRAME, MAX_RANGE), and every read and write is bounded in
time, so a peer can neither make this device allocate without bound nor hold it forever.
From OFFER_EXCHANGE_PROTOCOL the pulling side opens with its offer
(PeerClient::open_offering, read by PeerChannel::receive_offer): the padded, capped
offer pages of what it holds, or a frame saying it offers nothing. A pair
below that version skips the opening, and the serving side lists what it would have offered
without one.
One side serves (serve): it lists the artifacts it offers (Offering), then
answers ranged pulls of exactly those and takes acknowledgements, authorizing each
request against the trust its TrustSource pins now (PeerSession::authorize), so a
peer revoked mid-session is refused at its next request. The other side pulls
(PeerClient): the transfer layer drives it through the shared resumable ranged fetch
(super::pull_over_channel), which verifies the reassembled bytes against their content
address. Every check runs against the identity the handshake verified
(PeerChannel::peer), never against a device id a frame claims.
Structs§
- Artifact
Secret - The 256-bit secret that seals a peering sync artifact, derived from the channel’s TLS exporter
under its own peering label. Fresh per session, never stored, never a user passphrase; its
Debugnever prints the bytes. - Local
Peer - What this device brings to a handshake: who it is, the key it proves that with, the trust it pins, and where it keeps the highest directory version it has verified.
- Offered
- One artifact a serving peer offers: its content address and length. Both are the server’s claims until the pulled bytes hash to the address.
- Offering
- The artifacts one serving session offers, each under the content address this device computed over its bytes.
- Peer
Channel - An established, verified peering channel: the TLS 1.3 stream the handshake completed, bound to the peer whose hybrid identity it verified. Every frame after the handshake travels inside this TLS session and nowhere else.
- Peer
Client - The pulling side of a verified channel: it reads the serving peer’s listing, then makes
requests one at a time. Its requests take
&self, so it can back aBlobSource(super::ChannelBlobSource). - Peer
Hello - The handshake hello each side sends over the encrypted channel: who it claims to be, the peering protocol window it speaks, the directory version it pins, and a hybrid signature over the channel-binding exporter material.
- Pinned
Trust - The trust a device pins to authenticate its peers: the shared account’s User IK and the
IK-signed
DeviceDirectory. Both same-user devices pin the same directory; a foreign device is simply absent from it, and a foreign directory fails to verify under our IK. - Range
Failure - A ranged pull that failed, with the bytes that arrived before it did, so a resumed pull starts after them.
- Serve
Report - What a serving session did.
- Served
Range - One ranged answer a serving session sent.
- Verified
Peer - A peer whose hybrid identity was verified over the established channel.
- Version
Window - A device’s supported peering-protocol window,
[min, max], bothYYYY-MM-DD.
Enums§
- Handshake
Role - Which end of the channel a hello was sent from. The role is part of what the hybrid proof signs, so a hello one end sent never verifies as the other end’s: a listener cannot reflect a dialer’s own hello back at it.
- Message
- The control messages the channel carries after the handshake. From
OFFER_EXCHANGE_PROTOCOLthe pulling side opens withOffer; the serving side then sendsListing; the pulling side then sends requests, each answered before the next is sent. - Update
Device - Which device must update for two disjoint windows to meet.
Constants§
- DEFAULT_
IO_ TIMEOUT - The default bound on every frame read and write after the handshake
(
PeerChannel::with_io_timeout). - HANDSHAKE_
TIMEOUT - The bound on the whole handshake: TLS, both hellos and the hybrid check. A peer that stalls it is dropped.
- LISTING_
BUILD_ ALLOWANCE - How long a
PeerClientthat sent an opening waits for the listing: the serving side cuts and seals its artifact once it has read the opening (an offer, or that the receiver offers nothing) and only then lists, which can take far longer than one frame’s I/O timeout. Added to that timeout. - MAX_
ARTIFACT_ LEN - The largest artifact an
Offeringlists and aPeerClientpulls. - MAX_
DATA_ FRAME - The largest data frame. A ranged answer is cut into frames of at most this many bytes.
- MAX_
FRAME - Frame ceiling for the handshake hello (a
device_id, a protocol string, and a hybrid signature) and for every control frame after it. Bounds a malicious length prefix. - MAX_
LISTING - The most artifacts one
Offeringlists; it keeps a listing withinMAX_FRAME. - MAX_
RANGE - The most bytes one ranged request is answered with, whatever it asked for.
- MIN_
PERSIST_ RATE - The slowest rate, in bytes per second, at which a serving session expects its peer to verify
and durably persist an artifact it pulled. While an offered artifact is unacknowledged, the
session waits for the peer’s next request for the channel’s I/O timeout plus the largest such
artifact’s length at this rate (
serve), so a large hand-off on slow storage is still acknowledged over the channel instead of timing out before its acknowledgement arrives. - MIN_
PULL_ RATE - The slowest rate, in bytes per second, at which a
PeerClientkeeps pulling a ranged answer. Each answer oflenbytes must arrive whole within the channel’s I/O timeout pluslendivided by this rate, so a peer that trickles frames just inside the per-frame timeout cannot hold the pulling side indefinitely. - OFFER_
EXCHANGE_ PROTOCOL - The peering protocol version that added the opening offer (
Message::Offer): on a channel negotiated at or above it, the pulling side opens with its offer (or says it offers nothing) before the serving side lists, so a sync artifact is cut to what the receiver is missing. A pair that negotiates below it exchanges no opening, and the serving side lists what it would have offered without one. The addition is additive: either version speaks the rest of the exchange unchanged. - PEERING_
PROTOCOL - The newest peering transport protocol version this build speaks — the top of its
VersionWindow. Date-based (YYYY-MM-DD), it shares the date grammar with the client-server protocol but is its own version space: peering values compare only against peering values, and the transport revs independently of the server protocol. - PEERING_
PROTOCOL_ MIN - The oldest peering transport protocol version this build still speaks — the bottom of its
VersionWindow.2026-10-23added the framed exchange after the hello (Message); a peer older than that closes the channel after its hello and carries no payload, so it is outside the window and the pair is told which device to update.
Functions§
- accept
- Server side of the peering handshake. Admits the source address through
limiter(refusing withPeeringError::RateLimitedbefore any TLS byte), completes a real mutual TLS 1.3 handshake overtcp, derives the channel-binding exporter, exchanges hellos (read-then-write, so the pair never deadlocks), and runs theverify_hellocheck, all withinHANDSHAKE_TIMEOUT. Returns the verified channel or the specific rejection — a wrong/revoked/foreign/stale peer fails the whole handshake before any payload, and no channel exists to send one over. - connect
- Client side of the peering handshake. The dialing device connects, drives the TLS 1.3
handshake to completion, derives the same exporters, exchanges hellos (write-then-read), and
runs the hybrid check, all within
HANDSHAKE_TIMEOUT. Seeacceptfor the security contract. - serve
- Serve
offeringto the channel’s verified peer until it says it is done. - verify_
hello - The application-layer hybrid check — the whole security of the channel. Run before any payload byte against the locally-pinned trust. In order: