/// /// import * as net from 'net' import { State } from './state' import Readable from './readable' import Writable from './writable' import { Handlers } from './handlers' import { HandlerResolve } from './handler' import Event from './event' import Request from './request' import ObfsMethod from '../obfs/obfs' export type EventTypes = { data: (data: Buffer) => void error: (err: Error) => void close: (connection: Connection) => void terminate: () => void } export type Options = { socks5: boolean socks4: boolean } /** * The Connection class set up listeners and handles incoming data. * a new instance get constructed pre each connection */ declare class Connection { static readonly CLIENT = 'CLIENT' static readonly SERVER = 'SERVER' type: 'CLIENT' | 'SERVER' /** * Resolve function for client only */ resolve?: (value: PromiseLike | HandlerResolve) => void /** * Reject function for client only */ reject?: (reason?: any) => void /** * Current state */ private state /** * Connection socket */ socket: net.Socket /** * Readable data */ readable: Readable /** * Authentication and request handlers */ handlers: Handlers /** * Main event instance */ event: Event /** * Server options */ options: Options /** * The obfuscation method */ obfs: ObfsMethod /** * Clients Request */ request?: Request constructor( event: Event, socket: net.Socket, handlers: Handlers, type: 'CLIENT' | 'SERVER', options?: Options ) /** * Writes the writable on the socket * @param writable - writable to write on socket * @returns void */ write(writable: Writable): void /** * Read n bytes of data without the modification of the readable object data * @param bytes - Number of bytes to be read from data * @returns Buffer */ cat(bytes?: number): Buffer /** * Read n bytes of data * @param bytes - Number of bytes to be read from data * @returns Buffer */ read(bytes?: number): Buffer /** * Read from data until a specific bytes * @param value - Buffer in which the reading process continues until it appears * @returns Buffer */ readUntil(value: Buffer | number): Buffer /** * Checks if the connection is alive * @returns void */ isAlive(): boolean /** * Closes the connection * @returns void */ close(): void /** * Change state from one to other * @param state - The state to change to * @returns void */ transitionTo(state: State): void /** * Parse request * @returns void */ parse(): void /** * Reply to the user with a proper response * @returns void */ reply(): void } export default Connection