Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e8f91b1af | |||
1049057f69 | |||
0622e00f64 | |||
c0f98d4a25 |
@ -172,43 +172,40 @@ func (m measurement) String() string {
|
||||
}
|
||||
|
||||
func (s *Server) probeUpstreamLatency() {
|
||||
if !s.once {
|
||||
s.once = true
|
||||
upstreams := s.upstreams()
|
||||
results := make([]measurement, len(upstreams))
|
||||
var wg sync.WaitGroup
|
||||
for idx, u := range upstreams {
|
||||
wg.Add(1)
|
||||
go func(idx int, u string) {
|
||||
defer wg.Done()
|
||||
// resolve a most-definitely cached record
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion("google.ch.", dns.TypeA)
|
||||
start := time.Now()
|
||||
_, _, err := s.client.Exchange(m, u)
|
||||
rtt := time.Since(start)
|
||||
if err != nil {
|
||||
// including unresponsive upstreams in results makes the update
|
||||
// code simpler:
|
||||
results[idx] = measurement{u, time.Duration(math.MaxInt64)}
|
||||
return
|
||||
}
|
||||
results[idx] = measurement{u, rtt}
|
||||
}(idx, u)
|
||||
}
|
||||
wg.Wait()
|
||||
// Re-order by resolving latency:
|
||||
sort.Slice(results, func(i, j int) bool {
|
||||
return results[i].rtt < results[j].rtt
|
||||
})
|
||||
log.Printf("probe results: %v %v", s.once, results)
|
||||
for idx, result := range results {
|
||||
upstreams[idx] = result.upstream
|
||||
}
|
||||
s.upstreamMu.Lock()
|
||||
defer s.upstreamMu.Unlock()
|
||||
s.upstream = upstreams
|
||||
upstreams := s.upstreams()
|
||||
results := make([]measurement, len(upstreams))
|
||||
var wg sync.WaitGroup
|
||||
for idx, u := range upstreams {
|
||||
wg.Add(1)
|
||||
go func(idx int, u string) {
|
||||
defer wg.Done()
|
||||
// resolve a most-definitely cached record
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion("google.ch.", dns.TypeA)
|
||||
start := time.Now()
|
||||
_, _, err := s.client.Exchange(m, u)
|
||||
rtt := time.Since(start)
|
||||
if err != nil {
|
||||
// including unresponsive upstreams in results makes the update
|
||||
// code simpler:
|
||||
results[idx] = measurement{u, time.Duration(math.MaxInt64)}
|
||||
return
|
||||
}
|
||||
results[idx] = measurement{u, rtt}
|
||||
}(idx, u)
|
||||
}
|
||||
wg.Wait()
|
||||
// Re-order by resolving latency:
|
||||
sort.Slice(results, func(i, j int) bool {
|
||||
return results[i].rtt < results[j].rtt
|
||||
})
|
||||
log.Printf("probe results: %v", results)
|
||||
for idx, result := range results {
|
||||
upstreams[idx] = result.upstream
|
||||
}
|
||||
s.upstreamMu.Lock()
|
||||
defer s.upstreamMu.Unlock()
|
||||
s.upstream = upstreams
|
||||
}
|
||||
|
||||
func (s *Server) hostByName(n lcHostname) (string, bool) {
|
||||
@ -553,6 +550,7 @@ func (s *Server) resolveSubname(domain string, q dns.Question) (dns.RR, error) {
|
||||
name := strings.TrimSuffix(q.Name, ".")
|
||||
name = strings.TrimSuffix(name, "."+string(s.domain)) // trim server domain
|
||||
name = strings.TrimSuffix(name, "."+strings.TrimSuffix(domain, "."+string(s.domain))) // trim function domain
|
||||
name = strings.TrimSuffix(name, ".lan") // trim function domain
|
||||
if ip, ok := s.subname(domain, name); ok {
|
||||
if q.Qtype == dns.TypeA && ip.IPv4.To4() != nil {
|
||||
return dns.NewRR(q.Name + " 3600 IN A " + ip.IPv4.String())
|
||||
|
Reference in New Issue
Block a user