Skip to content

Commit

Permalink
simplify stop and remove peer
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jun 25, 2024
1 parent ff05627 commit c59c930
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,25 +440,16 @@ func (sw *Switch) stopAndRemovePeer(peer Peer, reason interface{}) {
// https://github.com/tendermint/tendermint/issues/3338
if sw.peers.Remove(peer) {
sw.metrics.Peers.Add(float64(-1))
if peer.IsOutbound() {
if sw.config.RegionAware {
region, err := sw.addrBook.GetAddressRegion(peer.SocketAddr())
if err != nil {
sw.Logger.Error("error getting region of peer when stopping peer", "peer", peer.ID(), "err", err)
return
}
if region != sw.MyRegion {
sw.CurrentNumOutboundPeersInOtherRegion--
}
if sw.config.RegionAware {
region, err := sw.addrBook.GetAddressRegion(peer.SocketAddr())
if err != nil {
sw.Logger.Error("error getting region of peer when stopping peer", "peer", peer.ID(), "err", err)
return
}
} else {
if sw.config.RegionAware {
region, err := sw.addrBook.GetAddressRegion(peer.SocketAddr())
if err != nil {
sw.Logger.Error("error getting region of peer when stopping peer", "peer", peer.ID(), "err", err)
return
}
if region != sw.MyRegion {
if region != sw.MyRegion {
if peer.IsOutbound() {
sw.CurrentNumOutboundPeersInOtherRegion--
} else {
sw.CurrentNumInboundPeersInOtherRegion--
}
}
Expand Down

0 comments on commit c59c930

Please sign in to comment.