@libp2p/interface-internal 2.1.1 → 2.2.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,4 +1,49 @@
1
1
  import type { Multiaddr } from '@multiformats/multiaddr';
2
+ /**
3
+ * The type of address:
4
+ *
5
+ * - 'transport' a listen address supplied by a transport
6
+ * - 'announce' a pre-configured announce address
7
+ * - 'observed' a peer reported this as a public address
8
+ * - 'dns-mapping' a DNS address dynamically mapped to one or more public addresses
9
+ * - 'ip-mapping' an external IP address dynamically mapped to a LAN address
10
+ */
11
+ export type AddressType = 'transport' | 'announce' | 'observed' | 'dns-mapping' | 'ip-mapping';
12
+ /**
13
+ * An address that has been configured or detected
14
+ */
15
+ export interface NodeAddress {
16
+ /**
17
+ * The multiaddr that represents the address
18
+ */
19
+ multiaddr: Multiaddr;
20
+ /**
21
+ * Dynamically configured addresses such as observed or IP/DNS mapped ones
22
+ * must be verified as valid by AutoNAT or some other means before the current
23
+ * node will add them to it's peer record and share them with peers.
24
+ *
25
+ * When this value is true, it's safe to share the address.
26
+ */
27
+ verified: boolean;
28
+ /**
29
+ * The timestamp at which the address was last verified
30
+ */
31
+ lastVerified?: number;
32
+ /**
33
+ * A millisecond timestamp after which this address should be reverified
34
+ */
35
+ expires: number;
36
+ /**
37
+ * The source of this address
38
+ */
39
+ type: AddressType;
40
+ }
41
+ export interface ConfirmAddressOptions {
42
+ /**
43
+ * Override the TTL of the observed address verification
44
+ */
45
+ ttl?: number;
46
+ }
2
47
  export interface AddressManager {
3
48
  /**
4
49
  * Get peer listen multiaddrs
@@ -17,7 +62,7 @@ export interface AddressManager {
17
62
  * Signal that we have confidence an observed multiaddr is publicly dialable -
18
63
  * this will make it appear in the output of getAddresses()
19
64
  */
20
- confirmObservedAddr(addr: Multiaddr): void;
65
+ confirmObservedAddr(addr: Multiaddr, options?: ConfirmAddressOptions): void;
21
66
  /**
22
67
  * Signal that we do not have confidence an observed multiaddr is publicly dialable -
23
68
  * this will remove it from the output of getObservedAddrs()
@@ -33,6 +78,10 @@ export interface AddressManager {
33
78
  * Get the current node's addresses
34
79
  */
35
80
  getAddresses(): Multiaddr[];
81
+ /**
82
+ * Return all known addresses with metadata
83
+ */
84
+ getAddressesWithMetadata(): NodeAddress[];
36
85
  /**
37
86
  * Adds a mapping between one or more IP addresses and a domain name - when
38
87
  * `getAddresses` is invoked, where the IP addresses are present in a
@@ -44,5 +93,20 @@ export interface AddressManager {
44
93
  * Remove a mapping previously added with `addDNSMapping`.
45
94
  */
46
95
  removeDNSMapping(domain: string): void;
96
+ /**
97
+ * Add a publicly routable address/port/protocol tuple that this node is
98
+ * reachable on. Where this node listens on a link-local (e.g. LAN) address
99
+ * with the same protocol for any transport, an additional listen address will
100
+ * be added with the IP and port replaced with this IP and port.
101
+ *
102
+ * It's possible to add a IPv6 address here and have it added to the address
103
+ * list, this is for the case when a router has an external IPv6 address with
104
+ * port forwarding configured, but it does IPv6 -> IPv4 NAT.
105
+ */
106
+ addPublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void;
107
+ /**
108
+ * Remove a publicly routable address that this node is no longer reachable on
109
+ */
110
+ removePublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void;
47
111
  }
