This commit is contained in:
KusakabeSi 2021-10-27 01:41:13 +00:00
parent 056f7173a0
commit 91d8e92b39
2 changed files with 12 additions and 6 deletions

View File

@ -107,10 +107,11 @@ func (et *endpoint_trylist) Delete(url string) {
delete(et.trymap_p2p, url)
}
func (et *endpoint_trylist) GetNextTry() string {
func (et *endpoint_trylist) GetNextTry() (bool, string) {
et.RLock()
defer et.RUnlock()
var smallest *endpoint_tryitem
FastTry := true
for _, v := range et.trymap_super {
if smallest == nil || smallest.lastTry.After(v.lastTry) {
smallest = v
@ -128,13 +129,16 @@ func (et *endpoint_trylist) GetNextTry() string {
}
}
if smallest == nil {
return ""
return false, ""
}
smallest.lastTry = time.Now()
if smallest.firstTry.After(time.Time{}) {
smallest.firstTry = time.Now()
}
return smallest.URL
if smallest.firstTry.Add(et.timeout).Before(time.Now()) {
FastTry = false
}
return FastTry, smallest.URL
}
type Peer struct {

View File

@ -647,7 +647,7 @@ func (device *Device) RoutineSetEndpoint() {
//Peer alives
continue
} else {
connurl := thepeer.endpoint_trylist.GetNextTry()
FastTry, connurl := thepeer.endpoint_trylist.GetNextTry()
if connurl == "" {
continue
}
@ -657,8 +657,10 @@ func (device *Device) RoutineSetEndpoint() {
thepeer.endpoint_trylist.Delete(connurl)
continue
}
NextRun = true
go device.SendPing(thepeer, int(device.DRoute.ConnNextTry+1), 1, 1)
if FastTry {
NextRun = true
go device.SendPing(thepeer, int(device.DRoute.ConnNextTry+1), 1, 1)
}
}
}