hypercore 11.21.4 → 11.21.5
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 +13 -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')
|
|
@@ -1062,6 +1063,17 @@ class Peer {
|
|
|
1062
1063
|
}
|
|
1063
1064
|
|
|
1064
1065
|
async ondata(data) {
|
|
1066
|
+
if (data.request !== 0) return this._handleData(data)
|
|
1067
|
+
|
|
1068
|
+
await this.replicator._pushLock.lock()
|
|
1069
|
+
try {
|
|
1070
|
+
await this._handleData(data)
|
|
1071
|
+
} finally {
|
|
1072
|
+
this.replicator._pushLock.unlock()
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
async _handleData(data) {
|
|
1065
1077
|
// always allow a fork conflict proof to be sent
|
|
1066
1078
|
if (data.request === 0 && data.upgrade && data.upgrade.start === 0) {
|
|
1067
1079
|
if (await this.core.checkConflict(data, this)) return
|
|
@@ -1769,6 +1781,7 @@ module.exports = class Replicator {
|
|
|
1769
1781
|
this._reorgs = []
|
|
1770
1782
|
this._ranges = []
|
|
1771
1783
|
|
|
1784
|
+
this._pushLock = new Mutex()
|
|
1772
1785
|
this._hadPeers = false
|
|
1773
1786
|
this._active = 0
|
|
1774
1787
|
this._ifAvailable = 0
|