Skip to content

Commit

Permalink
dnsforward: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Dec 20, 2023
1 parent 1499da1 commit 3a98dee
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions internal/dnsforward/http.go
Expand Up @@ -70,7 +70,7 @@ type jsonDNSConfig struct {
DisableIPv6 *bool `json:"disable_ipv6"`

// UpstreamMode defines the way DNS requests are constructed.
UpstreamMode *UpstreamMode `json:"upstream_mode"`
UpstreamMode *jsonUpstreamMode `json:"upstream_mode"`

// BlockedResponseTTL is the TTL for blocked responses.
BlockedResponseTTL *uint32 `json:"blocked_response_ttl"`
Expand Down Expand Up @@ -114,20 +114,20 @@ type jsonDNSConfig struct {
DefaultLocalPTRUpstreams []string `json:"default_local_ptr_upstreams,omitempty"`
}

// UpstreamMode is a enumeration of upstream modes.
type UpstreamMode string
// jsonUpstreamMode is a enumeration of upstream modes.
type jsonUpstreamMode string

const (
// UpstreamModeEmpty is the default value on frontend, it is used as
// UpstreamModeLoadBalance mode.
// jsonUpstreamModeEmpty is the default value on frontend, it is used as
// jsonUpstreamModeLoadBalance mode.
//
// Deprecated
// TODO(d.kolyshev): Use UpstreamModeLoadBalance instead.
UpstreamModeEmpty UpstreamMode = ""
// TODO(d.kolyshev): Use jsonUpstreamModeLoadBalance instead.
jsonUpstreamModeEmpty jsonUpstreamMode = ""

UpstreamModeLoadBalance UpstreamMode = "load_balance"
UpstreamModeParallel UpstreamMode = "parallel"
UpstreamModeFastestAddr UpstreamMode = "fastest_addr"
jsonUpstreamModeLoadBalance jsonUpstreamMode = "load_balance"
jsonUpstreamModeParallel jsonUpstreamMode = "parallel"
jsonUpstreamModeFastestAddr jsonUpstreamMode = "fastest_addr"
)

func (s *Server) getDNSConfig() (c *jsonDNSConfig) {
Expand Down Expand Up @@ -161,16 +161,16 @@ func (s *Server) getDNSConfig() (c *jsonDNSConfig) {
usePrivateRDNS := s.conf.UsePrivateRDNS
localPTRUpstreams := stringutil.CloneSliceOrEmpty(s.conf.LocalPTRResolvers)

var upstreamMode UpstreamMode
var upstreamMode jsonUpstreamMode
switch s.conf.UpstreamMode {
case UpstreamModeTypeLoadBalance:
// TODO(d.kolyshev): Support UpstreamModeLoadBalance on frontend instead
// of UpstreamModeEmpty.
upstreamMode = UpstreamModeEmpty
// TODO(d.kolyshev): Support jsonUpstreamModeLoadBalance on frontend instead
// of jsonUpstreamModeEmpty.
upstreamMode = jsonUpstreamModeEmpty
case UpstreamModeTypeParallel:
upstreamMode = UpstreamModeParallel
upstreamMode = jsonUpstreamModeParallel
case UpstreamModeTypeFastestAddr:
upstreamMode = UpstreamModeFastestAddr
upstreamMode = jsonUpstreamModeFastestAddr
}

defPTRUps, err := s.defaultLocalPTRUpstreams()
Expand Down Expand Up @@ -251,10 +251,10 @@ func (req *jsonDNSConfig) checkUpstreamMode() (err error) {

switch um := *req.UpstreamMode; um {
case
UpstreamModeEmpty,
UpstreamModeLoadBalance,
UpstreamModeParallel,
UpstreamModeFastestAddr:
jsonUpstreamModeEmpty,
jsonUpstreamModeLoadBalance,
jsonUpstreamModeParallel,
jsonUpstreamModeFastestAddr:
return nil
default:
return fmt.Errorf("upstream_mode: incorrect value %q", um)
Expand Down Expand Up @@ -488,13 +488,13 @@ func (s *Server) setConfig(dc *jsonDNSConfig) (shouldRestart bool) {

// mustParseUpstreamMode returns an upstream mode parsed from string. Panics in
// case of invalid value.
func mustParseUpstreamMode(mode UpstreamMode) (um UpstreamModeType) {
func mustParseUpstreamMode(mode jsonUpstreamMode) (um UpstreamModeType) {
switch mode {
case UpstreamModeEmpty, UpstreamModeLoadBalance:
case jsonUpstreamModeEmpty, jsonUpstreamModeLoadBalance:
return UpstreamModeTypeLoadBalance
case UpstreamModeParallel:
case jsonUpstreamModeParallel:
return UpstreamModeTypeParallel
case UpstreamModeFastestAddr:
case jsonUpstreamModeFastestAddr:
return UpstreamModeTypeFastestAddr
default:
// Should never happen, since the value should be validated.
Expand Down

0 comments on commit 3a98dee

Please sign in to comment.