mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 15:47:21 +00:00
eth/dropper: simplify sync status query
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
1647f51eed
commit
7a76bdd75e
1 changed files with 2 additions and 20 deletions
|
|
@ -40,8 +40,6 @@ const (
|
|||
// dropping when no more peers can be added. Larger numbers result in more
|
||||
// aggressive drop behavior.
|
||||
peerDropThreshold = 0
|
||||
// Sync status poll interval (no need to be too reactive here)
|
||||
syncCheckInterval = 60 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -158,27 +156,11 @@ func randomDuration(min, max time.Duration) time.Duration {
|
|||
func (cm *dropper) loop() {
|
||||
defer cm.wg.Done()
|
||||
|
||||
// Set up periodic timer to pull syncing status.
|
||||
// We could get syncing status in a few ways:
|
||||
// - poll the sync status (we use this for now)
|
||||
// - subscribe to Downloader.mux
|
||||
// - subscribe to DownloaderAPI (which itself polls the sync status)
|
||||
syncing := cm.syncingFunc()
|
||||
syncCheckTimer := time.NewTimer(syncCheckInterval)
|
||||
defer syncCheckTimer.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-syncCheckTimer.C:
|
||||
// Update info about syncing status, and rearm the timers.
|
||||
syncingNew := cm.syncingFunc()
|
||||
if syncing != syncingNew {
|
||||
// Syncing status changed, we might need to update the timers.
|
||||
syncing = syncingNew
|
||||
}
|
||||
syncCheckTimer.Reset(syncCheckInterval)
|
||||
case <-cm.peerDropTimer.C:
|
||||
if !syncing {
|
||||
// Drop a random peer if we are not syncing and the peer count is close to the limit.
|
||||
if !cm.syncingFunc() {
|
||||
cm.dropRandomPeer()
|
||||
}
|
||||
cm.peerDropTimer.Reset(randomDuration(peerDropIntervalMin, peerDropIntervalMax))
|
||||
|
|
|
|||
Loading…
Reference in a new issue