@libp2p/interface-internal 0.0.1-05abd49f

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.
Files changed (39) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +36 -0
  3. package/dist/index.min.js +3 -0
  4. package/dist/src/address-manager/index.d.ts +37 -0
  5. package/dist/src/address-manager/index.d.ts.map +1 -0
  6. package/dist/src/address-manager/index.js +2 -0
  7. package/dist/src/address-manager/index.js.map +1 -0
  8. package/dist/src/connection-manager/index.d.ts +71 -0
  9. package/dist/src/connection-manager/index.d.ts.map +1 -0
  10. package/dist/src/connection-manager/index.js +2 -0
  11. package/dist/src/connection-manager/index.js.map +1 -0
  12. package/dist/src/index.d.ts +548 -0
  13. package/dist/src/index.d.ts.map +1 -0
  14. package/dist/src/index.js +17 -0
  15. package/dist/src/index.js.map +1 -0
  16. package/dist/src/record/index.d.ts +33 -0
  17. package/dist/src/record/index.d.ts.map +1 -0
  18. package/dist/src/record/index.js +2 -0
  19. package/dist/src/record/index.js.map +1 -0
  20. package/dist/src/registrar/index.d.ts +60 -0
  21. package/dist/src/registrar/index.d.ts.map +1 -0
  22. package/dist/src/registrar/index.js +2 -0
  23. package/dist/src/registrar/index.js.map +1 -0
  24. package/dist/src/transport-manager/index.d.ts +15 -0
  25. package/dist/src/transport-manager/index.d.ts.map +1 -0
  26. package/dist/src/transport-manager/index.js +2 -0
  27. package/dist/src/transport-manager/index.js.map +1 -0
  28. package/dist/src/upgrader/index.d.ts +18 -0
  29. package/dist/src/upgrader/index.d.ts.map +1 -0
  30. package/dist/src/upgrader/index.js +2 -0
  31. package/dist/src/upgrader/index.js.map +1 -0
  32. package/package.json +96 -0
  33. package/src/address-manager/index.ts +43 -0
  34. package/src/connection-manager/index.ts +79 -0
  35. package/src/index.ts +598 -0
  36. package/src/record/index.ts +35 -0
  37. package/src/registrar/index.ts +71 -0
  38. package/src/transport-manager/index.ts +15 -0
  39. package/src/upgrader/index.ts +20 -0
package/src/index.ts ADDED
@@ -0,0 +1,598 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Exports a `Libp2p` type for modules to use as a type argument.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import type { Libp2p } from '@libp2p/interface'
10
+ *
11
+ * function doSomethingWithLibp2p (node: Libp2p) {
12
+ * // ...
13
+ * }
14
+ * ```
15
+ */
16
+
17
+ import type { StreamHandler, StreamHandlerOptions } from './registrar/index.js'
18
+ import type { AbortOptions } from '@libp2p/interface'
19
+ import type { Connection, Stream } from '@libp2p/interface/connection'
20
+ import type { ContentRouting } from '@libp2p/interface/content-routing'
21
+ import type { EventEmitter } from '@libp2p/interface/events'
22
+ import type { KeyChain } from '@libp2p/interface/keychain'
23
+ import type { Metrics } from '@libp2p/interface/metrics'
24
+ import type { PeerId } from '@libp2p/interface/peer-id'
25
+ import type { PeerInfo } from '@libp2p/interface/peer-info'
26
+ import type { PeerRouting } from '@libp2p/interface/peer-routing'
27
+ import type { Address, Peer, PeerStore } from '@libp2p/interface/peer-store'
28
+ import type { Startable } from '@libp2p/interface/startable'
29
+ import type { Topology } from '@libp2p/interface/topology'
30
+ import type { Listener } from '@libp2p/interface/transport'
31
+ import type { Multiaddr } from '@multiformats/multiaddr'
32
+
33
+ /**
34
+ * Used by the connection manager to sort addresses into order before dialling
35
+ */
36
+ export interface AddressSorter {
37
+ (a: Address, b: Address): -1 | 0 | 1
38
+ }
39
+
40
+ /**
41
+ * Event detail emitted when peer data changes
42
+ */
43
+ export interface PeerUpdate {
44
+ peer: Peer
45
+ previous?: Peer
46
+ }
47
+
48
+ /**
49
+ * Peer data signed by the remote Peer's public key
50
+ */
51
+ export interface SignedPeerRecord {
52
+ addresses: Multiaddr[]
53
+ seq: bigint
54
+ }
55
+
56
+ /**
57
+ * Data returned from a successful identify response
58
+ */
59
+ export interface IdentifyResult {
60
+ /**
61
+ * The remote Peer's PeerId
62
+ */
63
+ peerId: PeerId
64
+
65
+ /**
66
+ * The unsigned addresses they are listening on. Note - any multiaddrs present
67
+ * in the signed peer record should be preferred to the value here.
68
+ */
69
+ listenAddrs: Multiaddr[]
70
+
71
+ /**
72
+ * The protocols the remote peer supports
73
+ */
74
+ protocols: string[]
75
+
76
+ /**
77
+ * The remote protocol version
78
+ */
79
+ protocolVersion?: string
80
+
81
+ /**
82
+ * The remote agent version
83
+ */
84
+ agentVersion?: string
85
+
86
+ /**
87
+ * The public key part of the remote PeerId - this is only useful for older
88
+ * RSA-based PeerIds, the more modern Ed25519 and secp256k1 types have the
89
+ * public key embedded in them
90
+ */
91
+ publicKey?: Uint8Array
92
+
93
+ /**
94
+ * If set this is the address that the remote peer saw the identify request
95
+ * originate from
96
+ */
97
+ observedAddr?: Multiaddr
98
+
99
+ /**
100
+ * If sent by the remote peer this is the deserialized signed peer record
101
+ */
102
+ signedPeerRecord?: SignedPeerRecord
103
+ }
104
+
105
+ /**
106
+ * Once you have a libp2p instance, you can listen to several events it emits,
107
+ * so that you can be notified of relevant network events.
108
+ *
109
+ * Event names are `noun:verb` so the first part is the name of the object
110
+ * being acted on and the second is the action.
111
+ */
112
+ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
113
+ /**
114
+ * This event is dispatched when a new network peer is discovered.
115
+ *
116
+ * @example
117
+ *
118
+ * ```js
119
+ * libp2p.addEventListener('peer:discovery', (event) => {
120
+ * const peerInfo = event.detail
121
+ * // ...
122
+ * })
123
+ * ```
124
+ */
125
+ 'peer:discovery': CustomEvent<PeerInfo>
126
+
127
+ /**
128
+ * This event will be triggered any time a new peer connects.
129
+ *
130
+ * @example
131
+ *
132
+ * ```js
133
+ * libp2p.addEventListener('peer:connect', (event) => {
134
+ * const peerId = event.detail
135
+ * // ...
136
+ * })
137
+ * ```
138
+ */
139
+ 'peer:connect': CustomEvent<PeerId>
140
+
141
+ /**
142
+ * This event will be triggered any time we are disconnected from another peer, regardless of
143
+ * the circumstances of that disconnection. If we happen to have multiple connections to a
144
+ * peer, this event will **only** be triggered when the last connection is closed.
145
+ *
146
+ * @example
147
+ *
148
+ * ```js
149
+ * libp2p.addEventListener('peer:disconnect', (event) => {
150
+ * const peerId = event.detail
151
+ * // ...
152
+ * })
153
+ * ```
154
+ */
155
+ 'peer:disconnect': CustomEvent<PeerId>
156
+
157
+ /**
158
+ * This event is dispatched after a remote peer has successfully responded to the identify
159
+ * protocol. Note that for this to be emitted, both peers must have an identify service
160
+ * configured.
161
+ *
162
+ * @example
163
+ *
164
+ * ```js
165
+ * libp2p.addEventListener('peer:identify', (event) => {
166
+ * const identifyResult = event.detail
167
+ * // ...
168
+ * })
169
+ * ```
170
+ */
171
+ 'peer:identify': CustomEvent<IdentifyResult>
172
+
173
+ /**
174
+ * This event is dispatched when the peer store data for a peer has been
175
+ * updated - e.g. their multiaddrs, protocols etc have changed.
176
+ *
177
+ * If they were previously known to this node, the old peer data will be
178
+ * set in the `previous` field.
179
+ *
180
+ * This may be in response to the identify protocol running, a manual
181
+ * update or some other event.
182
+ */
183
+ 'peer:update': CustomEvent<PeerUpdate>
184
+
185
+ /**
186
+ * This event is dispatched when the current node's peer record changes -
187
+ * for example a transport started listening on a new address or a new
188
+ * protocol handler was registered.
189
+ *
190
+ * @example
191
+ *
192
+ * ```js
193
+ * libp2p.addEventListener('self:peer:update', (event) => {
194
+ * const { peer } = event.detail
195
+ * // ...
196
+ * })
197
+ * ```
198
+ */
199
+ 'self:peer:update': CustomEvent<PeerUpdate>
200
+
201
+ /**
202
+ * This event is dispatched when a transport begins listening on a new address
203
+ */
204
+ 'transport:listening': CustomEvent<Listener>
205
+
206
+ /**
207
+ * This event is dispatched when a transport stops listening on an address
208
+ */
209
+ 'transport:close': CustomEvent<Listener>
210
+
211
+ /**
212
+ * This event is dispatched when the connection manager has more than the
213
+ * configured allowable max connections and has closed some connections to
214
+ * bring the node back under the limit.
215
+ */
216
+ 'connection:prune': CustomEvent<Connection[]>
217
+
218
+ /**
219
+ * This event notifies listeners when new incoming or outgoing connections
220
+ * are opened.
221
+ */
222
+ 'connection:open': CustomEvent<Connection>
223
+
224
+ /**
225
+ * This event notifies listeners when incoming or outgoing connections are
226
+ * closed.
227
+ */
228
+ 'connection:close': CustomEvent<Connection>
229
+
230
+ /**
231
+ * This event notifies listeners that the node has started
232
+ *
233
+ * ```js
234
+ * libp2p.addEventListener('start', (event) => {
235
+ * console.info(libp2p.isStarted()) // true
236
+ * })
237
+ * ```
238
+ */
239
+ 'start': CustomEvent<Libp2p<T>>
240
+
241
+ /**
242
+ * This event notifies listeners that the node has stopped
243
+ *
244
+ * ```js
245
+ * libp2p.addEventListener('stop', (event) => {
246
+ * console.info(libp2p.isStarted()) // false
247
+ * })
248
+ * ```
249
+ */
250
+ 'stop': CustomEvent<Libp2p<T>>
251
+ }
252
+
253
+ /**
254
+ * A map of user defined services available on the libp2p node via the
255
+ * `services` key
256
+ *
257
+ * @example
258
+ *
259
+ * ```js
260
+ * const node = await createLibp2p({
261
+ * // ...other options
262
+ * services: {
263
+ * myService: myService({
264
+ * // ...service options
265
+ * })
266
+ * }
267
+ * })
268
+ *
269
+ * // invoke methods on the service
270
+ * node.services.myService.anOperation()
271
+ * ```
272
+ */
273
+ export type ServiceMap = Record<string, unknown>
274
+
275
+ export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success'
276
+
277
+ /**
278
+ * An item in the dial queue
279
+ */
280
+ export interface PendingDial {
281
+ /**
282
+ * A unique identifier for this dial
283
+ */
284
+ id: string
285
+
286
+ /**
287
+ * The current status of the dial
288
+ */
289
+ status: PendingDialStatus
290
+
291
+ /**
292
+ * If known, this is the peer id that libp2p expects to be dialling
293
+ */
294
+ peerId?: PeerId
295
+
296
+ /**
297
+ * The list of multiaddrs that will be dialled. The returned connection will
298
+ * use the first address that succeeds, all other dials part of this pending
299
+ * dial will be cancelled.
300
+ */
301
+ multiaddrs: Multiaddr[]
302
+ }
303
+
304
+ /**
305
+ * Libp2p nodes implement this interface.
306
+ */
307
+ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, EventEmitter<Libp2pEvents<T>> {
308
+ /**
309
+ * The PeerId is a unique identifier for a node on the network.
310
+ *
311
+ * It is the hash of an RSA public key or, for Ed25519 or secp256k1 keys,
312
+ * the key itself.
313
+ *
314
+ * @example
315
+ *
316
+ * ```js
317
+ * console.info(libp2p.peerId)
318
+ * // PeerId(12D3Foo...)
319
+ * ````
320
+ */
321
+ peerId: PeerId
322
+
323
+ /**
324
+ * The peer store holds information we know about other peers on the network.
325
+ * - multiaddrs, supported protocols, etc.
326
+ *
327
+ * @example
328
+ *
329
+ * ```js
330
+ * const peer = await libp2p.peerStore.get(peerId)
331
+ * console.info(peer)
332
+ * // { id: PeerId(12D3Foo...), addresses: [] ... }
333
+ * ```
334
+ */
335
+ peerStore: PeerStore
336
+
337
+ /**
338
+ * The peer routing subsystem allows the user to find peers on the network
339
+ * or to find peers close to binary keys.
340
+ *
341
+ * @example
342
+ *
343
+ * ```js
344
+ * const peerInfo = await libp2p.peerRouting.findPeer(peerId)
345
+ * console.info(peerInfo)
346
+ * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
347
+ * ```
348
+ *
349
+ * @example
350
+ *
351
+ * ```js
352
+ * for await (const peerInfo of libp2p.peerRouting.getClosestPeers(key)) {
353
+ * console.info(peerInfo)
354
+ * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
355
+ * }
356
+ * ```
357
+ */
358
+ peerRouting: PeerRouting
359
+
360
+ /**
361
+ * The content routing subsystem allows the user to find providers for content,
362
+ * let the network know they are providers for content, and get/put values to
363
+ * the DHT.
364
+ *
365
+ * @example
366
+ *
367
+ * ```js
368
+ * for await (const peerInfo of libp2p.contentRouting.findProviders(cid)) {
369
+ * console.info(peerInfo)
370
+ * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
371
+ * }
372
+ * ```
373
+ */
374
+ contentRouting: ContentRouting
375
+
376
+ /**
377
+ * The keychain contains the keys used by the current node, and can create new
378
+ * keys, export them, import them, etc.
379
+ *
380
+ * @example
381
+ *
382
+ * ```js
383
+ * const keyInfo = await libp2p.keychain.createKey('new key')
384
+ * console.info(keyInfo)
385
+ * // { id: '...', name: 'new key' }
386
+ * ```
387
+ */
388
+ keychain: KeyChain
389
+
390
+ /**
391
+ * The metrics subsystem allows recording values to assess the health/performance
392
+ * of the running node.
393
+ *
394
+ * @example
395
+ *
396
+ * ```js
397
+ * const metric = libp2p.metrics.registerMetric({
398
+ * 'my-metric'
399
+ * })
400
+ *
401
+ * // later
402
+ * metric.update(5)
403
+ * ```
404
+ */
405
+ metrics?: Metrics
406
+
407
+ /**
408
+ * Get a deduplicated list of peer advertising multiaddrs by concatenating
409
+ * the listen addresses used by transports with any configured
410
+ * announce addresses as well as observed addresses reported by peers.
411
+ *
412
+ * If Announce addrs are specified, configured listen addresses will be
413
+ * ignored though observed addresses will still be included.
414
+ *
415
+ * @example
416
+ *
417
+ * ```js
418
+ * const listenMa = libp2p.getMultiaddrs()
419
+ * // [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
420
+ * ```
421
+ */
422
+ getMultiaddrs: () => Multiaddr[]
423
+
424
+ /**
425
+ * Returns a list of supported protocols
426
+ *
427
+ * @example
428
+ *
429
+ * ```js
430
+ * const protocols = libp2p.getProtocols()
431
+ * // [ '/ipfs/ping/1.0.0', '/ipfs/id/1.0.0' ]
432
+ * ```
433
+ */
434
+ getProtocols: () => string[]
435
+
436
+ /**
437
+ * Return a list of all connections this node has open, optionally filtering
438
+ * by a PeerId
439
+ *
440
+ * @example
441
+ *
442
+ * ```js
443
+ * for (const connection of libp2p.getConnections()) {
444
+ * console.log(peerId, connection.remoteAddr.toString())
445
+ * // Logs the PeerId string and the observed remote multiaddr of each Connection
446
+ * }
447
+ * ```
448
+ */
449
+ getConnections: (peerId?: PeerId) => Connection[]
450
+
451
+ /**
452
+ * Return the list of dials currently in progress or queued to start
453
+ *
454
+ * @example
455
+ *
456
+ * ```js
457
+ * for (const pendingDial of libp2p.getDialQueue()) {
458
+ * console.log(pendingDial)
459
+ * }
460
+ * ```
461
+ */
462
+ getDialQueue: () => PendingDial[]
463
+
464
+ /**
465
+ * Return a list of all peers we currently have a connection open to
466
+ */
467
+ getPeers: () => PeerId[]
468
+
469
+ /**
470
+ * Dials to the provided peer. If successful, the known metadata of the
471
+ * peer will be added to the nodes `peerStore`.
472
+ *
473
+ * If a PeerId is passed as the first argument, the peer will need to have known multiaddrs for it in the PeerStore.
474
+ *
475
+ * @example
476
+ *
477
+ * ```js
478
+ * const conn = await libp2p.dial(remotePeerId)
479
+ *
480
+ * // create a new stream within the connection
481
+ * const { stream, protocol } = await conn.newStream(['/echo/1.1.0', '/echo/1.0.0'])
482
+ *
483
+ * // protocol negotiated: 'echo/1.0.0' means that the other party only supports the older version
484
+ *
485
+ * // ...
486
+ * await conn.close()
487
+ * ```
488
+ */
489
+ dial: (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions) => Promise<Connection>
490
+
491
+ /**
492
+ * Dials to the provided peer and tries to handshake with the given protocols in order.
493
+ * If successful, the known metadata of the peer will be added to the nodes `peerStore`,
494
+ * and the `MuxedStream` will be returned together with the successful negotiated protocol.
495
+ *
496
+ * @example
497
+ *
498
+ * ```js
499
+ * import { pipe } from 'it-pipe'
500
+ *
501
+ * const { stream, protocol } = await libp2p.dialProtocol(remotePeerId, protocols)
502
+ *
503
+ * // Use this new stream like any other duplex stream
504
+ * pipe([1, 2, 3], stream, consume)
505
+ * ```
506
+ */
507
+ dialProtocol: (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: AbortOptions) => Promise<Stream>
508
+
509
+ /**
510
+ * Attempts to gracefully close an open connection to the given peer. If the connection is not closed in the grace period, it will be forcefully closed.
511
+ *
512
+ * @example
513
+ *
514
+ * ```js
515
+ * await libp2p.hangUp(remotePeerId)
516
+ * ```
517
+ */
518
+ hangUp: (peer: PeerId | Multiaddr) => Promise<void>
519
+
520
+ /**
521
+ * Sets up [multistream-select routing](https://github.com/multiformats/multistream-select) of protocols to their application handlers. Whenever a stream is opened on one of the provided protocols, the handler will be called. `handle` must be called in order to register a handler and support for a given protocol. This also informs other peers of the protocols you support.
522
+ *
523
+ * `libp2p.handle(protocols, handler, options)`
524
+ *
525
+ * In the event of a new handler for the same protocol being added, the first one is discarded.
526
+ *
527
+ * @example
528
+ *
529
+ * ```js
530
+ * const handler = ({ connection, stream, protocol }) => {
531
+ * // use stream or connection according to the needs
532
+ * }
533
+ *
534
+ * libp2p.handle('/echo/1.0.0', handler, {
535
+ * maxInboundStreams: 5,
536
+ * maxOutboundStreams: 5
537
+ * })
538
+ * ```
539
+ */
540
+ handle: (protocol: string | string[], handler: StreamHandler, options?: StreamHandlerOptions) => Promise<void>
541
+
542
+ /**
543
+ * Removes the handler for each protocol. The protocol
544
+ * will no longer be supported on streams.
545
+ *
546
+ * @example
547
+ *
548
+ * ```js
549
+ * libp2p.unhandle(['/echo/1.0.0'])
550
+ * ```
551
+ */
552
+ unhandle: (protocols: string[] | string) => Promise<void>
553
+
554
+ /**
555
+ * Register a topology to be informed when peers are encountered that
556
+ * support the specified protocol
557
+ *
558
+ * @example
559
+ *
560
+ * ```js
561
+ * const id = await libp2p.register('/echo/1.0.0', {
562
+ * onConnect: (peer, connection) => {
563
+ * // handle connect
564
+ * },
565
+ * onDisconnect: (peer, connection) => {
566
+ * // handle disconnect
567
+ * }
568
+ * })
569
+ * ```
570
+ */
571
+ register: (protocol: string, topology: Topology) => Promise<string>
572
+
573
+ /**
574
+ * Unregister topology to no longer be informed when peers connect or
575
+ * disconnect.
576
+ *
577
+ * @example
578
+ *
579
+ * ```js
580
+ * const id = await libp2p.register(...)
581
+ *
582
+ * libp2p.unregister(id)
583
+ * ```
584
+ */
585
+ unregister: (id: string) => void
586
+
587
+ /**
588
+ * Returns the public key for the passed PeerId. If the PeerId is of the 'RSA' type
589
+ * this may mean searching the DHT if the key is not present in the KeyStore.
590
+ * A set of user defined services
591
+ */
592
+ getPublicKey: (peer: PeerId, options?: AbortOptions) => Promise<Uint8Array>
593
+
594
+ /**
595
+ * A set of user defined services
596
+ */
597
+ services: T
598
+ }
@@ -0,0 +1,35 @@
1
+ import type { PeerId } from '@libp2p/interface/peer-id'
2
+ import type { Uint8ArrayList } from 'uint8arraylist'
3
+
4
+ /**
5
+ * Record is the base implementation of a record that can be used as the payload of a libp2p envelope.
6
+ */
7
+ export interface Record {
8
+ /**
9
+ * signature domain.
10
+ */
11
+ domain: string
12
+ /**
13
+ * identifier of the type of record
14
+ */
15
+ codec: Uint8Array
16
+ /**
17
+ * Marshal a record to be used in an envelope.
18
+ */
19
+ marshal: () => Uint8Array
20
+ /**
21
+ * Verifies if the other provided Record is identical to this one.
22
+ */
23
+ equals: (other: Record) => boolean
24
+ }
25
+
26
+ export interface Envelope {
27
+ peerId: PeerId
28
+ payloadType: Uint8Array | Uint8ArrayList
29
+ payload: Uint8Array
30
+ signature: Uint8Array | Uint8ArrayList
31
+
32
+ marshal: () => Uint8Array
33
+ validate: (domain: string) => Promise<boolean>
34
+ equals: (other: Envelope) => boolean
35
+ }
@@ -0,0 +1,71 @@
1
+ import type { Connection, Stream } from '@libp2p/interface/connection'
2
+ import type { Topology } from '@libp2p/interface/topology'
3
+
4
+ export interface IncomingStreamData {
5
+ stream: Stream
6
+ connection: Connection
7
+ }
8
+
9
+ export interface StreamHandler {
10
+ (data: IncomingStreamData): void
11
+ }
12
+
13
+ export interface StreamHandlerOptions {
14
+ /**
15
+ * How many incoming streams can be open for this protocol at the same time on each connection (default: 32)
16
+ */
17
+ maxInboundStreams?: number
18
+
19
+ /**
20
+ * How many outgoing streams can be open for this protocol at the same time on each connection (default: 64)
21
+ */
22
+ maxOutboundStreams?: number
23
+ }
24
+
25
+ export interface StreamHandlerRecord {
26
+ handler: StreamHandler
27
+ options: StreamHandlerOptions
28
+ }
29
+
30
+ export interface Registrar {
31
+ /**
32
+ * Return the list of protocols with registered handlers
33
+ */
34
+ getProtocols: () => string[]
35
+
36
+ /**
37
+ * Add a protocol handler
38
+ */
39
+ handle: (protocol: string, handler: StreamHandler, options?: StreamHandlerOptions) => Promise<void>
40
+
41
+ /**
42
+ * Remove a protocol handler
43
+ */
44
+ unhandle: (protocol: string) => Promise<void>
45
+
46
+ /**
47
+ * Return the handler for the passed protocol
48
+ */
49
+ getHandler: (protocol: string) => StreamHandlerRecord
50
+
51
+ /**
52
+ * Register a topology handler for a protocol - the topology will be
53
+ * invoked when peers are discovered on the network that support the
54
+ * passed protocol.
55
+ *
56
+ * An id will be returned that can later be used to unregister the
57
+ * topology.
58
+ */
59
+ register: (protocol: string, topology: Topology) => Promise<string>
60
+
61
+ /**
62
+ * Remove the topology handler with the passed id.
63
+ */
64
+ unregister: (id: string) => void
65
+
66
+ /**
67
+ * Return all topology handlers that wish to be informed about peers
68
+ * that support the passed protocol.
69
+ */
70
+ getTopologies: (protocol: string) => Topology[]
71
+ }
@@ -0,0 +1,15 @@
1
+ import type { Connection } from '@libp2p/interface/connection'
2
+ import type { Listener, Transport } from '@libp2p/interface/transport'
3
+ import type { Multiaddr } from '@multiformats/multiaddr'
4
+
5
+ export interface TransportManager {
6
+ add: (transport: Transport) => void
7
+ dial: (ma: Multiaddr, options?: any) => Promise<Connection>
8
+ getAddrs: () => Multiaddr[]
9
+ getTransports: () => Transport[]
10
+ getListeners: () => Listener[]
11
+ transportForMultiaddr: (ma: Multiaddr) => Transport | undefined
12
+ listen: (addrs: Multiaddr[]) => Promise<void>
13
+ remove: (key: string) => Promise<void>
14
+ removeAll: () => Promise<void>
15
+ }