2020-12-11 12:18:54 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/mr-karan/doggo/pkg/resolvers"
|
|
|
|
)
|
|
|
|
|
2020-12-12 11:57:13 +01:00
|
|
|
// initResolver checks for various flags and initialises
|
2020-12-12 08:46:45 +01:00
|
|
|
// the correct resolver based on the config.
|
2020-12-13 13:19:10 +01:00
|
|
|
func (hub *Hub) initResolver() error {
|
2020-12-12 07:16:13 +01:00
|
|
|
// check if DOH flag is set.
|
|
|
|
if hub.QueryFlags.IsDOH {
|
2020-12-13 13:19:10 +01:00
|
|
|
rslvr, err := resolvers.NewDOHResolver(hub.QueryFlags.Nameservers)
|
2020-12-12 07:16:13 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
hub.Resolver = rslvr
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-13 13:19:10 +01:00
|
|
|
if len(hub.QueryFlags.Nameservers) == 0 {
|
2020-12-11 12:18:54 +01:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// TODO: Add a method for reading system default nameserver in windows.
|
|
|
|
} else {
|
2020-12-13 08:15:45 +01:00
|
|
|
rslvr, err := resolvers.NewSystemResolver(resolvers.DefaultResolvConfPath)
|
2020-12-11 12:18:54 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
hub.Resolver = rslvr
|
2020-12-12 07:16:13 +01:00
|
|
|
return nil
|
2020-12-11 12:18:54 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-12-13 13:19:10 +01:00
|
|
|
rslvr, err := resolvers.NewClassicResolver(hub.QueryFlags.Nameservers, resolvers.ClassicResolverOpts{
|
2020-12-12 07:46:54 +01:00
|
|
|
UseIPv4: hub.QueryFlags.UseIPv4,
|
|
|
|
UseIPv6: hub.QueryFlags.UseIPv6,
|
2020-12-12 08:46:45 +01:00
|
|
|
UseTLS: hub.QueryFlags.IsDOT,
|
|
|
|
UseTCP: hub.QueryFlags.UseTCP,
|
2020-12-12 07:46:54 +01:00
|
|
|
})
|
2020-12-12 07:16:13 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-11 12:18:54 +01:00
|
|
|
hub.Resolver = rslvr
|
2020-12-12 07:16:13 +01:00
|
|
|
return nil
|
2020-12-11 12:18:54 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|