cleanup(netx): remove subpackages and unnecessary code (#788)
This pull request consists of several small and obvious cleanups in the netx directory. See https://github.com/ooni/probe/issues/2121
This commit is contained in:
parent
9354191b85
commit
1cb820b19d
17 changed files with 201 additions and 815 deletions
|
|
@ -1,49 +0,0 @@
|
|||
package resolver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
// CacheResolver is a resolver that caches successful replies.
|
||||
type CacheResolver struct {
|
||||
ReadOnly bool
|
||||
model.Resolver
|
||||
mu sync.Mutex
|
||||
cache map[string][]string
|
||||
}
|
||||
|
||||
// LookupHost implements Resolver.LookupHost
|
||||
func (r *CacheResolver) LookupHost(
|
||||
ctx context.Context, hostname string) ([]string, error) {
|
||||
if entry := r.Get(hostname); entry != nil {
|
||||
return entry, nil
|
||||
}
|
||||
entry, err := r.Resolver.LookupHost(ctx, hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !r.ReadOnly {
|
||||
r.Set(hostname, entry)
|
||||
}
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
// Get gets the currently configured entry for domain, or nil
|
||||
func (r *CacheResolver) Get(domain string) []string {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
return r.cache[domain]
|
||||
}
|
||||
|
||||
// Set allows to pre-populate the cache
|
||||
func (r *CacheResolver) Set(domain string, addresses []string) {
|
||||
r.mu.Lock()
|
||||
if r.cache == nil {
|
||||
r.cache = make(map[string][]string)
|
||||
}
|
||||
r.cache[domain] = addresses
|
||||
r.mu.Unlock()
|
||||
}
|
||||
Loading…
Reference in a new issue