diff options
author | gluk256 <gluk256@users.noreply.github.com> | 2017-12-21 17:31:44 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-12-21 17:31:44 +0800 |
commit | 9f1007e554e223b12354d3c91ae7fb040cf8b865 (patch) | |
tree | 4e8e3704b344ffd804f30586a0b0740cd598c307 /whisper/whisperv6/whisper.go | |
parent | 4b939c23e46d0160ba68c9b86d889041bb0905a0 (diff) | |
download | dexon-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar dexon-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.gz dexon-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.bz2 dexon-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.lz dexon-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.xz dexon-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.zst dexon-9f1007e554e223b12354d3c91ae7fb040cf8b865.zip |
whisper/whisperv6: message bundling (#15666)
Changed the communication protocol for ordinary message,
according to EIP 627. Messages will be send in bundles, i.e.
array of messages will be sent instead of single message.
Diffstat (limited to 'whisper/whisperv6/whisper.go')
-rw-r--r-- | whisper/whisperv6/whisper.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go index d09baab3f..2cc1e64f5 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go @@ -515,18 +515,26 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error { log.Warn("unxepected status message received", "peer", p.peer.ID()) case messagesCode: // decode the contained envelopes - var envelope Envelope - if err := packet.Decode(&envelope); err != nil { - log.Warn("failed to decode envelope, peer will be disconnected", "peer", p.peer.ID(), "err", err) - return errors.New("invalid envelope") + var envelopes []*Envelope + if err := packet.Decode(&envelopes); err != nil { + log.Warn("failed to decode envelopes, peer will be disconnected", "peer", p.peer.ID(), "err", err) + return errors.New("invalid envelopes") } - cached, err := wh.add(&envelope) - if err != nil { - log.Warn("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err) - return errors.New("invalid envelope") + + trouble := false + for _, env := range envelopes { + cached, err := wh.add(env) + if err != nil { + trouble = true + log.Error("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err) + } + if cached { + p.mark(env) + } } - if cached { - p.mark(&envelope) + + if trouble { + return errors.New("invalid envelope") } case p2pCode: // peer-to-peer message, sent directly to peer bypassing PoW checks, etc. |