"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "internal/util/autohosts.go" between
AdGuardHome-0.105.1.tar.gz and AdGuardHome-0.105.2.tar.gz

About: AdGuard Home is a network-wide ads & trackers blocking DNS server. It operates as a DNS server that re-routes tracking domains to a "black hole," thus preventing your devices from connecting to those servers.

autohosts.go  (AdGuardHome-0.105.1):autohosts.go  (AdGuardHome-0.105.2)
skipping to change at line 24 skipping to change at line 24
"github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/log"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
) )
type onChangedT func() type onChangedT func()
// AutoHosts - automatic DNS records // AutoHosts - automatic DNS records
type AutoHosts struct { type AutoHosts struct {
// lock protects table and tableReverse. // lock protects table and tableReverse.
lock sync.Mutex lock sync.RWMutex
// table is the host-to-IPs map. // table is the host-to-IPs map.
table map[string][]net.IP table map[string][]net.IP
// tableReverse is the IP-to-hosts map. // tableReverse is the IP-to-hosts map.
// //
// TODO(a.garipov): Make better use of newtypes. Perhaps a custom map. // TODO(a.garipov): Make better use of newtypes. Perhaps a custom map.
tableReverse map[string][]string tableReverse map[string][]string
hostsFn string // path to the main hosts-file hostsFn string // path to the main hosts-file
hostsDirs []string // paths to OS-specific directories with host s-files hostsDirs []string // paths to OS-specific directories with host s-files
watcher *fsnotify.Watcher // file and directory watcher object watcher *fsnotify.Watcher // file and directory watcher object
skipping to change at line 122 skipping to change at line 122
} }
// Process returns the list of IP addresses for the hostname or nil if nothing // Process returns the list of IP addresses for the hostname or nil if nothing
// found. // found.
func (a *AutoHosts) Process(host string, qtype uint16) []net.IP { func (a *AutoHosts) Process(host string, qtype uint16) []net.IP {
if qtype == dns.TypePTR { if qtype == dns.TypePTR {
return nil return nil
} }
var ipsCopy []net.IP var ipsCopy []net.IP
a.lock.Lock() a.lock.RLock()
defer a.lock.RUnlock()
if ips, ok := a.table[host]; ok { if ips, ok := a.table[host]; ok {
ipsCopy = make([]net.IP, len(ips)) ipsCopy = make([]net.IP, len(ips))
copy(ipsCopy, ips) copy(ipsCopy, ips)
} }
a.lock.Unlock()
log.Debug("AutoHosts: answer: %s -> %v", host, ipsCopy) log.Debug("AutoHosts: answer: %s -> %v", host, ipsCopy)
return ipsCopy return ipsCopy
} }
// ProcessReverse processes a PTR request. It returns nil if nothing is found. // ProcessReverse processes a PTR request. It returns nil if nothing is found.
func (a *AutoHosts) ProcessReverse(addr string, qtype uint16) (hosts []string) { func (a *AutoHosts) ProcessReverse(addr string, qtype uint16) (hosts []string) {
if qtype != dns.TypePTR { if qtype != dns.TypePTR {
return nil return nil
} }
ipReal := DNSUnreverseAddr(addr) ipReal := DNSUnreverseAddr(addr)
if ipReal == nil { if ipReal == nil {
return nil return nil
} }
ipStr := ipReal.String() ipStr := ipReal.String()
a.lock.Lock() a.lock.RLock()
defer a.lock.Unlock() defer a.lock.RUnlock()
hosts = a.tableReverse[ipStr] hosts = a.tableReverse[ipStr]
if len(hosts) == 0 { if len(hosts) == 0 {
return nil // not found return nil // not found
} }
log.Debug("AutoHosts: reverse-lookup: %s -> %s", addr, hosts) log.Debug("AutoHosts: reverse-lookup: %s -> %s", addr, hosts)
return hosts return hosts
} }
// List returns an IP-to-hostnames table. It is safe for concurrent use. // List returns an IP-to-hostnames table. It is safe for concurrent use.
func (a *AutoHosts) List() (ipToHosts map[string][]string) { func (a *AutoHosts) List() (ipToHosts map[string][]string) {
a.lock.Lock() a.lock.RLock()
defer a.lock.Unlock() defer a.lock.RUnlock()
ipToHosts = make(map[string][]string, len(a.tableReverse)) ipToHosts = make(map[string][]string, len(a.tableReverse))
for k, v := range a.tableReverse { for k, v := range a.tableReverse {
ipToHosts[k] = v ipToHosts[k] = v
} }
return ipToHosts return ipToHosts
} }
// update table // update table
skipping to change at line 342 skipping to change at line 341
log.Error("AutoHosts: Opening directory: %s: %s", dir, err) log.Error("AutoHosts: Opening directory: %s: %s", dir, err)
} }
continue continue
} }
for _, fi := range fis { for _, fi := range fis {
a.load(table, tableRev, dir+"/"+fi.Name()) a.load(table, tableRev, dir+"/"+fi.Name())
} }
} }
a.lock.Lock() func() {
a.table = table a.lock.Lock()
a.tableReverse = tableRev defer a.lock.Unlock()
a.lock.Unlock()
a.table = table
a.tableReverse = tableRev
}()
a.notify() a.notify()
} }
 End of changes. 6 change blocks. 
12 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)