server: Use local addr var in version handler.

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.
This commit is contained in:
Dave Collins 2018-08-10 23:11:19 -05:00
parent c8b9fab820
commit 8c981e4ef2
No known key found for this signature in database
GPG key ID: B8904D9D9C93D1F2

View file

@ -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 // it is updated regardless in the case a new minimum protocol version is
// enforced and the remote node has not upgraded yet. // enforced and the remote node has not upgraded yet.
isInbound := sp.Inbound() isInbound := sp.Inbound()
remoteAddr := sp.NA()
addrManager := sp.server.addrManager addrManager := sp.server.addrManager
if !cfg.SimNet && !isInbound { 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 // Ignore peers that have a protcol version that is too old. The peer
@ -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. // connections and it believes itself to be close to the best known tip.
if !cfg.DisableListen && sp.server.syncManager.IsCurrent() { if !cfg.DisableListen && sp.server.syncManager.IsCurrent() {
// Get address that best matches. // Get address that best matches.
lna := addrManager.GetBestLocalAddress(sp.NA()) lna := addrManager.GetBestLocalAddress(remoteAddr)
if addrmgr.IsRoutable(lna) { if addrmgr.IsRoutable(lna) {
// Filter addresses the peer already knows about. // Filter addresses the peer already knows about.
addresses := []*wire.NetAddress{lna} addresses := []*wire.NetAddress{lna}
@ -474,7 +475,7 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgRej
} }
// Mark the address as a known good address. // 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 // Add the remote peer time as a sample for creating an offset against