|
|
@ -36,7 +36,8 @@ type Peer struct { |
|
|
|
|
|
|
|
|
|
|
|
trusted bool |
|
|
|
trusted bool |
|
|
|
powRequirement float64 |
|
|
|
powRequirement float64 |
|
|
|
bloomFilter []byte // may contain nil in case of full node
|
|
|
|
bloomFilter []byte |
|
|
|
|
|
|
|
fullNode bool |
|
|
|
|
|
|
|
|
|
|
|
known *set.Set // Messages already known by the peer to avoid wasting bandwidth
|
|
|
|
known *set.Set // Messages already known by the peer to avoid wasting bandwidth
|
|
|
|
|
|
|
|
|
|
|
@ -53,6 +54,8 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer { |
|
|
|
powRequirement: 0.0, |
|
|
|
powRequirement: 0.0, |
|
|
|
known: set.New(), |
|
|
|
known: set.New(), |
|
|
|
quit: make(chan struct{}), |
|
|
|
quit: make(chan struct{}), |
|
|
|
|
|
|
|
bloomFilter: makeFullNodeBloom(), |
|
|
|
|
|
|
|
fullNode: true, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -118,11 +121,7 @@ func (peer *Peer) handshake() error { |
|
|
|
if sz != bloomFilterSize && sz != 0 { |
|
|
|
if sz != bloomFilterSize && sz != 0 { |
|
|
|
return fmt.Errorf("peer [%x] sent bad status message: wrong bloom filter size %d", peer.ID(), sz) |
|
|
|
return fmt.Errorf("peer [%x] sent bad status message: wrong bloom filter size %d", peer.ID(), sz) |
|
|
|
} |
|
|
|
} |
|
|
|
if isFullNode(bloom) { |
|
|
|
peer.setBloomFilter(bloom) |
|
|
|
peer.bloomFilter = nil |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
peer.bloomFilter = bloom |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -226,10 +225,21 @@ func (peer *Peer) notifyAboutBloomFilterChange(bloom []byte) error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (peer *Peer) bloomMatch(env *Envelope) bool { |
|
|
|
func (peer *Peer) bloomMatch(env *Envelope) bool { |
|
|
|
if peer.bloomFilter == nil { |
|
|
|
return peer.fullNode || bloomFilterMatch(peer.bloomFilter, env.Bloom()) |
|
|
|
// no filter - full node, accepts all envelops
|
|
|
|
} |
|
|
|
return true |
|
|
|
|
|
|
|
|
|
|
|
func (peer *Peer) setBloomFilter(bloom []byte) { |
|
|
|
|
|
|
|
peer.bloomFilter = bloom |
|
|
|
|
|
|
|
peer.fullNode = isFullNode(bloom) |
|
|
|
|
|
|
|
if peer.fullNode && peer.bloomFilter == nil { |
|
|
|
|
|
|
|
peer.bloomFilter = makeFullNodeBloom() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return bloomFilterMatch(peer.bloomFilter, env.Bloom()) |
|
|
|
func makeFullNodeBloom() []byte { |
|
|
|
|
|
|
|
bloom := make([]byte, bloomFilterSize) |
|
|
|
|
|
|
|
for i := 0; i < bloomFilterSize; i++ { |
|
|
|
|
|
|
|
bloom[i] = 0xFF |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return bloom |
|
|
|
} |
|
|
|
} |
|
|
|