config_json.go 579 B

123456789101112131415161718192021222324252627
  1. // +build json
  2. package transport
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/transport/internet/kcp"
  6. "github.com/v2ray/v2ray-core/transport/internet/tcp"
  7. )
  8. func (this *Config) UnmarshalJSON(data []byte) error {
  9. type JsonConfig struct {
  10. TCPConfig *tcp.Config `json:"tcpSettings"`
  11. KCPConfig kcp.Config `json:"kcpSettings"`
  12. }
  13. jsonConfig := &JsonConfig{
  14. KCPConfig: kcp.DefaultConfig(),
  15. }
  16. if err := json.Unmarshal(data, jsonConfig); err != nil {
  17. return err
  18. }
  19. this.tcpConfig = jsonConfig.TCPConfig
  20. this.kcpConfig = jsonConfig.KCPConfig
  21. return nil
  22. }