@libp2p/interface-internal 2.3.0-4ab04faf0 → 2.3.0-68ad3663e

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.
@@ -48,42 +48,64 @@ 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
+ */
51
56
  export interface AddressManager {
52
57
  /**
53
58
  * Get peer listen multiaddrs
59
+ *
60
+ * @returns An array of `Multiaddr` objects representing listen addresses.
54
61
  */
55
62
  getListenAddrs(): Multiaddr[];
56
63
  /**
57
64
  * Get peer announcing multiaddrs
65
+ *
66
+ * @returns An array of `Multiaddr` objects representing announce addresses.
58
67
  */
59
68
  getAnnounceAddrs(): Multiaddr[];
60
69
  /**
61
70
  * Get observed multiaddrs - these addresses may not have been confirmed as
62
71
  * publicly dialable yet
72
+ *
73
+ * @returns An array of `Multiaddr` objects representing observed addresses.
63
74
  */
64
75
  getObservedAddrs(): Multiaddr[];
65
76
  /**
66
77
  * Signal that we have confidence an observed multiaddr is publicly dialable -
67
78
  * this will make it appear in the output of getAddresses()
79
+ *
80
+ * @param addr - The observed address.
81
+ * @param options - Additional options for confirmation.
68
82
  */
69
83
  confirmObservedAddr(addr: Multiaddr, options?: ConfirmAddressOptions): void;
70
84
  /**
71
85
  * Signal that we do not have confidence an observed multiaddr is publicly dialable -
72
86
  * this will remove it from the output of getObservedAddrs()
87
+ *
88
+ * @param addr - The observed address to remove.
73
89
  */
74
90
  removeObservedAddr(addr: Multiaddr): void;
75
91
  /**
76
92
  * Add peer observed addresses. These will then appear in the output of getObservedAddrs
77
93
  * but not getAddresses() until their dialability has been confirmed via a call to
78
94
  * confirmObservedAddr.
95
+ *
96
+ * @param addr - The observed address to add.
79
97
  */
80
98
  addObservedAddr(addr: Multiaddr): void;
81
99
  /**
82
100
  * Get the current node's addresses
101
+ *
102
+ * @returns An array of `Multiaddr` objects representing node addresses.
83
103
  */
84
104
  getAddresses(): Multiaddr[];
85
105
  /**
86
106
  * Return all known addresses with metadata
107
+ *
108
+ * @returns An array of `NodeAddress` objects.
87
109
  */
88
110
  getAddressesWithMetadata(): NodeAddress[];
89
111
  /**
@@ -91,10 +113,15 @@ export interface AddressManager {
91
113
  * `getAddresses` is invoked, where the IP addresses are present in a
92
114
  * multiaddr, an additional multiaddr will be added with `ip4` and `ip6`
93
115
  * tuples replaced with `dns4` and `dns6 ones respectively.
116
+ *
117
+ * @param domain - The domain name to map.
118
+ * @param ipAddresses - The associated IP addresses.
94
119
  */
95
120
  addDNSMapping(domain: string, ipAddresses: string[]): void;
96
121
  /**
97
122
  * Remove a mapping previously added with `addDNSMapping`.
123
+ *
124
+ * @param domain - The domain name mapping to remove.
98
125
  */
99
126
  removeDNSMapping(domain: string): void;
100
127
  /**
@@ -106,10 +133,22 @@ export interface AddressManager {
106
133
  * It's possible to add a IPv6 address here and have it added to the address
107
134
  * list, this is for the case when a router has an external IPv6 address with
108
135
  * 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`).
109
142
  */
110
143
  addPublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void;
111
144
  /**
112
145
  * 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`).
113
152
  */
114
153
  removePublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void;
115
154
  }
