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/peer.go | |
parent | 4b939c23e46d0160ba68c9b86d889041bb0905a0 (diff) | |
download | go-tangerine-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar go-tangerine-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.gz go-tangerine-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.bz2 go-tangerine-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.lz go-tangerine-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.xz go-tangerine-9f1007e554e223b12354d3c91ae7fb040cf8b865.tar.zst go-tangerine-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/peer.go')
-rw-r--r-- | whisper/whisperv6/peer.go | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/whisper/whisperv6/peer.go b/whisper/whisperv6/peer.go index ac7b3b12b..ffc39505e 100644 --- a/whisper/whisperv6/peer.go +++ b/whisper/whisperv6/peer.go @@ -149,21 +149,26 @@ func (peer *Peer) expire() { // broadcast iterates over the collection of envelopes and transmits yet unknown // ones over the network. func (p *Peer) broadcast() error { - var cnt int envelopes := p.host.Envelopes() + bundle := make([]*Envelope, 0, len(envelopes)) for _, envelope := range envelopes { if !p.marked(envelope) { - err := p2p.Send(p.ws, messagesCode, envelope) - if err != nil { - return err - } else { - p.mark(envelope) - cnt++ - } + bundle = append(bundle, envelope) } } - if cnt > 0 { - log.Trace("broadcast", "num. messages", cnt) + + 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 } |