connection.go 779 B

1234567891011121314151617181920212223242526272829303132
  1. package json
  2. import (
  3. "encoding/json"
  4. "github.com/v2ray/v2ray-core/common/log"
  5. "github.com/v2ray/v2ray-core/config"
  6. )
  7. type ConnectionConfig struct {
  8. ProtocolString string `json:"protocol"`
  9. SettingsMessage json.RawMessage `json:"settings"`
  10. Type config.Type `json:"-"`
  11. }
  12. func (c *ConnectionConfig) Protocol() string {
  13. return c.ProtocolString
  14. }
  15. func (c *ConnectionConfig) Settings() interface{} {
  16. creator, found := configCache[getConfigKey(c.Protocol(), c.Type)]
  17. if !found {
  18. panic("Unknown protocol " + c.Protocol())
  19. }
  20. configObj := creator()
  21. err := json.Unmarshal(c.SettingsMessage, configObj)
  22. if err != nil {
  23. log.Error("Unable to parse connection config: %v", err)
  24. panic("Failed to parse connection config.")
  25. }
  26. return configObj
  27. }