hypercore 11.35.4 → 11.36.0
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/README.md +5 -0
- package/index.js +13 -0
- package/lib/core.js +10 -0
- package/lib/replicator.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ Alternatively you can pass a [Hypercore Storage](https://github.com/holepunchto/
|
|
|
58
58
|
onseq: (index, core) => { ... }, // A callback called when core.get(index) is called.
|
|
59
59
|
notDownloadingLinger: 20000, // How many milliseconds to wait after downloading finishes keeping the connection open. Defaults to a random number between 20-40s
|
|
60
60
|
allowFork: true, // Enables updating core when it forks
|
|
61
|
+
allowLatestBlock: false, // Request latest block when requesting upgrade
|
|
61
62
|
userData: { foo: 'bar' }, // An object to assign to the local User Data storage
|
|
62
63
|
manifest: undefined, // Advanced option. Set the manifest when creating the hypercore. See Manifest section for more info
|
|
63
64
|
preload: undefined, // Advanced option. A promise that returns constructor options overrides before the core is opened
|
|
@@ -701,6 +702,10 @@ Set the core to be active or not. A core is considered 'active' if it should lin
|
|
|
701
702
|
|
|
702
703
|
When calling `core.setActive(true)` make sure to later call `core.setActive(false)` to mark it as inactive otherwise the core's activity tracking will be inaccurate and keep replication channels open.
|
|
703
704
|
|
|
705
|
+
#### `core.setAlwaysLatestBlock(enabled)`
|
|
706
|
+
|
|
707
|
+
Set whether the replicator should always include a request for the latest block in an upgrade request (aka the peer has a length update). A runtime method for updating the `allowLatestBlock` option.
|
|
708
|
+
|
|
704
709
|
#### `await core.setUserData(key, value)`
|
|
705
710
|
|
|
706
711
|
Set a key in the User Data key-value store.
|
package/index.js
CHANGED
|
@@ -308,6 +308,19 @@ class Hypercore extends EventEmitter {
|
|
|
308
308
|
this.core.replicator.updateActivity(this._active ? 1 : -1)
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
+
async setAlwaysLatestBlock(bool) {
|
|
312
|
+
if (!this.opened) await this.opening
|
|
313
|
+
|
|
314
|
+
const enabled = !!bool
|
|
315
|
+
if (enabled === this.core.replicator._alwaysLatestBlockEnabled) return
|
|
316
|
+
this.core.replicator._alwaysLatestBlockEnabled = enabled
|
|
317
|
+
this.core.replicator._alwaysLatestBlock += enabled
|
|
318
|
+
? 1
|
|
319
|
+
: this.core.replicator._alwaysLatestBlock === 0
|
|
320
|
+
? 0
|
|
321
|
+
: -1
|
|
322
|
+
}
|
|
323
|
+
|
|
311
324
|
async _open(storage, key, opts) {
|
|
312
325
|
const preload = opts.preload || (opts.parent && opts.parent.preload)
|
|
313
326
|
|
package/lib/core.js
CHANGED
|
@@ -154,6 +154,12 @@ module.exports = class Core {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
this.opened = true
|
|
157
|
+
|
|
158
|
+
// always make sure we get an initial update
|
|
159
|
+
if (this.state.length === 0 && !isWritableHeader(this.header)) {
|
|
160
|
+
this.replicator.setDownloading(true)
|
|
161
|
+
this.replicator.setDownloading(false)
|
|
162
|
+
}
|
|
157
163
|
}
|
|
158
164
|
|
|
159
165
|
async _tryOpen(opts) {
|
|
@@ -1034,6 +1040,10 @@ async function maybeGetRootsFromStorage(storage, length) {
|
|
|
1034
1040
|
}
|
|
1035
1041
|
}
|
|
1036
1042
|
|
|
1043
|
+
function isWritableHeader(header) {
|
|
1044
|
+
return !!(header && header.keyPair && header.keyPair.secretKey)
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1037
1047
|
function noop() {}
|
|
1038
1048
|
|
|
1039
1049
|
async function getCoreInfo(storage) {
|
package/lib/replicator.js
CHANGED
|
@@ -2023,7 +2023,8 @@ module.exports = class Replicator {
|
|
|
2023
2023
|
this._blocks = new BlockTracker(this)
|
|
2024
2024
|
this._hashes = new BlockTracker(this)
|
|
2025
2025
|
|
|
2026
|
-
this.
|
|
2026
|
+
this._alwaysLatestBlockEnabled = !!alwaysLatestBlock
|
|
2027
|
+
this._alwaysLatestBlock = this._alwaysLatestBlockEnabled ? 1 : 0
|
|
2027
2028
|
this._queued = []
|
|
2028
2029
|
|
|
2029
2030
|
this._seeks = []
|