@libp2p/upnp-nat 2.0.11 → 2.0.12-3650283f7
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 +4 -4
- package/dist/src/check-external-address.d.ts.map +1 -1
- package/dist/src/check-external-address.js +10 -26
- 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 +12 -47
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/upnp-nat.d.ts +11 -24
- package/dist/src/upnp-nat.d.ts.map +1 -1
- package/dist/src/upnp-nat.js +56 -175
- 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 +14 -34
- package/src/constants.ts +3 -0
- package/src/gateway-finder.ts +70 -0
- package/src/index.ts +13 -53
- package/src/upnp-nat.ts +60 -213
- package/src/upnp-port-mapper.ts +223 -0
- package/dist/typedoc-urls.json +0 -12
|
@@ -1,19 +1,19 @@
|
|
|
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
|
}
|
|
9
9
|
export interface ExternalAddressCheckerInit {
|
|
10
10
|
interval?: number;
|
|
11
11
|
timeout?: number;
|
|
12
|
-
|
|
12
|
+
onExternalAddressChange?(newExternalAddress: string): void;
|
|
13
13
|
}
|
|
14
14
|
export interface ExternalAddress {
|
|
15
15
|
getPublicIp(options?: AbortOptions): Promise<string> | string;
|
|
16
16
|
}
|
|
17
|
-
export declare function dynamicExternalAddress(components: ExternalAddressCheckerComponents, init
|
|
17
|
+
export declare function dynamicExternalAddress(components: ExternalAddressCheckerComponents, init: ExternalAddressCheckerInit): ExternalAddress;
|
|
18
18
|
export declare function staticExternalAddress(address: string): ExternalAddress;
|
|
19
19
|
//# sourceMappingURL=check-external-address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-external-address.d.ts","sourceRoot":"","sources":["../../src/check-external-address.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NotStartedError, start, stop } from '@libp2p/interface';
|
|
2
2
|
import { repeatingTask } from '@libp2p/utils/repeating-task';
|
|
3
|
-
import { multiaddr } from '@multiformats/multiaddr';
|
|
4
3
|
import pDefer from 'p-defer';
|
|
5
4
|
import { raceSignal } from 'race-signal';
|
|
6
5
|
/**
|
|
@@ -8,18 +7,18 @@ import { raceSignal } from 'race-signal';
|
|
|
8
7
|
*/
|
|
9
8
|
class ExternalAddressChecker {
|
|
10
9
|
log;
|
|
11
|
-
|
|
10
|
+
gateway;
|
|
12
11
|
addressManager;
|
|
13
12
|
started;
|
|
14
13
|
lastPublicIp;
|
|
15
14
|
lastPublicIpPromise;
|
|
16
15
|
check;
|
|
17
|
-
|
|
18
|
-
constructor(components, init
|
|
16
|
+
onExternalAddressChange;
|
|
17
|
+
constructor(components, init) {
|
|
19
18
|
this.log = components.logger.forComponent('libp2p:upnp-nat:external-address-check');
|
|
20
|
-
this.
|
|
19
|
+
this.gateway = components.gateway;
|
|
21
20
|
this.addressManager = components.addressManager;
|
|
22
|
-
this.
|
|
21
|
+
this.onExternalAddressChange = init.onExternalAddressChange;
|
|
23
22
|
this.started = false;
|
|
24
23
|
this.checkExternalAddress = this.checkExternalAddress.bind(this);
|
|
25
24
|
this.lastPublicIpPromise = pDefer();
|
|
@@ -33,7 +32,6 @@ class ExternalAddressChecker {
|
|
|
33
32
|
return;
|
|
34
33
|
}
|
|
35
34
|
await start(this.check);
|
|
36
|
-
this.check.start();
|
|
37
35
|
this.started = true;
|
|
38
36
|
}
|
|
39
37
|
async stop() {
|
|
@@ -53,32 +51,18 @@ class ExternalAddressChecker {
|
|
|
53
51
|
}
|
|
54
52
|
async checkExternalAddress(options) {
|
|
55
53
|
try {
|
|
56
|
-
const externalAddress = await this.
|
|
54
|
+
const externalAddress = await this.gateway.externalIp(options);
|
|
57
55
|
// check if our public address has changed
|
|
58
56
|
if (this.lastPublicIp != null && externalAddress !== this.lastPublicIp) {
|
|
59
57
|
this.log('external address changed from %s to %s', this.lastPublicIp, externalAddress);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!addrString.includes(this.lastPublicIp)) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
// create a new version of the multiaddr with the new public IP
|
|
66
|
-
const newAddress = multiaddr(addrString.replace(this.lastPublicIp, externalAddress));
|
|
67
|
-
// remove the old address and add the new one
|
|
68
|
-
this.addressManager.removeObservedAddr(ma);
|
|
69
|
-
this.addressManager.confirmObservedAddr(newAddress);
|
|
70
|
-
if (this.autoConfirmAddress) {
|
|
71
|
-
this.addressManager.confirmObservedAddr(newAddress);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
this.addressManager.addObservedAddr(newAddress);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
58
|
+
// notify listeners that the address has changed
|
|
59
|
+
this.onExternalAddressChange?.(externalAddress);
|
|
77
60
|
}
|
|
78
61
|
this.lastPublicIp = externalAddress;
|
|
79
62
|
this.lastPublicIpPromise.resolve(externalAddress);
|
|
80
63
|
}
|
|
81
64
|
catch (err) {
|
|
65
|
+
this.log.error('could not resolve external address - %e', err);
|
|
82
66
|
if (this.lastPublicIp != null) {
|
|
83
67
|
// ignore the error if we've previously run successfully
|
|
84
68
|
return;
|
|
@@ -87,7 +71,7 @@ class ExternalAddressChecker {
|
|
|
87
71
|
}
|
|
88
72
|
}
|
|
89
73
|
}
|
|
90
|
-
export function dynamicExternalAddress(components, init
|
|
74
|
+
export function dynamicExternalAddress(components, init) {
|
|
91
75
|
return new ExternalAddressChecker(components, init);
|
|
92
76
|
}
|
|
93
77
|
export function staticExternalAddress(address) {
|
|
@@ -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,
|
|
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;IAChB,cAAc,CAAgB;IACvC,OAAO,CAAS;IAChB,YAAY,CAAS;IACZ,mBAAmB,CAAyB;IAC5C,KAAK,CAAe;IACpB,uBAAuB,CAAuC;IAE/E,YAAa,UAA4C,EAAE,IAAgC;QACzF,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,wCAAwC,CAAC,CAAA;QACnF,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;QACjC,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAA;QAC/C,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,uBAAuB,CAAA;QAC3D,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QAEpB,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEhE,IAAI,CAAC,mBAAmB,GAAG,MAAM,EAAE,CAAA;QAEnC,IAAI,CAAC,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C,eAAe,CAAC,CAAA;YACjD,CAAC;YAED,IAAI,CAAC,YAAY,GAAG,eAAe,CAAA;YACnC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;QACnD,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,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,58 +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
|
-
|
|
75
|
-
/**
|
|
76
|
-
* How long UPnP port mappings should last for in seconds (minimum 1200)
|
|
77
|
-
*/
|
|
78
|
-
ttl?: number;
|
|
79
|
-
/**
|
|
80
|
-
* Whether to automatically refresh UPnP port mappings when their TTL is reached
|
|
81
|
-
*/
|
|
82
|
-
keepAlive?: boolean;
|
|
65
|
+
portMappingDescription?: string;
|
|
83
66
|
/**
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
gateway?: string;
|
|
87
|
-
/**
|
|
88
|
-
* How long in ms to wait before giving up trying to auto-detect a
|
|
89
|
-
* `urn:schemas-upnp-org:device:InternetGatewayDevice:1` device on the local
|
|
90
|
-
* network
|
|
67
|
+
* How long UPnP port mappings should last for in ms
|
|
91
68
|
*
|
|
92
|
-
* @default
|
|
69
|
+
* @default 720_000
|
|
93
70
|
*/
|
|
94
|
-
|
|
71
|
+
portMappingTTL?: number;
|
|
95
72
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* multiple addresses are being added, the mapping function is debounced by
|
|
99
|
-
* this number of ms
|
|
73
|
+
* Whether to automatically refresh UPnP port mappings when their TTL is
|
|
74
|
+
* reached
|
|
100
75
|
*
|
|
101
|
-
* @default
|
|
76
|
+
* @default true
|
|
102
77
|
*/
|
|
103
|
-
|
|
78
|
+
portMappingAutoRefresh?: boolean;
|
|
104
79
|
/**
|
|
105
80
|
* A preconfigured instance of a NatAPI client can be passed as an option,
|
|
106
81
|
* otherwise one will be created
|
|
107
82
|
*/
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Any mapped addresses are added to the observed address list. These
|
|
111
|
-
* addresses require additional verification by the `@libp2p/autonat` protocol
|
|
112
|
-
* or similar before they are trusted.
|
|
113
|
-
*
|
|
114
|
-
* To skip this verification and trust them immediately pass `true` here
|
|
115
|
-
*
|
|
116
|
-
* @default false
|
|
117
|
-
*/
|
|
118
|
-
autoConfirmAddress?: boolean;
|
|
83
|
+
portMappingClient?: UPnPNATClient;
|
|
119
84
|
}
|
|
120
85
|
export interface UPnPNATComponents {
|
|
121
86
|
peerId: PeerId;
|
|
@@ -125,7 +90,7 @@ export interface UPnPNATComponents {
|
|
|
125
90
|
events: TypedEventTarget<Libp2pEvents>;
|
|
126
91
|
}
|
|
127
92
|
export interface UPnPNAT {
|
|
128
|
-
|
|
93
|
+
portMappingClient: UPnPNATClient;
|
|
129
94
|
}
|
|
130
95
|
export declare function uPnPNAT(init?: UPnPNATInit): (components: UPnPNATComponents) => UPnPNAT;
|
|
131
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;
|
|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
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,40 +1,27 @@
|
|
|
1
|
-
import { serviceCapabilities
|
|
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 localAddress?;
|
|
12
|
-
private readonly description;
|
|
13
|
-
private readonly ttl;
|
|
14
|
-
private readonly keepAlive;
|
|
15
|
-
private readonly gateway?;
|
|
16
|
-
private started;
|
|
17
6
|
private readonly log;
|
|
18
|
-
private readonly
|
|
19
|
-
private readonly
|
|
20
|
-
private
|
|
21
|
-
|
|
7
|
+
private readonly components;
|
|
8
|
+
private readonly init;
|
|
9
|
+
private started;
|
|
10
|
+
portMappingClient: UPnPNATClient;
|
|
11
|
+
private shutdownController?;
|
|
12
|
+
private readonly mapIpAddressesDebounced;
|
|
13
|
+
private readonly gatewayFinder;
|
|
14
|
+
private readonly portMappers;
|
|
22
15
|
constructor(components: UPnPNATComponents, init: UPnPNATInit);
|
|
23
16
|
readonly [Symbol.toStringTag] = "@libp2p/upnp-nat";
|
|
24
17
|
readonly [serviceCapabilities]: string[];
|
|
25
|
-
get [serviceDependencies](): string[];
|
|
26
18
|
isStarted(): boolean;
|
|
27
19
|
start(): Promise<void>;
|
|
28
20
|
/**
|
|
29
21
|
* Stops the NAT manager
|
|
30
22
|
*/
|
|
31
23
|
stop(): Promise<void>;
|
|
32
|
-
|
|
33
|
-
private getUnmappedAddresses;
|
|
24
|
+
onGatewayDiscovered(event: CustomEvent<Gateway>): void;
|
|
34
25
|
mapIpAddresses(): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Some ISPs have double-NATs, there's not much we can do with them
|
|
37
|
-
*/
|
|
38
|
-
private assertNotBehindDoubleNAT;
|
|
39
26
|
}
|
|
40
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,EA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