/// import * as net from 'net'; import { EventTypes, Options } from '../helper/connection'; import { Handler } from '../helper/handler'; import { Handlers } from '../helper/handlers'; import { AuthMethod } from '../helper/authMethod'; import { ObfsBuilder } from '../obfs/obfs'; type ConnectionListener = ((socket: net.Socket) => void) | undefined; /** * The Server class is responsible for creating a TCP socket server, * and listening for incoming connections and handling socks relevant requests */ export declare class Server { /** * The TCP socket server */ private socketServer; /** * The array of all live connections */ private connections; /** * The object which contains all default handlers */ private readonly handlers; /** * The main event object */ private readonly event; constructor(options?: Options, connectionListener?: ConnectionListener); on(event: 'data', callback: EventTypes['data']): void; on(event: 'error', callback: EventTypes['error']): void; /** * Get the handler function, and push it into this.handlers.req * @param handler - Emitted when socks5 clients send an authentication request * @returns Server */ useAuth(handler: AuthMethod): Server; /** * Get the handler function, and update this.handlers.req * @param cmd - Specify handler type (connect | associate | bind) * @param handler - Emitted when new request appears * @returns Server */ useReq(cmd: keyof Handlers['req'], handler: Handler): Server; /** * Get the handler function, and update this.handlers.userId * @param handler - Emitted when new request appears specifically on socks4 * @returns Server */ useIdent(handler: (userId: string) => boolean): Server; /** * Get the handler function, and update this.handlers.userId * @param handler - Emitted when new request appears * @returns Server */ useObfs(handler: ObfsBuilder): Server; /** * Get the primary's server handle, and listen on it * @param port - Port to listen on * @param host - Host to listen on * @param listeningListener - Emitted when new connection appears * @returns Server */ listen(port: number, host: string, listeningListener?: (() => void) | undefined): Server; /** * Terminate connections and server * @param callback - Emitted when the server closes * @returns void */ close(callback?: ((err?: Error | undefined) => void) | undefined): void; } /** * Creates a new SOCKS server * @param options - Optional inputs * @param connectionListener - Connection Listener * @returns Server */ export declare const createServer: (options?: Options, connectionListener?: ConnectionListener) => Server; export {};