Skip to content

Commit

Permalink
server: Use local addr var in version handler.
Browse files Browse the repository at this point in the history
This modifies the OnVersion handler for server peers to use a local
variable for the remote address of the peer in order to avoid grabbing
the mutex multiple times.

There are no functional changes.

Backported from Decred.
  • Loading branch information
davecgh committed Aug 11, 2018
1 parent 06f8b3e commit e0b9c2b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server.go
Expand Up @@ -406,9 +406,10 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgRej
// it is updated regardless in the case a new minimum protocol version is
// enforced and the remote node has not upgraded yet.
isInbound := sp.Inbound()
remoteAddr := sp.NA()
addrManager := sp.server.addrManager
if !cfg.SimNet && !isInbound {
addrManager.SetServices(sp.NA(), msg.Services)
addrManager.SetServices(remoteAddr, msg.Services)
}

// Ignore peers that have a protcol version that is too old. The peer
Expand Down Expand Up @@ -457,7 +458,7 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgRej
// connections and it believes itself to be close to the best known tip.
if !cfg.DisableListen && sp.server.syncManager.IsCurrent() {
// Get address that best matches.
lna := addrManager.GetBestLocalAddress(sp.NA())
lna := addrManager.GetBestLocalAddress(remoteAddr)
if addrmgr.IsRoutable(lna) {
// Filter addresses the peer already knows about.
addresses := []*wire.NetAddress{lna}
Expand All @@ -474,7 +475,7 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgRej
}

// Mark the address as a known good address.
addrManager.Good(sp.NA())
addrManager.Good(remoteAddr)
}

// Add the remote peer time as a sample for creating an offset against
Expand Down

0 comments on commit e0b9c2b

Please sign in to comment.