update kcp config

pull/215/head
v2ray 2016-06-17 16:57:48 +02:00
parent 42ae2d804f
commit f5d613f10a
4 changed files with 22 additions and 56 deletions

View File

@ -8,7 +8,7 @@ import (
// Config for V2Ray transport layer. // Config for V2Ray transport layer.
type Config struct { type Config struct {
tcpConfig *tcp.Config tcpConfig *tcp.Config
kcpConfig *kcp.Config kcpConfig kcp.Config
} }
// Apply applies this Config. // Apply applies this Config.
@ -16,8 +16,6 @@ func (this *Config) Apply() error {
if this.tcpConfig != nil { if this.tcpConfig != nil {
this.tcpConfig.Apply() this.tcpConfig.Apply()
} }
if this.kcpConfig != nil {
this.kcpConfig.Apply() this.kcpConfig.Apply()
}
return nil return nil
} }

View File

@ -12,14 +12,16 @@ import (
func (this *Config) UnmarshalJSON(data []byte) error { func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct { type JsonConfig struct {
TCPConfig *tcp.Config `json:"tcpSettings"` 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 { if err := json.Unmarshal(data, jsonConfig); err != nil {
return err return err
} }
this.tcpConfig = jsonConfig.TCPConfig this.tcpConfig = jsonConfig.TCPConfig
this.kcpConfig = jsonConfig.KCPCOnfig this.kcpConfig = jsonConfig.KCPConfig
return nil return nil
} }

View File

@ -38,29 +38,25 @@ fast3,fast2,fast,normal
->>>>>> less bandwich wasted ->>>>>> less bandwich wasted
*/ */
type Config struct { type Config struct {
Mode string
Mtu int Mtu int
Sndwnd int Sndwnd int
Rcvwnd int Rcvwnd int
Acknodelay bool Acknodelay bool
Dscp int
ReadTimeout int
WriteTimeout int
} }
func (this *Config) Apply() { func (this *Config) Apply() {
effectiveConfig = *this effectiveConfig = *this
} }
var ( func DefaultConfig() Config {
effectiveConfig = Config{ return Config{
Mode: "normal",
Mtu: 1350, Mtu: 1350,
Sndwnd: 1024, Sndwnd: 1024,
Rcvwnd: 1024, Rcvwnd: 1024,
Dscp: 0, Acknodelay: true,
ReadTimeout: 600,
WriteTimeout: 500,
Acknodelay: false,
} }
}
var (
effectiveConfig = DefaultConfig()
) )

View File

@ -8,45 +8,15 @@ import (
func (this *Config) UnmarshalJSON(data []byte) error { func (this *Config) UnmarshalJSON(data []byte) error {
type JSONConfig struct { type JSONConfig struct {
Mode *string `json:"Mode"` Mtu *int `json:"mtu"`
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"`
} }
jsonConfig := new(JSONConfig) jsonConfig := new(JSONConfig)
if err := json.Unmarshal(data, &jsonConfig); err != nil { if err := json.Unmarshal(data, &jsonConfig); err != nil {
return err return err
} }
if jsonConfig.Mode != nil {
this.Mode = *jsonConfig.Mode
}
if jsonConfig.Mtu != nil { if jsonConfig.Mtu != nil {
this.Mtu = *jsonConfig.Mtu 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 return nil
} }