hypercore 11.21.4 → 11.21.6
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/replicator.js +14 -0
- package/package.json +1 -1
package/lib/replicator.js
CHANGED
|
@@ -26,6 +26,7 @@ const b4a = require('b4a')
|
|
|
26
26
|
const safetyCatch = require('safety-catch')
|
|
27
27
|
const RandomIterator = require('random-array-iterator')
|
|
28
28
|
const flatTree = require('flat-tree')
|
|
29
|
+
const Mutex = require('./mutex')
|
|
29
30
|
const ReceiverQueue = require('./receiver-queue')
|
|
30
31
|
const HotswapQueue = require('./hotswap-queue')
|
|
31
32
|
const RemoteBitfield = require('./remote-bitfield')
|
|
@@ -895,6 +896,7 @@ class Peer {
|
|
|
895
896
|
|
|
896
897
|
async push(index) {
|
|
897
898
|
if (!this.remoteAllowPush) return
|
|
899
|
+
if (!this.remoteDownloading) return
|
|
898
900
|
if (this.core.state.fork !== this.remoteFork) return
|
|
899
901
|
if (this.remoteBitfield.get(index)) return
|
|
900
902
|
|
|
@@ -1062,6 +1064,17 @@ class Peer {
|
|
|
1062
1064
|
}
|
|
1063
1065
|
|
|
1064
1066
|
async ondata(data) {
|
|
1067
|
+
if (data.request !== 0) return this._handleData(data)
|
|
1068
|
+
|
|
1069
|
+
await this.replicator._pushLock.lock()
|
|
1070
|
+
try {
|
|
1071
|
+
await this._handleData(data)
|
|
1072
|
+
} finally {
|
|
1073
|
+
this.replicator._pushLock.unlock()
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
async _handleData(data) {
|
|
1065
1078
|
// always allow a fork conflict proof to be sent
|
|
1066
1079
|
if (data.request === 0 && data.upgrade && data.upgrade.start === 0) {
|
|
1067
1080
|
if (await this.core.checkConflict(data, this)) return
|
|
@@ -1769,6 +1782,7 @@ module.exports = class Replicator {
|
|
|
1769
1782
|
this._reorgs = []
|
|
1770
1783
|
this._ranges = []
|
|
1771
1784
|
|
|
1785
|
+
this._pushLock = new Mutex()
|
|
1772
1786
|
this._hadPeers = false
|
|
1773
1787
|
this._active = 0
|
|
1774
1788
|
this._ifAvailable = 0
|