@@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AA;IAE7B;;;;OAIG;IACH,gBAAgB,IAAI,SAAS,EAAE,CAAA;IAE/B;;;;;OAKG;IACH,gBAAgB,IAAI,SAAS,EAAE,CAAA;IAE/B;;;;;;OAMG;IACH,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAA;IAE3E;;;;;OAKG;IACH,kBAAkB,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IAEzC;;;;;;OAMG;IACH,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IAEtC;;;;OAIG;IACH,YAAY,IAAI,SAAS,EAAE,CAAA;IAE3B;;;;OAIG;IACH,wBAAwB,IAAI,WAAW,EAAE,CAAA;IAEzC;;;;;;;;OAQG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAE1D;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAEtC;;;;;;;;;;;;;;;OAeG;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;;;;;;;;OAQG;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,6 +2,9 @@ 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
+ */
5
8
  export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> {
6
9
  /**
7
10
  * Connection requests with a higher priority will be executed before those
@@ -30,45 +33,46 @@ export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<Ope
30
33
  */
31
34
  initiator?: boolean;
32
35
  }
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
+ */
33
41
  export interface ConnectionManager {
34
42
  /**
35
43
  * Return connections, optionally filtering by a PeerId
36
44
  *
37
- * @example
38
- *
39
- * ```TypeScript
40
- * const connections = libp2p.connectionManager.get(peerId)
41
- * // []
42
- * ```
45
+ * @param peerId - The PeerId to filter connections (optional).
46
+ * @returns An array of active `Connection` objects.
43
47
  */
44
48
  getConnections(peerId?: PeerId): Connection[];
45
49
  /**
46
50
  * Return a map of all connections with their associated PeerIds
47
51
  *
48
- * @example
49
- *
50
- * ```TypeScript
51
- * const connectionsMap = libp2p.connectionManager.getConnectionsMap()
52
- * ```
52
+ * @returns A `PeerMap` containing `Connection[]` objects.
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.
58
60
  */
59
61
  getMaxConnections(): number;
60
62
  /**
61
63
  * Open a connection to a remote peer
62
64
  *
63
- * @example
64
- *
65
- * ```TypeScript
66
- * const connection = await libp2p.connectionManager.openConnection(peerId)
67
- * ```
65
+ * @param peer - The target `PeerId`, `Multiaddr`, or an array of `Multiaddr`s.
66
+ * @param options - Optional parameters for connection handling.
67
+ * @returns A promise that resolves to a `Connection` object.
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.
72
76
  */
73
77
  closeConnections(peer: PeerId, options?: AbortOptions): Promise<void>;
74
78
  /**
@@ -76,6 +80,9 @@ export interface ConnectionManager {
76
80
  * exchanged, this lets the ConnectionManager check we have sufficient
77
81
  * resources to accept the connection in which case it will return true,
78
82
  * 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.
79
86
  */
80
87
  acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean>;
81
88
  /**
@@ -85,11 +92,7 @@ export interface ConnectionManager {
85
92
  /**
86
93
  * Return the list of in-progress or queued dials
87
94
  *
88
- * @example
89
- *
90
- * ```TypeScript
91
- * const dials = libp2p.connectionManager.getDialQueue()
92
- * ```
95
+ * @returns An array of `PendingDial` objects.
93
96
  */
94
97
  getDialQueue(): PendingDial[];
95
98
  /**
@@ -100,6 +103,10 @@ export interface ConnectionManager {
100
103
  * would not block the dial attempt.
101
104
  *
102
105
  * 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.
103
110
  */
104
111
  isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>;
105
112
  }
@@ -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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B,IAAI,IAAI,CAAA;IAE3B;;;;OAIG;IACH,YAAY,IAAI,WAAW,EAAE,CAAA;IAE7B;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC9F"}
@@ -1,3 +1,12 @@
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
+ */
1
10
  export * from './address-manager.js';
2
11
  export * from './connection-manager.js';
3
12
  export * from './random-walk.js';
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,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,3 +1,12 @@
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
+ */
1
10
  export * from './address-manager.js';
2
11
  export * from './connection-manager.js';
3
12
  export * from './random-walk.js';
@@ -1 +1 @@
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
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA"}
@@ -1,12 +1,19 @@
1
1
  import type { AbortOptions, PeerInfo } from '@libp2p/interface';
2
2
  /**
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.
3
+ * The `RandomWalk` component uses the libp2p peer routing to find arbitrary
4
+ * network peers. Consumers may then dial these peers, causing the Identify
5
+ * protocol to run and any registered topologies to be notified of their
6
+ * supported protocols.
5
7
  */
6
8
  export interface RandomWalk {
7
9
  /**
8
- * Begin or join an existing walk. Abort the passed signal if you wish to
9
- * abort the walk early.
10
+ * Initiates a random walk for peer discovery.
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.
10
17
  */
11
18
  walk(options?: AbortOptions): AsyncGenerator<PeerInfo>;
12
19
  }
