hypercore 10.38.2 → 11.0.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 +13 -30
- package/index.js +388 -444
- package/lib/audit.js +33 -41
- package/lib/bit-interlude.js +174 -0
- package/lib/bitfield.js +79 -87
- package/lib/block-store.js +12 -50
- package/lib/copy-prologue.js +236 -0
- package/lib/core.js +413 -746
- package/lib/download.js +42 -4
- package/lib/merkle-tree.js +263 -406
- package/lib/multisig.js +9 -6
- package/lib/mutex.js +4 -0
- package/lib/remote-bitfield.js +9 -9
- package/lib/replicator.js +247 -177
- package/lib/session-state.js +949 -0
- package/lib/verifier.js +20 -13
- package/package.json +2 -2
- package/lib/batch.js +0 -431
- package/lib/big-header.js +0 -55
- package/lib/oplog.js +0 -228
package/lib/download.js
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
module.exports = class Download {
|
|
2
|
-
constructor (
|
|
3
|
-
this.
|
|
2
|
+
constructor (session, range) {
|
|
3
|
+
this.session = session
|
|
4
|
+
this.range = range
|
|
5
|
+
this.request = null
|
|
6
|
+
this.opened = false
|
|
7
|
+
this.opening = this._open()
|
|
8
|
+
this.opening.catch(noop)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
ready () {
|
|
12
|
+
return this.opening
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async _open () {
|
|
16
|
+
if (this.session.opened === false) await this.session.opening
|
|
17
|
+
this._download()
|
|
18
|
+
this.opened = true
|
|
4
19
|
}
|
|
5
20
|
|
|
6
21
|
async done () {
|
|
7
|
-
|
|
22
|
+
await this.ready()
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
return await this.request.promise
|
|
26
|
+
} catch (err) {
|
|
27
|
+
if (isSessionMoved(err)) return this._download()
|
|
28
|
+
throw err
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_download () {
|
|
33
|
+
const activeRequests = (this.range && this.range.activeRequests) || this.session.activeRequests
|
|
34
|
+
this.request = this.session.core.replicator.addRange(activeRequests, this.range)
|
|
35
|
+
this.request.promise.catch(noop)
|
|
36
|
+
return this.request.promise
|
|
8
37
|
}
|
|
9
38
|
|
|
10
39
|
/**
|
|
@@ -15,8 +44,17 @@ module.exports = class Download {
|
|
|
15
44
|
}
|
|
16
45
|
|
|
17
46
|
destroy () {
|
|
18
|
-
this.
|
|
47
|
+
this._destroyBackground().catch(noop)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async _destroyBackground () {
|
|
51
|
+
if (this.opened === false) await this.ready()
|
|
52
|
+
if (this.request.context) this.request.context.detach(this.request)
|
|
19
53
|
}
|
|
20
54
|
}
|
|
21
55
|
|
|
22
56
|
function noop () {}
|
|
57
|
+
|
|
58
|
+
function isSessionMoved (err) {
|
|
59
|
+
return err.code === 'SESSION_MOVED'
|
|
60
|
+
}
|