Initialize the server rtt with the startup measurement

This commit is contained in:
Frank Denis 2019-06-03 17:07:30 +02:00
parent 30f2a4fd6b
commit b63df9cdfa
1 changed files with 5 additions and 3 deletions

View File

@ -106,6 +106,7 @@ func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp s
dlog.Fatalf("[%s] != [%s]", name, newServer.Name)
}
newServer.rtt = ewma.NewMovingAverage(RTTEwmaDecay)
newServer.rtt.Set(float64(newServer.initialRtt))
serversInfo.Lock()
defer serversInfo.Unlock()
previousIndex = -1
@ -343,10 +344,11 @@ func (serversInfo *ServersInfo) fetchDoHServerInfo(proxy *Proxy, name string, st
respBody[0] != 0xca || respBody[1] != 0xfe || respBody[4] != 0x00 || respBody[5] != 0x01 {
return ServerInfo{}, errors.New("Webserver returned an unexpected response")
}
xrtt := int(rtt.Nanoseconds() / 1000000)
if isNew {
dlog.Noticef("[%s] OK (DoH) - rtt: %dms", name, rtt.Nanoseconds()/1000000)
dlog.Noticef("[%s] OK (DoH) - rtt: %dms", name, xrtt)
} else {
dlog.Infof("[%s] OK (DoH) - rtt: %dms", name, rtt.Nanoseconds()/1000000)
dlog.Infof("[%s] OK (DoH) - rtt: %dms", name, xrtt)
}
return ServerInfo{
Proto: stamps.StampProtoTypeDoH,
@ -354,7 +356,7 @@ func (serversInfo *ServersInfo) fetchDoHServerInfo(proxy *Proxy, name string, st
Timeout: proxy.timeout,
URL: url,
HostName: stamp.ProviderName,
initialRtt: int(rtt.Nanoseconds() / 1000000),
initialRtt: xrtt,
useGet: useGet,
}, nil
}