config_json.go 797 B

1234567891011121314151617181920212223242526272829303132
  1. // +build json
  2. package transport
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/transport/hub/kcpv"
  6. )
  7. func (this *Config) UnmarshalJSON(data []byte) error {
  8. type JsonConfig struct {
  9. ConnectionReuse bool `json:"connectionReuse"`
  10. EnableKcp bool `json:"EnableKCP,omitempty"`
  11. KcpConfig *kcpv.Config `json:"KcpConfig,omitempty"`
  12. }
  13. jsonConfig := &JsonConfig{
  14. ConnectionReuse: true,
  15. EnableKcp: false,
  16. }
  17. if err := json.Unmarshal(data, jsonConfig); err != nil {
  18. return err
  19. }
  20. this.ConnectionReuse = jsonConfig.ConnectionReuse
  21. this.enableKcp = jsonConfig.EnableKcp
  22. this.kcpConfig = jsonConfig.KcpConfig
  23. if jsonConfig.KcpConfig.AdvancedConfigs == nil {
  24. jsonConfig.KcpConfig.AdvancedConfigs = kcpv.DefaultAdvancedConfigs
  25. }
  26. return nil
  27. }