浏览代码

Added Config for KCP connetions

Shelikhoo 9 年之前
父节点
当前提交
a8792b2b60
共有 3 个文件被更改,包括 27 次插入2 次删除
  1. 8 0
      transport/config.go
  2. 11 2
      transport/config_json.go
  3. 8 0
      transport/transport.go

+ 8 - 0
transport/config.go

@@ -1,12 +1,20 @@
 package transport
 
+import "github.com/v2ray/v2ray-core/transport/hub/kcpv"
+
 type Config struct {
 	ConnectionReuse bool
+	enableKcp       bool
+	kcpConfig       *kcpv.Config
 }
 
 func (this *Config) Apply() error {
 	if this.ConnectionReuse {
 		connectionReuse = true
 	}
+	enableKcp = this.enableKcp
+	if enableKcp {
+		KcpConfig = this.kcpConfig
+	}
 	return nil
 }

+ 11 - 2
transport/config_json.go

@@ -2,18 +2,27 @@
 
 package transport
 
-import "encoding/json"
+import (
+	"encoding/json"
+
+	"github.com/v2ray/v2ray-core/transport/hub/kcpv"
+)
 
 func (this *Config) UnmarshalJSON(data []byte) error {
 	type JsonConfig struct {
-		ConnectionReuse bool `json:"connectionReuse"`
+		ConnectionReuse bool         `json:"connectionReuse"`
+		EnableKcp       bool         `json:"EnableKCP,omitempty"`
+		KcpConfig       *kcpv.Config `json:"KcpConfig,omitempty"`
 	}
 	jsonConfig := &JsonConfig{
 		ConnectionReuse: true,
+		EnableKcp:       false,
 	}
 	if err := json.Unmarshal(data, jsonConfig); err != nil {
 		return err
 	}
 	this.ConnectionReuse = jsonConfig.ConnectionReuse
+	this.enableKcp = jsonConfig.EnableKcp
+	this.kcpConfig = kcpConfig
 	return nil
 }

+ 8 - 0
transport/transport.go

@@ -1,9 +1,17 @@
 package transport
 
+import "github.com/v2ray/v2ray-core/transport/hub/kcpv"
+
 var (
 	connectionReuse = true
+	enableKcp       = false
+	KcpConfig       *kcpv.Config
 )
 
 func IsConnectionReusable() bool {
 	return connectionReuse
 }
+
+func IsKcpEnabled() bool {
+	return enableKcp
+}