1 |
|
2 |
|
3 |
|
4 | import { EventEmitter } from 'events';
|
5 | import { SocksClientOptions, SocksClientChainOptions, SocksRemoteHost, SocksProxy, SocksClientBoundEvent, SocksClientEstablishedEvent, SocksUDPFrameDetails } from '../common/constants';
|
6 | import { SocksClientError } from '../common/util';
|
7 | import { Duplex } from 'stream';
|
8 | declare interface SocksClient {
|
9 | on(event: 'error', listener: (err: SocksClientError) => void): this;
|
10 | on(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
|
11 | on(event: 'established', listener: (info: SocksClientEstablishedEvent) => void): this;
|
12 | once(event: string, listener: (...args: unknown[]) => void): this;
|
13 | once(event: 'error', listener: (err: SocksClientError) => void): this;
|
14 | once(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
|
15 | once(event: 'established', listener: (info: SocksClientEstablishedEvent) => void): this;
|
16 | emit(event: string | symbol, ...args: unknown[]): boolean;
|
17 | emit(event: 'error', err: SocksClientError): boolean;
|
18 | emit(event: 'bound', info: SocksClientBoundEvent): boolean;
|
19 | emit(event: 'established', info: SocksClientEstablishedEvent): boolean;
|
20 | }
|
21 | declare class SocksClient extends EventEmitter implements SocksClient {
|
22 | private options;
|
23 | private socket;
|
24 | private state;
|
25 | private receiveBuffer;
|
26 | private nextRequiredPacketBufferSize;
|
27 | private socks5ChosenAuthType;
|
28 | private onDataReceived;
|
29 | private onClose;
|
30 | private onError;
|
31 | private onConnect;
|
32 | constructor(options: SocksClientOptions);
|
33 | /**
|
34 | * Creates a new SOCKS connection.
|
35 | *
|
36 | * Note: Supports callbacks and promises. Only supports the connect command.
|
37 | * @param options { SocksClientOptions } Options.
|
38 | * @param callback { Function } An optional callback function.
|
39 | * @returns { Promise }
|
40 | */
|
41 | static createConnection(options: SocksClientOptions, callback?: (error: Error | null, info?: SocksClientEstablishedEvent) => void): Promise<SocksClientEstablishedEvent>;
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | static createConnectionChain(options: SocksClientChainOptions, callback?: (error: Error | null, socket?: SocksClientEstablishedEvent) => void): Promise<SocksClientEstablishedEvent>;
|
52 | |
53 |
|
54 |
|
55 |
|
56 | static createUDPFrame(options: SocksUDPFrameDetails): Buffer;
|
57 | |
58 |
|
59 |
|
60 |
|
61 | static parseUDPFrame(data: Buffer): SocksUDPFrameDetails;
|
62 | |
63 |
|
64 |
|
65 | private setState;
|
66 | |
67 |
|
68 |
|
69 |
|
70 | connect(existingSocket?: Duplex): void;
|
71 | private getSocketOptions;
|
72 | |
73 |
|
74 |
|
75 |
|
76 | private onEstablishedTimeout;
|
77 | |
78 |
|
79 |
|
80 | private onConnectHandler;
|
81 | |
82 |
|
83 |
|
84 |
|
85 | private onDataReceivedHandler;
|
86 | |
87 |
|
88 |
|
89 | private processData;
|
90 | |
91 |
|
92 |
|
93 |
|
94 | private onCloseHandler;
|
95 | |
96 |
|
97 |
|
98 |
|
99 | private onErrorHandler;
|
100 | |
101 |
|
102 |
|
103 | private removeInternalSocketHandlers;
|
104 | |
105 |
|
106 |
|
107 |
|
108 | private closeSocket;
|
109 | |
110 |
|
111 |
|
112 | private sendSocks4InitialHandshake;
|
113 | |
114 |
|
115 |
|
116 |
|
117 | private handleSocks4FinalHandshakeResponse;
|
118 | |
119 |
|
120 |
|
121 |
|
122 | private handleSocks4IncomingConnectionResponse;
|
123 | |
124 |
|
125 |
|
126 | private sendSocks5InitialHandshake;
|
127 | |
128 |
|
129 |
|
130 |
|
131 | private handleInitialSocks5HandshakeResponse;
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 | private sendSocks5UserPassAuthentication;
|
138 | private sendSocks5CustomAuthentication;
|
139 | private handleSocks5CustomAuthHandshakeResponse;
|
140 | private handleSocks5AuthenticationNoAuthHandshakeResponse;
|
141 | private handleSocks5AuthenticationUserPassHandshakeResponse;
|
142 | |
143 |
|
144 |
|
145 |
|
146 | private handleInitialSocks5AuthenticationHandshakeResponse;
|
147 | |
148 |
|
149 |
|
150 | private sendSocks5CommandRequest;
|
151 | |
152 |
|
153 |
|
154 |
|
155 | private handleSocks5FinalHandshakeResponse;
|
156 | |
157 |
|
158 |
|
159 | private handleSocks5IncomingConnectionResponse;
|
160 | get socksClientOptions(): SocksClientOptions;
|
161 | }
|
162 | export { SocksClient, SocksClientOptions, SocksClientChainOptions, SocksClientError, SocksRemoteHost, SocksProxy, SocksUDPFrameDetails, };
|