ee-core 2.9.2 → 2.10.1
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.
- package/LICENSE +21 -21
- package/README.md +65 -65
- package/addon/index.js +34 -34
- package/addon/window/index.js +98 -98
- package/bin/tools.js +8 -8
- package/config/cache.js +41 -38
- package/config/config.default.js +331 -330
- package/config/index.js +86 -73
- package/const/channel.js +17 -17
- package/const/index.js +8 -8
- package/controller/baseContextClass.js +34 -34
- package/controller/index.js +34 -34
- package/core/index.js +10 -10
- package/core/lib/ee.js +216 -216
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +435 -435
- package/core/lib/loader/file_loader.js +326 -326
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +130 -130
- package/core/lib/loader/mixin/controller.js +125 -125
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/function.js +30 -30
- package/core/lib/utils/index.js +133 -133
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/cross/index.js +183 -183
- package/cross/spawnProcess.js +183 -183
- package/ee/appLoader.js +48 -48
- package/ee/application.js +99 -99
- package/ee/baseApp.js +103 -102
- package/ee/eeApp.js +408 -408
- package/ee/index.js +57 -57
- package/electron/app/index.js +64 -58
- package/electron/index.js +19 -19
- package/electron/window/index.js +73 -73
- package/electron/window/winState.js +186 -186
- package/exception/index.js +112 -112
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.js +13 -13
- package/httpclient/index.js +161 -161
- package/index.js +54 -54
- package/jobs/baseJobClass.js +16 -16
- package/jobs/child/app.js +58 -65
- package/jobs/child/forkProcess.js +145 -145
- package/jobs/child/index.js +82 -82
- package/jobs/child-pool/index.js +213 -213
- package/jobs/index.js +8 -8
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.js +31 -31
- package/jobs/renderer/index.js +141 -141
- package/jobs/renderer/loadView.js +40 -40
- package/jobs/unification.js +63 -63
- package/loader/index.js +172 -172
- package/log/index.js +68 -68
- package/log/logger.js +86 -80
- package/main/index.js +56 -56
- package/message/childMessage.js +54 -54
- package/message/index.js +18 -18
- package/old-utils/index.js +91 -91
- package/package.json +38 -38
- package/ps/index.js +371 -371
- package/services/baseContextClass.js +34 -34
- package/services/index.js +40 -40
- package/socket/httpServer.js +147 -147
- package/socket/index.js +81 -81
- package/socket/io.js +27 -27
- package/socket/ipcServer.js +112 -112
- package/socket/socketServer.js +69 -67
- package/storage/index.js +38 -38
- package/storage/jsondb/adapters/Base.js +23 -23
- package/storage/jsondb/adapters/FileSync.js +64 -52
- package/storage/jsondb/main.js +55 -42
- package/storage/jsondbStorage.js +195 -195
- package/storage/sqliteStorage.js +123 -123
- package/utils/co.js +237 -237
- package/utils/copyto.js +160 -160
- package/utils/depd/index.js +538 -538
- package/utils/depd/lib/browser/index.js +77 -77
- package/utils/extend.js +73 -73
- package/utils/get-port/index.d.ts +64 -64
- package/utils/get-port/index.js +148 -148
- package/utils/helper.js +220 -220
- package/utils/index.js +160 -160
- package/utils/ip.js +261 -261
- package/utils/is.js +145 -145
- package/utils/json.js +72 -72
- package/utils/pargv.js +263 -263
- package/utils/time/index.js +19 -19
- package/utils/time/ms.js +162 -162
- package/utils/wrap.js +35 -35
package/utils/ip.js
CHANGED
|
@@ -1,261 +1,261 @@
|
|
|
1
|
-
const { promisify } = require('util');
|
|
2
|
-
const dgram = require('dgram');
|
|
3
|
-
const { isIPv6, isIPv4 } = require('net');
|
|
4
|
-
const dns = require('dns-socket');
|
|
5
|
-
const HttpClient = require('../httpclient');
|
|
6
|
-
|
|
7
|
-
const emptyIP = '';
|
|
8
|
-
const defaults = {
|
|
9
|
-
timeout: 3000,
|
|
10
|
-
type: 'http', // 'http' | 'dns' | 'all'
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const dnsServers = [
|
|
14
|
-
{
|
|
15
|
-
v4: {
|
|
16
|
-
servers: [
|
|
17
|
-
'208.67.222.222',
|
|
18
|
-
'208.67.220.220',
|
|
19
|
-
'208.67.222.220',
|
|
20
|
-
'208.67.220.222',
|
|
21
|
-
],
|
|
22
|
-
name: 'myip.opendns.com',
|
|
23
|
-
type: 'A',
|
|
24
|
-
},
|
|
25
|
-
v6: {
|
|
26
|
-
servers: [
|
|
27
|
-
'2620:0:ccc::2',
|
|
28
|
-
'2620:0:ccd::2',
|
|
29
|
-
],
|
|
30
|
-
name: 'myip.opendns.com',
|
|
31
|
-
type: 'AAAA',
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
const type = {
|
|
37
|
-
v4: {
|
|
38
|
-
dnsServers: dnsServers.map(({v4: {servers, ...question}}) => ({
|
|
39
|
-
servers, question,
|
|
40
|
-
})),
|
|
41
|
-
httpsUrls: [
|
|
42
|
-
'https://icanhazip.com/',
|
|
43
|
-
'https://api.ipify.org/',
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
|
-
v6: {
|
|
47
|
-
dnsServers: dnsServers.map(({v6: {servers, ...question}}) => ({
|
|
48
|
-
servers, question,
|
|
49
|
-
})),
|
|
50
|
-
httpsUrls: [
|
|
51
|
-
'https://icanhazip.com/',
|
|
52
|
-
'https://api6.ipify.org/',
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const queryDns = (version, options) => {
|
|
58
|
-
const data = type[version];
|
|
59
|
-
const socket = dns({
|
|
60
|
-
retries: 0,
|
|
61
|
-
maxQueries: 1,
|
|
62
|
-
socket: dgram.createSocket(version === 'v6' ? 'udp6' : 'udp4'),
|
|
63
|
-
timeout: options.timeout,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const socketQuery = promisify(socket.query.bind(socket));
|
|
67
|
-
const promise = (async () => {
|
|
68
|
-
for (const dnsServerInfo of data.dnsServers) {
|
|
69
|
-
const {servers, question} = dnsServerInfo;
|
|
70
|
-
for (const server of servers) {
|
|
71
|
-
if (socket.destroyed) {
|
|
72
|
-
return emptyIP;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const {name, type, transform} = question;
|
|
77
|
-
const dnsResponse = await socketQuery({questions: [{name, type}]}, 53, server);
|
|
78
|
-
|
|
79
|
-
const {
|
|
80
|
-
answers: {
|
|
81
|
-
0: {
|
|
82
|
-
data,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
} = dnsResponse;
|
|
86
|
-
const response = (typeof data === 'string' ? data : data.toString()).trim();
|
|
87
|
-
const ip = (transform && version === 'v6') ? transform(response) : response;
|
|
88
|
-
const method = version === 'v6' ? isIPv6 : isIPv4;
|
|
89
|
-
|
|
90
|
-
if (ip && method(ip)) {
|
|
91
|
-
socket.destroy();
|
|
92
|
-
return ip;
|
|
93
|
-
}
|
|
94
|
-
} catch (error) {
|
|
95
|
-
// Log.coreLogger.error('[ee-core] [utils/ip] queryDns error:', error);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
socket.destroy();
|
|
101
|
-
return emptyIP;
|
|
102
|
-
})();
|
|
103
|
-
|
|
104
|
-
promise.cancel = () => {
|
|
105
|
-
socket.destroy();
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
return promise;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const queryHttps = (version, options) => {
|
|
112
|
-
let cancel;
|
|
113
|
-
const hc = new HttpClient();
|
|
114
|
-
|
|
115
|
-
const promise = (async () => {
|
|
116
|
-
const requestOptions = {
|
|
117
|
-
method: 'GET',
|
|
118
|
-
timeout: options.timeout,
|
|
119
|
-
dataType: 'text',
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const urls = [
|
|
123
|
-
...type[version].httpsUrls,
|
|
124
|
-
...(options.fallbackUrls ?? []),
|
|
125
|
-
];
|
|
126
|
-
|
|
127
|
-
for (const url of urls) {
|
|
128
|
-
try {
|
|
129
|
-
const gotPromise = hc.request(url, requestOptions);
|
|
130
|
-
gotPromise.cancel = () => {
|
|
131
|
-
// todo
|
|
132
|
-
}
|
|
133
|
-
cancel = gotPromise.cancel;
|
|
134
|
-
|
|
135
|
-
const response = await gotPromise;
|
|
136
|
-
let result = response.status == 200 ? response.data : '';
|
|
137
|
-
const ip = result.trim();
|
|
138
|
-
|
|
139
|
-
const method = version === 'v6' ? isIPv6 : isIPv4;
|
|
140
|
-
|
|
141
|
-
if (ip && method(ip)) {
|
|
142
|
-
return ip;
|
|
143
|
-
}
|
|
144
|
-
} catch (error) {
|
|
145
|
-
//Log.coreLogger.error('[ee-core] [utils/ip] queryHttps error:', error);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return emptyIP;
|
|
150
|
-
})();
|
|
151
|
-
|
|
152
|
-
promise.cancel = function () {
|
|
153
|
-
return cancel.apply(this);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
return promise;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const queryAll = (version, options) => {
|
|
160
|
-
let cancel;
|
|
161
|
-
const promise = (async () => {
|
|
162
|
-
let response;
|
|
163
|
-
const dnsPromise = queryDns(version, options);
|
|
164
|
-
cancel = dnsPromise.cancel;
|
|
165
|
-
try {
|
|
166
|
-
response = await dnsPromise;
|
|
167
|
-
} catch {
|
|
168
|
-
const httpsPromise = queryHttps(version, options);
|
|
169
|
-
cancel = httpsPromise.cancel;
|
|
170
|
-
response = await httpsPromise;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return response;
|
|
174
|
-
})();
|
|
175
|
-
|
|
176
|
-
promise.cancel = cancel;
|
|
177
|
-
|
|
178
|
-
return promise;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 查询 public ipv4
|
|
183
|
-
*/
|
|
184
|
-
function publicIpv4(options) {
|
|
185
|
-
options = {
|
|
186
|
-
...defaults,
|
|
187
|
-
...options,
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
if (options.type == 'http') {
|
|
191
|
-
return queryHttps('v4', options);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (options.type == 'dns') {
|
|
195
|
-
return queryDns('v4', options);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return queryAll('v4', options);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 查询public ipv6
|
|
203
|
-
*/
|
|
204
|
-
function publicIpv6(options) {
|
|
205
|
-
options = {
|
|
206
|
-
...defaults,
|
|
207
|
-
...options,
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
if (options.type == 'http') {
|
|
211
|
-
return queryHttps('v6', options);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (options.type == 'dns') {
|
|
215
|
-
return queryDns('v6', options);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return queryAll('v6', options);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* todo 未来趋势是ipv6优先,以后再放开
|
|
223
|
-
*/
|
|
224
|
-
const publicIp = createPublicIp(publicIpv4, publicIpv6);
|
|
225
|
-
function createPublicIp(publicIpv4, publicIpv6) {
|
|
226
|
-
return function publicIp(options) {
|
|
227
|
-
const ipv4Promise = publicIpv4(options);
|
|
228
|
-
const ipv6Promise = publicIpv6(options);
|
|
229
|
-
|
|
230
|
-
const promise = (async () => {
|
|
231
|
-
try {
|
|
232
|
-
const ipv6 = await ipv6Promise;
|
|
233
|
-
ipv4Promise.cancel();
|
|
234
|
-
return ipv6;
|
|
235
|
-
} catch (ipv6Error) {
|
|
236
|
-
//Log.coreLogger.error('[ee-core] [utils/ip] publicIp ipv6Error:', ipv6Error);
|
|
237
|
-
try {
|
|
238
|
-
return await ipv4Promise;
|
|
239
|
-
} catch (ipv4Error) {
|
|
240
|
-
//Log.coreLogger.error('[ee-core] [utils/ip] publicIp ipv4Error:', ipv4Error);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
})();
|
|
244
|
-
|
|
245
|
-
promise.cancel = () => {
|
|
246
|
-
ipv4Promise.cancel();
|
|
247
|
-
ipv6Promise.cancel();
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
return promise;
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const IP = {
|
|
255
|
-
//publicIp,
|
|
256
|
-
publicIpv4,
|
|
257
|
-
publicIpv6
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
module.exports = IP;
|
|
261
|
-
|
|
1
|
+
const { promisify } = require('util');
|
|
2
|
+
const dgram = require('dgram');
|
|
3
|
+
const { isIPv6, isIPv4 } = require('net');
|
|
4
|
+
const dns = require('dns-socket');
|
|
5
|
+
const HttpClient = require('../httpclient');
|
|
6
|
+
|
|
7
|
+
const emptyIP = '';
|
|
8
|
+
const defaults = {
|
|
9
|
+
timeout: 3000,
|
|
10
|
+
type: 'http', // 'http' | 'dns' | 'all'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const dnsServers = [
|
|
14
|
+
{
|
|
15
|
+
v4: {
|
|
16
|
+
servers: [
|
|
17
|
+
'208.67.222.222',
|
|
18
|
+
'208.67.220.220',
|
|
19
|
+
'208.67.222.220',
|
|
20
|
+
'208.67.220.222',
|
|
21
|
+
],
|
|
22
|
+
name: 'myip.opendns.com',
|
|
23
|
+
type: 'A',
|
|
24
|
+
},
|
|
25
|
+
v6: {
|
|
26
|
+
servers: [
|
|
27
|
+
'2620:0:ccc::2',
|
|
28
|
+
'2620:0:ccd::2',
|
|
29
|
+
],
|
|
30
|
+
name: 'myip.opendns.com',
|
|
31
|
+
type: 'AAAA',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const type = {
|
|
37
|
+
v4: {
|
|
38
|
+
dnsServers: dnsServers.map(({v4: {servers, ...question}}) => ({
|
|
39
|
+
servers, question,
|
|
40
|
+
})),
|
|
41
|
+
httpsUrls: [
|
|
42
|
+
'https://icanhazip.com/',
|
|
43
|
+
'https://api.ipify.org/',
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
v6: {
|
|
47
|
+
dnsServers: dnsServers.map(({v6: {servers, ...question}}) => ({
|
|
48
|
+
servers, question,
|
|
49
|
+
})),
|
|
50
|
+
httpsUrls: [
|
|
51
|
+
'https://icanhazip.com/',
|
|
52
|
+
'https://api6.ipify.org/',
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const queryDns = (version, options) => {
|
|
58
|
+
const data = type[version];
|
|
59
|
+
const socket = dns({
|
|
60
|
+
retries: 0,
|
|
61
|
+
maxQueries: 1,
|
|
62
|
+
socket: dgram.createSocket(version === 'v6' ? 'udp6' : 'udp4'),
|
|
63
|
+
timeout: options.timeout,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const socketQuery = promisify(socket.query.bind(socket));
|
|
67
|
+
const promise = (async () => {
|
|
68
|
+
for (const dnsServerInfo of data.dnsServers) {
|
|
69
|
+
const {servers, question} = dnsServerInfo;
|
|
70
|
+
for (const server of servers) {
|
|
71
|
+
if (socket.destroyed) {
|
|
72
|
+
return emptyIP;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const {name, type, transform} = question;
|
|
77
|
+
const dnsResponse = await socketQuery({questions: [{name, type}]}, 53, server);
|
|
78
|
+
|
|
79
|
+
const {
|
|
80
|
+
answers: {
|
|
81
|
+
0: {
|
|
82
|
+
data,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
} = dnsResponse;
|
|
86
|
+
const response = (typeof data === 'string' ? data : data.toString()).trim();
|
|
87
|
+
const ip = (transform && version === 'v6') ? transform(response) : response;
|
|
88
|
+
const method = version === 'v6' ? isIPv6 : isIPv4;
|
|
89
|
+
|
|
90
|
+
if (ip && method(ip)) {
|
|
91
|
+
socket.destroy();
|
|
92
|
+
return ip;
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
// Log.coreLogger.error('[ee-core] [utils/ip] queryDns error:', error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
socket.destroy();
|
|
101
|
+
return emptyIP;
|
|
102
|
+
})();
|
|
103
|
+
|
|
104
|
+
promise.cancel = () => {
|
|
105
|
+
socket.destroy();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return promise;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const queryHttps = (version, options) => {
|
|
112
|
+
let cancel;
|
|
113
|
+
const hc = new HttpClient();
|
|
114
|
+
|
|
115
|
+
const promise = (async () => {
|
|
116
|
+
const requestOptions = {
|
|
117
|
+
method: 'GET',
|
|
118
|
+
timeout: options.timeout,
|
|
119
|
+
dataType: 'text',
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const urls = [
|
|
123
|
+
...type[version].httpsUrls,
|
|
124
|
+
...(options.fallbackUrls ?? []),
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
for (const url of urls) {
|
|
128
|
+
try {
|
|
129
|
+
const gotPromise = hc.request(url, requestOptions);
|
|
130
|
+
gotPromise.cancel = () => {
|
|
131
|
+
// todo
|
|
132
|
+
}
|
|
133
|
+
cancel = gotPromise.cancel;
|
|
134
|
+
|
|
135
|
+
const response = await gotPromise;
|
|
136
|
+
let result = response.status == 200 ? response.data : '';
|
|
137
|
+
const ip = result.trim();
|
|
138
|
+
|
|
139
|
+
const method = version === 'v6' ? isIPv6 : isIPv4;
|
|
140
|
+
|
|
141
|
+
if (ip && method(ip)) {
|
|
142
|
+
return ip;
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
//Log.coreLogger.error('[ee-core] [utils/ip] queryHttps error:', error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return emptyIP;
|
|
150
|
+
})();
|
|
151
|
+
|
|
152
|
+
promise.cancel = function () {
|
|
153
|
+
return cancel.apply(this);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
return promise;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const queryAll = (version, options) => {
|
|
160
|
+
let cancel;
|
|
161
|
+
const promise = (async () => {
|
|
162
|
+
let response;
|
|
163
|
+
const dnsPromise = queryDns(version, options);
|
|
164
|
+
cancel = dnsPromise.cancel;
|
|
165
|
+
try {
|
|
166
|
+
response = await dnsPromise;
|
|
167
|
+
} catch {
|
|
168
|
+
const httpsPromise = queryHttps(version, options);
|
|
169
|
+
cancel = httpsPromise.cancel;
|
|
170
|
+
response = await httpsPromise;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return response;
|
|
174
|
+
})();
|
|
175
|
+
|
|
176
|
+
promise.cancel = cancel;
|
|
177
|
+
|
|
178
|
+
return promise;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 查询 public ipv4
|
|
183
|
+
*/
|
|
184
|
+
function publicIpv4(options) {
|
|
185
|
+
options = {
|
|
186
|
+
...defaults,
|
|
187
|
+
...options,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
if (options.type == 'http') {
|
|
191
|
+
return queryHttps('v4', options);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (options.type == 'dns') {
|
|
195
|
+
return queryDns('v4', options);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return queryAll('v4', options);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 查询public ipv6
|
|
203
|
+
*/
|
|
204
|
+
function publicIpv6(options) {
|
|
205
|
+
options = {
|
|
206
|
+
...defaults,
|
|
207
|
+
...options,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
if (options.type == 'http') {
|
|
211
|
+
return queryHttps('v6', options);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (options.type == 'dns') {
|
|
215
|
+
return queryDns('v6', options);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return queryAll('v6', options);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* todo 未来趋势是ipv6优先,以后再放开
|
|
223
|
+
*/
|
|
224
|
+
const publicIp = createPublicIp(publicIpv4, publicIpv6);
|
|
225
|
+
function createPublicIp(publicIpv4, publicIpv6) {
|
|
226
|
+
return function publicIp(options) {
|
|
227
|
+
const ipv4Promise = publicIpv4(options);
|
|
228
|
+
const ipv6Promise = publicIpv6(options);
|
|
229
|
+
|
|
230
|
+
const promise = (async () => {
|
|
231
|
+
try {
|
|
232
|
+
const ipv6 = await ipv6Promise;
|
|
233
|
+
ipv4Promise.cancel();
|
|
234
|
+
return ipv6;
|
|
235
|
+
} catch (ipv6Error) {
|
|
236
|
+
//Log.coreLogger.error('[ee-core] [utils/ip] publicIp ipv6Error:', ipv6Error);
|
|
237
|
+
try {
|
|
238
|
+
return await ipv4Promise;
|
|
239
|
+
} catch (ipv4Error) {
|
|
240
|
+
//Log.coreLogger.error('[ee-core] [utils/ip] publicIp ipv4Error:', ipv4Error);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
})();
|
|
244
|
+
|
|
245
|
+
promise.cancel = () => {
|
|
246
|
+
ipv4Promise.cancel();
|
|
247
|
+
ipv6Promise.cancel();
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return promise;
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const IP = {
|
|
255
|
+
//publicIp,
|
|
256
|
+
publicIpv4,
|
|
257
|
+
publicIpv6
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
module.exports = IP;
|
|
261
|
+
|