Package-level declarations

Types

Link copied to clipboard
interface Connection

A point-to-point, message-oriented duplex link between exactly two peers.

Link copied to clipboard

A transport-agnostic stream of inbound peer Connections — the "front door" of a hosted session. Unlike KtorServerLoom.nextLink(), which collapses each accepted session into a finished 2-peer us.tractat.kuilt.core.Seam, accept yields the raw Connection (a hub spoke) so a composer can bond many of them into one group view.

Link copied to clipboard

Raised through acceptPump's onFailure when a conn's handle does not finish within the timeout.

Link copied to clipboard
object Hello

The one-shot identity preamble: the body of the first frame on a handshaking link.

Link copied to clipboard

The link ended before the remote sent any frame, so there was no hello to read.

Link copied to clipboard

The body does not open with the kuil magic: the remote is not a kuilt peer (or predates v1).

Link copied to clipboard

The body is well-formed but carries a zero-length PeerId.

Link copied to clipboard

A Hello body this build refuses, or a link that closed before sending one. Each subclass names what was wrong, so a version break or a foreign peer never reads as generic corruption.

Link copied to clipboard
class HelloIdLengthMismatchException(val declaredIdLength: Int, val remainingBytes: Int) : HelloFormatException

idLen disagrees with the bytes after the header — short, or (v1 is strict) trailing bytes.

Link copied to clipboard

The id bytes are not valid UTF-8; they are refused rather than decoded with replacement characters.

Link copied to clipboard

The remote's hello claims this peer's own id — typically a peer that dialed its own advertised endpoint (#1488). Not a format error: the bytes were a valid hello.

Link copied to clipboard

The body ended before the header (magic, version, flags, idLen) was complete.

Link copied to clipboard

Hello.encode cannot represent this peer's own id as UTF-8 — it holds a lone surrogate. Not a format error: it is raised locally, before anything is sent.

Link copied to clipboard
class HelloUnsupportedVersionException(val receivedVersion: Int, val supportedVersion: Int) : HelloFormatException

The body declares a Hello version this build does not implement.

Link copied to clipboard
fun interface LinkAdmission

Admission policy for mesh links: decides, per link, whether a handshaked connection may join the mesh.

Link copied to clipboard
class LinkRejectedException(val remoteId: PeerId, val attested: Boolean) : Exception

The per-link signal raised by Mesh.addLink when a handshaked link is rejected by the mesh's LinkAdmission policy. The offending connection is already closed and was never published.

Link copied to clipboard

A Seam over a fully-connected N-peer mesh of point-to-point Connections, with support for admitting links that arrive after construction.

Link copied to clipboard
sealed interface MeshDisplacement

Something the mesh's duplicate-link dedup did that a consumer's own logger should be able to see.

Properties

Link copied to clipboard

How long a deduplicated loser is drained before the seam gives up on the remote's goodbye (#2474).

Link copied to clipboard

Default depth of a peer's receiver ordering hold (#2474): how far the live link may run ahead of a drained link's tail before the seam gives up on ordering the two and releases early.

Functions

Link copied to clipboard
fun CoroutineScope.acceptPump(source: ConnectionSource, handshakeTimeout: Duration, onFailure: (Throwable) -> Unit = {}, handle: suspend (Connection) -> Unit): Job

Persistent, concurrent, handshake-timed accept loop. Drains source forever; each accepted Connection is handled in its OWN child coroutine under handshakeTimeout, so one conn that connects but never completes its handshake can never starve later conns — the sequential while (isActive) { handle(source.accept()) } pattern wedges on such a conn; this replaces it.

Link copied to clipboard
suspend fun handshaking(conn: Connection, selfId: PeerId, dispatcher: CoroutineContext, policy: DeliveryPolicy = DeliveryPolicy.Reliable): Seam

A 2-peer Seam for transports that do NOT carry identity out of band. Sends a Hello preamble as the first frame, awaits the peer's preamble, then delegates to identified over the same single collection of Connection.incoming. Suspends until the peer's preamble arrives.

Link copied to clipboard
suspend fun hubMesh(selfId: PeerId, connections: List<Connection>, dispatcher: CoroutineContext, random: Random = Random.Default, policy: DeliveryPolicy = DeliveryPolicy.Reliable, admission: LinkAdmission = LinkAdmission.AcceptAll, drainBound: Duration = DEFAULT_MESH_DRAIN_BOUND, orderingHoldCapacity: Int = DEFAULT_MESH_ORDERING_HOLD_CAPACITY, onDisplacement: (MeshDisplacement) -> Unit = {}): Mesh

Build a hub-mesh Seam — the start-empty-and-grow topology (a host admitting joiners).

Link copied to clipboard
fun identified(conn: Connection, selfId: PeerId, remoteId: PeerId, dispatcher: CoroutineContext, policy: DeliveryPolicy = DeliveryPolicy.Reliable): Seam

A byte-transparent 2-peer Seam over a Connection whose two identities are known. broadcast == sendTo(remoteId). Woven at construction; Torn on conn EOF/error or close. Concurrent sends are serialized through an internal channel + single writer so wire order matches call order.

Link copied to clipboard
suspend fun meshSeam(selfId: PeerId, connections: List<Connection>, dispatcher: CoroutineContext, random: Random = Random.Default, policy: DeliveryPolicy = DeliveryPolicy.Reliable, admission: LinkAdmission = LinkAdmission.AcceptAll, drainBound: Duration = DEFAULT_MESH_DRAIN_BOUND, orderingHoldCapacity: Int = DEFAULT_MESH_ORDERING_HOLD_CAPACITY, onDisplacement: (MeshDisplacement) -> Unit = {}): Mesh

Build a fully-connected N-peer mesh Seam from a set of raw point-to-point connections.

Link copied to clipboard
suspend fun peerMesh(selfId: PeerId, connections: List<Connection>, dispatcher: CoroutineContext, random: Random = Random.Default, policy: DeliveryPolicy = DeliveryPolicy.Reliable, admission: LinkAdmission = LinkAdmission.AcceptAll, drainBound: Duration = DEFAULT_MESH_DRAIN_BOUND, orderingHoldCapacity: Int = DEFAULT_MESH_ORDERING_HOLD_CAPACITY, onDisplacement: (MeshDisplacement) -> Unit = {}): Mesh

Build a symmetric peer-mesh Seam — the contract-conforming N-peer fabric.