mirror of
https://github.com/AdguardTeam/dnsproxy.git
synced 2026-10-12 02:01:26 +00:00
Squashed commit of the following:
commit 7ba8eb71029d4cda6ec9fbc07ee8cbe5d2c3f29a
Author: Dimitry Kolyshev <[email protected]>
Date: Wed Jul 3 16:00:12 2024 +0300
main: imp code
commit e2b8ec56351b3e1ecbf7899f01252e7c930459c9
Merge: 4c7c08c 55efb45
Author: Dimitry Kolyshev <[email protected]>
Date: Wed Jul 3 13:03:36 2024 +0300
Merge remote-tracking branch 'origin/master' into AG-33516-upstream-modes
commit 4c7c08cf84b9b4e9bdd6db0fd6fa88a7184e84da
Author: Dimitry Kolyshev <[email protected]>
Date: Wed Jul 3 11:14:13 2024 +0300
all: imp docs
commit a239d748c79c3bbc02938b8c1d18dd3378061b2c
Author: Dimitry Kolyshev <[email protected]>
Date: Wed Jul 3 11:14:03 2024 +0300
proxy: imp code
commit d8bd87de5c5fc5da25d096cffcad772a3224cf65
Author: Dimitry Kolyshev <[email protected]>
Date: Fri Jun 28 11:48:52 2024 +0300
main: upstream mode
commit afd8043ce4b4028c1add5fc25fca56dda47c180c
Author: Dimitry Kolyshev <[email protected]>
Date: Fri Jun 28 08:11:45 2024 +0300
proxy: upstream mode
commit fca53d26e2b4925aa9e0b92cd3da6c16bc015814
Author: Dimitry Kolyshev <[email protected]>
Date: Thu Jun 27 10:15:58 2024 +0300
proxy: upstream mode
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package proxy
|
|
|
|
import (
|
|
"encoding"
|
|
"fmt"
|
|
)
|
|
|
|
// UpstreamMode is an enumeration of upstream mode representations.
|
|
//
|
|
// TODO(d.kolyshev): Set uint8 as underlying type.
|
|
type UpstreamMode string
|
|
|
|
const (
|
|
// UpstreamModeLoadBalance is the default upstream mode. It balances the
|
|
// upstreams load.
|
|
UpstreamModeLoadBalance UpstreamMode = "load_balance"
|
|
|
|
// UpstreamModeParallel makes server to query all configured upstream
|
|
// servers in parallel.
|
|
UpstreamModeParallel UpstreamMode = "parallel"
|
|
|
|
// UpstreamModeFastestAddr controls whether the server should respond to A
|
|
// or AAAA requests only with the fastest IP address detected by ICMP
|
|
// response time or TCP connection time.
|
|
UpstreamModeFastestAddr UpstreamMode = "fastest_addr"
|
|
)
|
|
|
|
// type check
|
|
var _ encoding.TextUnmarshaler = (*UpstreamMode)(nil)
|
|
|
|
// UnmarshalText implements [encoding.TextUnmarshaler] interface for
|
|
// *UpstreamMode.
|
|
func (m *UpstreamMode) UnmarshalText(b []byte) (err error) {
|
|
switch um := UpstreamMode(b); um {
|
|
case
|
|
UpstreamModeLoadBalance,
|
|
UpstreamModeParallel,
|
|
UpstreamModeFastestAddr:
|
|
*m = um
|
|
default:
|
|
return fmt.Errorf(
|
|
"invalid upstream mode %q, supported: %q, %q, %q",
|
|
b,
|
|
UpstreamModeLoadBalance,
|
|
UpstreamModeParallel,
|
|
UpstreamModeFastestAddr,
|
|
)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// type check
|
|
var _ encoding.TextMarshaler = UpstreamMode("")
|
|
|
|
// MarshalText implements [encoding.TextMarshaler] interface for UpstreamMode.
|
|
func (m UpstreamMode) MarshalText() (text []byte, err error) {
|
|
return []byte(m), nil
|
|
}
|