2016-01-15 06:43:06 -05:00
|
|
|
// +build json
|
|
|
|
|
|
|
|
package outbound
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
2016-02-03 05:58:42 -05:00
|
|
|
proto "github.com/v2ray/v2ray-core/common/protocol"
|
2016-01-15 06:43:06 -05:00
|
|
|
"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-02-03 05:58:42 -05:00
|
|
|
Users []*proto.User `json:"users"`
|
2016-01-15 06:43:06 -05:00
|
|
|
}
|
|
|
|
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-01-15 07:17:04 -05:00
|
|
|
this.Destination = v2net.TCPDestination(rawConfig.Address.Address, rawConfig.Port)
|
2016-01-15 06:43:06 -05:00
|
|
|
return nil
|
|
|
|
}
|