@libp2p/upnp-nat 2.0.12-98b43045c → 2.0.12-b02ea9b6e
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/src/check-external-address.d.ts +2 -2
- package/dist/src/check-external-address.d.ts.map +1 -1
- package/dist/src/check-external-address.js +4 -4
- package/dist/src/check-external-address.js.map +1 -1
- package/dist/src/constants.d.ts +4 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +4 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/gateway-finder.d.ts +26 -0
- package/dist/src/gateway-finder.d.ts.map +1 -0
- package/dist/src/gateway-finder.js +48 -0
- package/dist/src/gateway-finder.js.map +1 -0
- package/dist/src/index.d.ts +13 -30
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/upnp-nat.d.ts +9 -24
- package/dist/src/upnp-nat.d.ts.map +1 -1
- package/dist/src/upnp-nat.js +52 -165
- package/dist/src/upnp-nat.js.map +1 -1
- package/dist/src/upnp-port-mapper.d.ts +38 -0
- package/dist/src/upnp-port-mapper.d.ts.map +1 -0
- package/dist/src/upnp-port-mapper.js +166 -0
- package/dist/src/upnp-port-mapper.js.map +1 -0
- package/package.json +8 -8
- package/src/check-external-address.ts +7 -8
- package/src/constants.ts +3 -0
- package/src/gateway-finder.ts +70 -0
- package/src/index.ts +14 -34
- package/src/upnp-nat.ts +57 -209
- package/src/upnp-port-mapper.ts +223 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Gateway } from '@achingbrain/nat-port-mapper';
|
|
2
2
|
import type { AbortOptions, ComponentLogger } from '@libp2p/interface';
|
|
3
3
|
import type { AddressManager } from '@libp2p/interface-internal';
|
|
4
4
|
export interface ExternalAddressCheckerComponents {
|
|
5
|
-
|
|
5
|
+
gateway: Gateway;
|
|
6
6
|
addressManager: AddressManager;
|
|
7
7
|
logger: ComponentLogger;
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-external-address.d.ts","sourceRoot":"","sources":["../../src/check-external-address.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"check-external-address.d.ts","sourceRoot":"","sources":["../../src/check-external-address.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAqB,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAIhE,MAAM,WAAW,gCAAgC;IAC/C,OAAO,EAAE,OAAO,CAAA;IAChB,cAAc,EAAE,cAAc,CAAA;IAC9B,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uBAAuB,CAAC,CAAC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3D;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;CAC/D;AAsFD,wBAAgB,sBAAsB,CAAE,UAAU,EAAE,gCAAgC,EAAE,IAAI,EAAE,0BAA0B,GAAG,eAAe,CAEvI;AAED,wBAAgB,qBAAqB,CAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CAIvE"}
|
|
@@ -7,7 +7,7 @@ import { raceSignal } from 'race-signal';
|
|
|
7
7
|
*/
|
|
8
8
|
class ExternalAddressChecker {
|
|
9
9
|
log;
|
|
10
|
-
|
|
10
|
+
gateway;
|
|
11
11
|
addressManager;
|
|
12
12
|
started;
|
|
13
13
|
lastPublicIp;
|
|
@@ -16,7 +16,7 @@ class ExternalAddressChecker {
|
|
|
16
16
|
onExternalAddressChange;
|
|
17
17
|
constructor(components, init) {
|
|
18
18
|
this.log = components.logger.forComponent('libp2p:upnp-nat:external-address-check');
|
|
19
|
-
this.
|
|
19
|
+
this.gateway = components.gateway;
|
|
20
20
|
this.addressManager = components.addressManager;
|
|
21
21
|
this.onExternalAddressChange = init.onExternalAddressChange;
|
|
22
22
|
this.started = false;
|
|
@@ -32,7 +32,6 @@ class ExternalAddressChecker {
|
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
await start(this.check);
|
|
35
|
-
this.check.start();
|
|
36
35
|
this.started = true;
|
|
37
36
|
}
|
|
38
37
|
async stop() {
|
|
@@ -52,7 +51,7 @@ class ExternalAddressChecker {
|
|
|
52
51
|
}
|
|
53
52
|
async checkExternalAddress(options) {
|
|
54
53
|
try {
|
|
55
|
-
const externalAddress = await this.
|
|
54
|
+
const externalAddress = await this.gateway.externalIp(options);
|
|
56
55
|
// check if our public address has changed
|
|
57
56
|
if (this.lastPublicIp != null && externalAddress !== this.lastPublicIp) {
|
|
58
57
|
this.log('external address changed from %s to %s', this.lastPublicIp, externalAddress);
|
|
@@ -63,6 +62,7 @@ class ExternalAddressChecker {
|
|
|
63
62
|
this.lastPublicIpPromise.resolve(externalAddress);
|
|
64
63
|
}
|
|
65
64
|
catch (err) {
|
|
65
|
+
this.log.error('could not resolve external address - %e', err);
|
|
66
66
|
if (this.lastPublicIp != null) {
|
|
67
67
|
// ignore the error if we've previously run successfully
|
|
68
68
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-external-address.js","sourceRoot":"","sources":["../../src/check-external-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,aA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CAAC,GAAG,CAAC,KAAK,CAAC,yCAAyC,EAAE,GAAG,CAAC,CAAA;YAE9D,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC;gBAC9B,wDAAwD;gBACxD,OAAM;YACR,CAAC;YAED,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,sBAAsB,CAAE,UAA4C,EAAE,IAAgC;IACpH,OAAO,IAAI,sBAAsB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACrD,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAE,OAAe;IACpD,OAAO;QACL,WAAW,EAAE,GAAG,EAAE,CAAC,OAAO;KAC3B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,SAAU,CAAA;AAC/C,eAAO,MAAM,8BAA8B,QAAS,CAAA;AACpD,eAAO,MAAM,+BAA+B,SAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAA;AAC/C,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAM,CAAA;AACpD,MAAM,CAAC,MAAM,+BAA+B,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TypedEventEmitter } from '@libp2p/interface';
|
|
2
|
+
import type { Gateway, UPnPNAT } from '@achingbrain/nat-port-mapper';
|
|
3
|
+
import type { ComponentLogger } from '@libp2p/interface';
|
|
4
|
+
export interface GatewayFinderComponents {
|
|
5
|
+
logger: ComponentLogger;
|
|
6
|
+
}
|
|
7
|
+
export interface GatewayFinderInit {
|
|
8
|
+
portMappingClient: UPnPNAT;
|
|
9
|
+
}
|
|
10
|
+
export interface GatewayFinderEvents {
|
|
11
|
+
'gateway': CustomEvent<Gateway>;
|
|
12
|
+
}
|
|
13
|
+
export declare class GatewayFinder extends TypedEventEmitter<GatewayFinderEvents> {
|
|
14
|
+
private readonly log;
|
|
15
|
+
private readonly gateways;
|
|
16
|
+
private readonly findGateways;
|
|
17
|
+
private readonly portMappingClient;
|
|
18
|
+
private started;
|
|
19
|
+
constructor(components: GatewayFinderComponents, init: GatewayFinderInit);
|
|
20
|
+
start(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Stops the NAT manager
|
|
23
|
+
*/
|
|
24
|
+
stop(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=gateway-finder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-finder.d.ts","sourceRoot":"","sources":["../../src/gateway-finder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAe,MAAM,mBAAmB,CAAA;AAGlE,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAGhE,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAChC;AAED,qBAAa,aAAc,SAAQ,iBAAiB,CAAC,mBAAmB,CAAC;IACvE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,OAAO,CAAS;gBAEX,UAAU,EAAE,uBAAuB,EAAE,IAAI,EAAE,iBAAiB;IA2BnE,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAS7B;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;CAI7B"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TypedEventEmitter, start, stop } from '@libp2p/interface';
|
|
2
|
+
import { repeatingTask } from '@libp2p/utils/repeating-task';
|
|
3
|
+
import { DEFAULT_GATEWAY_SEARCH_INTERVAL, DEFAULT_GATEWAY_SEARCH_TIMEOUT } from './constants.js';
|
|
4
|
+
export class GatewayFinder extends TypedEventEmitter {
|
|
5
|
+
log;
|
|
6
|
+
gateways;
|
|
7
|
+
findGateways;
|
|
8
|
+
portMappingClient;
|
|
9
|
+
started;
|
|
10
|
+
constructor(components, init) {
|
|
11
|
+
super();
|
|
12
|
+
this.log = components.logger.forComponent('libp2p:upnp-nat');
|
|
13
|
+
this.portMappingClient = init.portMappingClient;
|
|
14
|
+
this.started = false;
|
|
15
|
+
this.gateways = [];
|
|
16
|
+
// every five minutes, search for network gateways for one minute
|
|
17
|
+
this.findGateways = repeatingTask(async (options) => {
|
|
18
|
+
for await (const gateway of this.portMappingClient.findGateways(options)) {
|
|
19
|
+
if (this.gateways.some(g => g.id === gateway.id)) {
|
|
20
|
+
// already seen this gateway
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
this.gateways.push(gateway);
|
|
24
|
+
this.safeDispatchEvent('gateway', {
|
|
25
|
+
detail: gateway
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}, DEFAULT_GATEWAY_SEARCH_INTERVAL, {
|
|
29
|
+
runImmediately: true,
|
|
30
|
+
timeout: DEFAULT_GATEWAY_SEARCH_TIMEOUT
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async start() {
|
|
34
|
+
if (this.started) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.started = true;
|
|
38
|
+
await start(this.findGateways);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Stops the NAT manager
|
|
42
|
+
*/
|
|
43
|
+
async stop() {
|
|
44
|
+
await stop(this.findGateways);
|
|
45
|
+
this.started = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=gateway-finder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-finder.js","sourceRoot":"","sources":["../../src/gateway-finder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,+BAA+B,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAA;AAiBhG,MAAM,OAAO,aAAc,SAAQ,iBAAsC;IACtD,GAAG,CAAQ;IACX,QAAQ,CAAW;IACnB,YAAY,CAAe;IAC3B,iBAAiB,CAAS;IACnC,OAAO,CAAS;IAExB,YAAa,UAAmC,EAAE,IAAuB;QACvE,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAA;QAC5D,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAA;QAC/C,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAA;QAElB,iEAAiE;QACjE,IAAI,CAAC,YAAY,GAAG,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAClD,IAAI,KAAK,EAAE,MAAM,OAAO,IAAI,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;oBACjD,4BAA4B;oBAC5B,SAAQ;gBACV,CAAC;gBAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBAC3B,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE;oBAChC,MAAM,EAAE,OAAO;iBAChB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,EAAE,+BAA+B,EAAE;YAClC,cAAc,EAAE,IAAI;YACpB,OAAO,EAAE,8BAA8B;SACxC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAM;QACR,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,MAAM,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC7B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;IACtB,CAAC;CACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
* })
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
import {
|
|
37
|
+
import type { UPnPNAT as UPnPNATClient, MapPortOptions } from '@achingbrain/nat-port-mapper';
|
|
38
38
|
import type { ComponentLogger, Libp2pEvents, NodeInfo, PeerId, TypedEventTarget } from '@libp2p/interface';
|
|
39
39
|
import type { AddressManager } from '@libp2p/interface-internal';
|
|
40
|
-
export type {
|
|
40
|
+
export type { UPnPNATClient, MapPortOptions };
|
|
41
41
|
export interface PMPOptions {
|
|
42
42
|
/**
|
|
43
43
|
* Whether to enable PMP as well as UPnP
|
|
@@ -45,11 +45,6 @@ export interface PMPOptions {
|
|
|
45
45
|
enabled?: boolean;
|
|
46
46
|
}
|
|
47
47
|
export interface UPnPNATInit {
|
|
48
|
-
/**
|
|
49
|
-
* Pass a string to hard code the external address, otherwise it will be
|
|
50
|
-
* auto-detected
|
|
51
|
-
*/
|
|
52
|
-
externalAddress?: string;
|
|
53
48
|
/**
|
|
54
49
|
* Check if the external address has changed this often in ms. Ignored if an
|
|
55
50
|
* external address is specified.
|
|
@@ -64,40 +59,28 @@ export interface UPnPNATInit {
|
|
|
64
59
|
* @default 10000
|
|
65
60
|
*/
|
|
66
61
|
externalAddressCheckTimeout?: number;
|
|
67
|
-
/**
|
|
68
|
-
* Pass a value to use instead of auto-detection
|
|
69
|
-
*/
|
|
70
|
-
localAddress?: string;
|
|
71
62
|
/**
|
|
72
63
|
* A string value to use for the port mapping description on the gateway
|
|
73
64
|
*/
|
|
74
|
-
|
|
65
|
+
portMappingDescription?: string;
|
|
75
66
|
/**
|
|
76
|
-
* How long UPnP port mappings should last for in
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Whether to automatically refresh UPnP port mappings when their TTL is reached
|
|
81
|
-
*/
|
|
82
|
-
keepAlive?: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Pass a value to use instead of auto-detection
|
|
67
|
+
* How long UPnP port mappings should last for in ms
|
|
68
|
+
*
|
|
69
|
+
* @default 720_000
|
|
85
70
|
*/
|
|
86
|
-
|
|
71
|
+
portMappingTTL?: number;
|
|
87
72
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* multiple addresses are being added, the mapping function is debounced by
|
|
91
|
-
* this number of ms
|
|
73
|
+
* Whether to automatically refresh UPnP port mappings when their TTL is
|
|
74
|
+
* reached
|
|
92
75
|
*
|
|
93
|
-
* @default
|
|
76
|
+
* @default true
|
|
94
77
|
*/
|
|
95
|
-
|
|
78
|
+
portMappingAutoRefresh?: boolean;
|
|
96
79
|
/**
|
|
97
80
|
* A preconfigured instance of a NatAPI client can be passed as an option,
|
|
98
81
|
* otherwise one will be created
|
|
99
82
|
*/
|
|
100
|
-
|
|
83
|
+
portMappingClient?: UPnPNATClient;
|
|
101
84
|
}
|
|
102
85
|
export interface UPnPNATComponents {
|
|
103
86
|
peerId: PeerId;
|
|
@@ -107,7 +90,7 @@ export interface UPnPNATComponents {
|
|
|
107
90
|
events: TypedEventTarget<Libp2pEvents>;
|
|
108
91
|
}
|
|
109
92
|
export interface UPnPNAT {
|
|
110
|
-
|
|
93
|
+
portMappingClient: UPnPNATClient;
|
|
111
94
|
}
|
|
112
95
|
export declare function uPnPNAT(init?: UPnPNATInit): (components: UPnPNATComponents) => UPnPNAT;
|
|
113
96
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,OAAO,IAAI,aAAa,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC1G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAEhE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,CAAA;AAE7C,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAA;IAErC;;;;;OAKG;IACH,2BAA2B,CAAC,EAAE,MAAM,CAAA;IAEpC;;OAEG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAE/B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAEhC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,aAAa,CAAA;CAClC;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,cAAc,EAAE,cAAc,CAAA;IAC9B,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,OAAO;IACtB,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED,wBAAgB,OAAO,CAAE,IAAI,GAAE,WAAgB,GAAG,CAAC,UAAU,EAAE,iBAAiB,KAAK,OAAO,CAI3F"}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,OAAO,IAAI,YAAY,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,eAAe,CAAA;AAsEvD,MAAM,UAAU,OAAO,CAAE,OAAoB,EAAE;IAC7C,OAAO,CAAC,UAA6B,EAAE,EAAE;QACvC,OAAO,IAAI,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC,CAAA;AACH,CAAC"}
|
package/dist/src/upnp-nat.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { serviceCapabilities } from '@libp2p/interface';
|
|
2
2
|
import type { UPnPNATComponents, UPnPNATInit, UPnPNAT as UPnPNATInterface } from './index.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Gateway, UPnPNAT as UPnPNATClient } from '@achingbrain/nat-port-mapper';
|
|
4
4
|
import type { Startable } from '@libp2p/interface';
|
|
5
|
-
export type { NatAPI, MapPortOptions };
|
|
6
5
|
export declare class UPnPNAT implements Startable, UPnPNATInterface {
|
|
7
|
-
client: NatAPI;
|
|
8
|
-
private readonly addressManager;
|
|
9
|
-
private readonly events;
|
|
10
|
-
private readonly externalAddress;
|
|
11
|
-
private readonly description;
|
|
12
|
-
private readonly ttl;
|
|
13
|
-
private readonly keepAlive;
|
|
14
|
-
private readonly gateway?;
|
|
15
|
-
private started;
|
|
16
6
|
private readonly log;
|
|
17
|
-
private readonly
|
|
18
|
-
private readonly
|
|
7
|
+
private readonly components;
|
|
8
|
+
private readonly init;
|
|
9
|
+
private started;
|
|
10
|
+
portMappingClient: UPnPNATClient;
|
|
19
11
|
private shutdownController?;
|
|
12
|
+
private readonly mapIpAddressesDebounced;
|
|
13
|
+
private readonly gatewayFinder;
|
|
14
|
+
private readonly portMappers;
|
|
20
15
|
constructor(components: UPnPNATComponents, init: UPnPNATInit);
|
|
21
16
|
readonly [Symbol.toStringTag] = "@libp2p/upnp-nat";
|
|
22
17
|
readonly [serviceCapabilities]: string[];
|
|
@@ -26,17 +21,7 @@ export declare class UPnPNAT implements Startable, UPnPNATInterface {
|
|
|
26
21
|
* Stops the NAT manager
|
|
27
22
|
*/
|
|
28
23
|
stop(): Promise<void>;
|
|
29
|
-
|
|
30
|
-
private getUnmappedAddresses;
|
|
24
|
+
onGatewayDiscovered(event: CustomEvent<Gateway>): void;
|
|
31
25
|
mapIpAddresses(): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* Some ISPs have double-NATs, there's not much we can do with them
|
|
34
|
-
*/
|
|
35
|
-
private assertNotBehindDoubleNAT;
|
|
36
|
-
/**
|
|
37
|
-
* Update the local address mappings when the gateway's external interface
|
|
38
|
-
* address changes
|
|
39
|
-
*/
|
|
40
|
-
private remapPorts;
|
|
41
26
|
}
|
|
42
27
|
//# sourceMappingURL=upnp-nat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upnp-nat.d.ts","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upnp-nat.d.ts","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAgC,MAAM,mBAAmB,CAAA;AAKrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7F,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAA;AACrF,OAAO,KAAK,EAAU,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAG1D,qBAAa,OAAQ,YAAW,SAAS,EAAE,gBAAgB;IACzD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,OAAO,CAAS;IACjB,iBAAiB,EAAE,aAAa,CAAA;IACvC,OAAO,CAAC,kBAAkB,CAAC,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkB;gBAEjC,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,WAAW;IA8B7D,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,sBAAqB;IAElD,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAEvC;IAED,SAAS,IAAK,OAAO;IAIf,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAa7B;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAQ5B,mBAAmB,CAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI;IAejD,cAAc,IAAK,OAAO,CAAC,IAAI,CAAC;CASvC"}
|
package/dist/src/upnp-nat.js
CHANGED
|
@@ -1,62 +1,44 @@
|
|
|
1
1
|
import { upnpNat } from '@achingbrain/nat-port-mapper';
|
|
2
|
-
import {
|
|
3
|
-
import { InvalidParametersError, serviceCapabilities, setMaxListeners, start, stop } from '@libp2p/interface';
|
|
2
|
+
import { serviceCapabilities, setMaxListeners, start, stop } from '@libp2p/interface';
|
|
4
3
|
import { debounce } from '@libp2p/utils/debounce';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { QUICV1, TCP, WebSockets, WebSocketsSecure, WebTransport } from '@multiformats/multiaddr-matcher';
|
|
9
|
-
import { dynamicExternalAddress, staticExternalAddress } from './check-external-address.js';
|
|
10
|
-
import { DoubleNATError, InvalidIPAddressError } from './errors.js';
|
|
11
|
-
const DEFAULT_TTL = 7200;
|
|
4
|
+
import { DEFAULT_PORT_MAPPING_TTL } from './constants.js';
|
|
5
|
+
import { GatewayFinder } from './gateway-finder.js';
|
|
6
|
+
import { UPnPPortMapper } from './upnp-port-mapper.js';
|
|
12
7
|
export class UPnPNAT {
|
|
13
|
-
client;
|
|
14
|
-
addressManager;
|
|
15
|
-
events;
|
|
16
|
-
externalAddress;
|
|
17
|
-
description;
|
|
18
|
-
ttl;
|
|
19
|
-
keepAlive;
|
|
20
|
-
gateway;
|
|
21
|
-
started;
|
|
22
8
|
log;
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
components;
|
|
10
|
+
init;
|
|
11
|
+
started;
|
|
12
|
+
portMappingClient;
|
|
25
13
|
shutdownController;
|
|
14
|
+
mapIpAddressesDebounced;
|
|
15
|
+
gatewayFinder;
|
|
16
|
+
portMappers;
|
|
26
17
|
constructor(components, init) {
|
|
27
18
|
this.log = components.logger.forComponent('libp2p:upnp-nat');
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
19
|
+
this.components = components;
|
|
20
|
+
this.init = init;
|
|
30
21
|
this.started = false;
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (this.ttl < DEFAULT_TTL) {
|
|
37
|
-
throw new InvalidParametersError(`NatManager ttl should be at least ${DEFAULT_TTL} seconds`);
|
|
38
|
-
}
|
|
39
|
-
this.client = init.client ?? upnpNat({
|
|
40
|
-
description: this.description,
|
|
41
|
-
ttl: this.ttl,
|
|
42
|
-
keepAlive: this.keepAlive,
|
|
43
|
-
gateway: this.gateway
|
|
22
|
+
this.portMappers = [];
|
|
23
|
+
this.portMappingClient = init.portMappingClient ?? upnpNat({
|
|
24
|
+
description: init.portMappingDescription ?? `${components.nodeInfo.name}@${components.nodeInfo.version} ${components.peerId.toString()}`,
|
|
25
|
+
ttl: init.portMappingTTL ?? DEFAULT_PORT_MAPPING_TTL,
|
|
26
|
+
autoRefresh: init.portMappingAutoRefresh ?? true
|
|
44
27
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
28
|
+
// trigger update when our addresses change
|
|
29
|
+
this.mapIpAddressesDebounced = debounce(async () => {
|
|
30
|
+
try {
|
|
31
|
+
await this.mapIpAddresses();
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
this.log.error('error mapping IP addresses - %e', err);
|
|
35
|
+
}
|
|
36
|
+
}, 5_000);
|
|
37
|
+
// trigger update when we discovery gateways on the network
|
|
38
|
+
this.gatewayFinder = new GatewayFinder(components, {
|
|
39
|
+
portMappingClient: this.portMappingClient
|
|
40
|
+
});
|
|
41
|
+
this.onGatewayDiscovered = this.onGatewayDiscovered.bind(this);
|
|
60
42
|
}
|
|
61
43
|
[Symbol.toStringTag] = '@libp2p/upnp-nat';
|
|
62
44
|
[serviceCapabilities] = [
|
|
@@ -72,133 +54,38 @@ export class UPnPNAT {
|
|
|
72
54
|
this.started = true;
|
|
73
55
|
this.shutdownController = new AbortController();
|
|
74
56
|
setMaxListeners(Infinity, this.shutdownController.signal);
|
|
75
|
-
this.events.addEventListener('self:peer:update', this.
|
|
76
|
-
|
|
57
|
+
this.components.events.addEventListener('self:peer:update', this.mapIpAddressesDebounced);
|
|
58
|
+
this.gatewayFinder.addEventListener('gateway', this.onGatewayDiscovered);
|
|
59
|
+
await start(this.mapIpAddressesDebounced, this.gatewayFinder, ...this.portMappers);
|
|
77
60
|
}
|
|
78
61
|
/**
|
|
79
62
|
* Stops the NAT manager
|
|
80
63
|
*/
|
|
81
64
|
async stop() {
|
|
82
|
-
try {
|
|
83
|
-
await this.client?.close();
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
this.log.error(err);
|
|
87
|
-
}
|
|
88
65
|
this.shutdownController?.abort();
|
|
89
|
-
this.events.removeEventListener('self:peer:update', this.
|
|
90
|
-
|
|
66
|
+
this.components.events.removeEventListener('self:peer:update', this.mapIpAddressesDebounced);
|
|
67
|
+
this.gatewayFinder.removeEventListener('gateway', this.onGatewayDiscovered);
|
|
68
|
+
await stop(this.mapIpAddressesDebounced, this.gatewayFinder, ...this.portMappers);
|
|
91
69
|
this.started = false;
|
|
92
70
|
}
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
.
|
|
96
|
-
|
|
71
|
+
onGatewayDiscovered(event) {
|
|
72
|
+
const mapper = new UPnPPortMapper(this.components, {
|
|
73
|
+
...this.init,
|
|
74
|
+
gateway: event.detail
|
|
97
75
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
// ignore loopback
|
|
107
|
-
if (isLoopback(ma)) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
// only IP based addresses
|
|
111
|
-
if (!(TCP.exactMatch(ma) ||
|
|
112
|
-
WebSockets.exactMatch(ma) ||
|
|
113
|
-
WebSocketsSecure.exactMatch(ma) ||
|
|
114
|
-
QUICV1.exactMatch(ma) ||
|
|
115
|
-
WebTransport.exactMatch(ma))) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const { port, host, family, transport } = ma.toOptions();
|
|
119
|
-
if (family !== ipType) {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (this.mappedPorts.has(`${host}-${port}-${transport}`)) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
output.push(ma);
|
|
126
|
-
}
|
|
127
|
-
return output;
|
|
76
|
+
this.portMappers.push(mapper);
|
|
77
|
+
start(mapper)
|
|
78
|
+
.then(() => {
|
|
79
|
+
this.mapIpAddressesDebounced();
|
|
80
|
+
})
|
|
81
|
+
.catch(() => { });
|
|
128
82
|
}
|
|
129
83
|
async mapIpAddresses() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
133
|
-
let ipType = 4;
|
|
134
|
-
if (isIPv4(externalHost)) {
|
|
135
|
-
ipType = 4;
|
|
136
|
-
}
|
|
137
|
-
else if (isIPv6(externalHost)) {
|
|
138
|
-
ipType = 6;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
throw new InvalidIPAddressError(`Public address ${externalHost} was not an IPv4 address`);
|
|
142
|
-
}
|
|
143
|
-
// filter addresses to get private, non-relay, IP based addresses that we
|
|
144
|
-
// haven't mapped yet
|
|
145
|
-
const addresses = this.getUnmappedAddresses(this.addressManager.getAddresses(), ipType);
|
|
146
|
-
if (addresses.length === 0) {
|
|
147
|
-
this.log('no private, non-relay, unmapped, IP based addresses found');
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
this.log('%s public IP %s', this.externalAddress != null ? 'using configured' : 'discovered', externalHost);
|
|
151
|
-
this.assertNotBehindDoubleNAT(externalHost);
|
|
152
|
-
for (const addr of addresses) {
|
|
153
|
-
// try to open uPnP ports for each thin waist address
|
|
154
|
-
const { family, host, port, transport } = addr.toOptions();
|
|
155
|
-
if (family === 6) {
|
|
156
|
-
// only support IPv4 addresses
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (this.mappedPorts.has(`${host}-${port}-${transport}`)) {
|
|
160
|
-
// already mapped this port
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
this.log(`creating mapping of %s:%s key ${host}-${port}-${transport}`, host, port);
|
|
165
|
-
const externalPort = await this.client.map(port, {
|
|
166
|
-
localAddress: host,
|
|
167
|
-
protocol: transport === 'tcp' ? 'TCP' : 'UDP'
|
|
168
|
-
});
|
|
169
|
-
this.mappedPorts.set(`${host}-${port}-${transport}`, {
|
|
170
|
-
externalHost,
|
|
171
|
-
externalPort
|
|
172
|
-
});
|
|
173
|
-
this.log('created mapping of %s:%s to %s:%s', externalHost, externalPort, host, port);
|
|
174
|
-
this.addressManager.addPublicAddressMapping(host, port, externalHost, externalPort, transport === 'tcp' ? 'tcp' : 'udp');
|
|
175
|
-
}
|
|
176
|
-
catch (err) {
|
|
177
|
-
this.log.error('failed to create mapping of %s:%s - %e', host, port, err);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Some ISPs have double-NATs, there's not much we can do with them
|
|
183
|
-
*/
|
|
184
|
-
assertNotBehindDoubleNAT(publicIp) {
|
|
185
|
-
const isPrivate = isPrivateIp(publicIp);
|
|
186
|
-
if (isPrivate === true) {
|
|
187
|
-
throw new DoubleNATError(`${publicIp} is private - please init uPnPNAT with 'externalAddress' set to an externally routable IP or ensure you are not behind a double NAT`);
|
|
188
|
-
}
|
|
189
|
-
if (isPrivate == null) {
|
|
190
|
-
throw new InvalidParametersError(`${publicIp} is not an IP address`);
|
|
84
|
+
try {
|
|
85
|
+
await Promise.all(this.portMappers.map(async (mapper) => mapper.mapIpAddresses()));
|
|
191
86
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
* Update the local address mappings when the gateway's external interface
|
|
195
|
-
* address changes
|
|
196
|
-
*/
|
|
197
|
-
remapPorts(newExternalHost) {
|
|
198
|
-
for (const [key, { externalHost, externalPort }] of this.mappedPorts.entries()) {
|
|
199
|
-
const [host, port, transport] = key.split('-');
|
|
200
|
-
this.addressManager.removePublicAddressMapping(host, parseInt(port), externalHost, externalPort, transport === 'tcp' ? 'tcp' : 'udp');
|
|
201
|
-
this.addressManager.addPublicAddressMapping(host, parseInt(port), newExternalHost, externalPort, transport === 'tcp' ? 'tcp' : 'udp');
|
|
87
|
+
catch (err) {
|
|
88
|
+
this.log.error('error mapping IP addresses - %e', err);
|
|
202
89
|
}
|
|
203
90
|
}
|
|
204
91
|
}
|
package/dist/src/upnp-nat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upnp-nat.js","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AACtD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"upnp-nat.js","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAA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