Skip to main content

Module delta

Module delta 

Source
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.
OfferPage
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_CAP addresses) 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 assets to the ones receiver is missing: missing_from(receiver, ours) over their head_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_pages would 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. None for an asset with no provenance, which no offer can name.
missing_from
The addresses local is missing relative to remote — the pull set the behind-device requests. This is remote \ 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 count addresses 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.