2016-01-15 06:43:06 -05:00
|
|
|
// +build json
|
|
|
|
|
|
|
|
package freedom
|
|
|
|
|
|
|
|
import (
|
2016-05-22 16:30:21 -04:00
|
|
|
"encoding/json"
|
2016-06-11 16:52:37 -04:00
|
|
|
"errors"
|
2016-05-24 16:41:51 -04:00
|
|
|
"strings"
|
2016-05-22 16:30:21 -04:00
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/proxy/registry"
|
2016-01-15 06:43:06 -05:00
|
|
|
)
|
|
|
|
|
2016-05-22 16:30:21 -04:00
|
|
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
|
|
|
type JsonConfig struct {
|
|
|
|
DomainStrategy string `json:"domainStrategy"`
|
2016-06-02 17:18:44 -04:00
|
|
|
Timeout uint32 `json:"timeout"`
|
2016-05-22 16:30:21 -04:00
|
|
|
}
|
|
|
|
jsonConfig := new(JsonConfig)
|
|
|
|
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
2016-06-11 16:52:37 -04:00
|
|
|
return errors.New("Freedom: Failed to parse config: " + err.Error())
|
2016-05-22 16:30:21 -04:00
|
|
|
}
|
2016-08-25 15:55:49 -04:00
|
|
|
this.DomainStrategy = Config_AS_IS
|
2016-05-24 16:41:51 -04:00
|
|
|
domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)
|
2016-08-25 15:55:49 -04:00
|
|
|
if domainStrategy == "useip" || domainStrategy == "use_ip" {
|
|
|
|
this.DomainStrategy = Config_USE_IP
|
2016-05-22 16:30:21 -04:00
|
|
|
}
|
2016-06-02 17:18:44 -04:00
|
|
|
this.Timeout = jsonConfig.Timeout
|
2016-05-22 16:30:21 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-15 06:43:06 -05:00
|
|
|
func init() {
|
2016-08-17 17:30:15 -04:00
|
|
|
registry.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) })
|
2016-01-15 06:43:06 -05:00
|
|
|
}
|