File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -348,6 +348,19 @@ func (c *Communication) startChannel(privKeyBytes []byte) error {
348348 routingDiscovery := discovery_routing .NewRoutingDiscovery (kademliaDHT )
349349 discovery_util .Advertise (ctx , routingDiscovery , c .rendezvous )
350350
351+ // Create a goroutine to shut down the DHT after 5 minutes
352+ go func () {
353+ select {
354+ case <- time .After (5 * time .Minute ):
355+ c .logger .Info ().Msg ("Closing Kademlia DHT after 5 minutes" )
356+ if err := kademliaDHT .Close (); err != nil {
357+ c .logger .Error ().Err (err ).Msg ("Failed to close Kademlia DHT" )
358+ }
359+ case <- ctx .Done ():
360+ c .logger .Info ().Msg ("Context done, not waiting for 5 minutes to close DHT" )
361+ }
362+ }()
363+
351364 err = c .bootStrapConnectivityCheck ()
352365 if err != nil {
353366 return err
You can’t perform that action at this time.
0 commit comments