Skip to content

Commit

Permalink
Use net.IP.Equal in peer.filterPathFromSourcePeer
Browse files Browse the repository at this point in the history
- Compares IPs using net.IP.Equal instead of using a string comparison
  in order to avoid unnecessary allocations.

- Adds peer.routerID to access IP, called by peer.RouterID.
  • Loading branch information
Britton Payne authored and fujita committed Mar 2, 2024
1 parent 003745a commit 3448996
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/server/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ func (peer *peer) ID() string {
return peer.fsm.pConf.State.NeighborAddress
}

func (peer *peer) RouterID() string {
func (peer *peer) routerID() net.IP {
peer.fsm.lock.RLock()
defer peer.fsm.lock.RUnlock()
if peer.fsm.peerInfo.ID != nil {
return peer.fsm.peerInfo.ID.String()
return peer.fsm.peerInfo.ID
}

func (peer *peer) RouterID() string {
if id := peer.routerID(); id != nil {
return id.String()
}
return ""
}
Expand Down Expand Up @@ -377,7 +381,7 @@ func (peer *peer) filterPathFromSourcePeer(path, old *table.Path) *table.Path {
// (whichever is not the new best path), we fail to send a withdraw towards
// B, and the route is "stuck".
// TODO: considerations for RFC6286
if peer.RouterID() != path.GetSource().ID.String() {
if !peer.routerID().Equal(path.GetSource().ID) {
return path
}

Expand Down

0 comments on commit 3448996

Please sign in to comment.