libp2p 1.6.1 → 1.7.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/dist/index.min.js +9 -9
- 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.js +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/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'
|
|
2
2
|
export const name = 'libp2p'
|