@libp2p/interface-internal 0.0.1-05abd49f → 0.0.1-1f7e18b0

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.
@@ -1,15 +1,8 @@
1
- import type { AbortOptions } from '@libp2p/interface';
1
+ import type { AbortOptions, PendingDial } from '@libp2p/interface';
2
2
  import type { Connection, MultiaddrConnection } from '@libp2p/interface/connection';
3
3
  import type { PeerId } from '@libp2p/interface/peer-id';
4
4
  import type { PeerMap } from '@libp2p/peer-collections';
5
5
  import type { Multiaddr } from '@multiformats/multiaddr';
6
- export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success';
7
- export interface PendingDial {
8
- id: string;
9
- status: PendingDialStatus;
10
- peerId?: PeerId;
11
- multiaddrs: Multiaddr[];
12
- }
13
6
  export interface ConnectionManager {
14
7
  /**
15
8
  * Return connections, optionally filtering by a PeerId
@@ -45,7 +38,7 @@ export interface ConnectionManager {
45
38
  /**
46
39
  * Close our connections to a peer
47
40
  */
48
- closeConnections: (peer: PeerId) => Promise<void>;
41
+ closeConnections: (peer: PeerId, options?: AbortOptions) => Promise<void>;
49
42
  /**
50
43
  * Invoked after an incoming connection is opened but before PeerIds are
51
44
  * exchanged, this lets the ConnectionManager check we have sufficient
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,GAAG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M,yBAAyB,CAAA;AAExD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;OASG;IACH,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,UAAU,EAAE,CAAA;IAEjD;;;;;;;;OAQG;IACH,iBAAiB,EAAE,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;IAE9C;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IAEvG;;OAEG;IACH,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzE;;;;;OAKG;IACH,wBAAwB,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAE3E;;OAEG;IACH,mBAAmB,EAAE,MAAM,IAAI,CAAA;IAE/B;;;;;;;;OAQG;IACH,YAAY,EAAE,MAAM,WAAW,EAAE,CAAA;CAClC"}
@@ -1,548 +1,2 @@
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
- }
1
+ export {};
548
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceR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AE,MAAM,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAA"}
package/dist/src/index.js CHANGED
@@ -1,17 +1,2 @@
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
1
  export {};
17
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAA"}
@@ -16,6 +16,12 @@ export interface StreamHandlerOptions {
16
16
  * How many outgoing streams can be open for this protocol at the same time on each connection (default: 64)
17
17
  */
18
18
  maxOutboundStreams?: number;
19
+ /**
20
+ * If true, allow this protocol to run on limited connections (e.g.
21
+ * connections with data or duration limits such as circuit relay
22
+ * connections) (default: false)
23
+ */
24
+ runOnTransientConnection?: boolean;
19
25
  }
20
26
  export interface StreamHandlerRecord {
21
27
  handler: StreamHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src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AAE,MAAM,KAAK,IAAI,CAAA;IAEhC;;;OAGG;IACH,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAA;CAChD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface-internal",
3
- "version": "0.0.1-05abd49f",
3
+ "version": "0.0.1-1f7e18b0",
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/master/packages/interface-internal#readme",
@@ -60,10 +60,6 @@
60
60
  "types": "./dist/src/registrar/index.d.ts",
61
61
  "import": "./dist/src/registrar/index.js"
62
62
  },
63
- "./transport": {
64
- "types": "./dist/src/transport/index.d.ts",
65
- "import": "./dist/src/transport/index.js"
66
- },
67
63
  "./transport-manager": {
68
64
  "types": "./dist/src/transport-manager/index.d.ts",
69
65
  "import": "./dist/src/transport-manager/index.js"
@@ -82,15 +78,12 @@
82
78
  "build": "aegir build"
83
79
  },
84
80
  "dependencies": {
85
- "@libp2p/interface": "0.0.1-05abd49f",
86
- "@libp2p/peer-collections": "3.0.2-05abd49f",
81
+ "@libp2p/interface": "0.0.1-1f7e18b0",
82
+ "@libp2p/peer-collections": "3.0.2-1f7e18b0",
87
83
  "@multiformats/multiaddr": "^12.1.3",
88
84
  "uint8arraylist": "^2.4.3"
89
85
  },
