diff --git a/CHANGELOG.md b/CHANGELOG.md index a803de1a..66d28e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to ### 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]). - Optimistic cache ([#2145]). - 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 [#1691]: https://github.com/AdguardTeam/AdGuardHome/issues/1691 [#1898]: https://github.com/AdguardTeam/AdGuardHome/issues/1898 +[#1992]: https://github.com/AdguardTeam/AdGuardHome/issues/1992 [#2141]: https://github.com/AdguardTeam/AdGuardHome/issues/2141 [#2145]: https://github.com/AdguardTeam/AdGuardHome/issues/2145 [#2280]: https://github.com/AdguardTeam/AdGuardHome/issues/2280 diff --git a/go.mod b/go.mod index fb1a886d..1939b752 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/AdguardTeam/AdGuardHome go 1.16 require ( - github.com/AdguardTeam/dnsproxy v0.39.2 - github.com/AdguardTeam/golibs v0.9.1 + github.com/AdguardTeam/dnsproxy v0.39.4 + github.com/AdguardTeam/golibs v0.9.2 github.com/AdguardTeam/urlfilter v0.14.6 github.com/NYTimes/gziphandler v1.1.1 github.com/ameshkov/dnscrypt/v2 v2.2.1 diff --git a/go.sum b/go.sum index 850b2375..b6ba1e36 100644 --- a/go.sum +++ b/go.sum @@ -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= 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/dnsproxy v0.39.2 h1:GqsR1S4fFfVsVCSrdrfa0RfsQ2u+MeNUMqDkxdTD3gU= -github.com/AdguardTeam/dnsproxy v0.39.2/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= +github.com/AdguardTeam/dnsproxy v0.39.4 h1:vjcogr0qpSTvRYzbXabBXblfzYpx+LOn91kjtnYgcrU= +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.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= -github.com/AdguardTeam/golibs v0.8.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= -github.com/AdguardTeam/golibs v0.9.1 h1:mHSN4LfaY1uGmHPsl97paAND/VeSnM5r9XQ7pSYx93o= -github.com/AdguardTeam/golibs v0.9.1/go.mod h1:fCAMwPBJ8S7YMYbTWvYS+eeTLblP5E04IDtNAo7y7IY= +github.com/AdguardTeam/golibs v0.9.2 h1:H3BDFkaosxvb+UgFlNVyN66GZ+JglcZULnJ7z7PukyQ= +github.com/AdguardTeam/golibs v0.9.2/go.mod h1:fCAMwPBJ8S7YMYbTWvYS+eeTLblP5E04IDtNAo7y7IY= 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/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.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.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 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/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/internal/home/duration.go b/internal/aghtime/duration.go similarity index 95% rename from internal/home/duration.go rename to internal/aghtime/duration.go index 53bc1aae..bf073656 100644 --- a/internal/home/duration.go +++ b/internal/aghtime/duration.go @@ -1,4 +1,5 @@ -package home +// Package aghtime defines some types for convenient work with time values. +package aghtime import ( "time" diff --git a/internal/home/duration_test.go b/internal/aghtime/duration_test.go similarity index 99% rename from internal/home/duration_test.go rename to internal/aghtime/duration_test.go index 1ae121d0..ae1b26f3 100644 --- a/internal/home/duration_test.go +++ b/internal/aghtime/duration_test.go @@ -1,4 +1,4 @@ -package home +package aghtime import ( "bytes" diff --git a/internal/dnsforward/config.go b/internal/dnsforward/config.go index 88b44fb2..eba5b23d 100644 --- a/internal/dnsforward/config.go +++ b/internal/dnsforward/config.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/AdguardTeam/AdGuardHome/internal/aghtime" "github.com/AdguardTeam/AdGuardHome/internal/filtering" "github.com/AdguardTeam/dnsproxy/proxy" "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) 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 + // FastestTimeout replaces the default timeout for dialing IP addresses + // when FastestAddr is true. + FastestTimeout aghtime.Duration `yaml:"fastest_timeout"` // Access settings // -- @@ -236,6 +240,7 @@ func (s *Server) createProxyConfig() (proxy.Config, error) { proxyConfig.UpstreamMode = proxy.UModeParallel } else if s.conf.FastestAddr { proxyConfig.UpstreamMode = proxy.UModeFastestAddr + proxyConfig.FastestPingTimeout = s.conf.FastestTimeout.Duration } if len(s.conf.BogusNXDomain) > 0 { diff --git a/internal/home/config.go b/internal/home/config.go index b3536210..710a582c 100644 --- a/internal/home/config.go +++ b/internal/home/config.go @@ -8,12 +8,14 @@ import ( "sync" "time" + "github.com/AdguardTeam/AdGuardHome/internal/aghtime" "github.com/AdguardTeam/AdGuardHome/internal/dhcpd" "github.com/AdguardTeam/AdGuardHome/internal/dnsforward" "github.com/AdguardTeam/AdGuardHome/internal/filtering" "github.com/AdguardTeam/AdGuardHome/internal/querylog" "github.com/AdguardTeam/AdGuardHome/internal/stats" "github.com/AdguardTeam/AdGuardHome/internal/version" + "github.com/AdguardTeam/dnsproxy/fastip" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" "github.com/google/renameio/maybe" @@ -106,9 +108,9 @@ type dnsConfig struct { 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 // QueryLogInterval is the interval for query log's files rotation. - QueryLogInterval Duration `yaml:"querylog_interval"` - 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 + QueryLogInterval aghtime.Duration `yaml:"querylog_interval"` + 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 dnsforward.FilteringConfig `yaml:",inline"` @@ -117,7 +119,7 @@ type dnsConfig struct { DnsfilterConf filtering.Config `yaml:",inline"` // 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. // For example, a machine called "myhost" can be addressed as @@ -178,6 +180,9 @@ var config = configuration{ Ratelimit: 20, RefuseAny: true, AllServers: false, + FastestTimeout: aghtime.Duration{ + Duration: fastip.DefaultPingWaitTimeout, + }, TrustedProxies: []string{"127.0.0.0/8", "::1/128"}, @@ -189,7 +194,7 @@ var config = configuration{ }, FilteringEnabled: true, // whether or not use filter lists FiltersUpdateIntervalHours: 24, - UpstreamTimeout: Duration{Duration: dnsforward.DefaultTimeout}, + UpstreamTimeout: aghtime.Duration{Duration: dnsforward.DefaultTimeout}, LocalDomainName: "lan", ResolveClients: true, UsePrivateRDNS: true, @@ -216,7 +221,7 @@ func initConfig() { config.DNS.QueryLogEnabled = 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.CacheSize = 4 * 1024 * 1024 @@ -285,7 +290,7 @@ func parseConfig() error { } if config.DNS.UpstreamTimeout.Duration == 0 { - config.DNS.UpstreamTimeout = Duration{Duration: dnsforward.DefaultTimeout} + config.DNS.UpstreamTimeout = aghtime.Duration{Duration: dnsforward.DefaultTimeout} } return nil @@ -332,7 +337,7 @@ func (c *configuration) write() error { Context.queryLog.WriteDiskConfig(&dc) config.DNS.QueryLogEnabled = dc.Enabled 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.AnonymizeClientIP = dc.AnonymizeClientIP } diff --git a/internal/home/upgrade.go b/internal/home/upgrade.go index 5599eb3b..8f587e71 100644 --- a/internal/home/upgrade.go +++ b/internal/home/upgrade.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/AdguardTeam/AdGuardHome/internal/aghtime" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" "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 } diff --git a/internal/home/upgrade_test.go b/internal/home/upgrade_test.go index 107bdf96..c4da5a58 100644 --- a/internal/home/upgrade_test.go +++ b/internal/home/upgrade_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/AdguardTeam/AdGuardHome/internal/aghtime" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -425,7 +426,7 @@ func TestUpgradeSchema11to12(t *testing.T) { name string }{{ ivl: 1, - want: Duration{Duration: 24 * time.Hour}, + want: aghtime.Duration{Duration: 24 * time.Hour}, wantErr: "", name: "success", }, { @@ -462,8 +463,8 @@ func TestUpgradeSchema11to12(t *testing.T) { newDNSConf, ok = dnsVal.(yobj) require.True(t, ok) - var newIvl Duration - newIvl, ok = newDNSConf["querylog_interval"].(Duration) + var newIvl aghtime.Duration + newIvl, ok = newDNSConf["querylog_interval"].(aghtime.Duration) require.True(t, ok) assert.Equal(t, tc.want, newIvl) @@ -504,8 +505,8 @@ func TestUpgradeSchema11to12(t *testing.T) { ivl, ok = dnsVal["querylog_interval"] require.True(t, ok) - var ivlVal Duration - ivlVal, ok = ivl.(Duration) + var ivlVal aghtime.Duration + ivlVal, ok = ivl.(aghtime.Duration) require.True(t, ok) assert.Equal(t, 90*24*time.Hour, ivlVal.Duration)