@libp2p/upnp-nat 1.2.5 → 2.0.0-1210884ed
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/errors.d.ts +4 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +7 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/upnp-nat.d.ts.map +1 -1
- package/dist/src/upnp-nat.js +5 -4
- package/dist/src/upnp-nat.js.map +1 -1
- package/package.json +7 -6
- package/src/errors.ts +6 -0
- package/src/upnp-nat.ts +5 -4
- package/dist/typedoc-urls.json +0 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;gBAC1B,OAAO,SAAwB;CAI7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAa,OAAO,GAAG,qBAAqB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upnp-nat.d.ts","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAA;AACxF,OAAO,
|
|
1
|
+
{"version":3,"file":"upnp-nat.d.ts","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAA;AACxF,OAAO,EAA0B,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AA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{ isLoopback } from '@libp2p/utils/multiaddr/is-loopback';
|
|
4
4
|
import { isPrivateIp } from '@libp2p/utils/private-ip';
|
|
5
5
|
import { fromNodeAddress } from '@multiformats/multiaddr';
|
|
6
6
|
import { isBrowser } from 'wherearewe';
|
|
7
|
+
import { DoubleNATError } from './errors.js';
|
|
7
8
|
const DEFAULT_TTL = 7200;
|
|
8
9
|
function highPort(min = 1024, max = 65535) {
|
|
9
10
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
@@ -30,7 +31,7 @@ export class UPnPNAT {
|
|
|
30
31
|
this.keepAlive = init.keepAlive ?? true;
|
|
31
32
|
this.gateway = init.gateway;
|
|
32
33
|
if (this.ttl < DEFAULT_TTL) {
|
|
33
|
-
throw new
|
|
34
|
+
throw new InvalidParametersError(`NatManager ttl should be at least ${DEFAULT_TTL} seconds`);
|
|
34
35
|
}
|
|
35
36
|
this.client = upnpNat({
|
|
36
37
|
description: this.description,
|
|
@@ -87,10 +88,10 @@ export class UPnPNAT {
|
|
|
87
88
|
const publicIp = this.externalAddress ?? await this.client.externalIp();
|
|
88
89
|
const isPrivate = isPrivateIp(publicIp);
|
|
89
90
|
if (isPrivate === true) {
|
|
90
|
-
throw new
|
|
91
|
+
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`);
|
|
91
92
|
}
|
|
92
93
|
if (isPrivate == null) {
|
|
93
|
-
throw new
|
|
94
|
+
throw new InvalidParametersError(`${publicIp} is not an IP address`);
|
|
94
95
|
}
|
|
95
96
|
const publicPort = highPort();
|
|
96
97
|
this.log(`opening uPnP connection from ${publicIp}:${publicPort} to ${host}:${port}`);
|
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,EAAoC,MAAM,8BAA8B,CAAA;AACxF,OAAO,EA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AAC;gBACpB,UAAU;gBACV,SAAS,EAAE,IAAI;gBACf,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,QAAQ,EAAE,SAAS,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;aAC5D,CAAC,CAAA;YAEF,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,eAAe,CAAC,eAAe,CAAC;gBAC7D,MAAM,EAAE,CAAC;gBACT,OAAO,EAAE,QAAQ;gBACjB,IAAI,EAAE,UAAU;aACjB,EAAE,SAAS,CAAC,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YACrC,OAAM;QACR,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QAC3B,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/upnp-nat",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-1210884ed",
|
|
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",
|
|
@@ -51,15 +51,16 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@achingbrain/nat-port-mapper": "^1.0.13",
|
|
54
|
-
"@libp2p/interface": "
|
|
55
|
-
"@libp2p/interface-internal": "
|
|
56
|
-
"@libp2p/utils": "
|
|
54
|
+
"@libp2p/interface": "2.0.0-1210884ed",
|
|
55
|
+
"@libp2p/interface-internal": "2.0.0-1210884ed",
|
|
56
|
+
"@libp2p/utils": "6.0.0-1210884ed",
|
|
57
57
|
"@multiformats/multiaddr": "^12.2.3",
|
|
58
58
|
"wherearewe": "^2.0.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@libp2p/
|
|
62
|
-
"@libp2p/
|
|
61
|
+
"@libp2p/crypto": "5.0.0-1210884ed",
|
|
62
|
+
"@libp2p/logger": "5.0.0-1210884ed",
|
|
63
|
+
"@libp2p/peer-id": "5.0.0-1210884ed",
|
|
63
64
|
"aegir": "^44.0.1",
|
|
64
65
|
"sinon-ts": "^2.0.0"
|
|
65
66
|
},
|
package/src/errors.ts
ADDED
package/src/upnp-nat.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { upnpNat, type NatAPI, type MapPortOptions } from '@achingbrain/nat-port-mapper'
|
|
2
|
-
import {
|
|
2
|
+
import { InvalidParametersError, serviceCapabilities } from '@libp2p/interface'
|
|
3
3
|
import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'
|
|
4
4
|
import { isPrivateIp } from '@libp2p/utils/private-ip'
|
|
5
5
|
import { fromNodeAddress } from '@multiformats/multiaddr'
|
|
6
6
|
import { isBrowser } from 'wherearewe'
|
|
7
|
+
import { DoubleNATError } from './errors.js'
|
|
7
8
|
import type { UPnPNATComponents, UPnPNATInit, UPnPNAT as UPnPNATInterface } from './index.js'
|
|
8
9
|
import type { Logger, Startable } from '@libp2p/interface'
|
|
9
10
|
|
|
@@ -40,7 +41,7 @@ export class UPnPNAT implements Startable, UPnPNATInterface {
|
|
|
40
41
|
this.gateway = init.gateway
|
|
41
42
|
|
|
42
43
|
if (this.ttl < DEFAULT_TTL) {
|
|
43
|
-
throw new
|
|
44
|
+
throw new InvalidParametersError(`NatManager ttl should be at least ${DEFAULT_TTL} seconds`)
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
this.client = upnpNat({
|
|
@@ -112,11 +113,11 @@ export class UPnPNAT implements Startable, UPnPNATInterface {
|
|
|
112
113
|
const isPrivate = isPrivateIp(publicIp)
|
|
113
114
|
|
|
114
115
|
if (isPrivate === true) {
|
|
115
|
-
throw new
|
|
116
|
+
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`)
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
if (isPrivate == null) {
|
|
119
|
-
throw new
|
|
120
|
+
throw new InvalidParametersError(`${publicIp} is not an IP address`)
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
const publicPort = highPort()
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"PMPOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_upnp_nat.PMPOptions.html",
|
|
3
|
-
".:PMPOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_upnp_nat.PMPOptions.html",
|
|
4
|
-
"UPnPNAT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_upnp_nat.UPnPNAT.html",
|
|
5
|
-
".:UPnPNAT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_upnp_nat.UPnPNAT.html",
|
|
6
|
-
"UPnPNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_upnp_nat.UPnPNATComponents.html",
|
|
7
|
-
".:UPnPNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_upnp_nat.UPnPNATComponents.html",
|
|
8
|
-
"UPnPNATInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_upnp_nat.UPnPNATInit.html",
|
|
9
|
-
".:UPnPNATInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_upnp_nat.UPnPNATInit.html",
|
|
10
|
-
"uPnPNAT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_upnp_nat.uPnPNAT-1.html",
|
|
11
|
-
".:uPnPNAT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_upnp_nat.uPnPNAT-1.html"
|
|
12
|
-
}
|