whisper: process all received envelopes, do not send empty bundle

This commit is contained in:
Vlad 2017-12-20 09:18:48 +02:00
parent 9020bfbbe5
commit b7ecc495c3
2 changed files with 20 additions and 13 deletions

View file

@ -157,7 +157,8 @@ func (p *Peer) broadcast() error {
}
}
// transmit the unknown batch (potentially empty)
if len(bundle) > 0 {
// transmit the batch of envelopes
if err := p2p.Send(p.ws, messagesCode, bundle); err != nil {
return err
}
@ -167,7 +168,6 @@ func (p *Peer) broadcast() error {
p.mark(e)
}
if len(bundle) > 0 {
log.Trace("broadcast", "num. messages", len(bundle))
}
return nil

View file

@ -520,16 +520,23 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
log.Warn("failed to decode envelopes, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid envelopes")
}
var trouble error
for _, env := range envelopes {
cached, err := wh.add(env)
if err != nil {
log.Warn("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid envelope")
if err != nil && trouble == nil {
// only report the first occurring error
trouble = err
}
if cached {
p.mark(env)
}
}
if trouble != nil {
log.Warn("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", trouble)
return errors.New("invalid envelope")
}
case p2pCode:
// peer-to-peer message, sent directly to peer bypassing PoW checks, etc.
// this message is not supposed to be forwarded to other peers, and