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