@@ -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;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;CACvD"}
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;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;;OAQG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;CACvD"}
@@ -16,21 +16,46 @@ 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
+ */
19
31
  export interface Registrar {
20
32
  /**
21
- * Return the list of protocols with registered handlers
33
+ * Retrieve the list of registered protocol handlers.
34
+ *
35
+ * @returns An array of protocol strings.
22
36
  */
23
37
  getProtocols(): string[];
24
38
  /**
25
- * Add a protocol handler
39
+ * Register a handler for a specific protocol.
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.
26
45
  */
27
46
  handle(protocol: string, handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>;
28
47
  /**
29
- * Remove a protocol handler
48
+ * Remove a registered protocol handler.
49
+ *
50
+ * @param protocol - The protocol to unhandle.
51
+ * @returns A promise that resolves once the handler is removed.
30
52
  */
31
53
  unhandle(protocol: string): Promise<void>;
32
54
  /**
33
- * Return the handler for the passed protocol
55
+ * Retrieve the registered handler for a given protocol.
56
+ *
57
+ * @param protocol - The protocol to query.
58
+ * @returns A `StreamHandlerRecord` containing the handler and options.
34
59
  */
35
60
  getHandler(protocol: string): StreamHandlerRecord;
36
61
  /**
@@ -40,15 +65,24 @@ export interface Registrar {
40
65
  *
41
66
  * An id will be returned that can later be used to unregister the
42
67
  * 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.
43
72
  */
44
73
  register(protocol: string, topology: Topology): Promise<string>;
45
74
  /**
46
- * Remove the topology handler with the passed id.
75
+ * Unregister a topology handler using its unique ID.
76
+ *
77
+ * @param id - The ID of the topology to unregister.
47
78
  */
48
79
  unregister(id: string): void;
49
80
  /**
50
- * Return all topology handlers that wish to be informed about peers
51
- * that support the passed protocol.
81
+ * Retrieve all topology handlers that are interested in peers
82
+ * supporting a given protocol.
83
+ *
84
+ * @param protocol - The protocol to query.
85
+ * @returns An array of registered `Topology` handlers.
52
86
  */
53
87
  getTopologies(protocol: string): Topology[];
54
88
  }
@@ -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,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,CAA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,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE/D;;;;OAIG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAE5B;;;;;;OAMG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAA;CAC5C"}
@@ -1,11 +1,25 @@
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
+ */
4
7
  export interface TransportManagerDialOptions extends AbortOptions, ProgressOptions<TransportManagerDialProgressEvents> {
5
8
  }
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
+ */
6
18
  export interface TransportManager {
7
19
  /**
8
- * Add a transport to the transport manager
20
+ * Add a transport to the transport manager.
21
+ *
22
+ * @param transport - The transport instance to be added.
9
23
  */
10
24
  add(transport: Transport): void;
11
25
  /**
@@ -13,39 +27,63 @@ export interface TransportManager {
13
27
  * by the connection manager so can cause memory leaks. If you need to dial
14
28
  * a multiaddr, you may want to call openConnection on the connection manager
15
29
  * 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.
16
34
  */
17
35
  dial(ma: Multiaddr, options?: TransportManagerDialOptions): Promise<Connection>;
18
36
  /**
19
37
  * Return all addresses currently being listened on
38
+ *
39
+ * @returns An array of `Multiaddr` objects.
20
40
  */
21
41
  getAddrs(): Multiaddr[];
22
42
  /**
23
43
  * Return all registered transports
44
+ *
45
+ * @returns An array of `Transport` instances.
24
46
  */
25
47
  getTransports(): Transport[];
26
48
  /**
27
49
  * Return all listeners
50
+ *
51
+ * @returns An array of `Listener` instances.
28
52
  */
29
53
  getListeners(): Listener[];
30
54
  /**
31
55
  * 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`.
32
59
  */
33
60
  dialTransportForMultiaddr(ma: Multiaddr): Transport | undefined;
34
61
  /**
35
62
  * Get the transport to listen on a given multiaddr, if one has been
36
63
  * configured
64
+ *
65
+ * @param ma - The target multiaddr.
66
+ * @returns A `Transport` instance if available, otherwise `undefined`.
37
67
  */
38
68
  listenTransportForMultiaddr(ma: Multiaddr): Transport | undefined;
39
69
  /**
40
70
  * 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.
41
74
  */
42
75
  listen(addrs: Multiaddr[]): Promise<void>;
43
76
  /**
44
77
  * 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.
45
81
  */
46
82
  remove(key: string): Promise<void>;
47
83
  /**
48
84
  * Remove all transports
85
+ *
86
+ * @returns A promise that resolves once all transports are removed.
49
87
  */
50
88
  removeAll(): Promise<void>;
51
89
  }
@@ -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,MAAM,WAAW,2BAA4B,SAAQ,YAAY,EAAE,eAAe,CAAC,kCAAkC,CAAC;CAErH;AAED,MAAM,WAAW,gB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AAE,SAAS,GAAG,IAAI,CAAA;IAE/B;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE/E;;;;OAIG;IACH,QAAQ,IAAI,SAAS,EAAE,CAAA;IAEvB;;;;OAIG;IACH,aAAa,IAAI,SAAS,EAAE,CAAA;IAE5B;;;;OAIG;IACH,YAAY,IAAI,QAAQ,EAAE,CAAA;IAE1B;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IAE/D;;;;;;OAMG;IACH,2BAA2B,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IAEjE;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzC;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAElC;;;;OAIG;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-4ab04faf0",
3
+ "version": "2.3.0-68ad3663e",
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-4ab04faf0",
52
- "@libp2p/peer-collections": "6.0.17-4ab04faf0",
51
+ "@libp2p/interface": "2.5.0-68ad3663e",
52
+ "@libp2p/peer-collections": "6.0.17-68ad3663e",
53
53
  "@multiformats/multiaddr": "^12.3.3",
54
54
  "progress-events": "^1.0.1"
55
55
  },
