Package-level declarations

Types

Link copied to clipboard
class ActiveSeamSlot(occupiedMessage: String = "already has an active session")

A self-healing single-active-session slot for a Loom/factory that hosts one live Seam at a time.

Link copied to clipboard
sealed interface CloseReason

Reason a Seam is being closed. Designed as a forward-compatible sealed hierarchy — new variants can be added without breaking existing when exhaustiveness because the common cases are covered.

Link copied to clipboard
data class DeliveryPolicy(val capacity: Int = DEFAULT_CAPACITY, val overflow: Overflow = Overflow.SUSPEND)

How an in-process fabric buffers frames for one receiver: a bounded capacity and an overflow strategy. There is deliberately no UNLIMITED option — unbounded delivery is the defect this type exists to make unrepresentable (#701).

Link copied to clipboard
sealed interface FabricAvailability

Whether a Loom's underlying transport fabric can be attempted on this runtime. A fabric scoped out by target (e.g. WebRTC only present on wasmJs) is simply absent — not Unavailable. Unavailable means present-but-not-usable-now.

Link copied to clipboard

Thrown by a Overflow.FAIL delivery buffer when a frame arrives and the buffer is full.

Link copied to clipboard
class InMemoryLoom(policy: DeliveryPolicy = DeliveryPolicy.Reliable) : Loom

In-memory implementation of Loom for use in tests and integration harnesses. All Seam instances produced by the same factory instance share a single in-memory mesh.

Link copied to clipboard
data class InMemoryTag(val sessionName: String, val peerKey: String = sessionName, val roomKey: String? = null) : Tag

A Tag implementation for the in-memory transport. Since the in-memory factory does not need network discovery, this carries only the session name. The factory itself provides the mesh context.

Link copied to clipboard
interface Loom

Establishes a Seam in the role of either an existing-session joiner or a new-session opener. The factory hides discovery (mDNS, MultipeerConnectivity advertising, WebSocket URL).

Link copied to clipboard

The default values a Loom factory hands to the knobs that every fabric shares.

Link copied to clipboard
class MuxClientLoom(base: Loom, baseRendezvous: Rendezvous, scope: CoroutineScope, nameOf: (Rendezvous) -> String) : Loom

A client Loom that weaves one base fabric and serves many logical sessions as named channels over a single NamedMux — the fix for "every join opens a new socket."

Link copied to clipboard
class MuxSeam(delegate: Seam, scope: CoroutineScope)

N-way multiplexer over a Seam.

Link copied to clipboard
class MuxServerLoom(source: ConnectionSource, scope: CoroutineScope, val selfId: PeerId, authorizer: RoomAuthorizer, dispatcher: CoroutineContext = requireNotNull(scope.coroutineContext[ContinuationInterceptor]) { "MuxServerLoom scope must have a ContinuationInterceptor (dispatcher)" }, random: Random = Random.Default, handshakeTimeout: Duration = 10.seconds) : Loom, ScopedCloseable

A server-side Loom that provides structural per-room isolation over a shared ConnectionSource.

Link copied to clipboard
class NamedMux(delegate: Seam, scope: CoroutineScope)

String-keyed multiplexer over a Seam — the unbounded-namespace sibling of MuxSeam.

Link copied to clipboard

Overflow behaviour when a bounded delivery buffer is full. Mirrors Reactor's onBackpressure*.

Link copied to clipboard
data class Pattern(val sessionName: String, val maxPeers: Int = 6, val roomKey: String? = null)

Configuration for opening a new peer session.

Link copied to clipboard
class PayloadTooLarge(val payloadBytes: Int, val budgetBytes: Int, val reservedBytes: Int) : IllegalArgumentException

Thrown by an addressed send whose payload exceeds the published send budget — Seam.maxPayloadBytes, or a budgeted derivative of it such as Room.maxPayloadBytes.

Link copied to clipboard
@Serializable
value class PeerId(val value: String)

Stable, comparable identifier for one peer within one session.

Link copied to clipboard
class PeerIdentityRegistry<T : Any>(selfId: PeerId)

The one place a fabric decides whether a peer-supplied identity may join its roster, and who is allowed to take it away again.

Link copied to clipboard
class PeerIdentityRejectedException(val endpoint: String, val reason: String) : Exception

A fabric refused an identity a remote announced for itself.

Link copied to clipboard

Thrown by Seam.sendTo when the addressed peer is not in Seam.peers.

Link copied to clipboard
value class PlyId(val value: String)

Stable identity of one constituent link ("ply") within a composite fabric.

Link copied to clipboard
value class Principal(val value: String)

An opaque, caller-verified identity for the peer on a connection — e.g. an authenticated device id or user id the host established out of band (token, TLS client cert, signed header) before admitting the peer.

Link copied to clipboard

A seam or connection whose transport accept carries a host-verified Principal. A fabric that can authenticate a connection (e.g. a Ktor server reading call.principal()) attaches one via a withPrincipal wrapper; admission layers read it at admit time and carry it onto the admitted peer.

Link copied to clipboard
interface PrincipalRoster

An observable PeerId → Principal roster: the landing spot for host-verified identities on paths that have no admit handshake or member objects (the hosted-hub topology).

Link copied to clipboard

Which half of a pumpIn pump failed — and, decisively, whether the pump is still running.

Link copied to clipboard
sealed interface Rendezvous

Describes the role a Loom peer takes when weaving a session.

Link copied to clipboard
fun interface RoomAuthorizer

Server-side authorization policy for room membership.

Link copied to clipboard
class RoomHubSeam(channelName: String, val selfId: PeerId, authorizer: RoomAuthorizer) : Seam, PrincipalRoster

Server-side hub Seam for one named room — the structural per-room isolation primitive.

Link copied to clipboard
abstract class ScopedCloseable(parentScope: CoroutineScope) : AutoCloseable

Base for coordinators that launch coroutines into an owned child scope and implement AutoCloseable.

Link copied to clipboard
interface Seam

One peer's view of a multi-peer session.

Link copied to clipboard

Thrown by raceCollapse when the Seam collapses mid-operation — the work being raced can no longer complete because the peers it needs are gone. A collapse surfaces two distinct ways and this exception covers both:

Link copied to clipboard
sealed interface SeamState

One peer's view of whether the fabric can carry frames.

Link copied to clipboard
class SeamStateGate(initial: SeamState)

Terminal-latching holder for a seam's SeamState — the primitive that makes the "lost terminal transition" bug class unrepresentable.

Link copied to clipboard
class Spool<T>(policy: DeliveryPolicy)

The one sanctioned per-receiver inbound buffer for in-process delivery.

Link copied to clipboard
class Swatch

Opaque message moving between peers. The wire layer does not interpret the bytes; that is the consumer's job.

Link copied to clipboard
interface Tag

Game-agnostic discovery handle. mDNS service record / MPC peer / WS URL.

Link copied to clipboard
data class TransportCapability(val roles: Set<TransportRole>, val availability: FabricAvailability)

A transport's self-report: the roles it plays and whether its fabric is usable now (availability). Produced pre-connect by Loom.capability and live per-session by Seam.capability.

Link copied to clipboard
sealed interface TransportRole

What role a transport plays. A single fabric may hold several roles at once (Apple Multipeer is WifiDirect + Bluetooth; a Network.framework fabric is Discovery + Data). Sealed so a novel fabric can add a case without editing a closed enum.

Link copied to clipboard
typealias Weft<C> = suspend () -> C

A weft is the thread woven in fresh on every pass of the shuttle across a Loom — here, a per-dial value recomputed on every Loom.weave attempt, including every reconnect. Never cached by kuilt: a fabric Loom implementation that needs fresh per-dial data invokes this itself, inside its own weave(), so the caller's C is recomputed on the first dial and on every subsequent redial.

Functions

Link copied to clipboard
fun checkNotUnderTestDispatcher(scope: CoroutineScope, typeName: String, substitute: String, strict: Boolean, expectVirtualTime: Boolean)

Emits a warning (or throws, when strict is true) if scope contains a kotlinx.coroutines.test.TestDispatcher.

Link copied to clipboard

Mint a fresh, globally-unique PeerId for one peer.

Link copied to clipboard
fun <T : Any> StateFlow<T>.latchingTo(latched: StateFlow<Boolean>, terminal: T): StateFlow<T>

A StateFlow view that follows this flow until latched flips to true, then reports terminal and never changes again.

Link copied to clipboard
fun <T> Flow<T>.pumpIn(scope: CoroutineScope, onFailure: (PumpFailure, Throwable) -> Unit, name: String, body: suspend (T) -> Unit): Job

Collect this flow in scope as a long-lived pump that a throw cannot kill — neither one raised in body nor one raised by the flow — reporting either through onFailure.

Link copied to clipboard
suspend fun <T> Seam.raceCollapse(abortWhen: (Set<PeerId>) -> Boolean = { it.size < 2 }, body: suspend () -> T): T

Run body but abort it with a SeamCollapsedException the instant this Seam collapses mid-operation — either the fabric latches SeamState.Torn (transport tear) OR the live peer set satisfies abortWhen (membership drain). Whichever of body, the tear, or the drain resolves first wins; the losers are cancelled.

Link copied to clipboard
inline fun <R> runCatchingCancellable(block: () -> R): Result<R>

Like runCatching but never swallows coroutine cancellation: a CancellationException always propagates, so a cancelled coroutine fails fast instead of being reported as a captured failure. Every other Throwable becomes Result.failure.

Link copied to clipboard
fun tieredSeam(local: Seam, peer: Seam, scope: CoroutineScope, policy: DeliveryPolicy = DeliveryPolicy.Reliable): Seam

Bond a local-tier and a peer-tier Seam — two views of the same node onto two disjoint peer sets — into one Seam whose roster is the union of both.

Link copied to clipboard
fun <Id> validFirstHop(sender: Id, origin: Id, trusted: Set<Id>): Boolean

The first-hop origin-spoofing rule, shared by every point that accepts a relay frame off a fabric — safety-critical wherever a relayed identity is credited.

Link copied to clipboard

Returns a Connection that reports principal via PrincipalAttested. When principal is null the receiver is returned unchanged — an unauthenticated connection carries no attestation and is never wrapped.