/** Native bidirectional channels (`docs/design/extensions.md`). */ export declare const CHANNEL = 149; export declare const FEATURE_CHANNEL: number; /** Its own bit: a `WATCH` an older server does not know is skipped in silence, * which reads exactly like a name nobody serves. */ export declare const FEATURE_CHANNEL_WATCH: number; export declare const CHANNEL_LISTEN = 1; export declare const CHANNEL_CONNECT = 2; export declare const CHANNEL_DATA = 3; export declare const CHANNEL_ACK = 4; export declare const CHANNEL_CLOSE = 5; export declare const CHANNEL_WATCH = 6; export declare const CHANNEL_UNWATCH = 7; export declare const CHANNEL_OPENED = 1; export declare const CHANNEL_ACCEPTED = 2; export declare const CHANNEL_CLOSED = 5; export declare const CHANNEL_NAMES = 6; export declare const CHANNEL_EXPECT_LISTENER_TOKEN: number; export declare const CHANNEL_CLOSE_NORMAL = 0; export declare const CHANNEL_CLOSE_CANCELLED = 1; export declare const CHANNEL_CLOSE_PEER_GONE = 2; export declare const CHANNEL_CLOSE_PROTOCOL_VIOLATION = 3; export declare const CHANNEL_CLOSE_SERVER_SHUTDOWN = 4; export declare const CHANNEL_MAX_NAME = 255; export declare const CHANNEL_MAX_PEER = 255; export declare const CHANNEL_MAX_METADATA: number; export declare const CHANNEL_MAX_PAYLOAD: number; export declare const CHANNEL_MAX_DETAIL: number; export declare const CHANNEL_WINDOW_BYTES: bigint; export declare const CHANNEL_MAX_UNCONSUMED_MESSAGES = 1024; /** Names one watch may declare. A watch names what it cares about so its * traffic cannot scale with churn it has no interest in. */ export declare const CHANNEL_MAX_WATCH_NAMES = 32; export type ChannelMessage = { kind: "opened"; channelId: number; status: number; window: bigint; peer: string; metadata: Uint8Array; detail: string; } | { kind: "accepted"; channelId: number; listenerId: number; window: bigint; peer: string; metadata: Uint8Array; } | { kind: "data"; channelId: number; payload: Uint8Array; } | { kind: "ack"; channelId: number; bytes: bigint; } | { kind: "closed"; channelId: number; reason: number; detail: string; } | { /** Which of a watch's declared names have a listener right now. A name * that was asked about and is missing here has none, so an empty list * is an answer rather than nothing to say. */ kind: "names"; channelId: number; names: string[]; }; export interface ChannelConnectOptions { metadata?: Uint8Array; /** Optimistically require one exact listener generation. */ listenerToken?: Uint8Array; } export declare function buildChannelListenMessage(channelId: number, name: string, metadata?: Uint8Array): Uint8Array; export declare function buildChannelConnectMessage(channelId: number, name: string, options?: ChannelConnectOptions): Uint8Array; export declare function buildChannelDataMessage(channelId: number, payload: Uint8Array): Uint8Array; export declare function buildChannelAckMessage(channelId: number, bytes: bigint): Uint8Array; export declare function buildChannelCloseMessage(channelId: number, reason?: number): Uint8Array; /** * Follow which of `names` currently have a listener. * * The ID is a client-created channel ID that carries no stream: it shares the * channel ID space so a watch and a channel can never be confused for one * another, and it is released by `buildChannelUnwatchMessage`. */ export declare function buildChannelWatchMessage(channelId: number, names: readonly string[]): Uint8Array; export declare function buildChannelUnwatchMessage(channelId: number): Uint8Array; /** Decode one server-to-client channel packet. Unknown or malformed packets return null. */ export declare function parseChannelMessage(bytes: Uint8Array): ChannelMessage | null; /** * Send-credit bookkeeping for one connected channel. * * The peer's window is the only backpressure a channel has: the server * refuses a DATA message that would put more than `window` unacknowledged * bytes on the wire, and a refusal closes the channel. Track the counters * here so a caller can ask before it builds a payload it cannot send. */ export declare class ChannelCredit { #private; constructor(window: bigint); get window(): bigint; /** Bytes this side may still send before the peer acknowledges more. */ get available(): bigint; /** Cumulative bytes received, which is what an ACK must carry. */ get received(): bigint; fits(length: number): boolean; /** Record an outgoing DATA payload. Returns false when credit is short and * nothing was recorded, so the caller can drop or queue instead. */ charge(length: number): boolean; /** Apply a peer ACK. Cumulative and monotonic; a replay is ignored. */ acknowledge(bytes: bigint): void; /** Record an incoming DATA payload and return the new cumulative total. */ receive(length: number): bigint; } /** How a caller observes one connected channel. */ export interface ChannelOpenOptions extends ChannelConnectOptions { /** One complete message from the peer. Already acknowledged. */ onData?(payload: Uint8Array): void; /** The peer acknowledged bytes; `available` is the new send credit. */ onCredit?(available: bigint): void; /** Final closure, from either side or from transport loss. */ onClosed?(reason: number, detail: string): void; } /** * A live watch over a set of channel names. * * Obtain one from `BlitConnection.watchChannelNames`. It resolves once the * server has answered with the state the registry is in, so a caller never has * to decide what an unanswered watch means. */ export interface ChannelNamesWatch { /** The declared names that have a listener, as of the last answer. */ readonly present: ReadonlySet; /** Stop watching. Idempotent, and safe after the transport is gone. */ stop(): void; } /** A live channel. Obtain one from `BlitConnection.connectChannel`. */ export interface ChannelHandle { readonly channelId: number; readonly name: string; /** Server-assigned label for the peer, e.g. `ext::`. */ readonly peer: string; readonly metadata: Uint8Array; /** Bytes that may be sent before the peer acknowledges more. */ readonly availableCredit: bigint; /** Send one message. Returns false when credit is short or the channel is * gone; throws only on a payload the protocol cannot carry. */ send(payload: Uint8Array | string): boolean; close(reason?: number): void; } //# sourceMappingURL=channel.d.ts.map