import type { IncomingMessage } from 'node:http';
import { BaseMessage, HandlerRequestData, InvokePrefixes, ISrpcServerOptions, RequestData, ResponseData, SrpcDisconnectCause, SrpcConnection, SrpcMeta, SrpcStream, TSrpcMessageHandlerFnOrClass } from './types';
export declare class SrpcServer<TMeta extends SrpcMeta = SrpcMeta, TClientOutput extends BaseMessage = BaseMessage, TServerOutput extends BaseMessage = BaseMessage, TResolvedMeta = TMeta> {
    protected readonly options: ISrpcServerOptions<TClientOutput, TServerOutput>;
    private readonly logger;
    private readonly wsServer;
    private readonly streamConnectionHandlers;
    private readonly streamDisconnectionHandlers;
    private readonly streamMessageHandlers;
    private readonly broadcastHandlers;
    private readonly blockedClientRequests;
    private readonly pendingClientRequests;
    private readonly pendingClientRequestBytes;
    private readonly inFlightClientRequests;
    private readonly inFlightClientRequestBytes;
    private readonly pendingServerRequestBytes;
    private readonly lateReplyTombstonesByStream;
    private readonly backpressuredByteStreams;
    private readonly backpressuredByteStreamBytes;
    private readonly publishedStreams;
    private readonly authReplayNoncesByPrincipal;
    private authNonceConsumer?;
    private readonly cleanupUpgradeHandler?;
    private readonly inactivityCheckInterval;
    private pendingHandshakeCount;
    private clientAuthorizer?;
    private clientKeyFetcher?;
    readonly streamsById: Map<string, SrpcStream<TMeta>>;
    readonly streamsByClientId: Map<string, SrpcStream<TMeta>>;
    protected readonly pendingStreamsByClientId: Map<string, SrpcStream<TMeta>>;
    constructor(options: ISrpcServerOptions<TClientOutput, TServerOutput>);
    private readonly verifyClient;
    private attachConnection;
    private createStream;
    private handleStreamEstablished;
    protected postEstablishCheck(_stream: SrpcStream<TMeta>): Promise<boolean>;
    /**
     * Hook for private/cluster CAS work after the initial protocol frame is
     * queued but before user connection handlers and public local publication.
     */
    protected onStreamWillActivate(_stream: SrpcStream<TMeta>): void | Promise<void>;
    /**
     * Allows a transport extension to recognize a locally-owned sender whose
     * state is maintained outside the core SrpcByteStream sender map.
     * Core remains strict by default.
     */
    protected hasExternalByteStreamSender(_stream: SrpcStream<TMeta>, _streamId: number): boolean;
    protected getCurrentStreamByClientId(clientId: string): SrpcStream<TMeta> | undefined;
    protected isCurrentStream(stream: SrpcStream<TMeta>): boolean;
    private activateStream;
    private handleWsMessage;
    private handleStreamDataReceived;
    private openClientRequests;
    protected handleByteSubstreamOperation(stream: SrpcStream<TMeta>, op: NonNullable<TClientOutput['byteStreamOperation']>, requestId?: string): void;
    private clearByteStreamBackpressureFlag;
    private clearByteStreamState;
    private updateByteStreamBufferedBytes;
    private totalBackpressuredByteStreamBytes;
    private handleClientRequest;
    protected runMessageHandler(handler: TSrpcMessageHandlerFnOrClass<SrpcStream<TMeta>, unknown, unknown>, stream: SrpcStream<TMeta>, data: unknown): Promise<unknown>;
    protected onStreamConnected(stream: SrpcStream<TMeta>): Promise<void>;
    protected onStreamActivated(_stream: SrpcStream<TMeta>): void | Promise<void>;
    protected onStreamDisconnected(stream: SrpcStream<TMeta>, cause: SrpcDisconnectCause): void;
    private revokeStream;
    protected cleanupStream(stream: SrpcStream<TMeta>, cause?: SrpcDisconnectCause): void;
    private closeStreamGracefully;
    private handleStreamDisconnected;
    private handleStreamError;
    private terminateInactiveStreams;
    private validateClientAuth;
    private fetchClientKey;
    private getRemoteAddress;
    protected writeToStream(stream: SrpcStream<TMeta>, data: TServerOutput): boolean;
    private writeEncodedToStream;
    protected writeToStreamAsync(stream: SrpcStream<TMeta>, data: TServerOutput): Promise<void>;
    private canWriteToStream;
    private closeStreamWithError;
    private isStreamDispatchAvailable;
    setClientAuthorizer(authorizer: (metadata: Record<string, unknown>, req: IncomingMessage) => Promise<boolean | Partial<TMeta>> | boolean | Partial<TMeta>): void;
    setClientKeyFetcher(fetcher: (clientId: string) => Promise<false | string> | false | string): void;
    /**
     * Installs an atomic service-wide auth-v2 nonce consumer. It must return
     * true only for the first `(principal, nonce)` consumption through
     * `expiresAt`; false rejects a replay. Core retains its fair local guard.
     */
    setAuthNonceConsumer(consumer: (principal: string, nonce: string, expiresAt: number) => boolean | Promise<boolean>): void;
    registerConnectionHandler(handler: (stream: SrpcStream<TMeta>) => void | Promise<void>): void;
    registerMessageHandler<P extends InvokePrefixes<TClientOutput, TServerOutput>>(prefix: P, handler: TSrpcMessageHandlerFnOrClass<SrpcStream<TMeta>, HandlerRequestData<TClientOutput, P>, ResponseData<TServerOutput, P>>): void;
    registerDisconnectHandler(handler: (stream: SrpcStream<TMeta>, cause: SrpcDisconnectCause) => void): void;
    registerBroadcastHandler(type: string, handler: (data: any, senderInstanceId: number) => void | Promise<void>): void;
    broadcast(type: string, data: any, options?: {
        skipSelf?: boolean;
    }): Promise<void>;
    resolveClient(clientId: string): Promise<SrpcConnection<TMeta | TResolvedMeta> | undefined>;
    listClients(): Promise<SrpcConnection<TMeta | TResolvedMeta>[]>;
    disconnectClient(streamOrClientId: SrpcStream<TMeta> | string, reason?: string): Promise<boolean>;
    updateClientMetadata(streamOrClientId: SrpcStream<TMeta> | string, metadata: Partial<TMeta>): Promise<boolean>;
    invoke<P extends InvokePrefixes<TServerOutput, TClientOutput>>(stream: SrpcStream<TMeta>, prefix: P, data: RequestData<TServerOutput, P>, timeoutMs?: number): Promise<ResponseData<TClientOutput, P>>;
    protected invokeWithRequestId<P extends InvokePrefixes<TServerOutput, TClientOutput>>(stream: SrpcStream<TMeta>, prefix: P, data: RequestData<TServerOutput, P>, timeoutMs: number, requestId: string): Promise<ResponseData<TClientOutput, P>>;
    protected encodeMeshInvokeRequest(prefix: string, data: unknown): Uint8Array;
    protected decodeMeshInvokeRequest(prefix: string, data: Uint8Array): unknown;
    protected encodeMeshInvokeResponse(prefix: string, data: unknown): Uint8Array;
    protected decodeMeshInvokeResponse(prefix: string, data: Uint8Array): unknown;
    protected reserveByteStreamSenderIds(stream: SrpcStream<TMeta>, count: number): number[];
    protected writeByteStreamOperation(stream: SrpcStream<TMeta>, operation: NonNullable<TServerOutput['byteStreamOperation']>): Promise<void>;
    private addLateReplyTombstone;
    private isLateReply;
    private pruneLateReplyTombstones;
    private get lateReplyTombstoneTtlMs();
    private get maxPendingClientRequests();
    private get maxPendingClientRequestBytes();
    private get maxInFlightClientRequests();
    private get maxInFlightClientRequestBytes();
    private get maxBufferedBytes();
    private get maxMessageBytes();
    private get maxPendingServerRequests();
    private get maxPendingServerRequestBytes();
    private get maxPendingHandshakes();
    private get maxActiveStreams();
    private get maxClientIdBytes();
    private get maxClientMetadataBytes();
    private get maxAuthReplayPrincipals();
    private validRemoteByteStreamOperation;
    private isLocalAuthNonceReplay;
    private consumeLocalAuthNonce;
    close(): void;
    static createInvoke<TM extends SrpcMeta, TCO extends BaseMessage, TSO extends BaseMessage>(instanceFn: () => SrpcServer<TM, TCO, TSO>): SrpcServer<TM, TCO, TSO>['invoke'];
}
//# sourceMappingURL=SrpcServer.d.ts.map