15
15
*/
16
16
17
17
import type { AbortOptions } from '@libp2p/interfaces'
18
- import type { EventEmitter } from '@libp2p/interfaces/events'
19
18
import type { Startable } from '@libp2p/interfaces/startable'
20
19
import type { Multiaddr } from '@multiformats/multiaddr'
21
20
import type { DualDHT } from '@libp2p/interface-dht'
22
21
import type { PeerStore } from '@libp2p/interface-peer-store'
23
22
import type { PeerId } from '@libp2p/interface-peer-id'
24
- import type { Connection , Stream } from '@libp2p/interface-connection'
23
+ import type { Stream } from '@libp2p/interface-connection'
25
24
import type { PeerRouting } from '@libp2p/interface-peer-routing'
26
25
import type { ContentRouting } from '@libp2p/interface-content-routing'
27
26
import type { PubSub } from '@libp2p/interface-pubsub'
28
- import type { StreamHandler , StreamHandlerOptions , Topology } from '@libp2p/interface-registrar'
27
+ import type { Registrar , StreamHandler , StreamHandlerOptions , Topology } from '@libp2p/interface-registrar'
29
28
import type { Metrics } from '@libp2p/interface-metrics'
30
- import type { PeerInfo } from '@libp2p/interface-peer-info'
31
29
import type { KeyChain } from '@libp2p/interface-keychain'
30
+ import type { ConnectionManager , ConnectionManagerEvents , Dialer } from '@libp2p/interface-connection-manager'
31
+ import type { PeerInfo } from '@libp2p/interface-peer-info/src'
32
+ import type { EventEmitter } from '@libp2p/interfaces/src/events'
33
+
32
34
33
35
/**
34
- * Once you have a libp2p instance, you can listen to several events it emits, so that you can be notified of relevant network events.
36
+ * Fetch service lookup function
35
37
*/
36
- export interface Libp2pEvents {
38
+ export interface LookupFunction {
39
+ ( key : string ) : Promise < Uint8Array | null >
40
+ }
41
+
42
+ /**
43
+ * Libp2p nodes implement this interface.
44
+ */
45
+ export interface Libp2p extends ConnectionManager , Dialer , Registrar , EventEmitter < ConnectionManagerEvents > , Startable {
37
46
/**
38
47
* @example
39
48
*
@@ -46,48 +55,6 @@ export interface Libp2pEvents {
46
55
*/
47
56
'peer:discovery' : CustomEvent < PeerInfo >
48
57
49
- /**
50
- * This event will be triggered anytime a new Connection is established to another peer.
51
- *
52
- * @example
53
- *
54
- * ```js
55
- * libp2p.connectionManager.addEventListener('peer:connect', (event) => {
56
- * const connection = event.detail
57
- * // ...
58
- * })
59
- * ```
60
- */
61
- 'peer:connect' : CustomEvent < Connection >
62
-
63
- /**
64
- * This event will be triggered anytime we are disconnected from another peer, regardless of
65
- * the circumstances of that disconnection. If we happen to have multiple connections to a
66
- * peer, this event will **only** be triggered when the last connection is closed.
67
- *
68
- * @example
69
- *
70
- * ```js
71
- * libp2p.connectionManager.addEventListener('peer:disconnect', (event) => {
72
- * const connection = event.detail
73
- * // ...
74
- * })
75
- * ```
76
- */
77
- 'peer:disconnect' : CustomEvent < Connection >
78
- }
79
-
80
- /**
81
- * Fetch service lookup function
82
- */
83
- export interface LookupFunction {
84
- ( key : string ) : Promise < Uint8Array | null >
85
- }
86
-
87
- /**
88
- * Libp2p nodes implement this interface.
89
- */
90
- export interface Libp2p extends Startable , EventEmitter < Libp2pEvents > {
91
58
/**
92
59
* The PeerId is a unique identifier for a node on the network.
93
60
*
@@ -308,47 +275,11 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> {
308
275
*/
309
276
getProtocols : ( ) => string [ ]
310
277
311
- /**
312
- * Return a list of all connections this node has open, optionally filtering
313
- * by a PeerId
314
- *
315
- * @example
316
- *
317
- * ```js
318
- * for (const connection of libp2p.getConnections()) {
319
- * console.log(peerId, connection.remoteAddr.toString())
320
- * // Logs the PeerId string and the observed remote multiaddr of each Connection
321
- * }
322
- * ```
323
- */
324
- getConnections : ( peerId ?: PeerId ) => Connection [ ]
325
-
326
278
/**
327
279
* Return a list of all peers we currently have a connection open to
328
280
*/
329
281
getPeers : ( ) => PeerId [ ]
330
282
331
- /**
332
- * Dials to the provided peer. If successful, the known metadata of the
333
- * peer will be added to the nodes `peerStore`.
334
- *
335
- * If a PeerId is passed as the first argument, the peer will need to have known multiaddrs for it in the PeerStore.
336
- *
337
- * @example
338
- *
339
- * ```js
340
- * const conn = await libp2p.dial(remotePeerId)
341
- *
342
- * // create a new stream within the connection
343
- * const { stream, protocol } = await conn.newStream(['/echo/1.1.0', '/echo/1.0.0'])
344
- *
345
- * // protocol negotiated: 'echo/1.0.0' means that the other party only supports the older version
346
- *
347
- * // ...
348
- * await conn.close()
349
- * ```
350
- */
351
- dial : ( peer : PeerId | Multiaddr , options ?: AbortOptions ) => Promise < Connection >
352
283
353
284
/**
354
285
* Dials to the provided peer and tries to handshake with the given protocols in order.
0 commit comments