Skip to content

Commit 323cbef

Browse files
mafintoshandrewosh
authored andcommitted
remove unconfigure
1 parent 7f011e1 commit 323cbef

File tree

1 file changed

+11
-42
lines changed

1 file changed

+11
-42
lines changed

index.js

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -222,68 +222,37 @@ class CorestoreNetworker extends Nanoresource {
222222
}
223223

224224
allStatuses () {
225-
return [ ...this._configurations].map(([k, v]) => {
225+
return [...this._configurations].map(([k, v]) => {
226226
return {
227227
discoveryKey: Buffer.from(k, 'hex'),
228-
announce: v.announce,
229-
lookup: v.lookup
228+
...v
230229
}
231230
})
232231
}
233232

234233
configure (discoveryKey, opts = {}, cb) {
235-
if (!this.swarm) this.open() // it is sync, which makes this easier below inregards to race conditions
236-
if (this.swarm && this.swarm.destroyed) return maybeOptional(cb, Promise.resolve())
237-
238-
const id = Symbol('id')
239-
const prom = this._configure(discoveryKey, opts, id, false)
240-
const keyString = toString(discoveryKey)
241-
const prev = this._configurations.get(keyString) || { lookup: false, announce: false, id: null }
242-
243-
prom.configureId = id
244-
prom.discoveryKey = discoveryKey
245-
prom.previous = prev
246-
247-
maybeOptional(cb, prom)
248-
249-
return prom
250-
}
251-
252-
unconfigure (prom, cb) {
253-
return maybeOptional(cb, this._unconfigure(prom))
234+
return maybeOptional(cb, this._configure(discoveryKey, opts))
254235
}
255236

256-
async _unconfigure (prom) {
257-
if (this.swarm && this.swarm.destroyed) return null
258-
if (!this.swarm) {
259-
await this.listen()
260-
return this.unconfigure(prom)
261-
}
262-
263-
const discoveryKey = prom.discoveryKey
264-
const keyString = toString(discoveryKey)
265-
const conf = this._configurations.get(keyString)
237+
async _configure (discoveryKey, opts) {
238+
if (!this.swarm) await this.open()
239+
if (this.swarm && this.swarm.destroyed) return
266240

267-
if (!conf || conf.id !== prom.configureId) return
268-
return this._configure(discoveryKey, prom.previous, prom.previous.id, true)
269-
}
270-
271-
async _configure (discoveryKey, opts, id, isUnconfigure) {
272241
const config = {
273242
announce: opts.announce !== false,
274243
lookup: opts.lookup !== false
275244
}
276-
opts = { ...opts, ...config, id }
245+
opts = { ...opts, ...config }
277246

278247
const keyString = toString(discoveryKey)
279-
const current = this._configurations.get(keyString)
248+
const prev = this._configurations.get(keyString)
249+
const joining = config.announce || config.lookup
280250

281-
if (id) this._configurations.set(keyString, opts)
251+
if (joining) this._configurations.set(keyString, opts)
282252
else this._configurations.delete(keyString)
283253

284-
const joining = config.announce || config.lookup
285254
if (joining) {
286-
if (isUnconfigure && current && current.lookup === config.lookup && current.announce === config.announce) return
255+
if (opts.rejoin === false && prev && prev.lookup === config.lookup && prev.announce === config.announce) return
287256
return this._join(discoveryKey, opts)
288257
} else {
289258
return this._leave(discoveryKey)

0 commit comments

Comments
 (0)