@@ -222,68 +222,37 @@ class CorestoreNetworker extends Nanoresource {
222
222
}
223
223
224
224
allStatuses ( ) {
225
- return [ ...this . _configurations ] . map ( ( [ k , v ] ) => {
225
+ return [ ...this . _configurations ] . map ( ( [ k , v ] ) => {
226
226
return {
227
227
discoveryKey : Buffer . from ( k , 'hex' ) ,
228
- announce : v . announce ,
229
- lookup : v . lookup
228
+ ...v
230
229
}
231
230
} )
232
231
}
233
232
234
233
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 ) )
254
235
}
255
236
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
266
240
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 ) {
272
241
const config = {
273
242
announce : opts . announce !== false ,
274
243
lookup : opts . lookup !== false
275
244
}
276
- opts = { ...opts , ...config , id }
245
+ opts = { ...opts , ...config }
277
246
278
247
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
280
250
281
- if ( id ) this . _configurations . set ( keyString , opts )
251
+ if ( joining ) this . _configurations . set ( keyString , opts )
282
252
else this . _configurations . delete ( keyString )
283
253
284
- const joining = config . announce || config . lookup
285
254
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
287
256
return this . _join ( discoveryKey , opts )
288
257
} else {
289
258
return this . _leave ( discoveryKey )
0 commit comments