90
86
  "devDependencies": {
91
- "aegir": "^39.0.10"
92
- },
93
- "typedoc": {
94
- "entryPoint": "./src/index.ts"
87
+ "aegir": "^40.0.1"
95
88
  }
96
89
  }
@@ -1,18 +1,9 @@
1
- import type { AbortOptions } from '@libp2p/interface'
1
+ import type { AbortOptions, PendingDial } from '@libp2p/interface'
2
2
  import type { Connection, MultiaddrConnection } from '@libp2p/interface/connection'
3
3
  import type { PeerId } from '@libp2p/interface/peer-id'
4
4
  import type { PeerMap } from '@libp2p/peer-collections'
5
5
  import type { Multiaddr } from '@multiformats/multiaddr'
6
6
 
7
- export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success'
8
-
9
- export interface PendingDial {
10
- id: string
11
- status: PendingDialStatus
12
- peerId?: PeerId
13
- multiaddrs: Multiaddr[]
14
- }
15
-
16
7
  export interface ConnectionManager {
17
8
  /**
18
9
  * Return connections, optionally filtering by a PeerId
@@ -51,7 +42,7 @@ export interface ConnectionManager {
51
42
  /**
52
43
  * Close our connections to a peer
53
44
  */
54
- closeConnections: (peer: PeerId) => Promise<void>
45
+ closeConnections: (peer: PeerId, options?: AbortOptions) => Promise<void>
55
46
 
56
47
  /**
57
48
  * Invoked after an incoming connection is opened but before PeerIds are
package/src/index.ts CHANGED
@@ -1,598 +1 @@
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
- }
1
+ export {}
@@ -20,6 +20,13 @@ export interface StreamHandlerOptions {
20
20
  * How many outgoing streams can be open for this protocol at the same time on each connection (default: 64)
21
21
  */
22
22
  maxOutboundStreams?: number
23
+
24
+ /**
25
+ * If true, allow this protocol to run on limited connections (e.g.
26
+ * connections with data or duration limits such as circuit relay
27
+ * connections) (default: false)
28
+ */
29
+ runOnTransientConnection?: boolean
23
30
  }
24
31
 
25
32
  export interface StreamHandlerRecord {
@@ -1,18 +0,0 @@
1
- import type { Connection, MultiaddrConnection } from '@libp2p/interface/connection';
2
- import type { StreamMuxerFactory } from '@libp2p/interface/stream-muxer';
3
- export interface UpgraderOptions {
4
- skipEncryption?: boolean;
5
- skipProtection?: boolean;
6
- muxerFactory?: StreamMuxerFactory;
7
- }
8
- export interface Upgrader {
9
- /**
10
- * Upgrades an outbound connection on `transport.dial`.
11
- */
12
- upgradeOutbound: (maConn: MultiaddrConnection, opts?: UpgraderOptions) => Promise<Connection>;
13
- /**
14
- * Upgrades an inbound connection on transport listener.
15
- */
16
- upgradeInbound: (maConn: MultiaddrConnection, opts?: UpgraderOptions) => Promise<Connection>;
17
- }
18
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/upgrader/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAExE,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,YAAY,CAAC,EAAE,kBAAkB,CAAA;CAClC;AAED,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,IAAI,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IAE7F;;OAEG;IACH,cAAc,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,IAAI,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;CAC7F"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/upgrader/index.ts"],"names":[],"mappings":""}
@@ -1,20 +0,0 @@
1
- import type { Connection, MultiaddrConnection } from '@libp2p/interface/connection'
2
- import type { StreamMuxerFactory } from '@libp2p/interface/stream-muxer'
3
-
4
- export interface UpgraderOptions {
5
- skipEncryption?: boolean
6
- skipProtection?: boolean
7
- muxerFactory?: StreamMuxerFactory
8
- }
9
-
10
- export interface Upgrader {
11
- /**
12
- * Upgrades an outbound connection on `transport.dial`.
13
- */
14
- upgradeOutbound: (maConn: MultiaddrConnection, opts?: UpgraderOptions) => Promise<Connection>
15
-
16
- /**
17
- * Upgrades an inbound connection on transport listener.
18
- */
19
- upgradeInbound: (maConn: MultiaddrConnection, opts?: UpgraderOptions) => Promise<Connection>
20
- }