aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/mailserver/mailserver.go
diff options
context:
space:
mode:
Diffstat (limited to 'whisper/mailserver/mailserver.go')
-rw-r--r--whisper/mailserver/mailserver.go44
1 files changed, 23 insertions, 21 deletions
diff --git a/whisper/mailserver/mailserver.go b/whisper/mailserver/mailserver.go
index a889c2bd2..57e6505ad 100644
--- a/whisper/mailserver/mailserver.go
+++ b/whisper/mailserver/mailserver.go
@@ -107,17 +107,16 @@ func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope)
return
}
- ok, lower, upper, topic := s.validateRequest(peer.ID(), request)
+ ok, lower, upper, bloom := s.validateRequest(peer.ID(), request)
if ok {
- s.processRequest(peer, lower, upper, topic)
+ s.processRequest(peer, lower, upper, bloom)
}
}
-func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, topic whisper.TopicType) []*whisper.Envelope {
+func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, bloom []byte) []*whisper.Envelope {
ret := make([]*whisper.Envelope, 0)
var err error
var zero common.Hash
- var empty whisper.TopicType
kl := NewDbKey(lower, zero)
ku := NewDbKey(upper, zero)
i := s.db.NewIterator(&util.Range{Start: kl.raw, Limit: ku.raw}, nil)
@@ -130,7 +129,7 @@ func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, to
log.Error(fmt.Sprintf("RLP decoding failed: %s", err))
}
- if topic == empty || envelope.Topic == topic {
+ if whisper.BloomFilterMatch(bloom, envelope.Bloom()) {
if peer == nil {
// used for test purposes
ret = append(ret, &envelope)
@@ -152,22 +151,16 @@ func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, to
return ret
}
-func (s *WMailServer) validateRequest(peerID []byte, request *whisper.Envelope) (bool, uint32, uint32, whisper.TopicType) {
- var topic whisper.TopicType
+func (s *WMailServer) validateRequest(peerID []byte, request *whisper.Envelope) (bool, uint32, uint32, []byte) {
if s.pow > 0.0 && request.PoW() < s.pow {
- return false, 0, 0, topic
+ return false, 0, 0, nil
}
f := whisper.Filter{KeySym: s.key}
decrypted := request.Open(&f)
if decrypted == nil {
log.Warn(fmt.Sprintf("Failed to decrypt p2p request"))
- return false, 0, 0, topic
- }
-
- if len(decrypted.Payload) < 8 {
- log.Warn(fmt.Sprintf("Undersized p2p request"))
- return false, 0, 0, topic
+ return false, 0, 0, nil
}
src := crypto.FromECDSAPub(decrypted.Src)
@@ -179,15 +172,24 @@ func (s *WMailServer) validateRequest(peerID []byte, request *whisper.Envelope)
// if !bytes.Equal(peerID, src) {
if src == nil {
log.Warn(fmt.Sprintf("Wrong signature of p2p request"))
- return false, 0, 0, topic
+ return false, 0, 0, nil
}
- lower := binary.BigEndian.Uint32(decrypted.Payload[:4])
- upper := binary.BigEndian.Uint32(decrypted.Payload[4:8])
-
- if len(decrypted.Payload) >= 8+whisper.TopicLength {
- topic = whisper.BytesToTopic(decrypted.Payload[8:])
+ var bloom []byte
+ payloadSize := len(decrypted.Payload)
+ if payloadSize < 8 {
+ log.Warn(fmt.Sprintf("Undersized p2p request"))
+ return false, 0, 0, nil
+ } else if payloadSize == 8 {
+ bloom = whisper.MakeFullNodeBloom()
+ } else if payloadSize < 8+whisper.BloomFilterSize {
+ log.Warn(fmt.Sprintf("Undersized bloom filter in p2p request"))
+ return false, 0, 0, nil
+ } else {
+ bloom = decrypted.Payload[8 : 8+whisper.BloomFilterSize]
}
- return true, lower, upper, topic
+ lower := binary.BigEndian.Uint32(decrypted.Payload[:4])
+ upper := binary.BigEndian.Uint32(decrypted.Payload[4:8])
+ return true, lower, upper, bloom
}