server: fix wireToAddrmgrNetAddress data race.

This fixes a data race for the network address passed into
wireToAddrmgrNetAddress.
This commit is contained in:
Donald Adu-Poku 2021-10-19 23:46:00 +00:00 committed by Dave Collins
parent cdf881d9ce
commit 0076cea6ff
4 changed files with 11 additions and 4 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.16
require (
github.com/davecgh/go-spew v1.1.1
github.com/decred/base58 v1.0.3
github.com/decred/dcrd/addrmgr/v2 v2.0.0-20210802141345-893802fc06b0
github.com/decred/dcrd/addrmgr/v2 v2.0.0-20211005210707-931a579e127b
github.com/decred/dcrd/bech32 v1.1.1
github.com/decred/dcrd/blockchain/stake/v4 v4.0.0-20210906140327-598bf66f24a6
github.com/decred/dcrd/blockchain/standalone/v2 v2.0.0

View File

@ -4,6 +4,7 @@ go 1.11
require (
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/addrmgr/v2 v2.0.0-20211005210707-931a579e127b
github.com/decred/dcrd/chaincfg/chainhash v1.0.2
github.com/decred/dcrd/lru v1.1.0
github.com/decred/dcrd/txscript/v4 v4.0.0-20210129190127-4ebd135a82f1

View File

@ -6,6 +6,8 @@ github.com/dchest/siphash v1.2.2 h1:9DFz8tQwl9pTVt5iok/9zKyzA1Q6bRGiF3HPiEEVr9I=
github.com/dchest/siphash v1.2.2/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
github.com/decred/base58 v1.0.3 h1:KGZuh8d1WEMIrK0leQRM47W85KqCAdl2N+uagbctdDI=
github.com/decred/base58 v1.0.3/go.mod h1:pXP9cXCfM2sFLb2viz2FNIdeMWmZDBKG3ZBYbiSM78E=
github.com/decred/dcrd/addrmgr/v2 v2.0.0-20211005210707-931a579e127b h1:T2pIvkj+0DRUxfw0e9k4XvvNHGELAaertBpTO3Ks0KI=
github.com/decred/dcrd/addrmgr/v2 v2.0.0-20211005210707-931a579e127b/go.mod h1:pFpkgqaKOORZmZ+GwO719PaXqBvBqt5ATUbMQ3QgYl8=
github.com/decred/dcrd/chaincfg/chainhash v1.0.2 h1:rt5Vlq/jM3ZawwiacWjPa+smINyLRN07EO0cNBV6DGU=
github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D9NuaFd+zGyNeIKgrhCXK60=
github.com/decred/dcrd/chaincfg/v3 v3.0.0 h1:+TFbu7ZmvBwM+SZz5mrj6cun9ts/6DAL5sqnsaFBHGQ=

View File

@ -579,10 +579,14 @@ func (p *Peer) ID() int32 {
// This function is safe for concurrent access.
func (p *Peer) NA() *wire.NetAddress {
p.flagsMtx.Lock()
na := p.na
if p.na == nil {
p.flagsMtx.Unlock()
return nil
}
na := *p.na
p.flagsMtx.Unlock()
return na
return &na
}
// Addr returns the peer address.
@ -1852,7 +1856,7 @@ func (p *Peer) localVersionMsg() (*wire.MsgVersion, error) {
}
}
theirNA := p.na
theirNA := p.NA()
// If we are behind a proxy and the connection comes from the proxy then
// we return an unroutable address as their address. This is to prevent