/** * @file association.ts * @description Minimal SCTP association over a datagram channel (DTLS), scoped * to the WebRTC data channel profile (RFC 8831). * @module sctp/association * * Implements the four-way INIT/INIT-ACK/COOKIE-ECHO/COOKIE-ACK setup, DATA * transmit/receive with TSN tracking and SACK, ordered and unordered delivery, * and reassembly of fragmented user messages. Congestion control is * intentionally simple (stop-and-go style with a generous rwnd) which is * adequate for control/data-channel traffic and interoperates with usrsctp * (the stack browsers use). * * The association rides on top of a reliable-ish datagram pipe provided by * DTLS; SCTP still provides framing, ordering, multiplexing and ack'ing. */ import { EventEmitter } from 'events'; declare const SCTP_PORT = 5000; declare const STATE: Readonly<{ CLOSED: "closed"; COOKIE_WAIT: "cookie-wait"; COOKIE_ECHOED: "cookie-echoed"; ESTABLISHED: "established"; }>; type StateValue = (typeof STATE)[keyof typeof STATE]; /** Options for constructing an {@link SctpAssociation}. */ export interface SctpAssociationOptions { /** the DTLS client initiates SCTP (RFC 8831) */ isClient?: boolean; } /** A complete user message surfaced via the 'message' event. */ export interface SctpMessage { streamId: number; ppid: number; data: Buffer; } /** * @class SctpAssociation * @extends EventEmitter * * Events: * - 'established' association is up * - 'message' ({streamId, ppid, data}) a complete user message arrived * - 'output' (Buffer) an SCTP packet to hand to DTLS * - 'close' */ declare class SctpAssociation extends EventEmitter { #private; isClient: boolean; state: StateValue; /** * @param {Object} opts * @param {boolean} opts.isClient - the DTLS client initiates SCTP (RFC 8831) */ constructor(opts?: SctpAssociationOptions); /** Start the association (client sends INIT). */ start(): void; /** * Feed an inbound SCTP packet (decrypted from DTLS). * @param {Buffer} packet */ receivePacket(packet: Buffer): void; /** * Send a user message on a stream. * @param {number} streamId * @param {number} ppid * @param {Buffer} data * @param {Object} [opts] * @param {boolean} [opts.unordered=false] */ sendData(streamId: number, ppid: number, data: Buffer, opts?: { unordered?: boolean; }): void; /** Gracefully close the association. */ shutdown(): void; } export { SctpAssociation, STATE, SCTP_PORT };