Merge pull request #1488 from Crypt-iQ/server_race_1108
server: add addressesMtx to fix race condition
This commit is contained in:
commit
79943b2331
1 changed files with 5 additions and 0 deletions
|
@ -273,6 +273,7 @@ type serverPeer struct {
|
|||
sentAddrs bool
|
||||
isWhitelisted bool
|
||||
filter *bloom.Filter
|
||||
addressesMtx sync.RWMutex
|
||||
knownAddresses map[string]struct{}
|
||||
banScore connmgr.DynamicBanScore
|
||||
quit chan struct{}
|
||||
|
@ -305,14 +306,18 @@ func (sp *serverPeer) newestBlock() (*chainhash.Hash, int32, error) {
|
|||
// addKnownAddresses adds the given addresses to the set of known addresses to
|
||||
// the peer to prevent sending duplicate addresses.
|
||||
func (sp *serverPeer) addKnownAddresses(addresses []*wire.NetAddress) {
|
||||
sp.addressesMtx.Lock()
|
||||
for _, na := range addresses {
|
||||
sp.knownAddresses[addrmgr.NetAddressKey(na)] = struct{}{}
|
||||
}
|
||||
sp.addressesMtx.Unlock()
|
||||
}
|
||||
|
||||
// addressKnown true if the given address is already known to the peer.
|
||||
func (sp *serverPeer) addressKnown(na *wire.NetAddress) bool {
|
||||
sp.addressesMtx.RLock()
|
||||
_, exists := sp.knownAddresses[addrmgr.NetAddressKey(na)]
|
||||
sp.addressesMtx.RUnlock()
|
||||
return exists
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue