From f6d4e599bda7abc33189bf8a438a6a8d6bad3d83 Mon Sep 17 00:00:00 2001 From: v2ray Date: Fri, 15 Jul 2016 21:27:23 +0200 Subject: [PATCH] configurable read and write buffer size --- transport/internet/kcp/config.go | 4 ++-- transport/internet/kcp/config_json.go | 28 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/transport/internet/kcp/config.go b/transport/internet/kcp/config.go index eeacaf06..8292fe70 100644 --- a/transport/internet/kcp/config.go +++ b/transport/internet/kcp/config.go @@ -49,8 +49,8 @@ func DefaultConfig() Config { UplinkCapacity: 5, DownlinkCapacity: 20, Congestion: false, - WriteBuffer: 4 * 1024 * 1024, - ReadBuffer: 4 * 1024 * 1024, + WriteBuffer: 1 * 1024 * 1024, + ReadBuffer: 1 * 1024 * 1024, } } diff --git a/transport/internet/kcp/config_json.go b/transport/internet/kcp/config_json.go index 4e3f1425..26f53e74 100644 --- a/transport/internet/kcp/config_json.go +++ b/transport/internet/kcp/config_json.go @@ -11,11 +11,13 @@ import ( func (this *Config) UnmarshalJSON(data []byte) error { type JSONConfig struct { - Mtu *uint32 `json:"mtu"` - Tti *uint32 `json:"tti"` - UpCap *uint32 `json:"uplinkCapacity"` - DownCap *uint32 `json:"downlinkCapacity"` - Congestion *bool `json:"congestion"` + Mtu *uint32 `json:"mtu"` + Tti *uint32 `json:"tti"` + UpCap *uint32 `json:"uplinkCapacity"` + DownCap *uint32 `json:"downlinkCapacity"` + Congestion *bool `json:"congestion"` + ReadBufferSize *uint32 `json:"readBufferSize"` + WriteBufferSize *uint32 `json:"writeBufferSize"` } jsonConfig := new(JSONConfig) if err := json.Unmarshal(data, &jsonConfig); err != nil { @@ -46,6 +48,22 @@ func (this *Config) UnmarshalJSON(data []byte) error { if jsonConfig.Congestion != nil { this.Congestion = *jsonConfig.Congestion } + if jsonConfig.ReadBufferSize != nil { + size := *jsonConfig.ReadBufferSize + if size > 0 { + this.ReadBuffer = size * 1024 * 1024 + } else { + this.ReadBuffer = 512 * 1024 + } + } + if jsonConfig.WriteBufferSize != nil { + size := *jsonConfig.WriteBufferSize + if size > 0 { + this.WriteBuffer = size * 1024 * 1024 + } else { + this.WriteBuffer = 512 * 1024 + } + } return nil }