Skip to content

Commit

Permalink
server: fix wireToAddrmgrNetAddress data race.
Browse files Browse the repository at this point in the history
This fixes a data race for the network address passed into
wireToAddrmgrNetAddress.
  • Loading branch information
dnldd authored and davecgh committed Oct 20, 2021
1 parent cdf881d commit 0076cea
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions peer/go.mod
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions peer/go.sum
Expand Up @@ -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=
Expand Down
10 changes: 7 additions & 3 deletions peer/peer.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0076cea

Please sign in to comment.