BobbinExchange

class BobbinExchange(seam: Seam, val creel: Creel, scope: CoroutineScope, quilterConfig: QuilterConfig = QuilterConfig())

Lazy-bobbin exchange over a Seam.

What it does. Peers share a GSet<BobbinMeta> manifest that is gossiped eagerly via a Quilter, so every peer knows which bobbins (content-addressed byte blobs) exist across the mesh. The actual bytes are fetched on demand: a peer that lacks a bobbin broadcasts a FetchMessage.Request, suspends until a FetchMessage.Response arrives from a peer that holds the bytes, verifies the content hash, caches the bytes in the local Creel, and returns them.

Single-collection. BobbinExchange takes sole ownership of seam.incoming via the internal MuxSeam (ADR-034). Do not collect seam.incoming elsewhere.

Thread-safety. Shared mutable state (the in-flight request map) is guarded by an explicit kotlinx.atomicfu.locks.ReentrantLock. No suspend calls are made inside the locked section. Correct under a multi-threaded dispatcher.

Exception discipline. Best-effort sends use runCatchingCancellable so that kotlinx.coroutines.CancellationException is never swallowed.

Parameters

seam

The Seam over which the manifest is gossiped and fetch messages travel. BobbinExchange takes sole ownership of Seam.incoming via the internal MuxSeam.

creel

The local content-addressed byte store shared with the caller. The exchange populates it on every successful fetch.

scope

Coroutine scope for all background jobs. Required — no default.

quilterConfig

Tuning for the internal manifest Quilter. In tests pass a short-cadence config with QuilterConfig.expectVirtualTime = true.

See also

Constructors

Link copied to clipboard
constructor(seam: Seam, creel: Creel, scope: CoroutineScope, quilterConfig: QuilterConfig = QuilterConfig())

Properties

Link copied to clipboard
Link copied to clipboard
val manifest: StateFlow<Set<BobbinMeta>>

The converged set of BobbinMeta entries known across the mesh — the union of every peer's advertised bobbins. An entry appears here as soon as the manifest GSet delta propagates; the kernel bytes may not yet be cached locally (that is the lazy part).

Functions

Link copied to clipboard
suspend fun fetch(hash: BobbinHash): ByteArray

Returns the bytes for hash.

Link copied to clipboard
fun put(bytes: ByteArray): BobbinHash

Stores bytes as a raw bobbin and advertises BobbinMeta(hash, variantOf = null) on the gossiped manifest so all peers learn the hash immediately.

Link copied to clipboard
fun putVariant(bytes: ByteArray, variantOf: VariantKey): BobbinHash

Stores bytes as a compiled variant and advertises BobbinMeta(hash, [variantOf]) so peers can discover the compiled-for-target version of the source kernel.