libp2p 1.6.1 → 1.7.0-3b9cbf7d8
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/dist/index.min.js +12 -12
- package/dist/src/address-manager/index.d.ts +1 -0
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +1 -0
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/components.d.ts +1 -0
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +31 -1
- package/dist/src/components.js.map +1 -1
- package/dist/src/config.d.ts +2 -2
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +1 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -0
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +1 -0
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/content-routing.d.ts +1 -0
- package/dist/src/content-routing.d.ts.map +1 -1
- package/dist/src/content-routing.js +1 -0
- package/dist/src/content-routing.js.map +1 -1
- package/dist/src/index.d.ts +16 -20
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +4 -4
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +6 -2
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -0
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +1 -0
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/random-walk.d.ts +1 -0
- package/dist/src/random-walk.d.ts.map +1 -1
- package/dist/src/random-walk.js +1 -0
- package/dist/src/random-walk.js.map +1 -1
- package/dist/src/registrar.d.ts +1 -0
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +1 -0
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +1 -0
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +1 -0
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +1 -0
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +1 -0
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +18 -18
- package/src/address-manager/index.ts +2 -0
- package/src/components.ts +39 -1
- package/src/config.ts +5 -5
- package/src/connection-manager/index.ts +2 -0
- package/src/content-routing.ts +2 -0
- package/src/index.ts +16 -16
- package/src/libp2p.ts +12 -7
- package/src/peer-routing.ts +2 -0
- package/src/random-walk.ts +2 -0
- package/src/registrar.ts +2 -0
- package/src/transport-manager.ts +2 -0
- package/src/upgrader.ts +2 -0
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -14
package/src/index.ts
CHANGED
|
@@ -19,65 +19,65 @@ import type { AddressManagerInit } from './address-manager/index.js'
|
|
|
19
19
|
import type { Components } from './components.js'
|
|
20
20
|
import type { ConnectionManagerInit } from './connection-manager/index.js'
|
|
21
21
|
import type { TransportManagerInit } from './transport-manager.js'
|
|
22
|
-
import type { Libp2p, ServiceMap,
|
|
22
|
+
import type { Libp2p, ServiceMap, ComponentLogger, NodeInfo, ConnectionProtector, ConnectionEncrypter, ConnectionGater, ContentRouting, Metrics, PeerDiscovery, PeerId, PeerRouting, StreamMuxerFactory, Transport, PrivateKey } from '@libp2p/interface'
|
|
23
23
|
import type { PersistentPeerStoreInit } from '@libp2p/peer-store'
|
|
24
24
|
import type { DNS } from '@multiformats/dns'
|
|
25
25
|
import type { Datastore } from 'interface-datastore'
|
|
26
26
|
|
|
27
|
-
export type ServiceFactoryMap<T extends
|
|
28
|
-
[Property in keyof T]: (components: Components) => T[Property]
|
|
27
|
+
export type ServiceFactoryMap<T extends ServiceMap = ServiceMap> = {
|
|
28
|
+
[Property in keyof T]: (components: Components & T) => T[Property]
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* For Libp2p configurations and modules details read the [Configuration Document](https://github.com/libp2p/js-libp2p/tree/main/doc/CONFIGURATION.md).
|
|
33
33
|
*/
|
|
34
|
-
export interface Libp2pInit<T extends ServiceMap =
|
|
34
|
+
export interface Libp2pInit<T extends ServiceMap = ServiceMap> {
|
|
35
35
|
/**
|
|
36
36
|
* peerId instance (it will be created if not provided)
|
|
37
37
|
*/
|
|
38
|
-
peerId
|
|
38
|
+
peerId?: PeerId
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Private key associated with the peerId
|
|
42
42
|
*/
|
|
43
|
-
privateKey
|
|
43
|
+
privateKey?: PrivateKey
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Metadata about the node - implementation name, version number, etc
|
|
47
47
|
*/
|
|
48
|
-
nodeInfo
|
|
48
|
+
nodeInfo?: NodeInfo
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Addresses for transport listening and to advertise to the network
|
|
52
52
|
*/
|
|
53
|
-
addresses
|
|
53
|
+
addresses?: AddressManagerInit
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* libp2p Connection Manager configuration
|
|
57
57
|
*/
|
|
58
|
-
connectionManager
|
|
58
|
+
connectionManager?: ConnectionManagerInit
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* A connection gater can deny new connections based on user criteria
|
|
62
62
|
*/
|
|
63
|
-
connectionGater
|
|
63
|
+
connectionGater?: ConnectionGater
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* libp2p transport manager configuration
|
|
67
67
|
*/
|
|
68
|
-
transportManager
|
|
68
|
+
transportManager?: TransportManagerInit
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* An optional datastore to persist peer information, DHT records, etc.
|
|
72
72
|
*
|
|
73
73
|
* An in-memory datastore will be used if one is not provided.
|
|
74
74
|
*/
|
|
75
|
-
datastore
|
|
75
|
+
datastore?: Datastore
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* libp2p PeerStore configuration
|
|
79
79
|
*/
|
|
80
|
-
peerStore
|
|
80
|
+
peerStore?: PersistentPeerStoreInit
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* An array that must include at least 1 compliant transport
|
|
@@ -102,7 +102,7 @@ export interface Libp2pInit<T extends ServiceMap = { x: Record<string, unknown>
|
|
|
102
102
|
/**
|
|
103
103
|
* Arbitrary libp2p modules
|
|
104
104
|
*/
|
|
105
|
-
services
|
|
105
|
+
services?: ServiceFactoryMap<T>
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* An optional logging implementation that can be used to write runtime logs.
|
|
@@ -135,7 +135,7 @@ export interface Libp2pInit<T extends ServiceMap = { x: Record<string, unknown>
|
|
|
135
135
|
|
|
136
136
|
export type { Libp2p }
|
|
137
137
|
|
|
138
|
-
export type Libp2pOptions<T extends ServiceMap =
|
|
138
|
+
export type Libp2pOptions<T extends ServiceMap = ServiceMap> = Libp2pInit<T> & { start?: boolean }
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Returns a new instance of the Libp2p interface, generating a new PeerId
|
|
@@ -163,7 +163,7 @@ export type Libp2pOptions<T extends ServiceMap = Record<string, unknown>> = Recu
|
|
|
163
163
|
* const libp2p = await createLibp2p(options)
|
|
164
164
|
* ```
|
|
165
165
|
*/
|
|
166
|
-
export async function createLibp2p <T extends ServiceMap =
|
|
166
|
+
export async function createLibp2p <T extends ServiceMap = ServiceMap> (options: Libp2pOptions<T> = {}): Promise<Libp2p<T>> {
|
|
167
167
|
const node = await createLibp2pNode(options)
|
|
168
168
|
|
|
169
169
|
if (options.start !== false) {
|
package/src/libp2p.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { MemoryDatastore } from 'datastore-core/memory'
|
|
|
10
10
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
11
11
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
12
12
|
import { DefaultAddressManager } from './address-manager/index.js'
|
|
13
|
-
import { defaultComponents } from './components.js'
|
|
13
|
+
import { checkServiceDependencies, defaultComponents } from './components.js'
|
|
14
14
|
import { connectionGater } from './config/connection-gater.js'
|
|
15
15
|
import { validateConfig } from './config.js'
|
|
16
16
|
import { DefaultConnectionManager } from './connection-manager/index.js'
|
|
@@ -27,7 +27,7 @@ import type { Libp2p, Libp2pInit, Libp2pOptions } from './index.js'
|
|
|
27
27
|
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus, IsDialableOptions } from '@libp2p/interface'
|
|
28
28
|
import type { StreamHandler, StreamHandlerOptions } from '@libp2p/interface-internal'
|
|
29
29
|
|
|
30
|
-
export class Libp2pNode<T extends ServiceMap =
|
|
30
|
+
export class Libp2pNode<T extends ServiceMap = ServiceMap> extends TypedEventEmitter<Libp2pEvents> implements Libp2p<T> {
|
|
31
31
|
public peerId: PeerId
|
|
32
32
|
public peerStore: PeerStore
|
|
33
33
|
public contentRouting: ContentRouting
|
|
@@ -37,10 +37,10 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
37
37
|
public logger: ComponentLogger
|
|
38
38
|
public status: Libp2pStatus
|
|
39
39
|
|
|
40
|
-
public components: Components
|
|
40
|
+
public components: Components & T
|
|
41
41
|
private readonly log: Logger
|
|
42
42
|
|
|
43
|
-
constructor (init: Libp2pInit<T>) {
|
|
43
|
+
constructor (init: Libp2pInit<T> & Required<Pick<Libp2pInit<T>, 'peerId'>>) {
|
|
44
44
|
super()
|
|
45
45
|
|
|
46
46
|
this.status = 'stopped'
|
|
@@ -66,6 +66,7 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
66
66
|
this.log = this.logger.forComponent('libp2p')
|
|
67
67
|
// @ts-expect-error {} may not be of type T
|
|
68
68
|
this.services = {}
|
|
69
|
+
// @ts-expect-error defaultComponents is missing component types added later
|
|
69
70
|
const components = this.components = defaultComponents({
|
|
70
71
|
peerId: init.peerId,
|
|
71
72
|
privateKey: init.privateKey,
|
|
@@ -111,7 +112,7 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
111
112
|
this.components.upgrader = new DefaultUpgrader(this.components, {
|
|
112
113
|
connectionEncryption: (init.connectionEncryption ?? []).map((fn, index) => this.configureComponent(`connection-encryption-${index}`, fn(this.components))),
|
|
113
114
|
muxers: (init.streamMuxers ?? []).map((fn, index) => this.configureComponent(`stream-muxers-${index}`, fn(this.components))),
|
|
114
|
-
inboundUpgradeTimeout: init.connectionManager
|
|
115
|
+
inboundUpgradeTimeout: init.connectionManager?.inboundUpgradeTimeout
|
|
115
116
|
})
|
|
116
117
|
|
|
117
118
|
// Setup the transport manager
|
|
@@ -187,6 +188,9 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
}
|
|
191
|
+
|
|
192
|
+
// Ensure all services have their required dependencies
|
|
193
|
+
checkServiceDependencies(components)
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
private configureComponent <T> (name: string, component: T): T {
|
|
@@ -194,6 +198,7 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
194
198
|
this.log.error('component %s was null or undefined', name)
|
|
195
199
|
}
|
|
196
200
|
|
|
201
|
+
// @ts-expect-error cannot assign props
|
|
197
202
|
this.components[name] = component
|
|
198
203
|
|
|
199
204
|
return component
|
|
@@ -406,14 +411,14 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
406
411
|
* Returns a new Libp2pNode instance - this exposes more of the internals than the
|
|
407
412
|
* libp2p interface and is useful for testing and debugging.
|
|
408
413
|
*/
|
|
409
|
-
export async function createLibp2pNode <T extends ServiceMap =
|
|
414
|
+
export async function createLibp2pNode <T extends ServiceMap = ServiceMap> (options: Libp2pOptions<T> = {}): Promise<Libp2pNode<T>> {
|
|
410
415
|
const peerId = options.peerId ??= await createEd25519PeerId()
|
|
411
416
|
|
|
412
417
|
if (peerId.privateKey == null) {
|
|
413
418
|
throw new CodeError('peer id was missing private key', 'ERR_MISSING_PRIVATE_KEY')
|
|
414
419
|
}
|
|
415
420
|
|
|
416
|
-
options.privateKey ??= await unmarshalPrivateKey(peerId.privateKey
|
|
421
|
+
options.privateKey ??= await unmarshalPrivateKey(peerId.privateKey)
|
|
417
422
|
|
|
418
423
|
return new Libp2pNode(await validateConfig(options))
|
|
419
424
|
}
|
package/src/peer-routing.ts
CHANGED
package/src/random-walk.ts
CHANGED
|
@@ -39,6 +39,8 @@ export class RandomWalk extends TypedEventEmitter<RandomWalkEvents> implements R
|
|
|
39
39
|
setMaxListeners(Infinity, this.shutdownController.signal)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
readonly [Symbol.toStringTag] = '@libp2p/random-walk'
|
|
43
|
+
|
|
42
44
|
start (): void {
|
|
43
45
|
this.shutdownController = new AbortController()
|
|
44
46
|
setMaxListeners(Infinity, this.shutdownController.signal)
|
package/src/registrar.ts
CHANGED
|
@@ -40,6 +40,8 @@ export class DefaultRegistrar implements Registrar {
|
|
|
40
40
|
this.components.events.addEventListener('peer:identify', this._onPeerIdentify)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
readonly [Symbol.toStringTag] = '@libp2p/registrar'
|
|
44
|
+
|
|
43
45
|
getProtocols (): string[] {
|
|
44
46
|
return Array.from(new Set<string>([
|
|
45
47
|
...this.handlers.keys()
|
package/src/transport-manager.ts
CHANGED
|
@@ -37,6 +37,8 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
37
37
|
this.faultTolerance = init.faultTolerance ?? FaultTolerance.FATAL_ALL
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
readonly [Symbol.toStringTag] = '@libp2p/transport-manager'
|
|
41
|
+
|
|
40
42
|
/**
|
|
41
43
|
* Adds a `Transport` to the manager
|
|
42
44
|
*/
|
package/src/upgrader.ts
CHANGED
|
@@ -122,6 +122,8 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
122
122
|
this.events = components.events
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
readonly [Symbol.toStringTag] = '@libp2p/upgrader'
|
|
126
|
+
|
|
125
127
|
async shouldBlockConnection (remotePeer: PeerId, maConn: MultiaddrConnection, connectionType: ConnectionDeniedType): Promise<void> {
|
|
126
128
|
const connectionGater = this.components.connectionGater[connectionType]
|
|
127
129
|
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '1.
|
|
1
|
+
export const version = '1.7.0-3b9cbf7d8'
|
|
2
2
|
export const name = 'libp2p'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
3
|
-
".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
4
|
-
"Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
5
|
-
".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
6
|
-
"ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
7
|
-
".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
8
|
-
"createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
9
|
-
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
10
|
-
"name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
11
|
-
"./version:name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
12
|
-
"version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html",
|
|
13
|
-
"./version:version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html"
|
|
14
|
-
}
|