@@ -42,6 +42,7 @@ class HyperDHT extends DHT {
4242 this . _validatedLocalAddresses = new Map ( )
4343
4444 this . _lastRandomPunch = 0
45+ this . _connectable = true
4546 this . _randomPunchInterval = opts . randomPunchInterval || 20000 // min 20s between random punches...
4647 this . _randomPunches = 0
4748 this . _randomPunchLimit = 1 // set to one for extra safety for now
@@ -76,19 +77,29 @@ class HyperDHT extends DHT {
7677 return new ConnectionPool ( this )
7778 }
7879
79- async resume ( ) {
80- await super . resume ( )
80+ async resume ( { log = noop } = { } ) {
81+ await super . resume ( { log } )
8182 const resuming = [ ]
8283 for ( const server of this . listening ) resuming . push ( server . resume ( ) )
84+ log ( 'Resuming hyperdht servers' )
8385 await Promise . allSettled ( resuming )
86+ log ( 'Done, hyperdht fully resumed' )
8487 }
8588
86- async suspend ( ) {
89+ async suspend ( { log = noop } = { } ) {
90+ this . _connectable = false // just so nothing gets connected during suspension
8791 const suspending = [ ]
8892 for ( const server of this . listening ) suspending . push ( server . suspend ( ) )
93+ log ( 'Suspending all hyperdht servers' )
8994 await Promise . allSettled ( suspending )
90- await super . suspend ( )
95+ log ( 'Done, clearing all raw streams' )
9196 await this . _rawStreams . clear ( )
97+ log ( 'Done, suspending dht-rpc' )
98+ await super . suspend ( { log } )
99+ log ( 'Done, clearing raw streams again' )
100+ await this . _rawStreams . clear ( )
101+ log ( 'Done, hyperdht fully suspended' )
102+ this . _connectable = true
92103 }
93104
94105 async destroy ( { force = false } = { } ) {
0 commit comments