|
|
|
@ -4,14 +4,18 @@ package kcp
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common"
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
|
|
|
|
type JSONConfig struct {
|
|
|
|
|
Mtu *int `json:"mtu"`
|
|
|
|
|
Tti *int `json:"tti"`
|
|
|
|
|
UpCap *int `json:"uplinkCapacity"`
|
|
|
|
|
DownCap *int `json:"downlinkCapacity"`
|
|
|
|
|
Congestion *bool `json:"congestion"`
|
|
|
|
|
}
|
|
|
|
|
jsonConfig := new(JSONConfig)
|
|
|
|
|
if err := json.Unmarshal(data, &jsonConfig); err != nil {
|
|
|
|
@ -21,9 +25,36 @@ func (this *Config) UnmarshalJSON(data []byte) error {
|
|
|
|
|
mtu := *jsonConfig.Mtu
|
|
|
|
|
if mtu < 576 || mtu > 1460 {
|
|
|
|
|
log.Error("KCP|Config: Invalid MTU size: ", mtu)
|
|
|
|
|
return errors.New("Invalid configuration")
|
|
|
|
|
return common.ErrBadConfiguration
|
|
|
|
|
}
|
|
|
|
|
this.Mtu = *jsonConfig.Mtu
|
|
|
|
|
this.Mtu = mtu
|
|
|
|
|
}
|
|
|
|
|
if jsonConfig.Tti != nil {
|
|
|
|
|
tti := *jsonConfig.Tti
|
|
|
|
|
if tti < 10 || tti > 100 {
|
|
|
|
|
log.Error("KCP|Config: Invalid TTI: ", tti)
|
|
|
|
|
return common.ErrBadConfiguration
|
|
|
|
|
}
|
|
|
|
|
this.Tti = tti
|
|
|
|
|
}
|
|
|
|
|
if jsonConfig.UpCap != nil {
|
|
|
|
|
upCap := *jsonConfig.UpCap
|
|
|
|
|
if upCap < 0 {
|
|
|
|
|
log.Error("KCP|Config: Invalid uplink capacity: ", upCap)
|
|
|
|
|
return common.ErrBadConfiguration
|
|
|
|
|
}
|
|
|
|
|
this.UplinkCapacity = upCap
|
|
|
|
|
}
|
|
|
|
|
if jsonConfig.DownCap != nil {
|
|
|
|
|
downCap := *jsonConfig.DownCap
|
|
|
|
|
if downCap < 0 {
|
|
|
|
|
log.Error("KCP|Config: Invalid downlink capacity: ", downCap)
|
|
|
|
|
return common.ErrBadConfiguration
|
|
|
|
|
}
|
|
|
|
|
this.DownlinkCapacity = downCap
|
|
|
|
|
}
|
|
|
|
|
if jsonConfig.Congestion != nil {
|
|
|
|
|
this.Congestion = *jsonConfig.Congestion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|