feat(proxy): tcp-режим для xray/sing-box поверх turn
This commit is contained in:
1 parent
e63279db18
commit
f7129099f7
60 files changed
+2953
-135
No files matched your search
@@ -313,9 +313,97 @@ func TestParseServer_GenObfKeySkipsConnectCheck(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServer_RejectsRemovedModeFlag(t *testing.T) {
|
||||
_, err := ParseServer([]string{"-connect", "x:1", "-mode", "tcp"}, io.Discard)
|
||||
if err == nil {
|
||||
t.Error("expected error on removed -mode flag")
|
||||
func TestParseServer_ProxyMode(t *testing.T) {
|
||||
s, err := ParseServer([]string{"-connect", "x:1", "-mode", "tcp"}, io.Discard)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s.Proxy.Mode != ProxyModeTCP {
|
||||
t.Errorf("Proxy.Mode = %q, want %q", s.Proxy.Mode, ProxyModeTCP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServer_InvalidMode(t *testing.T) {
|
||||
_, err := ParseServer([]string{"-connect", "x:1", "-mode", "quic"}, io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "invalid -mode") {
|
||||
t.Errorf("expected mode error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServer_KCPFlagsRequireTCPMode(t *testing.T) {
|
||||
_, err := ParseServer([]string{"-connect", "x:1", "-kcp-mtu", "900"}, io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "-kcp-*") {
|
||||
t.Errorf("expected kcp/mode error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServer_KCPProfileApplied(t *testing.T) {
|
||||
s, err := ParseServer([]string{"-connect", "x:1", "-mode", "tcp", "-kcp-mtu", "900", "-kcp-interval", "40"}, io.Discard)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s.KCP.Profile.MTU != 900 || s.KCP.Profile.Interval != 40 {
|
||||
t.Errorf("KCP profile = %+v", s.KCP.Profile)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServer_KCPMTUOutOfRange(t *testing.T) {
|
||||
_, err := ParseServer([]string{"-connect", "x:1", "-mode", "tcp", "-kcp-mtu", "2000"}, io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "-kcp-mtu") {
|
||||
t.Errorf("expected kcp-mtu error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseClient_ProxyMode(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
args []string
|
||||
want ProxyMode
|
||||
}{
|
||||
{"default-udp", nil, ProxyModeUDP},
|
||||
{"tcp", []string{"-mode", "tcp"}, ProxyModeTCP},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
c, err := ParseClient(append(validClientArgs(), tc.args...), io.Discard)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.Proxy.Mode != tc.want {
|
||||
t.Errorf("Proxy.Mode = %q, want %q", c.Proxy.Mode, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseClient_InvalidMode(t *testing.T) {
|
||||
_, err := ParseClient(append(validClientArgs(), "-mode", "quic"), io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "invalid -mode") {
|
||||
t.Errorf("expected mode error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseClient_ObfTimingAllowedInTCP(t *testing.T) {
|
||||
args := append(validClientArgs(), "-mode", "tcp", "-obf-profile", "rtpopus3", "-obf-key", testObfKey, "-obf-timing", "20ms")
|
||||
c, err := ParseClient(args, io.Discard)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseClient() error = %v", err)
|
||||
}
|
||||
if c.Obf.Timing != 20*time.Millisecond {
|
||||
t.Errorf("Obf.Timing = %v, want 20ms", c.Obf.Timing)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseClient_ObfTimingRequiresProfile(t *testing.T) {
|
||||
_, err := ParseClient(append(validClientArgs(), "-obf-timing", "20ms"), io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "-obf-timing") {
|
||||
t.Errorf("expected obf-timing/profile error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseClient_KCPFlagsRequireTCPMode(t *testing.T) {
|
||||
_, err := ParseClient(append(validClientArgs(), "-kcp-sndwnd", "128"), io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "-kcp-*") {
|
||||
t.Errorf("expected kcp/mode error, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user