Connection

interface Connection

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

The minimal SPI a message transport (WebSocket, gRPC bidi stream, Multipeer, Nearby) implements to become a kuilt fabric. Stream transports (TCP) do not implement this directly — they provide a kotlinx-io Source/Sink and use :kuilt-stream's framed() to obtain a Connection.

Each frame is a whole message; the link preserves frame boundaries and FIFO order.

Neither send nor close may report a failure as a cancellation — the obligation us.tractat.kuilt.core.Seam.close states in full, for the same reason and with the same withTimeout trap. MeshSeam closes a whole roster of connections under a best-effort guard, so one callee-minted CancellationException here cancels that loop and leaks every remaining link (#1826).

Properties

Link copied to clipboard
abstract val incoming: Flow<ByteArray>

Whole messages received from the peer, in order. Single-collection.

Link copied to clipboard
open val maxFrameBytes: Int?

The largest frame send accepts, or null when this link cannot name a ceiling.

Functions

Link copied to clipboard
abstract suspend fun close()

Close the link. Idempotent. Completes incoming.

Link copied to clipboard
open suspend fun flush(timeout: Duration): FlushOutcome

Wait, up to timeout, until a close of this link goes out behind every frame whose send returned before this call, so it cannot be what throws one away on this device.

Link copied to clipboard
abstract suspend fun send(frame: ByteArray)

Send one whole message. Suspends until the transport accepts it (backpressure).

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.