Skip to content

Commit fe47d25

Browse files
committed
Merge branch 'master' into whitelist-connection-gater
2 parents 983cfc9 + f8b548c commit fe47d25

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

p2p/communication.go

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

0 commit comments

Comments
 (0)