import { type PipeId, type RelayErrorCode, type RendezvousId } from '@pellux/goodvibes-transport-core/relay'; /** The subset of a WebSocket the hub needs. Keeps the hub runtime-neutral. */ export interface RelayServerSocket { send(data: string | Uint8Array): void; close(code?: number, reason?: string): void; } /** Optional structured logger; defaults to silent. */ export interface RelayServerLogger { info(message: string, fields?: Record): void; warn(message: string, fields?: Record): void; error(message: string, fields?: Record): void; } /** Caps and rate limits that keep a public instance from becoming a liability. */ export interface RelayServerLimits { /** Maximum concurrently-registered daemons. */ readonly maxDaemons: number; /** Maximum concurrent client pipes across all daemons. */ readonly maxPipes: number; /** Maximum concurrent client pipes for a single daemon. */ readonly maxPipesPerDaemon: number; /** Maximum bytes in a single forwarded data frame. */ readonly maxMessageBytes: number; /** Maximum register/connect attempts per remote address per rolling minute. */ readonly maxHandshakesPerMinutePerAddr: number; } export declare const DEFAULT_RELAY_LIMITS: RelayServerLimits; /** * The runtime-neutral rendezvous core. One instance per relay process. Every * connection is represented by a `RelayConnection` returned from `accept`. */ export declare class RelayHub { private readonly daemons; private readonly pipes; private readonly limits; private readonly logger; private readonly rateLimiter; constructor(options?: { limits?: Partial; logger?: RelayServerLogger; }); /** Current occupancy, surfaces/monitoring can read this. */ stats(): { readonly daemons: number; readonly pipes: number; }; /** Maximum bytes allowed in a single forwarded data frame. */ get maxMessageBytes(): number; /** Begin tracking a freshly-connected socket. */ accept(socket: RelayServerSocket, remoteAddr: string): RelayConnection; /** @internal */ _rateOk(addr: string): boolean; /** @internal Register a daemon under a rendezvous id. Returns an error code or null on success. */ _register(rid: RendezvousId, socket: RelayServerSocket): RelayErrorCode | null; /** @internal Open a client pipe to a registered daemon. */ _openPipe(rid: RendezvousId, client: RelayServerSocket): { pipeId: PipeId; pipeIdBytes: Uint8Array; } | RelayErrorCode; /** @internal Forward an opaque payload from a client to its daemon (adds pipe prefix). */ _clientToDaemon(pipeId: PipeId, payload: Uint8Array): boolean; /** @internal Forward an opaque daemon frame ([pipeId][payload]) to the right client. */ _daemonToClient(frame: Uint8Array): boolean; /** @internal Tear down a single pipe, notifying the surviving peer. */ _closePipe(pipeId: PipeId, notify: 'client' | 'daemon' | 'both', reason?: string): void; /** @internal Remove a daemon registration and close all its pipes. */ _unregister(rid: RendezvousId): void; } /** Per-connection state machine. One instance per accepted socket. */ export declare class RelayConnection { private readonly hub; private readonly socket; private readonly remoteAddr; private role; private rid; private pipeId; constructor(hub: RelayHub, socket: RelayServerSocket, remoteAddr: string); /** Handle a text (control) frame from this socket. */ handleText(text: string): void; /** Handle a binary (data) frame from this socket. */ handleBinary(bytes: Uint8Array): void; /** Handle socket closure. */ handleClose(): void; private onRegister; private onConnect; private fail; } //# sourceMappingURL=relay-server.d.ts.map