Skip to content

Commit

Permalink
feat: emit an event in EventBus upon dial error
Browse files Browse the repository at this point in the history
  • Loading branch information
adklempner committed Sep 19, 2024
1 parent 991e872 commit 322633b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions waku/v2/peermanager/peer_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ func (c *PeerConnectionStrategy) dialPeers() {
}
}

type DialError struct {
Err error
PeerID peer.ID
}

func (c *PeerConnectionStrategy) dialPeer(pi peer.AddrInfo, sem chan struct{}) {
defer c.WaitGroup().Done()
ctx, cancel := context.WithTimeout(c.Context(), c.dialTimeout)
Expand All @@ -281,6 +286,15 @@ func (c *PeerConnectionStrategy) dialPeer(pi peer.AddrInfo, sem chan struct{}) {
c.addConnectionBackoff(pi.ID)
c.host.Peerstore().(wps.WakuPeerstore).AddConnFailure(pi.ID)
c.logger.Warn("connecting to peer", logging.HostID("peerID", pi.ID), zap.Error(err))
em, emitterErr := c.host.EventBus().Emitter(new(DialError))
if emitterErr != nil {
c.logger.Error("error creating DialError emitter", zap.Error(emitterErr))
}
emitterErr = em.Emit(DialError{Err: err, PeerID: pi.ID})
if emitterErr != nil {
c.logger.Error("error emitting DialError in event bus", zap.Error(emitterErr))
}
defer em.Close()
}
c.host.Peerstore().(wps.WakuPeerstore).ResetConnFailures(pi.ID)
<-sem
Expand Down

0 comments on commit 322633b

Please sign in to comment.