receiver_json.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // +build json
  2. package outbound
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/common/log"
  6. v2net "github.com/v2ray/v2ray-core/common/net"
  7. "github.com/v2ray/v2ray-core/common/protocol"
  8. "github.com/v2ray/v2ray-core/common/serial"
  9. "github.com/v2ray/v2ray-core/proxy/internal"
  10. )
  11. func (this *Receiver) UnmarshalJSON(data []byte) error {
  12. type RawConfigTarget struct {
  13. Address *v2net.AddressJson `json:"address"`
  14. Port v2net.Port `json:"port"`
  15. Users []*protocol.User `json:"users"`
  16. }
  17. var rawConfig RawConfigTarget
  18. if err := json.Unmarshal(data, &rawConfig); err != nil {
  19. return err
  20. }
  21. if len(rawConfig.Users) == 0 {
  22. log.Error("VMess: 0 user configured for VMess outbound.")
  23. return internal.ErrBadConfiguration
  24. }
  25. this.Accounts = rawConfig.Users
  26. if rawConfig.Address == nil {
  27. log.Error("VMess: Address is not set in VMess outbound config.")
  28. return internal.ErrBadConfiguration
  29. }
  30. if rawConfig.Address.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) {
  31. rawConfig.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(2891346854, nil))
  32. }
  33. this.Destination = v2net.TCPDestination(rawConfig.Address.Address, rawConfig.Port)
  34. return nil
  35. }