feat(webconnectivity): long-term-evolution prototype (#882)
See https://github.com/ooni/probe/issues/2237
This commit is contained in:
parent
9ba6f8dcbb
commit
1a1d3126ae
20 changed files with 3067 additions and 1 deletions
37
internal/experiment/webconnectivity/dnscache.go
Normal file
37
internal/experiment/webconnectivity/dnscache.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package webconnectivity
|
||||
|
||||
import "sync"
|
||||
|
||||
// DNSCache wraps a model.Resolver to provide DNS caching.
|
||||
//
|
||||
// The zero value is invalid; please, use NewDNSCache to construct.
|
||||
type DNSCache struct {
|
||||
// mu provides mutual exclusion.
|
||||
mu *sync.Mutex
|
||||
|
||||
// values contains already resolved values.
|
||||
values map[string][]string
|
||||
}
|
||||
|
||||
// Get gets values from the cache
|
||||
func (c *DNSCache) Get(domain string) ([]string, bool) {
|
||||
c.mu.Lock()
|
||||
values, found := c.values[domain]
|
||||
c.mu.Unlock()
|
||||
return values, found
|
||||
}
|
||||
|
||||
// Set inserts into the cache
|
||||
func (c *DNSCache) Set(domain string, values []string) {
|
||||
c.mu.Lock()
|
||||
c.values[domain] = values
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
// NewDNSCache creates a new DNSCache instance.
|
||||
func NewDNSCache() *DNSCache {
|
||||
return &DNSCache{
|
||||
mu: &sync.Mutex{},
|
||||
values: map[string][]string{},
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue