mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
// +build json
|
|
|
|
package internet
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"errors"
|
|
"github.com/golang/protobuf/ptypes"
|
|
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
|
|
}
|
|
this.SecurityType = SecurityType_None
|
|
if strings.ToLower(jsonConfig.Security) == "tls" {
|
|
this.SecurityType = SecurityType_TLS
|
|
}
|
|
if jsonConfig.TLSSettings != nil {
|
|
anyTLSSettings, err := ptypes.MarshalAny(jsonConfig.TLSSettings)
|
|
if err != nil {
|
|
return errors.New("Internet: Failed to parse TLS settings: " + err.Error())
|
|
}
|
|
this.SecuritySettings = append(this.SecuritySettings, &SecuritySettings{
|
|
Type: SecurityType_TLS,
|
|
Settings: anyTLSSettings,
|
|
})
|
|
}
|
|
return nil
|
|
}
|