hypercore 10.37.8 → 10.37.9
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/merkle-tree.js +2 -0
- package/lib/replicator.js +14 -9
- package/package.json +1 -1
package/lib/merkle-tree.js
CHANGED
|
@@ -1351,12 +1351,14 @@ async function generateProof (tree, block, hash, seek, upgrade) {
|
|
|
1351
1351
|
const [pNode, pSeek, pUpgrade, pAdditional] = await settleProof(p)
|
|
1352
1352
|
|
|
1353
1353
|
if (block) {
|
|
1354
|
+
if (pNode === null) throw INVALID_OPERATION('Invalid block request')
|
|
1354
1355
|
result.block = {
|
|
1355
1356
|
index: block.index,
|
|
1356
1357
|
value: null, // populated upstream, alloc it here for simplicity
|
|
1357
1358
|
nodes: pNode
|
|
1358
1359
|
}
|
|
1359
1360
|
} else if (hash) {
|
|
1361
|
+
if (pNode === null) throw INVALID_OPERATION('Invalid hash request')
|
|
1360
1362
|
result.hash = {
|
|
1361
1363
|
index: hash.index,
|
|
1362
1364
|
nodes: pNode
|
package/lib/replicator.js
CHANGED
|
@@ -1021,11 +1021,16 @@ class Peer {
|
|
|
1021
1021
|
this.protomux.uncork()
|
|
1022
1022
|
}
|
|
1023
1023
|
|
|
1024
|
-
_makeRequest (needsUpgrade, priority) {
|
|
1024
|
+
_makeRequest (needsUpgrade, priority, minLength) {
|
|
1025
1025
|
if (needsUpgrade === true && this.replicator._shouldUpgrade(this) === false) {
|
|
1026
1026
|
return null
|
|
1027
1027
|
}
|
|
1028
1028
|
|
|
1029
|
+
// ensure that the remote has signalled they have the length we request
|
|
1030
|
+
if (this.remoteLength < minLength) {
|
|
1031
|
+
return null
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1029
1034
|
if (needsUpgrade === false && this.replicator._autoUpgrade(this) === true) {
|
|
1030
1035
|
needsUpgrade = true
|
|
1031
1036
|
}
|
|
@@ -1048,12 +1053,12 @@ class Peer {
|
|
|
1048
1053
|
}
|
|
1049
1054
|
|
|
1050
1055
|
_requestManifest () {
|
|
1051
|
-
const req = this._makeRequest(false, 0)
|
|
1056
|
+
const req = this._makeRequest(false, 0, 0)
|
|
1052
1057
|
this._send(req)
|
|
1053
1058
|
}
|
|
1054
1059
|
|
|
1055
1060
|
_requestUpgrade (u) {
|
|
1056
|
-
const req = this._makeRequest(true, 0)
|
|
1061
|
+
const req = this._makeRequest(true, 0, 0)
|
|
1057
1062
|
if (req === null) return false
|
|
1058
1063
|
|
|
1059
1064
|
this._send(req)
|
|
@@ -1070,7 +1075,7 @@ class Peer {
|
|
|
1070
1075
|
if (fork !== this.remoteFork) return false
|
|
1071
1076
|
|
|
1072
1077
|
if (s.seeker.start >= length) {
|
|
1073
|
-
const req = this._makeRequest(true, 0)
|
|
1078
|
+
const req = this._makeRequest(true, 0, 0)
|
|
1074
1079
|
|
|
1075
1080
|
// We need an upgrade for the seek, if non can be provided, skip
|
|
1076
1081
|
if (req === null) return false
|
|
@@ -1102,7 +1107,7 @@ class Peer {
|
|
|
1102
1107
|
const h = this.replicator._hashes.add(index, PRIORITY.NORMAL)
|
|
1103
1108
|
if (h.inflight.length > 0) continue
|
|
1104
1109
|
|
|
1105
|
-
const req = this._makeRequest(false, h.priority)
|
|
1110
|
+
const req = this._makeRequest(false, h.priority, index + 1)
|
|
1106
1111
|
const nodes = flatTree.depth(s.seeker.start + s.seeker.end - 1)
|
|
1107
1112
|
|
|
1108
1113
|
req.hash = { index: 2 * index, nodes }
|
|
@@ -1175,7 +1180,7 @@ class Peer {
|
|
|
1175
1180
|
return false
|
|
1176
1181
|
}
|
|
1177
1182
|
|
|
1178
|
-
const req = this._makeRequest(b.index >= length, b.priority)
|
|
1183
|
+
const req = this._makeRequest(b.index >= length, b.priority, b.index + 1)
|
|
1179
1184
|
if (req === null) return false
|
|
1180
1185
|
|
|
1181
1186
|
this._sendBlockRequest(req, b)
|
|
@@ -1192,7 +1197,7 @@ class Peer {
|
|
|
1192
1197
|
return false
|
|
1193
1198
|
}
|
|
1194
1199
|
|
|
1195
|
-
const req = this._makeRequest(index >= length, b.priority)
|
|
1200
|
+
const req = this._makeRequest(index >= length, b.priority, index + 1)
|
|
1196
1201
|
|
|
1197
1202
|
// If the request cannot be satisfied, dealloc the block request if no one is subscribed to it
|
|
1198
1203
|
if (req === null) {
|
|
@@ -1269,7 +1274,7 @@ class Peer {
|
|
|
1269
1274
|
}
|
|
1270
1275
|
|
|
1271
1276
|
_requestForkProof (f) {
|
|
1272
|
-
const req = this._makeRequest(false, 0)
|
|
1277
|
+
const req = this._makeRequest(false, 0, 0)
|
|
1273
1278
|
|
|
1274
1279
|
req.upgrade = { start: 0, length: this.remoteLength }
|
|
1275
1280
|
req.manifest = !this.core.header.manifest
|
|
@@ -1293,7 +1298,7 @@ class Peer {
|
|
|
1293
1298
|
|
|
1294
1299
|
if (this._remoteHasBlock(index) === false) continue
|
|
1295
1300
|
|
|
1296
|
-
const req = this._makeRequest(false, 0)
|
|
1301
|
+
const req = this._makeRequest(false, 0, 0)
|
|
1297
1302
|
|
|
1298
1303
|
req.hash = { index: 2 * index, nodes: f.batch.want.nodes }
|
|
1299
1304
|
|