mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Clean up global discovery timer handing
This commit is contained in:
parent
bbe7e6525d
commit
fe2dd79838
@ -258,10 +258,13 @@ func (d *Discoverer) sendExternalAnnouncements() {
|
|||||||
buf = d.announcementPkt()
|
buf = d.announcementPkt()
|
||||||
}
|
}
|
||||||
|
|
||||||
var bcastTick = time.Tick(d.globalBcastIntv)
|
nextAnnouncement := time.NewTimer(0)
|
||||||
var errTick <-chan time.Time
|
for {
|
||||||
|
select {
|
||||||
|
case <-d.stopGlobal:
|
||||||
|
return
|
||||||
|
|
||||||
sendOneAnnouncement := func() {
|
case <-nextAnnouncement.C:
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
@ -290,31 +293,11 @@ func (d *Discoverer) sendExternalAnnouncements() {
|
|||||||
d.extAnnounceOKmut.Unlock()
|
d.extAnnounceOKmut.Unlock()
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
errTick = nil
|
nextAnnouncement.Reset(d.globalBcastIntv)
|
||||||
} else if errTick != nil {
|
} else {
|
||||||
errTick = time.Tick(d.errorRetryIntv)
|
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")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user