1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-03 06:30:42 +00:00

update kcp config

This commit is contained in:
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.
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
}

View File

@ -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
}

View File

@ -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()
)

View File

@ -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
}