Skip to content

Commit

Permalink
fix: add peer addresses on expiry if peer is discovered again (#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem authored Jun 18, 2024
1 parent b3b8f70 commit a062083
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions waku/v2/peermanager/peer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ func (pm *PeerManager) AddDiscoveredPeer(p service.PeerData, connectNow bool) {
//Check if the peer is already present, if so skip adding
_, err := pm.host.Peerstore().(wps.WakuPeerstore).Origin(p.AddrInfo.ID)
if err == nil {
//Add addresses if existing addresses have expired
existingAddrs := pm.host.Peerstore().Addrs(p.AddrInfo.ID)
if len(existingAddrs) == 0 {
pm.host.Peerstore().AddAddrs(p.AddrInfo.ID, p.AddrInfo.Addrs, peerstore.AddressTTL)
}
enr, err := pm.host.Peerstore().(wps.WakuPeerstore).ENR(p.AddrInfo.ID)
// Verifying if the enr record is more recent (DiscV5 and peer exchange can return peers already seen)
if err == nil {
Expand Down Expand Up @@ -474,8 +479,8 @@ func (pm *PeerManager) AddDiscoveredPeer(p service.PeerData, connectNow bool) {
}
}

// addPeer adds peer to only the peerStore.
// It also sets additional metadata such as origin, ENR and supported protocols
// addPeer adds peer to the peerStore.
// It also sets additional metadata such as origin and supported protocols
func (pm *PeerManager) addPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubSubTopics []string, protocols ...protocol.ID) error {
if pm.maxPeers <= pm.host.Peerstore().Peers().Len() {
pm.logger.Error("could not add peer as peer store capacity is reached", logging.HostID("peer", ID), zap.Int("capacity", pm.maxPeers))
Expand Down
4 changes: 2 additions & 2 deletions waku/v2/protocol/relay/waku_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,15 @@ func (w *WakuRelay) unsubscribeFromPubsubTopic(topicData *pubsubTopicSubscriptio

err := topicData.topic.Close()
if err != nil {
w.log.Error("failed to close the pubsubTopic", zap.String("topic", pubSubTopic))
w.log.Error("failed to close the pubsubTopic", zap.String("topic", pubSubTopic), zap.Error(err))
return err
}

w.RemoveTopicValidator(pubSubTopic)

err = w.pubsub.UnregisterTopicValidator(pubSubTopic)
if err != nil {
w.log.Error("failed to unregister topic validator", zap.String("topic", pubSubTopic))
w.log.Error("failed to unregister topic validator", zap.String("topic", pubSubTopic), zap.Error(err))
return err
}

Expand Down

0 comments on commit a062083

Please sign in to comment.