summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/node_modules/socks/typings/client/socksclient.d.ts
blob: 33e1c25fc5ef73ebee5a2966fd9a92a1feb9ddf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/// <reference types="node" />
import { EventEmitter } from 'events';
import { SocksClientOptions, SocksClientChainOptions, SocksRemoteHost, SocksProxy, SocksClientBoundEvent, SocksClientEstablishedEvent, SocksUDPFrameDetails } from '../common/constants';
import { SocksClientError } from '../common/util';
import { Duplex } from 'stream';
interface SocksClient {
    on(event: 'error', listener: (err: SocksClientError) => void): this;
    on(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
    on(event: 'established', listener: (info: SocksClientEstablishedEvent) => void): this;
    once(event: string, listener: (...args: any[]) => void): this;
    once(event: 'error', listener: (err: SocksClientError) => void): this;
    once(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
    once(event: 'established', listener: (info: SocksClientEstablishedEvent) => void): this;
    emit(event: string | symbol, ...args: any[]): boolean;
    emit(event: 'error', err: SocksClientError): boolean;
    emit(event: 'bound', info: SocksClientBoundEvent): boolean;
    emit(event: 'established', info: SocksClientEstablishedEvent): boolean;
}
declare class SocksClient extends EventEmitter implements SocksClient {
    private _options;
    private _socket;
    private _state;
    private _receiveBuffer;
    private _nextRequiredPacketBufferSize;
    private _onDataReceived;
    private _onClose;
    private _onError;
    private _onConnect;
    constructor(options: SocksClientOptions);
    /**
     * Creates a new SOCKS connection.
     *
     * Note: Supports callbacks and promises. Only supports the connect command.
     * @param options { SocksClientOptions } Options.
     * @param callback { Function } An optional callback function.
     * @returns { Promise }
     */
    static createConnection(options: SocksClientOptions, callback?: Function): Promise<SocksClientEstablishedEvent>;
    /**
     * Creates a new SOCKS connection chain to a destination host through 2 or more SOCKS proxies.
     *
     * Note: Supports callbacks and promises. Only supports the connect method.
     * Note: Implemented via createConnection() factory function.
     * @param options { SocksClientChainOptions } Options
     * @param callback { Function } An optional callback function.
     * @returns { Promise }
     */
    static createConnectionChain(options: SocksClientChainOptions, callback?: Function): Promise<SocksClientEstablishedEvent>;
    /**
     * Creates a SOCKS UDP Frame.
     * @param options
     */
    static createUDPFrame(options: SocksUDPFrameDetails): Buffer;
    /**
     * Parses a SOCKS UDP frame.
     * @param data
     */
    static parseUDPFrame(data: Buffer): SocksUDPFrameDetails;
    /**
     * Gets the SocksClient internal state.
     */
    /**
     * Internal state setter. If the SocksClient is in an error state, it cannot be changed to a non error state.
     */
    private state;
    /**
     * Starts the connection establishment to the proxy and destination.
     * @param existing_socket Connected socket to use instead of creating a new one (internal use).
     */
    connect(existing_socket?: Duplex): void;
    /**
     * Handles internal Socks timeout callback.
     * Note: If the Socks client is not BoundWaitingForConnection or Established, the connection will be closed.
     */
    private onEstablishedTimeout();
    /**
     * Handles Socket connect event.
     */
    private onConnect();
    /**
     * Handles Socket data event.
     * @param data
     */
    private onDataReceived(data);
    /**
     * Handles processing of the data we have received.
     */
    private processData();
    /**
     * Handles Socket close event.
     * @param had_error
     */
    private onClose();
    /**
     * Handles Socket error event.
     * @param err
     */
    private onError(err);
    /**
     * Removes internal event listeners on the underlying Socket.
     */
    private removeInternalSocketHandlers();
    /**
     * Closes and destroys the underlying Socket. Emits an error event.
     * @param err { String } An error string to include in error event.
     */
    private _closeSocket(err);
    /**
     * Sends initial Socks v4 handshake request.
     */
    private sendSocks4InitialHandshake();
    /**
     * Handles Socks v4 handshake response.
     * @param data
     */
    private handleSocks4FinalHandshakeResponse();
    /**
     * Handles Socks v4 incoming connection request (BIND)
     * @param data
     */
    private handleSocks4IncomingConnectionResponse();
    /**
     * Sends initial Socks v5 handshake request.
     */
    private sendSocks5InitialHandshake();
    /**
     * Handles initial Socks v5 handshake response.
     * @param data
     */
    private handleInitialSocks5HandshakeResponse();
    /**
     * Sends Socks v5 user & password auth handshake.
     *
     * Note: No auth and user/pass are currently supported.
     */
    private sendSocks5UserPassAuthentication();
    /**
     * Handles Socks v5 auth handshake response.
     * @param data
     */
    private handleInitialSocks5AuthenticationHandshakeResponse();
    /**
     * Sends Socks v5 final handshake request.
     */
    private sendSocks5CommandRequest();
    /**
     * Handles Socks v5 final handshake response.
     * @param data
     */
    private handleSocks5FinalHandshakeResponse();
    /**
     * Handles Socks v5 incoming connection request (BIND).
     */
    private handleSocks5IncomingConnectionResponse();
    readonly socksClientOptions: SocksClientOptions;
}
export { SocksClient, SocksClientOptions, SocksClientChainOptions, SocksRemoteHost, SocksProxy, SocksUDPFrameDetails };