/** TCP and UDP relay (docs/design/net.md): wire constants, message builders and parsers, and a transport-agnostic stream table. */ /** Open a socket: [0x80][stream_id:2][flags:1][port:2][host_len:2][host:N] + TLS block */ export declare const C2S_NET_OPEN = 128; /** Stream payload, TCP only: [0x81][stream_id:2][data:N] */ export declare const C2S_NET_DATA = 129; /** Cumulative byte-window credit, TCP only: [0x82][stream_id:2][bytes:8] */ export declare const C2S_NET_ACK = 130; /** Close or half-close: [0x83][stream_id:2][flags:1] */ export declare const C2S_NET_CLOSE = 131; /** One datagram, UDP only: [0x84][stream_id:2][payload:N] */ export declare const C2S_NET_DGRAM = 132; /** Open result: [0x80][stream_id:2][status:1][alpn_len:1][alpn:N][detail_len:2][detail:N] + optional [window:8] */ export declare const S2C_NET_OPENED = 128; /** Stream payload, TCP only: [0x81][stream_id:2][data:N] */ export declare const S2C_NET_DATA = 129; /** Cumulative byte-window credit, TCP only: [0x82][stream_id:2][bytes:8] */ export declare const S2C_NET_ACK = 130; /** Socket ended: [0x83][stream_id:2][reason:1][detail_len:2][detail:N] */ export declare const S2C_NET_CLOSED = 131; /** One datagram, UDP only: [0x84][stream_id:2][payload:N] */ export declare const S2C_NET_DGRAM = 132; /** `S2C_HELLO` feature bit: the server supports the `NET_*` family. */ export declare const FEATURE_NET: number; /** Terminate TLS toward the target; relayed bytes are plaintext. */ export declare const NET_OPEN_TLS: number; /** Skip certificate verification. */ export declare const NET_OPEN_INSECURE: number; /** Open a UDP datagram flow rather than a TCP stream. */ export declare const NET_OPEN_UDP: number; /** Shut down only the client's write side, leaving the stream readable. */ export declare const NET_CLOSE_WRITE: number; export declare const NET_STATUS_OK = 0; export declare const NET_STATUS_UNKNOWN_ID = 1; export declare const NET_STATUS_NOT_FOUND = 2; export declare const NET_STATUS_REFUSED = 3; export declare const NET_STATUS_PERMISSION = 4; export declare const NET_STATUS_TLS = 5; export declare const NET_STATUS_BUDGET = 6; export declare const NET_STATUS_INVALID = 7; export declare const NET_STATUS_OTHER = 9; export declare function netStatusText(status: number): string; export declare const NET_CLOSED_EOF = 0; export declare const NET_CLOSED_RESET = 1; export declare const NET_CLOSED_TIMEOUT = 2; export declare const NET_CLOSED_POLICY = 3; export declare const NET_CLOSED_BUDGET = 4; export declare const NET_CLOSED_SHUTDOWN = 5; export declare function netClosedText(reason: number): string; /** Maximum `NET_DATA`/`NET_DGRAM` payload. */ export declare const NET_MAX_CHUNK: number; /** Largest per-stream unacked-byte window, and the one a stream gets when it is the only one open. */ export declare const NET_WINDOW_BYTES: number; /** * Smallest per-stream unacked-byte window the server ever grants. * * The real window is a share of the connection's aggregate, reported on the * accept; until it arrives this much is safe at any concurrency. */ export declare const NET_WINDOW_MIN: number; /** Maximum concurrent sockets per connection. */ export declare const NET_MAX_SOCKETS = 256; export interface NetOpenOptions { /** Terminate TLS toward the target (TCP only). */ tls?: boolean; /** Skip certificate verification; the server must also permit it. */ insecure?: boolean; /** Open a datagram flow instead of a stream. */ udp?: boolean; /** SNI to present; empty or omitted uses `host`. */ sni?: string; /** ALPN protocols to offer, in order. */ alpn?: readonly string[]; } export declare function netOpenFlags(options?: NetOpenOptions): number; export declare function buildNetOpenMessage(streamId: number, host: string, port: number, options?: NetOpenOptions): Uint8Array; export declare function buildNetDataMessage(streamId: number, data: Uint8Array): Uint8Array; export declare function buildNetDgramMessage(streamId: number, payload: Uint8Array): Uint8Array; export declare function buildNetAckMessage(streamId: number, bytes: number): Uint8Array; export declare function buildNetCloseMessage(streamId: number, flags?: number): Uint8Array; export interface NetOpenedMessage { streamId: number; status: number; alpn: string; detail: string; /** The send window the server granted, absent from a server that does not report one. */ window?: number; } export declare function parseNetOpenedMessage(bytes: Uint8Array): NetOpenedMessage | null; export interface NetClosedMessage { streamId: number; reason: number; detail: string; } export declare function parseNetClosedMessage(bytes: Uint8Array): NetClosedMessage | null; /** Split `[stream_id:2][payload:N]` off a data or datagram message. */ export declare function parseNetPayload(bytes: Uint8Array, opcode: number): { streamId: number; payload: Uint8Array; } | null; export declare function parseNetAckMessage(bytes: Uint8Array): { streamId: number; bytes: number; } | null; /** True for any S2C opcode in the family's `0x80` block. */ export declare function isNetMessage(opcode: number): boolean; /** One relayed socket, from the client's side. */ export interface NetStream { readonly streamId: number; /** Resolves with the negotiated ALPN once the socket is open, rejects with the server's reason if it never opened. */ readonly opened: Promise; /** Queue bytes toward the target, respecting the server's credit. */ write(data: Uint8Array): Promise; /** Shut down the write side, leaving the stream readable — the FIN some protocols use to signal end of input. */ shutdownWrite(): void; /** Abort in both directions. */ close(): void; /** Payload from the target, in order, until the socket ends. */ read(): AsyncGenerator; } /** Every relayed socket on one connection: id allocation, credit, and demux. */ export declare class NetStreams { private readonly send; private readonly streams; private nextId; constructor(send: (msg: Uint8Array) => void); get openCount(): number; /** Open a relayed socket. */ open(host: string, port: number, options?: NetOpenOptions): NetStream; private allocId; private stream; /** Feed one S2C message in. */ handleMessage(bytes: Uint8Array): boolean; /** Fail every live socket, for a connection that has gone away. */ reset(err: Error): void; private finish; private wake; } //# sourceMappingURL=net.d.ts.map