whisper: remove unnecessary advertised map and make advertisements more aggressive

This commit is contained in:
Dmitry Shulyak 2018-02-16 16:25:50 +02:00
parent f0de0f2230
commit 9294ebbc12

View file

@ -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 {