hypercore 11.16.2 → 11.18.0
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 +31 -29
- package/index.js +153 -155
- package/lib/audit.js +17 -6
- package/lib/bit-interlude.js +17 -7
- package/lib/bitfield.js +72 -52
- package/lib/caps.js +5 -1
- package/lib/copy-prologue.js +14 -10
- package/lib/core.js +109 -56
- package/lib/default-encryption.js +14 -28
- package/lib/download.js +10 -10
- package/lib/fully-remote-proof.js +3 -3
- package/lib/hotswap-queue.js +5 -5
- package/lib/info.js +4 -4
- package/lib/inspect.js +50 -0
- package/lib/merkle-tree.js +143 -104
- package/lib/messages.js +163 -143
- package/lib/multisig.js +19 -12
- package/lib/mutex.js +9 -7
- package/lib/receiver-queue.js +6 -6
- package/lib/remote-bitfield.js +30 -32
- package/lib/replicator.js +383 -265
- package/lib/session-state.js +112 -75
- package/lib/streams.js +16 -16
- package/lib/verifier.js +69 -43
- package/package.json +5 -3
package/lib/hotswap-queue.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const TICKS = 16
|
|
2
2
|
|
|
3
3
|
module.exports = class HotswapQueue {
|
|
4
|
-
constructor
|
|
4
|
+
constructor() {
|
|
5
5
|
this.priorities = [[], [], []]
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
*
|
|
8
|
+
*pick(peer) {
|
|
9
9
|
for (let i = 0; i < this.priorities.length; i++) {
|
|
10
10
|
// try first one more than second one etc etc
|
|
11
11
|
let ticks = (this.priorities.length - i) * TICKS
|
|
@@ -30,7 +30,7 @@ module.exports = class HotswapQueue {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
add
|
|
33
|
+
add(block) {
|
|
34
34
|
if (block.hotswap !== null) this.remove(block)
|
|
35
35
|
if (block.inflight.length === 0 || block.inflight.length >= 3) return
|
|
36
36
|
|
|
@@ -41,7 +41,7 @@ module.exports = class HotswapQueue {
|
|
|
41
41
|
block.hotswap = { ref: this, queue, index }
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
remove
|
|
44
|
+
remove(block) {
|
|
45
45
|
const hotswap = block.hotswap
|
|
46
46
|
if (hotswap === null) return
|
|
47
47
|
|
|
@@ -52,7 +52,7 @@ module.exports = class HotswapQueue {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function hasInflight
|
|
55
|
+
function hasInflight(block, peer) {
|
|
56
56
|
for (let j = 0; j < block.inflight.length; j++) {
|
|
57
57
|
if (block.inflight[j].peer === peer) return true
|
|
58
58
|
}
|
package/lib/info.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module.exports = class Info {
|
|
2
|
-
constructor
|
|
2
|
+
constructor(opts = {}) {
|
|
3
3
|
this.key = opts.key
|
|
4
4
|
this.discoveryKey = opts.discoveryKey
|
|
5
5
|
this.length = opts.length || 0
|
|
@@ -10,7 +10,7 @@ module.exports = class Info {
|
|
|
10
10
|
this.storage = opts.storage || null
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
static async from
|
|
13
|
+
static async from(session, opts = {}) {
|
|
14
14
|
return new Info({
|
|
15
15
|
key: session.key,
|
|
16
16
|
discoveryKey: session.discoveryKey,
|
|
@@ -23,7 +23,7 @@ module.exports = class Info {
|
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
static async storage
|
|
26
|
+
static async storage(session) {
|
|
27
27
|
const { oplog, tree, blocks, bitfield } = session.core
|
|
28
28
|
try {
|
|
29
29
|
return {
|
|
@@ -37,7 +37,7 @@ module.exports = class Info {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
static bytesUsed
|
|
40
|
+
static bytesUsed(file) {
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
42
42
|
file.stat((err, st) => {
|
|
43
43
|
if (err) {
|
package/lib/inspect.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const b4a = require('b4a')
|
|
2
|
+
|
|
3
|
+
module.exports = function (core, depth, opts) {
|
|
4
|
+
let indent = ''
|
|
5
|
+
if (typeof opts.indentationLvl === 'number') {
|
|
6
|
+
while (indent.length < opts.indentationLvl) indent += ' '
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let peers = ''
|
|
10
|
+
const min = Math.min(core.peers.length, 5)
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < min; i++) {
|
|
13
|
+
const peer = core.peers[i]
|
|
14
|
+
|
|
15
|
+
peers += `${indent} Peer(\n`
|
|
16
|
+
peers += `${indent} remotePublicKey: ${opts.stylize(toHex(peer.remotePublicKey), 'string')}\n`
|
|
17
|
+
peers += `${indent} remoteLength: ${opts.stylize(peer.remoteLength, 'number')}\n`
|
|
18
|
+
peers += `${indent} remoteFork: ${opts.stylize(peer.remoteFork, 'number')}\n`
|
|
19
|
+
peers += `${indent} remoteCanUpgrade: ${opts.stylize(peer.remoteCanUpgrade, 'boolean')}\n`
|
|
20
|
+
peers += `${indent} )\n`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (core.peers.length > 5) {
|
|
24
|
+
peers += `${indent} ... and ${core.peers.length - 5} more\n`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (peers) peers = `[\n${peers}${indent} ]`
|
|
28
|
+
else peers = `[ ${opts.stylize(0, 'number')} ]`
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
`${core.constructor.name}(\n` +
|
|
32
|
+
`${indent} id: ${opts.stylize(core.id, 'string')}\n` +
|
|
33
|
+
`${indent} key: ${opts.stylize(toHex(core.key), 'string')}\n` +
|
|
34
|
+
`${indent} discoveryKey: ${opts.stylize(toHex(core.discoveryKey), 'string')}\n` +
|
|
35
|
+
`${indent} opened: ${opts.stylize(core.opened, 'boolean')}\n` +
|
|
36
|
+
`${indent} closed: ${opts.stylize(core.closed, 'boolean')}\n` +
|
|
37
|
+
`${indent} snapshotted: ${opts.stylize(core.snapshotted, 'boolean')}\n` +
|
|
38
|
+
`${indent} writable: ${opts.stylize(core.writable, 'boolean')}\n` +
|
|
39
|
+
`${indent} length: ${opts.stylize(core.length, 'number')}\n` +
|
|
40
|
+
`${indent} fork: ${opts.stylize(core.fork, 'number')}\n` +
|
|
41
|
+
`${indent} sessions: [ ${opts.stylize(core.sessions.length, 'number')} ]\n` +
|
|
42
|
+
`${indent} activeRequests: [ ${opts.stylize(core.activeRequests.length, 'number')} ]\n` +
|
|
43
|
+
`${indent} peers: ${peers}\n` +
|
|
44
|
+
`${indent})'`
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function toHex(buf) {
|
|
49
|
+
return buf && b4a.toString(buf, 'hex')
|
|
50
|
+
}
|