@libp2p/upnp-nat 2.0.12 → 3.0.0

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,69 +1,46 @@
1
1
  import { upnpNat } from '@achingbrain/nat-port-mapper';
2
- import { isIPv4, isIPv6 } from '@chainsafe/is-ip';
3
- import { InvalidParametersError, serviceCapabilities, serviceDependencies, start, stop } from '@libp2p/interface';
2
+ import { serviceCapabilities, serviceDependencies, setMaxListeners, start, stop } from '@libp2p/interface';
4
3
  import { debounce } from '@libp2p/utils/debounce';
5
- import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback';
6
- import { isPrivate } from '@libp2p/utils/multiaddr/is-private';
7
- import { isPrivateIp } from '@libp2p/utils/private-ip';
8
- import { multiaddr } from '@multiformats/multiaddr';
9
- import { QUICV1, TCP, WebSockets, WebSocketsSecure, WebTransport } from '@multiformats/multiaddr-matcher';
10
- import { raceSignal } from 'race-signal';
11
- import { dynamicExternalAddress, staticExternalAddress } from './check-external-address.js';
12
- import { DoubleNATError, InvalidIPAddressError } from './errors.js';
13
- const DEFAULT_TTL = 7200;
4
+ import { GatewayFinder } from './gateway-finder.js';
5
+ import { UPnPPortMapper } from './upnp-port-mapper.js';
14
6
  export class UPnPNAT {
15
- client;
16
- addressManager;
17
- events;
18
- externalAddress;
19
- localAddress;
20
- description;
21
- ttl;
22
- keepAlive;
23
- gateway;
24
- started;
25
7
  log;
26
- gatewayDetectionTimeout;
27
- mappedPorts;
28
- onSelfPeerUpdate;
8
+ components;
9
+ init;
10
+ started;
11
+ portMappingClient;
12
+ shutdownController;
13
+ mapIpAddressesDebounced;
14
+ gatewayFinder;
15
+ portMappers;
29
16
  autoConfirmAddress;
30
17
  constructor(components, init) {
31
18
  this.log = components.logger.forComponent('libp2p:upnp-nat');
32
- this.addressManager = components.addressManager;
33
- this.events = components.events;
19
+ this.components = components;
20
+ this.init = init;
34
21
  this.started = false;
35
- this.localAddress = init.localAddress;
36
- this.description = init.description ?? `${components.nodeInfo.name}@${components.nodeInfo.version} ${components.peerId.toString()}`;
37
- this.ttl = init.ttl ?? DEFAULT_TTL;
38
- this.keepAlive = init.keepAlive ?? true;
39
- this.gateway = init.gateway;
40
- this.gatewayDetectionTimeout = init.gatewayDetectionTimeout ?? 10000;
22
+ this.portMappers = [];
41
23
  this.autoConfirmAddress = init.autoConfirmAddress ?? false;
42
- this.mappedPorts = new Map();
43
- if (this.ttl < DEFAULT_TTL) {
44
- throw new InvalidParametersError(`NatManager ttl should be at least ${DEFAULT_TTL} seconds`);
45
- }
46
- this.client = init.client ?? upnpNat({
47
- description: this.description,
48
- ttl: this.ttl,
49
- keepAlive: this.keepAlive,
50
- gateway: this.gateway
24
+ this.portMappingClient = init.portMappingClient ?? upnpNat({
25
+ description: init.portMappingDescription ?? `${components.nodeInfo.name}@${components.nodeInfo.version} ${components.peerId.toString()}`,
26
+ ttl: init.portMappingTTL,
27
+ autoRefresh: init.portMappingAutoRefresh,
28
+ refreshThreshold: init.portMappingRefreshThreshold
51
29
  });
52
- this.onSelfPeerUpdate = debounce(this._onSelfPeerUpdate.bind(this), init.delay ?? 5000);
53
- if (typeof init.externalAddress === 'string') {
54
- this.externalAddress = staticExternalAddress(init.externalAddress);
55
- }
56
- else {
57
- this.externalAddress = dynamicExternalAddress({
58
- client: this.client,
59
- addressManager: this.addressManager,
60
- logger: components.logger
61
- }, {
62
- autoConfirmAddress: init.autoConfirmAddress,
63
- interval: init.externalAddressCheckInterval,
64
- timeout: init.externalAddressCheckTimeout
65
- });
66
- }
30
+ // trigger update when our addresses change
31
+ this.mapIpAddressesDebounced = debounce(async () => {
32
+ try {
33
+ await this.mapIpAddresses();
34
+ }
35
+ catch (err) {
36
+ this.log.error('error mapping IP addresses - %e', err);
37
+ }
38
+ }, 5_000);
39
+ // trigger update when we discovery gateways on the network
40
+ this.gatewayFinder = new GatewayFinder(components, {
41
+ portMappingClient: this.portMappingClient
42
+ });
43
+ this.onGatewayDiscovered = this.onGatewayDiscovered.bind(this);
67
44
  }
68
45
  [Symbol.toStringTag] = '@libp2p/upnp-nat';
69
46
  [serviceCapabilities] = [
@@ -85,126 +62,42 @@ export class UPnPNAT {
85
62
  return;
86
63
  }
87
64
  this.started = true;
88
- this.events.addEventListener('self:peer:update', this.onSelfPeerUpdate);
89
- await start(this.externalAddress, this.onSelfPeerUpdate);
65
+ this.shutdownController = new AbortController();
66
+ setMaxListeners(Infinity, this.shutdownController.signal);
67
+ this.components.events.addEventListener('self:peer:update', this.mapIpAddressesDebounced);
68
+ this.gatewayFinder.addEventListener('gateway', this.onGatewayDiscovered);
69
+ await start(this.mapIpAddressesDebounced, this.gatewayFinder, ...this.portMappers);
90
70
  }
91
71
  /**
92
72
  * Stops the NAT manager
93
73
  */
94
74
  async stop() {
95
- try {
96
- await this.client?.close();
97
- }
98
- catch (err) {
99
- this.log.error(err);
100
- }
101
- this.events.removeEventListener('self:peer:update', this.onSelfPeerUpdate);
102
- await stop(this.externalAddress, this.onSelfPeerUpdate);
75
+ this.shutdownController?.abort();
76
+ this.components.events.removeEventListener('self:peer:update', this.mapIpAddressesDebounced);
77
+ this.gatewayFinder.removeEventListener('gateway', this.onGatewayDiscovered);
78
+ await stop(this.mapIpAddressesDebounced, this.gatewayFinder, ...this.portMappers);
103
79
  this.started = false;
104
80
  }
105
- _onSelfPeerUpdate() {
106
- this.mapIpAddresses()
107
- .catch(err => {
108
- this.log.error('error mapping IP addresses - %e', err);
81
+ onGatewayDiscovered(event) {
82
+ const mapper = new UPnPPortMapper(this.components, {
83
+ ...this.init,
84
+ gateway: event.detail
109
85
  });
110
- }
111
- getUnmappedAddresses(multiaddrs, ipType) {
112
- const output = [];
113
- for (const ma of multiaddrs) {
114
- // ignore public addresses
115
- if (!isPrivate(ma)) {
116
- continue;
117
- }
118
- // ignore loopback
119
- if (isLoopback(ma)) {
120
- continue;
121
- }
122
- // only IP based addresses
123
- if (!(TCP.exactMatch(ma) ||
124
- WebSockets.exactMatch(ma) ||
125
- WebSocketsSecure.exactMatch(ma) ||
126
- QUICV1.exactMatch(ma) ||
127
- WebTransport.exactMatch(ma))) {
128
- continue;
129
- }
130
- const { port, family } = ma.toOptions();
131
- if (family !== ipType) {
132
- continue;
133
- }
134
- if (this.mappedPorts.has(port)) {
135
- continue;
136
- }
137
- output.push(ma);
138
- }
139
- return output;
86
+ this.portMappers.push(mapper);
87
+ start(mapper)
88
+ .then(() => {
89
+ this.mapIpAddressesDebounced();
90
+ })
91
+ .catch(() => { });
140
92
  }
141
93
  async mapIpAddresses() {
142
- if (this.externalAddress == null) {
143
- this.log('discovering public address');
144
- }
145
- const publicIp = await this.externalAddress.getPublicIp({
146
- signal: AbortSignal.timeout(this.gatewayDetectionTimeout)
147
- });
148
- this.externalAddress ?? await raceSignal(this.client.externalIp(), AbortSignal.timeout(this.gatewayDetectionTimeout), {
149
- errorMessage: `Did not discover a "urn:schemas-upnp-org:device:InternetGatewayDevice:1" device on the local network after ${this.gatewayDetectionTimeout}ms - UPnP may not be configured on your router correctly`
150
- });
151
- let ipType = 4;
152
- if (isIPv4(publicIp)) {
153
- ipType = 4;
154
- }
155
- else if (isIPv6(publicIp)) {
156
- ipType = 6;
157
- }
158
- else {
159
- throw new InvalidIPAddressError(`Public address ${publicIp} was not an IPv4 address`);
160
- }
161
- // filter addresses to get private, non-relay, IP based addresses that we
162
- // haven't mapped yet
163
- const addresses = this.getUnmappedAddresses(this.addressManager.getAddresses(), ipType);
164
- if (addresses.length === 0) {
165
- this.log('no private, non-relay, unmapped, IP based addresses found');
166
- return;
167
- }
168
- this.log('%s public IP %s', this.externalAddress != null ? 'using configured' : 'discovered', publicIp);
169
- this.assertNotBehindDoubleNAT(publicIp);
170
- for (const addr of addresses) {
171
- // try to open uPnP ports for each thin waist address
172
- const { family, host, port, transport } = addr.toOptions();
173
- if (family === 6) {
174
- // only support IPv4 addresses
175
- continue;
176
- }
177
- if (this.mappedPorts.has(port)) {
178
- // already mapped this port
179
- continue;
180
- }
181
- const protocol = transport.toUpperCase();
182
- this.log(`creating mapping of ${host}:${port}`);
183
- const mappedPort = await this.client.map(port, {
184
- localAddress: host,
185
- protocol: protocol === 'TCP' ? 'TCP' : 'UDP'
186
- });
187
- this.mappedPorts.set(port, mappedPort);
188
- const ma = multiaddr(addr.toString().replace(`/ip${family}/${host}/${transport}/${port}`, `/ip${family}/${publicIp}/${transport}/${mappedPort}`));
189
- this.log(`created mapping of ${publicIp}:${mappedPort} to ${host}:${port} as %a`, ma);
190
- if (this.autoConfirmAddress) {
191
- this.addressManager.confirmObservedAddr(ma);
192
- }
193
- else {
194
- this.addressManager.addObservedAddr(ma);
195
- }
196
- }
197
- }
198
- /**
199
- * Some ISPs have double-NATs, there's not much we can do with them
200
- */
201
- assertNotBehindDoubleNAT(publicIp) {
202
- const isPrivate = isPrivateIp(publicIp);
203
- if (isPrivate === true) {
204
- throw new DoubleNATError(`${publicIp} is private - please set config.nat.externalIp to an externally routable IP or ensure you are not behind a double NAT`);
94
+ try {
95
+ await Promise.all(this.portMappers.map(async (mapper) => mapper.mapIpAddresses({
96
+ autoConfirmAddress: this.autoConfirmAddress
97
+ })));
205
98
  }
206
- if (isPrivate == null) {
207
- throw new InvalidParametersError(`${publicIp} is not an IP address`);
99
+ catch (err) {
100
+ this.log.error('error mapping IP addresses - %e', err);
208
101
  }
209
102
  }
210
103
  }
@@ -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,mBAAmB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACjH,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MA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AI,CAAC,WAAW,CAAC,CAAA;QACjF,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;IACtB,CAAC;IAED,mBAAmB,CAAE,KAA2B;QAC9C,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE;YACjD,GAAG,IAAI,CAAC,IAAI;YACZ,OAAO,EAAE,KAAK,CAAC,MAAM;SACtB,CAAC,CAAA;QAEF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAE7B,KAAK,CAAC,MAAM,CAAC;aACV,IAAI,CAAC,GAAG,EAAE;YACT,IAAI,CAAC,uBAAuB,EAAE,CAAA;QAChC,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,cAAc;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"}
@@ -0,0 +1,42 @@
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
+ private isIPAddress;
41
+ }
42
+ //# 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;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"}
@@ -0,0 +1,179 @@
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
+ const MAX_DATE = 8_640_000_000_000_000;
12
+ export class UPnPPortMapper {
13
+ gateway;
14
+ externalAddress;
15
+ addressManager;
16
+ log;
17
+ mappedPorts;
18
+ started;
19
+ constructor(components, init) {
20
+ this.log = components.logger.forComponent(`libp2p:upnp-nat:gateway:${init.gateway.id}`);
21
+ this.addressManager = components.addressManager;
22
+ this.gateway = init.gateway;
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
+ });
32
+ this.gateway = init.gateway;
33
+ this.mappedPorts = new Map();
34
+ this.started = false;
35
+ }
36
+ async start() {
37
+ if (this.started) {
38
+ return;
39
+ }
40
+ await start(this.externalAddress);
41
+ this.started = true;
42
+ }
43
+ async stop() {
44
+ try {
45
+ const shutdownTimeout = AbortSignal.timeout(1000);
46
+ await this.gateway.stop({
47
+ signal: shutdownTimeout
48
+ });
49
+ }
50
+ catch (err) {
51
+ this.log.error('error closing gateway - %e', err);
52
+ }
53
+ await stop(this.externalAddress);
54
+ this.started = false;
55
+ }
56
+ /**
57
+ * Update the local address mappings when the gateway's external interface
58
+ * address changes
59
+ */
60
+ remapPorts(newExternalHost) {
61
+ for (const [key, { externalHost, externalPort }] of this.mappedPorts.entries()) {
62
+ const [host, port, transport] = key.split('-');
63
+ this.addressManager.removePublicAddressMapping(host, parseInt(port), externalHost, externalPort, transport === 'tcp' ? 'tcp' : 'udp');
64
+ this.addressManager.addPublicAddressMapping(host, parseInt(port), newExternalHost, externalPort, transport === 'tcp' ? 'tcp' : 'udp');
65
+ }
66
+ }
67
+ /**
68
+ * Return any eligible multiaddrs that are not mapped on the detected gateway
69
+ */
70
+ getUnmappedAddresses(multiaddrs, publicAddresses) {
71
+ const output = [];
72
+ for (const { multiaddr: ma, type } of multiaddrs) {
73
+ // only consider transport addresses, ignore mapped/observed addrs
74
+ if (type !== 'transport') {
75
+ continue;
76
+ }
77
+ const stringTuples = ma.stringTuples();
78
+ const address = `${stringTuples[0][1]}`;
79
+ // ignore public IPv4 addresses
80
+ if (isIPv4(address) && !isPrivate(ma)) {
81
+ continue;
82
+ }
83
+ // ignore any addresses that match the interface on the network gateway
84
+ if (publicAddresses.includes(address)) {
85
+ continue;
86
+ }
87
+ // ignore loopback
88
+ if (isLoopback(ma)) {
89
+ continue;
90
+ }
91
+ // ignore link-local addresses
92
+ if (isLinkLocal(ma)) {
93
+ continue;
94
+ }
95
+ // only IP based addresses
96
+ if (!this.isIPAddress(ma)) {
97
+ continue;
98
+ }
99
+ const { port, transport } = ma.toOptions();
100
+ if (this.mappedPorts.has(`${port}-${transport}`)) {
101
+ continue;
102
+ }
103
+ output.push(ma);
104
+ }
105
+ return output;
106
+ }
107
+ async mapIpAddresses(options) {
108
+ try {
109
+ const externalHost = await this.externalAddress.getPublicIp();
110
+ // filter addresses to get private, non-relay, IP based addresses that we
111
+ // haven't mapped yet
112
+ const addresses = this.getUnmappedAddresses(this.addressManager.getAddressesWithMetadata(), [externalHost]);
113
+ if (addresses.length === 0) {
114
+ this.log('no private, non-relay, unmapped, IP based addresses found');
115
+ return;
116
+ }
117
+ this.log('discovered public IP %s', externalHost);
118
+ this.assertNotBehindDoubleNAT(externalHost);
119
+ for (const addr of addresses) {
120
+ // try to open uPnP ports for each thin waist address
121
+ const { port, host, transport, family } = addr.toOptions();
122
+ // don't try to open port on IPv6 host via IPv4 gateway
123
+ if (family === 4 && this.gateway.family !== 'IPv4') {
124
+ continue;
125
+ }
126
+ // don't try to open port on IPv4 host via IPv6 gateway
127
+ if (family === 6 && this.gateway.family !== 'IPv6') {
128
+ continue;
129
+ }
130
+ const key = `${host}-${port}-${transport}`;
131
+ if (this.mappedPorts.has(key)) {
132
+ // already mapped this port
133
+ continue;
134
+ }
135
+ try {
136
+ const mapping = await this.gateway.map(port, host, {
137
+ protocol: transport === 'tcp' ? 'TCP' : 'UDP'
138
+ });
139
+ this.mappedPorts.set(key, mapping);
140
+ this.addressManager.addPublicAddressMapping(mapping.internalHost, mapping.internalPort, mapping.externalHost, mapping.externalPort, transport === 'tcp' ? 'tcp' : 'udp');
141
+ this.log('created mapping of %s:%s to %s:%s for protocol %s', mapping.internalHost, mapping.internalPort, mapping.externalHost, mapping.externalPort, transport);
142
+ if (options?.autoConfirmAddress === true) {
143
+ const ma = multiaddr(`/ip${family}/${host}/${transport}/${port}`);
144
+ this.log('auto-confirming IP address %a', ma);
145
+ this.addressManager.confirmObservedAddr(ma, {
146
+ ttl: MAX_DATE - Date.now()
147
+ });
148
+ }
149
+ }
150
+ catch (err) {
151
+ this.log.error('failed to create mapping for %s:%d for protocol - %e', host, port, transport, err);
152
+ }
153
+ }
154
+ }
155
+ catch (err) {
156
+ this.log.error('error finding gateways - %e', err);
157
+ }
158
+ }
159
+ /**
160
+ * Some ISPs have double-NATs, there's not much we can do with them
161
+ */
162
+ assertNotBehindDoubleNAT(publicIp) {
163
+ const isPrivate = isPrivateIp(publicIp);
164
+ if (isPrivate === true) {
165
+ 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`);
166
+ }
167
+ if (isPrivate == null) {
168
+ throw new InvalidParametersError(`${publicIp} is not an IP address`);
169
+ }
170
+ }
171
+ isIPAddress(ma) {
172
+ return TCP.exactMatch(ma) ||
173
+ WebSockets.exactMatch(ma) ||
174
+ WebSocketsSecure.exactMatch(ma) ||
175
+ QUICV1.exactMatch(ma) ||
176
+ WebTransport.exactMatch(ma);
177
+ }
178
+ }
179
+ //# 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,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,oCAAoC,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA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AEG;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;IAEO,WAAW,CAAE,EAAa;QAChC,OAAO,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACvB,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": "2.0.12",
3
+ "version": "3.0.0",
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",
56
- "@libp2p/interface-internal": "^2.1.1",
57
- "@libp2p/utils": "^6.2.1",
58
- "@multiformats/multiaddr": "^12.2.3",
59
- "@multiformats/multiaddr-matcher": "^1.4.0",
55
+ "@libp2p/interface": "^2.3.0",
56
+ "@libp2p/interface-internal": "^2.2.0",
57
+ "@libp2p/utils": "^6.3.0",
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",
65
- "@libp2p/logger": "^5.1.4",
66
- "@libp2p/peer-id": "^5.0.8",
67
- "aegir": "^44.0.1",
64
+ "@libp2p/crypto": "^5.0.8",
65
+ "@libp2p/logger": "^5.1.5",
66
+ "@libp2p/peer-id": "^5.0.9",
67
+ "aegir": "^45.0.5",
68
68
  "sinon-ts": "^2.0.0"
69
69
  },
70
70
  "sideEffects": false