@dominevo/series-scraper-core 0.0.87 → 0.0.89
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/dist/controllers/logs.controller.d.ts +7 -6
- package/dist/controllers/logs.controller.js +26 -9
- package/dist/controllers/vpn.controller.d.ts +2 -0
- package/dist/controllers/vpn.controller.js +14 -4
- package/dist/index.d.ts +5 -0
- package/dist/index.js +10 -1
- package/dist/ports/host-info.d.ts +6 -0
- package/dist/ports/log-files.d.ts +17 -7
- package/dist/ports/log-files.js +12 -0
- package/dist/ports/log-scrub.d.ts +2 -0
- package/dist/ports/log-scrub.js +58 -0
- package/dist/ports/logger.d.ts +0 -5
- package/dist/ports/logger.js +12 -2
- package/dist/scraper.module.js +6 -0
- package/dist/services/core.service.d.ts +4 -1
- package/dist/services/core.service.js +21 -2
- package/dist/services/download.service.d.ts +3 -0
- package/dist/services/download.service.js +33 -0
- package/dist/services/egress/direct-allowance.d.ts +17 -0
- package/dist/services/egress/direct-allowance.js +14 -0
- package/dist/services/egress/egress-gate.d.ts +66 -0
- package/dist/services/egress/egress-gate.js +119 -0
- package/dist/services/egress/egress-router.d.ts +2 -0
- package/dist/services/egress/egress-router.js +5 -0
- package/dist/services/egress/firewall-policy.d.ts +3 -2
- package/dist/services/egress/firewall-policy.js +4 -3
- package/dist/services/egress/outbound-routes.d.ts +2 -0
- package/dist/services/egress/outbound-routes.js +33 -0
- package/dist/services/egress/routing-dispatcher.js +7 -0
- package/dist/services/egress/vpn-gate.guard.d.ts +8 -0
- package/dist/services/egress/vpn-gate.guard.js +35 -0
- package/dist/services/plugin-loader.service.d.ts +12 -1
- package/dist/services/plugin-loader.service.js +44 -3
- package/dist/services/plugin-network-guard.js +4 -2
- package/dist/services/vpn.service.d.ts +32 -2
- package/dist/services/vpn.service.js +216 -17
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
var VpnService_1;
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.VpnService = void 0;
|
|
17
|
+
exports.errorWithCause = errorWithCause;
|
|
17
18
|
const common_1 = require("@nestjs/common");
|
|
18
19
|
const tokens_1 = require("../ports/tokens");
|
|
19
20
|
const logger_1 = require("../ports/logger");
|
|
@@ -27,13 +28,38 @@ const exit_runtime_1 = require("./egress/exit-runtime");
|
|
|
27
28
|
const egress_context_1 = require("./egress/egress-context");
|
|
28
29
|
const host_rules_1 = require("./egress/host-rules");
|
|
29
30
|
const leak_guard_1 = require("./egress/leak-guard");
|
|
31
|
+
const egress_gate_1 = require("./egress/egress-gate");
|
|
30
32
|
const firewall_policy_1 = require("./egress/firewall-policy");
|
|
31
33
|
const routing_dispatcher_1 = require("./egress/routing-dispatcher");
|
|
32
34
|
const wireproxy_supervisor_1 = require("./egress/wireproxy-supervisor");
|
|
33
35
|
const CONTAINER_NETWORK = 'Container network';
|
|
34
36
|
const TEST_ENDPOINT = 'https://api.ipify.org?format=json';
|
|
37
|
+
/** An error with its `cause` chain ("fetch failed" alone says nothing); the logger scrubs it. */
|
|
38
|
+
function errorWithCause(err) {
|
|
39
|
+
const parts = [];
|
|
40
|
+
let current = err;
|
|
41
|
+
for (let depth = 0; depth < 4 && current !== undefined && current !== null; depth++) {
|
|
42
|
+
if (current instanceof Error) {
|
|
43
|
+
const code = 'code' in current && typeof current.code === 'string' ? ` [${current.code}]` : '';
|
|
44
|
+
parts.push(`${current.message}${code}`);
|
|
45
|
+
current = 'cause' in current ? current.cause : undefined;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
parts.push(String(current));
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return parts.join(' <- cause: ');
|
|
53
|
+
}
|
|
35
54
|
const TEST_TIMEOUT_MS = 15_000;
|
|
36
55
|
const LEAK_GUARD_INTERVAL_MS = 10 * 60 * 1000;
|
|
56
|
+
/** Hosts of a VPN provider's own API: the only ones `fetchProviderJson` reaches without a ready exit. */
|
|
57
|
+
const PROVIDER_API_HOSTS = ['api.nordvpn.com'];
|
|
58
|
+
const PROVIDER_FETCH_TIMEOUT_MS = 20_000;
|
|
59
|
+
const PROVIDER_FETCH_MAX_BYTES = 20 * 1024 * 1024;
|
|
60
|
+
/** With an exit required, a leak is found within a minute, and a closed gate asks again every 15 s. */
|
|
61
|
+
const LEAK_GUARD_REQUIRED_INTERVAL_MS = 60 * 1000;
|
|
62
|
+
const GATE_RETRY_MS = 15 * 1000;
|
|
37
63
|
const BLOCK_SWEEP_INTERVAL_MS = 5 * 60 * 1000;
|
|
38
64
|
/** Chrome would otherwise reveal the real address through WebRTC UDP, whatever the proxy. */
|
|
39
65
|
const WEBRTC_LEAK_ARGS = [
|
|
@@ -49,7 +75,7 @@ function hostOfUrl(url) {
|
|
|
49
75
|
}
|
|
50
76
|
}
|
|
51
77
|
let VpnService = VpnService_1 = class VpnService {
|
|
52
|
-
constructor(providersRepo, settingsRepo, host, binaries) {
|
|
78
|
+
constructor(providersRepo, settingsRepo, host, binaries, gate) {
|
|
53
79
|
this.providersRepo = providersRepo;
|
|
54
80
|
this.settingsRepo = settingsRepo;
|
|
55
81
|
this.host = host;
|
|
@@ -64,33 +90,43 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
64
90
|
this.directAgent = new undici_1.Agent();
|
|
65
91
|
this.tunnels = new Map();
|
|
66
92
|
this.leakFlagged = new Map();
|
|
93
|
+
/** The last leak-check answer per exit. Absent means unknown: nothing has compared its IP yet. */
|
|
94
|
+
this.verdicts = new Map();
|
|
67
95
|
this.leakGuardActive = false;
|
|
68
96
|
this.leakGuardRunning = false;
|
|
69
|
-
this.
|
|
97
|
+
this.gate = gate ?? new egress_gate_1.EgressGate(host);
|
|
98
|
+
this.settings = (0, firewall_policy_1.applyFirewallPolicy)(this.settingsRepo.get(), this.host.egressFirewall, this.gate.required);
|
|
70
99
|
this.router = new egress_router_1.EgressRouter({
|
|
71
100
|
getSettings: () => this.settings,
|
|
72
|
-
getExit: (id) => this.exits.get(id),
|
|
101
|
+
getExit: (id) => this.effective(this.exits.get(id)),
|
|
102
|
+
waiting: (host) => this.waitingFor(host),
|
|
73
103
|
blocks: this.blocks,
|
|
74
104
|
logger: this.logger,
|
|
75
105
|
});
|
|
76
106
|
this.routing = new routing_dispatcher_1.RoutingDispatcher(this.router, this.directAgent, this.logger);
|
|
77
107
|
}
|
|
78
108
|
async onApplicationBootstrap() {
|
|
109
|
+
// Every plugin calls the global fetch: routing happens here, not per call site. It is installed
|
|
110
|
+
// BEFORE any tunnel is spawned, so a request issued while the exits come up is judged by the
|
|
111
|
+
// router (refused when it has no ready exit), never sent on the direct network.
|
|
112
|
+
this.previousGlobal = (0, undici_1.getGlobalDispatcher)();
|
|
113
|
+
(0, undici_1.setGlobalDispatcher)(this.routing);
|
|
114
|
+
this.logger.log('Network egress routing installed as the global dispatcher');
|
|
79
115
|
const swept = await (0, wireproxy_supervisor_1.sweepStaleWireproxyDirs)();
|
|
80
116
|
if (swept > 0)
|
|
81
117
|
this.logger.warn(`Removed ${swept} stale wireproxy config director${swept === 1 ? 'y' : 'ies'} left by a previous run`);
|
|
82
118
|
await this.reload();
|
|
83
119
|
this.logFirewallPosture();
|
|
84
|
-
// Every plugin calls the global fetch: routing happens here, not per call site.
|
|
85
|
-
this.previousGlobal = (0, undici_1.getGlobalDispatcher)();
|
|
86
|
-
(0, undici_1.setGlobalDispatcher)(this.routing);
|
|
87
|
-
this.logger.log('Network egress routing installed as the global dispatcher');
|
|
88
120
|
this.startLeakGuard();
|
|
89
121
|
this.blockSweepTimer = setInterval(() => this.blocks.sweep(), BLOCK_SWEEP_INTERVAL_MS);
|
|
90
122
|
this.blockSweepTimer.unref();
|
|
91
123
|
}
|
|
92
124
|
/** With the egress firewall on, say so once, and shout when nothing can leave at all. */
|
|
93
125
|
logFirewallPosture() {
|
|
126
|
+
if (this.gate.required && !this.host.egressFirewall) {
|
|
127
|
+
this.logger.log('Strict mode forced on: this host requires a VPN exit before any outbound work (an application-level guarantee, there is no firewall)');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
94
130
|
if (!this.host.egressFirewall)
|
|
95
131
|
return;
|
|
96
132
|
this.logger.log('Strict mode forced on by EGRESS_FIREWALL');
|
|
@@ -103,6 +139,9 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
103
139
|
if (this.leakTimer)
|
|
104
140
|
clearInterval(this.leakTimer);
|
|
105
141
|
this.leakTimer = undefined;
|
|
142
|
+
if (this.gateRetryTimer)
|
|
143
|
+
clearInterval(this.gateRetryTimer);
|
|
144
|
+
this.gateRetryTimer = undefined;
|
|
106
145
|
if (this.blockSweepTimer)
|
|
107
146
|
clearInterval(this.blockSweepTimer);
|
|
108
147
|
this.blockSweepTimer = undefined;
|
|
@@ -166,7 +205,10 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
166
205
|
getDispatcherForExit(egressId) {
|
|
167
206
|
// An entry override beats a pinned link exit: precedence is override > pin > rules.
|
|
168
207
|
const id = egress_context_1.egressContext.current()?.egressId ?? egressId;
|
|
169
|
-
const
|
|
208
|
+
const waiting = this.waitingFor('pinned download');
|
|
209
|
+
if (waiting)
|
|
210
|
+
throw waiting;
|
|
211
|
+
const handle = this.effective(this.exits.get(id));
|
|
170
212
|
if (handle?.ready)
|
|
171
213
|
return handle.dispatcher;
|
|
172
214
|
throw this.pinnedError(id, 'pinned download');
|
|
@@ -279,6 +321,7 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
279
321
|
return;
|
|
280
322
|
this.exits = new Map(this.exits).set(id, { ...handle, ready: false, error: reason });
|
|
281
323
|
this.logger.error(`Exit "${handle.egress.name}" marked not ready: ${reason}`);
|
|
324
|
+
this.updateGate();
|
|
282
325
|
}
|
|
283
326
|
/** Leak guard recovery. Only a handle that was built live can simply be flipped back. */
|
|
284
327
|
markReady(id) {
|
|
@@ -289,6 +332,7 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
289
332
|
return;
|
|
290
333
|
this.exits = new Map(this.exits).set(id, { ...handle, ready: true, error: undefined });
|
|
291
334
|
this.logger.log(`Exit "${handle.egress.name}" is ready again`);
|
|
335
|
+
this.updateGate();
|
|
292
336
|
}
|
|
293
337
|
/** Rebuild every exit after settings or exit changes. One reload at a time. */
|
|
294
338
|
reload() {
|
|
@@ -338,12 +382,20 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
338
382
|
}
|
|
339
383
|
const previous = [...this.exits.values()];
|
|
340
384
|
const kept = new Set([...next.values()].map((h) => h.dispatcher));
|
|
341
|
-
this.settings = (0, firewall_policy_1.applyFirewallPolicy)(settings, this.host.egressFirewall);
|
|
385
|
+
this.settings = (0, firewall_policy_1.applyFirewallPolicy)(settings, this.host.egressFirewall, this.gate.required);
|
|
386
|
+
for (const id of [...this.verdicts.keys()]) {
|
|
387
|
+
const before = this.exits.get(id);
|
|
388
|
+
const after = next.get(id);
|
|
389
|
+
if (!before || !after || before.fingerprint === undefined || before.fingerprint !== after.fingerprint || before.dispatcher !== after.dispatcher) {
|
|
390
|
+
this.verdicts.delete(id);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
342
393
|
this.exits = next;
|
|
343
394
|
for (const id of [...this.leakFlagged.keys()])
|
|
344
395
|
if (!next.has(id))
|
|
345
396
|
this.leakFlagged.delete(id);
|
|
346
397
|
await this.pruneTunnels(new Set(all.map((e) => e.id)));
|
|
398
|
+
this.updateGate();
|
|
347
399
|
if (this.leakGuardActive)
|
|
348
400
|
void this.runLeakGuard();
|
|
349
401
|
// Replaced exits drain in the background: in-flight downloads finish, the mutex is not held for them.
|
|
@@ -404,10 +456,12 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
404
456
|
if (settings.defaultEgressId)
|
|
405
457
|
ids.add(settings.defaultEgressId);
|
|
406
458
|
settings.rules.forEach((r) => r.egressIds.forEach((id) => ids.add(id)));
|
|
459
|
+
if (settings.captchaFallbackEgressId)
|
|
460
|
+
ids.add(settings.captchaFallbackEgressId);
|
|
407
461
|
return [...ids];
|
|
408
462
|
}
|
|
409
463
|
pinnedError(egressId, host) {
|
|
410
|
-
const handle = this.exits.get(egressId);
|
|
464
|
+
const handle = this.effective(this.exits.get(egressId));
|
|
411
465
|
return new egress_router_1.EgressNotReadyError(egressId, handle?.egress.name ?? egressId, host, handle ? handle.error ?? 'not ready' : 'exit no longer exists');
|
|
412
466
|
}
|
|
413
467
|
/** The exit that serves `url`: the pinned one, else the one routing picks. Undefined = direct (no chain). */
|
|
@@ -415,10 +469,14 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
415
469
|
// An entry override beats a pinned link exit (override > pin > rules).
|
|
416
470
|
const egressId = egress_context_1.egressContext.current()?.egressId ?? pinnedId;
|
|
417
471
|
if (egressId) {
|
|
418
|
-
const
|
|
472
|
+
const target = hostOfUrl(url) ?? url;
|
|
473
|
+
const waiting = this.waitingFor(target);
|
|
474
|
+
if (waiting)
|
|
475
|
+
throw waiting;
|
|
476
|
+
const pinned = this.effective(this.exits.get(egressId));
|
|
419
477
|
if (pinned?.ready)
|
|
420
478
|
return pinned;
|
|
421
|
-
throw this.pinnedError(egressId,
|
|
479
|
+
throw this.pinnedError(egressId, target);
|
|
422
480
|
}
|
|
423
481
|
const host = hostOfUrl(url);
|
|
424
482
|
if (!host || (0, host_rules_1.isLocalHost)(host))
|
|
@@ -455,7 +513,7 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
455
513
|
return await this.buildLiveHandle(egress, localPort, fingerprint);
|
|
456
514
|
}
|
|
457
515
|
catch (err) {
|
|
458
|
-
const message =
|
|
516
|
+
const message = errorWithCause(err);
|
|
459
517
|
this.logger.error(`Exit "${egress.name}" setup failed: ${message}`);
|
|
460
518
|
return this.notReadyHandle(egress, `setup failed: ${message}`);
|
|
461
519
|
}
|
|
@@ -517,7 +575,7 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
517
575
|
return;
|
|
518
576
|
}
|
|
519
577
|
// The tunnel may listen on a new port: the exit is rebuilt against it, never just flipped.
|
|
520
|
-
void this.serialize(() => this.rebuildExit(egressId)).catch((err) => this.logger.error(`Exit ${egressId}: could not follow its tunnel: ${
|
|
578
|
+
void this.serialize(() => this.rebuildExit(egressId)).catch((err) => this.logger.error(`Exit ${egressId}: could not follow its tunnel: ${errorWithCause(err)}`));
|
|
521
579
|
}
|
|
522
580
|
async rebuildExit(egressId) {
|
|
523
581
|
const egress = this.providersRepo.getById(egressId);
|
|
@@ -533,6 +591,7 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
533
591
|
this.retire([current]);
|
|
534
592
|
if (live.ready)
|
|
535
593
|
this.logger.log(`Exit "${egress.name}" is ready again`);
|
|
594
|
+
this.updateGate();
|
|
536
595
|
}
|
|
537
596
|
async pruneTunnels(keep) {
|
|
538
597
|
const gone = [...this.tunnels.entries()].filter(([id]) => !keep.has(id));
|
|
@@ -544,8 +603,71 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
544
603
|
startLeakGuard() {
|
|
545
604
|
this.leakGuardActive = true;
|
|
546
605
|
void this.runLeakGuard();
|
|
547
|
-
this.leakTimer = setInterval(() => void this.runLeakGuard(), LEAK_GUARD_INTERVAL_MS);
|
|
606
|
+
this.leakTimer = setInterval(() => void this.runLeakGuard(), this.gate.required ? LEAK_GUARD_REQUIRED_INTERVAL_MS : LEAK_GUARD_INTERVAL_MS);
|
|
548
607
|
this.leakTimer.unref();
|
|
608
|
+
if (this.gate.required) {
|
|
609
|
+
// A closed gate does not wait for the next scheduled check: a verdict that came back unknown is asked again.
|
|
610
|
+
this.gateRetryTimer = setInterval(() => {
|
|
611
|
+
if (!this.gate.isOpen())
|
|
612
|
+
void this.runLeakGuard();
|
|
613
|
+
}, GATE_RETRY_MS);
|
|
614
|
+
this.gateRetryTimer.unref();
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Fetch a JSON document from a VPN provider's own API (the lookup that resolves a server for an exit).
|
|
619
|
+
* On a host that requires an exit this is the one outbound call allowed while the gate is closed: an
|
|
620
|
+
* operator with no exit yet could never create the one that opens it. It goes on the direct network,
|
|
621
|
+
* only to a provider API host, https only, bounded in time and size, and every call is logged.
|
|
622
|
+
*/
|
|
623
|
+
async fetchProviderJson(url) {
|
|
624
|
+
if (!this.gate.required) {
|
|
625
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(PROVIDER_FETCH_TIMEOUT_MS) });
|
|
626
|
+
if (!res.ok)
|
|
627
|
+
throw new Error(`${new URL(url).hostname} answered HTTP ${res.status}`);
|
|
628
|
+
return res.json();
|
|
629
|
+
}
|
|
630
|
+
const target = new URL(url);
|
|
631
|
+
if (target.protocol !== 'https:' || !PROVIDER_API_HOSTS.includes(target.hostname)) {
|
|
632
|
+
throw new Error(`${target.hostname} is not a VPN provider API host`);
|
|
633
|
+
}
|
|
634
|
+
this.logger.log(`Direct provider lookup: ${target.hostname}${target.pathname} (the only outbound call allowed without a ready exit)`);
|
|
635
|
+
// A redirect would turn this into a direct fetch of any host, so it is an error. DNS is not pinned
|
|
636
|
+
// to a known address: accepted, the call is TLS to a fixed host name.
|
|
637
|
+
const res = await (0, undici_1.fetch)(url, {
|
|
638
|
+
dispatcher: this.providerDispatcher(),
|
|
639
|
+
redirect: 'error',
|
|
640
|
+
signal: AbortSignal.timeout(PROVIDER_FETCH_TIMEOUT_MS),
|
|
641
|
+
});
|
|
642
|
+
if (!res.ok)
|
|
643
|
+
throw new Error(`${target.hostname} answered HTTP ${res.status}`);
|
|
644
|
+
const cap = this.providerMaxBytes();
|
|
645
|
+
const declared = Number(res.headers.get('content-length'));
|
|
646
|
+
if (Number.isFinite(declared) && declared > cap) {
|
|
647
|
+
await res.body?.cancel();
|
|
648
|
+
throw new Error(`${target.hostname} announced more than ${cap} bytes`);
|
|
649
|
+
}
|
|
650
|
+
const chunks = [];
|
|
651
|
+
let received = 0;
|
|
652
|
+
if (res.body) {
|
|
653
|
+
for await (const chunk of res.body) {
|
|
654
|
+
received += chunk.byteLength;
|
|
655
|
+
if (received > cap) {
|
|
656
|
+
// Leaving the loop by throwing cancels the stream.
|
|
657
|
+
throw new Error(`${target.hostname} answered more than ${cap} bytes`);
|
|
658
|
+
}
|
|
659
|
+
chunks.push(chunk);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
663
|
+
}
|
|
664
|
+
/** How many bytes a provider lookup may read. Overridable for specs. */
|
|
665
|
+
providerMaxBytes() {
|
|
666
|
+
return PROVIDER_FETCH_MAX_BYTES;
|
|
667
|
+
}
|
|
668
|
+
/** The direct network, as the leak probe uses it. Overridable for specs. */
|
|
669
|
+
providerDispatcher() {
|
|
670
|
+
return this.directAgent;
|
|
549
671
|
}
|
|
550
672
|
/** The IP the world sees for a route. Overridable; undefined when the lookup failed. */
|
|
551
673
|
async lookupEgressIp(route) {
|
|
@@ -581,6 +703,10 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
581
703
|
const id = handle.egress.id;
|
|
582
704
|
const exitIp = await this.lookupEgressIp({ kind: 'exit', egressId: id });
|
|
583
705
|
const verdict = (0, leak_guard_1.evaluateLeak)({ exitIp, directIp });
|
|
706
|
+
// A failed lookup says nothing: it never revokes a verdict a check already gave, and it
|
|
707
|
+
// never grants one. A host that requires an exit therefore stays closed until one answers.
|
|
708
|
+
if (verdict !== 'unknown')
|
|
709
|
+
this.verdicts.set(id, verdict);
|
|
584
710
|
if (verdict === 'leak' && !this.leakFlagged.has(id)) {
|
|
585
711
|
const reason = 'leak guard: this exit reports the same egress IP as the direct network';
|
|
586
712
|
this.leakFlagged.set(id, reason);
|
|
@@ -597,8 +723,80 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
597
723
|
}
|
|
598
724
|
finally {
|
|
599
725
|
this.leakGuardRunning = false;
|
|
726
|
+
this.updateGate();
|
|
600
727
|
}
|
|
601
728
|
}
|
|
729
|
+
// ── The VPN gate ───────────────────────────────────────────────────────────
|
|
730
|
+
verdictOf(id) {
|
|
731
|
+
return this.verdicts.get(id) ?? 'unknown';
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* An exit as a request may use it. On a host that requires an exit, a VPN exit serves only
|
|
735
|
+
* after the leak check has compared its IP with the direct one and found them different.
|
|
736
|
+
*/
|
|
737
|
+
effective(handle) {
|
|
738
|
+
if (!handle || !this.gate.required || handle.egress.type === 'direct' || !handle.ready)
|
|
739
|
+
return handle;
|
|
740
|
+
if (this.verdictOf(handle.egress.id) === 'ok')
|
|
741
|
+
return handle;
|
|
742
|
+
return { ...handle, ready: false, error: 'waiting for the leak check to confirm the exit IP differs from the direct one' };
|
|
743
|
+
}
|
|
744
|
+
/** The refusal for a non-local host while the gate is closed. */
|
|
745
|
+
waitingFor(host) {
|
|
746
|
+
if (this.gate.isOpen())
|
|
747
|
+
return undefined;
|
|
748
|
+
const id = this.settings.defaultEgressId ?? '';
|
|
749
|
+
return new egress_gate_1.WaitingForVpnError(id, this.exits.get(id)?.egress.name ?? 'default exit', host, this.gate.status());
|
|
750
|
+
}
|
|
751
|
+
/** The default exit's tunnel is up, its connection test passed and the leak check says `ok`. */
|
|
752
|
+
gateEvaluation() {
|
|
753
|
+
const id = this.settings.defaultEgressId;
|
|
754
|
+
if (!id)
|
|
755
|
+
return { open: false, reason: 'no default exit is configured' };
|
|
756
|
+
const handle = this.exits.get(id);
|
|
757
|
+
if (!handle)
|
|
758
|
+
return { open: false, reason: 'the default exit no longer exists' };
|
|
759
|
+
if (handle.egress.type === 'direct')
|
|
760
|
+
return { open: false, reason: `the default exit "${handle.egress.name}" is a direct connection, not a VPN` };
|
|
761
|
+
if (!handle.ready)
|
|
762
|
+
return { open: false, reason: `the default exit "${handle.egress.name}" is not ready: ${handle.error ?? 'unknown reason'}` };
|
|
763
|
+
const verdict = this.verdictOf(id);
|
|
764
|
+
if (verdict === 'leak')
|
|
765
|
+
return { open: false, reason: `the default exit "${handle.egress.name}" leaks: it reports the direct IP` };
|
|
766
|
+
if (verdict === 'unknown')
|
|
767
|
+
return { open: false, reason: `the leak check has not yet confirmed the default exit "${handle.egress.name}"` };
|
|
768
|
+
return { open: true };
|
|
769
|
+
}
|
|
770
|
+
gateExits() {
|
|
771
|
+
const roles = new Map();
|
|
772
|
+
const add = (id, role) => {
|
|
773
|
+
if (!id)
|
|
774
|
+
return;
|
|
775
|
+
const list = roles.get(id) ?? [];
|
|
776
|
+
if (!list.includes(role))
|
|
777
|
+
list.push(role);
|
|
778
|
+
roles.set(id, list);
|
|
779
|
+
};
|
|
780
|
+
add(this.settings.defaultEgressId, 'default');
|
|
781
|
+
this.settings.rules.forEach((r) => r.egressIds.forEach((id) => add(id, 'rule')));
|
|
782
|
+
add(this.settings.captchaFallbackEgressId, 'captcha');
|
|
783
|
+
return [...roles.entries()].map(([id, list]) => {
|
|
784
|
+
const handle = this.exits.get(id);
|
|
785
|
+
return {
|
|
786
|
+
id,
|
|
787
|
+
name: handle?.egress.name ?? id,
|
|
788
|
+
roles: list,
|
|
789
|
+
ready: !!handle?.ready,
|
|
790
|
+
verdict: this.verdictOf(id),
|
|
791
|
+
...(handle && !handle.ready && handle.error ? { error: handle.error } : {}),
|
|
792
|
+
};
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
updateGate() {
|
|
796
|
+
if (!this.gate.required)
|
|
797
|
+
return;
|
|
798
|
+
this.gate.evaluate(this.gateEvaluation(), this.gateExits());
|
|
799
|
+
}
|
|
602
800
|
async runTest(dispatcher) {
|
|
603
801
|
const started = Date.now();
|
|
604
802
|
try {
|
|
@@ -613,7 +811,7 @@ let VpnService = VpnService_1 = class VpnService {
|
|
|
613
811
|
return { ok: true, egressIp: body.ip, latencyMs };
|
|
614
812
|
}
|
|
615
813
|
catch (err) {
|
|
616
|
-
return { ok: false, error:
|
|
814
|
+
return { ok: false, error: errorWithCause(err), latencyMs: Date.now() - started };
|
|
617
815
|
}
|
|
618
816
|
}
|
|
619
817
|
};
|
|
@@ -622,6 +820,7 @@ exports.VpnService = VpnService = VpnService_1 = __decorate([
|
|
|
622
820
|
(0, common_1.Injectable)(),
|
|
623
821
|
__param(2, (0, common_1.Inject)(tokens_1.HOST_INFO)),
|
|
624
822
|
__param(3, (0, common_1.Inject)(tokens_1.BINARIES)),
|
|
823
|
+
__param(4, (0, common_1.Optional)()),
|
|
625
824
|
__metadata("design:paramtypes", [vpn_providers_repository_1.VpnProvidersRepository,
|
|
626
|
-
vpn_settings_repository_1.VpnSettingsRepository, Object, Object])
|
|
825
|
+
vpn_settings_repository_1.VpnSettingsRepository, Object, Object, egress_gate_1.EgressGate])
|
|
627
826
|
], VpnService);
|
package/package.json
CHANGED