From 8c981e4ef299d5376b6ebe87fa4dafccb83e0117 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 10 Aug 2018 23:11:19 -0500 Subject: [PATCH] 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. --- server.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 7fe114b1..42f34da5 100644 --- a/server.go +++ b/server.go @@ -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 @@ -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} @@ -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