Clean up global discovery timer handing

This commit is contained in:
Jakob Borg 2014-11-19 01:03:43 +04:00
parent bbe7e6525d
commit fe2dd79838

View File

@ -258,10 +258,13 @@ func (d *Discoverer) sendExternalAnnouncements() {
buf = d.announcementPkt()
}
var bcastTick = time.Tick(d.globalBcastIntv)
var errTick <-chan time.Time
nextAnnouncement := time.NewTimer(0)
for {
select {
case <-d.stopGlobal:
return
sendOneAnnouncement := func() {
case <-nextAnnouncement.C:
var ok bool
if debug {
@ -290,31 +293,11 @@ func (d *Discoverer) sendExternalAnnouncements() {
d.extAnnounceOKmut.Unlock()
if ok {
errTick = nil
} else if errTick != nil {
errTick = time.Tick(d.errorRetryIntv)
nextAnnouncement.Reset(d.globalBcastIntv)
} else {
nextAnnouncement.Reset(d.errorRetryIntv)
}
}
// Announce once, immediately
sendOneAnnouncement()
loop:
for {
select {
case <-d.stopGlobal:
break loop
case <-errTick:
sendOneAnnouncement()
case <-bcastTick:
sendOneAnnouncement()
}
}
if debug {
l.Debugln("discover: stopping global")
}
}