whisperv5: fix protocol of whisperv5 envelopes

This commit is contained in:
Andreas Schmid 2017-05-15 18:26:24 +02:00 committed by Victor Farazdagi
parent 4d1d5c7912
commit 01d3aa9fe1
1 changed files with 9 additions and 12 deletions

View File

@ -568,21 +568,18 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
log.Warn("unxepected status message received", "peer", p.peer.ID()) log.Warn("unxepected status message received", "peer", p.peer.ID())
case messagesCode: case messagesCode:
// decode the contained envelopes // decode the contained envelopes
var envelopes []*Envelope var envelope Envelope
if err := packet.Decode(&envelopes); err != nil { if err := packet.Decode(&envelope); err != nil {
log.Warn("failed to decode envelope, peer will be disconnected", "peer", p.peer.ID(), "err", err) log.Warn("failed to decode envelope, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid envelope") return errors.New("invalid envelope")
} }
// inject all envelopes into the internal pool cached, err := wh.add(&envelope)
for _, envelope := range envelopes {
cached, err := wh.add(envelope)
if err != nil { if err != nil {
log.Warn("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err) log.Warn("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid envelope") return errors.New("invalid envelope")
} }
if cached { if cached {
p.mark(envelope) p.mark(&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.