Skip to content

Commit

Permalink
Correctly handle Peerstore entries
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Apr 30, 2024
1 parent ab9f161 commit 756e3f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 0 additions & 2 deletions pkg/network/p2p/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func (m *Manager) DialPeer(ctx context.Context, peer *network.Peer) error {
return ierrors.WithMessagef(network.ErrMaxAutopeeringPeersReached, "peer %s is not allowed", peer.ID.String())
}

// Set the current peer's multiaddresses to the peerstore, so that they can be used for dialing.
m.libp2pHost.Peerstore().SetAddrs(peer.ID, m.addrFilter(peer.PeerAddresses), 10*time.Minute)
cancelCtx := ctx

stream, err := m.P2PHost().NewStream(cancelCtx, peer.ID, network.CoreProtocolID)
Expand Down
5 changes: 5 additions & 0 deletions pkg/network/p2p/manualpeering/manualpeering.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (m *Manager) RemovePeer(peerID peer.ID) error {
return ierrors.Wrapf(err, "failed to drop known peer %s in the gossip layer", peerID.String())
}

m.networkManager.P2PHost().Peerstore().RemovePeer(peerID)

return nil
}

Expand Down Expand Up @@ -179,6 +181,9 @@ func (m *Manager) AddPeer(multiAddr multiaddr.Multiaddr) (*network.Peer, error)
return peer, nil
}

// Set the current peer's multiaddresses to the peerstore, so that they can be used for dialing.
m.networkManager.P2PHost().Peerstore().SetAddrs(newPeer.ID, newPeer.PeerAddresses, 10*time.Minute)

m.logger.LogInfof("Adding new peer to the list of known peers in manual peering %s", newPeer)
m.knownPeers[newPeer.ID] = newPeer

Expand Down

0 comments on commit 756e3f7

Please sign in to comment.