hypercore 10.37.16 → 10.37.18
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/core.js +12 -1
- package/lib/replicator.js +14 -3
- package/package.json +1 -1
package/lib/core.js
CHANGED
|
@@ -107,7 +107,7 @@ module.exports = class Core {
|
|
|
107
107
|
external: null,
|
|
108
108
|
key: opts.key || (compat ? manifest.signers[0].publicKey : Verifier.manifestHash(manifest)),
|
|
109
109
|
manifest,
|
|
110
|
-
keyPair,
|
|
110
|
+
keyPair: keyPair ? { publicKey: keyPair.publicKey, secretKey: keyPair.secretKey || null } : null,
|
|
111
111
|
userData: [],
|
|
112
112
|
tree: {
|
|
113
113
|
fork: 0,
|
|
@@ -131,6 +131,11 @@ module.exports = class Core {
|
|
|
131
131
|
header.tree.rootHash = unslab(header.tree.rootHash)
|
|
132
132
|
header.tree.signature = unslab(header.tree.signature)
|
|
133
133
|
|
|
134
|
+
if (header.keyPair) {
|
|
135
|
+
header.keyPair.publicKey = unslab(header.keyPair.publicKey)
|
|
136
|
+
header.keyPair.secretKey = unslab(header.keyPair.secretKey)
|
|
137
|
+
}
|
|
138
|
+
|
|
134
139
|
if (opts.manifest) {
|
|
135
140
|
// if we provide a manifest and no key, verify that the stored key is the same
|
|
136
141
|
if (!opts.key && !Verifier.isValidManifest(header.key, Verifier.createManifest(opts.manifest))) {
|
|
@@ -204,6 +209,10 @@ module.exports = class Core {
|
|
|
204
209
|
}
|
|
205
210
|
}
|
|
206
211
|
|
|
212
|
+
for (const entry of header.userData) {
|
|
213
|
+
entry.value = unslab(entry.value)
|
|
214
|
+
}
|
|
215
|
+
|
|
207
216
|
return new this(header, compat, crypto, oplog, bigHeader, tree, blocks, bitfield, verifier, opts.sessions || [], legacy, opts.globalCache || null, opts.onupdate || noop, opts.onconflict || noop)
|
|
208
217
|
}
|
|
209
218
|
|
|
@@ -1022,6 +1031,8 @@ function addReorgHint (list, tree, batch) {
|
|
|
1022
1031
|
}
|
|
1023
1032
|
|
|
1024
1033
|
function updateUserData (list, key, value) {
|
|
1034
|
+
value = unslab(value)
|
|
1035
|
+
|
|
1025
1036
|
for (let i = 0; i < list.length; i++) {
|
|
1026
1037
|
if (list[i].key === key) {
|
|
1027
1038
|
if (value) list[i].value = value
|
package/lib/replicator.js
CHANGED
|
@@ -972,8 +972,8 @@ class Peer {
|
|
|
972
972
|
this._remoteContiguousLength = start
|
|
973
973
|
}
|
|
974
974
|
|
|
975
|
-
if (start === 0 && drop === false
|
|
976
|
-
this._remoteContiguousLength = length
|
|
975
|
+
if (start === 0 && drop === false) {
|
|
976
|
+
if (length > this._remoteContiguousLength) this._remoteContiguousLength = length
|
|
977
977
|
} else if (length === 1) {
|
|
978
978
|
const bitfield = this.core.skipBitfield === null ? this.core.bitfield : this.core.skipBitfield
|
|
979
979
|
this.remoteBitfield.set(start, has)
|
|
@@ -1095,7 +1095,7 @@ class Peer {
|
|
|
1095
1095
|
let index = off + i
|
|
1096
1096
|
if (index > s.seeker.end) index -= len
|
|
1097
1097
|
|
|
1098
|
-
if (this.
|
|
1098
|
+
if (this._remoteHasBlock(index) === false) continue
|
|
1099
1099
|
if (this.core.bitfield.get(index) === true) continue
|
|
1100
1100
|
if (!this._hasTreeParent(index)) continue
|
|
1101
1101
|
|
|
@@ -1997,6 +1997,17 @@ module.exports = class Replicator {
|
|
|
1997
1997
|
}
|
|
1998
1998
|
|
|
1999
1999
|
_onwant (peer, start, length) {
|
|
2000
|
+
const contig = Math.min(this.core.tree.length, this.core.header.hints.contiguousLength)
|
|
2001
|
+
|
|
2002
|
+
if (start + length < contig || (this.core.tree.length === contig)) {
|
|
2003
|
+
peer.wireRange.send({
|
|
2004
|
+
drop: false,
|
|
2005
|
+
start: 0,
|
|
2006
|
+
length: contig
|
|
2007
|
+
})
|
|
2008
|
+
return
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2000
2011
|
length = Math.min(length, this.core.tree.length - start)
|
|
2001
2012
|
|
|
2002
2013
|
peer.protomux.cork()
|