mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-02 17:27:50 -04:00
37 lines
902 B
Go
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
|
|
}
|