hypercore 11.35.1 → 11.35.3
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/lib/mark-bitfield.js +4 -0
- package/lib/replicator.js +7 -2
- package/package.json +1 -1
package/lib/mark-bitfield.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const BigSparseArray = require('big-sparse-array')
|
|
2
2
|
const { Transform } = require('streamx')
|
|
3
3
|
const quickbit = require('./compat').quickbit
|
|
4
|
+
const Mutex = require('./mutex')
|
|
4
5
|
const b4a = require('b4a')
|
|
5
6
|
|
|
6
7
|
const BITS_PER_PAGE = 32768
|
|
@@ -34,6 +35,7 @@ module.exports = class MarkBitfield {
|
|
|
34
35
|
|
|
35
36
|
constructor(storage) {
|
|
36
37
|
this.storage = storage
|
|
38
|
+
this.mutex = new Mutex()
|
|
37
39
|
this._pages = new BigSparseArray()
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -68,9 +70,11 @@ module.exports = class MarkBitfield {
|
|
|
68
70
|
if (p) {
|
|
69
71
|
await p.loaded
|
|
70
72
|
p.set(j, val)
|
|
73
|
+
await this.mutex.lock()
|
|
71
74
|
const tx = this.storage.write()
|
|
72
75
|
tx.putMark(i, p.bitfield)
|
|
73
76
|
await tx.flush()
|
|
77
|
+
this.mutex.unlock()
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
|
package/lib/replicator.js
CHANGED
|
@@ -978,7 +978,8 @@ class Peer {
|
|
|
978
978
|
this.remoteOpened &&
|
|
979
979
|
this.protomux.drained &&
|
|
980
980
|
this.receiverQueue.length > 0 &&
|
|
981
|
-
!this.removed
|
|
981
|
+
!this.removed &&
|
|
982
|
+
this.core.closing === null
|
|
982
983
|
) {
|
|
983
984
|
const msg = this.receiverQueue.shift()
|
|
984
985
|
await this._handleRequest(msg)
|
|
@@ -989,6 +990,7 @@ class Peer {
|
|
|
989
990
|
}
|
|
990
991
|
|
|
991
992
|
async push(index) {
|
|
993
|
+
if (this.core.closing !== null) return
|
|
992
994
|
if (!this.remoteAllowPush) return
|
|
993
995
|
if (!this.remoteDownloading) return
|
|
994
996
|
if (this.core.state.length <= index) return
|
|
@@ -1269,7 +1271,7 @@ class Peer {
|
|
|
1269
1271
|
return
|
|
1270
1272
|
}
|
|
1271
1273
|
|
|
1272
|
-
if (this.core.closed && !isCriticalError(err)) return
|
|
1274
|
+
if ((this.core.closing !== null || this.core.closed) && !isCriticalError(err)) return
|
|
1273
1275
|
|
|
1274
1276
|
if (err.code !== 'INVALID_OPERATION') {
|
|
1275
1277
|
// might be a fork, verify
|
|
@@ -1405,6 +1407,8 @@ class Peer {
|
|
|
1405
1407
|
}
|
|
1406
1408
|
|
|
1407
1409
|
async onrange({ drop, start, length }) {
|
|
1410
|
+
if (this.core.closing !== null) return
|
|
1411
|
+
|
|
1408
1412
|
const has = drop === false
|
|
1409
1413
|
|
|
1410
1414
|
if (drop === true && start < this._remoteContiguousLength) {
|
|
@@ -1956,6 +1960,7 @@ class Peer {
|
|
|
1956
1960
|
}
|
|
1957
1961
|
}
|
|
1958
1962
|
} catch (err) {
|
|
1963
|
+
if (this.core.closing !== null) return
|
|
1959
1964
|
this.stream.destroy(err)
|
|
1960
1965
|
return
|
|
1961
1966
|
}
|