2016-06-14 16:54:08 -04:00
|
|
|
// +build json
|
|
|
|
|
|
|
|
package kcp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-06-18 11:14:39 -04:00
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
2016-06-14 16:54:08 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
|
|
|
type JSONConfig struct {
|
2016-06-17 10:57:48 -04:00
|
|
|
Mtu *int `json:"mtu"`
|
2016-06-14 17:25:06 -04:00
|
|
|
}
|
|
|
|
jsonConfig := new(JSONConfig)
|
2016-06-14 16:54:08 -04:00
|
|
|
if err := json.Unmarshal(data, &jsonConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-06-14 17:25:06 -04:00
|
|
|
if jsonConfig.Mtu != nil {
|
2016-06-18 11:14:39 -04:00
|
|
|
mtu := *jsonConfig.Mtu
|
|
|
|
if mtu < 576 || mtu > 1460 {
|
|
|
|
log.Error("KCP|Config: Invalid MTU size: ", mtu)
|
|
|
|
return errors.New("Invalid configuration")
|
|
|
|
}
|
2016-06-14 17:25:06 -04:00
|
|
|
this.Mtu = *jsonConfig.Mtu
|
|
|
|
}
|
|
|
|
|
2016-06-14 16:54:08 -04:00
|
|
|
return nil
|
|
|
|
}
|