From 9294ebbc125d39cee2e47251f0f8650511c9cdc4 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Fri, 16 Feb 2018 16:25:50 +0200 Subject: [PATCH] whisper: remove unnecessary advertised map and make advertisements more aggressive --- whisper/whisperv5/peer.go | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/whisper/whisperv5/peer.go b/whisper/whisperv5/peer.go index 93dc720eaf..fdabe6377f 100644 --- a/whisper/whisperv5/peer.go +++ b/whisper/whisperv5/peer.go @@ -34,23 +34,21 @@ type Peer struct { ws p2p.MsgReadWriter trusted bool - known *set.Set // Messages already known by the peer to avoid wasting bandwidth - advertised map[common.Hash]struct{} - hashes chan common.Hash - quit chan struct{} + known *set.Set // Messages already known by the peer to avoid wasting bandwidth + hashes chan common.Hash + quit chan struct{} } // newPeer creates a new whisper peer object, but does not run the handshake itself. func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer { return &Peer{ - host: host, - peer: remote, - ws: rw, - trusted: false, - known: set.New(), - advertised: make(map[common.Hash]struct{}), - hashes: make(chan common.Hash, 20), - quit: make(chan struct{}), + host: host, + peer: remote, + ws: rw, + trusted: false, + known: set.New(), + hashes: make(chan common.Hash, 20), + quit: make(chan struct{}), } } @@ -104,8 +102,8 @@ func (p *Peer) update() { // Start the tickers for the updates expire := time.NewTicker(expirationCycle) transmit := time.NewTicker(transmissionCycle) - hashesTransmit := time.NewTicker(100 * time.Millisecond) - hashes := make([]common.Hash, 0, 10) + hashesTransmit := time.NewTicker(20 * time.Millisecond) + hashes := make([]common.Hash, 0, 4) // Loop and transmit until termination is requested for { select { @@ -124,9 +122,6 @@ func (p *Peer) update() { } hashes = hashes[:0] case hash := <-p.hashes: - if _, ok := p.advertised[hash]; ok { - continue - } if p.known.Has(hash) { continue } @@ -201,13 +196,7 @@ func (p *Peer) broadcastHashes(hashes []common.Hash) error { return nil } log.Trace("broadcast", "hashes", hashes) - if err := p2p.Send(p.ws, hashesCode, hashes); err != nil { - return err - } - for _, hash := range hashes { - p.advertised[hash] = struct{}{} - } - return nil + return p2p.Send(p.ws, hashesCode, hashes) } func (p *Peer) ID() []byte {