Changes to allow host "Set" to be standard, providers being able to use other query types, cache all responses, etc.

This commit is contained in:
Tyler
2020-02-07 22:38:22 -05:00
parent f726a5d5ae
commit 3383c5e4f9
10 changed files with 107 additions and 172 deletions

View File

@ -1,11 +1,13 @@
package resolver
import "github.com/miekg/dns"
type Question struct {
Name string
Type string
Type uint16
Class string
}
func (q *Question) String() string {
return q.Name + " " + q.Class + " " + q.Type
return q.Name + " " + q.Class + " " + dns.TypeToString[q.Type]
}

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"meow.tf/joker/godns/log"
"meow.tf/joker/godns/settings"
"meow.tf/joker/godns/utils"
"net"
"os"
@ -37,13 +36,13 @@ type RResp struct {
type Resolver struct {
servers []string
domain_server *suffixTreeNode
config *settings.ResolvSettings
config *Settings
clients map[string]*dns.Client
clientLock sync.RWMutex
}
func NewResolver(c settings.ResolvSettings) *Resolver {
func NewResolver(c Settings) *Resolver {
r := &Resolver{
servers: []string{},
domain_server: newSuffixTreeRoot(),
@ -109,26 +108,26 @@ func (r *Resolver) parseServerListFile(buf *os.File) {
r.domain_server.sinsert(strings.Split(domain, "."), ip)
case 1:
srv_port := strings.Split(line, "#")
srvPort := strings.Split(line, "#")
if len(srv_port) > 2 {
if len(srvPort) > 2 {
continue
}
ip := ""
if ip = srv_port[0]; !utils.IsIP(ip) {
if ip = srvPort[0]; !utils.IsIP(ip) {
continue
}
port := "53"
if len(srv_port) == 2 {
if _, err := strconv.Atoi(srv_port[1]); err != nil {
if len(srvPort) == 2 {
if _, err := strconv.Atoi(srvPort[1]); err != nil {
continue
}
port = srv_port[1]
port = srvPort[1]
}
r.servers = append(r.servers, net.JoinHostPort(ip, port))
@ -222,8 +221,14 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error
}
func (r *Resolver) resolverFor(net, nameserver string) (*dns.Client, error) {
key := net
if net == "tcp-tls" {
key = net + ":" + nameserver
}
r.clientLock.RLock()
client, exists := r.clients[net]
client, exists := r.clients[key]
r.clientLock.RUnlock()
if exists {
@ -249,7 +254,7 @@ func (r *Resolver) resolverFor(net, nameserver string) (*dns.Client, error) {
}
r.clientLock.Lock()
r.clients[net] = client
r.clients[key] = client
r.clientLock.Lock()
return client, nil

9
resolver/settings.go Normal file
View File

@ -0,0 +1,9 @@
package resolver
type Settings struct {
Timeout int `toml:"timeout" env:"RESOLV_TIMEOUT"`
Interval int `toml:"interval" env:"RESOLV_INTERVAL"`
SetEDNS0 bool `toml:"setedns0" env:"RESOLV_EDNS0"`
ServerListFile []string `toml:"server-list-file" env:"SERVER_LIST_FILE"`
ResolvFile string `toml:"resolv-file" env:"RESOLV_FILE"`
}