hypercore 11.27.7 → 11.27.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/index.js +4 -0
- package/lib/core.js +0 -1
- package/lib/session-state.js +15 -27
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -376,12 +376,16 @@ class Hypercore extends EventEmitter {
|
|
|
376
376
|
const state = this.state
|
|
377
377
|
|
|
378
378
|
if (opts.atom) {
|
|
379
|
+
await parentState.mutex.lock()
|
|
379
380
|
this.state = await parentState.createSession(null, false, opts.atom)
|
|
381
|
+
parentState.mutex.unlock()
|
|
380
382
|
if (state) state.unref()
|
|
381
383
|
} else if (opts.name) {
|
|
382
384
|
// todo: need to make named sessions safe before ready
|
|
383
385
|
// atm we always copy the state in passCapabilities
|
|
386
|
+
await parentState.mutex.lock()
|
|
384
387
|
this.state = await parentState.createSession(opts.name, !!opts.overwrite, null)
|
|
388
|
+
parentState.mutex.unlock()
|
|
385
389
|
if (state) state.unref() // ref'ed above in setup session
|
|
386
390
|
}
|
|
387
391
|
|
package/lib/core.js
CHANGED
package/lib/session-state.js
CHANGED
|
@@ -123,7 +123,7 @@ class SessionState {
|
|
|
123
123
|
return this.core.header.tree.fork
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
async
|
|
126
|
+
async _updateSnapshotStorage(storage) {
|
|
127
127
|
if (!this.atomized || !this.atomized.flushing) return this.treeInfo()
|
|
128
128
|
await this.atomized.flushed()
|
|
129
129
|
|
|
@@ -206,12 +206,16 @@ class SessionState {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
async snapshot() {
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
try {
|
|
210
|
+
await this.mutex.lock()
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
const storage = this.storage.snapshot()
|
|
213
|
+
const treeInfo = await this._updateSnapshotStorage(storage)
|
|
213
214
|
|
|
214
|
-
|
|
215
|
+
return new SessionState(this.core, null, storage, treeInfo, this.name)
|
|
216
|
+
} finally {
|
|
217
|
+
this._unlock()
|
|
218
|
+
}
|
|
215
219
|
}
|
|
216
220
|
|
|
217
221
|
updateDependency(tx, length) {
|
|
@@ -251,10 +255,6 @@ class SessionState {
|
|
|
251
255
|
return true
|
|
252
256
|
}
|
|
253
257
|
|
|
254
|
-
_precommit() {
|
|
255
|
-
this.commiting = true
|
|
256
|
-
}
|
|
257
|
-
|
|
258
258
|
async _commit() {
|
|
259
259
|
await this.mutex.lock()
|
|
260
260
|
|
|
@@ -264,7 +264,6 @@ class SessionState {
|
|
|
264
264
|
this.lastTruncation = null
|
|
265
265
|
await this.parent._oncommit(this, bitfield)
|
|
266
266
|
} finally {
|
|
267
|
-
this.commiting = false
|
|
268
267
|
this.mutex.unlock()
|
|
269
268
|
}
|
|
270
269
|
}
|
|
@@ -311,8 +310,7 @@ class SessionState {
|
|
|
311
310
|
|
|
312
311
|
if (this.core.hintsChanged && this.isDefault()) await this.core.flushHints()
|
|
313
312
|
} finally {
|
|
314
|
-
this.
|
|
315
|
-
this.core.checkIfIdle()
|
|
313
|
+
this._unlock()
|
|
316
314
|
}
|
|
317
315
|
}
|
|
318
316
|
|
|
@@ -346,7 +344,6 @@ class SessionState {
|
|
|
346
344
|
}
|
|
347
345
|
|
|
348
346
|
const tx = this.createWriteBatch()
|
|
349
|
-
this.updating = true
|
|
350
347
|
|
|
351
348
|
if (bitfield) {
|
|
352
349
|
tx.putBlock(bitfield.start, value)
|
|
@@ -384,9 +381,7 @@ class SessionState {
|
|
|
384
381
|
|
|
385
382
|
if (this.core.hintsChanged && this.isDefault()) await this.core.flushHints()
|
|
386
383
|
} finally {
|
|
387
|
-
this.
|
|
388
|
-
this.updating = false
|
|
389
|
-
this.mutex.unlock()
|
|
384
|
+
this._unlock()
|
|
390
385
|
}
|
|
391
386
|
|
|
392
387
|
return true
|
|
@@ -849,7 +844,7 @@ class SessionState {
|
|
|
849
844
|
|
|
850
845
|
if (this.core.hintsChanged && this.isDefault()) await this.core.flushHints()
|
|
851
846
|
} finally {
|
|
852
|
-
this.
|
|
847
|
+
this._unlock()
|
|
853
848
|
}
|
|
854
849
|
}
|
|
855
850
|
|
|
@@ -1027,15 +1022,8 @@ class SessionState {
|
|
|
1027
1022
|
byteLength: this.byteLength
|
|
1028
1023
|
}
|
|
1029
1024
|
} finally {
|
|
1030
|
-
|
|
1031
|
-
this.
|
|
1032
|
-
|
|
1033
|
-
if (srcLocked) {
|
|
1034
|
-
state.mutex.unlock()
|
|
1035
|
-
state._clearActiveBatch()
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
this.core.checkIfIdle()
|
|
1025
|
+
if (srcLocked) state._unlock()
|
|
1026
|
+
this._unlock()
|
|
1039
1027
|
}
|
|
1040
1028
|
}
|
|
1041
1029
|
|
|
@@ -1144,7 +1132,7 @@ class SessionState {
|
|
|
1144
1132
|
|
|
1145
1133
|
this._moveToCore(core.core, truncated, appended)
|
|
1146
1134
|
} finally {
|
|
1147
|
-
this.
|
|
1135
|
+
this._unlock()
|
|
1148
1136
|
}
|
|
1149
1137
|
}
|
|
1150
1138
|
|