48
112
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/address-manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,cAAc,IAAI,SAAS,EAAE,CAAA;IAE7B;;OAEG;IACH,gBAAgB,IAAI,SAAS,EAAE,CAAA;IAE/B;;;OAGG;IACH,gBAAgB,IAAI,SAAS,EAAE,CAAA;IAE/B;;;OAGG;IACH,mBAAmB,CAAC,IAAI,EAA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AAE,qBAAqB,GAAG,IAAI,CAAA;IAE3E;;;OAGG;IACH,kBAAkB,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IAEzC;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IAEtC;;OAEG;IACH,YAAY,IAAI,SAAS,EAAE,CAAA;IAE3B;;OAEG;IACH,wBAAwB,IAAI,WAAW,EAAE,CAAA;IAEzC;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAE1D;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAEtC;;;;;;;;;OASG;IACH,uBAAuB,CAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,CAAA;IAE7I;;OAEG;IACH,0BAA0B,CAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,CAAA;CACjJ"}
@@ -41,6 +41,11 @@ export interface ConnectionManager {
41
41
  * ```
42
42
  */
43
43
  getConnectionsMap(): PeerMap<Connection[]>;
44
+ /**
45
+ * Returns the configured maximum number of connections this connection
46
+ * manager will accept
47
+ */
48
+ getMaxConnections(): number;
44
49
  /**
45
50
  * Open a connection to a remote peer
46
51
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,iBAAiB,EAA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AE,CAAA;IAE7B;;;;;;;;OAQG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC9F"}
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "AddressManager": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.AddressManager.html",
3
+ "ConfirmAddressOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.ConfirmAddressOptions.html",
3
4
  "ConnectionManager": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.ConnectionManager.html",
4
5
  "Envelope": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.Envelope.html",
5
6
  "IncomingStreamData": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.IncomingStreamData.html",
7
+ "NodeAddress": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.NodeAddress.html",
6
8
  "OpenConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.OpenConnectionOptions.html",
7
9
  "RandomWalk": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.RandomWalk.html",
8
10
  "Record": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.Record.html",
@@ -11,5 +13,6 @@
11
13
  "StreamHandlerOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.StreamHandlerOptions.html",
12
14
  "StreamHandlerRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.StreamHandlerRecord.html",
13
15
  "TransportManager": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.TransportManager.html",
14
- "TransportManagerDialOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.TransportManagerDialOptions.html"
16
+ "TransportManagerDialOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_internal.TransportManagerDialOptions.html",
17
+ "AddressType": "https://libp2p.github.io/js-libp2p/types/_libp2p_interface_internal.AddressType.html"
15
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface-internal",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "Interfaces implemented by internal libp2p components",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface-internal#readme",
@@ -48,14 +48,14 @@
48
48
  "build": "aegir build"
49
49
  },
50
50
  "dependencies": {
51
- "@libp2p/interface": "^2.2.1",
52
- "@libp2p/peer-collections": "^6.0.12",
53
- "@multiformats/multiaddr": "^12.2.3",
54
- "progress-events": "^1.0.0",
51
+ "@libp2p/interface": "^2.3.0",
52
+ "@libp2p/peer-collections": "^6.0.13",
53
+ "@multiformats/multiaddr": "^12.3.3",
54
+ "progress-events": "^1.0.1",
55
55
  "uint8arraylist": "^2.4.8"
56
56
  },
57
57
  "devDependencies": {
58
- "aegir": "^44.0.1"
58
+ "aegir": "^45.0.5"
59
59
  },
60
60
  "sideEffects": false
61
61
  }
@@ -1,5 +1,57 @@
1
1
  import type { Multiaddr } from '@multiformats/multiaddr'
2
2
 
3
+ /**
4
+ * The type of address:
5
+ *
6
+ * - 'transport' a listen address supplied by a transport
7
+ * - 'announce' a pre-configured announce address
8
+ * - 'observed' a peer reported this as a public address
9
+ * - 'dns-mapping' a DNS address dynamically mapped to one or more public addresses
10
+ * - 'ip-mapping' an external IP address dynamically mapped to a LAN address
11
+ */
12
+ export type AddressType = 'transport' | 'announce' | 'observed' | 'dns-mapping' | 'ip-mapping'
13
+
14
+ /**
15
+ * An address that has been configured or detected
16
+ */
17
+ export interface NodeAddress {
18
+ /**
19
+ * The multiaddr that represents the address
20
+ */
21
+ multiaddr: Multiaddr
22
+
23
+ /**
24
+ * Dynamically configured addresses such as observed or IP/DNS mapped ones
25
+ * must be verified as valid by AutoNAT or some other means before the current
26
+ * node will add them to it's peer record and share them with peers.
27
+ *
28
+ * When this value is true, it's safe to share the address.
29
+ */
30
+ verified: boolean
31
+
32
+ /**
33
+ * The timestamp at which the address was last verified
34
+ */
35
+ lastVerified?: number
36
+
37
+ /**
38
+ * A millisecond timestamp after which this address should be reverified
39
+ */
40
+ expires: number
41
+
42
+ /**
43
+ * The source of this address
44
+ */
45
+ type: AddressType
46
+ }
47
+
48
+ export interface ConfirmAddressOptions {
49
+ /**
50
+ * Override the TTL of the observed address verification
51
+ */
52
+ ttl?: number
53
+ }
54
+
3
55
  export interface AddressManager {
4
56
  /**
5
57
  * Get peer listen multiaddrs
@@ -21,7 +73,7 @@ export interface AddressManager {
21
73
  * Signal that we have confidence an observed multiaddr is publicly dialable -
22
74
  * this will make it appear in the output of getAddresses()
23
75
  */
24
- confirmObservedAddr(addr: Multiaddr): void
76
+ confirmObservedAddr(addr: Multiaddr, options?: ConfirmAddressOptions): void
25
77
 
26
78
  /**
27
79
  * Signal that we do not have confidence an observed multiaddr is publicly dialable -
@@ -41,6 +93,11 @@ export interface AddressManager {
41
93
  */
42
94
  getAddresses(): Multiaddr[]
43
95
 
96
+ /**
97
+ * Return all known addresses with metadata
98
+ */
99
+ getAddressesWithMetadata(): NodeAddress[]
100
+
44
101
  /**
45
102
  * Adds a mapping between one or more IP addresses and a domain name - when
46
103
  * `getAddresses` is invoked, where the IP addresses are present in a
@@ -53,4 +110,21 @@ export interface AddressManager {
53
110
  * Remove a mapping previously added with `addDNSMapping`.
54
111
  */
55
112
  removeDNSMapping(domain: string): void
113
+
114
+ /**
115
+ * Add a publicly routable address/port/protocol tuple that this node is
116
+ * reachable on. Where this node listens on a link-local (e.g. LAN) address
117
+ * with the same protocol for any transport, an additional listen address will
118
+ * be added with the IP and port replaced with this IP and port.
119
+ *
120
+ * It's possible to add a IPv6 address here and have it added to the address
121
+ * list, this is for the case when a router has an external IPv6 address with
122
+ * port forwarding configured, but it does IPv6 -> IPv4 NAT.
123
+ */
124
+ addPublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void
125
+
126
+ /**
127
+ * Remove a publicly routable address that this node is no longer reachable on
128
+ */
129
+ removePublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void
56
130
  }
@@ -46,6 +46,12 @@ export interface ConnectionManager {
46
46
  */
47
47
  getConnectionsMap(): PeerMap<Connection[]>
48
48
 
49
+ /**
50
+ * Returns the configured maximum number of connections this connection
51
+ * manager will accept
52
+ */
53
+ getMaxConnections(): number
54
+
49
55
  /**
50
56
  * Open a connection to a remote peer
51
57
  *
package/LICENSE DELETED
@@ -1,4 +0,0 @@
1
- This project is dual licensed under MIT and Apache-2.0.
2
-
3
- MIT: https://www.opensource.org/licenses/mit
4
- Apache-2.0: https://www.apache.org/licenses/license-2.0