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

View file

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