-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request: AG-33516-upstream-modes
Squashed commit of the following: commit 7ba8eb7 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jul 3 16:00:12 2024 +0300 main: imp code commit e2b8ec5 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 4c7c08c Author: Dimitry Kolyshev <[email protected]> Date: Wed Jul 3 11:14:13 2024 +0300 all: imp docs commit a239d74 Author: Dimitry Kolyshev <[email protected]> Date: Wed Jul 3 11:14:03 2024 +0300 proxy: imp code commit d8bd87d Author: Dimitry Kolyshev <[email protected]> Date: Fri Jun 28 11:48:52 2024 +0300 main: upstream mode commit afd8043 Author: Dimitry Kolyshev <[email protected]> Date: Fri Jun 28 08:11:45 2024 +0300 proxy: upstream mode commit fca53d2 Author: Dimitry Kolyshev <[email protected]> Date: Thu Jun 27 10:15:58 2024 +0300 proxy: upstream mode
- Loading branch information
Showing
7 changed files
with
106 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package proxy_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/AdguardTeam/dnsproxy/proxy" | ||
"github.com/AdguardTeam/golibs/testutil" | ||
) | ||
|
||
func TestUpstreamMode_encoding(t *testing.T) { | ||
t.Parallel() | ||
|
||
v := proxy.UpstreamModeLoadBalance | ||
|
||
testutil.AssertMarshalText(t, "load_balance", &v) | ||
testutil.AssertUnmarshalText(t, "load_balance", &v) | ||
} |