chore: add logs for peer connection backoff (#1018)

This commit is contained in:
Prem Chaitanya Prathi 2024-01-30 17:20:35 +05:30 committed by GitHub
parent 0f00fb8d96
commit b647314846
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -130,7 +130,7 @@ func (c *PeerConnectionStrategy) consumeSubscription(s subscription) {
if len(c.host.Network().Peers()) < waku_proto.GossipSubOptimalFullMeshSize { if len(c.host.Network().Peers()) < waku_proto.GossipSubOptimalFullMeshSize {
triggerImmediateConnection = true triggerImmediateConnection = true
} }
c.logger.Debug("adding discovered peer", logging.HostID("peer", p.AddrInfo.ID)) c.logger.Debug("adding discovered peer", logging.HostID("peerID", p.AddrInfo.ID))
c.pm.AddDiscoveredPeer(p, triggerImmediateConnection) c.pm.AddDiscoveredPeer(p, triggerImmediateConnection)
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
@ -198,13 +198,18 @@ func (c *PeerConnectionStrategy) canDialPeer(pi peer.AddrInfo) bool {
tv := val.(*connCacheData) tv := val.(*connCacheData)
now := time.Now() now := time.Now()
if now.Before(tv.nextTry) { if now.Before(tv.nextTry) {
c.logger.Debug("Skipping connecting to peer due to backoff strategy",
zap.Time("currentTime", now), zap.Time("until", tv.nextTry))
return false return false
} }
c.logger.Debug("Proceeding with connecting to peer",
zap.Time("currentTime", now), zap.Time("nextTry", tv.nextTry))
tv.nextTry = now.Add(tv.strat.Delay()) tv.nextTry = now.Add(tv.strat.Delay())
} else { } else {
cachedPeer = &connCacheData{strat: c.backoff()} cachedPeer = &connCacheData{strat: c.backoff()}
cachedPeer.nextTry = time.Now().Add(cachedPeer.strat.Delay()) cachedPeer.nextTry = time.Now().Add(cachedPeer.strat.Delay())
c.logger.Debug("Initializing connectionCache for peer ",
logging.HostID("peerID", pi.ID), zap.Time("until", cachedPeer.nextTry))
c.cache.Add(pi.ID, cachedPeer) c.cache.Add(pi.ID, cachedPeer)
} }
return true return true

View File

@ -112,7 +112,7 @@ func (pm *PeerManager) discoverPeersByPubsubTopics(pubsubTopics []string, proto
for _, shardInfo := range shardsInfo { for _, shardInfo := range shardsInfo {
err = pm.DiscoverAndConnectToPeers(ctx, shardInfo.ClusterID, shardInfo.ShardIDs[0], proto, maxCount) err = pm.DiscoverAndConnectToPeers(ctx, shardInfo.ClusterID, shardInfo.ShardIDs[0], proto, maxCount)
if err != nil { if err != nil {
pm.logger.Error("failed to discover and conenct to peers", zap.Error(err)) pm.logger.Error("failed to discover and connect to peers", zap.Error(err))
} }
} }
} else { } else {