fix(webconnectivity@v0.5): fetch HTTP only using system-resolver addrs (#935)

While there, change the emoji logger to emit whitespace on info logs. This makes warnings stand out even more.

Closes https://github.com/ooni/probe/issues/2258
This commit is contained in:
Simone Basso 2022-09-05 13:33:59 +02:00 committed by GitHub
commit 3b24b1196d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 92 additions and 43 deletions

View file

@ -2,6 +2,26 @@ package webconnectivity
import "sync"
// DNSEntry is an entry in the DNS cache.
type DNSEntry struct {
// Addr is the cached address
Addr string
// Flags contains flags
Flags int64
}
const (
// DNSAddrFlagSystemResolver means we discovered this addr using the system resolver.
DNSAddrFlagSystemResolver = 1 << iota
// DNSAddrFlagUDP means we discovered this addr using the UDP resolver.
DNSAddrFlagUDP
// DNSAddrFlagHTTPS means we discovered this addr using the DNS-over-HTTPS resolver.
DNSAddrFlagHTTPS
)
// DNSCache wraps a model.Resolver to provide DNS caching.
//
// The zero value is invalid; please, use NewDNSCache to construct.
@ -10,11 +30,11 @@ type DNSCache struct {
mu *sync.Mutex
// values contains already resolved values.
values map[string][]string
values map[string][]DNSEntry
}
// Get gets values from the cache
func (c *DNSCache) Get(domain string) ([]string, bool) {
func (c *DNSCache) Get(domain string) ([]DNSEntry, bool) {
c.mu.Lock()
values, found := c.values[domain]
c.mu.Unlock()
@ -22,7 +42,7 @@ func (c *DNSCache) Get(domain string) ([]string, bool) {
}
// Set inserts into the cache
func (c *DNSCache) Set(domain string, values []string) {
func (c *DNSCache) Set(domain string, values []DNSEntry) {
c.mu.Lock()
c.values[domain] = values
c.mu.Unlock()
@ -32,6 +52,6 @@ func (c *DNSCache) Set(domain string, values []string) {
func NewDNSCache() *DNSCache {
return &DNSCache{
mu: &sync.Mutex{},
values: map[string][]string{},
values: map[string][]DNSEntry{},
}
}