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 { if err := p2p.Send(p.ws, messagesCode, bundle); err != nil {
return err return err
} }
@ -167,7 +168,6 @@ func (p *Peer) broadcast() error {
p.mark(e) p.mark(e)
} }
if len(bundle) > 0 {
log.Trace("broadcast", "num. messages", len(bundle)) log.Trace("broadcast", "num. messages", len(bundle))
} }
return nil 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) log.Warn("failed to decode envelopes, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid envelopes") return errors.New("invalid envelopes")
} }
var trouble error
for _, env := range envelopes { for _, env := range envelopes {
cached, err := wh.add(env) cached, err := wh.add(env)
if err != nil { if err != nil && trouble == nil {
log.Warn("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err) // only report the first occurring error
return errors.New("invalid envelope") trouble = err
} }
if cached { if cached {
p.mark(env) 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: case p2pCode:
// peer-to-peer message, sent directly to peer bypassing PoW checks, etc. // peer-to-peer message, sent directly to peer bypassing PoW checks, etc.
// this message is not supposed to be forwarded to other peers, and // this message is not supposed to be forwarded to other peers, and