@libp2p/interface-compliance-tests 6.1.8-02f285fc8 → 6.1.8-2feaeddb4
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/src/mocks/index.d.ts +0 -2
- package/dist/src/mocks/index.d.ts.map +1 -1
- package/dist/src/mocks/index.js +0 -2
- package/dist/src/mocks/index.js.map +1 -1
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +204 -3
- package/dist/src/transport/index.js.map +1 -1
- package/package.json +14 -15
- package/src/mocks/index.ts +0 -2
- package/src/transport/index.ts +261 -5
- package/dist/src/mocks/connection-gater.d.ts +0 -3
- package/dist/src/mocks/connection-gater.d.ts.map +0 -1
- package/dist/src/mocks/connection-gater.js +0 -17
- package/dist/src/mocks/connection-gater.js.map +0 -1
- package/dist/src/mocks/metrics.d.ts +0 -3
- package/dist/src/mocks/metrics.d.ts.map +0 -1
- package/dist/src/mocks/metrics.js +0 -286
- package/dist/src/mocks/metrics.js.map +0 -1
- package/dist/src/mocks/peer-discovery.d.ts +0 -21
- package/dist/src/mocks/peer-discovery.d.ts.map +0 -1
- package/dist/src/mocks/peer-discovery.js +0 -47
- package/dist/src/mocks/peer-discovery.js.map +0 -1
- package/src/mocks/connection-gater.ts +0 -18
- package/src/mocks/metrics.ts +0 -385
- package/src/mocks/peer-discovery.ts +0 -59
package/src/transport/index.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { stop } from '@libp2p/interface'
|
|
2
2
|
import { expect } from 'aegir/chai'
|
|
3
3
|
import delay from 'delay'
|
|
4
|
+
import drain from 'it-drain'
|
|
5
|
+
import { pushable } from 'it-pushable'
|
|
4
6
|
import pDefer from 'p-defer'
|
|
5
7
|
import { pEvent } from 'p-event'
|
|
8
|
+
import pRetry from 'p-retry'
|
|
6
9
|
import pWaitFor from 'p-wait-for'
|
|
7
10
|
import { raceSignal } from 'race-signal'
|
|
8
11
|
import { isValidTick } from '../is-valid-tick.js'
|
|
9
12
|
import { createPeer, getTransportManager, getUpgrader, slowNetwork } from './utils.js'
|
|
10
13
|
import type { TestSetup } from '../index.js'
|
|
11
14
|
import type { Echo } from '@libp2p/echo'
|
|
12
|
-
import type { Connection, Libp2p, Stream } from '@libp2p/interface'
|
|
15
|
+
import type { Connection, Libp2p, Stream, StreamHandler } from '@libp2p/interface'
|
|
13
16
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
14
17
|
import type { MultiaddrMatcher } from '@multiformats/multiaddr-matcher'
|
|
15
18
|
import type { Libp2pInit } from 'libp2p'
|
|
@@ -164,14 +167,14 @@ export default (common: TestSetup<TransportTestFixtures>): void => {
|
|
|
164
167
|
remoteConn = await incomingConnectionPromise.promise
|
|
165
168
|
}
|
|
166
169
|
|
|
167
|
-
const streams: Stream[] = []
|
|
168
|
-
|
|
169
170
|
for (let i = 0; i < 5; i++) {
|
|
170
|
-
|
|
171
|
+
await connection.newStream('/echo/1.0.0', {
|
|
171
172
|
maxOutboundStreams: 5
|
|
172
|
-
})
|
|
173
|
+
})
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
const streams = connection.streams
|
|
177
|
+
|
|
175
178
|
// Close the connection and verify all streams have been closed
|
|
176
179
|
await connection.close()
|
|
177
180
|
|
|
@@ -259,6 +262,249 @@ export default (common: TestSetup<TransportTestFixtures>): void => {
|
|
|
259
262
|
expect(output).to.equalBytes(input)
|
|
260
263
|
}
|
|
261
264
|
})
|
|
265
|
+
|
|
266
|
+
it('can close a stream for reading but send a large amount of data', async function () {
|
|
267
|
+
const timeout = 120_000
|
|
268
|
+
this.timeout(timeout);
|
|
269
|
+
({ dialer, listener, dialAddrs } = await getSetup(common))
|
|
270
|
+
|
|
271
|
+
if (listener == null) {
|
|
272
|
+
return this.skip()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const protocol = '/send-data/1.0.0'
|
|
276
|
+
const chunkSize = 1024
|
|
277
|
+
const bytes = chunkSize * 1024 * 10
|
|
278
|
+
const deferred = pDefer()
|
|
279
|
+
|
|
280
|
+
await listener.handle(protocol, ({ stream }) => {
|
|
281
|
+
Promise.resolve().then(async () => {
|
|
282
|
+
let read = 0
|
|
283
|
+
|
|
284
|
+
for await (const buf of stream.source) {
|
|
285
|
+
read += buf.byteLength
|
|
286
|
+
|
|
287
|
+
if (read === bytes) {
|
|
288
|
+
deferred.resolve()
|
|
289
|
+
break
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
.catch(err => {
|
|
294
|
+
deferred.reject(err)
|
|
295
|
+
stream.abort(err)
|
|
296
|
+
})
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
const stream = await dialer.dialProtocol(dialAddrs[0], protocol)
|
|
300
|
+
|
|
301
|
+
await stream.closeRead()
|
|
302
|
+
|
|
303
|
+
await stream.sink((async function * () {
|
|
304
|
+
for (let i = 0; i < bytes; i += chunkSize) {
|
|
305
|
+
yield new Uint8Array(chunkSize)
|
|
306
|
+
}
|
|
307
|
+
})())
|
|
308
|
+
|
|
309
|
+
await stream.close()
|
|
310
|
+
|
|
311
|
+
await deferred.promise
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('can close a stream for writing but receive a large amount of data', async function () {
|
|
315
|
+
const timeout = 120_000
|
|
316
|
+
this.timeout(timeout);
|
|
317
|
+
({ dialer, listener, dialAddrs } = await getSetup(common))
|
|
318
|
+
|
|
319
|
+
if (listener == null) {
|
|
320
|
+
return this.skip()
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const protocol = '/receive-data/1.0.0'
|
|
324
|
+
const chunkSize = 1024
|
|
325
|
+
const bytes = chunkSize * 1024 * 10
|
|
326
|
+
const deferred = pDefer()
|
|
327
|
+
|
|
328
|
+
await listener.handle(protocol, ({ stream }) => {
|
|
329
|
+
Promise.resolve().then(async () => {
|
|
330
|
+
await stream.sink((async function * () {
|
|
331
|
+
for (let i = 0; i < bytes; i += chunkSize) {
|
|
332
|
+
yield new Uint8Array(chunkSize)
|
|
333
|
+
}
|
|
334
|
+
})())
|
|
335
|
+
|
|
336
|
+
await stream.close()
|
|
337
|
+
})
|
|
338
|
+
.catch(err => {
|
|
339
|
+
deferred.reject(err)
|
|
340
|
+
stream.abort(err)
|
|
341
|
+
})
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
const stream = await dialer.dialProtocol(dialAddrs[0], protocol)
|
|
345
|
+
|
|
346
|
+
await stream.closeWrite()
|
|
347
|
+
|
|
348
|
+
let read = 0
|
|
349
|
+
|
|
350
|
+
for await (const buf of stream.source) {
|
|
351
|
+
read += buf.byteLength
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
expect(read).to.equal(bytes)
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
it('can close local stream for writing and reading while a remote stream is writing', async function () {
|
|
358
|
+
({ dialer, listener, dialAddrs } = await getSetup(common))
|
|
359
|
+
|
|
360
|
+
if (listener == null) {
|
|
361
|
+
return this.skip()
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* NodeA NodeB
|
|
366
|
+
* | <--- STOP_SENDING |
|
|
367
|
+
* | FIN ---> |
|
|
368
|
+
* | <--- FIN |
|
|
369
|
+
* | FIN_ACK ---> |
|
|
370
|
+
* | <--- FIN_ACK |
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
const getRemoteStream = pDefer<Stream>()
|
|
374
|
+
const protocol = '/close-local-while-remote-writes/1.0.0'
|
|
375
|
+
|
|
376
|
+
const streamHandler: StreamHandler = ({ stream }) => {
|
|
377
|
+
void Promise.resolve().then(async () => {
|
|
378
|
+
getRemoteStream.resolve(stream)
|
|
379
|
+
})
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
await listener.handle(protocol, (info) => {
|
|
383
|
+
streamHandler(info)
|
|
384
|
+
}, {
|
|
385
|
+
runOnLimitedConnection: true
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
const connection = await dialer.dial(dialAddrs[0])
|
|
389
|
+
|
|
390
|
+
// open a stream on the echo protocol
|
|
391
|
+
const stream = await connection.newStream(protocol, {
|
|
392
|
+
runOnLimitedConnection: true
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
// close the write end immediately
|
|
396
|
+
const p = stream.closeWrite()
|
|
397
|
+
|
|
398
|
+
const remoteStream = await getRemoteStream.promise
|
|
399
|
+
// close the readable end of the remote stream
|
|
400
|
+
await remoteStream.closeRead()
|
|
401
|
+
|
|
402
|
+
// keep the remote write end open, this should delay the FIN_ACK reply to the local stream
|
|
403
|
+
const remoteInputStream = pushable<Uint8Array>()
|
|
404
|
+
void remoteStream.sink(remoteInputStream)
|
|
405
|
+
|
|
406
|
+
// wait for remote to receive local close-write
|
|
407
|
+
await pRetry(() => {
|
|
408
|
+
if (remoteStream.readStatus !== 'closed') {
|
|
409
|
+
throw new Error('Remote stream read status ' + remoteStream.readStatus)
|
|
410
|
+
}
|
|
411
|
+
}, {
|
|
412
|
+
minTimeout: 100
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
// remote closes write
|
|
416
|
+
remoteInputStream.end()
|
|
417
|
+
|
|
418
|
+
// wait to receive FIN_ACK
|
|
419
|
+
await p
|
|
420
|
+
|
|
421
|
+
// wait for remote to notice closure
|
|
422
|
+
await pRetry(() => {
|
|
423
|
+
if (remoteStream.status !== 'closed') {
|
|
424
|
+
throw new Error('Remote stream not closed')
|
|
425
|
+
}
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
assertStreamClosed(stream)
|
|
429
|
+
assertStreamClosed(remoteStream)
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
it('can close local stream for writing and reading while a remote stream is writing using source/sink', async function () {
|
|
433
|
+
({ dialer, listener, dialAddrs } = await getSetup(common))
|
|
434
|
+
|
|
435
|
+
if (listener == null) {
|
|
436
|
+
return this.skip()
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* NodeA NodeB
|
|
441
|
+
* | FIN ---> |
|
|
442
|
+
* | <--- FIN |
|
|
443
|
+
* | FIN_ACK ---> |
|
|
444
|
+
* | <--- FIN_ACK |
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
const getRemoteStream = pDefer<Stream>()
|
|
448
|
+
const protocol = '/close-local-while-remote-reads/1.0.0'
|
|
449
|
+
|
|
450
|
+
const streamHandler: StreamHandler = ({ stream }) => {
|
|
451
|
+
void Promise.resolve().then(async () => {
|
|
452
|
+
getRemoteStream.resolve(stream)
|
|
453
|
+
})
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
await listener.handle(protocol, (info) => {
|
|
457
|
+
streamHandler(info)
|
|
458
|
+
}, {
|
|
459
|
+
runOnLimitedConnection: true
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
const connection = await dialer.dial(dialAddrs[0])
|
|
463
|
+
|
|
464
|
+
// open a stream on the echo protocol
|
|
465
|
+
const stream = await connection.newStream(protocol, {
|
|
466
|
+
runOnLimitedConnection: true
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
// keep the remote write end open, this should delay the FIN_ACK reply to the local stream
|
|
470
|
+
const p = stream.sink([])
|
|
471
|
+
|
|
472
|
+
const remoteStream = await getRemoteStream.promise
|
|
473
|
+
// close the readable end of the remote stream
|
|
474
|
+
await remoteStream.closeRead()
|
|
475
|
+
// readable end should finish
|
|
476
|
+
await drain(remoteStream.source)
|
|
477
|
+
|
|
478
|
+
// wait for remote to receive local close-write
|
|
479
|
+
await pRetry(() => {
|
|
480
|
+
if (remoteStream.readStatus !== 'closed') {
|
|
481
|
+
throw new Error('Remote stream read status ' + remoteStream.readStatus)
|
|
482
|
+
}
|
|
483
|
+
}, {
|
|
484
|
+
minTimeout: 100
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
// remote closes write
|
|
488
|
+
await remoteStream.sink([])
|
|
489
|
+
|
|
490
|
+
// wait to receive FIN_ACK
|
|
491
|
+
await p
|
|
492
|
+
|
|
493
|
+
// close read end of stream
|
|
494
|
+
await stream.closeRead()
|
|
495
|
+
// readable end should finish
|
|
496
|
+
await drain(stream.source)
|
|
497
|
+
|
|
498
|
+
// wait for remote to notice closure
|
|
499
|
+
await pRetry(() => {
|
|
500
|
+
if (remoteStream.status !== 'closed') {
|
|
501
|
+
throw new Error('Remote stream not closed')
|
|
502
|
+
}
|
|
503
|
+
})
|
|
504
|
+
|
|
505
|
+
assertStreamClosed(stream)
|
|
506
|
+
assertStreamClosed(remoteStream)
|
|
507
|
+
})
|
|
262
508
|
})
|
|
263
509
|
|
|
264
510
|
describe('events', () => {
|
|
@@ -323,3 +569,13 @@ export default (common: TestSetup<TransportTestFixtures>): void => {
|
|
|
323
569
|
})
|
|
324
570
|
})
|
|
325
571
|
}
|
|
572
|
+
|
|
573
|
+
function assertStreamClosed (stream: Stream): void {
|
|
574
|
+
expect(stream.status).to.equal('closed')
|
|
575
|
+
expect(stream.readStatus).to.equal('closed')
|
|
576
|
+
expect(stream.writeStatus).to.equal('closed')
|
|
577
|
+
|
|
578
|
+
expect(stream.timeline.close).to.be.a('number')
|
|
579
|
+
expect(stream.timeline.closeRead).to.be.a('number')
|
|
580
|
+
expect(stream.timeline.closeWrite).to.be.a('number')
|
|
581
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-gater.d.ts","sourceRoot":"","sources":["../../../src/mocks/connection-gater.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExD,wBAAgB,mBAAmB,IAAK,eAAe,CAetD"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function mockConnectionGater() {
|
|
2
|
-
return {
|
|
3
|
-
denyDialPeer: async () => Promise.resolve(false),
|
|
4
|
-
denyDialMultiaddr: async () => Promise.resolve(false),
|
|
5
|
-
denyInboundConnection: async () => Promise.resolve(false),
|
|
6
|
-
denyOutboundConnection: async () => Promise.resolve(false),
|
|
7
|
-
denyInboundEncryptedConnection: async () => Promise.resolve(false),
|
|
8
|
-
denyOutboundEncryptedConnection: async () => Promise.resolve(false),
|
|
9
|
-
denyInboundUpgradedConnection: async () => Promise.resolve(false),
|
|
10
|
-
denyOutboundUpgradedConnection: async () => Promise.resolve(false),
|
|
11
|
-
denyInboundRelayReservation: async () => Promise.resolve(false),
|
|
12
|
-
denyOutboundRelayedConnection: async () => Promise.resolve(false),
|
|
13
|
-
denyInboundRelayedConnection: async () => Promise.resolve(false),
|
|
14
|
-
filterMultiaddrForPeer: async () => Promise.resolve(true)
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=connection-gater.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-gater.js","sourceRoot":"","sources":["../../../src/mocks/connection-gater.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAChD,iBAAiB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACrD,qBAAqB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACzD,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1D,8BAA8B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAClE,+BAA+B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACnE,6BAA6B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACjE,8BAA8B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAClE,2BAA2B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAC/D,6BAA6B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACjE,4BAA4B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAChE,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;KAC1D,CAAA;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/mocks/metrics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA2E,OAAO,EAAoL,MAAM,mBAAmB,CAAA;AA6X3S,wBAAgB,WAAW,IAAK,MAAM,OAAO,CAE5C"}
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { TDigest } from 'tdigest';
|
|
2
|
-
class DefaultMetric {
|
|
3
|
-
value = 0;
|
|
4
|
-
update(value) {
|
|
5
|
-
this.value = value;
|
|
6
|
-
}
|
|
7
|
-
increment(value = 1) {
|
|
8
|
-
this.value += value;
|
|
9
|
-
}
|
|
10
|
-
decrement(value = 1) {
|
|
11
|
-
this.value -= value;
|
|
12
|
-
}
|
|
13
|
-
reset() {
|
|
14
|
-
this.value = 0;
|
|
15
|
-
}
|
|
16
|
-
timer() {
|
|
17
|
-
const start = Date.now();
|
|
18
|
-
return () => {
|
|
19
|
-
this.value = Date.now() - start;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
class DefaultGroupMetric {
|
|
24
|
-
values = {};
|
|
25
|
-
update(values) {
|
|
26
|
-
Object.entries(values).forEach(([key, value]) => {
|
|
27
|
-
this.values[key] = value;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
increment(values) {
|
|
31
|
-
Object.entries(values).forEach(([key, value]) => {
|
|
32
|
-
this.values[key] = this.values[key] ?? 0;
|
|
33
|
-
const inc = typeof value === 'number' ? value : 1;
|
|
34
|
-
this.values[key] += Number(inc);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
decrement(values) {
|
|
38
|
-
Object.entries(values).forEach(([key, value]) => {
|
|
39
|
-
this.values[key] = this.values[key] ?? 0;
|
|
40
|
-
const dec = typeof value === 'number' ? value : 1;
|
|
41
|
-
this.values[key] -= Number(dec);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
reset() {
|
|
45
|
-
this.values = {};
|
|
46
|
-
}
|
|
47
|
-
timer(key) {
|
|
48
|
-
const start = Date.now();
|
|
49
|
-
return () => {
|
|
50
|
-
this.values[key] = Date.now() - start;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
class DefaultHistogram {
|
|
55
|
-
bucketValues = new Map();
|
|
56
|
-
countValue = 0;
|
|
57
|
-
sumValue = 0;
|
|
58
|
-
constructor(opts) {
|
|
59
|
-
const buckets = [
|
|
60
|
-
...(opts.buckets ?? [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]),
|
|
61
|
-
Infinity
|
|
62
|
-
];
|
|
63
|
-
for (const bucket of buckets) {
|
|
64
|
-
this.bucketValues.set(bucket, 0);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
observe(value) {
|
|
68
|
-
this.countValue++;
|
|
69
|
-
this.sumValue += value;
|
|
70
|
-
for (const [bucket, count] of this.bucketValues.entries()) {
|
|
71
|
-
if (value <= bucket) {
|
|
72
|
-
this.bucketValues.set(bucket, count + 1);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
reset() {
|
|
77
|
-
this.countValue = 0;
|
|
78
|
-
this.sumValue = 0;
|
|
79
|
-
for (const bucket of this.bucketValues.keys()) {
|
|
80
|
-
this.bucketValues.set(bucket, 0);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
timer() {
|
|
84
|
-
const start = Date.now();
|
|
85
|
-
return () => {
|
|
86
|
-
this.observe(Date.now() - start);
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
class DefaultHistogramGroup {
|
|
91
|
-
histograms = {};
|
|
92
|
-
constructor(opts) {
|
|
93
|
-
this.histograms = {};
|
|
94
|
-
}
|
|
95
|
-
observe(values) {
|
|
96
|
-
for (const [key, value] of Object.entries(values)) {
|
|
97
|
-
if (this.histograms[key] === undefined) {
|
|
98
|
-
this.histograms[key] = new DefaultHistogram({});
|
|
99
|
-
}
|
|
100
|
-
this.histograms[key].observe(value);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
reset() {
|
|
104
|
-
for (const histogram of Object.values(this.histograms)) {
|
|
105
|
-
histogram.reset();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
timer(key) {
|
|
109
|
-
const start = Date.now();
|
|
110
|
-
return () => {
|
|
111
|
-
this.observe({ [key]: Date.now() - start });
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
class DefaultSummary {
|
|
116
|
-
sumValue = 0;
|
|
117
|
-
countValue = 0;
|
|
118
|
-
percentiles;
|
|
119
|
-
tdigest = new TDigest(0.01);
|
|
120
|
-
compressCount;
|
|
121
|
-
constructor(opts) {
|
|
122
|
-
this.percentiles = opts.percentiles ?? [0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999];
|
|
123
|
-
this.compressCount = opts.compressCount ?? 1000;
|
|
124
|
-
}
|
|
125
|
-
observe(value) {
|
|
126
|
-
this.sumValue += value;
|
|
127
|
-
this.countValue++;
|
|
128
|
-
this.tdigest.push(value);
|
|
129
|
-
if (this.tdigest.size() > this.compressCount) {
|
|
130
|
-
this.tdigest.compress();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
reset() {
|
|
134
|
-
this.sumValue = 0;
|
|
135
|
-
this.countValue = 0;
|
|
136
|
-
this.tdigest.reset();
|
|
137
|
-
}
|
|
138
|
-
timer() {
|
|
139
|
-
const start = Date.now();
|
|
140
|
-
return () => {
|
|
141
|
-
this.observe(Date.now() - start);
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
class DefaultSummaryGroup {
|
|
146
|
-
summaries = {};
|
|
147
|
-
opts;
|
|
148
|
-
constructor(opts) {
|
|
149
|
-
this.summaries = {};
|
|
150
|
-
this.opts = opts;
|
|
151
|
-
}
|
|
152
|
-
observe(values) {
|
|
153
|
-
for (const [key, value] of Object.entries(values)) {
|
|
154
|
-
if (this.summaries[key] === undefined) {
|
|
155
|
-
this.summaries[key] = new DefaultSummary(this.opts);
|
|
156
|
-
}
|
|
157
|
-
this.summaries[key].observe(value);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
reset() {
|
|
161
|
-
for (const summary of Object.values(this.summaries)) {
|
|
162
|
-
summary.reset();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
timer(key) {
|
|
166
|
-
const start = Date.now();
|
|
167
|
-
return () => {
|
|
168
|
-
this.observe({ [key]: Date.now() - start });
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
class MockMetrics {
|
|
173
|
-
metrics = new Map();
|
|
174
|
-
trackMultiaddrConnection(maConn) {
|
|
175
|
-
}
|
|
176
|
-
trackProtocolStream(stream, connection) {
|
|
177
|
-
}
|
|
178
|
-
registerMetric(name, opts) {
|
|
179
|
-
if (name == null || name.trim() === '') {
|
|
180
|
-
throw new Error('Metric name is required');
|
|
181
|
-
}
|
|
182
|
-
if (opts?.calculate != null) {
|
|
183
|
-
// calculated metric
|
|
184
|
-
this.metrics.set(name, opts.calculate);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const metric = new DefaultMetric();
|
|
188
|
-
this.metrics.set(name, metric);
|
|
189
|
-
return metric;
|
|
190
|
-
}
|
|
191
|
-
registerCounter(name, opts) {
|
|
192
|
-
if (name == null || name.trim() === '') {
|
|
193
|
-
throw new Error('Metric name is required');
|
|
194
|
-
}
|
|
195
|
-
if (opts?.calculate != null) {
|
|
196
|
-
// calculated metric
|
|
197
|
-
this.metrics.set(name, opts.calculate);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const metric = new DefaultMetric();
|
|
201
|
-
this.metrics.set(name, metric);
|
|
202
|
-
return metric;
|
|
203
|
-
}
|
|
204
|
-
registerMetricGroup(name, opts) {
|
|
205
|
-
if (name == null || name.trim() === '') {
|
|
206
|
-
throw new Error('Metric name is required');
|
|
207
|
-
}
|
|
208
|
-
if (opts?.calculate != null) {
|
|
209
|
-
// calculated metric
|
|
210
|
-
this.metrics.set(name, opts.calculate);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const metric = new DefaultGroupMetric();
|
|
214
|
-
this.metrics.set(name, metric);
|
|
215
|
-
return metric;
|
|
216
|
-
}
|
|
217
|
-
registerCounterGroup(name, opts) {
|
|
218
|
-
if (name == null || name.trim() === '') {
|
|
219
|
-
throw new Error('Metric name is required');
|
|
220
|
-
}
|
|
221
|
-
if (opts?.calculate != null) {
|
|
222
|
-
// calculated metric
|
|
223
|
-
this.metrics.set(name, opts.calculate);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
const metric = new DefaultGroupMetric();
|
|
227
|
-
this.metrics.set(name, metric);
|
|
228
|
-
return metric;
|
|
229
|
-
}
|
|
230
|
-
registerHistogram(name, opts = {}) {
|
|
231
|
-
if (name == null || name.trim() === '') {
|
|
232
|
-
throw new Error('Metric name is required');
|
|
233
|
-
}
|
|
234
|
-
if (opts?.calculate != null) {
|
|
235
|
-
// calculated metric
|
|
236
|
-
this.metrics.set(name, opts.calculate);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
const metric = new DefaultHistogram(opts);
|
|
240
|
-
this.metrics.set(name, metric);
|
|
241
|
-
return metric;
|
|
242
|
-
}
|
|
243
|
-
registerHistogramGroup(name, opts = {}) {
|
|
244
|
-
if (name == null || name.trim() === '') {
|
|
245
|
-
throw new Error('Metric name is required');
|
|
246
|
-
}
|
|
247
|
-
if (opts?.calculate != null) {
|
|
248
|
-
// calculated metric
|
|
249
|
-
this.metrics.set(name, opts.calculate);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const metric = new DefaultHistogramGroup(opts);
|
|
253
|
-
this.metrics.set(name, metric);
|
|
254
|
-
return metric;
|
|
255
|
-
}
|
|
256
|
-
registerSummary(name, opts = {}) {
|
|
257
|
-
if (name == null || name.trim() === '') {
|
|
258
|
-
throw new Error('Metric name is required');
|
|
259
|
-
}
|
|
260
|
-
if (opts?.calculate != null) {
|
|
261
|
-
// calculated metric
|
|
262
|
-
this.metrics.set(name, opts.calculate);
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
const metric = new DefaultSummary(opts);
|
|
266
|
-
this.metrics.set(name, metric);
|
|
267
|
-
return metric;
|
|
268
|
-
}
|
|
269
|
-
registerSummaryGroup(name, opts = {}) {
|
|
270
|
-
if (name == null || name.trim() === '') {
|
|
271
|
-
throw new Error('Metric name is required');
|
|
272
|
-
}
|
|
273
|
-
if (opts?.calculate != null) {
|
|
274
|
-
// calculated metric
|
|
275
|
-
this.metrics.set(name, opts.calculate);
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const metric = new DefaultSummaryGroup(opts);
|
|
279
|
-
this.metrics.set(name, metric);
|
|
280
|
-
return metric;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
export function mockMetrics() {
|
|
284
|
-
return () => new MockMetrics();
|
|
285
|
-
}
|
|
286
|
-
//# sourceMappingURL=metrics.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/mocks/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGjC,MAAM,aAAa;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AyB,CAAC,CAAA;QAC5C,CAAC;QAED,IAAI,IAAI,EAAE,SAAS,IAAI,IAAI,EAAE,CAAC;YAC5B,oBAAoB;YACpB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;YACtC,OAAM;QACR,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;QACvC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAE9B,OAAO,MAAM,CAAA;IACf,CAAC;IAID,oBAAoB,CAAE,IAAY,EAAE,OAAY,EAAE;QAChD,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;QAC5C,CAAC;QAED,IAAI,IAAI,EAAE,SAAS,IAAI,IAAI,EAAE,CAAC;YAC5B,oBAAoB;YACpB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;YACtC,OAAM;QACR,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAE9B,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,GAAG,EAAE,CAAC,IAAI,WAAW,EAAE,CAAA;AAChC,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { TypedEventEmitter, peerDiscoverySymbol } from '@libp2p/interface';
|
|
2
|
-
import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface';
|
|
3
|
-
interface MockDiscoveryInit {
|
|
4
|
-
discoveryDelay?: number;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Emits 'peer' events on discovery.
|
|
8
|
-
*/
|
|
9
|
-
export declare class MockDiscovery extends TypedEventEmitter<PeerDiscoveryEvents> implements PeerDiscovery {
|
|
10
|
-
readonly options: MockDiscoveryInit;
|
|
11
|
-
private _isRunning;
|
|
12
|
-
private _timer;
|
|
13
|
-
constructor(init?: {});
|
|
14
|
-
readonly [peerDiscoverySymbol]: this;
|
|
15
|
-
start(): void;
|
|
16
|
-
stop(): void;
|
|
17
|
-
isStarted(): boolean;
|
|
18
|
-
_discoverPeer(): void;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=peer-discovery.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"peer-discovery.d.ts","sourceRoot":"","sources":["../../../src/mocks/peer-discovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAG1E,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAY,MAAM,mBAAmB,CAAA;AAErF,UAAU,iBAAiB;IACzB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,iBAAiB,CAAC,mBAAmB,CAAE,YAAW,aAAa;IAChG,SAAgB,OAAO,EAAE,iBAAiB,CAAA;IAC1C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAK;gBAEN,IAAI,KAAK;IAOtB,QAAQ,CAAC,CAAC,mBAAmB,CAAC,OAAO;IAErC,KAAK,IAAK,IAAI;IAKd,IAAI,IAAK,IAAI;IAKb,SAAS,IAAK,OAAO;IAIrB,aAAa,IAAK,IAAI;CAiBvB"}
|