@libp2p/upnp-nat 2.0.12 → 3.0.0-127abe24b
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 +17 -30
- package/dist/src/check-external-address.js.map +1 -1
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +3 -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 +53 -0
- package/dist/src/gateway-finder.js.map +1 -0
- package/dist/src/index.d.ts +16 -35
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/upnp-nat.d.ts +10 -21
- package/dist/src/upnp-nat.d.ts.map +1 -1
- package/dist/src/upnp-nat.js +58 -165
- package/dist/src/upnp-nat.js.map +1 -1
- package/dist/src/upnp-port-mapper.d.ts +42 -0
- package/dist/src/upnp-port-mapper.d.ts.map +1 -0
- package/dist/src/upnp-port-mapper.js +179 -0
- package/dist/src/upnp-port-mapper.js.map +1 -0
- package/package.json +11 -11
- package/src/check-external-address.ts +24 -40
- package/src/constants.ts +2 -0
- package/src/gateway-finder.ts +75 -0
- package/src/index.ts +17 -39
- package/src/upnp-nat.ts +62 -201
- package/src/upnp-port-mapper.ts +242 -0
- package/LICENSE +0 -4
- 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;AA0FD,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,21 +7,20 @@ 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
|
-
this.lastPublicIpPromise = pDefer();
|
|
26
24
|
this.check = repeatingTask(this.checkExternalAddress, init.interval ?? 30000, {
|
|
27
25
|
timeout: init.timeout ?? 10000,
|
|
28
26
|
runImmediately: true
|
|
@@ -33,7 +31,6 @@ class ExternalAddressChecker {
|
|
|
33
31
|
return;
|
|
34
32
|
}
|
|
35
33
|
await start(this.check);
|
|
36
|
-
this.check.start();
|
|
37
34
|
this.started = true;
|
|
38
35
|
}
|
|
39
36
|
async stop() {
|
|
@@ -47,47 +44,37 @@ class ExternalAddressChecker {
|
|
|
47
44
|
if (!this.started) {
|
|
48
45
|
throw new NotStartedError('Not started yet');
|
|
49
46
|
}
|
|
50
|
-
|
|
47
|
+
if (this.lastPublicIp != null) {
|
|
48
|
+
return this.lastPublicIp;
|
|
49
|
+
}
|
|
50
|
+
this.lastPublicIpPromise = pDefer();
|
|
51
|
+
return raceSignal(this.lastPublicIpPromise.promise, options?.signal, {
|
|
51
52
|
errorMessage: 'Requesting the public IP from the network gateway timed out - UPnP may not be enabled'
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
55
|
async checkExternalAddress(options) {
|
|
55
56
|
try {
|
|
56
|
-
const externalAddress = await this.
|
|
57
|
+
const externalAddress = await this.gateway.externalIp(options);
|
|
57
58
|
// check if our public address has changed
|
|
58
59
|
if (this.lastPublicIp != null && externalAddress !== this.lastPublicIp) {
|
|
59
60
|
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
|
-
}
|
|
61
|
+
// notify listeners that the address has changed
|
|
62
|
+
this.onExternalAddressChange?.(externalAddress);
|
|
77
63
|
}
|
|
78
64
|
this.lastPublicIp = externalAddress;
|
|
79
|
-
this.lastPublicIpPromise
|
|
65
|
+
this.lastPublicIpPromise?.resolve(externalAddress);
|
|
80
66
|
}
|
|
81
67
|
catch (err) {
|
|
68
|
+
this.log.error('could not resolve external address - %e', err);
|
|
82
69
|
if (this.lastPublicIp != null) {
|
|
83
70
|
// ignore the error if we've previously run successfully
|
|
84
71
|
return;
|
|
85
72
|
}
|
|
86
|
-
this.lastPublicIpPromise
|
|
73
|
+
this.lastPublicIpPromise?.reject(err);
|
|
87
74
|
}
|
|
88
75
|
}
|
|
89
76
|
}
|
|
90
|
-
export function dynamicExternalAddress(components, init
|
|
77
|
+
export function dynamicExternalAddress(components, init) {
|
|
91
78
|
return new ExternalAddressChecker(components, init);
|
|
92
79
|
}
|
|
93
80
|
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;IACrB,mBAAmB,CAA0B;IACpC,KAAK,CAAe;IACpB,uBAAuB,C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O;KAC3B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,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,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;IAgCnE,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAS7B;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;CAI7B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
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({
|
|
19
|
+
...options,
|
|
20
|
+
searchInterval: 10000
|
|
21
|
+
})) {
|
|
22
|
+
if (this.gateways.some(g => {
|
|
23
|
+
return g.id === gateway.id && g.family === gateway.family;
|
|
24
|
+
})) {
|
|
25
|
+
// already seen this gateway
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
this.gateways.push(gateway);
|
|
29
|
+
this.safeDispatchEvent('gateway', {
|
|
30
|
+
detail: gateway
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}, DEFAULT_GATEWAY_SEARCH_INTERVAL, {
|
|
34
|
+
runImmediately: true,
|
|
35
|
+
timeout: DEFAULT_GATEWAY_SEARCH_TIMEOUT
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async start() {
|
|
39
|
+
if (this.started) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.started = true;
|
|
43
|
+
await start(this.findGateways);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Stops the NAT manager
|
|
47
|
+
*/
|
|
48
|
+
async stop() {
|
|
49
|
+
await stop(this.findGateways);
|
|
50
|
+
this.started = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# 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,E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B,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,48 +59,34 @@ 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
|
-
*
|
|
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
|
-
* network
|
|
73
|
+
* Whether to automatically refresh UPnP port mappings when their TTL is
|
|
74
|
+
* reached
|
|
91
75
|
*
|
|
92
|
-
* @default
|
|
76
|
+
* @default true
|
|
93
77
|
*/
|
|
94
|
-
|
|
78
|
+
portMappingAutoRefresh?: boolean;
|
|
95
79
|
/**
|
|
96
|
-
*
|
|
97
|
-
* when the node's addresses change. To avoid starting to map ports while
|
|
98
|
-
* multiple addresses are being added, the mapping function is debounced by
|
|
99
|
-
* this number of ms
|
|
80
|
+
* How long before a port mapping expires to refresh it in ms
|
|
100
81
|
*
|
|
101
|
-
* @default
|
|
82
|
+
* @default 60_000
|
|
102
83
|
*/
|
|
103
|
-
|
|
84
|
+
portMappingRefreshThreshold?: number;
|
|
104
85
|
/**
|
|
105
86
|
* A preconfigured instance of a NatAPI client can be passed as an option,
|
|
106
87
|
* otherwise one will be created
|
|
107
88
|
*/
|
|
108
|
-
|
|
89
|
+
portMappingClient?: UPnPNATClient;
|
|
109
90
|
/**
|
|
110
91
|
* Any mapped addresses are added to the observed address list. These
|
|
111
92
|
* addresses require additional verification by the `@libp2p/autonat` protocol
|
|
@@ -125,7 +106,7 @@ export interface UPnPNATComponents {
|
|
|
125
106
|
events: TypedEventTarget<Libp2pEvents>;
|
|
126
107
|
}
|
|
127
108
|
export interface UPnPNAT {
|
|
128
|
-
|
|
109
|
+
portMappingClient: UPnPNATClient;
|
|
129
110
|
}
|
|
130
111
|
export declare function uPnPNAT(init?: UPnPNATInit): (components: UPnPNATComponents) => UPnPNAT;
|
|
131
112
|
//# 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;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,MAAM,CAAA;IAEpC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,aAAa,CAAA;IAEjC;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;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;AAwFvD,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,23 +1,17 @@
|
|
|
1
1
|
import { serviceCapabilities, serviceDependencies } 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
|
|
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;
|
|
21
15
|
private readonly autoConfirmAddress;
|
|
22
16
|
constructor(components: UPnPNATComponents, init: UPnPNATInit);
|
|
23
17
|
readonly [Symbol.toStringTag] = "@libp2p/upnp-nat";
|
|
@@ -29,12 +23,7 @@ export declare class UPnPNAT implements Startable, UPnPNATInterface {
|
|
|
29
23
|
* Stops the NAT manager
|
|
30
24
|
*/
|
|
31
25
|
stop(): Promise<void>;
|
|
32
|
-
|
|
33
|
-
private getUnmappedAddresses;
|
|
26
|
+
onGatewayDiscovered(event: CustomEvent<Gateway>): void;
|
|
34
27
|
mapIpAddresses(): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Some ISPs have double-NATs, there's not much we can do with them
|
|
37
|
-
*/
|
|
38
|
-
private assertNotBehindDoubleNAT;
|
|
39
28
|
}
|
|
40
29
|
//# 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,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;IAgC7D,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,sBAAqB;IAElD,QAAQ,CAAC,CA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