Skip to content

Commit

Permalink
Pull request 261: 333-opt-timeout
Browse files Browse the repository at this point in the history
Merge in GO/dnsproxy from 333-opt-timeout to master

Closes #333.

Squashed commit of the following:

commit f049d5e
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jun 13 16:54:26 2023 +0300

    main: imp docs, code

commit 627ed3b
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jun 13 16:22:04 2023 +0300

    main: rm short form, consider for local

commit d46aa00
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jun 13 13:58:21 2023 +0300

    main: upd docs

commit 641cc92
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jun 13 13:38:28 2023 +0300

    main: configurable timeout
  • Loading branch information
EugeneOne1 committed Jun 13, 2023
1 parent 6b03405 commit c70af9f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Application Options:
be specified multiple times
--all-servers If specified, parallel queries to all configured upstream servers are enabled
--fastest-addr Respond to A or AAAA requests only with the fastest IP address
--timeout= Timeout for outbound DNS queries to remote upstream servers in a
human-readable form (default: 10s)
--cache If specified, DNS cache is enabled
--cache-size= Cache size (in bytes). Default: 64k
--cache-min-ttl= Minimum TTL value for DNS entries, in seconds. Capped at 3600.
Expand Down
1 change: 1 addition & 0 deletions config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ ratelimit: 0
udp-buf-size: 0
upstream:
- "1.1.1.1:53"
timeout: '10s'
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/mathutil"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/timeutil"
"github.com/ameshkov/dnscrypt/v2"
goFlags "github.com/jessevdk/go-flags"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -110,6 +112,10 @@ type Options struct {
// detected by ICMP response time or TCP connection time
FastestAddress bool `yaml:"fastest-addr" long:"fastest-addr" description:"Respond to A or AAAA requests only with the fastest IP address" optional:"yes" optional-value:"true"`

// Timeout for outbound DNS queries to remote upstream servers in a
// human-readable form. Default is 10s.
Timeout timeutil.Duration `yaml:"timeout" long:"timeout" description:"Timeout for outbound DNS queries to remote upstream servers in a human-readable form" default:"10s"`

// Cache settings
// --

Expand Down Expand Up @@ -184,7 +190,6 @@ type Options struct {
var VersionString = "dev" // nolint:gochecknoglobals

const (
defaultTimeout = 10 * time.Second
defaultLocalTimeout = 1 * time.Second
)

Expand Down Expand Up @@ -351,12 +356,13 @@ func initUpstreams(config *proxy.Config, options *Options) {

var err error

timeout := options.Timeout.Duration
upstreams := loadServersList(options.Upstreams)
upsOpts := &upstream.Options{
HTTPVersions: httpVersions,
InsecureSkipVerify: options.Insecure,
Bootstrap: options.BootstrapDNS,
Timeout: defaultTimeout,
Timeout: timeout,
}
config.UpstreamConfig, err = proxy.ParseUpstreamsConfig(upstreams, upsOpts)
if err != nil {
Expand All @@ -367,7 +373,7 @@ func initUpstreams(config *proxy.Config, options *Options) {
privUpsOpts := &upstream.Options{
HTTPVersions: httpVersions,
Bootstrap: options.BootstrapDNS,
Timeout: defaultLocalTimeout,
Timeout: mathutil.Min(defaultLocalTimeout, timeout),
}
config.PrivateRDNSUpstreamConfig, err = proxy.ParseUpstreamsConfig(privUpstreams, privUpsOpts)
if err != nil {
Expand Down
71 changes: 71 additions & 0 deletions vendor/github.com/AdguardTeam/golibs/timeutil/duration.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ github.com/AdguardTeam/golibs/mathutil
github.com/AdguardTeam/golibs/netutil
github.com/AdguardTeam/golibs/stringutil
github.com/AdguardTeam/golibs/testutil
github.com/AdguardTeam/golibs/timeutil
# github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da
## explicit
github.com/aead/chacha20/chacha
Expand Down

0 comments on commit c70af9f

Please sign in to comment.