@libp2p/upnp-nat 3.0.5-26313e695 → 3.0.5-66c3ec5e1
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/README.md +0 -40
- package/dist/src/check-external-address.d.ts.map +1 -1
- package/dist/src/check-external-address.js +2 -0
- package/dist/src/check-external-address.js.map +1 -1
- package/dist/src/{search-gateway-finder.d.ts → gateway-finder.d.ts} +12 -7
- package/dist/src/gateway-finder.d.ts.map +1 -0
- package/dist/src/{search-gateway-finder.js → gateway-finder.js} +5 -2
- package/dist/src/gateway-finder.js.map +1 -0
- package/dist/src/index.d.ts +0 -63
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -40
- package/dist/src/index.js.map +1 -1
- package/dist/src/upnp-nat.d.ts +1 -6
- package/dist/src/upnp-nat.d.ts.map +1 -1
- package/dist/src/upnp-nat.js +11 -20
- package/dist/src/upnp-nat.js.map +1 -1
- package/dist/src/upnp-port-mapper.d.ts +0 -1
- package/dist/src/upnp-port-mapper.d.ts.map +1 -1
- package/dist/src/upnp-port-mapper.js +10 -15
- package/dist/src/upnp-port-mapper.js.map +1 -1
- package/package.json +7 -7
- package/src/check-external-address.ts +2 -0
- package/src/{search-gateway-finder.ts → gateway-finder.ts} +11 -5
- package/src/index.ts +0 -65
- package/src/upnp-nat.ts +12 -28
- package/src/upnp-port-mapper.ts +10 -16
- package/dist/src/search-gateway-finder.d.ts.map +0 -1
- package/dist/src/search-gateway-finder.js.map +0 -1
- package/dist/src/static-gateway-finder.d.ts +0 -23
- package/dist/src/static-gateway-finder.d.ts.map +0 -1
- package/dist/src/static-gateway-finder.js +0 -42
- package/dist/src/static-gateway-finder.js.map +0 -1
- package/src/static-gateway-finder.ts +0 -60
package/README.md
CHANGED
|
@@ -57,46 +57,6 @@ const node = await createLibp2p({
|
|
|
57
57
|
})
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
## Example - Manually specifying gateways and external ports
|
|
61
|
-
|
|
62
|
-
Some ISP-provided routers are underpowered and may require rebooting before
|
|
63
|
-
they will respond to SSDP M-SEARCH messages.
|
|
64
|
-
|
|
65
|
-
You can manually specify your external address and/or gateways, though note
|
|
66
|
-
that those gateways will still need to have UPnP enabled in order for libp2p
|
|
67
|
-
to configure mapping of external ports (for IPv4) and/or opening pinholes in
|
|
68
|
-
the firewall (for IPv6).
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
import { createLibp2p } from 'libp2p'
|
|
72
|
-
import { tcp } from '@libp2p/tcp'
|
|
73
|
-
import { uPnPNAT } from '@libp2p/upnp-nat'
|
|
74
|
-
|
|
75
|
-
const node = await createLibp2p({
|
|
76
|
-
addresses: {
|
|
77
|
-
listen: [
|
|
78
|
-
'/ip4/0.0.0.0/tcp/0'
|
|
79
|
-
]
|
|
80
|
-
},
|
|
81
|
-
transports: [
|
|
82
|
-
tcp()
|
|
83
|
-
],
|
|
84
|
-
services: {
|
|
85
|
-
upnpNAT: uPnPNAT({
|
|
86
|
-
// manually specify external address - this will normally be an IPv4
|
|
87
|
-
// address that the router is performing NAT with
|
|
88
|
-
externalAddress: '92.137.164.96',
|
|
89
|
-
gateways: [
|
|
90
|
-
// an IPv4 gateway
|
|
91
|
-
'http://192.168.1.1:8080/path/to/descriptor.xml',
|
|
92
|
-
// an IPv6 gateway
|
|
93
|
-
'http://[xx:xx:xx:xx]:8080/path/to/descriptor.xml'
|
|
94
|
-
]
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
```
|
|
99
|
-
|
|
100
60
|
# Install
|
|
101
61
|
|
|
102
62
|
```console
|
|
@@ -1 +1 @@
|
|
|
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,m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IAAI,EAAE,0BAA0B,GAAG,eAAe,CAEvI;AAED,wBAAgB,qBAAqB,CAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CAIvE"}
|
|
@@ -8,6 +8,7 @@ import { raceSignal } from 'race-signal';
|
|
|
8
8
|
class ExternalAddressChecker {
|
|
9
9
|
log;
|
|
10
10
|
gateway;
|
|
11
|
+
addressManager;
|
|
11
12
|
started;
|
|
12
13
|
lastPublicIp;
|
|
13
14
|
lastPublicIpPromise;
|
|
@@ -16,6 +17,7 @@ class ExternalAddressChecker {
|
|
|
16
17
|
constructor(components, init) {
|
|
17
18
|
this.log = components.logger.forComponent('libp2p:upnp-nat:external-address-check');
|
|
18
19
|
this.gateway = components.gateway;
|
|
20
|
+
this.addressManager = components.addressManager;
|
|
19
21
|
this.onExternalAddressChange = init.onExternalAddressChange;
|
|
20
22
|
this.started = false;
|
|
21
23
|
this.checkExternalAddress = this.checkExternalAddress.bind(this);
|
|
@@ -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,aAAa,CAAA;AAuBxC;;GAEG;AACH,MAAM,sBAAsB;IACT,GAAG,CAAQ;IACX,OAAO,CAAS;
|
|
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,UAA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AM,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"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { TypedEventEmitter } from '@libp2p/interface';
|
|
2
|
-
import type {
|
|
3
|
-
import type { UPnPNAT } from '@achingbrain/nat-port-mapper';
|
|
2
|
+
import type { Gateway, UPnPNAT } from '@achingbrain/nat-port-mapper';
|
|
4
3
|
import type { ComponentLogger } from '@libp2p/interface';
|
|
5
|
-
export interface
|
|
4
|
+
export interface GatewayFinderComponents {
|
|
6
5
|
logger: ComponentLogger;
|
|
7
6
|
}
|
|
8
|
-
export interface
|
|
7
|
+
export interface GatewayFinderInit {
|
|
9
8
|
portMappingClient: UPnPNAT;
|
|
10
9
|
initialSearchInterval?: number;
|
|
11
10
|
initialSearchTimeout?: number;
|
|
@@ -14,14 +13,20 @@ export interface SearchGatewayFinderInit {
|
|
|
14
13
|
searchTimeout?: number;
|
|
15
14
|
searchMessageInterval?: number;
|
|
16
15
|
}
|
|
17
|
-
export
|
|
16
|
+
export interface GatewayFinderEvents {
|
|
17
|
+
'gateway': CustomEvent<Gateway>;
|
|
18
|
+
}
|
|
19
|
+
export declare class GatewayFinder extends TypedEventEmitter<GatewayFinderEvents> {
|
|
18
20
|
private readonly log;
|
|
19
21
|
private readonly gateways;
|
|
20
22
|
private readonly findGateways;
|
|
21
23
|
private readonly portMappingClient;
|
|
22
24
|
private started;
|
|
23
|
-
constructor(components:
|
|
25
|
+
constructor(components: GatewayFinderComponents, init: GatewayFinderInit);
|
|
24
26
|
start(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Stops the NAT manager
|
|
29
|
+
*/
|
|
25
30
|
stop(): Promise<void>;
|
|
26
31
|
}
|
|
27
|
-
//# sourceMappingURL=
|
|
32
|
+
//# 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;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,4BAA4B,CAAC,EAAE,MAAM,CAAA;IACrC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;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;IAmDnE,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAS7B;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;CAI7B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedEventEmitter, start, stop } from '@libp2p/interface';
|
|
2
2
|
import { repeatingTask } from '@libp2p/utils/repeating-task';
|
|
3
3
|
import { DEFAULT_GATEWAY_SEARCH_INTERVAL, DEFAULT_GATEWAY_SEARCH_MESSAGE_INTERVAL, DEFAULT_GATEWAY_SEARCH_TIMEOUT, DEFAULT_INITIAL_GATEWAY_SEARCH_INTERVAL, DEFAULT_INITIAL_GATEWAY_SEARCH_MESSAGE_INTERVAL, DEFAULT_INITIAL_GATEWAY_SEARCH_TIMEOUT } from './constants.js';
|
|
4
|
-
export class
|
|
4
|
+
export class GatewayFinder extends TypedEventEmitter {
|
|
5
5
|
log;
|
|
6
6
|
gateways;
|
|
7
7
|
findGateways;
|
|
@@ -58,9 +58,12 @@ export class SearchGatewayFinder extends TypedEventEmitter {
|
|
|
58
58
|
this.started = true;
|
|
59
59
|
await start(this.findGateways);
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Stops the NAT manager
|
|
63
|
+
*/
|
|
61
64
|
async stop() {
|
|
62
65
|
await stop(this.findGateways);
|
|
63
66
|
this.started = false;
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
|
-
//# sourceMappingURL=
|
|
69
|
+
//# 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,uCAAuC,EAAE,8BAA8B,EAAE,uCAAuC,EAAE,+CAA+C,EAAE,sCAAsC,EAAE,MAAM,gBAAgB,CAAA;AAuB3Q,MAAM,OAAO,aAAc,SAAQ,iBAAsC;I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* })
|
|
35
35
|
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example Manually specifying gateways and external ports
|
|
38
|
-
*
|
|
39
|
-
* Some ISP-provided routers are underpowered and may require rebooting before
|
|
40
|
-
* they will respond to SSDP M-SEARCH messages.
|
|
41
|
-
*
|
|
42
|
-
* You can manually specify your external address and/or gateways, though note
|
|
43
|
-
* that those gateways will still need to have UPnP enabled in order for libp2p
|
|
44
|
-
* to configure mapping of external ports (for IPv4) and/or opening pinholes in
|
|
45
|
-
* the firewall (for IPv6).
|
|
46
|
-
*
|
|
47
|
-
* ```typescript
|
|
48
|
-
* import { createLibp2p } from 'libp2p'
|
|
49
|
-
* import { tcp } from '@libp2p/tcp'
|
|
50
|
-
* import { uPnPNAT } from '@libp2p/upnp-nat'
|
|
51
|
-
*
|
|
52
|
-
* const node = await createLibp2p({
|
|
53
|
-
* addresses: {
|
|
54
|
-
* listen: [
|
|
55
|
-
* '/ip4/0.0.0.0/tcp/0'
|
|
56
|
-
* ]
|
|
57
|
-
* },
|
|
58
|
-
* transports: [
|
|
59
|
-
* tcp()
|
|
60
|
-
* ],
|
|
61
|
-
* services: {
|
|
62
|
-
* upnpNAT: uPnPNAT({
|
|
63
|
-
* // manually specify external address - this will normally be an IPv4
|
|
64
|
-
* // address that the router is performing NAT with
|
|
65
|
-
* externalAddress: '92.137.164.96',
|
|
66
|
-
* gateways: [
|
|
67
|
-
* // an IPv4 gateway
|
|
68
|
-
* 'http://192.168.1.1:8080/path/to/descriptor.xml',
|
|
69
|
-
* // an IPv6 gateway
|
|
70
|
-
* 'http://[xx:xx:xx:xx]:8080/path/to/descriptor.xml'
|
|
71
|
-
* ]
|
|
72
|
-
* })
|
|
73
|
-
* }
|
|
74
|
-
* })
|
|
75
|
-
* ```
|
|
76
36
|
*/
|
|
77
37
|
import type { UPnPNAT as UPnPNATClient, MapPortOptions } from '@achingbrain/nat-port-mapper';
|
|
78
38
|
import type { ComponentLogger, Libp2pEvents, NodeInfo, PeerId, TypedEventTarget } from '@libp2p/interface';
|
|
@@ -85,13 +45,6 @@ export interface PMPOptions {
|
|
|
85
45
|
enabled?: boolean;
|
|
86
46
|
}
|
|
87
47
|
export interface UPnPNATInit {
|
|
88
|
-
/**
|
|
89
|
-
* By default we query discovered/configured gateways for their external
|
|
90
|
-
* address. To specify it manually instead, pass a value here.
|
|
91
|
-
*
|
|
92
|
-
* Typically this would be an IPv4 address that the router performs NAT with.
|
|
93
|
-
*/
|
|
94
|
-
externalAddress?: string;
|
|
95
48
|
/**
|
|
96
49
|
* Check if the external address has changed this often in ms. Ignored if an
|
|
97
50
|
* external address is specified.
|
|
@@ -144,22 +97,6 @@ export interface UPnPNATInit {
|
|
|
144
97
|
* @default false
|
|
145
98
|
*/
|
|
146
99
|
autoConfirmAddress?: boolean;
|
|
147
|
-
/**
|
|
148
|
-
* By default we search for local gateways using SSDP M-SEARCH messages. To
|
|
149
|
-
* manually specify a gateway instead, pass values here.
|
|
150
|
-
*
|
|
151
|
-
* A lot of ISP-provided gateway/routers are underpowered so may need
|
|
152
|
-
* rebooting before they will respond to M-SEARCH messages.
|
|
153
|
-
*
|
|
154
|
-
* Each value is an IPv4 or IPv6 URL of the UPnP device descriptor document,
|
|
155
|
-
* e.g. `http://192.168.1.1:8080/description.xml`. Please see the
|
|
156
|
-
* documentation of your gateway to discover the URL.
|
|
157
|
-
*
|
|
158
|
-
* Note that some gateways will randomise the port/path the descriptor
|
|
159
|
-
* document is served from and even change it over time so you may be forced
|
|
160
|
-
* to use an SSDP search instead.
|
|
161
|
-
*/
|
|
162
|
-
gateways?: string[];
|
|
163
100
|
/**
|
|
164
101
|
* How often to search for network gateways in ms.
|
|
165
102
|
*
|
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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[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EAAE,MAAM,CAAA;CAC9B;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
CHANGED
|
@@ -33,46 +33,6 @@
|
|
|
33
33
|
* }
|
|
34
34
|
* })
|
|
35
35
|
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example Manually specifying gateways and external ports
|
|
38
|
-
*
|
|
39
|
-
* Some ISP-provided routers are underpowered and may require rebooting before
|
|
40
|
-
* they will respond to SSDP M-SEARCH messages.
|
|
41
|
-
*
|
|
42
|
-
* You can manually specify your external address and/or gateways, though note
|
|
43
|
-
* that those gateways will still need to have UPnP enabled in order for libp2p
|
|
44
|
-
* to configure mapping of external ports (for IPv4) and/or opening pinholes in
|
|
45
|
-
* the firewall (for IPv6).
|
|
46
|
-
*
|
|
47
|
-
* ```typescript
|
|
48
|
-
* import { createLibp2p } from 'libp2p'
|
|
49
|
-
* import { tcp } from '@libp2p/tcp'
|
|
50
|
-
* import { uPnPNAT } from '@libp2p/upnp-nat'
|
|
51
|
-
*
|
|
52
|
-
* const node = await createLibp2p({
|
|
53
|
-
* addresses: {
|
|
54
|
-
* listen: [
|
|
55
|
-
* '/ip4/0.0.0.0/tcp/0'
|
|
56
|
-
* ]
|
|
57
|
-
* },
|
|
58
|
-
* transports: [
|
|
59
|
-
* tcp()
|
|
60
|
-
* ],
|
|
61
|
-
* services: {
|
|
62
|
-
* upnpNAT: uPnPNAT({
|
|
63
|
-
* // manually specify external address - this will normally be an IPv4
|
|
64
|
-
* // address that the router is performing NAT with
|
|
65
|
-
* externalAddress: '92.137.164.96',
|
|
66
|
-
* gateways: [
|
|
67
|
-
* // an IPv4 gateway
|
|
68
|
-
* 'http://192.168.1.1:8080/path/to/descriptor.xml',
|
|
69
|
-
* // an IPv6 gateway
|
|
70
|
-
* 'http://[xx:xx:xx:xx]:8080/path/to/descriptor.xml'
|
|
71
|
-
* ]
|
|
72
|
-
* })
|
|
73
|
-
* }
|
|
74
|
-
* })
|
|
75
|
-
* ```
|
|
76
36
|
*/
|
|
77
37
|
import { UPnPNAT as UPnPNATClass } from './upnp-nat.js';
|
|
78
38
|
export function uPnPNAT(init = {}) {
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
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;AA4JvD,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,12 +1,7 @@
|
|
|
1
1
|
import { serviceCapabilities, serviceDependencies } from '@libp2p/interface';
|
|
2
2
|
import type { UPnPNATComponents, UPnPNATInit, UPnPNAT as UPnPNATInterface } from './index.js';
|
|
3
3
|
import type { Gateway, UPnPNAT as UPnPNATClient } from '@achingbrain/nat-port-mapper';
|
|
4
|
-
import type { Startable
|
|
5
|
-
export interface GatewayFinderEvents {
|
|
6
|
-
'gateway': CustomEvent<Gateway>;
|
|
7
|
-
}
|
|
8
|
-
export interface GatewayFinder extends TypedEventTarget<GatewayFinderEvents> {
|
|
9
|
-
}
|
|
4
|
+
import type { Startable } from '@libp2p/interface';
|
|
10
5
|
export declare class UPnPNAT implements Startable, UPnPNATInterface {
|
|
11
6
|
private readonly log;
|
|
12
7
|
private readonly components;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upnp-nat.d.ts","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAgC,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"upnp-nat.d.ts","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAgC,MAAM,mBAAmB,CAAA;AAI1G,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;IAC9C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAS;gBAE/B,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,WAAW;IAsC7D,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,sBAAqB;IAElD,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAEvC;IAED,IAAI,CAAC,mBAAmB,CAAC,IAAK,MAAM,EAAE,CAQrC;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;CAWvC"}
|
package/dist/src/upnp-nat.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { upnpNat } from '@achingbrain/nat-port-mapper';
|
|
2
2
|
import { serviceCapabilities, serviceDependencies, setMaxListeners, start, stop } from '@libp2p/interface';
|
|
3
3
|
import { debounce } from '@libp2p/utils/debounce';
|
|
4
|
-
import {
|
|
5
|
-
import { StaticGatewayFinder } from './static-gateway-finder.js';
|
|
4
|
+
import { GatewayFinder } from './gateway-finder.js';
|
|
6
5
|
import { UPnPPortMapper } from './upnp-port-mapper.js';
|
|
7
6
|
export class UPnPNAT {
|
|
8
7
|
log;
|
|
@@ -37,24 +36,16 @@ export class UPnPNAT {
|
|
|
37
36
|
this.log.error('error mapping IP addresses - %e', err);
|
|
38
37
|
}
|
|
39
38
|
}, 5_000);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
initialSearchInterval: init.initialGatewaySearchInterval,
|
|
51
|
-
initialSearchTimeout: init.initialGatewaySearchTimeout,
|
|
52
|
-
initialSearchMessageInterval: init.initialGatewaySearchMessageInterval,
|
|
53
|
-
searchInterval: init.gatewaySearchInterval,
|
|
54
|
-
searchTimeout: init.gatewaySearchTimeout,
|
|
55
|
-
searchMessageInterval: init.gatewaySearchMessageInterval
|
|
56
|
-
});
|
|
57
|
-
}
|
|
39
|
+
// trigger update when we discovery gateways on the network
|
|
40
|
+
this.gatewayFinder = new GatewayFinder(components, {
|
|
41
|
+
portMappingClient: this.portMappingClient,
|
|
42
|
+
initialSearchInterval: init.initialGatewaySearchInterval,
|
|
43
|
+
initialSearchTimeout: init.initialGatewaySearchTimeout,
|
|
44
|
+
initialSearchMessageInterval: init.initialGatewaySearchMessageInterval,
|
|
45
|
+
searchInterval: init.gatewaySearchInterval,
|
|
46
|
+
searchTimeout: init.gatewaySearchTimeout,
|
|
47
|
+
searchMessageInterval: init.gatewaySearchMessageInterval
|
|
48
|
+
});
|
|
58
49
|
this.onGatewayDiscovered = this.onGatewayDiscovered.bind(this);
|
|
59
50
|
}
|
|
60
51
|
[Symbol.toStringTag] = '@libp2p/upnp-nat';
|
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,mBAAmB,EAAE,mBAAmB,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC1G,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,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,mBAAmB,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC1G,O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;QAClB,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC;gBACzD,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;aAC5C,CAAC,CAAC,CACJ,CAAA;QACH,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAA;QACxD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -3,7 +3,6 @@ import type { ComponentLogger } from '@libp2p/interface';
|
|
|
3
3
|
import type { AddressManager } from '@libp2p/interface-internal';
|
|
4
4
|
export interface UPnPPortMapperInit {
|
|
5
5
|
gateway: Gateway;
|
|
6
|
-
externalAddress?: string;
|
|
7
6
|
externalAddressCheckInterval?: number;
|
|
8
7
|
externalAddressCheckTimeout?: number;
|
|
9
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upnp-port-mapper.d.ts","sourceRoot":"","sources":["../../src/upnp-port-mapper.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,4BAA4B,CAAA;AAK7E,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAA;IAChB,
|
|
1
|
+
{"version":3,"file":"upnp-port-mapper.d.ts","sourceRoot":"","sources":["../../src/upnp-port-mapper.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,4BAA4B,CAAA;AAK7E,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAA;IAChB,4BAA4B,CAAC,EAAE,MAAM,CAAA;IACrC,2BAA2B,CAAC,EAAE,MAAM,CAAA;CACrC;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,eAAe,CAAA;IACvB,cAAc,EAAE,cAAc,CAAA;CAC/B;AAOD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAC/C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0B;IACtD,OAAO,CAAC,OAAO,CAAS;gBAEX,UAAU,EAAE,wBAAwB,EAAE,IAAI,EAAE,kBAAkB;IAkBrE,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IASvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAe5B;;;OAGG;IACH,OAAO,CAAC,UAAU;IAalB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAiDtB,cAAc,CAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA8D/D;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAYhC,OAAO,CAAC,WAAW;CAOpB"}
|
|
@@ -6,7 +6,7 @@ import { isPrivate } from '@libp2p/utils/multiaddr/is-private';
|
|
|
6
6
|
import { isPrivateIp } from '@libp2p/utils/private-ip';
|
|
7
7
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
8
8
|
import { QUICV1, TCP, WebSockets, WebSocketsSecure, WebTransport } from '@multiformats/multiaddr-matcher';
|
|
9
|
-
import { dynamicExternalAddress
|
|
9
|
+
import { dynamicExternalAddress } from './check-external-address.js';
|
|
10
10
|
import { DoubleNATError } from './errors.js';
|
|
11
11
|
const MAX_DATE = 8_640_000_000_000_000;
|
|
12
12
|
export class UPnPPortMapper {
|
|
@@ -20,20 +20,15 @@ export class UPnPPortMapper {
|
|
|
20
20
|
this.log = components.logger.forComponent(`libp2p:upnp-nat:gateway:${init.gateway.id}`);
|
|
21
21
|
this.addressManager = components.addressManager;
|
|
22
22
|
this.gateway = init.gateway;
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
interval: init.externalAddressCheckInterval,
|
|
33
|
-
timeout: init.externalAddressCheckTimeout,
|
|
34
|
-
onExternalAddressChange: this.remapPorts.bind(this)
|
|
35
|
-
});
|
|
36
|
-
}
|
|
23
|
+
this.externalAddress = dynamicExternalAddress({
|
|
24
|
+
gateway: this.gateway,
|
|
25
|
+
addressManager: this.addressManager,
|
|
26
|
+
logger: components.logger
|
|
27
|
+
}, {
|
|
28
|
+
interval: init.externalAddressCheckInterval,
|
|
29
|
+
timeout: init.externalAddressCheckTimeout,
|
|
30
|
+
onExternalAddressChange: this.remapPorts.bind(this)
|
|
31
|
+
});
|
|
37
32
|
this.gateway = init.gateway;
|
|
38
33
|
this.mappedPorts = new Map();
|
|
39
34
|
this.started = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upnp-port-mapper.js","sourceRoot":"","sources":["../../src/upnp-port-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,oCA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vB,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACzB,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACrB,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAC/B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/upnp-nat",
|
|
3
|
-
"version": "3.0.5-
|
|
3
|
+
"version": "3.0.5-66c3ec5e1",
|
|
4
4
|
"description": "UPnP NAT hole punching",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/upnp-nat#readme",
|
|
@@ -52,18 +52,18 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@achingbrain/nat-port-mapper": "^4.0.0",
|
|
54
54
|
"@chainsafe/is-ip": "^2.0.2",
|
|
55
|
-
"@libp2p/interface": "2.4.1-
|
|
56
|
-
"@libp2p/interface-internal": "2.2.3-
|
|
57
|
-
"@libp2p/utils": "6.4.0-
|
|
55
|
+
"@libp2p/interface": "2.4.1-66c3ec5e1",
|
|
56
|
+
"@libp2p/interface-internal": "2.2.3-66c3ec5e1",
|
|
57
|
+
"@libp2p/utils": "6.4.0-66c3ec5e1",
|
|
58
58
|
"@multiformats/multiaddr": "^12.3.3",
|
|
59
59
|
"@multiformats/multiaddr-matcher": "^1.6.0",
|
|
60
60
|
"p-defer": "^4.0.1",
|
|
61
61
|
"race-signal": "^1.1.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@libp2p/crypto": "5.0.10-
|
|
65
|
-
"@libp2p/logger": "5.1.7-
|
|
66
|
-
"@libp2p/peer-id": "5.0.11-
|
|
64
|
+
"@libp2p/crypto": "5.0.10-66c3ec5e1",
|
|
65
|
+
"@libp2p/logger": "5.1.7-66c3ec5e1",
|
|
66
|
+
"@libp2p/peer-id": "5.0.11-66c3ec5e1",
|
|
67
67
|
"aegir": "^45.0.5",
|
|
68
68
|
"sinon-ts": "^2.0.0"
|
|
69
69
|
},
|
|
@@ -30,6 +30,7 @@ export interface ExternalAddress {
|
|
|
30
30
|
class ExternalAddressChecker implements ExternalAddress, Startable {
|
|
31
31
|
private readonly log: Logger
|
|
32
32
|
private readonly gateway: Gateway
|
|
33
|
+
private readonly addressManager: AddressManager
|
|
33
34
|
private started: boolean
|
|
34
35
|
private lastPublicIp?: string
|
|
35
36
|
private lastPublicIpPromise?: DeferredPromise<string>
|
|
@@ -39,6 +40,7 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
|
|
|
39
40
|
constructor (components: ExternalAddressCheckerComponents, init: ExternalAddressCheckerInit) {
|
|
40
41
|
this.log = components.logger.forComponent('libp2p:upnp-nat:external-address-check')
|
|
41
42
|
this.gateway = components.gateway
|
|
43
|
+
this.addressManager = components.addressManager
|
|
42
44
|
this.onExternalAddressChange = init.onExternalAddressChange
|
|
43
45
|
this.started = false
|
|
44
46
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { TypedEventEmitter, start, stop } from '@libp2p/interface'
|
|
2
2
|
import { repeatingTask } from '@libp2p/utils/repeating-task'
|
|
3
3
|
import { DEFAULT_GATEWAY_SEARCH_INTERVAL, DEFAULT_GATEWAY_SEARCH_MESSAGE_INTERVAL, DEFAULT_GATEWAY_SEARCH_TIMEOUT, DEFAULT_INITIAL_GATEWAY_SEARCH_INTERVAL, DEFAULT_INITIAL_GATEWAY_SEARCH_MESSAGE_INTERVAL, DEFAULT_INITIAL_GATEWAY_SEARCH_TIMEOUT } from './constants.js'
|
|
4
|
-
import type { GatewayFinder, GatewayFinderEvents } from './upnp-nat.js'
|
|
5
4
|
import type { Gateway, UPnPNAT } from '@achingbrain/nat-port-mapper'
|
|
6
5
|
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
|
7
6
|
import type { RepeatingTask } from '@libp2p/utils/repeating-task'
|
|
8
7
|
|
|
9
|
-
export interface
|
|
8
|
+
export interface GatewayFinderComponents {
|
|
10
9
|
logger: ComponentLogger
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
export interface
|
|
12
|
+
export interface GatewayFinderInit {
|
|
14
13
|
portMappingClient: UPnPNAT
|
|
15
14
|
initialSearchInterval?: number
|
|
16
15
|
initialSearchTimeout?: number
|
|
@@ -20,14 +19,18 @@ export interface SearchGatewayFinderInit {
|
|
|
20
19
|
searchMessageInterval?: number
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
export
|
|
22
|
+
export interface GatewayFinderEvents {
|
|
23
|
+
'gateway': CustomEvent<Gateway>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class GatewayFinder extends TypedEventEmitter<GatewayFinderEvents> {
|
|
24
27
|
private readonly log: Logger
|
|
25
28
|
private readonly gateways: Gateway[]
|
|
26
29
|
private readonly findGateways: RepeatingTask
|
|
27
30
|
private readonly portMappingClient: UPnPNAT
|
|
28
31
|
private started: boolean
|
|
29
32
|
|
|
30
|
-
constructor (components:
|
|
33
|
+
constructor (components: GatewayFinderComponents, init: GatewayFinderInit) {
|
|
31
34
|
super()
|
|
32
35
|
|
|
33
36
|
this.log = components.logger.forComponent('libp2p:upnp-nat')
|
|
@@ -87,6 +90,9 @@ export class SearchGatewayFinder extends TypedEventEmitter<GatewayFinderEvents>
|
|
|
87
90
|
await start(this.findGateways)
|
|
88
91
|
}
|
|
89
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Stops the NAT manager
|
|
95
|
+
*/
|
|
90
96
|
async stop (): Promise<void> {
|
|
91
97
|
await stop(this.findGateways)
|
|
92
98
|
this.started = false
|
package/src/index.ts
CHANGED
|
@@ -33,46 +33,6 @@
|
|
|
33
33
|
* }
|
|
34
34
|
* })
|
|
35
35
|
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example Manually specifying gateways and external ports
|
|
38
|
-
*
|
|
39
|
-
* Some ISP-provided routers are underpowered and may require rebooting before
|
|
40
|
-
* they will respond to SSDP M-SEARCH messages.
|
|
41
|
-
*
|
|
42
|
-
* You can manually specify your external address and/or gateways, though note
|
|
43
|
-
* that those gateways will still need to have UPnP enabled in order for libp2p
|
|
44
|
-
* to configure mapping of external ports (for IPv4) and/or opening pinholes in
|
|
45
|
-
* the firewall (for IPv6).
|
|
46
|
-
*
|
|
47
|
-
* ```typescript
|
|
48
|
-
* import { createLibp2p } from 'libp2p'
|
|
49
|
-
* import { tcp } from '@libp2p/tcp'
|
|
50
|
-
* import { uPnPNAT } from '@libp2p/upnp-nat'
|
|
51
|
-
*
|
|
52
|
-
* const node = await createLibp2p({
|
|
53
|
-
* addresses: {
|
|
54
|
-
* listen: [
|
|
55
|
-
* '/ip4/0.0.0.0/tcp/0'
|
|
56
|
-
* ]
|
|
57
|
-
* },
|
|
58
|
-
* transports: [
|
|
59
|
-
* tcp()
|
|
60
|
-
* ],
|
|
61
|
-
* services: {
|
|
62
|
-
* upnpNAT: uPnPNAT({
|
|
63
|
-
* // manually specify external address - this will normally be an IPv4
|
|
64
|
-
* // address that the router is performing NAT with
|
|
65
|
-
* externalAddress: '92.137.164.96',
|
|
66
|
-
* gateways: [
|
|
67
|
-
* // an IPv4 gateway
|
|
68
|
-
* 'http://192.168.1.1:8080/path/to/descriptor.xml',
|
|
69
|
-
* // an IPv6 gateway
|
|
70
|
-
* 'http://[xx:xx:xx:xx]:8080/path/to/descriptor.xml'
|
|
71
|
-
* ]
|
|
72
|
-
* })
|
|
73
|
-
* }
|
|
74
|
-
* })
|
|
75
|
-
* ```
|
|
76
36
|
*/
|
|
77
37
|
|
|
78
38
|
import { UPnPNAT as UPnPNATClass } from './upnp-nat.js'
|
|
@@ -90,14 +50,6 @@ export interface PMPOptions {
|
|
|
90
50
|
}
|
|
91
51
|
|
|
92
52
|
export interface UPnPNATInit {
|
|
93
|
-
/**
|
|
94
|
-
* By default we query discovered/configured gateways for their external
|
|
95
|
-
* address. To specify it manually instead, pass a value here.
|
|
96
|
-
*
|
|
97
|
-
* Typically this would be an IPv4 address that the router performs NAT with.
|
|
98
|
-
*/
|
|
99
|
-
externalAddress?: string
|
|
100
|
-
|
|
101
53
|
/**
|
|
102
54
|
* Check if the external address has changed this often in ms. Ignored if an
|
|
103
55
|
* external address is specified.
|
|
@@ -158,23 +110,6 @@ export interface UPnPNATInit {
|
|
|
158
110
|
*/
|
|
159
111
|
autoConfirmAddress?: boolean
|
|
160
112
|
|
|
161
|
-
/**
|
|
162
|
-
* By default we search for local gateways using SSDP M-SEARCH messages. To
|
|
163
|
-
* manually specify a gateway instead, pass values here.
|
|
164
|
-
*
|
|
165
|
-
* A lot of ISP-provided gateway/routers are underpowered so may need
|
|
166
|
-
* rebooting before they will respond to M-SEARCH messages.
|
|
167
|
-
*
|
|
168
|
-
* Each value is an IPv4 or IPv6 URL of the UPnP device descriptor document,
|
|
169
|
-
* e.g. `http://192.168.1.1:8080/description.xml`. Please see the
|
|
170
|
-
* documentation of your gateway to discover the URL.
|
|
171
|
-
*
|
|
172
|
-
* Note that some gateways will randomise the port/path the descriptor
|
|
173
|
-
* document is served from and even change it over time so you may be forced
|
|
174
|
-
* to use an SSDP search instead.
|
|
175
|
-
*/
|
|
176
|
-
gateways?: string[]
|
|
177
|
-
|
|
178
113
|
/**
|
|
179
114
|
* How often to search for network gateways in ms.
|
|
180
115
|
*
|
package/src/upnp-nat.ts
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { upnpNat } from '@achingbrain/nat-port-mapper'
|
|
2
2
|
import { serviceCapabilities, serviceDependencies, setMaxListeners, start, stop } from '@libp2p/interface'
|
|
3
3
|
import { debounce } from '@libp2p/utils/debounce'
|
|
4
|
-
import {
|
|
5
|
-
import { StaticGatewayFinder } from './static-gateway-finder.js'
|
|
4
|
+
import { GatewayFinder } from './gateway-finder.js'
|
|
6
5
|
import { UPnPPortMapper } from './upnp-port-mapper.js'
|
|
7
6
|
import type { UPnPNATComponents, UPnPNATInit, UPnPNAT as UPnPNATInterface } from './index.js'
|
|
8
7
|
import type { Gateway, UPnPNAT as UPnPNATClient } from '@achingbrain/nat-port-mapper'
|
|
9
|
-
import type { Logger, Startable
|
|
8
|
+
import type { Logger, Startable } from '@libp2p/interface'
|
|
10
9
|
import type { DebouncedFunction } from '@libp2p/utils/debounce'
|
|
11
10
|
|
|
12
|
-
export interface GatewayFinderEvents {
|
|
13
|
-
'gateway': CustomEvent<Gateway>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface GatewayFinder extends TypedEventTarget<GatewayFinderEvents> {
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
11
|
export class UPnPNAT implements Startable, UPnPNATInterface {
|
|
21
12
|
private readonly log: Logger
|
|
22
13
|
private readonly components: UPnPNATComponents
|
|
@@ -53,23 +44,16 @@ export class UPnPNAT implements Startable, UPnPNATInterface {
|
|
|
53
44
|
}
|
|
54
45
|
}, 5_000)
|
|
55
46
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
initialSearchTimeout: init.initialGatewaySearchTimeout,
|
|
67
|
-
initialSearchMessageInterval: init.initialGatewaySearchMessageInterval,
|
|
68
|
-
searchInterval: init.gatewaySearchInterval,
|
|
69
|
-
searchTimeout: init.gatewaySearchTimeout,
|
|
70
|
-
searchMessageInterval: init.gatewaySearchMessageInterval
|
|
71
|
-
})
|
|
72
|
-
}
|
|
47
|
+
// trigger update when we discovery gateways on the network
|
|
48
|
+
this.gatewayFinder = new GatewayFinder(components, {
|
|
49
|
+
portMappingClient: this.portMappingClient,
|
|
50
|
+
initialSearchInterval: init.initialGatewaySearchInterval,
|
|
51
|
+
initialSearchTimeout: init.initialGatewaySearchTimeout,
|
|
52
|
+
initialSearchMessageInterval: init.initialGatewaySearchMessageInterval,
|
|
53
|
+
searchInterval: init.gatewaySearchInterval,
|
|
54
|
+
searchTimeout: init.gatewaySearchTimeout,
|
|
55
|
+
searchMessageInterval: init.gatewaySearchMessageInterval
|
|
56
|
+
})
|
|
73
57
|
|
|
74
58
|
this.onGatewayDiscovered = this.onGatewayDiscovered.bind(this)
|
|
75
59
|
}
|
package/src/upnp-port-mapper.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { isPrivate } from '@libp2p/utils/multiaddr/is-private'
|
|
|
6
6
|
import { isPrivateIp } from '@libp2p/utils/private-ip'
|
|
7
7
|
import { multiaddr } from '@multiformats/multiaddr'
|
|
8
8
|
import { QUICV1, TCP, WebSockets, WebSocketsSecure, WebTransport } from '@multiformats/multiaddr-matcher'
|
|
9
|
-
import { dynamicExternalAddress
|
|
9
|
+
import { dynamicExternalAddress } from './check-external-address.js'
|
|
10
10
|
import { DoubleNATError } from './errors.js'
|
|
11
11
|
import type { ExternalAddress } from './check-external-address.js'
|
|
12
12
|
import type { Gateway } from '@achingbrain/nat-port-mapper'
|
|
@@ -18,7 +18,6 @@ const MAX_DATE = 8_640_000_000_000_000
|
|
|
18
18
|
|
|
19
19
|
export interface UPnPPortMapperInit {
|
|
20
20
|
gateway: Gateway
|
|
21
|
-
externalAddress?: string
|
|
22
21
|
externalAddressCheckInterval?: number
|
|
23
22
|
externalAddressCheckTimeout?: number
|
|
24
23
|
}
|
|
@@ -49,20 +48,15 @@ export class UPnPPortMapper {
|
|
|
49
48
|
this.log = components.logger.forComponent(`libp2p:upnp-nat:gateway:${init.gateway.id}`)
|
|
50
49
|
this.addressManager = components.addressManager
|
|
51
50
|
this.gateway = init.gateway
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
interval: init.externalAddressCheckInterval,
|
|
62
|
-
timeout: init.externalAddressCheckTimeout,
|
|
63
|
-
onExternalAddressChange: this.remapPorts.bind(this)
|
|
64
|
-
})
|
|
65
|
-
}
|
|
51
|
+
this.externalAddress = dynamicExternalAddress({
|
|
52
|
+
gateway: this.gateway,
|
|
53
|
+
addressManager: this.addressManager,
|
|
54
|
+
logger: components.logger
|
|
55
|
+
}, {
|
|
56
|
+
interval: init.externalAddressCheckInterval,
|
|
57
|
+
timeout: init.externalAddressCheckTimeout,
|
|
58
|
+
onExternalAddressChange: this.remapPorts.bind(this)
|
|
59
|
+
})
|
|
66
60
|
this.gateway = init.gateway
|
|
67
61
|
this.mappedPorts = new Map()
|
|
68
62
|
this.started = false
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-gateway-finder.d.ts","sourceRoot":"","sources":["../../src/search-gateway-finder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAe,MAAM,mBAAmB,CAAA;AAGlE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACvE,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAGhE,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,4BAA4B,CAAC,EAAE,MAAM,CAAA;IACrC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB,CAAC,mBAAmB,CAAE,YAAW,aAAa;IACtG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,Q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I,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;YACpD,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,qBAAqB,IAAI,uCAAuC,EAAE;YACxE,cAAc,EAAE,IAAI;YACpB,OAAO,EAAE,IAAI,CAAC,oBAAoB,IAAI,sCAAsC;SAC7E,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,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC7B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;IACtB,CAAC;CACF"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface';
|
|
2
|
-
import type { GatewayFinder, GatewayFinderEvents } from './upnp-nat.js';
|
|
3
|
-
import type { UPnPNAT } from '@achingbrain/nat-port-mapper';
|
|
4
|
-
import type { ComponentLogger } from '@libp2p/interface';
|
|
5
|
-
export interface StaticGatewayFinderComponents {
|
|
6
|
-
logger: ComponentLogger;
|
|
7
|
-
}
|
|
8
|
-
export interface StaticGatewayFinderInit {
|
|
9
|
-
portMappingClient: UPnPNAT;
|
|
10
|
-
gateways: string[];
|
|
11
|
-
}
|
|
12
|
-
export declare class StaticGatewayFinder extends TypedEventEmitter<GatewayFinderEvents> implements GatewayFinder {
|
|
13
|
-
private readonly log;
|
|
14
|
-
private readonly gatewayUrls;
|
|
15
|
-
private readonly gateways;
|
|
16
|
-
private readonly portMappingClient;
|
|
17
|
-
private started;
|
|
18
|
-
constructor(components: StaticGatewayFinderComponents, init: StaticGatewayFinderInit);
|
|
19
|
-
start(): Promise<void>;
|
|
20
|
-
afterStart(): Promise<void>;
|
|
21
|
-
stop(): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=static-gateway-finder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"static-gateway-finder.d.ts","sourceRoot":"","sources":["../../src/static-gateway-finder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACvE,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAEhE,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB,CAAC,mBAAmB,CAAE,YAAW,aAAa;IACtG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAO;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,OAAO,CAAS;gBAEX,UAAU,EAAE,6BAA6B,EAAE,IAAI,EAAE,uBAAuB;IAU/E,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAIvB,UAAU,IAAK,OAAO,CAAC,IAAI,CAAC;IAqB5B,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface';
|
|
2
|
-
export class StaticGatewayFinder extends TypedEventEmitter {
|
|
3
|
-
log;
|
|
4
|
-
gatewayUrls;
|
|
5
|
-
gateways;
|
|
6
|
-
portMappingClient;
|
|
7
|
-
started;
|
|
8
|
-
constructor(components, init) {
|
|
9
|
-
super();
|
|
10
|
-
this.log = components.logger.forComponent('libp2p:upnp-nat:static-gateway-finder');
|
|
11
|
-
this.portMappingClient = init.portMappingClient;
|
|
12
|
-
this.started = false;
|
|
13
|
-
this.gateways = [];
|
|
14
|
-
this.gatewayUrls = init.gateways.map(url => new URL(url));
|
|
15
|
-
}
|
|
16
|
-
async start() {
|
|
17
|
-
this.started = true;
|
|
18
|
-
}
|
|
19
|
-
async afterStart() {
|
|
20
|
-
for (const url of this.gatewayUrls) {
|
|
21
|
-
try {
|
|
22
|
-
this.log('fetching gateway descriptor from %s', url);
|
|
23
|
-
const gateway = await this.portMappingClient.getGateway(url);
|
|
24
|
-
if (!this.started) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
this.log('found static gateway at %s', url);
|
|
28
|
-
this.gateways.push(gateway);
|
|
29
|
-
this.safeDispatchEvent('gateway', {
|
|
30
|
-
detail: gateway
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
this.log.error('could not contact static gateway at %s - %e', url, err);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async stop() {
|
|
39
|
-
this.started = false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=static-gateway-finder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"static-gateway-finder.js","sourceRoot":"","sources":["../../src/static-gateway-finder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAcrD,MAAM,OAAO,mBAAoB,SAAQ,iBAAsC;IAC5D,GAAG,CAAQ;IACX,WAAW,CAAO;IAClB,QAAQ,CAAW;IACnB,iBAAiB,CAAS;IACnC,OAAO,CAAS;IAExB,YAAa,UAAyC,E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AAC,OAAO,GAAG,KAAK,CAAA;IACtB,CAAC;CACF"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface'
|
|
2
|
-
import type { GatewayFinder, GatewayFinderEvents } from './upnp-nat.js'
|
|
3
|
-
import type { Gateway, UPnPNAT } from '@achingbrain/nat-port-mapper'
|
|
4
|
-
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
|
5
|
-
|
|
6
|
-
export interface StaticGatewayFinderComponents {
|
|
7
|
-
logger: ComponentLogger
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface StaticGatewayFinderInit {
|
|
11
|
-
portMappingClient: UPnPNAT
|
|
12
|
-
gateways: string[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class StaticGatewayFinder extends TypedEventEmitter<GatewayFinderEvents> implements GatewayFinder {
|
|
16
|
-
private readonly log: Logger
|
|
17
|
-
private readonly gatewayUrls: URL[]
|
|
18
|
-
private readonly gateways: Gateway[]
|
|
19
|
-
private readonly portMappingClient: UPnPNAT
|
|
20
|
-
private started: boolean
|
|
21
|
-
|
|
22
|
-
constructor (components: StaticGatewayFinderComponents, init: StaticGatewayFinderInit) {
|
|
23
|
-
super()
|
|
24
|
-
|
|
25
|
-
this.log = components.logger.forComponent('libp2p:upnp-nat:static-gateway-finder')
|
|
26
|
-
this.portMappingClient = init.portMappingClient
|
|
27
|
-
this.started = false
|
|
28
|
-
this.gateways = []
|
|
29
|
-
this.gatewayUrls = init.gateways.map(url => new URL(url))
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async start (): Promise<void> {
|
|
33
|
-
this.started = true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async afterStart (): Promise<void> {
|
|
37
|
-
for (const url of this.gatewayUrls) {
|
|
38
|
-
try {
|
|
39
|
-
this.log('fetching gateway descriptor from %s', url)
|
|
40
|
-
const gateway = await this.portMappingClient.getGateway(url)
|
|
41
|
-
|
|
42
|
-
if (!this.started) {
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.log('found static gateway at %s', url)
|
|
47
|
-
this.gateways.push(gateway)
|
|
48
|
-
this.safeDispatchEvent('gateway', {
|
|
49
|
-
detail: gateway
|
|
50
|
-
})
|
|
51
|
-
} catch (err) {
|
|
52
|
-
this.log.error('could not contact static gateway at %s - %e', url, err)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async stop (): Promise<void> {
|
|
58
|
-
this.started = false
|
|
59
|
-
}
|
|
60
|
-
}
|