@libp2p/interface 0.1.6 → 1.0.0
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.
- package/README.md +15 -1
- package/dist/index.min.js +1 -1
- package/dist/src/connection/index.d.ts +15 -3
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +2 -2
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-encrypter/index.d.ts +7 -5
- package/dist/src/connection-encrypter/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.d.ts +1 -1
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +1 -1
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/errors.d.ts +20 -5
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +20 -8
- package/dist/src/errors.js.map +1 -1
- package/dist/src/events.d.ts +0 -1
- package/dist/src/events.d.ts.map +1 -1
- package/dist/src/events.js +0 -2
- package/dist/src/events.js.map +1 -1
- package/dist/src/index.d.ts +34 -14
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +21 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/keys/index.d.ts +5 -4
- package/dist/src/keys/index.d.ts.map +1 -1
- package/dist/src/keys/index.js.map +1 -1
- package/dist/src/peer-discovery/index.d.ts +1 -1
- package/dist/src/peer-discovery/index.d.ts.map +1 -1
- package/dist/src/peer-discovery/index.js +1 -1
- package/dist/src/peer-discovery/index.js.map +1 -1
- package/dist/src/peer-id/index.d.ts +1 -1
- package/dist/src/peer-id/index.d.ts.map +1 -1
- package/dist/src/peer-id/index.js +2 -2
- package/dist/src/peer-id/index.js.map +1 -1
- package/dist/src/peer-info/index.d.ts +12 -1
- package/dist/src/peer-info/index.d.ts.map +1 -1
- package/dist/src/peer-routing/index.d.ts +1 -1
- package/dist/src/peer-routing/index.d.ts.map +1 -1
- package/dist/src/peer-routing/index.js +1 -1
- package/dist/src/peer-routing/index.js.map +1 -1
- package/dist/src/startable.d.ts +8 -1
- package/dist/src/startable.d.ts.map +1 -1
- package/dist/src/startable.js +8 -0
- package/dist/src/startable.js.map +1 -1
- package/dist/src/stream-muxer/index.d.ts +2 -2
- package/dist/src/stream-muxer/index.d.ts.map +1 -1
- package/dist/src/stream-muxer/stream.d.ts +2 -149
- package/dist/src/stream-muxer/stream.d.ts.map +1 -1
- package/dist/src/stream-muxer/stream.js +8 -322
- package/dist/src/stream-muxer/stream.js.map +1 -1
- package/dist/src/topology/index.d.ts +0 -2
- package/dist/src/topology/index.d.ts.map +1 -1
- package/dist/src/transport/index.d.ts +2 -2
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +2 -2
- package/dist/src/transport/index.js.map +1 -1
- package/dist/typedoc-urls.json +263 -266
- package/package.json +15 -27
- package/src/connection/index.ts +19 -4
- package/src/connection-encrypter/index.ts +7 -5
- package/src/content-routing/index.ts +1 -1
- package/src/errors.ts +21 -8
- package/src/events.ts +0 -3
- package/src/index.ts +37 -15
- package/src/keys/index.ts +6 -4
- package/src/peer-discovery/index.ts +1 -1
- package/src/peer-id/index.ts +2 -2
- package/src/peer-info/index.ts +13 -1
- package/src/peer-routing/index.ts +1 -1
- package/src/startable.ts +8 -2
- package/src/stream-muxer/index.ts +2 -2
- package/src/stream-muxer/stream.ts +9 -494
- package/src/topology/index.ts +0 -3
- package/src/transport/index.ts +3 -3
- package/dist/src/keychain/index.d.ts +0 -154
- package/dist/src/keychain/index.d.ts.map +0 -1
- package/dist/src/keychain/index.js +0 -23
- package/dist/src/keychain/index.js.map +0 -1
- package/dist/src/metrics/tracked-map.d.ts +0 -17
- package/dist/src/metrics/tracked-map.d.ts.map +0 -1
- package/dist/src/metrics/tracked-map.js +0 -38
- package/dist/src/metrics/tracked-map.js.map +0 -1
- package/src/keychain/index.ts +0 -167
- package/src/metrics/tracked-map.ts +0 -65
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interface",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "The interface implemented by a libp2p node",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p/tree/
|
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/libp2p/js-libp2p.git"
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/libp2p/js-libp2p/issues"
|
|
13
13
|
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"provenance": true
|
|
17
|
+
},
|
|
14
18
|
"keywords": [
|
|
15
19
|
"interface",
|
|
16
20
|
"libp2p"
|
|
@@ -39,9 +43,6 @@
|
|
|
39
43
|
"!dist/test",
|
|
40
44
|
"!**/*.tsbuildinfo"
|
|
41
45
|
],
|
|
42
|
-
"browser": {
|
|
43
|
-
"events": "./dist/src/events.browser.js"
|
|
44
|
-
},
|
|
45
46
|
"exports": {
|
|
46
47
|
".": {
|
|
47
48
|
"types": "./dist/src/index.d.ts",
|
|
@@ -150,33 +151,20 @@
|
|
|
150
151
|
"scripts": {
|
|
151
152
|
"clean": "aegir clean",
|
|
152
153
|
"lint": "aegir lint",
|
|
153
|
-
"dep-check": "aegir dep-check",
|
|
154
|
-
"build": "aegir build"
|
|
155
|
-
"test": "aegir test",
|
|
156
|
-
"test:chrome": "aegir test -t browser --cov",
|
|
157
|
-
"test:chrome-webworker": "aegir test -t webworker",
|
|
158
|
-
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
159
|
-
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
160
|
-
"test:node": "aegir test -t node --cov",
|
|
161
|
-
"test:electron-main": "aegir test -t electron-main"
|
|
154
|
+
"dep-check": "aegir dep-check -i @libp2p/utils",
|
|
155
|
+
"build": "aegir build"
|
|
162
156
|
},
|
|
163
157
|
"dependencies": {
|
|
164
|
-
"@multiformats/multiaddr": "^12.1.
|
|
165
|
-
"
|
|
166
|
-
"it-pushable": "^3.2.0",
|
|
158
|
+
"@multiformats/multiaddr": "^12.1.10",
|
|
159
|
+
"it-pushable": "^3.2.1",
|
|
167
160
|
"it-stream-types": "^2.0.1",
|
|
168
|
-
"multiformats": "^12.
|
|
169
|
-
"p-defer": "^4.0.0",
|
|
170
|
-
"race-signal": "^1.0.0",
|
|
161
|
+
"multiformats": "^12.1.3",
|
|
171
162
|
"uint8arraylist": "^2.4.3"
|
|
172
163
|
},
|
|
173
164
|
"devDependencies": {
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
"
|
|
178
|
-
"it-drain": "^3.0.3",
|
|
179
|
-
"sinon": "^17.0.0",
|
|
180
|
-
"sinon-ts": "^2.0.0"
|
|
165
|
+
"aegir": "^41.0.2"
|
|
166
|
+
},
|
|
167
|
+
"browser": {
|
|
168
|
+
"events": "./dist/src/events.browser.js"
|
|
181
169
|
}
|
|
182
170
|
}
|
package/src/connection/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbortOptions } from '../index.js'
|
|
1
|
+
import type { AbortOptions, Logger } from '../index.js'
|
|
2
2
|
import type { PeerId } from '../peer-id/index.js'
|
|
3
3
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
4
|
import type { Duplex, Source } from 'it-stream-types'
|
|
@@ -169,6 +169,11 @@ export interface Stream extends Duplex<AsyncGenerator<Uint8ArrayList>, Source<Ui
|
|
|
169
169
|
* The current status of the writable end of the stream
|
|
170
170
|
*/
|
|
171
171
|
writeStatus: WriteStatus
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The stream logger
|
|
175
|
+
*/
|
|
176
|
+
log: Logger
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
export interface NewStreamOptions extends AbortOptions {
|
|
@@ -268,12 +273,17 @@ export interface Connection {
|
|
|
268
273
|
* Immediately close the connection, any queued data will be discarded
|
|
269
274
|
*/
|
|
270
275
|
abort(err: Error): void
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* The connection logger
|
|
279
|
+
*/
|
|
280
|
+
log: Logger
|
|
271
281
|
}
|
|
272
282
|
|
|
273
|
-
export const
|
|
283
|
+
export const connectionSymbol = Symbol.for('@libp2p/connection')
|
|
274
284
|
|
|
275
285
|
export function isConnection (other: any): other is Connection {
|
|
276
|
-
return other != null && Boolean(other[
|
|
286
|
+
return other != null && Boolean(other[connectionSymbol])
|
|
277
287
|
}
|
|
278
288
|
|
|
279
289
|
export interface ConnectionProtector {
|
|
@@ -308,7 +318,7 @@ export interface MultiaddrConnectionTimeline {
|
|
|
308
318
|
* a peer. It is a low-level primitive and is the raw connection
|
|
309
319
|
* without encryption or stream multiplexing.
|
|
310
320
|
*/
|
|
311
|
-
export interface MultiaddrConnection extends Duplex<AsyncGenerator<Uint8Array
|
|
321
|
+
export interface MultiaddrConnection extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
|
|
312
322
|
/**
|
|
313
323
|
* Gracefully close the connection. All queued data will be written to the
|
|
314
324
|
* underlying transport.
|
|
@@ -329,4 +339,9 @@ export interface MultiaddrConnection extends Duplex<AsyncGenerator<Uint8Array>,
|
|
|
329
339
|
* When connection lifecycle events occurred
|
|
330
340
|
*/
|
|
331
341
|
timeline: MultiaddrConnectionTimeline
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The multiaddr connection logger
|
|
345
|
+
*/
|
|
346
|
+
log: Logger
|
|
332
347
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { MultiaddrConnection } from '../connection/index.js'
|
|
1
2
|
import type { PeerId } from '../peer-id/index.js'
|
|
2
|
-
import type { Duplex
|
|
3
|
+
import type { Duplex } from 'it-stream-types'
|
|
4
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* A libp2p connection encrypter module must be compliant to this interface
|
|
@@ -13,18 +15,18 @@ export interface ConnectionEncrypter<Extension = unknown> {
|
|
|
13
15
|
* pass it for extra verification, otherwise it will be determined during
|
|
14
16
|
* the handshake.
|
|
15
17
|
*/
|
|
16
|
-
secureOutbound(localPeer: PeerId, connection:
|
|
18
|
+
secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise<SecuredConnection<Stream, Extension>>
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Decrypt incoming data. If the remote PeerId is known,
|
|
20
22
|
* pass it for extra verification, otherwise it will be determined during
|
|
21
23
|
* the handshake
|
|
22
24
|
*/
|
|
23
|
-
secureInbound(localPeer: PeerId, connection:
|
|
25
|
+
secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise<SecuredConnection<Stream, Extension>>
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
export interface SecuredConnection<Extension = unknown> {
|
|
27
|
-
conn:
|
|
28
|
+
export interface SecuredConnection<Stream = any, Extension = unknown> {
|
|
29
|
+
conn: Stream
|
|
28
30
|
remoteExtensions?: Extension
|
|
29
31
|
remotePeer: PeerId
|
|
30
32
|
}
|
|
@@ -21,7 +21,7 @@ import type { CID } from 'multiformats/cid'
|
|
|
21
21
|
* }
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export const
|
|
24
|
+
export const contentRoutingSymbol = Symbol.for('@libp2p/content-routing')
|
|
25
25
|
|
|
26
26
|
export interface ContentRouting {
|
|
27
27
|
/**
|
package/src/errors.ts
CHANGED
|
@@ -18,6 +18,10 @@ export class AbortError extends Error {
|
|
|
18
18
|
static readonly type = 'aborted'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* An {@see Error } subclass that defines a `.code` property that calling code
|
|
23
|
+
* can use to detect what type of error has been thrown and act accordingly.
|
|
24
|
+
*/
|
|
21
25
|
export class CodeError<T extends Record<string, any> = Record<string, never>> extends Error {
|
|
22
26
|
public readonly props: T
|
|
23
27
|
|
|
@@ -55,13 +59,22 @@ export class InvalidCryptoExchangeError extends Error {
|
|
|
55
59
|
static readonly code = 'ERR_INVALID_CRYPTO_EXCHANGE'
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
/**
|
|
63
|
+
* A generic error code indicating that a timeout occurred
|
|
64
|
+
*/
|
|
65
|
+
export const ERR_TIMEOUT = 'ERR_TIMEOUT'
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
/**
|
|
68
|
+
* A generic error code indicating that invalid paramters were passed
|
|
69
|
+
*/
|
|
70
|
+
export const ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS'
|
|
65
71
|
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
/**
|
|
73
|
+
* A generic error code indicating that something was not found
|
|
74
|
+
*/
|
|
75
|
+
export const ERR_NOT_FOUND = 'ERR_NOT_FOUND'
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A generic error code indicating that the message was invalid
|
|
79
|
+
*/
|
|
80
|
+
export const ERR_INVALID_MESSAGE = 'ERR_INVALID_MESSAGE'
|
package/src/events.ts
CHANGED
|
@@ -117,9 +117,6 @@ class CustomEventPolyfill<T = any> extends Event {
|
|
|
117
117
|
|
|
118
118
|
export const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill
|
|
119
119
|
|
|
120
|
-
// TODO: remove this in v1
|
|
121
|
-
export { TypedEventEmitter as EventEmitter }
|
|
122
|
-
|
|
123
120
|
// create a setMaxListeners that doesn't break browser usage
|
|
124
121
|
export const setMaxListeners: typeof nodeSetMaxListeners = (n, ...eventTargets) => {
|
|
125
122
|
try {
|
package/src/index.ts
CHANGED
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
import type { Connection, NewStreamOptions, Stream } from './connection/index.js'
|
|
18
18
|
import type { ContentRouting } from './content-routing/index.js'
|
|
19
19
|
import type { TypedEventTarget } from './events.js'
|
|
20
|
-
import type { KeyChain } from './keychain/index.js'
|
|
21
20
|
import type { Metrics } from './metrics/index.js'
|
|
22
21
|
import type { PeerId } from './peer-id/index.js'
|
|
23
22
|
import type { PeerInfo } from './peer-info/index.js'
|
|
@@ -394,20 +393,6 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
394
393
|
*/
|
|
395
394
|
contentRouting: ContentRouting
|
|
396
395
|
|
|
397
|
-
/**
|
|
398
|
-
* The keychain contains the keys used by the current node, and can create new
|
|
399
|
-
* keys, export them, import them, etc.
|
|
400
|
-
*
|
|
401
|
-
* @example
|
|
402
|
-
*
|
|
403
|
-
* ```js
|
|
404
|
-
* const keyInfo = await libp2p.keychain.createKey('new key')
|
|
405
|
-
* console.info(keyInfo)
|
|
406
|
-
* // { id: '...', name: 'new key' }
|
|
407
|
-
* ```
|
|
408
|
-
*/
|
|
409
|
-
keychain: KeyChain
|
|
410
|
-
|
|
411
396
|
/**
|
|
412
397
|
* The metrics subsystem allows recording values to assess the health/performance
|
|
413
398
|
* of the running node.
|
|
@@ -624,6 +609,21 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
624
609
|
services: T
|
|
625
610
|
}
|
|
626
611
|
|
|
612
|
+
/**
|
|
613
|
+
* Metadata about the current node
|
|
614
|
+
*/
|
|
615
|
+
export interface NodeInfo {
|
|
616
|
+
/**
|
|
617
|
+
* The implementation name
|
|
618
|
+
*/
|
|
619
|
+
name: string
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* The implementation version
|
|
623
|
+
*/
|
|
624
|
+
version: string
|
|
625
|
+
}
|
|
626
|
+
|
|
627
627
|
/**
|
|
628
628
|
* An object that contains an AbortSignal as
|
|
629
629
|
* the optional `signal` property.
|
|
@@ -660,3 +660,25 @@ export interface LoggerOptions {
|
|
|
660
660
|
export type RecursivePartial<T> = {
|
|
661
661
|
[P in keyof T]?: T[P] extends Array<infer I> ? Array<RecursivePartial<I>> : T[P] extends (...args: any[]) => any ? T[P] : RecursivePartial<T[P]>
|
|
662
662
|
}
|
|
663
|
+
|
|
664
|
+
export * from './connection/index.js'
|
|
665
|
+
export * from './connection-encrypter/index.js'
|
|
666
|
+
export * from './connection-gater/index.js'
|
|
667
|
+
export * from './content-routing/index.js'
|
|
668
|
+
export * from './keys/index.js'
|
|
669
|
+
export * from './metrics/index.js'
|
|
670
|
+
export * from './peer-discovery/index.js'
|
|
671
|
+
export * from './peer-id/index.js'
|
|
672
|
+
export * from './peer-info/index.js'
|
|
673
|
+
export * from './peer-routing/index.js'
|
|
674
|
+
export * from './peer-store/index.js'
|
|
675
|
+
export * from './peer-store/tags.js'
|
|
676
|
+
export * from './pubsub/index.js'
|
|
677
|
+
export * from './record/index.js'
|
|
678
|
+
export * from './stream-handler/index.js'
|
|
679
|
+
export * from './stream-muxer/index.js'
|
|
680
|
+
export * from './topology/index.js'
|
|
681
|
+
export * from './transport/index.js'
|
|
682
|
+
export * from './errors.js'
|
|
683
|
+
export * from './events.js'
|
|
684
|
+
export * from './startable.js'
|
package/src/keys/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
2
|
+
|
|
1
3
|
export interface PublicKey {
|
|
2
4
|
readonly bytes: Uint8Array
|
|
3
|
-
verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>
|
|
5
|
+
verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean | Promise<boolean>
|
|
4
6
|
marshal(): Uint8Array
|
|
5
7
|
equals(key: PublicKey): boolean
|
|
6
|
-
hash(): Promise<Uint8Array>
|
|
8
|
+
hash(): Uint8Array | Promise<Uint8Array>
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -12,10 +14,10 @@ export interface PublicKey {
|
|
|
12
14
|
export interface PrivateKey {
|
|
13
15
|
readonly public: PublicKey
|
|
14
16
|
readonly bytes: Uint8Array
|
|
15
|
-
sign(data: Uint8Array): Promise<Uint8Array>
|
|
17
|
+
sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise<Uint8Array>
|
|
16
18
|
marshal(): Uint8Array
|
|
17
19
|
equals(key: PrivateKey): boolean
|
|
18
|
-
hash(): Promise<Uint8Array>
|
|
20
|
+
hash(): Uint8Array | Promise<Uint8Array>
|
|
19
21
|
/**
|
|
20
22
|
* Gets the ID of the key.
|
|
21
23
|
*
|
|
@@ -20,7 +20,7 @@ import type { PeerInfo } from '../peer-info/index.js'
|
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
export const
|
|
23
|
+
export const peerDiscoverySymbol = Symbol.for('@libp2p/peer-discovery')
|
|
24
24
|
|
|
25
25
|
export interface PeerDiscoveryEvents {
|
|
26
26
|
'peer': CustomEvent<PeerInfo>
|
package/src/peer-id/index.ts
CHANGED
|
@@ -32,8 +32,8 @@ export interface Secp256k1PeerId extends BasePeerId {
|
|
|
32
32
|
|
|
33
33
|
export type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId
|
|
34
34
|
|
|
35
|
-
export const
|
|
35
|
+
export const peerIdSymbol = Symbol.for('@libp2p/peer-id')
|
|
36
36
|
|
|
37
37
|
export function isPeerId (other: any): other is PeerId {
|
|
38
|
-
return other != null && Boolean(other[
|
|
38
|
+
return other != null && Boolean(other[peerIdSymbol])
|
|
39
39
|
}
|
package/src/peer-info/index.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { PeerId } from '../peer-id/index.js'
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A `PeerInfo` is a lightweight object that represents a remote peer, it can be
|
|
6
|
+
* obtained from peer discovery mechanisms, HTTP RPC endpoints, etc.
|
|
7
|
+
*
|
|
8
|
+
* @see https://docs.libp2p.io/concepts/fundamentals/peers/#peer-info
|
|
9
|
+
*/
|
|
4
10
|
export interface PeerInfo {
|
|
11
|
+
/**
|
|
12
|
+
* The identifier of the remote peer
|
|
13
|
+
*/
|
|
5
14
|
id: PeerId
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The multiaddrs a peer is listening on
|
|
18
|
+
*/
|
|
6
19
|
multiaddrs: Multiaddr[]
|
|
7
|
-
protocols: string[]
|
|
8
20
|
}
|
package/src/startable.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Implemented by components that have a lifecycle
|
|
3
3
|
*/
|
|
4
4
|
export interface Startable {
|
|
5
|
-
isStarted(): boolean
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* If implemented, this method will be invoked before the start method.
|
|
9
7
|
*
|
|
@@ -51,6 +49,10 @@ export function isStartable (obj: any): obj is Startable {
|
|
|
51
49
|
return obj != null && typeof obj.start === 'function' && typeof obj.stop === 'function'
|
|
52
50
|
}
|
|
53
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Start one or more {@link Startable}s, calling the `beforeStart` and
|
|
54
|
+
* `afterStart` lifecycle methods if defined.
|
|
55
|
+
*/
|
|
54
56
|
export async function start (...objs: any[]): Promise<void> {
|
|
55
57
|
const startables: Startable[] = []
|
|
56
58
|
|
|
@@ -83,6 +85,10 @@ export async function start (...objs: any[]): Promise<void> {
|
|
|
83
85
|
)
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Stop one or more {@link Startable}s, calling the `beforeStop` and
|
|
90
|
+
* `afterStop` lifecycle methods if defined.
|
|
91
|
+
*/
|
|
86
92
|
export async function stop (...objs: any[]): Promise<void> {
|
|
87
93
|
const startables: Startable[] = []
|
|
88
94
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Direction, Stream } from '../connection/index.js'
|
|
2
2
|
import type { AbortOptions } from '../index.js'
|
|
3
|
-
import type { Duplex
|
|
3
|
+
import type { Duplex } from 'it-stream-types'
|
|
4
4
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
5
5
|
|
|
6
6
|
export interface StreamMuxerFactory {
|
|
@@ -18,7 +18,7 @@ export interface StreamMuxerFactory {
|
|
|
18
18
|
/**
|
|
19
19
|
* A libp2p stream muxer
|
|
20
20
|
*/
|
|
21
|
-
export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array
|
|
21
|
+
export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
|
|
22
22
|
/**
|
|
23
23
|
* The protocol used to select this muxer during connection opening
|
|
24
24
|
*/
|