@libp2p/upnp-nat 0.0.0 → 1.0.0-7682861f9

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/README.md CHANGED
@@ -1,25 +1,54 @@
1
1
  [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
2
2
  [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
3
3
  [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
4
- [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain)
5
5
 
6
- # Install
6
+ > UPnP NAT hole punching
7
7
 
8
- ```console
9
- $ npm i @libp2p/peer-id
10
- ```
8
+ # About
9
+
10
+ The service exported by this module attempts to configure NAT hole punching
11
+ via UPnP.
12
+
13
+ This will make your node publicly accessible from the internet.
14
+
15
+ For this to work there are some prerequisites:
11
16
 
12
- ## Browser `<script>` tag
17
+ 1. Your router must have UPnP support enabled
18
+ 2. Your libp2p node must be listening on a non-loopback IPv4 address
19
+ 3. You must not be [double-NATed](https://kb.netgear.com/30186/What-is-double-NAT-and-why-is-it-bad) by your ISP
13
20
 
14
- Loading this module through a script tag will make it's exports available as `Libp2pPeerId` in the global namespace.
21
+ ## Example
15
22
 
16
- ```html
17
- <script src="https://unpkg.com/@libp2p/peer-id/dist/index.min.js"></script>
23
+ ```typescript
24
+ import { createLibp2p } from 'libp2p'
25
+ import { tcp } from '@libp2p/tcp'
26
+ import { uPnPNAT } from '@libp2p/upnp-nat'
27
+
28
+ const node = await createLibp2p({
29
+ addresses: [
30
+ listen: [
31
+ '/ip4/0.0.0.0/tcp/0'
32
+ ]
33
+ ],
34
+ transports: [
35
+ tcp()
36
+ ],
37
+ services: {
38
+ upnpNAT: uPnPNAT()
39
+ }
40
+ })
41
+ ```
42
+
43
+ # Install
44
+
45
+ ```console
46
+ $ npm i @libp2p/upnp-nat
18
47
  ```
19
48
 
20
49
  # API Docs
21
50
 
22
- - <https://libp2p.github.io/js-libp2p/modules/_libp2p_peer_id.html>
51
+ - <https://libp2p.github.io/js-libp2p/modules/_libp2p_upnp_nat.html>
23
52
 
24
53
  # License
25
54
 
@@ -1,7 +1,41 @@
1
- import type { ComponentLogger, NodeInfo } from '@libp2p/interface';
2
- import type { PeerId } from '@libp2p/interface/peer-id';
3
- import type { AddressManager } from '@libp2p/interface-internal/address-manager';
4
- import type { TransportManager } from '@libp2p/interface-internal/transport-manager';
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * The service exported by this module attempts to configure NAT hole punching
5
+ * via UPnP.
6
+ *
7
+ * This will make your node publicly accessible from the internet.
8
+ *
9
+ * For this to work there are some prerequisites:
10
+ *
11
+ * 1. Your router must have UPnP support enabled
12
+ * 2. Your libp2p node must be listening on a non-loopback IPv4 address
13
+ * 3. You must not be [double-NATed](https://kb.netgear.com/30186/What-is-double-NAT-and-why-is-it-bad) by your ISP
14
+ *
15
+ * @example
16
+ *
17
+ * ```typescript
18
+ * import { createLibp2p } from 'libp2p'
19
+ * import { tcp } from '@libp2p/tcp'
20
+ * import { uPnPNAT } from '@libp2p/upnp-nat'
21
+ *
22
+ * const node = await createLibp2p({
23
+ * addresses: [
24
+ * listen: [
25
+ * '/ip4/0.0.0.0/tcp/0'
26
+ * ]
27
+ * ],
28
+ * transports: [
29
+ * tcp()
30
+ * ],
31
+ * services: {
32
+ * upnpNAT: uPnPNAT()
33
+ * }
34
+ * })
35
+ * ```
36
+ */
37
+ import type { ComponentLogger, NodeInfo, PeerId } from '@libp2p/interface';
38
+ import type { AddressManager, TransportManager } from '@libp2p/interface-internal';
5
39
  export interface PMPOptions {
6
40
  /**
7
41
  * Whether to enable PMP as well as UPnP
@@ -41,5 +75,5 @@ export interface UPnPNATComponents {
41
75
  transportManager: TransportManager;
42
76
  addressManager: AddressManager;
43
77
  }
44
- export declare function uPnPNATService(init?: UPnPNATInit): (components: UPnPNATComponents) => unknown;
78
+ export declare function uPnPNAT(init?: UPnPNATInit): (components: UPnPNATComponents) => unknown;
45
79
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAEpF,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,cAAc,EAAE,cAAc,CAAA;CAC/B;AAED,wBAAgB,cAAc,CAAE,IAAI,GAAE,WAAgB,GAAG,CAAC,UAAU,EAAE,iBAAiB,KAAK,OAAO,CAIlG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAElF,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,cAAc,EAAE,cAAc,CAAA;CAC/B;AAED,wBAAgB,OAAO,CAAE,IAAI,GAAE,WAAgB,GAAG,CAAC,UAAU,EAAE,iBAAiB,KAAK,OAAO,CAI3F"}
package/dist/src/index.js CHANGED
@@ -1,5 +1,41 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * The service exported by this module attempts to configure NAT hole punching
5
+ * via UPnP.
6
+ *
7
+ * This will make your node publicly accessible from the internet.
8
+ *
9
+ * For this to work there are some prerequisites:
10
+ *
11
+ * 1. Your router must have UPnP support enabled
12
+ * 2. Your libp2p node must be listening on a non-loopback IPv4 address
13
+ * 3. You must not be [double-NATed](https://kb.netgear.com/30186/What-is-double-NAT-and-why-is-it-bad) by your ISP
14
+ *
15
+ * @example
16
+ *
17
+ * ```typescript
18
+ * import { createLibp2p } from 'libp2p'
19
+ * import { tcp } from '@libp2p/tcp'
20
+ * import { uPnPNAT } from '@libp2p/upnp-nat'
21
+ *
22
+ * const node = await createLibp2p({
23
+ * addresses: [
24
+ * listen: [
25
+ * '/ip4/0.0.0.0/tcp/0'
26
+ * ]
27
+ * ],
28
+ * transports: [
29
+ * tcp()
30
+ * ],
31
+ * services: {
32
+ * upnpNAT: uPnPNAT()
33
+ * }
34
+ * })
35
+ * ```
36
+ */
1
37
  import { UPnPNAT } from './upnp-nat.js';
2
- export function uPnPNATService(init = {}) {
38
+ export function uPnPNAT(init = {}) {
3
39
  return (components) => {
4
40
  return new UPnPNAT(components, init);
5
41
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAqDvC,MAAM,UAAU,cAAc,CAAE,OAAoB,EAAE;IACpD,OAAO,CAAC,UAA6B,EAAE,EAAE;QACvC,OAAO,IAAI,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAmDvC,MAAM,UAAU,OAAO,CAAE,OAAoB,EAAE;IAC7C,OAAO,CAAC,UAA6B,EAAE,EAAE;QACvC,OAAO,IAAI,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC,CAAA;AACH,CAAC"}
@@ -1,8 +1,7 @@
1
1
  import { type NatAPI } from '@achingbrain/nat-port-mapper';
2
2
  import type { UPnPNATComponents, UPnPNATInit } from './index.js';
3
- import type { Startable } from '@libp2p/interface/startable';
3
+ import type { Startable } from '@libp2p/interface';
4
4
  export declare class UPnPNAT implements Startable {
5
- #private;
6
5
  private readonly components;
7
6
  private readonly externalAddress?;
8
7
  private readonly localAddress?;
@@ -12,6 +11,7 @@ export declare class UPnPNAT implements Startable {
12
11
  private readonly gateway?;
13
12
  private started;
14
13
  private client?;
14
+ private readonly log;
15
15
  constructor(components: UPnPNATComponents, init: UPnPNATInit);
16
16
  isStarted(): boolean;
17
17
  start(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"upnp-nat.d.ts","sourceRoot":"","sources":["../../src/upnp-nat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAMnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAQ5D,qBAAa,OAAQ,YAAW,SAAS;;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAQ;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAQ;IACjC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,CAAQ;gBAGV,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,WAAW;IAiB7D,SAAS,IAAK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
1
1
  import { upnpNat } from '@achingbrain/nat-port-mapper';
2
- import { CodeError, ERR_INVALID_PARAMETERS } from '@libp2p/interface/errors';
2
+ import { CodeError, ERR_INVALID_PARAMETERS } from '@libp2p/interface';
3
3
  import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback';
4
4
  import { fromNodeAddress } from '@multiformats/multiaddr';
5
5
  import isPrivateIp from 'private-ip';
@@ -18,10 +18,10 @@ export class UPnPNAT {
18
18
  gateway;
19
19
  started;
20
20
  client;
21
- #log;
21
+ log;
22
22
  constructor(components, init) {
23
23
  this.components = components;
24
- this.#log = components.logger.forComponent('libp2p:upnp-nat');
24
+ this.log = components.logger.forComponent('libp2p:upnp-nat');
25
25
  this.started = false;
26
26
  this.externalAddress = init.externalAddress;
27
27
  this.localAddress = init.localAddress;
@@ -52,7 +52,7 @@ export class UPnPNAT {
52
52
  // done async to not slow down startup
53
53
  void this.mapIpAddresses().catch((err) => {
54
54
  // hole punching errors are non-fatal
55
- this.#log.error(err);
55
+ this.log.error(err);
56
56
  });
57
57
  }
58
58
  async mapIpAddresses() {
@@ -84,7 +84,7 @@ export class UPnPNAT {
84
84
  throw new CodeError(`${publicIp} is not an IP address`, ERR_INVALID_PARAMETERS);
85
85
  }
86
86
  const publicPort = highPort();
87
- this.#log(`opening uPnP connection from ${publicIp}:${publicPort} to ${host}:${port}`);
87
+ this.log(`opening uPnP connection from ${publicIp}:${publicPort} to ${host}:${port}`);
88
88
  await client.map({
89
89
  publicPort,
90
90
  localPort: port,
@@ -122,7 +122,7 @@ export class UPnPNAT {
122
122
  this.client = undefined;
123
123
  }
124
124
  catch (err) {
125
- this.#log.error(err);
125
+ this.log.error(err);
126
126
  }
127
127
  }
128
128
  }
@@ -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;AACnE,OAAO,EAAE,SAAS,EAAE,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AAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@libp2p/upnp-nat",
3
- "version": "0.0.0",
3
+ "version": "1.0.0-7682861f9",
4
4
  "description": "UPnP NAT hole punching",
5
5
  "license": "Apache-2.0 OR MIT",
6
- "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/peer-id#readme",
6
+ "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/upnp-nat#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/libp2p/js-libp2p.git"
@@ -11,6 +11,10 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/libp2p/js-libp2p/issues"
13
13
  },
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "provenance": true
17
+ },
14
18
  "keywords": [
15
19
  "IPFS"
16
20
  ],
@@ -46,16 +50,16 @@
46
50
  },
47
51
  "dependencies": {
48
52
  "@achingbrain/nat-port-mapper": "^1.0.12",
49
- "@libp2p/interface": "^0.1.6",
50
- "@libp2p/interface-internal": "^0.1.9",
51
- "@libp2p/utils": "^4.0.7",
53
+ "@libp2p/interface": "1.0.0-7682861f9",
54
+ "@libp2p/interface-internal": "0.1.10-7682861f9",
55
+ "@libp2p/utils": "5.0.0-7682861f9",
52
56
  "@multiformats/multiaddr": "^12.1.10",
53
57
  "private-ip": "^3.0.1",
54
58
  "wherearewe": "^2.0.1"
55
59
  },
56
60
  "devDependencies": {
57
- "@libp2p/logger": "^3.1.0",
58
- "@libp2p/peer-id-factory": "^3.0.8",
61
+ "@libp2p/logger": "4.0.0-7682861f9",
62
+ "@libp2p/peer-id-factory": "3.0.9-7682861f9",
59
63
  "aegir": "^41.0.2",
60
64
  "sinon-ts": "^2.0.0"
61
65
  }
package/src/index.ts CHANGED
@@ -36,10 +36,8 @@
36
36
  */
37
37
 
38
38
  import { UPnPNAT } from './upnp-nat.js'
39
- import type { ComponentLogger, NodeInfo } from '@libp2p/interface'
40
- import type { PeerId } from '@libp2p/interface/peer-id'
41
- import type { AddressManager } from '@libp2p/interface-internal/address-manager'
42
- import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
39
+ import type { ComponentLogger, NodeInfo, PeerId } from '@libp2p/interface'
40
+ import type { AddressManager, TransportManager } from '@libp2p/interface-internal'
43
41
 
44
42
  export interface PMPOptions {
45
43
  /**
package/src/upnp-nat.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { upnpNat, type NatAPI } from '@achingbrain/nat-port-mapper'
2
- import { CodeError, ERR_INVALID_PARAMETERS } from '@libp2p/interface/errors'
2
+ import { CodeError, ERR_INVALID_PARAMETERS } from '@libp2p/interface'
3
3
  import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'
4
4
  import { fromNodeAddress } from '@multiformats/multiaddr'
5
5
  import isPrivateIp from 'private-ip'
6
6
  import { isBrowser } from 'wherearewe'
7
7
  import type { UPnPNATComponents, UPnPNATInit } from './index.js'
8
- import type { Logger } from '@libp2p/interface'
9
- import type { Startable } from '@libp2p/interface/startable'
8
+ import type { Logger, Startable } from '@libp2p/interface'
10
9
 
11
10
  const DEFAULT_TTL = 7200
12
11
 
@@ -24,12 +23,12 @@ export class UPnPNAT implements Startable {
24
23
  private readonly gateway?: string
25
24
  private started: boolean
26
25
  private client?: NatAPI
27
- readonly #log: Logger
26
+ private readonly log: Logger
28
27
 
29
28
  constructor (components: UPnPNATComponents, init: UPnPNATInit) {
30
29
  this.components = components
31
30
 
32
- this.#log = components.logger.forComponent('libp2p:upnp-nat')
31
+ this.log = components.logger.forComponent('libp2p:upnp-nat')
33
32
  this.started = false
34
33
  this.externalAddress = init.externalAddress
35
34
  this.localAddress = init.localAddress
@@ -66,7 +65,7 @@ export class UPnPNAT implements Startable {
66
65
  // done async to not slow down startup
67
66
  void this.mapIpAddresses().catch((err) => {
68
67
  // hole punching errors are non-fatal
69
- this.#log.error(err)
68
+ this.log.error(err)
70
69
  })
71
70
  }
72
71
 
@@ -108,7 +107,7 @@ export class UPnPNAT implements Startable {
108
107
 
109
108
  const publicPort = highPort()
110
109
 
111
- this.#log(`opening uPnP connection from ${publicIp}:${publicPort} to ${host}:${port}`)
110
+ this.log(`opening uPnP connection from ${publicIp}:${publicPort} to ${host}:${port}`)
112
111
 
113
112
  await client.map({
114
113
  publicPort,
@@ -152,7 +151,7 @@ export class UPnPNAT implements Startable {
152
151
  await this.client.close()
153
152
  this.client = undefined
154
153
  } catch (err: any) {
155
- this.#log.error(err)
154
+ this.log.error(err)
156
155
  }
157
156
  }
158
157
  }