@libp2p/upnp-nat 2.0.12-bc90b4fd5 → 2.0.12-d19974d93

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.
@@ -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,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC7G,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACzG,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAC3F,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AASnE,MAAM,WAAW,GAAG,IAAI,CAAA;AASxB,MAAM,OAAO,OAAO;IACX,MAAM,CAAQ;IACJ,cAAc,CAAgB;IAC9B,MAAM,CAAgC;IACtC,eAAe,CAAiB;IAChC,WAAW,CAAQ;IACnB,GAAG,CAAQ;IACX,SAAS,CAAS;IAClB,OAAO,CAAS;IACzB,OAAO,CAAS;IACP,GAAG,CAAQ;IACX,WAAW,CAA0B;IACrC,gBAAgB,CAAmB;IAC5C,kBAAkB,CAAkB;IAE5C,YAAa,UAA6B,EAAE,IAAiB;QAC3D,IAAI,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AAM,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"}
@@ -0,0 +1,41 @@
1
+ import type { Gateway } from '@achingbrain/nat-port-mapper';
2
+ import type { ComponentLogger } from '@libp2p/interface';
3
+ import type { AddressManager } from '@libp2p/interface-internal';
4
+ export interface UPnPPortMapperInit {
5
+ gateway: Gateway;
6
+ externalAddressCheckInterval?: number;
7
+ externalAddressCheckTimeout?: number;
8
+ }
9
+ export interface UPnPPortMapperComponents {
10
+ logger: ComponentLogger;
11
+ addressManager: AddressManager;
12
+ }
13
+ export interface MapPortsOptions {
14
+ autoConfirmAddress?: boolean;
15
+ }
16
+ export declare class UPnPPortMapper {
17
+ private readonly gateway;
18
+ private readonly externalAddress;
19
+ private readonly addressManager;
20
+ private readonly log;
21
+ private readonly mappedPorts;
22
+ private started;
23
+ constructor(components: UPnPPortMapperComponents, init: UPnPPortMapperInit);
24
+ start(): Promise<void>;
25
+ stop(): Promise<void>;
26
+ /**
27
+ * Update the local address mappings when the gateway's external interface
28
+ * address changes
29
+ */
30
+ private remapPorts;
31
+ /**
32
+ * Return any eligible multiaddrs that are not mapped on the detected gateway
33
+ */
34
+ private getUnmappedAddresses;
35
+ mapIpAddresses(options?: MapPortsOptions): Promise<void>;
36
+ /**
37
+ * Some ISPs have double-NATs, there's not much we can do with them
38
+ */
39
+ private assertNotBehindDoubleNAT;
40
+ }
41
+ //# sourceMappingURL=upnp-port-mapper.d.ts.map
@@ -0,0 +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;AAGhE,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;IAkDtB,cAAc,CAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA4D/D;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAWjC"}
@@ -0,0 +1,169 @@
1
+ import { isIPv4 } from '@chainsafe/is-ip';
2
+ import { InvalidParametersError, start, stop } from '@libp2p/interface';
3
+ import { isLinkLocal } from '@libp2p/utils/multiaddr/is-link-local';
4
+ import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback';
5
+ import { isPrivate } from '@libp2p/utils/multiaddr/is-private';
6
+ import { isPrivateIp } from '@libp2p/utils/private-ip';
7
+ import { multiaddr } from '@multiformats/multiaddr';
8
+ import { QUICV1, TCP, WebSockets, WebSocketsSecure, WebTransport } from '@multiformats/multiaddr-matcher';
9
+ import { dynamicExternalAddress } from './check-external-address.js';
10
+ import { DoubleNATError } from './errors.js';
11
+ export class UPnPPortMapper {
12
+ gateway;
13
+ externalAddress;
14
+ addressManager;
15
+ log;
16
+ mappedPorts;
17
+ started;
18
+ constructor(components, init) {
19
+ this.log = components.logger.forComponent(`libp2p:upnp-nat:gateway:${init.gateway.id}`);
20
+ this.addressManager = components.addressManager;
21
+ this.gateway = init.gateway;
22
+ this.externalAddress = dynamicExternalAddress({
23
+ gateway: this.gateway,
24
+ addressManager: this.addressManager,
25
+ logger: components.logger
26
+ }, {
27
+ interval: init.externalAddressCheckInterval,
28
+ timeout: init.externalAddressCheckTimeout,
29
+ onExternalAddressChange: this.remapPorts.bind(this)
30
+ });
31
+ this.gateway = init.gateway;
32
+ this.mappedPorts = new Map();
33
+ this.started = false;
34
+ }
35
+ async start() {
36
+ if (this.started) {
37
+ return;
38
+ }
39
+ await start(this.externalAddress);
40
+ this.started = true;
41
+ }
42
+ async stop() {
43
+ try {
44
+ const shutdownTimeout = AbortSignal.timeout(1000);
45
+ await this.gateway.stop({
46
+ signal: shutdownTimeout
47
+ });
48
+ }
49
+ catch (err) {
50
+ this.log.error('error closing gateway - %e', err);
51
+ }
52
+ await stop(this.externalAddress);
53
+ this.started = false;
54
+ }
55
+ /**
56
+ * Update the local address mappings when the gateway's external interface
57
+ * address changes
58
+ */
59
+ remapPorts(newExternalHost) {
60
+ for (const [key, { externalHost, externalPort }] of this.mappedPorts.entries()) {
61
+ const [host, port, transport] = key.split('-');
62
+ this.addressManager.removePublicAddressMapping(host, parseInt(port), externalHost, externalPort, transport === 'tcp' ? 'tcp' : 'udp');
63
+ this.addressManager.addPublicAddressMapping(host, parseInt(port), newExternalHost, externalPort, transport === 'tcp' ? 'tcp' : 'udp');
64
+ }
65
+ }
66
+ /**
67
+ * Return any eligible multiaddrs that are not mapped on the detected gateway
68
+ */
69
+ getUnmappedAddresses(multiaddrs, publicAddresses) {
70
+ const output = [];
71
+ for (const ma of multiaddrs) {
72
+ const stringTuples = ma.stringTuples();
73
+ const address = `${stringTuples[0][1]}`;
74
+ // ignore public IPv4 addresses
75
+ if (isIPv4(address) && !isPrivate(ma)) {
76
+ continue;
77
+ }
78
+ // ignore any addresses that match the interface on the network gateway
79
+ if (publicAddresses.includes(address)) {
80
+ continue;
81
+ }
82
+ // ignore loopback
83
+ if (isLoopback(ma)) {
84
+ continue;
85
+ }
86
+ // ignore link-local addresses
87
+ if (isLinkLocal(ma)) {
88
+ continue;
89
+ }
90
+ // only IP based addresses
91
+ if (!(TCP.exactMatch(ma) ||
92
+ WebSockets.exactMatch(ma) ||
93
+ WebSocketsSecure.exactMatch(ma) ||
94
+ QUICV1.exactMatch(ma) ||
95
+ WebTransport.exactMatch(ma))) {
96
+ continue;
97
+ }
98
+ const { port, transport } = ma.toOptions();
99
+ if (this.mappedPorts.has(`${port}-${transport}`)) {
100
+ continue;
101
+ }
102
+ output.push(ma);
103
+ }
104
+ return output;
105
+ }
106
+ async mapIpAddresses(options) {
107
+ try {
108
+ const externalHost = await this.externalAddress.getPublicIp();
109
+ // filter addresses to get private, non-relay, IP based addresses that we
110
+ // haven't mapped yet
111
+ const addresses = this.getUnmappedAddresses(this.addressManager.getAddresses(), [externalHost]);
112
+ if (addresses.length === 0) {
113
+ this.log('no private, non-relay, unmapped, IP based addresses found');
114
+ return;
115
+ }
116
+ this.log('discovered public IP %s', externalHost);
117
+ this.assertNotBehindDoubleNAT(externalHost);
118
+ for (const addr of addresses) {
119
+ // try to open uPnP ports for each thin waist address
120
+ const { port, host, transport, family } = addr.toOptions();
121
+ // don't try to open port on IPv6 host via IPv4 gateway
122
+ if (family === 4 && this.gateway.family !== 'IPv4') {
123
+ continue;
124
+ }
125
+ // don't try to open port on IPv4 host via IPv6 gateway
126
+ if (family === 6 && this.gateway.family !== 'IPv6') {
127
+ continue;
128
+ }
129
+ const key = `${host}-${port}-${transport}`;
130
+ if (this.mappedPorts.has(key)) {
131
+ // already mapped this port
132
+ continue;
133
+ }
134
+ try {
135
+ const mapping = await this.gateway.map(port, host, {
136
+ protocol: transport === 'tcp' ? 'TCP' : 'UDP'
137
+ });
138
+ this.mappedPorts.set(key, mapping);
139
+ this.addressManager.addPublicAddressMapping(mapping.internalHost, mapping.internalPort, mapping.externalHost, mapping.externalPort, transport === 'tcp' ? 'tcp' : 'udp');
140
+ this.log('created mapping of %s:%s to %s:%s for protocol %s', mapping.internalHost, mapping.internalPort, mapping.externalHost, mapping.externalPort, transport);
141
+ if (options?.autoConfirmAddress === true) {
142
+ const ma = multiaddr(`/ip${family}/${host}/${transport}/${port}`);
143
+ this.log('auto-confirming IP address %a', ma);
144
+ this.addressManager.confirmObservedAddr(ma);
145
+ }
146
+ }
147
+ catch (err) {
148
+ this.log.error('failed to create mapping for %s:%d for protocol - %e', host, port, transport, err);
149
+ }
150
+ }
151
+ }
152
+ catch (err) {
153
+ this.log.error('error finding gateways - %e', err);
154
+ }
155
+ }
156
+ /**
157
+ * Some ISPs have double-NATs, there's not much we can do with them
158
+ */
159
+ assertNotBehindDoubleNAT(publicIp) {
160
+ const isPrivate = isPrivateIp(publicIp);
161
+ if (isPrivate === true) {
162
+ 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`);
163
+ }
164
+ if (isPrivate == null) {
165
+ throw new InvalidParametersError(`${publicIp} is not an IP address`);
166
+ }
167
+ }
168
+ }
169
+ //# sourceMappingURL=upnp-port-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upnp-port-mapper.js","sourceRoot":"","sources":["../../src/upnp-port-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBA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AAG,EAAE,CAAC;oBACb,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,sDAAsD,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,CAAA;gBACpG,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;QACpD,CAAC;IACH,CAAC;IAED;;OAEG;IACK,wBAAwB,CAAE,QAAgB;QAChD,MAAM,SAAS,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAA;QAEvC,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,MAAM,IAAI,cAAc,CAAC,GAAG,QAAQ,qIAAqI,CAAC,CAAA;QAC5K,CAAC;QAED,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,sBAAsB,CAAC,GAAG,QAAQ,uBAAuB,CAAC,CAAA;QACtE,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/upnp-nat",
3
- "version": "2.0.12-bc90b4fd5",
3
+ "version": "2.0.12-d19974d93",
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",
@@ -50,21 +50,21 @@
50
50
  "test:electron-main": "aegir test -t electron-main"
51
51
  },
52
52
  "dependencies": {
53
- "@achingbrain/nat-port-mapper": "^2.0.1",
53
+ "@achingbrain/nat-port-mapper": "^4.0.0",
54
54
  "@chainsafe/is-ip": "^2.0.2",
55
- "@libp2p/interface": "2.2.1-bc90b4fd5",
56
- "@libp2p/interface-internal": "2.1.1-bc90b4fd5",
57
- "@libp2p/utils": "6.2.1-bc90b4fd5",
58
- "@multiformats/multiaddr": "^12.2.3",
59
- "@multiformats/multiaddr-matcher": "^1.4.0",
55
+ "@libp2p/interface": "2.2.1-d19974d93",
56
+ "@libp2p/interface-internal": "2.1.1-d19974d93",
57
+ "@libp2p/utils": "6.2.1-d19974d93",
58
+ "@multiformats/multiaddr": "^12.3.3",
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.7-bc90b4fd5",
65
- "@libp2p/logger": "5.1.4-bc90b4fd5",
66
- "@libp2p/peer-id": "5.0.8-bc90b4fd5",
67
- "aegir": "^44.0.1",
64
+ "@libp2p/crypto": "5.0.7-d19974d93",
65
+ "@libp2p/logger": "5.1.4-d19974d93",
66
+ "@libp2p/peer-id": "5.0.8-d19974d93",
67
+ "aegir": "^45.0.5",
68
68
  "sinon-ts": "^2.0.0"
69
69
  },
70
70
  "sideEffects": false
@@ -2,14 +2,14 @@ import { NotStartedError, start, stop } from '@libp2p/interface'
2
2
  import { repeatingTask } from '@libp2p/utils/repeating-task'
3
3
  import pDefer from 'p-defer'
4
4
  import { raceSignal } from 'race-signal'
5
- import type { NatAPI } from '@achingbrain/nat-port-mapper'
5
+ import type { Gateway } from '@achingbrain/nat-port-mapper'
6
6
  import type { AbortOptions, ComponentLogger, Logger, Startable } from '@libp2p/interface'
7
7
  import type { AddressManager } from '@libp2p/interface-internal'
8
8
  import type { RepeatingTask } from '@libp2p/utils/repeating-task'
9
9
  import type { DeferredPromise } from 'p-defer'
10
10
 
11
11
  export interface ExternalAddressCheckerComponents {
12
- client: NatAPI
12
+ gateway: Gateway
13
13
  addressManager: AddressManager
14
14
  logger: ComponentLogger
15
15
  }
@@ -29,7 +29,7 @@ export interface ExternalAddress {
29
29
  */
30
30
  class ExternalAddressChecker implements ExternalAddress, Startable {
31
31
  private readonly log: Logger
32
- private readonly client: NatAPI
32
+ private readonly gateway: Gateway
33
33
  private readonly addressManager: AddressManager
34
34
  private started: boolean
35
35
  private lastPublicIp?: string
@@ -39,7 +39,7 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
39
39
 
40
40
  constructor (components: ExternalAddressCheckerComponents, init: ExternalAddressCheckerInit) {
41
41
  this.log = components.logger.forComponent('libp2p:upnp-nat:external-address-check')
42
- this.client = components.client
42
+ this.gateway = components.gateway
43
43
  this.addressManager = components.addressManager
44
44
  this.onExternalAddressChange = init.onExternalAddressChange
45
45
  this.started = false
@@ -60,14 +60,11 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
60
60
  }
61
61
 
62
62
  await start(this.check)
63
-
64
- this.check.start()
65
63
  this.started = true
66
64
  }
67
65
 
68
66
  async stop (): Promise<void> {
69
67
  await stop(this.check)
70
-
71
68
  this.started = false
72
69
  }
73
70
 
@@ -86,7 +83,7 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
86
83
 
87
84
  private async checkExternalAddress (options?: AbortOptions): Promise<void> {
88
85
  try {
89
- const externalAddress = await this.client.externalIp(options)
86
+ const externalAddress = await this.gateway.externalIp(options)
90
87
 
91
88
  // check if our public address has changed
92
89
  if (this.lastPublicIp != null && externalAddress !== this.lastPublicIp) {
@@ -99,6 +96,8 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
99
96
  this.lastPublicIp = externalAddress
100
97
  this.lastPublicIpPromise.resolve(externalAddress)
101
98
  } catch (err: any) {
99
+ this.log.error('could not resolve external address - %e', err)
100
+
102
101
  if (this.lastPublicIp != null) {
103
102
  // ignore the error if we've previously run successfully
104
103
  return
@@ -0,0 +1,2 @@
1
+ export const DEFAULT_GATEWAY_SEARCH_TIMEOUT = 60_000
2
+ export const DEFAULT_GATEWAY_SEARCH_INTERVAL = 300_000
@@ -0,0 +1,75 @@
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
+ import type { Gateway, UPnPNAT } from '@achingbrain/nat-port-mapper'
5
+ import type { ComponentLogger, Logger } from '@libp2p/interface'
6
+ import type { RepeatingTask } from '@libp2p/utils/repeating-task'
7
+
8
+ export interface GatewayFinderComponents {
9
+ logger: ComponentLogger
10
+ }
11
+
12
+ export interface GatewayFinderInit {
13
+ portMappingClient: UPnPNAT
14
+ }
15
+
16
+ export interface GatewayFinderEvents {
17
+ 'gateway': CustomEvent<Gateway>
18
+ }
19
+
20
+ export class GatewayFinder extends TypedEventEmitter<GatewayFinderEvents> {
21
+ private readonly log: Logger
22
+ private readonly gateways: Gateway[]
23
+ private readonly findGateways: RepeatingTask
24
+ private readonly portMappingClient: UPnPNAT
25
+ private started: boolean
26
+
27
+ constructor (components: GatewayFinderComponents, init: GatewayFinderInit) {
28
+ super()
29
+
30
+ this.log = components.logger.forComponent('libp2p:upnp-nat')
31
+ this.portMappingClient = init.portMappingClient
32
+ this.started = false
33
+ this.gateways = []
34
+
35
+ // every five minutes, search for network gateways for one minute
36
+ this.findGateways = repeatingTask(async (options) => {
37
+ for await (const gateway of this.portMappingClient.findGateways({
38
+ ...options,
39
+ searchInterval: 10000
40
+ })) {
41
+ if (this.gateways.some(g => {
42
+ return g.id === gateway.id && g.family === gateway.family
43
+ })) {
44
+ // already seen this gateway
45
+ continue
46
+ }
47
+
48
+ this.gateways.push(gateway)
49
+ this.safeDispatchEvent('gateway', {
50
+ detail: gateway
51
+ })
52
+ }
53
+ }, DEFAULT_GATEWAY_SEARCH_INTERVAL, {
54
+ runImmediately: true,
55
+ timeout: DEFAULT_GATEWAY_SEARCH_TIMEOUT
56
+ })
57
+ }
58
+
59
+ async start (): Promise<void> {
60
+ if (this.started) {
61
+ return
62
+ }
63
+
64
+ this.started = true
65
+ await start(this.findGateways)
66
+ }
67
+
68
+ /**
69
+ * Stops the NAT manager
70
+ */
71
+ async stop (): Promise<void> {
72
+ await stop(this.findGateways)
73
+ this.started = false
74
+ }
75
+ }
package/src/index.ts CHANGED
@@ -35,11 +35,12 @@
35
35
  * ```
36
36
  */
37
37
 
38
- import { UPnPNAT as UPnPNATClass, type NatAPI, type MapPortOptions } from './upnp-nat.js'
38
+ import { UPnPNAT as UPnPNATClass } from './upnp-nat.js'
39
+ import type { UPnPNAT as UPnPNATClient, MapPortOptions } from '@achingbrain/nat-port-mapper'
39
40
  import type { ComponentLogger, Libp2pEvents, NodeInfo, PeerId, TypedEventTarget } from '@libp2p/interface'
40
41
  import type { AddressManager } from '@libp2p/interface-internal'
41
42
 
42
- export type { NatAPI, MapPortOptions }
43
+ export type { UPnPNATClient, MapPortOptions }
43
44
 
44
45
  export interface PMPOptions {
45
46
  /**
@@ -49,12 +50,6 @@ export interface PMPOptions {
49
50
  }
50
51
 
51
52
  export interface UPnPNATInit {
52
- /**
53
- * Pass a string to hard code the external address, otherwise it will be
54
- * auto-detected
55
- */
56
- externalAddress?: string
57
-
58
53
  /**
59
54
  * Check if the external address has changed this often in ms. Ignored if an
60
55
  * external address is specified.
@@ -71,46 +66,49 @@ export interface UPnPNATInit {
71
66
  */
72
67
  externalAddressCheckTimeout?: number
73
68
 
74
- /**
75
- * Pass a value to use instead of auto-detection
76
- */
77
- localAddress?: string
78
-
79
69
  /**
80
70
  * A string value to use for the port mapping description on the gateway
81
71
  */
82
- description?: string
83
-
84
- /**
85
- * How long UPnP port mappings should last for in seconds (minimum 1200)
86
- */
87
- ttl?: number
72
+ portMappingDescription?: string
88
73
 
89
74
  /**
90
- * Whether to automatically refresh UPnP port mappings when their TTL is reached
75
+ * How long UPnP port mappings should last for in ms
76
+ *
77
+ * @default 720_000
91
78
  */
92
- keepAlive?: boolean
79
+ portMappingTTL?: number
93
80
 
94
81
  /**
95
- * Pass a value to use instead of auto-detection
82
+ * Whether to automatically refresh UPnP port mappings when their TTL is
83
+ * reached
84
+ *
85
+ * @default true
96
86
  */
97
- gateway?: string
87
+ portMappingAutoRefresh?: boolean
98
88
 
99
89
  /**
100
- * Ports are mapped when the `self:peer:update` event fires, which happens
101
- * when the node's addresses change. To avoid starting to map ports while
102
- * multiple addresses are being added, the mapping function is debounced by
103
- * this number of ms
90
+ * How long before a port mapping expires to refresh it in ms
104
91
  *
105
- * @default 5000
92
+ * @default 60_000
106
93
  */
107
- delay?: number
94
+ portMappingRefreshThreshold?: number
108
95
 
109
96
  /**
110
97
  * A preconfigured instance of a NatAPI client can be passed as an option,
111
98
  * otherwise one will be created
112
99
  */
113
- client?: NatAPI
100
+ portMappingClient?: UPnPNATClient
101
+
102
+ /**
103
+ * Any mapped addresses are added to the observed address list. These
104
+ * addresses require additional verification by the `@libp2p/autonat` protocol
105
+ * or similar before they are trusted.
106
+ *
107
+ * To skip this verification and trust them immediately pass `true` here
108
+ *
109
+ * @default false
110
+ */
111
+ autoConfirmAddress?: boolean
114
112
  }
115
113
 
116
114
  export interface UPnPNATComponents {
@@ -122,7 +120,7 @@ export interface UPnPNATComponents {
122
120
  }
123
121
 
124
122
  export interface UPnPNAT {
125
- client: NatAPI
123
+ portMappingClient: UPnPNATClient
126
124
  }
127
125
 
128
126
  export function uPnPNAT (init: UPnPNATInit = {}): (components: UPnPNATComponents) => UPnPNAT {