浏览代码

Refine "only" in Mux config

RPRX 2 年之前
父节点
当前提交
29d7865d78
共有 4 个文件被更改,包括 14 次插入7 次删除
  1. 1 1
      app/proxyman/config.pb.go
  2. 1 1
      app/proxyman/config.proto
  3. 11 4
      infra/conf/xray.go
  4. 1 1
      infra/conf/xray_test.go

+ 1 - 1
app/proxyman/config.pb.go

@@ -595,7 +595,7 @@ type MultiplexingConfig struct {
 	Enabled bool `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"`
 	// Max number of concurrent connections that one Mux connection can handle.
 	Concurrency uint32 `protobuf:"varint,2,opt,name=concurrency,proto3" json:"concurrency,omitempty"`
-	// Both(0), TCP(1), UDP(2).
+	// Both(0), TCP(net.Network_TCP), UDP(net.Network_UDP).
 	Only uint32 `protobuf:"varint,3,opt,name=only,proto3" json:"only,omitempty"`
 }
 

+ 1 - 1
app/proxyman/config.proto

@@ -98,6 +98,6 @@ message MultiplexingConfig {
   bool enabled = 1;
   // Max number of concurrent connections that one Mux connection can handle.
   uint32 concurrency = 2;
-  // Both(0), TCP(1), UDP(2).
+  // Both(0), TCP(net.Network_TCP), UDP(net.Network_UDP).
   uint32 only = 3;
 }

+ 11 - 4
infra/conf/xray.go

@@ -114,9 +114,9 @@ type MuxConfig struct {
 }
 
 // Build creates MultiplexingConfig, Concurrency < 0 completely disables mux.
-func (m *MuxConfig) Build() *proxyman.MultiplexingConfig {
+func (m *MuxConfig) Build() (*proxyman.MultiplexingConfig, error) {
 	if m.Concurrency < 0 {
-		return nil
+		return nil, nil
 	}
 	if m.Concurrency == 0 {
 		m.Concurrency = 8
@@ -128,13 +128,16 @@ func (m *MuxConfig) Build() *proxyman.MultiplexingConfig {
 	}
 
 	switch strings.ToLower(m.Only) {
+	case "", "both":
 	case "tcp":
 		config.Only = uint32(net.Network_TCP)
 	case "udp":
 		config.Only = uint32(net.Network_UDP)
+	default:
+		return nil, newError(`unknown "only": `, m.Only)
 	}
 
-	return config
+	return config, nil
 }
 
 type InboundDetourAllocationConfig struct {
@@ -348,7 +351,11 @@ func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) {
 	}
 
 	if c.MuxSettings != nil {
-		senderSettings.MultiplexSettings = c.MuxSettings.Build()
+		ms, err := c.MuxSettings.Build()
+		if err != nil {
+			return nil, newError("failed to build Mux config.").Base(err)
+		}
+		senderSettings.MultiplexSettings = ms
 	}
 
 	settings := []byte("{}")

+ 1 - 1
infra/conf/xray_test.go

@@ -357,7 +357,7 @@ func TestMuxConfig_Build(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
 			m := &MuxConfig{}
 			common.Must(json.Unmarshal([]byte(tt.fields), m))
-			if got := m.Build(); !reflect.DeepEqual(got, tt.want) {
+			if got, _ := m.Build(); !reflect.DeepEqual(got, tt.want) {
 				t.Errorf("MuxConfig.Build() = %v, want %v", got, tt.want)
 			}
 		})