Pull request: 1992 configurable timeouts

Merge in DNS/adguard-home from 1992-conf-timeouts to master

Updates #1992.

Squashed commit of the following:

commit 1050c54fb407bec0617728690763b0392b3440b0
Merge: 05f71c3e 59544160
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Fri Aug 27 20:04:25 2021 +0300

    Merge branch 'master' into 1992-conf-timeouts

commit 05f71c3e5397909d943e69d49a247bf4f67619b0
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Fri Aug 27 20:03:06 2021 +0300

    home: use const

commit d0861792b42e6d066aa3ffdb3937e29477235ee0
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Fri Aug 27 19:16:26 2021 +0300

    home: fix default timeout

commit ba26fcdcf66366350c89d5a82c4da91ade45838f
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Fri Aug 27 16:50:33 2021 +0300

    all: mk ping timeout configurable
This commit is contained in:
Eugene Burkov 2021-08-27 20:16:07 +03:00
parent 595441603f
commit e064e0f277
9 changed files with 38 additions and 24 deletions

View File

@ -15,6 +15,8 @@ and this project adheres to
### Added ### Added
- New `FastestTimeout` field that replaces the default timeout for dialing the
IP addresses when AdGuard Home works in "Fastest IP address" mode ([#1992]).
- Static IP address detection on FreeBSD ([#3289]). - Static IP address detection on FreeBSD ([#3289]).
- Optimistic cache ([#2145]). - Optimistic cache ([#2145]).
- New possible value of `6h` for `querylog_interval` setting ([#2504]). - New possible value of `6h` for `querylog_interval` setting ([#2504]).
@ -139,6 +141,7 @@ In this release, the schema version has changed from 10 to 12.
[#1381]: https://github.com/AdguardTeam/AdGuardHome/issues/1381 [#1381]: https://github.com/AdguardTeam/AdGuardHome/issues/1381
[#1691]: https://github.com/AdguardTeam/AdGuardHome/issues/1691 [#1691]: https://github.com/AdguardTeam/AdGuardHome/issues/1691
[#1898]: https://github.com/AdguardTeam/AdGuardHome/issues/1898 [#1898]: https://github.com/AdguardTeam/AdGuardHome/issues/1898
[#1992]: https://github.com/AdguardTeam/AdGuardHome/issues/1992
[#2141]: https://github.com/AdguardTeam/AdGuardHome/issues/2141 [#2141]: https://github.com/AdguardTeam/AdGuardHome/issues/2141
[#2145]: https://github.com/AdguardTeam/AdGuardHome/issues/2145 [#2145]: https://github.com/AdguardTeam/AdGuardHome/issues/2145
[#2280]: https://github.com/AdguardTeam/AdGuardHome/issues/2280 [#2280]: https://github.com/AdguardTeam/AdGuardHome/issues/2280

4
go.mod
View File

@ -3,8 +3,8 @@ module github.com/AdguardTeam/AdGuardHome
go 1.16 go 1.16
require ( require (
github.com/AdguardTeam/dnsproxy v0.39.2 github.com/AdguardTeam/dnsproxy v0.39.4
github.com/AdguardTeam/golibs v0.9.1 github.com/AdguardTeam/golibs v0.9.2
github.com/AdguardTeam/urlfilter v0.14.6 github.com/AdguardTeam/urlfilter v0.14.6
github.com/NYTimes/gziphandler v1.1.1 github.com/NYTimes/gziphandler v1.1.1
github.com/ameshkov/dnscrypt/v2 v2.2.1 github.com/ameshkov/dnscrypt/v2 v2.2.1

10
go.sum
View File

@ -9,13 +9,12 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/AdguardTeam/dhcp v0.0.0-20210519141215-51808c73c0bf h1:gc042VRSIRSUzZ+Px6xQCRWNJZTaPkomisDfUZmoFNk= github.com/AdguardTeam/dhcp v0.0.0-20210519141215-51808c73c0bf h1:gc042VRSIRSUzZ+Px6xQCRWNJZTaPkomisDfUZmoFNk=
github.com/AdguardTeam/dhcp v0.0.0-20210519141215-51808c73c0bf/go.mod h1:TKl4jN3Voofo4UJIicyNhWGp/nlQqQkFxmwIFTvBkKI= github.com/AdguardTeam/dhcp v0.0.0-20210519141215-51808c73c0bf/go.mod h1:TKl4jN3Voofo4UJIicyNhWGp/nlQqQkFxmwIFTvBkKI=
github.com/AdguardTeam/dnsproxy v0.39.2 h1:GqsR1S4fFfVsVCSrdrfa0RfsQ2u+MeNUMqDkxdTD3gU= github.com/AdguardTeam/dnsproxy v0.39.4 h1:vjcogr0qpSTvRYzbXabBXblfzYpx+LOn91kjtnYgcrU=
github.com/AdguardTeam/dnsproxy v0.39.2/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= github.com/AdguardTeam/dnsproxy v0.39.4/go.mod h1:JZUxXM70BUlAmMaJEPa6Wh+Tz7eBAQx6DM1GMt+Ff5E=
github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
github.com/AdguardTeam/golibs v0.8.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.9.2 h1:H3BDFkaosxvb+UgFlNVyN66GZ+JglcZULnJ7z7PukyQ=
github.com/AdguardTeam/golibs v0.9.1 h1:mHSN4LfaY1uGmHPsl97paAND/VeSnM5r9XQ7pSYx93o= github.com/AdguardTeam/golibs v0.9.2/go.mod h1:fCAMwPBJ8S7YMYbTWvYS+eeTLblP5E04IDtNAo7y7IY=
github.com/AdguardTeam/golibs v0.9.1/go.mod h1:fCAMwPBJ8S7YMYbTWvYS+eeTLblP5E04IDtNAo7y7IY=
github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU= github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU=
github.com/AdguardTeam/urlfilter v0.14.6 h1:emqoKZElooHACYehRBYENeKVN1a/rspxiqTIMYLuoIo= github.com/AdguardTeam/urlfilter v0.14.6 h1:emqoKZElooHACYehRBYENeKVN1a/rspxiqTIMYLuoIo=
github.com/AdguardTeam/urlfilter v0.14.6/go.mod h1:klx4JbOfc4EaNb5lWLqOwfg+pVcyRukmoJRvO55lL5U= github.com/AdguardTeam/urlfilter v0.14.6/go.mod h1:klx4JbOfc4EaNb5lWLqOwfg+pVcyRukmoJRvO55lL5U=
@ -362,7 +361,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

View File

@ -1,4 +1,5 @@
package home // Package aghtime defines some types for convenient work with time values.
package aghtime
import ( import (
"time" "time"

View File

@ -1,4 +1,4 @@
package home package aghtime
import ( import (
"bytes" "bytes"

View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/aghtime"
"github.com/AdguardTeam/AdGuardHome/internal/filtering" "github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy" "github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/dnsproxy/upstream"
@ -87,6 +88,9 @@ type FilteringConfig struct {
BootstrapDNS []string `yaml:"bootstrap_dns"` // a list of bootstrap DNS for DoH and DoT (plain DNS only) BootstrapDNS []string `yaml:"bootstrap_dns"` // a list of bootstrap DNS for DoH and DoT (plain DNS only)
AllServers bool `yaml:"all_servers"` // if true, parallel queries to all configured upstream servers are enabled AllServers bool `yaml:"all_servers"` // if true, parallel queries to all configured upstream servers are enabled
FastestAddr bool `yaml:"fastest_addr"` // use Fastest Address algorithm FastestAddr bool `yaml:"fastest_addr"` // use Fastest Address algorithm
// FastestTimeout replaces the default timeout for dialing IP addresses
// when FastestAddr is true.
FastestTimeout aghtime.Duration `yaml:"fastest_timeout"`
// Access settings // Access settings
// -- // --
@ -236,6 +240,7 @@ func (s *Server) createProxyConfig() (proxy.Config, error) {
proxyConfig.UpstreamMode = proxy.UModeParallel proxyConfig.UpstreamMode = proxy.UModeParallel
} else if s.conf.FastestAddr { } else if s.conf.FastestAddr {
proxyConfig.UpstreamMode = proxy.UModeFastestAddr proxyConfig.UpstreamMode = proxy.UModeFastestAddr
proxyConfig.FastestPingTimeout = s.conf.FastestTimeout.Duration
} }
if len(s.conf.BogusNXDomain) > 0 { if len(s.conf.BogusNXDomain) > 0 {

View File

@ -8,12 +8,14 @@ import (
"sync" "sync"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/aghtime"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd" "github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward" "github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering" "github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog" "github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/stats" "github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/AdGuardHome/internal/version" "github.com/AdguardTeam/AdGuardHome/internal/version"
"github.com/AdguardTeam/dnsproxy/fastip"
"github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/log"
"github.com/google/renameio/maybe" "github.com/google/renameio/maybe"
@ -106,7 +108,7 @@ type dnsConfig struct {
QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled
QueryLogFileEnabled bool `yaml:"querylog_file_enabled"` // if true, query log will be written to a file QueryLogFileEnabled bool `yaml:"querylog_file_enabled"` // if true, query log will be written to a file
// QueryLogInterval is the interval for query log's files rotation. // QueryLogInterval is the interval for query log's files rotation.
QueryLogInterval Duration `yaml:"querylog_interval"` QueryLogInterval aghtime.Duration `yaml:"querylog_interval"`
QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk
AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats
@ -117,7 +119,7 @@ type dnsConfig struct {
DnsfilterConf filtering.Config `yaml:",inline"` DnsfilterConf filtering.Config `yaml:",inline"`
// UpstreamTimeout is the timeout for querying upstream servers. // UpstreamTimeout is the timeout for querying upstream servers.
UpstreamTimeout Duration `yaml:"upstream_timeout"` UpstreamTimeout aghtime.Duration `yaml:"upstream_timeout"`
// LocalDomainName is the domain name used for known internal hosts. // LocalDomainName is the domain name used for known internal hosts.
// For example, a machine called "myhost" can be addressed as // For example, a machine called "myhost" can be addressed as
@ -178,6 +180,9 @@ var config = configuration{
Ratelimit: 20, Ratelimit: 20,
RefuseAny: true, RefuseAny: true,
AllServers: false, AllServers: false,
FastestTimeout: aghtime.Duration{
Duration: fastip.DefaultPingWaitTimeout,
},
TrustedProxies: []string{"127.0.0.0/8", "::1/128"}, TrustedProxies: []string{"127.0.0.0/8", "::1/128"},
@ -189,7 +194,7 @@ var config = configuration{
}, },
FilteringEnabled: true, // whether or not use filter lists FilteringEnabled: true, // whether or not use filter lists
FiltersUpdateIntervalHours: 24, FiltersUpdateIntervalHours: 24,
UpstreamTimeout: Duration{Duration: dnsforward.DefaultTimeout}, UpstreamTimeout: aghtime.Duration{Duration: dnsforward.DefaultTimeout},
LocalDomainName: "lan", LocalDomainName: "lan",
ResolveClients: true, ResolveClients: true,
UsePrivateRDNS: true, UsePrivateRDNS: true,
@ -216,7 +221,7 @@ func initConfig() {
config.DNS.QueryLogEnabled = true config.DNS.QueryLogEnabled = true
config.DNS.QueryLogFileEnabled = true config.DNS.QueryLogFileEnabled = true
config.DNS.QueryLogInterval = Duration{Duration: 90 * 24 * time.Hour} config.DNS.QueryLogInterval = aghtime.Duration{Duration: 90 * 24 * time.Hour}
config.DNS.QueryLogMemSize = 1000 config.DNS.QueryLogMemSize = 1000
config.DNS.CacheSize = 4 * 1024 * 1024 config.DNS.CacheSize = 4 * 1024 * 1024
@ -285,7 +290,7 @@ func parseConfig() error {
} }
if config.DNS.UpstreamTimeout.Duration == 0 { if config.DNS.UpstreamTimeout.Duration == 0 {
config.DNS.UpstreamTimeout = Duration{Duration: dnsforward.DefaultTimeout} config.DNS.UpstreamTimeout = aghtime.Duration{Duration: dnsforward.DefaultTimeout}
} }
return nil return nil
@ -332,7 +337,7 @@ func (c *configuration) write() error {
Context.queryLog.WriteDiskConfig(&dc) Context.queryLog.WriteDiskConfig(&dc)
config.DNS.QueryLogEnabled = dc.Enabled config.DNS.QueryLogEnabled = dc.Enabled
config.DNS.QueryLogFileEnabled = dc.FileEnabled config.DNS.QueryLogFileEnabled = dc.FileEnabled
config.DNS.QueryLogInterval = Duration{Duration: dc.RotationIvl} config.DNS.QueryLogInterval = aghtime.Duration{Duration: dc.RotationIvl}
config.DNS.QueryLogMemSize = dc.MemSize config.DNS.QueryLogMemSize = dc.MemSize
config.DNS.AnonymizeClientIP = dc.AnonymizeClientIP config.DNS.AnonymizeClientIP = dc.AnonymizeClientIP
} }

View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/aghtime"
"github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil" "github.com/AdguardTeam/golibs/netutil"
@ -684,7 +685,7 @@ func upgradeSchema11to12(diskConf yobj) (err error) {
} }
} }
dns[field] = Duration{Duration: time.Duration(qlogIvl) * 24 * time.Hour} dns[field] = aghtime.Duration{Duration: time.Duration(qlogIvl) * 24 * time.Hour}
return nil return nil
} }

View File

@ -4,6 +4,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/aghtime"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -425,7 +426,7 @@ func TestUpgradeSchema11to12(t *testing.T) {
name string name string
}{{ }{{
ivl: 1, ivl: 1,
want: Duration{Duration: 24 * time.Hour}, want: aghtime.Duration{Duration: 24 * time.Hour},
wantErr: "", wantErr: "",
name: "success", name: "success",
}, { }, {
@ -462,8 +463,8 @@ func TestUpgradeSchema11to12(t *testing.T) {
newDNSConf, ok = dnsVal.(yobj) newDNSConf, ok = dnsVal.(yobj)
require.True(t, ok) require.True(t, ok)
var newIvl Duration var newIvl aghtime.Duration
newIvl, ok = newDNSConf["querylog_interval"].(Duration) newIvl, ok = newDNSConf["querylog_interval"].(aghtime.Duration)
require.True(t, ok) require.True(t, ok)
assert.Equal(t, tc.want, newIvl) assert.Equal(t, tc.want, newIvl)
@ -504,8 +505,8 @@ func TestUpgradeSchema11to12(t *testing.T) {
ivl, ok = dnsVal["querylog_interval"] ivl, ok = dnsVal["querylog_interval"]
require.True(t, ok) require.True(t, ok)
var ivlVal Duration var ivlVal aghtime.Duration
ivlVal, ok = ivl.(Duration) ivlVal, ok = ivl.(aghtime.Duration)
require.True(t, ok) require.True(t, ok)
assert.Equal(t, 90*24*time.Hour, ivlVal.Duration) assert.Equal(t, 90*24*time.Hour, ivlVal.Duration)