doggo/cmd/resolver.go

69 lines
1.9 KiB
Go
Raw Normal View History

2020-12-11 12:18:54 +01:00
package main
import (
"time"
2020-12-11 12:18:54 +01:00
"github.com/mr-karan/doggo/pkg/resolvers"
)
2020-12-17 12:27:44 +01:00
// loadResolvers loads differently configured
// resolvers based on a list of nameserver.
func (hub *Hub) loadResolvers() error {
2020-12-16 14:08:34 +01:00
// for each nameserver, initialise the correct resolver
for _, ns := range hub.Nameservers {
2020-12-16 14:25:07 +01:00
if ns.Type == DOHResolver {
2020-12-16 14:08:34 +01:00
hub.Logger.Debug("initiating DOH resolver")
rslvr, err := resolvers.NewDOHResolver(ns.Address, resolvers.DOHResolverOpts{
Timeout: hub.QueryFlags.Timeout * time.Second,
})
if err != nil {
return err
}
hub.Resolver = append(hub.Resolver, rslvr)
2020-12-12 07:16:13 +01:00
}
2020-12-16 15:10:01 +01:00
if ns.Type == DOTResolver {
hub.Logger.Debug("initiating DOT resolver")
rslvr, err := resolvers.NewClassicResolver(ns.Address, resolvers.ClassicResolverOpts{
IPv4Only: hub.QueryFlags.UseIPv4,
IPv6Only: hub.QueryFlags.UseIPv6,
Timeout: hub.QueryFlags.Timeout * time.Second,
UseTLS: true,
UseTCP: true,
})
if err != nil {
return err
}
hub.Resolver = append(hub.Resolver, rslvr)
}
2020-12-16 14:25:07 +01:00
if ns.Type == TCPResolver {
2020-12-16 14:08:34 +01:00
hub.Logger.Debug("initiating TCP resolver")
2020-12-16 15:10:01 +01:00
rslvr, err := resolvers.NewClassicResolver(ns.Address, resolvers.ClassicResolverOpts{
2020-12-16 14:08:34 +01:00
IPv4Only: hub.QueryFlags.UseIPv4,
IPv6Only: hub.QueryFlags.UseIPv6,
Timeout: hub.QueryFlags.Timeout * time.Second,
2020-12-16 15:10:01 +01:00
UseTLS: false,
UseTCP: true,
2020-12-16 14:08:34 +01:00
})
if err != nil {
return err
}
hub.Resolver = append(hub.Resolver, rslvr)
2020-12-11 12:18:54 +01:00
}
2020-12-17 17:38:23 +01:00
if ns.Type == UDPResolver {
2020-12-16 14:08:34 +01:00
hub.Logger.Debug("initiating UDP resolver")
2020-12-16 15:10:01 +01:00
rslvr, err := resolvers.NewClassicResolver(ns.Address, resolvers.ClassicResolverOpts{
2020-12-16 14:08:34 +01:00
IPv4Only: hub.QueryFlags.UseIPv4,
IPv6Only: hub.QueryFlags.UseIPv6,
Timeout: hub.QueryFlags.Timeout * time.Second,
2020-12-16 15:10:01 +01:00
UseTLS: false,
UseTCP: false,
2020-12-16 14:08:34 +01:00
})
if err != nil {
return err
}
hub.Resolver = append(hub.Resolver, rslvr)
2020-12-12 07:16:13 +01:00
}
2020-12-11 12:18:54 +01:00
}
return nil
}