@libp2p/interface-internal 2.3.0-68ad3663e → 2.3.0-b818882e0
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/address-manager.d.ts +0 -39
- package/dist/src/address-manager.d.ts.map +1 -1
- package/dist/src/connection-manager.d.ts +21 -28
- package/dist/src/connection-manager.d.ts.map +1 -1
- package/dist/src/index.d.ts +0 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/random-walk.d.ts +4 -11
- package/dist/src/random-walk.d.ts.map +1 -1
- package/dist/src/registrar.d.ts +7 -41
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/transport-manager.d.ts +1 -39
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/address-manager.ts +0 -39
- package/src/connection-manager.ts +21 -28
- package/src/index.ts +0 -10
- package/src/random-walk.ts +4 -11
- package/src/registrar.ts +7 -41
- package/src/transport-manager.ts +1 -39
|
@@ -48,64 +48,42 @@ export interface ConfirmAddressOptions {
|
|
|
48
48
|
*/
|
|
49
49
|
type?: AddressType;
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
52
|
-
* The `AddressManager` provides an interface for managing peer addresses
|
|
53
|
-
* in libp2p. It supports handling multiple types of addresses, verifying their validity,
|
|
54
|
-
* and storing mappings between internal and external addresses.
|
|
55
|
-
*/
|
|
56
51
|
export interface AddressManager {
|
|
57
52
|
/**
|
|
58
53
|
* Get peer listen multiaddrs
|
|
59
|
-
*
|
|
60
|
-
* @returns An array of `Multiaddr` objects representing listen addresses.
|
|
61
54
|
*/
|
|
62
55
|
getListenAddrs(): Multiaddr[];
|
|
63
56
|
/**
|
|
64
57
|
* Get peer announcing multiaddrs
|
|
65
|
-
*
|
|
66
|
-
* @returns An array of `Multiaddr` objects representing announce addresses.
|
|
67
58
|
*/
|
|
68
59
|
getAnnounceAddrs(): Multiaddr[];
|
|
69
60
|
/**
|
|
70
61
|
* Get observed multiaddrs - these addresses may not have been confirmed as
|
|
71
62
|
* publicly dialable yet
|
|
72
|
-
*
|
|
73
|
-
* @returns An array of `Multiaddr` objects representing observed addresses.
|
|
74
63
|
*/
|
|
75
64
|
getObservedAddrs(): Multiaddr[];
|
|
76
65
|
/**
|
|
77
66
|
* Signal that we have confidence an observed multiaddr is publicly dialable -
|
|
78
67
|
* this will make it appear in the output of getAddresses()
|
|
79
|
-
*
|
|
80
|
-
* @param addr - The observed address.
|
|
81
|
-
* @param options - Additional options for confirmation.
|
|
82
68
|
*/
|
|
83
69
|
confirmObservedAddr(addr: Multiaddr, options?: ConfirmAddressOptions): void;
|
|
84
70
|
/**
|
|
85
71
|
* Signal that we do not have confidence an observed multiaddr is publicly dialable -
|
|
86
72
|
* this will remove it from the output of getObservedAddrs()
|
|
87
|
-
*
|
|
88
|
-
* @param addr - The observed address to remove.
|
|
89
73
|
*/
|
|
90
74
|
removeObservedAddr(addr: Multiaddr): void;
|
|
91
75
|
/**
|
|
92
76
|
* Add peer observed addresses. These will then appear in the output of getObservedAddrs
|
|
93
77
|
* but not getAddresses() until their dialability has been confirmed via a call to
|
|
94
78
|
* confirmObservedAddr.
|
|
95
|
-
*
|
|
96
|
-
* @param addr - The observed address to add.
|
|
97
79
|
*/
|
|
98
80
|
addObservedAddr(addr: Multiaddr): void;
|
|
99
81
|
/**
|
|
100
82
|
* Get the current node's addresses
|
|
101
|
-
*
|
|
102
|
-
* @returns An array of `Multiaddr` objects representing node addresses.
|
|
103
83
|
*/
|
|
104
84
|
getAddresses(): Multiaddr[];
|
|
105
85
|
/**
|
|
106
86
|
* Return all known addresses with metadata
|
|
107
|
-
*
|
|
108
|
-
* @returns An array of `NodeAddress` objects.
|
|
109
87
|
*/
|
|
110
88
|
getAddressesWithMetadata(): NodeAddress[];
|
|
111
89
|
/**
|
|
@@ -113,15 +91,10 @@ export interface AddressManager {
|
|
|
113
91
|
* `getAddresses` is invoked, where the IP addresses are present in a
|
|
114
92
|
* multiaddr, an additional multiaddr will be added with `ip4` and `ip6`
|
|
115
93
|
* tuples replaced with `dns4` and `dns6 ones respectively.
|
|
116
|
-
*
|
|
117
|
-
* @param domain - The domain name to map.
|
|
118
|
-
* @param ipAddresses - The associated IP addresses.
|
|
119
94
|
*/
|
|
120
95
|
addDNSMapping(domain: string, ipAddresses: string[]): void;
|
|
121
96
|
/**
|
|
122
97
|
* Remove a mapping previously added with `addDNSMapping`.
|
|
123
|
-
*
|
|
124
|
-
* @param domain - The domain name mapping to remove.
|
|
125
98
|
*/
|
|
126
99
|
removeDNSMapping(domain: string): void;
|
|
127
100
|
/**
|
|
@@ -133,22 +106,10 @@ export interface AddressManager {
|
|
|
133
106
|
* It's possible to add a IPv6 address here and have it added to the address
|
|
134
107
|
* list, this is for the case when a router has an external IPv6 address with
|
|
135
108
|
* port forwarding configured, but it does IPv6 -> IPv4 NAT.
|
|
136
|
-
*
|
|
137
|
-
* @param internalIp - The internal IP address.
|
|
138
|
-
* @param internalPort - The internal port number.
|
|
139
|
-
* @param externalIp - The external IP address.
|
|
140
|
-
* @param externalPort - The external port number (optional).
|
|
141
|
-
* @param protocol - The transport protocol (`tcp` or `udp`).
|
|
142
109
|
*/
|
|
143
110
|
addPublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void;
|
|
144
111
|
/**
|
|
145
112
|
* Remove a publicly routable address that this node is no longer reachable on
|
|
146
|
-
*
|
|
147
|
-
* @param internalIp - The internal IP address.
|
|
148
|
-
* @param internalPort - The internal port number.
|
|
149
|
-
* @param externalIp - The external IP address.
|
|
150
|
-
* @param externalPort - The external port number (optional).
|
|
151
|
-
* @param protocol - The transport protocol (`tcp` or `udp`).
|
|
152
113
|
*/
|
|
153
114
|
removePublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void;
|
|
154
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-manager.d.ts","sourceRoot":"","sources":["../../src/address-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,GAAG,YAAY,CAAA;AAE9F;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;;;;;OAMG;IACH,QAAQ,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB;AAED
|
|
1
|
+
{"version":3,"file":"address-manager.d.ts","sourceRoot":"","sources":["../../src/address-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,GAAG,YAAY,CAAA;AAE9F;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;;;;;OAMG;IACH,QAAQ,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB;AAED,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,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,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"}
|
|
@@ -2,9 +2,6 @@ import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId
|
|
|
2
2
|
import type { PeerMap } from '@libp2p/peer-collections';
|
|
3
3
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
4
4
|
import type { ProgressOptions } from 'progress-events';
|
|
5
|
-
/**
|
|
6
|
-
* Options for opening a connection to a remote peer.
|
|
7
|
-
*/
|
|
8
5
|
export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> {
|
|
9
6
|
/**
|
|
10
7
|
* Connection requests with a higher priority will be executed before those
|
|
@@ -33,46 +30,45 @@ export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<Ope
|
|
|
33
30
|
*/
|
|
34
31
|
initiator?: boolean;
|
|
35
32
|
}
|
|
36
|
-
/**
|
|
37
|
-
* The `ConnectionManager` handles managing connections between peers in a libp2p network.
|
|
38
|
-
* It provides methods for opening, closing, and querying connections.This also provides methods
|
|
39
|
-
* for accessing the dial queue.
|
|
40
|
-
*/
|
|
41
33
|
export interface ConnectionManager {
|
|
42
34
|
/**
|
|
43
35
|
* Return connections, optionally filtering by a PeerId
|
|
44
36
|
*
|
|
45
|
-
* @
|
|
46
|
-
*
|
|
37
|
+
* @example
|
|
38
|
+
*
|
|
39
|
+
* ```TypeScript
|
|
40
|
+
* const connections = libp2p.connectionManager.get(peerId)
|
|
41
|
+
* // []
|
|
42
|
+
* ```
|
|
47
43
|
*/
|
|
48
44
|
getConnections(peerId?: PeerId): Connection[];
|
|
49
45
|
/**
|
|
50
46
|
* Return a map of all connections with their associated PeerIds
|
|
51
47
|
*
|
|
52
|
-
* @
|
|
48
|
+
* @example
|
|
49
|
+
*
|
|
50
|
+
* ```TypeScript
|
|
51
|
+
* const connectionsMap = libp2p.connectionManager.getConnectionsMap()
|
|
52
|
+
* ```
|
|
53
53
|
*/
|
|
54
54
|
getConnectionsMap(): PeerMap<Connection[]>;
|
|
55
55
|
/**
|
|
56
56
|
* Returns the configured maximum number of connections this connection
|
|
57
57
|
* manager will accept
|
|
58
|
-
*
|
|
59
|
-
* @returns The maximum connection limit.
|
|
60
58
|
*/
|
|
61
59
|
getMaxConnections(): number;
|
|
62
60
|
/**
|
|
63
61
|
* Open a connection to a remote peer
|
|
64
62
|
*
|
|
65
|
-
* @
|
|
66
|
-
*
|
|
67
|
-
*
|
|
63
|
+
* @example
|
|
64
|
+
*
|
|
65
|
+
* ```TypeScript
|
|
66
|
+
* const connection = await libp2p.connectionManager.openConnection(peerId)
|
|
67
|
+
* ```
|
|
68
68
|
*/
|
|
69
69
|
openConnection(peer: PeerId | Multiaddr | Multiaddr[], options?: OpenConnectionOptions): Promise<Connection>;
|
|
70
70
|
/**
|
|
71
71
|
* Close our connections to a peer
|
|
72
|
-
*
|
|
73
|
-
* @param peer - The `PeerId` whose connections should be closed.
|
|
74
|
-
* @param options - Optional abort options.
|
|
75
|
-
* @returns A promise that resolves once the connections are closed.
|
|
76
72
|
*/
|
|
77
73
|
closeConnections(peer: PeerId, options?: AbortOptions): Promise<void>;
|
|
78
74
|
/**
|
|
@@ -80,9 +76,6 @@ export interface ConnectionManager {
|
|
|
80
76
|
* exchanged, this lets the ConnectionManager check we have sufficient
|
|
81
77
|
* resources to accept the connection in which case it will return true,
|
|
82
78
|
* otherwise it will return false.
|
|
83
|
-
*
|
|
84
|
-
* @param maConn - The multiaddr connection to evaluate.
|
|
85
|
-
* @returns A promise that resolves to `true` if the connection can be accepted, `false` otherwise.
|
|
86
79
|
*/
|
|
87
80
|
acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean>;
|
|
88
81
|
/**
|
|
@@ -92,7 +85,11 @@ export interface ConnectionManager {
|
|
|
92
85
|
/**
|
|
93
86
|
* Return the list of in-progress or queued dials
|
|
94
87
|
*
|
|
95
|
-
* @
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* ```TypeScript
|
|
91
|
+
* const dials = libp2p.connectionManager.getDialQueue()
|
|
92
|
+
* ```
|
|
96
93
|
*/
|
|
97
94
|
getDialQueue(): PendingDial[];
|
|
98
95
|
/**
|
|
@@ -103,10 +100,6 @@ export interface ConnectionManager {
|
|
|
103
100
|
* would not block the dial attempt.
|
|
104
101
|
*
|
|
105
102
|
* This may involve resolving DNS addresses so you should pass an AbortSignal.
|
|
106
|
-
*
|
|
107
|
-
* @param multiaddr - The target multiaddr or an array of multiaddrs.
|
|
108
|
-
* @param options - Optional parameters for dialability check.
|
|
109
|
-
* @returns A promise that resolves to `true` if the multiaddr is dialable, `false` otherwise.
|
|
110
103
|
*/
|
|
111
104
|
isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>;
|
|
112
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../src/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAC5J,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD
|
|
1
|
+
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../src/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAC5J,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,MAAM,WAAW,qBAAsB,SAAQ,YAAY,EAAE,eAAe,CAAC,4BAA4B,CAAC;IACxG;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;OASG;IACH,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE,CAAA;IAE7C;;;;;;;;OAQG;IACH,iBAAiB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;IAE1C;;;OAGG;IACH,iBAAiB,IAAI,MAAM,CAAA;IAE3B;;;;;;;;OAQG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE5G;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAErE;;;;;OAKG;IACH,wBAAwB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAEvE;;OAEG;IACH,mBAAmB,IAAI,IAAI,CAAA;IAE3B;;;;;;;;OAQG;IACH,YAAY,IAAI,WAAW,EAAE,CAAA;IAE7B;;;;;;;;OAQG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC9F"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* This module serves as the entry point for `@libp2p/interface-internal`,
|
|
5
|
-
* re-exporting key components such as `AddressManager`, `ConnectionManager`,
|
|
6
|
-
* `RandomWalk`, `Registrar`, and `TransportManager`.
|
|
7
|
-
*
|
|
8
|
-
* These interfaces and classes define the core internal behaviors of libp2p.
|
|
9
|
-
*/
|
|
10
1
|
export * from './address-manager.js';
|
|
11
2
|
export * from './connection-manager.js';
|
|
12
3
|
export * from './random-walk.js';
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* This module serves as the entry point for `@libp2p/interface-internal`,
|
|
5
|
-
* re-exporting key components such as `AddressManager`, `ConnectionManager`,
|
|
6
|
-
* `RandomWalk`, `Registrar`, and `TransportManager`.
|
|
7
|
-
*
|
|
8
|
-
* These interfaces and classes define the core internal behaviors of libp2p.
|
|
9
|
-
*/
|
|
10
1
|
export * from './address-manager.js';
|
|
11
2
|
export * from './connection-manager.js';
|
|
12
3
|
export * from './random-walk.js';
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA"}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import type { AbortOptions, PeerInfo } from '@libp2p/interface';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* protocol to run and any registered topologies to be notified of their
|
|
6
|
-
* supported protocols.
|
|
3
|
+
* RandomWalk finds random peers on the network and dials them. Use this after
|
|
4
|
+
* registering a Topology if you need to discover common network services.
|
|
7
5
|
*/
|
|
8
6
|
export interface RandomWalk {
|
|
9
7
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* This method either begins a new random walk or joins an existing one. The process
|
|
13
|
-
* continues to find and return random peers until it is aborted.
|
|
14
|
-
*
|
|
15
|
-
* @param options - Optional `AbortOptions` to allow early termination of the walk.
|
|
16
|
-
* @returns An `AsyncGenerator` that yields discovered `PeerInfo` objects.
|
|
8
|
+
* Begin or join an existing walk. Abort the passed signal if you wish to
|
|
9
|
+
* abort the walk early.
|
|
17
10
|
*/
|
|
18
11
|
walk(options?: AbortOptions): AsyncGenerator<PeerInfo>;
|
|
19
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random-walk.d.ts","sourceRoot":"","sources":["../../src/random-walk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE/D
|
|
1
|
+
{"version":3,"file":"random-walk.d.ts","sourceRoot":"","sources":["../../src/random-walk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE/D;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;CACvD"}
|
package/dist/src/registrar.d.ts
CHANGED
|
@@ -16,46 +16,21 @@ StreamHandlerOptions,
|
|
|
16
16
|
* @deprecated This type should be imported from @libp2p/interface directly
|
|
17
17
|
*/
|
|
18
18
|
StreamHandlerRecord };
|
|
19
|
-
/**
|
|
20
|
-
* The `Registrar` provides an interface for registering protocol handlers -
|
|
21
|
-
* these are invoked when remote peers open streams on the local node with the
|
|
22
|
-
* corresponding protocol name.
|
|
23
|
-
*
|
|
24
|
-
* It also allows configuring network topologies for a given protocol(s). The
|
|
25
|
-
* topology callbacks are invoked when a peer that supports those protocols
|
|
26
|
-
* connects or disconnects.
|
|
27
|
-
*
|
|
28
|
-
* The Identify protocol must be configured on the current node for topologies
|
|
29
|
-
* to function.
|
|
30
|
-
*/
|
|
31
19
|
export interface Registrar {
|
|
32
20
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @returns An array of protocol strings.
|
|
21
|
+
* Return the list of protocols with registered handlers
|
|
36
22
|
*/
|
|
37
23
|
getProtocols(): string[];
|
|
38
24
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @param protocol - The protocol string (e.g., `/my-protocol/1.0.0`).
|
|
42
|
-
* @param handler - The function that handles incoming streams.
|
|
43
|
-
* @param options - Optional configuration options for the handler.
|
|
44
|
-
* @returns A promise that resolves once the handler is registered.
|
|
25
|
+
* Add a protocol handler
|
|
45
26
|
*/
|
|
46
27
|
handle(protocol: string, handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>;
|
|
47
28
|
/**
|
|
48
|
-
* Remove a
|
|
49
|
-
*
|
|
50
|
-
* @param protocol - The protocol to unhandle.
|
|
51
|
-
* @returns A promise that resolves once the handler is removed.
|
|
29
|
+
* Remove a protocol handler
|
|
52
30
|
*/
|
|
53
31
|
unhandle(protocol: string): Promise<void>;
|
|
54
32
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @param protocol - The protocol to query.
|
|
58
|
-
* @returns A `StreamHandlerRecord` containing the handler and options.
|
|
33
|
+
* Return the handler for the passed protocol
|
|
59
34
|
*/
|
|
60
35
|
getHandler(protocol: string): StreamHandlerRecord;
|
|
61
36
|
/**
|
|
@@ -65,24 +40,15 @@ export interface Registrar {
|
|
|
65
40
|
*
|
|
66
41
|
* An id will be returned that can later be used to unregister the
|
|
67
42
|
* topology.
|
|
68
|
-
*
|
|
69
|
-
* @param protocol - The protocol to register.
|
|
70
|
-
* @param topology - The topology handler to register.
|
|
71
|
-
* @returns A promise resolving to a unique ID for the registered topology.
|
|
72
43
|
*/
|
|
73
44
|
register(protocol: string, topology: Topology): Promise<string>;
|
|
74
45
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @param id - The ID of the topology to unregister.
|
|
46
|
+
* Remove the topology handler with the passed id.
|
|
78
47
|
*/
|
|
79
48
|
unregister(id: string): void;
|
|
80
49
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @param protocol - The protocol to query.
|
|
85
|
-
* @returns An array of registered `Topology` handlers.
|
|
50
|
+
* Return all topology handlers that wish to be informed about peers
|
|
51
|
+
* that support the passed protocol.
|
|
86
52
|
*/
|
|
87
53
|
getTopologies(protocol: string): Topology[];
|
|
88
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE/H,YAAY;AACV;;GAEG;AACH,kBAAkB;AAElB;;GAEG;AACH,aAAa;AAEb;;GAEG;AACH,oBAAoB;AAEpB;;GAEG;AACH,mBAAmB,EACpB,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE/H,YAAY;AACV;;GAEG;AACH,kBAAkB;AAElB;;GAEG;AACH,aAAa;AAEb;;GAEG;AACH,oBAAoB;AAEpB;;GAEG;AACH,mBAAmB,EACpB,CAAA;AAED,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,YAAY,IAAI,MAAM,EAAE,CAAA;IAExB;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE/F;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzC;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,CAAA;IAEjD;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE/D;;OAEG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAE5B;;;OAGG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAA;CAC5C"}
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import type { AbortOptions, Connection, Listener, Transport, TransportManagerDialProgressEvents } from '@libp2p/interface';
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
3
|
import type { ProgressOptions } from 'progress-events';
|
|
4
|
-
/**
|
|
5
|
-
* Options for dialing a connection using the `TransportManager`.
|
|
6
|
-
*/
|
|
7
4
|
export interface TransportManagerDialOptions extends AbortOptions, ProgressOptions<TransportManagerDialProgressEvents> {
|
|
8
5
|
}
|
|
9
|
-
/**
|
|
10
|
-
* The `TransportManager` handles the management of network transports, allowing
|
|
11
|
-
* opening connections or listening using specific transports, etc.
|
|
12
|
-
*
|
|
13
|
-
* This is a low-level component - any connections opened will not be managed by
|
|
14
|
-
* the `ConnectionManager` or included in any configured connection limits, etc.
|
|
15
|
-
*
|
|
16
|
-
* Most consumers will call `openConnection` on the `ConnectionManager` instead.
|
|
17
|
-
*/
|
|
18
6
|
export interface TransportManager {
|
|
19
7
|
/**
|
|
20
|
-
* Add a transport to the transport manager
|
|
21
|
-
*
|
|
22
|
-
* @param transport - The transport instance to be added.
|
|
8
|
+
* Add a transport to the transport manager
|
|
23
9
|
*/
|
|
24
10
|
add(transport: Transport): void;
|
|
25
11
|
/**
|
|
@@ -27,63 +13,39 @@ export interface TransportManager {
|
|
|
27
13
|
* by the connection manager so can cause memory leaks. If you need to dial
|
|
28
14
|
* a multiaddr, you may want to call openConnection on the connection manager
|
|
29
15
|
* instead.
|
|
30
|
-
*
|
|
31
|
-
* @param ma - The multiaddr to dial.
|
|
32
|
-
* @param options - Optional dial options.
|
|
33
|
-
* @returns A promise that resolves to a `Connection` object.
|
|
34
16
|
*/
|
|
35
17
|
dial(ma: Multiaddr, options?: TransportManagerDialOptions): Promise<Connection>;
|
|
36
18
|
/**
|
|
37
19
|
* Return all addresses currently being listened on
|
|
38
|
-
*
|
|
39
|
-
* @returns An array of `Multiaddr` objects.
|
|
40
20
|
*/
|
|
41
21
|
getAddrs(): Multiaddr[];
|
|
42
22
|
/**
|
|
43
23
|
* Return all registered transports
|
|
44
|
-
*
|
|
45
|
-
* @returns An array of `Transport` instances.
|
|
46
24
|
*/
|
|
47
25
|
getTransports(): Transport[];
|
|
48
26
|
/**
|
|
49
27
|
* Return all listeners
|
|
50
|
-
*
|
|
51
|
-
* @returns An array of `Listener` instances.
|
|
52
28
|
*/
|
|
53
29
|
getListeners(): Listener[];
|
|
54
30
|
/**
|
|
55
31
|
* Get the transport to dial a given multiaddr, if one has been configured
|
|
56
|
-
*
|
|
57
|
-
* @param ma - The target multiaddr.
|
|
58
|
-
* @returns A `Transport` instance if available, otherwise `undefined`.
|
|
59
32
|
*/
|
|
60
33
|
dialTransportForMultiaddr(ma: Multiaddr): Transport | undefined;
|
|
61
34
|
/**
|
|
62
35
|
* Get the transport to listen on a given multiaddr, if one has been
|
|
63
36
|
* configured
|
|
64
|
-
*
|
|
65
|
-
* @param ma - The target multiaddr.
|
|
66
|
-
* @returns A `Transport` instance if available, otherwise `undefined`.
|
|
67
37
|
*/
|
|
68
38
|
listenTransportForMultiaddr(ma: Multiaddr): Transport | undefined;
|
|
69
39
|
/**
|
|
70
40
|
* Listen on the passed multiaddrs
|
|
71
|
-
*
|
|
72
|
-
* @param addrs - An array of multiaddrs to listen on.
|
|
73
|
-
* @returns A promise that resolves once the transport is actively listening.
|
|
74
41
|
*/
|
|
75
42
|
listen(addrs: Multiaddr[]): Promise<void>;
|
|
76
43
|
/**
|
|
77
44
|
* Remove a previously configured transport
|
|
78
|
-
*
|
|
79
|
-
* @param key - The transport key or identifier.
|
|
80
|
-
* @returns A promise that resolves once the transport is removed.
|
|
81
45
|
*/
|
|
82
46
|
remove(key: string): Promise<void>;
|
|
83
47
|
/**
|
|
84
48
|
* Remove all transports
|
|
85
|
-
*
|
|
86
|
-
* @returns A promise that resolves once all transports are removed.
|
|
87
49
|
*/
|
|
88
50
|
removeAll(): Promise<void>;
|
|
89
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-manager.d.ts","sourceRoot":"","sources":["../../src/transport-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,kCAAkC,EAAE,MAAM,mBAAmB,CAAA;AAC1H,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD
|
|
1
|
+
{"version":3,"file":"transport-manager.d.ts","sourceRoot":"","sources":["../../src/transport-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,kCAAkC,EAAE,MAAM,mBAAmB,CAAA;AAC1H,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,MAAM,WAAW,2BAA4B,SAAQ,YAAY,EAAE,eAAe,CAAC,kCAAkC,CAAC;CAErH;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAA;IAE/B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE/E;;OAEG;IACH,QAAQ,IAAI,SAAS,EAAE,CAAA;IAEvB;;OAEG;IACH,aAAa,IAAI,SAAS,EAAE,CAAA;IAE5B;;OAEG;IACH,YAAY,IAAI,QAAQ,EAAE,CAAA;IAE1B;;OAEG;IACH,yBAAyB,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IAE/D;;;OAGG;IACH,2BAA2B,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IAEjE;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzC;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAElC;;OAEG;IACH,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interface-internal",
|
|
3
|
-
"version": "2.3.0-
|
|
3
|
+
"version": "2.3.0-b818882e0",
|
|
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,8 +48,8 @@
|
|
|
48
48
|
"build": "aegir build"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@libp2p/interface": "2.5.0-
|
|
52
|
-
"@libp2p/peer-collections": "6.0.17-
|
|
51
|
+
"@libp2p/interface": "2.5.0-b818882e0",
|
|
52
|
+
"@libp2p/peer-collections": "6.0.17-b818882e0",
|
|
53
53
|
"@multiformats/multiaddr": "^12.3.3",
|
|
54
54
|
"progress-events": "^1.0.1"
|
|
55
55
|
},
|
package/src/address-manager.ts
CHANGED
|
@@ -57,48 +57,32 @@ export interface ConfirmAddressOptions {
|
|
|
57
57
|
type?: AddressType
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/**
|
|
61
|
-
* The `AddressManager` provides an interface for managing peer addresses
|
|
62
|
-
* in libp2p. It supports handling multiple types of addresses, verifying their validity,
|
|
63
|
-
* and storing mappings between internal and external addresses.
|
|
64
|
-
*/
|
|
65
60
|
export interface AddressManager {
|
|
66
61
|
/**
|
|
67
62
|
* Get peer listen multiaddrs
|
|
68
|
-
*
|
|
69
|
-
* @returns An array of `Multiaddr` objects representing listen addresses.
|
|
70
63
|
*/
|
|
71
64
|
getListenAddrs(): Multiaddr[]
|
|
72
65
|
|
|
73
66
|
/**
|
|
74
67
|
* Get peer announcing multiaddrs
|
|
75
|
-
*
|
|
76
|
-
* @returns An array of `Multiaddr` objects representing announce addresses.
|
|
77
68
|
*/
|
|
78
69
|
getAnnounceAddrs(): Multiaddr[]
|
|
79
70
|
|
|
80
71
|
/**
|
|
81
72
|
* Get observed multiaddrs - these addresses may not have been confirmed as
|
|
82
73
|
* publicly dialable yet
|
|
83
|
-
*
|
|
84
|
-
* @returns An array of `Multiaddr` objects representing observed addresses.
|
|
85
74
|
*/
|
|
86
75
|
getObservedAddrs(): Multiaddr[]
|
|
87
76
|
|
|
88
77
|
/**
|
|
89
78
|
* Signal that we have confidence an observed multiaddr is publicly dialable -
|
|
90
79
|
* this will make it appear in the output of getAddresses()
|
|
91
|
-
*
|
|
92
|
-
* @param addr - The observed address.
|
|
93
|
-
* @param options - Additional options for confirmation.
|
|
94
80
|
*/
|
|
95
81
|
confirmObservedAddr(addr: Multiaddr, options?: ConfirmAddressOptions): void
|
|
96
82
|
|
|
97
83
|
/**
|
|
98
84
|
* Signal that we do not have confidence an observed multiaddr is publicly dialable -
|
|
99
85
|
* this will remove it from the output of getObservedAddrs()
|
|
100
|
-
*
|
|
101
|
-
* @param addr - The observed address to remove.
|
|
102
86
|
*/
|
|
103
87
|
removeObservedAddr(addr: Multiaddr): void
|
|
104
88
|
|
|
@@ -106,22 +90,16 @@ export interface AddressManager {
|
|
|
106
90
|
* Add peer observed addresses. These will then appear in the output of getObservedAddrs
|
|
107
91
|
* but not getAddresses() until their dialability has been confirmed via a call to
|
|
108
92
|
* confirmObservedAddr.
|
|
109
|
-
*
|
|
110
|
-
* @param addr - The observed address to add.
|
|
111
93
|
*/
|
|
112
94
|
addObservedAddr(addr: Multiaddr): void
|
|
113
95
|
|
|
114
96
|
/**
|
|
115
97
|
* Get the current node's addresses
|
|
116
|
-
*
|
|
117
|
-
* @returns An array of `Multiaddr` objects representing node addresses.
|
|
118
98
|
*/
|
|
119
99
|
getAddresses(): Multiaddr[]
|
|
120
100
|
|
|
121
101
|
/**
|
|
122
102
|
* Return all known addresses with metadata
|
|
123
|
-
*
|
|
124
|
-
* @returns An array of `NodeAddress` objects.
|
|
125
103
|
*/
|
|
126
104
|
getAddressesWithMetadata(): NodeAddress[]
|
|
127
105
|
|
|
@@ -130,16 +108,11 @@ export interface AddressManager {
|
|
|
130
108
|
* `getAddresses` is invoked, where the IP addresses are present in a
|
|
131
109
|
* multiaddr, an additional multiaddr will be added with `ip4` and `ip6`
|
|
132
110
|
* tuples replaced with `dns4` and `dns6 ones respectively.
|
|
133
|
-
*
|
|
134
|
-
* @param domain - The domain name to map.
|
|
135
|
-
* @param ipAddresses - The associated IP addresses.
|
|
136
111
|
*/
|
|
137
112
|
addDNSMapping(domain: string, ipAddresses: string[]): void
|
|
138
113
|
|
|
139
114
|
/**
|
|
140
115
|
* Remove a mapping previously added with `addDNSMapping`.
|
|
141
|
-
*
|
|
142
|
-
* @param domain - The domain name mapping to remove.
|
|
143
116
|
*/
|
|
144
117
|
removeDNSMapping(domain: string): void
|
|
145
118
|
|
|
@@ -152,23 +125,11 @@ export interface AddressManager {
|
|
|
152
125
|
* It's possible to add a IPv6 address here and have it added to the address
|
|
153
126
|
* list, this is for the case when a router has an external IPv6 address with
|
|
154
127
|
* port forwarding configured, but it does IPv6 -> IPv4 NAT.
|
|
155
|
-
*
|
|
156
|
-
* @param internalIp - The internal IP address.
|
|
157
|
-
* @param internalPort - The internal port number.
|
|
158
|
-
* @param externalIp - The external IP address.
|
|
159
|
-
* @param externalPort - The external port number (optional).
|
|
160
|
-
* @param protocol - The transport protocol (`tcp` or `udp`).
|
|
161
128
|
*/
|
|
162
129
|
addPublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void
|
|
163
130
|
|
|
164
131
|
/**
|
|
165
132
|
* Remove a publicly routable address that this node is no longer reachable on
|
|
166
|
-
*
|
|
167
|
-
* @param internalIp - The internal IP address.
|
|
168
|
-
* @param internalPort - The internal port number.
|
|
169
|
-
* @param externalIp - The external IP address.
|
|
170
|
-
* @param externalPort - The external port number (optional).
|
|
171
|
-
* @param protocol - The transport protocol (`tcp` or `udp`).
|
|
172
133
|
*/
|
|
173
134
|
removePublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void
|
|
174
135
|
}
|
|
@@ -3,9 +3,6 @@ import type { PeerMap } from '@libp2p/peer-collections'
|
|
|
3
3
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
4
|
import type { ProgressOptions } from 'progress-events'
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Options for opening a connection to a remote peer.
|
|
8
|
-
*/
|
|
9
6
|
export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> {
|
|
10
7
|
/**
|
|
11
8
|
* Connection requests with a higher priority will be executed before those
|
|
@@ -37,50 +34,49 @@ export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<Ope
|
|
|
37
34
|
initiator?: boolean
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
/**
|
|
41
|
-
* The `ConnectionManager` handles managing connections between peers in a libp2p network.
|
|
42
|
-
* It provides methods for opening, closing, and querying connections.This also provides methods
|
|
43
|
-
* for accessing the dial queue.
|
|
44
|
-
*/
|
|
45
37
|
export interface ConnectionManager {
|
|
46
38
|
/**
|
|
47
39
|
* Return connections, optionally filtering by a PeerId
|
|
48
40
|
*
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
41
|
+
* @example
|
|
42
|
+
*
|
|
43
|
+
* ```TypeScript
|
|
44
|
+
* const connections = libp2p.connectionManager.get(peerId)
|
|
45
|
+
* // []
|
|
46
|
+
* ```
|
|
51
47
|
*/
|
|
52
48
|
getConnections(peerId?: PeerId): Connection[]
|
|
53
49
|
|
|
54
50
|
/**
|
|
55
51
|
* Return a map of all connections with their associated PeerIds
|
|
56
52
|
*
|
|
57
|
-
* @
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* ```TypeScript
|
|
56
|
+
* const connectionsMap = libp2p.connectionManager.getConnectionsMap()
|
|
57
|
+
* ```
|
|
58
58
|
*/
|
|
59
59
|
getConnectionsMap(): PeerMap<Connection[]>
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Returns the configured maximum number of connections this connection
|
|
63
63
|
* manager will accept
|
|
64
|
-
*
|
|
65
|
-
* @returns The maximum connection limit.
|
|
66
64
|
*/
|
|
67
65
|
getMaxConnections(): number
|
|
68
66
|
|
|
69
67
|
/**
|
|
70
68
|
* Open a connection to a remote peer
|
|
71
69
|
*
|
|
72
|
-
* @
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
* @example
|
|
71
|
+
*
|
|
72
|
+
* ```TypeScript
|
|
73
|
+
* const connection = await libp2p.connectionManager.openConnection(peerId)
|
|
74
|
+
* ```
|
|
75
75
|
*/
|
|
76
76
|
openConnection(peer: PeerId | Multiaddr | Multiaddr[], options?: OpenConnectionOptions): Promise<Connection>
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* Close our connections to a peer
|
|
80
|
-
*
|
|
81
|
-
* @param peer - The `PeerId` whose connections should be closed.
|
|
82
|
-
* @param options - Optional abort options.
|
|
83
|
-
* @returns A promise that resolves once the connections are closed.
|
|
84
80
|
*/
|
|
85
81
|
closeConnections(peer: PeerId, options?: AbortOptions): Promise<void>
|
|
86
82
|
|
|
@@ -89,9 +85,6 @@ export interface ConnectionManager {
|
|
|
89
85
|
* exchanged, this lets the ConnectionManager check we have sufficient
|
|
90
86
|
* resources to accept the connection in which case it will return true,
|
|
91
87
|
* otherwise it will return false.
|
|
92
|
-
*
|
|
93
|
-
* @param maConn - The multiaddr connection to evaluate.
|
|
94
|
-
* @returns A promise that resolves to `true` if the connection can be accepted, `false` otherwise.
|
|
95
88
|
*/
|
|
96
89
|
acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean>
|
|
97
90
|
|
|
@@ -103,7 +96,11 @@ export interface ConnectionManager {
|
|
|
103
96
|
/**
|
|
104
97
|
* Return the list of in-progress or queued dials
|
|
105
98
|
*
|
|
106
|
-
* @
|
|
99
|
+
* @example
|
|
100
|
+
*
|
|
101
|
+
* ```TypeScript
|
|
102
|
+
* const dials = libp2p.connectionManager.getDialQueue()
|
|
103
|
+
* ```
|
|
107
104
|
*/
|
|
108
105
|
getDialQueue(): PendingDial[]
|
|
109
106
|
|
|
@@ -115,10 +112,6 @@ export interface ConnectionManager {
|
|
|
115
112
|
* would not block the dial attempt.
|
|
116
113
|
*
|
|
117
114
|
* This may involve resolving DNS addresses so you should pass an AbortSignal.
|
|
118
|
-
*
|
|
119
|
-
* @param multiaddr - The target multiaddr or an array of multiaddrs.
|
|
120
|
-
* @param options - Optional parameters for dialability check.
|
|
121
|
-
* @returns A promise that resolves to `true` if the multiaddr is dialable, `false` otherwise.
|
|
122
115
|
*/
|
|
123
116
|
isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>
|
|
124
117
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* This module serves as the entry point for `@libp2p/interface-internal`,
|
|
5
|
-
* re-exporting key components such as `AddressManager`, `ConnectionManager`,
|
|
6
|
-
* `RandomWalk`, `Registrar`, and `TransportManager`.
|
|
7
|
-
*
|
|
8
|
-
* These interfaces and classes define the core internal behaviors of libp2p.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
1
|
export * from './address-manager.js'
|
|
12
2
|
export * from './connection-manager.js'
|
|
13
3
|
export * from './random-walk.js'
|
package/src/random-walk.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import type { AbortOptions, PeerInfo } from '@libp2p/interface'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* protocol to run and any registered topologies to be notified of their
|
|
7
|
-
* supported protocols.
|
|
4
|
+
* RandomWalk finds random peers on the network and dials them. Use this after
|
|
5
|
+
* registering a Topology if you need to discover common network services.
|
|
8
6
|
*/
|
|
9
7
|
export interface RandomWalk {
|
|
10
8
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* This method either begins a new random walk or joins an existing one. The process
|
|
14
|
-
* continues to find and return random peers until it is aborted.
|
|
15
|
-
*
|
|
16
|
-
* @param options - Optional `AbortOptions` to allow early termination of the walk.
|
|
17
|
-
* @returns An `AsyncGenerator` that yields discovered `PeerInfo` objects.
|
|
9
|
+
* Begin or join an existing walk. Abort the passed signal if you wish to
|
|
10
|
+
* abort the walk early.
|
|
18
11
|
*/
|
|
19
12
|
walk(options?: AbortOptions): AsyncGenerator<PeerInfo>
|
|
20
13
|
}
|
package/src/registrar.ts
CHANGED
|
@@ -22,49 +22,24 @@ export type {
|
|
|
22
22
|
StreamHandlerRecord
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* The `Registrar` provides an interface for registering protocol handlers -
|
|
27
|
-
* these are invoked when remote peers open streams on the local node with the
|
|
28
|
-
* corresponding protocol name.
|
|
29
|
-
*
|
|
30
|
-
* It also allows configuring network topologies for a given protocol(s). The
|
|
31
|
-
* topology callbacks are invoked when a peer that supports those protocols
|
|
32
|
-
* connects or disconnects.
|
|
33
|
-
*
|
|
34
|
-
* The Identify protocol must be configured on the current node for topologies
|
|
35
|
-
* to function.
|
|
36
|
-
*/
|
|
37
25
|
export interface Registrar {
|
|
38
26
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @returns An array of protocol strings.
|
|
27
|
+
* Return the list of protocols with registered handlers
|
|
42
28
|
*/
|
|
43
29
|
getProtocols(): string[]
|
|
44
30
|
|
|
45
31
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @param protocol - The protocol string (e.g., `/my-protocol/1.0.0`).
|
|
49
|
-
* @param handler - The function that handles incoming streams.
|
|
50
|
-
* @param options - Optional configuration options for the handler.
|
|
51
|
-
* @returns A promise that resolves once the handler is registered.
|
|
32
|
+
* Add a protocol handler
|
|
52
33
|
*/
|
|
53
34
|
handle(protocol: string, handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>
|
|
54
35
|
|
|
55
36
|
/**
|
|
56
|
-
* Remove a
|
|
57
|
-
*
|
|
58
|
-
* @param protocol - The protocol to unhandle.
|
|
59
|
-
* @returns A promise that resolves once the handler is removed.
|
|
37
|
+
* Remove a protocol handler
|
|
60
38
|
*/
|
|
61
39
|
unhandle(protocol: string): Promise<void>
|
|
62
40
|
|
|
63
41
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @param protocol - The protocol to query.
|
|
67
|
-
* @returns A `StreamHandlerRecord` containing the handler and options.
|
|
42
|
+
* Return the handler for the passed protocol
|
|
68
43
|
*/
|
|
69
44
|
getHandler(protocol: string): StreamHandlerRecord
|
|
70
45
|
|
|
@@ -75,26 +50,17 @@ export interface Registrar {
|
|
|
75
50
|
*
|
|
76
51
|
* An id will be returned that can later be used to unregister the
|
|
77
52
|
* topology.
|
|
78
|
-
*
|
|
79
|
-
* @param protocol - The protocol to register.
|
|
80
|
-
* @param topology - The topology handler to register.
|
|
81
|
-
* @returns A promise resolving to a unique ID for the registered topology.
|
|
82
53
|
*/
|
|
83
54
|
register(protocol: string, topology: Topology): Promise<string>
|
|
84
55
|
|
|
85
56
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @param id - The ID of the topology to unregister.
|
|
57
|
+
* Remove the topology handler with the passed id.
|
|
89
58
|
*/
|
|
90
59
|
unregister(id: string): void
|
|
91
60
|
|
|
92
61
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* @param protocol - The protocol to query.
|
|
97
|
-
* @returns An array of registered `Topology` handlers.
|
|
62
|
+
* Return all topology handlers that wish to be informed about peers
|
|
63
|
+
* that support the passed protocol.
|
|
98
64
|
*/
|
|
99
65
|
getTopologies(protocol: string): Topology[]
|
|
100
66
|
}
|
package/src/transport-manager.ts
CHANGED
|
@@ -2,27 +2,13 @@ import type { AbortOptions, Connection, Listener, Transport, TransportManagerDia
|
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import type { ProgressOptions } from 'progress-events'
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Options for dialing a connection using the `TransportManager`.
|
|
7
|
-
*/
|
|
8
5
|
export interface TransportManagerDialOptions extends AbortOptions, ProgressOptions<TransportManagerDialProgressEvents> {
|
|
9
6
|
|
|
10
7
|
}
|
|
11
8
|
|
|
12
|
-
/**
|
|
13
|
-
* The `TransportManager` handles the management of network transports, allowing
|
|
14
|
-
* opening connections or listening using specific transports, etc.
|
|
15
|
-
*
|
|
16
|
-
* This is a low-level component - any connections opened will not be managed by
|
|
17
|
-
* the `ConnectionManager` or included in any configured connection limits, etc.
|
|
18
|
-
*
|
|
19
|
-
* Most consumers will call `openConnection` on the `ConnectionManager` instead.
|
|
20
|
-
*/
|
|
21
9
|
export interface TransportManager {
|
|
22
10
|
/**
|
|
23
|
-
* Add a transport to the transport manager
|
|
24
|
-
*
|
|
25
|
-
* @param transport - The transport instance to be added.
|
|
11
|
+
* Add a transport to the transport manager
|
|
26
12
|
*/
|
|
27
13
|
add(transport: Transport): void
|
|
28
14
|
|
|
@@ -31,71 +17,47 @@ export interface TransportManager {
|
|
|
31
17
|
* by the connection manager so can cause memory leaks. If you need to dial
|
|
32
18
|
* a multiaddr, you may want to call openConnection on the connection manager
|
|
33
19
|
* instead.
|
|
34
|
-
*
|
|
35
|
-
* @param ma - The multiaddr to dial.
|
|
36
|
-
* @param options - Optional dial options.
|
|
37
|
-
* @returns A promise that resolves to a `Connection` object.
|
|
38
20
|
*/
|
|
39
21
|
dial(ma: Multiaddr, options?: TransportManagerDialOptions): Promise<Connection>
|
|
40
22
|
|
|
41
23
|
/**
|
|
42
24
|
* Return all addresses currently being listened on
|
|
43
|
-
*
|
|
44
|
-
* @returns An array of `Multiaddr` objects.
|
|
45
25
|
*/
|
|
46
26
|
getAddrs(): Multiaddr[]
|
|
47
27
|
|
|
48
28
|
/**
|
|
49
29
|
* Return all registered transports
|
|
50
|
-
*
|
|
51
|
-
* @returns An array of `Transport` instances.
|
|
52
30
|
*/
|
|
53
31
|
getTransports(): Transport[]
|
|
54
32
|
|
|
55
33
|
/**
|
|
56
34
|
* Return all listeners
|
|
57
|
-
*
|
|
58
|
-
* @returns An array of `Listener` instances.
|
|
59
35
|
*/
|
|
60
36
|
getListeners(): Listener[]
|
|
61
37
|
|
|
62
38
|
/**
|
|
63
39
|
* Get the transport to dial a given multiaddr, if one has been configured
|
|
64
|
-
*
|
|
65
|
-
* @param ma - The target multiaddr.
|
|
66
|
-
* @returns A `Transport` instance if available, otherwise `undefined`.
|
|
67
40
|
*/
|
|
68
41
|
dialTransportForMultiaddr(ma: Multiaddr): Transport | undefined
|
|
69
42
|
|
|
70
43
|
/**
|
|
71
44
|
* Get the transport to listen on a given multiaddr, if one has been
|
|
72
45
|
* configured
|
|
73
|
-
*
|
|
74
|
-
* @param ma - The target multiaddr.
|
|
75
|
-
* @returns A `Transport` instance if available, otherwise `undefined`.
|
|
76
46
|
*/
|
|
77
47
|
listenTransportForMultiaddr(ma: Multiaddr): Transport | undefined
|
|
78
48
|
|
|
79
49
|
/**
|
|
80
50
|
* Listen on the passed multiaddrs
|
|
81
|
-
*
|
|
82
|
-
* @param addrs - An array of multiaddrs to listen on.
|
|
83
|
-
* @returns A promise that resolves once the transport is actively listening.
|
|
84
51
|
*/
|
|
85
52
|
listen(addrs: Multiaddr[]): Promise<void>
|
|
86
53
|
|
|
87
54
|
/**
|
|
88
55
|
* Remove a previously configured transport
|
|
89
|
-
*
|
|
90
|
-
* @param key - The transport key or identifier.
|
|
91
|
-
* @returns A promise that resolves once the transport is removed.
|
|
92
56
|
*/
|
|
93
57
|
remove(key: string): Promise<void>
|
|
94
58
|
|
|
95
59
|
/**
|
|
96
60
|
* Remove all transports
|
|
97
|
-
*
|
|
98
|
-
* @returns A promise that resolves once all transports are removed.
|
|
99
61
|
*/
|
|
100
62
|
removeAll(): Promise<void>
|
|
101
63
|
}
|