libp2p 2.8.7 → 2.8.8-2a7425cdb
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 +10 -10
- package/dist/index.min.js.map +4 -4
- package/dist/src/address-manager/dns-mappings.d.ts.map +1 -1
- package/dist/src/address-manager/dns-mappings.js +5 -1
- package/dist/src/address-manager/dns-mappings.js.map +1 -1
- package/dist/src/address-manager/index.d.ts +2 -1
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/address-manager/ip-mappings.d.ts.map +1 -1
- package/dist/src/address-manager/ip-mappings.js +5 -1
- package/dist/src/address-manager/ip-mappings.js.map +1 -1
- package/dist/src/address-manager/observed-addresses.d.ts.map +1 -1
- package/dist/src/address-manager/observed-addresses.js +5 -1
- package/dist/src/address-manager/observed-addresses.js.map +1 -1
- package/dist/src/address-manager/transport-addresses.d.ts.map +1 -1
- package/dist/src/address-manager/transport-addresses.js +5 -1
- package/dist/src/address-manager/transport-addresses.js.map +1 -1
- package/dist/src/content-routing.js +1 -1
- package/dist/src/content-routing.js.map +1 -1
- package/dist/src/libp2p.d.ts +2 -2
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +6 -6
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.js +2 -2
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/registrar.d.ts +3 -2
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +22 -6
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +4 -1
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +21 -8
- 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 +12 -12
- package/src/address-manager/dns-mappings.ts +5 -1
- package/src/address-manager/index.ts +2 -1
- package/src/address-manager/ip-mappings.ts +5 -1
- package/src/address-manager/observed-addresses.ts +5 -1
- package/src/address-manager/transport-addresses.ts +5 -1
- package/src/content-routing.ts +1 -1
- package/src/libp2p.ts +6 -6
- package/src/peer-routing.ts +2 -2
- package/src/registrar.ts +26 -7
- package/src/transport-manager.ts +4 -1
- package/src/upgrader.ts +22 -8
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -21
package/src/registrar.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { InvalidParametersError } from '@libp2p/interface'
|
|
2
2
|
import { mergeOptions } from '@libp2p/utils/merge-options'
|
|
3
|
+
import { trackedMap } from '@libp2p/utils/tracked-map'
|
|
3
4
|
import * as errorsJs from './errors.js'
|
|
4
|
-
import type { IdentifyResult, Libp2pEvents, Logger, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology, StreamHandler, StreamHandlerRecord, StreamHandlerOptions } from '@libp2p/interface'
|
|
5
|
+
import type { IdentifyResult, Libp2pEvents, Logger, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology, StreamHandler, StreamHandlerRecord, StreamHandlerOptions, AbortOptions, Metrics } from '@libp2p/interface'
|
|
5
6
|
import type { Registrar as RegistrarInterface } from '@libp2p/interface-internal'
|
|
6
7
|
import type { ComponentLogger } from '@libp2p/logger'
|
|
7
8
|
|
|
@@ -13,6 +14,7 @@ export interface RegistrarComponents {
|
|
|
13
14
|
peerStore: PeerStore
|
|
14
15
|
events: TypedEventTarget<Libp2pEvents>
|
|
15
16
|
logger: ComponentLogger
|
|
17
|
+
metrics?: Metrics
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -25,10 +27,24 @@ export class Registrar implements RegistrarInterface {
|
|
|
25
27
|
private readonly components: RegistrarComponents
|
|
26
28
|
|
|
27
29
|
constructor (components: RegistrarComponents) {
|
|
30
|
+
this.components = components
|
|
28
31
|
this.log = components.logger.forComponent('libp2p:registrar')
|
|
29
32
|
this.topologies = new Map()
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
components.metrics?.registerMetricGroup('libp2p_registrar_topologies', {
|
|
34
|
+
calculate: () => {
|
|
35
|
+
const output: Record<string, number> = {}
|
|
36
|
+
|
|
37
|
+
for (const [key, value] of this.topologies) {
|
|
38
|
+
output[key] = value.size
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return output
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
this.handlers = trackedMap({
|
|
45
|
+
name: 'libp2p_registrar_protocol_handlers',
|
|
46
|
+
metrics: components.metrics
|
|
47
|
+
})
|
|
32
48
|
|
|
33
49
|
this._onDisconnect = this._onDisconnect.bind(this)
|
|
34
50
|
this._onPeerUpdate = this._onPeerUpdate.bind(this)
|
|
@@ -90,14 +106,14 @@ export class Registrar implements RegistrarInterface {
|
|
|
90
106
|
// Add new protocol to self protocols in the peer store
|
|
91
107
|
await this.components.peerStore.merge(this.components.peerId, {
|
|
92
108
|
protocols: [protocol]
|
|
93
|
-
})
|
|
109
|
+
}, opts)
|
|
94
110
|
}
|
|
95
111
|
|
|
96
112
|
/**
|
|
97
113
|
* Removes the handler for each protocol. The protocol
|
|
98
114
|
* will no longer be supported on streams.
|
|
99
115
|
*/
|
|
100
|
-
async unhandle (protocols: string | string[]): Promise<void> {
|
|
116
|
+
async unhandle (protocols: string | string[], options?: AbortOptions): Promise<void> {
|
|
101
117
|
const protocolList = Array.isArray(protocols) ? protocols : [protocols]
|
|
102
118
|
|
|
103
119
|
protocolList.forEach(protocol => {
|
|
@@ -107,7 +123,7 @@ export class Registrar implements RegistrarInterface {
|
|
|
107
123
|
// Update self protocols in the peer store
|
|
108
124
|
await this.components.peerStore.patch(this.components.peerId, {
|
|
109
125
|
protocols: this.getProtocols()
|
|
110
|
-
})
|
|
126
|
+
}, options)
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
/**
|
|
@@ -153,8 +169,11 @@ export class Registrar implements RegistrarInterface {
|
|
|
153
169
|
*/
|
|
154
170
|
_onDisconnect (evt: CustomEvent<PeerId>): void {
|
|
155
171
|
const remotePeer = evt.detail
|
|
172
|
+
const options = {
|
|
173
|
+
signal: AbortSignal.timeout(5_000)
|
|
174
|
+
}
|
|
156
175
|
|
|
157
|
-
void this.components.peerStore.get(remotePeer)
|
|
176
|
+
void this.components.peerStore.get(remotePeer, options)
|
|
158
177
|
.then(peer => {
|
|
159
178
|
for (const protocol of peer.protocols) {
|
|
160
179
|
const topologies = this.topologies.get(protocol)
|
package/src/transport-manager.ts
CHANGED
|
@@ -42,7 +42,10 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
42
42
|
this.log = components.logger.forComponent('libp2p:transports')
|
|
43
43
|
this.components = components
|
|
44
44
|
this.started = false
|
|
45
|
-
this.transports =
|
|
45
|
+
this.transports = trackedMap({
|
|
46
|
+
name: 'libp2p_transport_manager_transports',
|
|
47
|
+
metrics: this.components.metrics
|
|
48
|
+
})
|
|
46
49
|
this.listeners = trackedMap({
|
|
47
50
|
name: 'libp2p_transport_manager_listeners',
|
|
48
51
|
metrics: this.components.metrics
|
package/src/upgrader.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { InvalidMultiaddrError, TooManyInboundProtocolStreamsError, TooManyOutboundProtocolStreamsError, LimitedConnectionError, setMaxListeners, InvalidPeerIdError } from '@libp2p/interface'
|
|
2
2
|
import * as mss from '@libp2p/multistream-select'
|
|
3
3
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
4
|
+
import { trackedMap } from '@libp2p/utils/tracked-map'
|
|
4
5
|
import { anySignal } from 'any-signal'
|
|
5
6
|
import { CustomProgressEvent } from 'progress-events'
|
|
7
|
+
import { raceSignal } from 'race-signal'
|
|
6
8
|
import { createConnection } from './connection/index.js'
|
|
7
9
|
import { PROTOCOL_NEGOTIATION_TIMEOUT, INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
|
|
8
10
|
import { ConnectionDeniedError, ConnectionInterceptedError, EncryptionFailedError, MuxerUnavailableError } from './errors.js'
|
|
@@ -129,13 +131,19 @@ export class Upgrader implements UpgraderInterface {
|
|
|
129
131
|
|
|
130
132
|
constructor (components: UpgraderComponents, init: UpgraderInit) {
|
|
131
133
|
this.components = components
|
|
132
|
-
this.connectionEncrypters =
|
|
134
|
+
this.connectionEncrypters = trackedMap({
|
|
135
|
+
name: 'libp2p_upgrader_connection_encrypters',
|
|
136
|
+
metrics: this.components.metrics
|
|
137
|
+
})
|
|
133
138
|
|
|
134
139
|
init.connectionEncrypters.forEach(encrypter => {
|
|
135
140
|
this.connectionEncrypters.set(encrypter.protocol, encrypter)
|
|
136
141
|
})
|
|
137
142
|
|
|
138
|
-
this.streamMuxers =
|
|
143
|
+
this.streamMuxers = trackedMap({
|
|
144
|
+
name: 'libp2p_upgrader_stream_multiplexers',
|
|
145
|
+
metrics: this.components.metrics
|
|
146
|
+
})
|
|
139
147
|
|
|
140
148
|
init.streamMuxers.forEach(muxer => {
|
|
141
149
|
this.streamMuxers.set(muxer.protocol, muxer)
|
|
@@ -193,13 +201,13 @@ export class Upgrader implements UpgraderInterface {
|
|
|
193
201
|
inbound: true
|
|
194
202
|
})
|
|
195
203
|
|
|
196
|
-
accepted = await this.components.connectionManager.acceptIncomingConnection(maConn)
|
|
204
|
+
accepted = await raceSignal(this.components.connectionManager.acceptIncomingConnection(maConn), signal)
|
|
197
205
|
|
|
198
206
|
if (!accepted) {
|
|
199
207
|
throw new ConnectionDeniedError('Connection denied')
|
|
200
208
|
}
|
|
201
209
|
|
|
202
|
-
await this.shouldBlockConnection('denyInboundConnection', maConn)
|
|
210
|
+
await raceSignal(this.shouldBlockConnection('denyInboundConnection', maConn), signal)
|
|
203
211
|
|
|
204
212
|
await this._performUpgrade(maConn, 'inbound', {
|
|
205
213
|
...opts,
|
|
@@ -234,7 +242,7 @@ export class Upgrader implements UpgraderInterface {
|
|
|
234
242
|
|
|
235
243
|
if (idStr != null) {
|
|
236
244
|
remotePeerId = peerIdFromString(idStr)
|
|
237
|
-
await this.shouldBlockConnection('denyOutboundConnection', remotePeerId, maConn)
|
|
245
|
+
await raceSignal(this.shouldBlockConnection('denyOutboundConnection', remotePeerId, maConn), opts.signal)
|
|
238
246
|
}
|
|
239
247
|
|
|
240
248
|
let direction: 'inbound' | 'outbound' = 'outbound'
|
|
@@ -387,11 +395,12 @@ export class Upgrader implements UpgraderInterface {
|
|
|
387
395
|
return
|
|
388
396
|
}
|
|
389
397
|
|
|
398
|
+
const signal = AbortSignal.timeout(this.inboundStreamProtocolNegotiationTimeout)
|
|
399
|
+
setMaxListeners(Infinity, signal)
|
|
400
|
+
|
|
390
401
|
void Promise.resolve()
|
|
391
402
|
.then(async () => {
|
|
392
403
|
const protocols = this.components.registrar.getProtocols()
|
|
393
|
-
const signal = AbortSignal.timeout(this.inboundStreamProtocolNegotiationTimeout)
|
|
394
|
-
setMaxListeners(Infinity, signal)
|
|
395
404
|
|
|
396
405
|
const { stream, protocol } = await mss.handle(muxedStream, protocols, {
|
|
397
406
|
signal,
|
|
@@ -440,6 +449,8 @@ export class Upgrader implements UpgraderInterface {
|
|
|
440
449
|
// the peer store should ensure that the peer is registered with that protocol
|
|
441
450
|
await this.components.peerStore.merge(remotePeer, {
|
|
442
451
|
protocols: [protocol]
|
|
452
|
+
}, {
|
|
453
|
+
signal
|
|
443
454
|
})
|
|
444
455
|
|
|
445
456
|
this.components.metrics?.trackProtocolStream(muxedStream, connection)
|
|
@@ -450,7 +461,10 @@ export class Upgrader implements UpgraderInterface {
|
|
|
450
461
|
connection.log.error('error handling incoming stream id %s - %e', muxedStream.id, err)
|
|
451
462
|
|
|
452
463
|
if (muxedStream.timeline.close == null) {
|
|
453
|
-
await muxedStream.close(
|
|
464
|
+
await muxedStream.close({
|
|
465
|
+
signal
|
|
466
|
+
})
|
|
467
|
+
.catch(err => muxedStream.abort(err))
|
|
454
468
|
}
|
|
455
469
|
})
|
|
456
470
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '2.8.
|
|
1
|
+
export const version = '2.8.8-2a7425cdb'
|
|
2
2
|
export const name = 'js-libp2p'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AddressFilter": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressFilter.html",
|
|
3
|
-
"AddressManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressManagerInit.html",
|
|
4
|
-
"ConnectionManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionManagerInit.html",
|
|
5
|
-
"ConnectionMonitorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionMonitorInit.html",
|
|
6
|
-
"Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
7
|
-
".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
8
|
-
"TransportManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.TransportManagerInit.html",
|
|
9
|
-
"Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
10
|
-
".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
11
|
-
"ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
12
|
-
".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
13
|
-
"createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
14
|
-
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
15
|
-
"userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user-agent.userAgent.html",
|
|
16
|
-
"./user-agent:userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user-agent.userAgent.html",
|
|
17
|
-
"name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
18
|
-
"./version:name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
19
|
-
"version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html",
|
|
20
|
-
"./version:version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html"
|
|
21
|
-
}
|