Skip to content

Commit f8b548c

Browse files
authored
shut down dht after 5 mins (#32)
1 parent 89fee4b commit f8b548c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

p2p/communication.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)