receiver_json.go 979 B

1234567891011121314151617181920212223242526272829303132333435
  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/proxy/internal"
  8. "github.com/v2ray/v2ray-core/proxy/vmess"
  9. )
  10. func (this *Receiver) UnmarshalJSON(data []byte) error {
  11. type RawConfigTarget struct {
  12. Address *v2net.AddressJson `json:"address"`
  13. Port v2net.Port `json:"port"`
  14. Users []*vmess.User `json:"users"`
  15. }
  16. var rawConfig RawConfigTarget
  17. if err := json.Unmarshal(data, &rawConfig); err != nil {
  18. return err
  19. }
  20. if len(rawConfig.Users) == 0 {
  21. log.Error("VMess: 0 user configured for VMess outbound.")
  22. return internal.ErrorBadConfiguration
  23. }
  24. this.Accounts = rawConfig.Users
  25. if rawConfig.Address == nil {
  26. log.Error("VMess: Address is not set in VMess outbound config.")
  27. return internal.ErrorBadConfiguration
  28. }
  29. this.Destination = v2net.TCPDestination(rawConfig.Address.Address, rawConfig.Port)
  30. return nil
  31. }