Expand description
Determining the delta: what each side is missing.
Before building an artifact the two devices must agree on what to move. Peering reuses the sync-cursor model rather than inventing a diff: each side offers the set of addresses it holds and its cursor, and the delta is the complement. “What changed” is already defined by the sync feed — peering borrows that definition wholesale. Because every address names an exact state, dedup is free: the complement already excludes anything the receiver holds.
The addresses a sync offer carries are the head record hashes of the assets a device
holds (record_hash of each chain’s last record): an asset whose head the
receiver already holds is what the complement leaves out, and a metadata edit that keeps the
ciphertext still moves, because it changes the head.
On the wire an offer is split into pages of at most OFFER_PAGE_CAP addresses, and each
page is padded to a size bucket (a power of two of address slots, at least
MIN_OFFER_BUCKET), so the encrypted channel’s record sizes reveal only a coarse bucket of
how much a device holds, and no single request can carry an unbounded offer. A whole offer is
at most MAX_OFFER_PAGES pages.
Structs§
- Offer
- One side’s offer in the delta negotiation: the addresses it currently holds and its sync cursor high-water mark. The cursor is carried for parity with server sync (a peer only offers state it has itself reconciled up to); the set is what the complement is computed over.
- Offer
Page - One decoded offer page: the sender’s cursor and the real addresses it carried.
Constants§
- MAX_
OFFER_ PAGES - The most pages one offer is carried in, so a whole offer (at most
MAX_OFFER_PAGES * OFFER_PAGE_CAPaddresses) is bounded too, not only each page. - MIN_
OFFER_ BUCKET - The smallest size bucket, in address slots, a page is padded to.
- OFFER_
PAGE_ CAP - The most addresses one offer page carries — the per-request cap.
Functions§
- cut_
to_ missing - Cut
assetsto the onesreceiveris missing:missing_from(receiver, ours)over theirhead_addresses. Returns what remains and how many the receiver’s offer excluded. An asset with no head address is kept, since no offer can show the receiver holds it. - decode_
offer_ page - Decode one wire offer page, refusing anything
Offer::encode_pageswould not produce: a size that is not a bucket, a bucket above the cap, a count above the bucket, or non-zero padding. - head_
address - The address an asset is offered under: its chain’s head record hash.
Nonefor an asset with no provenance, which no offer can name. - missing_
from - The addresses
localis missing relative toremote— the pull set the behind-device requests. This isremote \ local: everything the remote holds that we do not, which is exactly the set to transfer (content-addressing makes anything we already hold a no-op, so the complement doubles as dedup). - offer_
bucket - The bucket, in address slots, a page holding
countaddresses is padded to. - symmetric_
difference - The symmetric difference of two offers — every address exactly one side holds. Over two
devices with overlapping-but-distinct content, this is the union of the two one-way pulls
(
(a \ b) ∪ (b \ a)): the total set of assets that must move for the pair to converge.