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

62 lines
1.4 KiB
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-10-02 17:43:58 -04:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/transport/internet/kcp"
"v2ray.com/core/transport/internet/tcp"
"v2ray.com/core/transport/internet/ws"
2016-10-02 17:43:58 -04:00
"github.com/golang/protobuf/ptypes"
2016-06-11 07:51:02 -04:00
)
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-14 16:54:08 -04:00
TCPConfig *tcp.Config `json:"tcpSettings"`
2016-10-02 17:43:58 -04:00
KCPConfig *kcp.Config `json:"kcpSettings"`
2016-08-13 09:39:34 -04:00
WSConfig *ws.Config `json:"wsSettings"`
2016-06-17 10:57:48 -04:00
}
2016-09-21 15:08:05 -04:00
jsonConfig := &JsonConfig{}
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-10-02 17:43:58 -04:00
if jsonConfig.TCPConfig != nil {
any, err := ptypes.MarshalAny(jsonConfig.TCPConfig)
if err != nil {
return err
}
this.NetworkSettings = append(this.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_TCP,
Settings: any,
})
}
if jsonConfig.KCPConfig != nil {
any, err := ptypes.MarshalAny(jsonConfig.KCPConfig)
if err != nil {
return err
}
this.NetworkSettings = append(this.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_KCP,
Settings: any,
})
}
if jsonConfig.WSConfig != nil {
any, err := ptypes.MarshalAny(jsonConfig.WSConfig)
if err != nil {
return err
}
this.NetworkSettings = append(this.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_WebSocket,
Settings: any,
})
}
2016-06-01 19:49:25 -04:00
return nil
}