mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
whisper: process all received envelopes, do not send empty bundle
This commit is contained in:
parent
9020bfbbe5
commit
b7ecc495c3
2 changed files with 20 additions and 13 deletions
|
|
@ -157,17 +157,17 @@ func (p *Peer) broadcast() error {
|
|||
}
|
||||
}
|
||||
|
||||
// transmit the unknown batch (potentially empty)
|
||||
if err := p2p.Send(p.ws, messagesCode, bundle); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// mark envelopes only if they were successfully sent
|
||||
for _, e := range bundle {
|
||||
p.mark(e)
|
||||
}
|
||||
|
||||
if len(bundle) > 0 {
|
||||
// transmit the batch of envelopes
|
||||
if err := p2p.Send(p.ws, messagesCode, bundle); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// mark envelopes only if they were successfully sent
|
||||
for _, e := range bundle {
|
||||
p.mark(e)
|
||||
}
|
||||
|
||||
log.Trace("broadcast", "num. messages", len(bundle))
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue