Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into AGDNS-2202-slog-vol-5
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Jul 4, 2024
2 parents 8bc8e4d + 2a1c257 commit 15bc993
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ type Options struct {
EDNSAddr string `yaml:"edns-addr" long:"edns-addr" description:"Send EDNS Client Address"`

// UpstreamMode determines the logic through which upstreams will be used.
UpstreamMode string `yaml:"upstream-mode" long:"upstream-mode" description:"" optional:"yes" optional-value:"load_balance"`
// If not specified the [proxy.UpstreamModeLoadBalance] is used.
UpstreamMode string `yaml:"upstream-mode" long:"upstream-mode" description:"Upstreams logic mode" optional:"yes" optional-value:"load_balance"`

// ListenAddrs is the list of server's listen addresses.
ListenAddrs []string `yaml:"listen-addrs" short:"l" long:"listen" description:"Listening addresses"`
Expand Down
14 changes: 14 additions & 0 deletions proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type Config struct {
HTTPSServerName string

// UpstreamMode determines the logic through which upstreams will be used.
// If not specified the [proxy.UpstreamModeLoadBalance] is used.
UpstreamMode UpstreamMode

// UDPListenAddr is the set of UDP addresses to listen for plain
Expand Down Expand Up @@ -270,6 +271,15 @@ func (p *Proxy) validateConfig() (err error) {
return fmt.Errorf("validating ratelimit: %w", err)
}

switch p.UpstreamMode {
case "":
// Go on.
case UpstreamModeFastestAddr, UpstreamModeLoadBalance, UpstreamModeParallel:
// Go on.
default:
return fmt.Errorf("bad upstream mode: %q", p.UpstreamMode)
}

p.logConfigInfo()

return nil
Expand Down Expand Up @@ -333,6 +343,10 @@ func (p *Proxy) logConfigInfo() {
if len(p.BogusNXDomain) > 0 {
p.logger.Info("bogus-nxdomain ip specified", "prefix_len", len(p.BogusNXDomain))
}

if p.UpstreamMode != "" {
p.logger.Info("upstream mode is set", "mode", p.UpstreamMode)
}
}

// validateListenAddrs returns an error if the addresses are not configured
Expand Down
5 changes: 3 additions & 2 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ func New(c *Config) (p *Proxy, err error) {
p.requestsSema = syncutil.EmptySemaphore{}
}

p.logger.Info("upstream mode is set", "mode", p.UpstreamMode)
if p.UpstreamMode == UpstreamModeFastestAddr {
if p.UpstreamMode == "" {
p.UpstreamMode = UpstreamModeLoadBalance
} else if p.UpstreamMode == UpstreamModeFastestAddr {
p.fastestAddr = fastip.New(&fastip.Config{
Logger: p.Logger,
PingWaitTimeout: p.FastestPingTimeout,
Expand Down

0 comments on commit 15bc993

Please # to comment.