@@ -57,32 +57,48 @@ 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
+ */
60
65
  export interface AddressManager {
61
66
  /**
62
67
  * Get peer listen multiaddrs
68
+ *
69
+ * @returns An array of `Multiaddr` objects representing listen addresses.
63
70
  */
64
71
  getListenAddrs(): Multiaddr[]
65
72
 
66
73
  /**
67
74
  * Get peer announcing multiaddrs
75
+ *
76
+ * @returns An array of `Multiaddr` objects representing announce addresses.
68
77
  */
69
78
  getAnnounceAddrs(): Multiaddr[]
70
79
 
71
80
  /**
72
81
  * Get observed multiaddrs - these addresses may not have been confirmed as
73
82
  * publicly dialable yet
83
+ *
84
+ * @returns An array of `Multiaddr` objects representing observed addresses.
74
85
  */
75
86
  getObservedAddrs(): Multiaddr[]
76
87
 
77
88
  /**
78
89
  * Signal that we have confidence an observed multiaddr is publicly dialable -
79
90
  * this will make it appear in the output of getAddresses()
91
+ *
92
+ * @param addr - The observed address.
93
+ * @param options - Additional options for confirmation.
80
94
  */
81
95
  confirmObservedAddr(addr: Multiaddr, options?: ConfirmAddressOptions): void
82
96
 
83
97
  /**
84
98
  * Signal that we do not have confidence an observed multiaddr is publicly dialable -
85
99
  * this will remove it from the output of getObservedAddrs()
100
+ *
101
+ * @param addr - The observed address to remove.
86
102
  */
87
103
  removeObservedAddr(addr: Multiaddr): void
88
104
 
@@ -90,16 +106,22 @@ export interface AddressManager {
90
106
  * Add peer observed addresses. These will then appear in the output of getObservedAddrs
91
107
  * but not getAddresses() until their dialability has been confirmed via a call to
92
108
  * confirmObservedAddr.
109
+ *
110
+ * @param addr - The observed address to add.
93
111
  */
94
112
  addObservedAddr(addr: Multiaddr): void
95
113
 
96
114
  /**
97
115
  * Get the current node's addresses
116
+ *
117
+ * @returns An array of `Multiaddr` objects representing node addresses.
98
118
  */
99
119
  getAddresses(): Multiaddr[]
100
120
 
101
121
  /**
102
122
  * Return all known addresses with metadata
123
+ *
124
+ * @returns An array of `NodeAddress` objects.
103
125
  */
104
126
  getAddressesWithMetadata(): NodeAddress[]
105
127
 
@@ -108,11 +130,16 @@ export interface AddressManager {
108
130
  * `getAddresses` is invoked, where the IP addresses are present in a
109
131
  * multiaddr, an additional multiaddr will be added with `ip4` and `ip6`
110
132
  * tuples replaced with `dns4` and `dns6 ones respectively.
133
+ *
134
+ * @param domain - The domain name to map.
135
+ * @param ipAddresses - The associated IP addresses.
111
136
  */
112
137
  addDNSMapping(domain: string, ipAddresses: string[]): void
113
138
 
114
139
  /**
115
140
  * Remove a mapping previously added with `addDNSMapping`.
141
+ *
142
+ * @param domain - The domain name mapping to remove.
116
143
  */
117
144
  removeDNSMapping(domain: string): void
118
145
 
@@ -125,11 +152,23 @@ export interface AddressManager {
125
152
  * It's possible to add a IPv6 address here and have it added to the address
126
153
  * list, this is for the case when a router has an external IPv6 address with
127
154
  * 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`).
128
161
  */
129
162
  addPublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void
130
163
 
131
164
  /**
132
165
  * 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`).
133
172
  */
134
173
  removePublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void
135
174
  }
@@ -3,6 +3,9 @@ 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
+ */
6
9
  export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> {
7
10
  /**
8
11
  * Connection requests with a higher priority will be executed before those
@@ -34,49 +37,50 @@ export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<Ope
34
37
  initiator?: boolean
35
38
  }
36
39
 
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
+ */
37
45
  export interface ConnectionManager {
38
46
  /**
39
47
  * Return connections, optionally filtering by a PeerId
40
48
  *
41
- * @example
42
- *
43
- * ```TypeScript
44
- * const connections = libp2p.connectionManager.get(peerId)
45
- * // []
46
- * ```
49
+ * @param peerId - The PeerId to filter connections (optional).
50
+ * @returns An array of active `Connection` objects.
47
51
  */
48
52
  getConnections(peerId?: PeerId): Connection[]
49
53
 
50
54
  /**
51
55
  * Return a map of all connections with their associated PeerIds
52
56
  *
53
- * @example
54
- *
55
- * ```TypeScript
56
- * const connectionsMap = libp2p.connectionManager.getConnectionsMap()
57
- * ```
57
+ * @returns A `PeerMap` containing `Connection[]` objects.
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.
64
66
  */
65
67
  getMaxConnections(): number
66
68
 
67
69
  /**
68
70
  * Open a connection to a remote peer
69
71
  *
70
- * @example
71
- *
72
- * ```TypeScript
73
- * const connection = await libp2p.connectionManager.openConnection(peerId)
74
- * ```
72
+ * @param peer - The target `PeerId`, `Multiaddr`, or an array of `Multiaddr`s.
73
+ * @param options - Optional parameters for connection handling.
74
+ * @returns A promise that resolves to a `Connection` object.
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.
80
84
  */
81
85
  closeConnections(peer: PeerId, options?: AbortOptions): Promise<void>
82
86
 
@@ -85,6 +89,9 @@ export interface ConnectionManager {
85
89
  * exchanged, this lets the ConnectionManager check we have sufficient
86
90
  * resources to accept the connection in which case it will return true,
87
91
  * 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.
88
95
  */
89
96
  acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean>
90
97
 
@@ -96,11 +103,7 @@ export interface ConnectionManager {
96
103
  /**
97
104
  * Return the list of in-progress or queued dials
98
105
  *
99
- * @example
100
- *
101
- * ```TypeScript
102
- * const dials = libp2p.connectionManager.getDialQueue()
103
- * ```
106
+ * @returns An array of `PendingDial` objects.
104
107
  */
105
108
  getDialQueue(): PendingDial[]
106
109
 
@@ -112,6 +115,10 @@ export interface ConnectionManager {
112
115
  * would not block the dial attempt.
113
116
  *
114
117
  * 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.
115
122
  */
116
123
  isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>
117
124
  }
package/src/index.ts CHANGED
@@ -1,3 +1,13 @@
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
11
  export * from './address-manager.js'
2
12
  export * from './connection-manager.js'
3
13
  export * from './random-walk.js'
@@ -1,13 +1,20 @@
1
1
  import type { AbortOptions, PeerInfo } from '@libp2p/interface'
2
2
 
3
3
  /**
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.
4
+ * The `RandomWalk` component uses the libp2p peer routing to find arbitrary
5
+ * network peers. Consumers may then dial these peers, causing the Identify
6
+ * protocol to run and any registered topologies to be notified of their
7
+ * supported protocols.
6
8
  */
7
9
  export interface RandomWalk {
8
10
  /**
9
- * Begin or join an existing walk. Abort the passed signal if you wish to
10
- * abort the walk early.
11
+ * Initiates a random walk for peer discovery.
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.
11
18
  */
12
19
  walk(options?: AbortOptions): AsyncGenerator<PeerInfo>
13
20
  }
package/src/registrar.ts CHANGED
@@ -22,24 +22,49 @@ 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
+ */
25
37
  export interface Registrar {
26
38
  /**
27
- * Return the list of protocols with registered handlers
39
+ * Retrieve the list of registered protocol handlers.
40
+ *
41
+ * @returns An array of protocol strings.
28
42
  */
29
43
  getProtocols(): string[]
30
44
 
31
45
  /**
32
- * Add a protocol handler
46
+ * Register a handler for a specific protocol.
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.
33
52
  */
34
53
  handle(protocol: string, handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>
35
54
 
36
55
  /**
37
- * Remove a protocol handler
56
+ * Remove a registered protocol handler.
57
+ *
58
+ * @param protocol - The protocol to unhandle.
59
+ * @returns A promise that resolves once the handler is removed.
38
60
  */
39
61
  unhandle(protocol: string): Promise<void>
40
62
 
41
63
  /**
42
- * Return the handler for the passed protocol
64
+ * Retrieve the registered handler for a given protocol.
65
+ *
66
+ * @param protocol - The protocol to query.
67
+ * @returns A `StreamHandlerRecord` containing the handler and options.
43
68
  */
44
69
  getHandler(protocol: string): StreamHandlerRecord
45
70
 
@@ -50,17 +75,26 @@ export interface Registrar {
50
75
  *
51
76
  * An id will be returned that can later be used to unregister the
52
77
  * 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.
53
82
  */
54
83
  register(protocol: string, topology: Topology): Promise<string>
55
84
 
56
85
  /**
57
- * Remove the topology handler with the passed id.
86
+ * Unregister a topology handler using its unique ID.
87
+ *
88
+ * @param id - The ID of the topology to unregister.
58
89
  */
59
90
  unregister(id: string): void
60
91
 
61
92
  /**
62
- * Return all topology handlers that wish to be informed about peers
63
- * that support the passed protocol.
93
+ * Retrieve all topology handlers that are interested in peers
94
+ * supporting a given protocol.
95
+ *
96
+ * @param protocol - The protocol to query.
97
+ * @returns An array of registered `Topology` handlers.
64
98
  */
65
99
  getTopologies(protocol: string): Topology[]
66
100
  }
@@ -2,13 +2,27 @@ 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
+ */
5
8
  export interface TransportManagerDialOptions extends AbortOptions, ProgressOptions<TransportManagerDialProgressEvents> {
6
9
 
7
10
  }
8
11
 
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
+ */
9
21
  export interface TransportManager {
10
22
  /**
11
- * Add a transport to the transport manager
23
+ * Add a transport to the transport manager.
24
+ *
25
+ * @param transport - The transport instance to be added.
12
26
  */
13
27
  add(transport: Transport): void
14
28
 
@@ -17,47 +31,71 @@ export interface TransportManager {
17
31
  * by the connection manager so can cause memory leaks. If you need to dial
18
32
  * a multiaddr, you may want to call openConnection on the connection manager
19
33
  * 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.
20
38
  */
21
39
  dial(ma: Multiaddr, options?: TransportManagerDialOptions): Promise<Connection>
22
40
 
23
41
  /**
24
42
  * Return all addresses currently being listened on
43
+ *
44
+ * @returns An array of `Multiaddr` objects.
25
45
  */
26
46
  getAddrs(): Multiaddr[]
27
47
 
28
48
  /**
29
49
  * Return all registered transports
50
+ *
51
+ * @returns An array of `Transport` instances.
30
52
  */
31
53
  getTransports(): Transport[]
32
54
 
33
55
  /**
34
56
  * Return all listeners
57
+ *
58
+ * @returns An array of `Listener` instances.
35
59
  */
36
60
  getListeners(): Listener[]
37
61
 
38
62
  /**
39
63
  * 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`.
40
67
  */
41
68
  dialTransportForMultiaddr(ma: Multiaddr): Transport | undefined
42
69
 
43
70
  /**
44
71
  * Get the transport to listen on a given multiaddr, if one has been
45
72
  * configured
73
+ *
74
+ * @param ma - The target multiaddr.
75
+ * @returns A `Transport` instance if available, otherwise `undefined`.
46
76
  */
47
77
  listenTransportForMultiaddr(ma: Multiaddr): Transport | undefined
48
78
 
49
79
  /**
50
80
  * 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.
51
84
  */
52
85
  listen(addrs: Multiaddr[]): Promise<void>
53
86
 
54
87
  /**
55
88
  * 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.
56
92
  */
57
93
  remove(key: string): Promise<void>
58
94
 
59
95
  /**
60
96
  * Remove all transports
97
+ *
98
+ * @returns A promise that resolves once all transports are removed.
61
99
  */
62
100
  removeAll(): Promise<void>
63
101
  }