@push.rocks/smartproxy
Version:
A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.
118 lines (117 loc) • 3.73 kB
TypeScript
import * as plugins from '../../plugins.js';
import type { IConnectionRecord } from './models/interfaces.js';
import { LifecycleComponent } from '../../core/utils/lifecycle-component.js';
import { WrappedSocket } from '../../core/models/wrapped-socket.js';
import type { SmartProxy } from './smart-proxy.js';
/**
* Manages connection lifecycle, tracking, and cleanup with performance optimizations
*/
export declare class ConnectionManager extends LifecycleComponent {
private smartProxy;
private connectionRecords;
private terminationStats;
private nextInactivityCheck;
private readonly maxConnections;
private readonly cleanupBatchSize;
private cleanupQueue;
private cleanupTimer;
private isProcessingCleanup;
private connectionsByRoute;
constructor(smartProxy: SmartProxy);
/**
* Generate a unique connection ID
*/
generateConnectionId(): string;
/**
* Create and track a new connection
* Accepts either a regular net.Socket or a WrappedSocket for transparent PROXY protocol support
*/
createConnection(socket: plugins.net.Socket | WrappedSocket): IConnectionRecord | null;
/**
* Track an existing connection
*/
trackConnection(connectionId: string, record: IConnectionRecord): void;
/**
* Schedule next inactivity check for a connection
*/
private scheduleInactivityCheck;
/**
* Start the inactivity check timer
*/
private startInactivityCheckTimer;
/**
* Get a connection by ID
*/
getConnection(connectionId: string): IConnectionRecord | undefined;
/**
* Get all active connections
*/
getConnections(): Map<string, IConnectionRecord>;
/**
* Get count of active connections
*/
getConnectionCount(): number;
/**
* Track connection by route
*/
trackConnectionByRoute(routeId: string, connectionId: string): void;
/**
* Remove connection tracking for a route
*/
removeConnectionByRoute(routeId: string, connectionId: string): void;
/**
* Get connection count by route
*/
getConnectionCountByRoute(routeId: string): number;
/**
* Initiates cleanup once for a connection
*/
initiateCleanupOnce(record: IConnectionRecord, reason?: string): void;
/**
* Queue a connection for cleanup
*/
private queueCleanup;
/**
* Process the cleanup queue in batches
*/
private processCleanupQueue;
/**
* Clean up a connection record
*/
cleanupConnection(record: IConnectionRecord, reason?: string): void;
/**
* Creates a generic error handler for incoming or outgoing sockets
*/
handleError(side: 'incoming' | 'outgoing', record: IConnectionRecord): (err: Error) => void;
/**
* Creates a generic close handler for incoming or outgoing sockets
*/
handleClose(side: 'incoming' | 'outgoing', record: IConnectionRecord): () => void;
/**
* Increment termination statistics
*/
incrementTerminationStat(side: 'incoming' | 'outgoing', reason: string): void;
/**
* Get termination statistics
*/
getTerminationStats(): {
incoming: Record<string, number>;
outgoing: Record<string, number>;
};
/**
* Optimized inactivity check - only checks connections that are due
*/
private performOptimizedInactivityCheck;
/**
* Legacy method for backward compatibility
*/
performInactivityCheck(): void;
/**
* Clear all connections (for shutdown)
*/
clearConnections(): Promise<void>;
/**
* Override LifecycleComponent's onCleanup method
*/
protected onCleanup(): Promise<void>;
}