import { type Dial } from "../egress/TransparentDial.js"; import { type InterceptProtocol } from "../intercept/Destination.js"; import { type InterceptRefusal, type GovernedCountsSource, type InterceptReport } from "../intercept/InterceptLedger.js"; import { type InterceptGovernor } from "./InterceptGovernor.js"; /** One listener: the port it binds, and the port the redirected connections were addressed to. */ export interface InterceptListenerSpec { readonly port: number; readonly destinationPort: number; } export interface InterceptorOptions { /** The address the listeners bind; loopback, since REDIRECT delivers locally generated packets there. */ readonly bind: string; readonly listeners: readonly InterceptListenerSpec[]; /** How long a client has to send bytes that name a destination. */ readonly peekTimeoutMs: number; readonly connectTimeoutMs: number; /** How long a spliced connection may stay silent in both directions. */ readonly idleTimeoutMs: number; readonly maxConnections: number; } export declare const INTERCEPT_DEFAULTS: { readonly bind: "127.0.0.1"; readonly httpPort: 15001; readonly httpsPort: 15002; readonly peekTimeoutMs: 5000; readonly connectTimeoutMs: 10000; readonly idleTimeoutMs: 300000; readonly maxConnections: 10000; }; export interface BoundListener { readonly address: string; readonly port: number; readonly destinationPort: number; } export type InterceptEvent = { readonly event: "INTERCEPT_STARTED"; readonly at: string; readonly listeners: readonly { readonly listen: string; readonly for_port: number; }[]; } | { readonly event: "INTERCEPT_OBSERVED"; readonly at: string; readonly protocol: InterceptProtocol; readonly host: string; readonly port: number; /** Taken by the gateway rather than spliced through. */ readonly governed: boolean; readonly method?: string; readonly target?: string; readonly alpn?: readonly string[]; } | { readonly event: "INTERCEPT_REFUSED"; readonly at: string; readonly reason: InterceptRefusal; readonly protocol: InterceptProtocol | null; readonly host?: string; readonly port?: number; readonly detail?: string; } | { readonly event: "INTERCEPT_GOVERNING"; readonly at: string; readonly hosts: readonly string[]; readonly unlisted: "passthrough" | "refuse"; /** Whether governed TLS is terminated: an operator authority was given. */ readonly tls: boolean; } | InterceptReport | { readonly event: "INTERCEPT_STOPPED"; readonly at: string; readonly signal: string; }; export interface InterceptorDependencies { readonly emit: (event: InterceptEvent) => void; readonly dial?: Dial; readonly now?: () => Date; /** The govern phase, when an operator listed destinations; null observes everything. */ readonly governor?: InterceptGovernor | null; /** The gateway's account of a governed destination, for the report; none when nothing is governed. */ readonly governedCounts?: GovernedCountsSource; } /** * When the interceptor prints its report unasked: as the count of connections * reaches each of these, and whenever a day has passed since the last report * at the moment a connection is counted. The stop always prints one. */ export declare const INTERCEPT_REPORT_MILESTONES: readonly number[]; export declare const INTERCEPT_REPORT_INTERVAL_MS: number; export declare class Interceptor { private readonly options; private readonly ledger; private readonly servers; private readonly bound; private readonly active; private readonly dial; private readonly now; private readonly emit; private readonly governor; private readonly governedCounts; private lastReportAt; constructor(options: InterceptorOptions, dependencies: InterceptorDependencies); /** Binds every listener; a port that cannot be bound closes the ones already bound and rejects. */ listen(): Promise; listeners(): readonly BoundListener[]; report(): InterceptReport; /** * The report on its own cadence, so a sidecar that runs for weeks is read * without being stopped: at each milestone in the count of connections, and * once a day has passed since the last report. */ private reportOnCadence; /** Stops accepting, drops every connection, and waits for the listeners to close. */ close(): Promise; private accept; /** Reads the client's first bytes until they name a destination, or refuse one, or run out of time. */ private peek; private place; /** Both directions, with back-pressure, half-close, an idle bound, and the bytes counted once at the end. */ private splice; private refuse; /** Whether a destination is one of this interceptor's own listeners: a connection that would loop. */ private isSelf; } //# sourceMappingURL=InterceptServer.d.ts.map