Skip to content

Commit

Permalink
slowly mode extensions to primary core instead so its stable
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Nov 23, 2024
1 parent b779c29 commit 679d3da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const ActiveWriters = require('./lib/active-writers')
const CorePool = require('./lib/core-pool')
const AutoWakeup = require('./lib/wakeup')

const WakeupExtension = require('./lib/extension')

const inspect = Symbol.for('nodejs.util.inspect.custom')
const INTERRUPT = new Error('Apply interrupted')

Expand Down Expand Up @@ -56,6 +58,7 @@ module.exports = class Autobase extends ReadyResource {
this._primaryBootstrap = null
if (this.bootstrap) {
this._primaryBootstrap = this.store.get({ key: this.bootstrap, compat: false, active: false, encryptionKey: this.encryptionKey })
this.wakeupExtension = new WakeupExtension(this, this._primaryBootstrap, true)
this.store = this.store.namespace(this._primaryBootstrap, { detach: false })
}

Expand Down Expand Up @@ -277,6 +280,7 @@ module.exports = class Autobase extends ReadyResource {
const ref = await this.local.getUserData('referrer')
if (ref && !b4a.equals(ref, this.local.key) && !this._primaryBootstrap) {
this._primaryBootstrap = this.store.get({ key: ref, compat: false, active: false, encryptionKey: this.encryptionKey })
this.wakeupExtension = new WakeupExtension(this, this._primaryBootstrap, true)
this.store = this.store.namespace(this._primaryBootstrap, { detach: false })
}

Expand All @@ -288,6 +292,7 @@ module.exports = class Autobase extends ReadyResource {
if (this.encryptionKey) await this._primaryBootstrap.setUserData('autobase/encryption', this.encryptionKey)
} else {
this.local.setUserData('autobase/local', this.local.key)
this.wakeupExtension = new WakeupExtension(this, this.local, true)
}

const { bootstrap, system, heads } = await this._loadSystemInfo()
Expand Down
8 changes: 5 additions & 3 deletions lib/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Wakeup } = require('./messages')
const VERSION = 1

module.exports = class WakeupExtension {
constructor (base, core) {
constructor (base, core, passive) {
this.base = base
this.core = core

Expand All @@ -19,8 +19,10 @@ module.exports = class WakeupExtension {
this.extension.send(req, peer)
})

for (const peer of this.core.peers) {
this.extension.send(req, peer)
if (!passive) {
for (const peer of this.core.peers) {
this.extension.send(req, peer)
}
}
}

Expand Down

0 comments on commit 679d3da

Please sign in to comment.