1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-29 23:36:25 -04:00
v2fly/transport/internet/connection_json.go
2016-10-16 14:22:21 +02:00

37 lines
902 B
Go

// +build json
package internet
import (
"encoding/json"
"strings"
"v2ray.com/core/common/loader"
v2net "v2ray.com/core/common/net"
v2tls "v2ray.com/core/transport/internet/tls"
)
func (this *StreamConfig) UnmarshalJSON(data []byte) error {
type JSONConfig struct {
Network *v2net.Network `json:"network"`
Security string `json:"security"`
TLSSettings *v2tls.Config `json:"tlsSettings"`
}
this.Network = v2net.Network_RawTCP
jsonConfig := new(JSONConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
if jsonConfig.Network != nil {
this.Network = *jsonConfig.Network
}
if strings.ToLower(jsonConfig.Security) == "tls" {
tlsSettings := jsonConfig.TLSSettings
if tlsSettings == nil {
tlsSettings = &v2tls.Config{}
}
this.SecuritySettings = append(this.SecuritySettings, loader.NewTypedSettings(tlsSettings))
}
return nil
}