Skip to content

Commit

Permalink
chore(timeout): add a timeout also for advertizing (#564)
Browse files Browse the repository at this point in the history
Signed-off-by: mudler <mudler@localai.io>
  • Loading branch information
mudler authored Aug 27, 2024
1 parent 2b64ee7 commit 2936cff
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/discovery/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,16 @@ func (d *DHT) FindClosePeers(ll log.StandardLogger, onlyStaticRelays bool, stati

func (d *DHT) announceAndConnect(l log.StandardLogger, ctx context.Context, kademliaDHT *dht.IpfsDHT, host host.Host, rv string) error {
l.Debug("Announcing ourselves...")

tCtx, c := context.WithTimeout(ctx, time.Second*120)
defer c()
routingDiscovery := discovery.NewRoutingDiscovery(kademliaDHT)
routingDiscovery.Advertise(ctx, rv)
routingDiscovery.Advertise(tCtx, rv)
l.Debug("Successfully announced!")
// Now, look for others who have announced
// This is like your friend telling you the location to meet you.
l.Debug("Searching for other peers...")

peerChan, err := routingDiscovery.FindPeers(ctx, rv)
if err != nil {
return err
Expand Down

0 comments on commit 2936cff

Please sign in to comment.