diff options
author | Pedro Pombeiro <pombeirp@users.noreply.github.com> | 2018-02-21 01:20:33 +0800 |
---|---|---|
committer | Pedro Pombeiro <pombeirp@users.noreply.github.com> | 2018-02-21 20:23:53 +0800 |
commit | 34d94e22d9c9f3c2373a398269ecbba0139827d2 (patch) | |
tree | cdf7f057c6432dccde6a7f7f43cf34a06f78e78a | |
parent | 5603715c06998ff9ed30eb134c4398ad1439ef48 (diff) | |
download | dexon-34d94e22d9c9f3c2373a398269ecbba0139827d2.tar.gz dexon-34d94e22d9c9f3c2373a398269ecbba0139827d2.tar.zst dexon-34d94e22d9c9f3c2373a398269ecbba0139827d2.zip |
whisper: Fix race condition in whisperv6/peer.go
-rw-r--r-- | whisper/whisperv6/peer.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/whisper/whisperv6/peer.go b/whisper/whisperv6/peer.go index 4ef0f3c43..6d75290fd 100644 --- a/whisper/whisperv6/peer.go +++ b/whisper/whisperv6/peer.go @@ -19,6 +19,7 @@ package whisperv6 import ( "fmt" "math" + "sync" "time" "github.com/ethereum/go-ethereum/common" @@ -36,6 +37,7 @@ type Peer struct { trusted bool powRequirement float64 + bloomMu sync.Mutex bloomFilter []byte fullNode bool @@ -225,10 +227,14 @@ func (peer *Peer) notifyAboutBloomFilterChange(bloom []byte) error { } func (peer *Peer) bloomMatch(env *Envelope) bool { + peer.bloomMu.Lock() + defer peer.bloomMu.Unlock() return peer.fullNode || bloomFilterMatch(peer.bloomFilter, env.Bloom()) } func (peer *Peer) setBloomFilter(bloom []byte) { + peer.bloomMu.Lock() + defer peer.bloomMu.Unlock() peer.bloomFilter = bloom peer.fullNode = isFullNode(bloom) if peer.fullNode && peer.bloomFilter == nil { |