File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,20 @@ func (c *Communication) startChannel(privKeyBytes []byte) error {
338338 // This is like telling your friends to meet you at the Eiffel Tower.
339339 routingDiscovery := discovery_routing .NewRoutingDiscovery (kademliaDHT )
340340 discovery_util .Advertise (ctx , routingDiscovery , c .rendezvous )
341+
342+ // Create a goroutine to shut down the DHT after 5 minutes
343+ go func () {
344+ select {
345+ case <- time .After (5 * time .Minute ):
346+ c .logger .Info ().Msg ("Closing Kademlia DHT after 5 minutes" )
347+ if err := kademliaDHT .Close (); err != nil {
348+ c .logger .Error ().Err (err ).Msg ("Failed to close Kademlia DHT" )
349+ }
350+ case <- ctx .Done ():
351+ c .logger .Info ().Msg ("Context done, not waiting for 5 minutes to close DHT" )
352+ }
353+ }()
354+
341355 err = c .bootStrapConnectivityCheck ()
342356 if err != nil {
343357 return err
You can’t perform that action at this time.
0 commit comments