From f5d613f10a4e12811162b75f196de8aa744ea1b6 Mon Sep 17 00:00:00 2001 From: v2ray Date: Fri, 17 Jun 2016 16:57:48 +0200 Subject: [PATCH] update kcp config --- transport/config.go | 6 ++--- transport/config_json.go | 8 ++++--- transport/internet/kcp/config.go | 32 ++++++++++++--------------- transport/internet/kcp/config_json.go | 32 +-------------------------- 4 files changed, 22 insertions(+), 56 deletions(-) diff --git a/transport/config.go b/transport/config.go index a98d1b84b..efe221fe7 100644 --- a/transport/config.go +++ b/transport/config.go @@ -8,7 +8,7 @@ import ( // Config for V2Ray transport layer. type Config struct { tcpConfig *tcp.Config - kcpConfig *kcp.Config + kcpConfig kcp.Config } // Apply applies this Config. @@ -16,8 +16,6 @@ func (this *Config) Apply() error { if this.tcpConfig != nil { this.tcpConfig.Apply() } - if this.kcpConfig != nil { - this.kcpConfig.Apply() - } + this.kcpConfig.Apply() return nil } diff --git a/transport/config_json.go b/transport/config_json.go index 30a8dcf26..c7cb2d634 100644 --- a/transport/config_json.go +++ b/transport/config_json.go @@ -12,14 +12,16 @@ import ( func (this *Config) UnmarshalJSON(data []byte) error { type JsonConfig struct { TCPConfig *tcp.Config `json:"tcpSettings"` - KCPCOnfig *kcp.Config `json:"kcpSettings"` + KCPConfig kcp.Config `json:"kcpSettings"` + } + jsonConfig := &JsonConfig{ + KCPConfig: kcp.DefaultConfig(), } - jsonConfig := new(JsonConfig) if err := json.Unmarshal(data, jsonConfig); err != nil { return err } this.tcpConfig = jsonConfig.TCPConfig - this.kcpConfig = jsonConfig.KCPCOnfig + this.kcpConfig = jsonConfig.KCPConfig return nil } diff --git a/transport/internet/kcp/config.go b/transport/internet/kcp/config.go index bdde10d10..8f2055c31 100644 --- a/transport/internet/kcp/config.go +++ b/transport/internet/kcp/config.go @@ -38,29 +38,25 @@ fast3,fast2,fast,normal ->>>>>> less bandwich wasted */ type Config struct { - Mode string - Mtu int - Sndwnd int - Rcvwnd int - Acknodelay bool - Dscp int - ReadTimeout int - WriteTimeout int + Mtu int + Sndwnd int + Rcvwnd int + Acknodelay bool } func (this *Config) Apply() { effectiveConfig = *this } -var ( - effectiveConfig = Config{ - Mode: "normal", - Mtu: 1350, - Sndwnd: 1024, - Rcvwnd: 1024, - Dscp: 0, - ReadTimeout: 600, - WriteTimeout: 500, - Acknodelay: false, +func DefaultConfig() Config { + return Config{ + Mtu: 1350, + Sndwnd: 1024, + Rcvwnd: 1024, + Acknodelay: true, } +} + +var ( + effectiveConfig = DefaultConfig() ) diff --git a/transport/internet/kcp/config_json.go b/transport/internet/kcp/config_json.go index 27571d43c..f604f10aa 100644 --- a/transport/internet/kcp/config_json.go +++ b/transport/internet/kcp/config_json.go @@ -8,45 +8,15 @@ import ( func (this *Config) UnmarshalJSON(data []byte) error { type JSONConfig struct { - Mode *string `json:"Mode"` - Mtu *int `json:"MaximumTransmissionUnit"` - Sndwnd *int `json:"SendingWindowSize"` - Rcvwnd *int `json:"ReceivingWindowSize"` - Acknodelay *bool `json:"AcknowledgeNoDelay"` - Dscp *int `json:"Dscp"` - ReadTimeout *int `json:"ReadTimeout"` - WriteTimeout *int `json:"WriteTimeout"` + Mtu *int `json:"mtu"` } jsonConfig := new(JSONConfig) if err := json.Unmarshal(data, &jsonConfig); err != nil { return err } - if jsonConfig.Mode != nil { - this.Mode = *jsonConfig.Mode - } - if jsonConfig.Mtu != nil { this.Mtu = *jsonConfig.Mtu } - if jsonConfig.Sndwnd != nil { - this.Sndwnd = *jsonConfig.Sndwnd - } - if jsonConfig.Rcvwnd != nil { - this.Rcvwnd = *jsonConfig.Rcvwnd - } - if jsonConfig.Acknodelay != nil { - this.Acknodelay = *jsonConfig.Acknodelay - } - if jsonConfig.Dscp != nil { - this.Dscp = *jsonConfig.Dscp - } - if jsonConfig.ReadTimeout != nil { - this.ReadTimeout = *jsonConfig.ReadTimeout - } - if jsonConfig.WriteTimeout != nil { - this.WriteTimeout = *jsonConfig.WriteTimeout - } - return nil }