hypercore 10.37.18 → 10.37.20

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/index.js CHANGED
@@ -26,7 +26,8 @@ const {
26
26
  BAD_ARGUMENT,
27
27
  SESSION_CLOSED,
28
28
  SESSION_NOT_WRITABLE,
29
- SNAPSHOT_NOT_AVAILABLE
29
+ SNAPSHOT_NOT_AVAILABLE,
30
+ DECODING_ERROR
30
31
  } = require('hypercore-errors')
31
32
 
32
33
  const promises = Symbol.for('hypercore.promises')
@@ -1108,7 +1109,11 @@ module.exports = class Hypercore extends EventEmitter {
1108
1109
 
1109
1110
  _decode (enc, block) {
1110
1111
  if (this.padding) block = block.subarray(this.padding)
1111
- if (enc) return c.decode(enc, block)
1112
+ try {
1113
+ if (enc) return c.decode(enc, block)
1114
+ } catch {
1115
+ throw DECODING_ERROR()
1116
+ }
1112
1117
  return block
1113
1118
  }
1114
1119
  }
package/lib/replicator.js CHANGED
@@ -358,6 +358,18 @@ class Peer {
358
358
  this.wireRange = this.channel.messages[8]
359
359
  this.wireExtension = this.channel.messages[9]
360
360
 
361
+ // Same stats as replicator, but for this specific peer
362
+ this.stats = {
363
+ wireSync: { tx: 0, rx: 0 },
364
+ wireRequest: { tx: 0, rx: 0 },
365
+ wireCancel: { tx: 0, rx: 0 },
366
+ wireData: { tx: 0, rx: 0 },
367
+ wireWant: { tx: 0, rx: 0 },
368
+ wireBitfield: { tx: 0, rx: 0 },
369
+ wireRange: { tx: 0, rx: 0 },
370
+ wireExtension: { tx: 0, rx: 0 }
371
+ }
372
+
361
373
  this.receiverQueue = new ReceiverQueue()
362
374
  this.receiverBusy = false
363
375
 
@@ -446,10 +458,12 @@ class Peer {
446
458
  start,
447
459
  length
448
460
  })
461
+ incrementTx(this.stats.wireRange, this.replicator.stats.wireRange)
449
462
  }
450
463
 
451
464
  extension (name, message) {
452
465
  this.wireExtension.send({ name: name === this.lastExtensionSent ? '' : name, message })
466
+ incrementTx(this.stats.wireExtension, this.replicator.stats.wireExtension)
453
467
  this.lastExtensionSent = name
454
468
  }
455
469
 
@@ -481,6 +495,7 @@ class Peer {
481
495
  downloading: this.replicator.isDownloading(),
482
496
  hasManifest: !!this.core.header.manifest && this.core.compat === false
483
497
  })
498
+ incrementTx(this.stats.wireSync, this.replicator.stats.wireSync)
484
499
  }
485
500
 
486
501
  onopen ({ seeks, capability }) {
@@ -730,6 +745,7 @@ class Peer {
730
745
  if (msg.manifest && this.core.header.manifest) {
731
746
  const manifest = this.core.header.manifest
732
747
  this.wireData.send({ request: msg.id, fork: this.core.tree.fork, block: null, hash: null, seek: null, upgrade: null, manifest })
748
+ incrementTx(this.stats.wireData, this.replicator.stats.wireData)
733
749
  return
734
750
  }
735
751
 
@@ -750,6 +766,7 @@ class Peer {
750
766
  upgrade: proof.upgrade,
751
767
  manifest: proof.manifest
752
768
  })
769
+ incrementTx(this.stats.wireData, this.replicator.stats.wireData)
753
770
  }
754
771
 
755
772
  _cancelRequest (req) {
@@ -767,6 +784,7 @@ class Peer {
767
784
  if (this.roundtripQueue === null) this.roundtripQueue = new RoundtripQueue()
768
785
  this.roundtripQueue.add(req.id)
769
786
  this.wireCancel.send({ request: req.id })
787
+ incrementTx(this.stats.wireCancel, this.replicator.stats.wireCancel)
770
788
  }
771
789
 
772
790
  _checkIfConflict () {
@@ -786,6 +804,8 @@ class Peer {
786
804
  length
787
805
  }
788
806
  })
807
+
808
+ incrementTx(this.stats.wireRequest, this.replicator.stats.wireRequest)
789
809
  }
790
810
 
791
811
  async ondata (data) {
@@ -1328,6 +1348,7 @@ class Peer {
1328
1348
  start: i * DEFAULT_SEGMENT_SIZE,
1329
1349
  length: DEFAULT_SEGMENT_SIZE
1330
1350
  })
1351
+ incrementTx(this.stats.wireWant, this.replicator.stats.wireWant)
1331
1352
  }
1332
1353
  }
1333
1354
 
@@ -1371,6 +1392,7 @@ class Peer {
1371
1392
  this.tracer.trace('send', req)
1372
1393
 
1373
1394
  this.wireRequest.send(req)
1395
+ incrementTx(this.stats.wireRequest, this.replicator.stats.wireRequest)
1374
1396
  }
1375
1397
  }
1376
1398
 
@@ -1404,6 +1426,19 @@ module.exports = class Replicator {
1404
1426
 
1405
1427
  this.inflightRange = inflightRange || DEFAULT_MAX_INFLIGHT
1406
1428
 
1429
+ // Note: nodata and unwant not currently tracked
1430
+ // tx = transmitted, rx = received
1431
+ this.stats = {
1432
+ wireSync: { tx: 0, rx: 0 },
1433
+ wireRequest: { tx: 0, rx: 0 },
1434
+ wireCancel: { tx: 0, rx: 0 },
1435
+ wireData: { tx: 0, rx: 0 },
1436
+ wireWant: { tx: 0, rx: 0 },
1437
+ wireBitfield: { tx: 0, rx: 0 },
1438
+ wireRange: { tx: 0, rx: 0 },
1439
+ wireExtension: { tx: 0, rx: 0 }
1440
+ }
1441
+
1407
1442
  this._attached = new Set()
1408
1443
  this._inflight = new InflightTracker()
1409
1444
  this._blocks = new BlockTracker()
@@ -2005,6 +2040,7 @@ module.exports = class Replicator {
2005
2040
  start: 0,
2006
2041
  length: contig
2007
2042
  })
2043
+ incrementTx(peer.stats.wireRange, this.stats.wireRange)
2008
2044
  return
2009
2045
  }
2010
2046
 
@@ -2014,6 +2050,7 @@ module.exports = class Replicator {
2014
2050
 
2015
2051
  for (const msg of this.core.bitfield.want(start, length)) {
2016
2052
  peer.wireBitfield.send(msg)
2053
+ incrementTx(peer.stats.wireBitfield, this.stats.wireBitfield)
2017
2054
  }
2018
2055
 
2019
2056
  peer.protomux.uncork()
@@ -2387,18 +2424,22 @@ function onwiredrain (c) {
2387
2424
  }
2388
2425
 
2389
2426
  function onwiresync (m, c) {
2427
+ incrementRx(c.userData.stats.wireSync, c.userData.replicator.stats.wireSync)
2390
2428
  return c.userData.onsync(m)
2391
2429
  }
2392
2430
 
2393
2431
  function onwirerequest (m, c) {
2432
+ incrementRx(c.userData.stats.wireRequest, c.userData.replicator.stats.wireRequest)
2394
2433
  return c.userData.onrequest(m)
2395
2434
  }
2396
2435
 
2397
2436
  function onwirecancel (m, c) {
2437
+ incrementRx(c.userData.stats.wireCancel, c.userData.replicator.stats.wireCancel)
2398
2438
  return c.userData.oncancel(m)
2399
2439
  }
2400
2440
 
2401
2441
  function onwiredata (m, c) {
2442
+ incrementRx(c.userData.stats.wireData, c.userData.replicator.stats.wireData)
2402
2443
  return c.userData.ondata(m)
2403
2444
  }
2404
2445
 
@@ -2407,6 +2448,7 @@ function onwirenodata (m, c) {
2407
2448
  }
2408
2449
 
2409
2450
  function onwirewant (m, c) {
2451
+ incrementRx(c.userData.stats.wireWant, c.userData.replicator.stats.wireWant)
2410
2452
  return c.userData.onwant(m)
2411
2453
  }
2412
2454
 
@@ -2415,14 +2457,17 @@ function onwireunwant (m, c) {
2415
2457
  }
2416
2458
 
2417
2459
  function onwirebitfield (m, c) {
2460
+ incrementRx(c.userData.stats.wireBitfield, c.userData.replicator.stats.wireBitfield)
2418
2461
  return c.userData.onbitfield(m)
2419
2462
  }
2420
2463
 
2421
2464
  function onwirerange (m, c) {
2465
+ incrementRx(c.userData.stats.wireRange, c.userData.replicator.stats.wireRange)
2422
2466
  return c.userData.onrange(m)
2423
2467
  }
2424
2468
 
2425
2469
  function onwireextension (m, c) {
2470
+ incrementRx(c.userData.stats.wireExtension, c.userData.replicator.stats.wireExtension)
2426
2471
  return c.userData.onextension(m)
2427
2472
  }
2428
2473
 
@@ -2437,3 +2482,13 @@ function isBlockRequest (req) {
2437
2482
  function isUpgradeRequest (req) {
2438
2483
  return req !== null && req.upgrade !== null
2439
2484
  }
2485
+
2486
+ function incrementTx (stats1, stats2) {
2487
+ stats1.tx++
2488
+ stats2.tx++
2489
+ }
2490
+
2491
+ function incrementRx (stats1, stats2) {
2492
+ stats1.rx++
2493
+ stats2.rx++
2494
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.37.18",
3
+ "version": "10.37.20",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {