mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
whisper: remove unnecessary advertised map and make advertisements more aggressive
This commit is contained in:
parent
f0de0f2230
commit
9294ebbc12
1 changed files with 13 additions and 24 deletions
|
|
@ -35,7 +35,6 @@ type Peer struct {
|
||||||
trusted bool
|
trusted bool
|
||||||
|
|
||||||
known *set.Set // Messages already known by the peer to avoid wasting bandwidth
|
known *set.Set // Messages already known by the peer to avoid wasting bandwidth
|
||||||
advertised map[common.Hash]struct{}
|
|
||||||
hashes chan common.Hash
|
hashes chan common.Hash
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +47,6 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
|
||||||
ws: rw,
|
ws: rw,
|
||||||
trusted: false,
|
trusted: false,
|
||||||
known: set.New(),
|
known: set.New(),
|
||||||
advertised: make(map[common.Hash]struct{}),
|
|
||||||
hashes: make(chan common.Hash, 20),
|
hashes: make(chan common.Hash, 20),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
@ -104,8 +102,8 @@ func (p *Peer) update() {
|
||||||
// Start the tickers for the updates
|
// Start the tickers for the updates
|
||||||
expire := time.NewTicker(expirationCycle)
|
expire := time.NewTicker(expirationCycle)
|
||||||
transmit := time.NewTicker(transmissionCycle)
|
transmit := time.NewTicker(transmissionCycle)
|
||||||
hashesTransmit := time.NewTicker(100 * time.Millisecond)
|
hashesTransmit := time.NewTicker(20 * time.Millisecond)
|
||||||
hashes := make([]common.Hash, 0, 10)
|
hashes := make([]common.Hash, 0, 4)
|
||||||
// Loop and transmit until termination is requested
|
// Loop and transmit until termination is requested
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
@ -124,9 +122,6 @@ func (p *Peer) update() {
|
||||||
}
|
}
|
||||||
hashes = hashes[:0]
|
hashes = hashes[:0]
|
||||||
case hash := <-p.hashes:
|
case hash := <-p.hashes:
|
||||||
if _, ok := p.advertised[hash]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if p.known.Has(hash) {
|
if p.known.Has(hash) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -201,13 +196,7 @@ func (p *Peer) broadcastHashes(hashes []common.Hash) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Trace("broadcast", "hashes", hashes)
|
log.Trace("broadcast", "hashes", hashes)
|
||||||
if err := p2p.Send(p.ws, hashesCode, hashes); err != nil {
|
return p2p.Send(p.ws, hashesCode, hashes)
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, hash := range hashes {
|
|
||||||
p.advertised[hash] = struct{}{}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) ID() []byte {
|
func (p *Peer) ID() []byte {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue