1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-19 19:06:43 -05:00
v2fly/proxy/vmess/outbound/receiver_json.go

40 lines
1.2 KiB
Go
Raw Normal View History

// +build json
package outbound
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
2016-05-07 14:26:29 -04:00
"github.com/v2ray/v2ray-core/common/protocol"
2016-05-23 14:16:36 -04:00
"github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/proxy/internal"
)
func (this *Receiver) UnmarshalJSON(data []byte) error {
type RawConfigTarget struct {
2016-01-15 07:17:04 -05:00
Address *v2net.AddressJson `json:"address"`
Port v2net.Port `json:"port"`
2016-05-07 14:26:29 -04:00
Users []*protocol.User `json:"users"`
}
var rawConfig RawConfigTarget
if err := json.Unmarshal(data, &rawConfig); err != nil {
return err
}
if len(rawConfig.Users) == 0 {
log.Error("VMess: 0 user configured for VMess outbound.")
return internal.ErrorBadConfiguration
}
this.Accounts = rawConfig.Users
if rawConfig.Address == nil {
log.Error("VMess: Address is not set in VMess outbound config.")
return internal.ErrorBadConfiguration
}
2016-05-23 14:16:36 -04:00
if rawConfig.Address.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) {
2016-06-26 16:34:48 -04:00
rawConfig.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(2891346854, nil))
2016-05-23 14:16:36 -04:00
}
2016-01-15 07:17:04 -05:00
this.Destination = v2net.TCPDestination(rawConfig.Address.Address, rawConfig.Port)
return nil
}