import type { IncomingMessage } from "node:http";
/** Sockets one identity may hold per client kind, and in all. */
export declare const SOCKETS_PER_KIND = 16;
export declare const SOCKETS_PER_IDENTITY = 32;
/** Every identity together; the backstop if identities themselves multiply. */
export declare const SOCKETS_TOTAL = 128;
/**
 * Who a WebSocket belongs to, from what the Hook itself trusts rather than a
 * client hint: a peer key's gateway rebuilds its request with `x-phren-origin:
 * peer` and the peer's fingerprint, so that is its own identity; everything
 * else arrives on the owner's local socket or the owner's SSH pipe and is the
 * owner. `x-phren-client` only picks a sub-pool inside the identity.
 */
export declare function socketIdentity(request: Pick<IncomingMessage, "headers">): string;
export declare const socketKind: (request: Pick<IncomingMessage, "headers">) => string;
/** How long an evicted socket has to flush its close frame before the TCP socket is destroyed. */
export declare const CLOSE_GRACE_MS = 1000;
/** How many evicted sockets may be waiting out their close handshake at once. */
export declare const CLOSING_MAX = 32;
/** The parts of a WebSocket a graceful close needs. */
export interface ClosableSocket {
    close(code: number, reason: string): void;
    terminate(): void;
    once(event: "close", listener: () => void): unknown;
    removeAllListeners(event: "message"): unknown;
}
/** How many evicted sockets are waiting out their close handshake. */
export declare const closingCount: () => number;
/** Terminates every socket still waiting out its close handshake; the Hook's shutdown calls this. */
export declare function terminateClosing(): void;
/** Sends the close frame first, then terminates only if the socket has not closed within the grace. */
export declare function closeGracefully(socket: ClosableSocket, code: number, reason: string, graceMs?: number): void;
/** Admits sockets oldest-first under the per-kind, per-identity and total caps. */
export declare class SocketBudget<S> {
    private readonly limits;
    private readonly entries;
    constructor(limits?: {
        kind: number;
        identity: number;
        total: number;
    });
    /** Register a socket; returns the sockets to close to stay inside the caps. */
    add(socket: S, identity: string, kind: string): S[];
    remove(socket: S): void;
    count(identity?: string): number;
}
