Add testing, cleanup, rework suffix tree to use nameservers. Parse nameservers from yaml.
This commit is contained in:
		@ -2,6 +2,7 @@ package hosts
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/miekg/dns"
 | 
			
		||||
	log "github.com/sirupsen/logrus"
 | 
			
		||||
	bolt "go.etcd.io/bbolt"
 | 
			
		||||
	"strings"
 | 
			
		||||
@ -67,7 +68,10 @@ func (b *BoltHosts) List() (HostMap, error) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (b *BoltHosts) Get(queryType uint16, domain string) (*Host, error) {
 | 
			
		||||
	log.Debug("Checking bolt provider for %s : %s", queryType, domain)
 | 
			
		||||
	log.WithFields(log.Fields{
 | 
			
		||||
		"queryType": dns.TypeToString[queryType],
 | 
			
		||||
		"question": domain,
 | 
			
		||||
	}).Debug("Checking bolt provider")
 | 
			
		||||
 | 
			
		||||
	domain = strings.ToLower(domain)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -62,7 +62,10 @@ func (f *FileHosts) List() (HostMap, error) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (f *FileHosts) Get(queryType uint16, domain string) (*Host, error) {
 | 
			
		||||
	log.Debug("Checking file provider for %s : %s", queryType, domain)
 | 
			
		||||
	log.WithFields(log.Fields{
 | 
			
		||||
		"queryType": dns.TypeToString[queryType],
 | 
			
		||||
		"question": domain,
 | 
			
		||||
	}).Debug("Checking file provider")
 | 
			
		||||
 | 
			
		||||
	// Does not support CNAME/TXT/etc
 | 
			
		||||
	if queryType != dns.TypeA && queryType != dns.TypeAAAA {
 | 
			
		||||
@ -102,7 +105,10 @@ func (f *FileHosts) Refresh() {
 | 
			
		||||
	buf, err := os.Open(f.file)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Warn("Update hosts records from file failed %s", err)
 | 
			
		||||
		log.WithFields(log.Fields{
 | 
			
		||||
			"file": f.file,
 | 
			
		||||
			"error": err,
 | 
			
		||||
		}).Warn("Hosts update from file failed")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -149,7 +155,11 @@ func (f *FileHosts) Refresh() {
 | 
			
		||||
			f.hosts[strings.ToLower(domain)] = Host{Values: []string{ip}}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	log.Debug("update hosts records from %s, total %d records.", f.file, len(f.hosts))
 | 
			
		||||
 | 
			
		||||
	log.WithFields(log.Fields{
 | 
			
		||||
		"file": f.file,
 | 
			
		||||
		"count": len(f.hosts),
 | 
			
		||||
	}).Debug("Updated hosts records")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (f *FileHosts) clear() {
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ package hosts
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/go-redis/redis/v7"
 | 
			
		||||
	"github.com/miekg/dns"
 | 
			
		||||
	log "github.com/sirupsen/logrus"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
@ -46,7 +47,10 @@ func (r *RedisHosts) List() (HostMap, error) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *RedisHosts) Get(queryType uint16, domain string) (*Host, error) {
 | 
			
		||||
	log.Debug("Checking redis provider for %s", domain)
 | 
			
		||||
	log.WithFields(log.Fields{
 | 
			
		||||
		"queryType": dns.TypeToString[queryType],
 | 
			
		||||
		"question": domain,
 | 
			
		||||
	}).Debug("Checking redis provider")
 | 
			
		||||
 | 
			
		||||
	domain = strings.ToLower(domain)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user