mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 11:20:45 +00:00
p2p/tracker: clean up code
This commit is contained in:
parent
1a482cac6a
commit
e89ff4a68a
1 changed files with 5 additions and 4 deletions
|
|
@ -139,7 +139,7 @@ func (t *Tracker) clean() {
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
if t.expire == nil {
|
if t.expire == nil {
|
||||||
return
|
return // Tracker was stopped.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expire anything within a certain threshold (might be no items at all if
|
// Expire anything within a certain threshold (might be no items at all if
|
||||||
|
|
@ -166,14 +166,15 @@ func (t *Tracker) clean() {
|
||||||
t.schedule()
|
t.schedule()
|
||||||
}
|
}
|
||||||
|
|
||||||
// schedule starts a timer to trigger on the expiration of the first network
|
// schedule starts a timer to trigger on the expiration of the first network packet.
|
||||||
// packet.
|
|
||||||
func (t *Tracker) schedule() {
|
func (t *Tracker) schedule() {
|
||||||
if t.expire.Len() == 0 {
|
if t.expire.Len() == 0 {
|
||||||
t.wake = nil
|
t.wake = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.wake = time.AfterFunc(time.Until(t.pending[t.expire.Front().Value.(uint64)].time.Add(t.timeout)), t.clean)
|
nextID := t.expire.Front().Value.(uint64)
|
||||||
|
nextTime := t.pending[nextID].time
|
||||||
|
t.wake = time.AfterFunc(time.Until(nextTime.Add(t.timeout)), t.clean)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop reclaims resources of the tracker.
|
// Stop reclaims resources of the tracker.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue