hypercore 10.37.24 → 10.37.26
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 +1 -11
- package/lib/core.js +0 -2
- package/lib/replicator.js +26 -17
- package/package.json +1 -2
package/index.js
CHANGED
|
@@ -10,7 +10,6 @@ const Protomux = require('protomux')
|
|
|
10
10
|
const z32 = require('z32')
|
|
11
11
|
const id = require('hypercore-id-encoding')
|
|
12
12
|
const safetyCatch = require('safety-catch')
|
|
13
|
-
const { createTracer } = require('hypertrace')
|
|
14
13
|
const unslab = require('unslab')
|
|
15
14
|
|
|
16
15
|
const Replicator = require('./lib/replicator')
|
|
@@ -57,7 +56,6 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
57
56
|
|
|
58
57
|
this[promises] = true
|
|
59
58
|
|
|
60
|
-
this.tracer = createTracer(this)
|
|
61
59
|
this.storage = null
|
|
62
60
|
this.crypto = opts.crypto || hypercoreCrypto
|
|
63
61
|
this.core = null
|
|
@@ -290,8 +288,6 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
290
288
|
this.writable = this._isWritable()
|
|
291
289
|
this.autoClose = o.autoClose
|
|
292
290
|
|
|
293
|
-
if (o.core) this.tracer.setParent(o.core.tracer)
|
|
294
|
-
|
|
295
291
|
if (this.snapshotted && this.core && !this._snapshot) this._updateSnapshot()
|
|
296
292
|
}
|
|
297
293
|
|
|
@@ -402,7 +398,6 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
402
398
|
onupdate: this._oncoreupdate.bind(this),
|
|
403
399
|
onconflict: this._oncoreconflict.bind(this)
|
|
404
400
|
})
|
|
405
|
-
this.tracer.setParent(this.core.tracer)
|
|
406
401
|
|
|
407
402
|
if (opts.userData) {
|
|
408
403
|
for (const [key, value] of Object.entries(opts.userData)) {
|
|
@@ -503,7 +498,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
503
498
|
}
|
|
504
499
|
|
|
505
500
|
if (this.replicator !== null) {
|
|
506
|
-
this.replicator.destroy()
|
|
501
|
+
await this.replicator.destroy()
|
|
507
502
|
}
|
|
508
503
|
|
|
509
504
|
await this.core.close()
|
|
@@ -841,8 +836,6 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
841
836
|
if (this.opened === false) await this.opening
|
|
842
837
|
if (!isValidIndex(index)) throw ASSERTION('block index is invalid')
|
|
843
838
|
|
|
844
|
-
this.tracer.trace('get', { index })
|
|
845
|
-
|
|
846
839
|
if (this.closing !== null) throw SESSION_CLOSED()
|
|
847
840
|
if (this._snapshot !== null && index >= this._snapshot.compatLength) throw SNAPSHOT_NOT_AVAILABLE()
|
|
848
841
|
|
|
@@ -967,8 +960,6 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
967
960
|
async _download (range) {
|
|
968
961
|
if (this.opened === false) await this.opening
|
|
969
962
|
|
|
970
|
-
this.tracer.trace('download', { range })
|
|
971
|
-
|
|
972
963
|
const activeRequests = (range && range.activeRequests) || this.activeRequests
|
|
973
964
|
|
|
974
965
|
return this.replicator.addRange(activeRequests, range)
|
|
@@ -1011,7 +1002,6 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
1011
1002
|
if (writable === false) throw SESSION_NOT_WRITABLE()
|
|
1012
1003
|
|
|
1013
1004
|
blocks = Array.isArray(blocks) ? blocks : [blocks]
|
|
1014
|
-
this.tracer.trace('append', { blocks })
|
|
1015
1005
|
|
|
1016
1006
|
const preappend = this.encryption && this._preappend
|
|
1017
1007
|
|
package/lib/core.js
CHANGED
|
@@ -13,11 +13,9 @@ const { BAD_ARGUMENT, STORAGE_EMPTY, STORAGE_CONFLICT, INVALID_OPERATION, INVALI
|
|
|
13
13
|
const m = require('./messages')
|
|
14
14
|
const Verifier = require('./verifier')
|
|
15
15
|
const audit = require('./audit')
|
|
16
|
-
const { createTracer } = require('hypertrace')
|
|
17
16
|
|
|
18
17
|
module.exports = class Core {
|
|
19
18
|
constructor (header, compat, crypto, oplog, bigHeader, tree, blocks, bitfield, verifier, sessions, legacy, globalCache, onupdate, onconflict) {
|
|
20
|
-
this.tracer = createTracer(this)
|
|
21
19
|
this.onupdate = onupdate
|
|
22
20
|
this.onconflict = onconflict
|
|
23
21
|
this.preupdate = null
|
package/lib/replicator.js
CHANGED
|
@@ -31,7 +31,6 @@ const RemoteBitfield = require('./remote-bitfield')
|
|
|
31
31
|
const { REQUEST_CANCELLED, REQUEST_TIMEOUT, INVALID_CAPABILITY, SNAPSHOT_NOT_AVAILABLE } = require('hypercore-errors')
|
|
32
32
|
const m = require('./messages')
|
|
33
33
|
const caps = require('./caps')
|
|
34
|
-
const { createTracer } = require('hypertrace')
|
|
35
34
|
|
|
36
35
|
const DEFAULT_MAX_INFLIGHT = [16, 512]
|
|
37
36
|
const SCALE_LATENCY = 50
|
|
@@ -39,6 +38,8 @@ const DEFAULT_SEGMENT_SIZE = 256 * 1024 * 8 // 256 KiB in bits
|
|
|
39
38
|
const NOT_DOWNLOADING_SLACK = 20000 + (Math.random() * 20000) | 0
|
|
40
39
|
const MAX_PEERS_UPGRADE = 3
|
|
41
40
|
|
|
41
|
+
const MAX_RANGES = 64
|
|
42
|
+
|
|
42
43
|
const PRIORITY = {
|
|
43
44
|
NORMAL: 0,
|
|
44
45
|
HIGH: 1,
|
|
@@ -331,7 +332,6 @@ class RoundtripQueue {
|
|
|
331
332
|
|
|
332
333
|
class Peer {
|
|
333
334
|
constructor (replicator, protomux, channel, useSession, inflightRange) {
|
|
334
|
-
this.tracer = createTracer(this, { parent: replicator.core.tracer })
|
|
335
335
|
this.core = replicator.core
|
|
336
336
|
this.replicator = replicator
|
|
337
337
|
this.stream = protomux.stream
|
|
@@ -530,8 +530,6 @@ class Peer {
|
|
|
530
530
|
}
|
|
531
531
|
|
|
532
532
|
onclose (isRemote) {
|
|
533
|
-
this.tracer.trace('onclose')
|
|
534
|
-
|
|
535
533
|
// we might have signalled to the remote that we are done (ie not downloading) and the remote might agree on that
|
|
536
534
|
// if that happens, the channel might be closed by the remote. if so just renegotiate it.
|
|
537
535
|
// TODO: add a CLOSE_REASON to mux to we can make this cleaner...
|
|
@@ -682,8 +680,6 @@ class Peer {
|
|
|
682
680
|
}
|
|
683
681
|
|
|
684
682
|
async onrequest (msg) {
|
|
685
|
-
this.tracer.trace('onrequest', msg)
|
|
686
|
-
|
|
687
683
|
const size = this.remoteRequests.size
|
|
688
684
|
this.remoteRequests.set(msg.id, msg)
|
|
689
685
|
|
|
@@ -817,8 +813,6 @@ class Peer {
|
|
|
817
813
|
}
|
|
818
814
|
|
|
819
815
|
async ondata (data) {
|
|
820
|
-
this.tracer.trace('ondata', data)
|
|
821
|
-
|
|
822
816
|
// always allow a fork conflict proof to be sent
|
|
823
817
|
if (data.request === 0 && data.upgrade && data.upgrade.start === 0) {
|
|
824
818
|
if (await this.core.checkConflict(data, this)) return
|
|
@@ -888,8 +882,6 @@ class Peer {
|
|
|
888
882
|
}
|
|
889
883
|
|
|
890
884
|
onnodata ({ request }) {
|
|
891
|
-
this.tracer.trace('onnodata', { request })
|
|
892
|
-
|
|
893
885
|
const req = request > 0 ? this.replicator._inflight.get(request) : null
|
|
894
886
|
|
|
895
887
|
if (req === null || req.peer !== this) return
|
|
@@ -1397,8 +1389,6 @@ class Peer {
|
|
|
1397
1389
|
return
|
|
1398
1390
|
}
|
|
1399
1391
|
|
|
1400
|
-
this.tracer.trace('send', req)
|
|
1401
|
-
|
|
1402
1392
|
this.wireRequest.send(req)
|
|
1403
1393
|
incrementTx(this.stats.wireRequest, this.replicator.stats.wireRequest)
|
|
1404
1394
|
}
|
|
@@ -1416,7 +1406,6 @@ module.exports = class Replicator {
|
|
|
1416
1406
|
onupload = noop,
|
|
1417
1407
|
oninvalid = noop
|
|
1418
1408
|
} = {}) {
|
|
1419
|
-
this.tracer = createTracer(this)
|
|
1420
1409
|
this.key = key
|
|
1421
1410
|
this.discoveryKey = core.crypto.discoveryKey(key)
|
|
1422
1411
|
this.core = core
|
|
@@ -1636,11 +1625,18 @@ module.exports = class Replicator {
|
|
|
1636
1625
|
|
|
1637
1626
|
const ref = r.attach(session)
|
|
1638
1627
|
|
|
1639
|
-
this._ranges.push(r)
|
|
1640
|
-
|
|
1641
1628
|
// Trigger this to see if this is already resolved...
|
|
1642
1629
|
// Also auto compresses the range based on local bitfield
|
|
1643
|
-
this.
|
|
1630
|
+
clampRange(this.core, r)
|
|
1631
|
+
|
|
1632
|
+
this._ranges.push(r)
|
|
1633
|
+
|
|
1634
|
+
if (r.end !== -1 && r.start >= r.end) {
|
|
1635
|
+
this._resolveRangeRequest(r, this._ranges.length - 1)
|
|
1636
|
+
return ref
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
this.updateAll()
|
|
1644
1640
|
|
|
1645
1641
|
return ref
|
|
1646
1642
|
}
|
|
@@ -1912,13 +1908,16 @@ module.exports = class Replicator {
|
|
|
1912
1908
|
async _updateNonPrimary (updateAll) {
|
|
1913
1909
|
// Check if running, if so skip it and the running one will issue another update for us (debounce)
|
|
1914
1910
|
while (++this._updatesPending === 1) {
|
|
1915
|
-
|
|
1911
|
+
let len = Math.min(MAX_RANGES, this._ranges.length)
|
|
1912
|
+
|
|
1913
|
+
for (let i = 0; i < len; i++) {
|
|
1916
1914
|
const r = this._ranges[i]
|
|
1917
1915
|
|
|
1918
1916
|
clampRange(this.core, r)
|
|
1919
1917
|
|
|
1920
1918
|
if (r.end !== -1 && r.start >= r.end) {
|
|
1921
1919
|
this._resolveRangeRequest(r, i--)
|
|
1920
|
+
if (len > this._ranges.length) len--
|
|
1922
1921
|
}
|
|
1923
1922
|
}
|
|
1924
1923
|
|
|
@@ -2200,11 +2199,13 @@ module.exports = class Replicator {
|
|
|
2200
2199
|
}
|
|
2201
2200
|
|
|
2202
2201
|
const ranges = new RandomIterator(this._ranges)
|
|
2202
|
+
let tried = 0
|
|
2203
2203
|
|
|
2204
2204
|
for (const r of ranges) {
|
|
2205
2205
|
if (peer._requestRange(r) === true) {
|
|
2206
2206
|
return true
|
|
2207
2207
|
}
|
|
2208
|
+
if (++tried >= MAX_RANGES) break
|
|
2208
2209
|
}
|
|
2209
2210
|
|
|
2210
2211
|
// Iterate from newest fork to oldest fork...
|
|
@@ -2323,18 +2324,26 @@ module.exports = class Replicator {
|
|
|
2323
2324
|
|
|
2324
2325
|
destroy () {
|
|
2325
2326
|
this.destroyed = true
|
|
2327
|
+
|
|
2326
2328
|
if (this._downloadingTimer) {
|
|
2327
2329
|
clearTimeout(this._downloadingTimer)
|
|
2328
2330
|
this._downloadingTimer = null
|
|
2329
2331
|
}
|
|
2332
|
+
|
|
2333
|
+
const waiting = []
|
|
2334
|
+
|
|
2330
2335
|
while (this.peers.length) {
|
|
2331
2336
|
const peer = this.peers[this.peers.length - 1]
|
|
2332
2337
|
this.detachFrom(peer.protomux)
|
|
2333
2338
|
peer.channel.close() // peer is removed from array in onclose
|
|
2339
|
+
waiting.push(peer.channel.fullyClosed())
|
|
2334
2340
|
}
|
|
2341
|
+
|
|
2335
2342
|
for (const protomux of this._attached) {
|
|
2336
2343
|
this.detachFrom(protomux)
|
|
2337
2344
|
}
|
|
2345
|
+
|
|
2346
|
+
return Promise.all(waiting)
|
|
2338
2347
|
}
|
|
2339
2348
|
|
|
2340
2349
|
_makePeer (protomux, useSession) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore",
|
|
3
|
-
"version": "10.37.
|
|
3
|
+
"version": "10.37.26",
|
|
4
4
|
"description": "Hypercore is a secure, distributed append-only log",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"hypercore-crypto": "^3.2.1",
|
|
53
53
|
"hypercore-errors": "^1.2.0",
|
|
54
54
|
"hypercore-id-encoding": "^1.2.0",
|
|
55
|
-
"hypertrace": "^1.2.1",
|
|
56
55
|
"is-options": "^1.0.1",
|
|
57
56
|
"protomux": "^3.5.0",
|
|
58
57
|
"quickbit-universal": "^2.2.0",
|