ddan-js 2.8.5 → 2.8.7

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.
@@ -5,6 +5,7 @@ const net_1 = require("net");
5
5
  const socks_1 = require("socks");
6
6
  const uuid_1 = require("../crypto/uuid");
7
7
  const index_1 = require("../qs/index");
8
+ const list_1 = require("../list");
8
9
  const event_1 = require("../../class/event");
9
10
  const pipeline_1 = require("../hook/modules/pipeline");
10
11
  const Socks5Event = {
@@ -24,9 +25,11 @@ class Socks5 {
24
25
  __logger;
25
26
  __totalReceived = 0;
26
27
  __totalSent = 0;
28
+ __rules = [];
27
29
  constructor(upstreamProxy, debug = false, logger) {
28
30
  this.__event = new event_1.default();
29
31
  this.upstreamProxy = this.filterProxyConfigs(upstreamProxy);
32
+ this._updateRules();
30
33
  this.__debug = debug;
31
34
  this.__uuid = (0, uuid_1.default)();
32
35
  this.__pipeline = new pipeline_1.default(1);
@@ -49,6 +52,9 @@ class Socks5 {
49
52
  get totalSent() {
50
53
  return this.__totalSent;
51
54
  }
55
+ get rules() {
56
+ return this.__rules;
57
+ }
52
58
  validateProxyConfig(proxyConfig) {
53
59
  const { ipaddress, port, userId, password } = proxyConfig || {};
54
60
  if (!ipaddress || typeof ipaddress !== 'string') {
@@ -109,6 +115,7 @@ class Socks5 {
109
115
  if (!configs || configs.length <= 0)
110
116
  return false;
111
117
  this.upstreamProxy = configs;
118
+ this._updateRules();
112
119
  return true;
113
120
  }
114
121
  setSystemProxy(use, config) {
@@ -162,7 +169,7 @@ class Socks5 {
162
169
  const addr = destination.addr;
163
170
  addrport = `${addr}:${destination.port}`;
164
171
  this.__debug && this.__logger?.info(`[socks5] handle connection`, addrport);
165
- const proxyConfig = this.getProxyConfig(addr);
172
+ const proxyConfig = this.findProxyConfig(addr);
166
173
  if (proxyConfig) {
167
174
  // 走上游代理
168
175
  const upstreamSocket = await this.connectToUpstreamProxy(destination, proxyConfig);
@@ -339,7 +346,7 @@ class Socks5 {
339
346
  clientSocket.end();
340
347
  });
341
348
  }
342
- getProxyConfig(addr) {
349
+ findProxyConfig(addr) {
343
350
  if (index_1.default.isLocalIpAddress(addr))
344
351
  return undefined;
345
352
  for (const cfg of this.upstreamProxy) {
@@ -408,5 +415,10 @@ class Socks5 {
408
415
  // nothing
409
416
  }
410
417
  }
418
+ _updateRules() {
419
+ if (!this.upstreamProxy)
420
+ return;
421
+ this.__rules = list_1.default.distinct(this.upstreamProxy.reduce((prev, current) => prev.concat(current?.rules || []), []));
422
+ }
411
423
  }
412
424
  exports.Socks5 = Socks5;
@@ -680,7 +680,7 @@ declare const dNode: {
680
680
  readDirectory: (dir: string, callback?: import("./typings").Ddan.Func1<string, any> | undefined) => Promise<unknown>;
681
681
  readFiles: (dir: string, files: string[], callback?: import("./typings").Ddan.Func1<string, any> | undefined) => Promise<void>;
682
682
  };
683
- export { dUtil, dHook, dWeb, dMini, dCdn, dStore, dJoker, dTracker, dLogger, dNode, Event, KValue, Mapping };
683
+ export { dUtil, dHook, dWeb, dMini, dCdn, dStore, dJoker, dTracker, dLogger, dNode, Event, KValue, Mapping, };
684
684
  declare const _default: {
685
685
  gbk: {
686
686
  gbkLength: (str: string) => number;
@@ -34,12 +34,14 @@ export declare class Socks5 {
34
34
  __logger: ILogger;
35
35
  __totalReceived: number;
36
36
  __totalSent: number;
37
+ __rules: string[];
37
38
  constructor(upstreamProxy: IRuleProxy | IRuleProxy[], debug?: boolean, logger?: ILogger);
38
39
  get id(): string;
39
40
  get port(): number;
40
41
  get url(): string;
41
42
  get totalReceived(): number;
42
43
  get totalSent(): number;
44
+ get rules(): string[];
43
45
  validateProxyConfig(proxyConfig: IProxy): "" | "无效的上游代理 IP 地址" | "无效的上游代理端口" | "无效的上游代理用户名" | "无效的上游代理密码";
44
46
  private filterProxyConfigs;
45
47
  start(startPort?: number): Promise<number>;
@@ -85,12 +87,13 @@ export declare class Socks5 {
85
87
  private connectToProxy;
86
88
  private connectToLocal;
87
89
  private setupDataForwarding;
88
- private getProxyConfig;
90
+ findProxyConfig(addr: string): IRuleProxy | undefined;
89
91
  private isAllowedDomain;
90
92
  close(): void;
91
93
  on(name: Socks5EventType, listener: (...args: any[]) => void): void;
92
94
  off(name: Socks5EventType, listener: (...args: any[]) => void): void;
93
95
  resetStatistics(): void;
94
96
  private _emit;
97
+ private _updateRules;
95
98
  }
96
99
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.8.5",
3
+ "version": "2.8.7",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",