libp2p 0.40.0-d8b7311 → 0.40.0-fb5fa3d
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 +1 -3
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +1 -1
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -11
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/dialer/index.d.ts +1 -2
- package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/index.js +3 -8
- package/dist/src/connection-manager/dialer/index.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +0 -8
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +6 -50
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +15 -3
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +2 -3
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +1 -2
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +10 -38
- package/dist/src/upgrader.js.map +1 -1
- package/package.json +8 -9
- package/src/address-manager/index.ts +3 -2
- package/src/circuit/README.md +6 -6
- package/src/config.ts +0 -11
- package/src/connection-manager/dialer/index.ts +4 -11
- package/src/connection-manager/index.ts +6 -55
- package/src/fetch/index.ts +16 -3
- package/src/index.ts +2 -2
- package/src/libp2p.ts +2 -3
- package/src/transport-manager.ts +1 -2
- package/src/upgrader.ts +13 -44
- package/src/version.ts +1 -1
- package/dist/src/metrics/index.d.ts +0 -93
- package/dist/src/metrics/index.d.ts.map +0 -1
- package/dist/src/metrics/index.js +0 -234
- package/dist/src/metrics/index.js.map +0 -1
- package/dist/src/metrics/moving-average.d.ts +0 -14
- package/dist/src/metrics/moving-average.d.ts.map +0 -1
- package/dist/src/metrics/moving-average.js +0 -40
- package/dist/src/metrics/moving-average.js.map +0 -1
- package/dist/src/metrics/stats.d.ts +0 -87
- package/dist/src/metrics/stats.d.ts.map +0 -1
- package/dist/src/metrics/stats.js +0 -183
- package/dist/src/metrics/stats.js.map +0 -1
- package/src/metrics/index.ts +0 -311
- package/src/metrics/moving-average.ts +0 -53
- package/src/metrics/stats.ts +0 -238
|
@@ -2,8 +2,6 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import errCode from 'err-code'
|
|
3
3
|
import mergeOptions from 'merge-options'
|
|
4
4
|
import { LatencyMonitor, SummaryObject } from './latency-monitor.js'
|
|
5
|
-
// @ts-expect-error retimer does not have types
|
|
6
|
-
import retimer from 'retimer'
|
|
7
5
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
8
6
|
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
9
7
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
@@ -38,8 +36,6 @@ const defaultOptions: Partial<ConnectionManagerInit> = {
|
|
|
38
36
|
maxIncomingPendingConnections: 10
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
const METRICS_SYSTEM = 'libp2p'
|
|
42
|
-
const METRICS_COMPONENT = 'connection-manager'
|
|
43
39
|
const STARTUP_RECONNECT_TIMEOUT = 60000
|
|
44
40
|
|
|
45
41
|
export interface ConnectionManagerInit {
|
|
@@ -183,7 +179,6 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
183
179
|
private readonly opts: Required<ConnectionManagerInit>
|
|
184
180
|
private readonly connections: Map<string, Connection[]>
|
|
185
181
|
private started: boolean
|
|
186
|
-
private timer?: ReturnType<retimer>
|
|
187
182
|
private readonly latencyMonitor: LatencyMonitor
|
|
188
183
|
private readonly startupReconnectTimeout: number
|
|
189
184
|
private connectOnStartupController?: TimeoutController
|
|
@@ -212,7 +207,6 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
212
207
|
this.connections = new Map()
|
|
213
208
|
|
|
214
209
|
this.started = false
|
|
215
|
-
this._checkMetrics = this._checkMetrics.bind(this)
|
|
216
210
|
|
|
217
211
|
this.latencyMonitor = new LatencyMonitor({
|
|
218
212
|
latencyCheckIntervalMs: init.pollInterval,
|
|
@@ -250,17 +244,9 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
250
244
|
* only event loop and connection limits will be monitored.
|
|
251
245
|
*/
|
|
252
246
|
async start () {
|
|
253
|
-
if (this.components.metrics != null) {
|
|
254
|
-
this.timer = this.timer ?? retimer(this._checkMetrics, this.opts.pollInterval)
|
|
255
|
-
}
|
|
256
|
-
|
|
257
247
|
// track inbound/outbound connections
|
|
258
|
-
this.components.metrics?.
|
|
259
|
-
|
|
260
|
-
component: METRICS_COMPONENT,
|
|
261
|
-
metric: 'connections',
|
|
262
|
-
label: 'direction',
|
|
263
|
-
value: () => {
|
|
248
|
+
this.components.metrics?.registerMetricGroup('libp2p_connection_manager_connections', {
|
|
249
|
+
calculate: () => {
|
|
264
250
|
const metric = {
|
|
265
251
|
inbound: 0,
|
|
266
252
|
outbound: 0
|
|
@@ -281,12 +267,9 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
281
267
|
})
|
|
282
268
|
|
|
283
269
|
// track total number of streams per protocol
|
|
284
|
-
this.components.metrics?.
|
|
285
|
-
system: METRICS_SYSTEM,
|
|
286
|
-
component: METRICS_COMPONENT,
|
|
287
|
-
metric: 'protocol-streams-total',
|
|
270
|
+
this.components.metrics?.registerMetricGroup('libp2p_protocol_streams_total', {
|
|
288
271
|
label: 'protocol',
|
|
289
|
-
|
|
272
|
+
calculate: () => {
|
|
290
273
|
const metric: Record<string, number> = {}
|
|
291
274
|
|
|
292
275
|
for (const conns of this.connections.values()) {
|
|
@@ -304,12 +287,9 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
304
287
|
})
|
|
305
288
|
|
|
306
289
|
// track 90th percentile of streams per protocol
|
|
307
|
-
this.components.metrics?.
|
|
308
|
-
system: METRICS_SYSTEM,
|
|
309
|
-
component: METRICS_COMPONENT,
|
|
310
|
-
metric: 'protocol-streams-per-connection-90th-percentile',
|
|
290
|
+
this.components.metrics?.registerMetricGroup('libp2p_connection_manager_protocol_streams_per_connection_90th_percentile', {
|
|
311
291
|
label: 'protocol',
|
|
312
|
-
|
|
292
|
+
calculate: () => {
|
|
313
293
|
const allStreams: Record<string, number[]> = {}
|
|
314
294
|
|
|
315
295
|
for (const conns of this.connections.values()) {
|
|
@@ -407,8 +387,6 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
407
387
|
* Stops the Connection Manager
|
|
408
388
|
*/
|
|
409
389
|
async stop () {
|
|
410
|
-
this.timer?.clear()
|
|
411
|
-
|
|
412
390
|
this.latencyMonitor.removeEventListener('data', this._onLatencyMeasure)
|
|
413
391
|
this.latencyMonitor.stop()
|
|
414
392
|
|
|
@@ -440,31 +418,6 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
440
418
|
this.connections.clear()
|
|
441
419
|
}
|
|
442
420
|
|
|
443
|
-
/**
|
|
444
|
-
* Checks the libp2p metrics to determine if any values have exceeded
|
|
445
|
-
* the configured maximums.
|
|
446
|
-
*
|
|
447
|
-
* @private
|
|
448
|
-
*/
|
|
449
|
-
async _checkMetrics () {
|
|
450
|
-
const metrics = this.components.metrics
|
|
451
|
-
|
|
452
|
-
if (metrics != null) {
|
|
453
|
-
try {
|
|
454
|
-
const movingAverages = metrics.getGlobal().getMovingAverages()
|
|
455
|
-
const received = movingAverages.dataReceived[this.opts.movingAverageInterval].movingAverage
|
|
456
|
-
await this._checkMaxLimit('maxReceivedData', received)
|
|
457
|
-
const sent = movingAverages.dataSent[this.opts.movingAverageInterval].movingAverage
|
|
458
|
-
await this._checkMaxLimit('maxSentData', sent)
|
|
459
|
-
const total = received + sent
|
|
460
|
-
await this._checkMaxLimit('maxData', total)
|
|
461
|
-
log.trace('metrics update', total)
|
|
462
|
-
} finally {
|
|
463
|
-
this.timer = retimer(this._checkMetrics, this.opts.pollInterval)
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
421
|
onConnect (evt: CustomEvent<Connection>) {
|
|
469
422
|
void this._onConnect(evt).catch(err => {
|
|
470
423
|
log.error(err)
|
|
@@ -524,8 +477,6 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
524
477
|
} else if (storedConn != null) {
|
|
525
478
|
this.connections.delete(peerId)
|
|
526
479
|
this.dispatchEvent(new CustomEvent<Connection>('peer:disconnect', { detail: connection }))
|
|
527
|
-
|
|
528
|
-
this.components.metrics?.onPeerDisconnected(connection.remotePeer)
|
|
529
480
|
}
|
|
530
481
|
}
|
|
531
482
|
|
package/src/fetch/index.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { pipe } from 'it-pipe'
|
|
|
14
14
|
import first from 'it-first'
|
|
15
15
|
import { TimeoutController } from 'timeout-abort-controller'
|
|
16
16
|
import { setMaxListeners } from 'events'
|
|
17
|
+
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
|
|
18
|
+
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
|
|
17
19
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
18
20
|
|
|
19
21
|
const log = logger('libp2p:fetch')
|
|
@@ -103,6 +105,7 @@ export class FetchService implements Startable {
|
|
|
103
105
|
|
|
104
106
|
// create a timeout if no abort signal passed
|
|
105
107
|
if (signal == null) {
|
|
108
|
+
log('using default timeout of %d ms', this.init.timeout)
|
|
106
109
|
timeoutController = new TimeoutController(this.init.timeout)
|
|
107
110
|
signal = timeoutController.signal
|
|
108
111
|
|
|
@@ -113,13 +116,15 @@ export class FetchService implements Startable {
|
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
try {
|
|
116
|
-
stream = await connection.newStream(
|
|
119
|
+
stream = await connection.newStream(this.protocol, {
|
|
117
120
|
signal
|
|
118
121
|
})
|
|
119
122
|
|
|
120
123
|
// make stream abortable
|
|
121
124
|
const source = abortableDuplex(stream, signal)
|
|
122
125
|
|
|
126
|
+
log('fetch %s', key)
|
|
127
|
+
|
|
123
128
|
const result = await pipe(
|
|
124
129
|
[FetchRequest.encode({ identifier: key })],
|
|
125
130
|
lp.encode(),
|
|
@@ -136,16 +141,20 @@ export class FetchService implements Startable {
|
|
|
136
141
|
|
|
137
142
|
switch (response.status) {
|
|
138
143
|
case (FetchResponse.StatusCode.OK): {
|
|
144
|
+
log('received status for %s ok', key)
|
|
139
145
|
return response.data
|
|
140
146
|
}
|
|
141
147
|
case (FetchResponse.StatusCode.NOT_FOUND): {
|
|
148
|
+
log('received status for %s not found', key)
|
|
142
149
|
return null
|
|
143
150
|
}
|
|
144
151
|
case (FetchResponse.StatusCode.ERROR): {
|
|
145
|
-
|
|
152
|
+
log('received status for %s error', key)
|
|
153
|
+
const errmsg = uint8arrayToString(response.data)
|
|
146
154
|
throw errCode(new Error('Error in fetch protocol response: ' + errmsg), codes.ERR_INVALID_PARAMETERS)
|
|
147
155
|
}
|
|
148
156
|
default: {
|
|
157
|
+
log('received status for %s unknown', key)
|
|
149
158
|
throw errCode(new Error('Unknown response status'), codes.ERR_INVALID_MESSAGE)
|
|
150
159
|
}
|
|
151
160
|
}
|
|
@@ -189,14 +198,18 @@ export class FetchService implements Startable {
|
|
|
189
198
|
let response: FetchResponse
|
|
190
199
|
const lookup = self._getLookupFunction(request.identifier)
|
|
191
200
|
if (lookup != null) {
|
|
201
|
+
log('look up data with identifier %s', request.identifier)
|
|
192
202
|
const data = await lookup(request.identifier)
|
|
193
203
|
if (data != null) {
|
|
204
|
+
log('sending status for %s ok', request.identifier)
|
|
194
205
|
response = { status: FetchResponse.StatusCode.OK, data }
|
|
195
206
|
} else {
|
|
207
|
+
log('sending status for %s not found', request.identifier)
|
|
196
208
|
response = { status: FetchResponse.StatusCode.NOT_FOUND, data: new Uint8Array(0) }
|
|
197
209
|
}
|
|
198
210
|
} else {
|
|
199
|
-
|
|
211
|
+
log('sending status for %s error', request.identifier)
|
|
212
|
+
const errmsg = uint8arrayFromString(`No lookup function registered for key: ${request.identifier}`)
|
|
200
213
|
response = { status: FetchResponse.StatusCode.ERROR, data: errmsg }
|
|
201
214
|
}
|
|
202
215
|
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ import type { ContentRouting } from '@libp2p/interface-content-routing'
|
|
|
20
20
|
import type { PubSub } from '@libp2p/interface-pubsub'
|
|
21
21
|
import type { Registrar, StreamHandler, StreamHandlerOptions } from '@libp2p/interface-registrar'
|
|
22
22
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
23
|
-
import type { Metrics
|
|
23
|
+
import type { Metrics } from '@libp2p/interface-metrics'
|
|
24
24
|
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
25
25
|
import type { KeyChain } from './keychain/index.js'
|
|
26
26
|
import type { ConnectionManagerInit } from './connection-manager/index.js'
|
|
@@ -104,7 +104,6 @@ export interface Libp2pInit {
|
|
|
104
104
|
connectionGater: Partial<ConnectionGater>
|
|
105
105
|
transportManager: TransportManagerConfig
|
|
106
106
|
datastore: Datastore
|
|
107
|
-
metrics: MetricsInit
|
|
108
107
|
peerStore: PeerStoreInit
|
|
109
108
|
peerRouting: PeerRoutingConfig
|
|
110
109
|
keychain: KeychainConfig
|
|
@@ -121,6 +120,7 @@ export interface Libp2pInit {
|
|
|
121
120
|
peerRouters?: Array<(components: Components) => PeerRouting>
|
|
122
121
|
contentRouters?: Array<(components: Components) => ContentRouting>
|
|
123
122
|
dht?: (components: Components) => DualDHT
|
|
123
|
+
metrics?: (components: Components) => Metrics
|
|
124
124
|
pubsub?: (components: Components) => PubSub
|
|
125
125
|
connectionProtector?: (components: Components) => ConnectionProtector
|
|
126
126
|
}
|
package/src/libp2p.ts
CHANGED
|
@@ -14,7 +14,6 @@ import { AutoDialler } from './connection-manager/auto-dialler.js'
|
|
|
14
14
|
import { Circuit } from './circuit/transport.js'
|
|
15
15
|
import { Relay } from './circuit/index.js'
|
|
16
16
|
import { KeyChain } from './keychain/index.js'
|
|
17
|
-
import { DefaultMetrics } from './metrics/index.js'
|
|
18
17
|
import { DefaultTransportManager } from './transport-manager.js'
|
|
19
18
|
import { DefaultUpgrader } from './upgrader.js'
|
|
20
19
|
import { DefaultRegistrar } from './registrar.js'
|
|
@@ -103,8 +102,8 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
103
102
|
]
|
|
104
103
|
|
|
105
104
|
// Create Metrics
|
|
106
|
-
if (init.metrics
|
|
107
|
-
this.metrics = this.components.metrics =
|
|
105
|
+
if (init.metrics != null) {
|
|
106
|
+
this.metrics = this.components.metrics = this.configureComponent(init.metrics(this.components))
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
this.peerStore = this.components.peerStore
|
package/src/transport-manager.ts
CHANGED
|
@@ -38,8 +38,7 @@ export class DefaultTransportManager extends EventEmitter<TransportManagerEvents
|
|
|
38
38
|
this.started = false
|
|
39
39
|
this.transports = new Map<string, Transport>()
|
|
40
40
|
this.listeners = trackedMap({
|
|
41
|
-
|
|
42
|
-
metric: 'listeners',
|
|
41
|
+
name: 'libp2p_transport_manager_listeners',
|
|
43
42
|
metrics: this.components.metrics
|
|
44
43
|
})
|
|
45
44
|
this.faultTolerance = init.faultTolerance ?? FaultTolerance.FATAL_ALL
|
package/src/upgrader.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import errCode from 'err-code'
|
|
3
3
|
import * as mss from '@libp2p/multistream-select'
|
|
4
|
-
import { pipe } from 'it-pipe'
|
|
5
|
-
// @ts-expect-error mutable-proxy does not export types
|
|
6
|
-
import mutableProxy from 'mutable-proxy'
|
|
7
4
|
import { codes } from './errors.js'
|
|
8
5
|
import { createConnection } from '@libp2p/connection'
|
|
9
6
|
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
@@ -146,9 +143,6 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
146
143
|
let upgradedConn: Duplex<Uint8Array>
|
|
147
144
|
let muxerFactory: StreamMuxerFactory | undefined
|
|
148
145
|
let cryptoProtocol
|
|
149
|
-
let setPeer
|
|
150
|
-
let proxyPeer
|
|
151
|
-
const metrics = this.components.metrics
|
|
152
146
|
|
|
153
147
|
const timeoutController = new TimeoutController(this.inboundUpgradeTimeout)
|
|
154
148
|
|
|
@@ -166,12 +160,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
166
160
|
throw errCode(new Error('The multiaddr connection is blocked by gater.acceptConnection'), codes.ERR_CONNECTION_INTERCEPTED)
|
|
167
161
|
}
|
|
168
162
|
|
|
169
|
-
|
|
170
|
-
({ setTarget: setPeer, proxy: proxyPeer } = mutableProxy())
|
|
171
|
-
const idString = `${(Math.random() * 1e9).toString(36)}${Date.now()}`
|
|
172
|
-
setPeer({ toString: () => idString })
|
|
173
|
-
metrics.trackStream({ stream: maConn, remotePeer: proxyPeer })
|
|
174
|
-
}
|
|
163
|
+
this.components.metrics?.trackMultiaddrConnection(maConn)
|
|
175
164
|
|
|
176
165
|
log('starting the inbound connection upgrade')
|
|
177
166
|
|
|
@@ -222,11 +211,6 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
222
211
|
throw errCode(new Error('The multiaddr connection is blocked by gater.acceptEncryptedConnection'), codes.ERR_CONNECTION_INTERCEPTED)
|
|
223
212
|
}
|
|
224
213
|
|
|
225
|
-
if (metrics != null) {
|
|
226
|
-
metrics.updatePlaceholder(proxyPeer, remotePeer)
|
|
227
|
-
setPeer(remotePeer)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
214
|
log('Successfully upgraded inbound connection')
|
|
231
215
|
|
|
232
216
|
return this._createConnection({
|
|
@@ -263,16 +247,8 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
263
247
|
let upgradedConn
|
|
264
248
|
let cryptoProtocol
|
|
265
249
|
let muxerFactory
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const metrics = this.components.metrics
|
|
269
|
-
|
|
270
|
-
if (metrics != null) {
|
|
271
|
-
({ setTarget: setPeer, proxy: proxyPeer } = mutableProxy())
|
|
272
|
-
const idString = `${(Math.random() * 1e9).toString(36)}${Date.now()}`
|
|
273
|
-
setPeer({ toB58String: () => idString })
|
|
274
|
-
metrics.trackStream({ stream: maConn, remotePeer: proxyPeer })
|
|
275
|
-
}
|
|
250
|
+
|
|
251
|
+
this.components.metrics?.trackMultiaddrConnection(maConn)
|
|
276
252
|
|
|
277
253
|
log('Starting the outbound connection upgrade')
|
|
278
254
|
|
|
@@ -335,11 +311,6 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
335
311
|
throw errCode(new Error('The multiaddr connection is blocked by gater.acceptEncryptedConnection'), codes.ERR_CONNECTION_INTERCEPTED)
|
|
336
312
|
}
|
|
337
313
|
|
|
338
|
-
if (metrics != null) {
|
|
339
|
-
metrics.updatePlaceholder(proxyPeer, remotePeer)
|
|
340
|
-
setPeer(remotePeer)
|
|
341
|
-
}
|
|
342
|
-
|
|
343
314
|
log('Successfully upgraded outbound connection')
|
|
344
315
|
|
|
345
316
|
return this._createConnection({
|
|
@@ -385,12 +356,6 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
385
356
|
const { stream, protocol } = await mss.handle(muxedStream, protocols)
|
|
386
357
|
log('%s: incoming stream opened on %s', direction, protocol)
|
|
387
358
|
|
|
388
|
-
const metrics = this.components.metrics
|
|
389
|
-
|
|
390
|
-
if (metrics != null) {
|
|
391
|
-
metrics.trackStream({ stream, remotePeer, protocol })
|
|
392
|
-
}
|
|
393
|
-
|
|
394
359
|
if (connection == null) {
|
|
395
360
|
return
|
|
396
361
|
}
|
|
@@ -415,6 +380,8 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
415
380
|
this.components.peerStore.protoBook.add(remotePeer, [protocol]).catch(err => log.error(err))
|
|
416
381
|
|
|
417
382
|
connection.addStream(muxedStream)
|
|
383
|
+
this.components.metrics?.trackProtocolStream(muxedStream, connection)
|
|
384
|
+
|
|
418
385
|
this._onStream({ connection, stream: muxedStream, protocol })
|
|
419
386
|
})
|
|
420
387
|
.catch(err => {
|
|
@@ -438,7 +405,6 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
438
405
|
|
|
439
406
|
log('%s: starting new stream on %s', direction, protocols)
|
|
440
407
|
const muxedStream = await muxer.newStream()
|
|
441
|
-
const metrics = this.components.metrics
|
|
442
408
|
let controller: TimeoutController | undefined
|
|
443
409
|
|
|
444
410
|
try {
|
|
@@ -456,10 +422,6 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
456
422
|
|
|
457
423
|
const { stream, protocol } = await mss.select(muxedStream, protocols, options)
|
|
458
424
|
|
|
459
|
-
if (metrics != null) {
|
|
460
|
-
metrics.trackStream({ stream, remotePeer, protocol })
|
|
461
|
-
}
|
|
462
|
-
|
|
463
425
|
const outgoingLimit = findOutgoingStreamLimit(protocol, this.components.registrar)
|
|
464
426
|
const streamCount = countStreams(protocol, 'outbound', connection)
|
|
465
427
|
|
|
@@ -480,6 +442,8 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
480
442
|
muxedStream.sink = stream.sink
|
|
481
443
|
muxedStream.stat.protocol = protocol
|
|
482
444
|
|
|
445
|
+
this.components.metrics?.trackProtocolStream(muxedStream, connection)
|
|
446
|
+
|
|
483
447
|
return muxedStream
|
|
484
448
|
} catch (err: any) {
|
|
485
449
|
log.error('could not create new stream', err)
|
|
@@ -501,7 +465,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
501
465
|
}
|
|
502
466
|
|
|
503
467
|
// Pipe all data through the muxer
|
|
504
|
-
|
|
468
|
+
void Promise.all([
|
|
469
|
+
muxer.sink(upgradedConn.source),
|
|
470
|
+
upgradedConn.sink(muxer.source)
|
|
471
|
+
]).catch(err => {
|
|
472
|
+
log.error(err)
|
|
473
|
+
})
|
|
505
474
|
}
|
|
506
475
|
|
|
507
476
|
const _timeline = maConn.timeline
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.40.0-
|
|
1
|
+
export const version = '0.40.0-fb5fa3d'
|
|
2
2
|
export const name = 'libp2p'
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { DefaultStats } from './stats.js';
|
|
2
|
-
import type { ComponentMetricsUpdate, Metrics, Stats, TrackedMetric, TrackStreamOptions } from '@libp2p/interface-metrics';
|
|
3
|
-
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
4
|
-
import type { Startable } from '@libp2p/interfaces/startable';
|
|
5
|
-
export interface OnMessageOptions {
|
|
6
|
-
remotePeer: PeerId;
|
|
7
|
-
protocol?: string;
|
|
8
|
-
direction: 'in' | 'out';
|
|
9
|
-
dataLength: number;
|
|
10
|
-
}
|
|
11
|
-
export interface MetricsInit {
|
|
12
|
-
enabled: boolean;
|
|
13
|
-
computeThrottleMaxQueueSize: number;
|
|
14
|
-
computeThrottleTimeout: number;
|
|
15
|
-
movingAverageIntervals: number[];
|
|
16
|
-
maxOldPeersRetention: number;
|
|
17
|
-
}
|
|
18
|
-
export declare class DefaultMetrics implements Metrics, Startable {
|
|
19
|
-
globalStats: DefaultStats;
|
|
20
|
-
private readonly enabled;
|
|
21
|
-
private readonly peerStats;
|
|
22
|
-
private readonly protocolStats;
|
|
23
|
-
private readonly oldPeers;
|
|
24
|
-
private running;
|
|
25
|
-
private readonly systems;
|
|
26
|
-
private readonly statsInit;
|
|
27
|
-
constructor(init: MetricsInit);
|
|
28
|
-
isStarted(): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Must be called for stats to saved. Any data pushed for tracking
|
|
31
|
-
* will be ignored.
|
|
32
|
-
*/
|
|
33
|
-
start(): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Stops all averages timers and prevents new data from being tracked.
|
|
36
|
-
* Once `stop` is called, `start` must be called to resume stats tracking.
|
|
37
|
-
*/
|
|
38
|
-
stop(): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Gets the global `Stats` object
|
|
41
|
-
*/
|
|
42
|
-
getGlobal(): DefaultStats;
|
|
43
|
-
/**
|
|
44
|
-
* Returns a list of `PeerId` strings currently being tracked
|
|
45
|
-
*/
|
|
46
|
-
getPeers(): string[];
|
|
47
|
-
getComponentMetrics(): Map<string, Map<string, Map<string, TrackedMetric>>>;
|
|
48
|
-
updateComponentMetric(update: ComponentMetricsUpdate): void;
|
|
49
|
-
/**
|
|
50
|
-
* Returns the `Stats` object for the given `PeerId` whether it
|
|
51
|
-
* is a live peer, or in the disconnected peer LRU cache.
|
|
52
|
-
*/
|
|
53
|
-
forPeer(peerId: PeerId): Stats | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Returns a list of all protocol strings currently being tracked
|
|
56
|
-
*/
|
|
57
|
-
getProtocols(): string[];
|
|
58
|
-
/**
|
|
59
|
-
* Returns the `Stats` object for the given `protocol`
|
|
60
|
-
*/
|
|
61
|
-
forProtocol(protocol: string): Stats | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* Should be called when all connections to a given peer
|
|
64
|
-
* have closed. The `Stats` collection for the peer will
|
|
65
|
-
* be stopped and moved to an LRU for temporary retention.
|
|
66
|
-
*/
|
|
67
|
-
onPeerDisconnected(peerId: PeerId): void;
|
|
68
|
-
/**
|
|
69
|
-
* Takes the metadata for a message and tracks it in the
|
|
70
|
-
* appropriate categories. If the protocol is present, protocol
|
|
71
|
-
* stats will also be tracked.
|
|
72
|
-
*/
|
|
73
|
-
_onMessage(opts: OnMessageOptions): void;
|
|
74
|
-
/**
|
|
75
|
-
* Replaces the `PeerId` string with the given `peerId`.
|
|
76
|
-
* If stats are already being tracked for the given `peerId`, the
|
|
77
|
-
* placeholder stats will be merged with the existing stats.
|
|
78
|
-
*
|
|
79
|
-
* @param {PeerId} placeholder - A peerId string
|
|
80
|
-
* @param {PeerId} peerId
|
|
81
|
-
* @returns {void}
|
|
82
|
-
*/
|
|
83
|
-
updatePlaceholder(placeholder: PeerId, peerId: PeerId): void;
|
|
84
|
-
/**
|
|
85
|
-
* Tracks data running through a given Duplex Iterable `stream`. If
|
|
86
|
-
* the `peerId` is not provided, a placeholder string will be created and
|
|
87
|
-
* returned. This allows lazy tracking of a peer when the peer is not yet known.
|
|
88
|
-
* When the `PeerId` is known, `Metrics.updatePlaceholder` should be called
|
|
89
|
-
* with the placeholder string returned from here, and the known `PeerId`.
|
|
90
|
-
*/
|
|
91
|
-
trackStream(opts: TrackStreamOptions): void;
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metrics/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAa,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC1H,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAY7D,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,IAAI,GAAG,KAAK,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,2BAA2B,EAAE,MAAM,CAAA;IACnC,sBAAsB,EAAE,MAAM,CAAA;IAC9B,sBAAsB,EAAE,MAAM,EAAE,CAAA;IAChC,oBAAoB,EAAE,MAAM,CAAA;CAC7B;AAED,qBAAa,cAAe,YAAW,OAAO,EAAE,SAAS;IAChD,WAAW,EAAE,YAAY,CAAA;IAEhC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA2B;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsD;IAC9E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;gBAExB,IAAI,EAAE,WAAW;IAe9B,SAAS;IAIT;;;OAGG;IACG,KAAK;IAQX;;;OAGG;IACG,IAAI;IAiBV;;OAEG;IACH,SAAS;IAIT;;OAEG;IACH,QAAQ;IAIR,mBAAmB;IAInB,qBAAqB,CAAE,MAAM,EAAE,sBAAsB;IA8BrD;;;OAGG;IACH,OAAO,CAAE,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IAK3C;;OAEG;IACH,YAAY,IAAK,MAAM,EAAE;IAIzB;;OAEG;IACH,WAAW,CAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IAIjD;;;;OAIG;IACH,kBAAkB,CAAE,MAAM,EAAE,MAAM;IAYlC;;;;OAIG;IACH,UAAU,CAAE,IAAI,EAAE,gBAAgB;IAkClC;;;;;;;;OAQG;IACH,iBAAiB,CAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAwBtD;;;;;;OAMG;IACH,WAAW,CAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI;CA+B7C"}
|