import { type SrpcByteStream } from '../../srpc/SrpcByteStream';
import { type SrpcConnection, type SrpcMeta, type SrpcStream } from '../../srpc/types';
import type { MeshLinkFrame } from '../mesh-link';
import { MeshLinkPeer, MeshLinkRuntime } from '../mesh-link';
import type { MeshClientRemoteTransport, MeshClientService } from './mesh-client-service';
import { MeshRemoteSrpcConnection, type MeshRemoteConnectionTransport } from './mesh-srpc-remote-connection';
export interface MeshLocalInvokeResult {
    body: Uint8Array;
    issuedSenderIds: number[];
    requiresExactSenderGrant?: boolean;
}
export declare class MeshLinkCapabilityError extends Error {
    constructor(message: string);
}
export interface MeshSrpcLinkControllerOptions<TMeta extends SrpcMeta, TRegistryMeta> {
    meshKey: string;
    requestTimeoutMs: number;
    runtime: MeshLinkRuntime;
    service: MeshClientService<TRegistryMeta, Record<string, unknown>>;
    getLocalConnection(clientId: string): SrpcStream<TMeta> | undefined;
    /** Includes a pending stream, which is not yet visible in active registry lookups. */
    hasLocalFenceConnection?(clientId: string, connectionId: string): boolean;
    invokeLocal(clientId: string, connectionId: string, prefix: string, data: Uint8Array, timeoutMs: number): Promise<Uint8Array | MeshLocalInvokeResult>;
    serviceInvokeLocal?(clientId: string, connectionId: string, type: string, data: unknown, timeoutMs: number): Promise<unknown>;
    reserveLocalSenderIds(clientId: string, connectionId: string, count: number): number[];
    writeLocalStream(clientId: string, connectionId: string, streamId: number, data: Uint8Array): Promise<void>;
    finishLocalStream(clientId: string, connectionId: string, streamId: number): Promise<void>;
    destroyLocalStream(clientId: string, connectionId: string, streamId: number, error?: string): Promise<void>;
    attachLocalReceiver(clientId: string, connectionId: string, streamId: number): SrpcByteStream;
    disconnectLocal(clientId: string, connectionId: string, reason?: string): Promise<void | boolean>;
    /** Exact ownership handoff; distinct from an operator-requested disconnect. */
    fenceLocal?(clientId: string, connectionId: string, reason?: string): Promise<void | boolean>;
    updateLocalMetadata(clientId: string, connectionId: string, metadata: Partial<TMeta>): Promise<TRegistryMeta | void>;
}
export declare class MeshSrpcLinkController<TMeta extends SrpcMeta, TRegistryMeta> implements MeshRemoteConnectionTransport<TRegistryMeta>, MeshClientRemoteTransport<TRegistryMeta> {
    private readonly options;
    private readonly remoteConnections;
    private readonly resolvingRemoteConnections;
    private readonly senderRoutes;
    private readonly terminalSenderRoutes;
    private readonly attachedReceivers;
    private readonly issuedSenderGrants;
    private readonly reservations;
    private readonly handleCapabilities;
    private readonly revokedRemoteCapabilities;
    private readonly cleanupMarkers;
    private readonly terminalForwards;
    private readonly closedOwnerIdentities;
    private readonly verifiedPeers;
    private readonly verifyingPeers;
    private readonly unregisterPeerCloseHandler;
    private readonly unregisterEndpointPinResolver;
    private readonly endpointPinUnregisters;
    private readonly remoteConnectionPruneTimer;
    private readonly terminalRetryTimer;
    private closePromise?;
    private closed;
    constructor(options: MeshSrpcLinkControllerOptions<TMeta, TRegistryMeta>);
    close(): Promise<void>;
    private closeInternal;
    resolveClient(clientId: string, deadlineAt?: number): Promise<SrpcConnection<TMeta | TRegistryMeta> | undefined>;
    listClients(): Promise<SrpcConnection<TMeta | TRegistryMeta>[]>;
    invoke(connection: SrpcConnection<TMeta | TRegistryMeta>, prefix: string, data: Uint8Array, timeoutMs: number, deadlineAt?: number): Promise<Uint8Array>;
    disconnect(connection: MeshRemoteSrpcConnection<TRegistryMeta>, reason?: string): Promise<void>;
    /** Generic MeshClientService invocation over the authenticated mesh link. */
    invokeClient(nodeId: number, request: {
        clientId: string;
        connectionId: string;
        type: string;
        data: unknown;
        timeoutMs?: number;
        deadlineAt?: number;
    }): Promise<unknown>;
    /** Exact-generation physical fence used by ownership takeover and close. */
    fenceClient(nodeId: number, request: {
        clientId: string;
        connectionId: string;
        reason?: string;
        timeoutMs?: number;
    }): Promise<boolean>;
    updateClientMetadata(nodeId: number, request: {
        clientId: string;
        connectionId: string;
        metadata: TRegistryMeta;
    }): Promise<boolean>;
    reserveSenderIds(connection: MeshRemoteSrpcConnection<TRegistryMeta>): Promise<number[]>;
    releaseSenderIds(connection: MeshRemoteSrpcConnection<TRegistryMeta>, ids: number[]): Promise<void>;
    private releaseReservation;
    updateMetadata(connection: MeshRemoteSrpcConnection<TRegistryMeta>, metadata: Partial<TMeta>): Promise<TRegistryMeta>;
    writeStream(connection: MeshRemoteSrpcConnection<TRegistryMeta>, streamId: number, data: Uint8Array): Promise<void>;
    finishStream(connection: MeshRemoteSrpcConnection<TRegistryMeta>, streamId: number): Promise<void>;
    destroyStream(connection: MeshRemoteSrpcConnection<TRegistryMeta>, streamId: number, error?: unknown): Promise<void>;
    private reserveAndConfirm;
    private retryReservation;
    attachReceiver(connection: MeshRemoteSrpcConnection<TRegistryMeta>, streamId: number): Promise<void>;
    activateSender(connection: MeshRemoteSrpcConnection<TRegistryMeta>, streamId: number): Promise<void>;
    route(peer: MeshLinkPeer, frame: MeshLinkFrame): Promise<MeshLinkFrame>;
    forwardClientDestroy(connectionId: string, streamId: number, error?: string): boolean;
    /** Core byte-stream teardown guard: only an authenticated route may
     * consume a sender owned by the opposite mesh endpoint. */
    hasSenderRoute(connectionId: string, streamId: number): boolean;
    invalidateConnection(clientId: string, connectionId: string): void;
    private resolveRegisteredClient;
    private createRemoteConnection;
    private assertCurrent;
    private requestOwner;
    private requestClientOwner;
    private assertNodeCapability;
    private supportsDirectLink;
    private pinNode;
    /** Pins remain only while a live connection or terminal-cleanup obligation
     * can address the endpoint.  Runtime pins themselves are ref-counted; this
     * releases the controller's last reference once no such obligation exists. */
    private pruneEndpointPins;
    private attachLocalReceiver;
    private queueTerminalForward;
    private retryTerminalForwards;
    private retryTerminalForward;
    private drainTerminalForwards;
    private closePinnedPeer;
    private reserveRoute;
    private confirmReservation;
    private assertFrameCapability;
    private assertCapabilityRevocation;
    private acceptCapabilityRevocation;
    private rememberRevokedRemoteCapability;
    private assertLocalStreamOwnership;
    private activateSenderRoute;
    private grantIssuedSenderIds;
    private assertIssuedSenderGrant;
    private pruneReservations;
    private rememberTerminalSenderRoute;
    private getTerminalSenderRoute;
    private reservationExpiresAt;
    private handleCapabilityExpiresAt;
    private abandonPeerReservations;
    private abandonRoute;
    private abandonIssuedSenderGrant;
    private closeHandleCapability;
    private removeHandleCapability;
    private isCapabilityActive;
    private getRemoteConnection;
    private invalidate;
    private invalidateResolution;
    private invalidateClientConnections;
    private invalidateOtherGenerations;
    private pruneRemoteConnections;
    private verifyPeerMembership;
    private countRoutesForConnection;
    private countReceiversForConnection;
    private deleteSenderRoutes;
    private releaseAndMarkStale;
    private queueCleanup;
    private rememberCleanup;
    private retryCleanupMarkers;
    private retryCleanupMarker;
    private drainCleanupMarkers;
    private closeCleanupTargetPeer;
    private rememberClosedOwnerIdentity;
    private assertLeaseSafe;
    private assertOpen;
}
//# sourceMappingURL=mesh-srpc-link-controller.d.ts.map