1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-07 10:47:48 -05:00
v2fly/transport/config_json.go

40 lines
996 B
Go
Raw Normal View History

2016-06-01 19:49:25 -04:00
// +build json
package transport
2016-06-11 07:51:02 -04:00
import (
"encoding/json"
2016-06-13 05:49:21 -04:00
"github.com/v2ray/v2ray-core/common/log"
2016-06-11 07:51:02 -04:00
"github.com/v2ray/v2ray-core/transport/hub/kcpv"
)
2016-06-01 19:49:25 -04:00
func (this *Config) UnmarshalJSON(data []byte) error {
2016-06-02 14:52:52 -04:00
type JsonConfig struct {
2016-06-11 07:51:02 -04:00
ConnectionReuse bool `json:"connectionReuse"`
EnableKcp bool `json:"EnableKCP,omitempty"`
KcpConfig *kcpv.Config `json:"KcpConfig,omitempty"`
2016-06-01 19:49:25 -04:00
}
2016-06-10 20:05:29 -04:00
jsonConfig := &JsonConfig{
ConnectionReuse: true,
2016-06-11 07:51:02 -04:00
EnableKcp: false,
2016-06-10 20:05:29 -04:00
}
2016-06-02 14:52:52 -04:00
if err := json.Unmarshal(data, jsonConfig); err != nil {
2016-06-01 19:49:25 -04:00
return err
}
2016-06-02 14:52:52 -04:00
this.ConnectionReuse = jsonConfig.ConnectionReuse
2016-06-11 07:51:02 -04:00
this.enableKcp = jsonConfig.EnableKcp
2016-06-13 05:49:21 -04:00
if jsonConfig.KcpConfig != nil {
this.kcpConfig = jsonConfig.KcpConfig
if jsonConfig.KcpConfig.AdvancedConfigs == nil {
jsonConfig.KcpConfig.AdvancedConfigs = kcpv.DefaultAdvancedConfigs
}
} else {
if jsonConfig.EnableKcp {
log.Error("transport: You have enabled KCP but no configure is given")
}
}
2016-06-01 19:49:25 -04:00
return nil
}