Add a timeout configuration for server

This commit is contained in:
Star Brilliant
2018-01-17 20:31:27 +08:00
parent d3b322842d
commit dcd6b0bb57
3 changed files with 10 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ type config struct {
Key string `toml:"key"`
Path string `toml:"path"`
Upstream []string `toml:"upstream"`
Timeout uint `toml:"timeout"`
Tries uint `toml:"tries"`
TCPOnly bool `toml:"tcp_only"`
Verbose bool `toml:"verbose"`
@@ -58,8 +59,11 @@ func loadConfig(path string) (*config, error) {
if len(conf.Upstream) == 0 {
conf.Upstream = []string { "8.8.8.8:53", "8.8.4.4:53" }
}
if conf.Timeout == 0 {
conf.Timeout = 10
}
if conf.Tries == 0 {
conf.Tries = 3
conf.Tries = 1
}
if (conf.Cert != "") != (conf.Key != "") {

View File

@@ -17,6 +17,9 @@ upstream = [
"8.8.4.4:53",
]
# Upstream timeout
timeout = 10
# Number of tries if upstream DNS fails
tries = 3

View File

@@ -52,9 +52,11 @@ func NewServer(conf *config) (s *Server) {
conf: conf,
udpClient: &dns.Client {
Net: "udp",
Timeout: time.Duration(conf.Timeout) * time.Second,
},
tcpClient: &dns.Client {
Net: "tcp",
Timeout: time.Duration(conf.Timeout) * time.Second,
},
servemux: http.NewServeMux(),
}