ddan-js 2.7.4 → 2.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,6 +38,11 @@ class Socks5 {
38
38
  get port() {
39
39
  return this.__port;
40
40
  }
41
+ get url() {
42
+ if (!this.__port)
43
+ return '';
44
+ return `socks5://127.0.0.1:${this.__port}`;
45
+ }
41
46
  validateProxyConfig(proxyConfig = this.upstreamProxy) {
42
47
  const { ipaddress, port, userId, password } = proxyConfig || {};
43
48
  if (!ipaddress || typeof ipaddress !== 'string') {
@@ -58,7 +63,7 @@ class Socks5 {
58
63
  if (this.validateProxyConfig())
59
64
  return 0;
60
65
  if (this.server) {
61
- this.__debug && console.info(`[socks] server is already running`);
66
+ this.__debug && console.info(`[socks5] server is already running`);
62
67
  return this.__port;
63
68
  }
64
69
  const port = await this.findAvailablePort(startPort);
@@ -67,10 +72,10 @@ class Socks5 {
67
72
  this.__port = port;
68
73
  this.server = net_1.default.createServer((socket) => this.handleSocksConnection(socket));
69
74
  this.server.listen(port, () => {
70
- this.__debug && this.__logger?.info(`[socks] server is running on port ${port}`);
75
+ this.__debug && this.__logger?.info(`[socks5] server is running on port ${port}`);
71
76
  });
72
77
  this.server.on('error', (err) => {
73
- this.__logger?.error('[socks] server error:', err);
78
+ this.__logger?.error('[socks5] server error:', err);
74
79
  this.close();
75
80
  });
76
81
  return port;
@@ -119,7 +124,7 @@ class Socks5 {
119
124
  port++; // 尝试下一个端口
120
125
  }
121
126
  }
122
- this.__debug && this.__logger?.warn('[socks] findAvailablePort failed');
127
+ this.__debug && this.__logger?.warn('[socks5] findAvailablePort failed');
123
128
  return 0;
124
129
  }
125
130
  async handleSocksConnection(clientSocket) {
@@ -136,27 +141,28 @@ class Socks5 {
136
141
  const destination = await this.parseClientRequest(clientSocket);
137
142
  const addr = destination.addr;
138
143
  addrport = `${addr}:${destination.port}`;
144
+ this.__debug && this.__logger?.info(`[socks5] handle connection`, addrport);
139
145
  if (this.isAllowedDomain(addr)) {
140
146
  // 走上游代理
141
147
  const upstreamSocket = await this.connectToUpstreamProxy(destination);
142
- this.__debug && this.__logger?.info(`[socks] handle connection upstream`, addrport);
148
+ this.__logger?.info(`[socks5] handle connection upstream`, addrport);
143
149
  this.setupDataForwarding(clientSocket, upstreamSocket);
144
150
  }
145
151
  else if (this.useSystemProxy && this.systemProxy && !index_1.default.isLocalIpAddress(addr)) {
146
152
  // 走系统代理
147
153
  const systemSocket = await this.connectToSystemProxy(destination);
148
- this.__debug && console.info(`[socks] handle connection system`, addrport);
154
+ this.__debug && console.info(`[socks5] handle connection system`, addrport);
149
155
  this.setupDataForwarding(clientSocket, systemSocket);
150
156
  }
151
157
  else {
152
- this.__debug && console.info(`[socks] handle connection local`, addrport);
158
+ this.__debug && console.info(`[socks5] handle connection local`, addrport);
153
159
  // 本地连接
154
160
  const localSocket = await this.connectToLocal(destination);
155
161
  this.setupDataForwarding(clientSocket, localSocket);
156
162
  }
157
163
  }
158
164
  catch (err) {
159
- this.__debug && this.__logger?.error('[socks] connection failed:', err);
165
+ this.__debug && this.__logger?.error('[socks5] connection failed:', err);
160
166
  // this.__event.emit(Socks5Event.Error, err, addrport)
161
167
  clientSocket.end(new Uint8Array([0x05, 0x01]));
162
168
  this._emit('error', err, addrport);
@@ -280,21 +286,21 @@ class Socks5 {
280
286
  clientSocket.pipe(targetSocket);
281
287
  targetSocket.pipe(clientSocket);
282
288
  const addrPort = `${targetSocket.localAddress}:${targetSocket.localPort}`;
283
- this.__debug && console.info(`[socks] setupDataForwarding ${addrPort}`);
289
+ this.__debug && console.info(`[socks5] setupDataForwarding ${addrPort}`);
284
290
  clientSocket.on('close', () => {
285
- this.__debug && console.info('[socks] client socket close', addrPort);
291
+ this.__debug && console.info('[socks5] client socket close', addrPort);
286
292
  targetSocket.end();
287
293
  });
288
294
  targetSocket.on('close', () => {
289
- this.__debug && console.info('[socks] target socket close', addrPort);
295
+ this.__debug && console.info('[socks5] target socket close', addrPort);
290
296
  clientSocket.end();
291
297
  });
292
298
  clientSocket.on('error', (err) => {
293
- this.__debug && console.error('[socks] client socket error:', err?.message);
299
+ this.__debug && console.error('[socks5] client socket error:', err?.message);
294
300
  targetSocket.end();
295
301
  });
296
302
  targetSocket.on('error', (err) => {
297
- this.__debug && console.error('[socks] target socket error:', err?.message);
303
+ this.__debug && console.error('[socks5] target socket error:', err?.message);
298
304
  clientSocket.end();
299
305
  });
300
306
  }
@@ -313,10 +319,10 @@ class Socks5 {
313
319
  try {
314
320
  if (!this.server)
315
321
  return;
316
- this.__debug && this.__logger?.info('[socks] closing SOCKS5 proxy server...');
322
+ this.__debug && this.__logger?.info('[socks5] closing SOCKS5 proxy server...');
317
323
  this.server.close((err) => {
318
324
  if (err) {
319
- this.__debug && this.__logger?.error('[socks] closing the server failed:', err);
325
+ this.__debug && this.__logger?.error('[socks5] closing the server failed:', err);
320
326
  }
321
327
  });
322
328
  // 销毁客户端 socket
@@ -328,7 +334,7 @@ class Socks5 {
328
334
  this.__port = 0;
329
335
  }
330
336
  catch (error) {
331
- this.__debug && this.__logger?.error('[socks] close error:', error);
337
+ this.__debug && this.__logger?.error('[socks5] close error:', error);
332
338
  }
333
339
  }
334
340
  on(name, listener) {
@@ -571,15 +571,16 @@ declare const dNode: {
571
571
  ipaddress: string;
572
572
  port: number;
573
573
  } | undefined> | undefined;
574
- toPacScript: ({ proxy, system, rules }: {
575
- proxy?: string | undefined;
576
- system?: string | undefined;
577
- rules?: string[] | undefined;
578
- }) => string;
574
+ toPacScript: (proxy: string, rules?: string[], defaultProxy?: string) => string;
579
575
  toPacProxy: (ipaddress: string, port: number, options?: {
580
576
  type?: "PROXY" | "SOCKS5" | "ALL" | undefined;
581
577
  direct?: boolean | undefined;
582
578
  } | undefined) => string;
579
+ pacScript: (host: string, port: number, options?: {
580
+ rules?: string[] | undefined;
581
+ type?: "PROXY" | "SOCKS5" | "ALL" | undefined;
582
+ useSystem?: boolean | undefined;
583
+ } | undefined) => Promise<string>;
583
584
  child_exec: (cmd: string) => Promise<[any, string]>;
584
585
  brotliCompress: typeof import("./modules/node/brotli").brotliCompress;
585
586
  brotliDecompress: typeof import("./modules/node/brotli").brotliDecompress;
@@ -9,15 +9,16 @@ declare const _default: {
9
9
  ipaddress: string;
10
10
  port: number;
11
11
  } | undefined> | undefined;
12
- toPacScript: ({ proxy, system, rules }: {
13
- proxy?: string | undefined;
14
- system?: string | undefined;
15
- rules?: string[] | undefined;
16
- }) => string;
12
+ toPacScript: (proxy: string, rules?: string[], defaultProxy?: string) => string;
17
13
  toPacProxy: (ipaddress: string, port: number, options?: {
18
14
  type?: "PROXY" | "SOCKS5" | "ALL" | undefined;
19
15
  direct?: boolean | undefined;
20
16
  } | undefined) => string;
17
+ pacScript: (host: string, port: number, options?: {
18
+ rules?: string[] | undefined;
19
+ type?: "PROXY" | "SOCKS5" | "ALL" | undefined;
20
+ useSystem?: boolean | undefined;
21
+ } | undefined) => Promise<string>;
21
22
  child_exec: (cmd: string) => Promise<[any, string]>;
22
23
  brotliCompress: typeof import("./brotli").brotliCompress;
23
24
  brotliDecompress: typeof import("./brotli").brotliDecompress;
@@ -1,16 +1,17 @@
1
- declare const _default: {
1
+ declare const _default_1: {
2
2
  getSystemProxy: () => Promise<{
3
3
  ipaddress: string;
4
4
  port: number;
5
5
  } | undefined> | undefined;
6
- toPacScript: ({ proxy, system, rules }: {
7
- proxy?: string | undefined;
8
- system?: string | undefined;
9
- rules?: string[] | undefined;
10
- }) => string;
6
+ toPacScript: (proxy: string, rules?: string[], defaultProxy?: string) => string;
11
7
  toPacProxy: (ipaddress: string, port: number, options?: {
12
8
  type?: "PROXY" | "SOCKS5" | "ALL" | undefined;
13
9
  direct?: boolean | undefined;
14
10
  } | undefined) => string;
11
+ pacScript: (host: string, port: number, options?: {
12
+ rules?: string[] | undefined;
13
+ type?: "PROXY" | "SOCKS5" | "ALL" | undefined;
14
+ useSystem?: boolean | undefined;
15
+ } | undefined) => Promise<string>;
15
16
  };
16
- export default _default;
17
+ export default _default_1;
@@ -33,6 +33,7 @@ export declare class Socks5 {
33
33
  constructor(upstreamProxy: IProxyConfig, allowedDomains?: string[] | ['*'], debug?: boolean, logger?: ILogger);
34
34
  get id(): string;
35
35
  get port(): number;
36
+ get url(): string;
36
37
  validateProxyConfig(proxyConfig?: IProxyConfig): "" | "无效的上游代理 IP 地址" | "无效的上游代理端口" | "无效的上游代理用户名" | "无效的上游代理密码";
37
38
  start(startPort?: number): Promise<number>;
38
39
  setUpstreamProxy(upstreamProxy: IProxyConfig): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.7.4",
3
+ "version": "2.7.6",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",