Skip to content

Commit

Permalink
all: mk ping timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Aug 27, 2021
1 parent d1de47b commit ba26fcd
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.3
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
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.3 h1:Nn2JHNZTz7S9iFJRi9txxzksDaDjyYSl0byhaiVRQcQ=
github.com/AdguardTeam/dnsproxy v0.39.3/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=
Expand Down Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion internal/home/duration.go → internal/aghtime/duration.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package home
// Package aghtime defines some types for convenient work with time values.
package aghtime

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package home
package aghtime

import (
"bytes"
Expand Down
5 changes: 5 additions & 0 deletions internal/dnsforward/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
// --
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 10 additions & 8 deletions internal/home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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"
Expand Down Expand Up @@ -106,9 +107,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"`

Expand All @@ -117,7 +118,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
Expand Down Expand Up @@ -178,6 +179,7 @@ var config = configuration{
Ratelimit: 20,
RefuseAny: true,
AllServers: false,
FastestTimeout: aghtime.Duration{Duration: 5 * time.Second},

TrustedProxies: []string{"127.0.0.0/8", "::1/128"},

Expand All @@ -189,7 +191,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,
Expand All @@ -216,7 +218,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
Expand Down Expand Up @@ -285,7 +287,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
Expand Down Expand Up @@ -332,7 +334,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
}
Expand Down
3 changes: 2 additions & 1 deletion internal/home/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions internal/home/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/AdguardTeam/AdGuardHome/internal/aghtime"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -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",
}, {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ba26fcd

Please sign in to comment.