Chore: remove forward compatibility code
This commit is contained in:
parent
f7aa21c0e5
commit
062fbffbae
5 changed files with 4 additions and 77 deletions
|
@ -169,7 +169,6 @@ proxies:
|
||||||
password: "password"
|
password: "password"
|
||||||
# udp: true
|
# udp: true
|
||||||
|
|
||||||
# old obfs configuration format remove after prerelease
|
|
||||||
- name: "ss2"
|
- name: "ss2"
|
||||||
type: ss
|
type: ss
|
||||||
server: server
|
server: server
|
||||||
|
@ -368,8 +367,6 @@ rules:
|
||||||
- GEOIP,CN,DIRECT
|
- GEOIP,CN,DIRECT
|
||||||
- DST-PORT,80,DIRECT
|
- DST-PORT,80,DIRECT
|
||||||
- SRC-PORT,7777,DIRECT
|
- SRC-PORT,7777,DIRECT
|
||||||
# FINAL would remove after prerelease
|
|
||||||
# you also can use `FINAL,Proxy` or `FINAL,,Proxy` now
|
|
||||||
- MATCH,auto
|
- MATCH,auto
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
|
@ -37,10 +37,6 @@ type ShadowSocksOption struct {
|
||||||
UDP bool `proxy:"udp,omitempty"`
|
UDP bool `proxy:"udp,omitempty"`
|
||||||
Plugin string `proxy:"plugin,omitempty"`
|
Plugin string `proxy:"plugin,omitempty"`
|
||||||
PluginOpts map[string]interface{} `proxy:"plugin-opts,omitempty"`
|
PluginOpts map[string]interface{} `proxy:"plugin-opts,omitempty"`
|
||||||
|
|
||||||
// deprecated when bump to 1.0
|
|
||||||
Obfs string `proxy:"obfs,omitempty"`
|
|
||||||
ObfsHost string `proxy:"obfs-host,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type simpleObfsOption struct {
|
type simpleObfsOption struct {
|
||||||
|
@ -122,17 +118,6 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
|
||||||
var obfsOption *simpleObfsOption
|
var obfsOption *simpleObfsOption
|
||||||
obfsMode := ""
|
obfsMode := ""
|
||||||
|
|
||||||
// forward compatibility before 1.0
|
|
||||||
if option.Obfs != "" {
|
|
||||||
obfsMode = option.Obfs
|
|
||||||
obfsOption = &simpleObfsOption{
|
|
||||||
Host: "bing.com",
|
|
||||||
}
|
|
||||||
if option.ObfsHost != "" {
|
|
||||||
obfsOption.Host = option.ObfsHost
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder := structure.NewDecoder(structure.Option{TagName: "obfs", WeaklyTypedInput: true})
|
decoder := structure.NewDecoder(structure.Option{TagName: "obfs", WeaklyTypedInput: true})
|
||||||
if option.Plugin == "obfs" {
|
if option.Plugin == "obfs" {
|
||||||
opts := simpleObfsOption{Host: "bing.com"}
|
opts := simpleObfsOption{Host: "bing.com"}
|
||||||
|
|
|
@ -126,12 +126,6 @@ type RawConfig struct {
|
||||||
Proxy []map[string]interface{} `yaml:"proxies"`
|
Proxy []map[string]interface{} `yaml:"proxies"`
|
||||||
ProxyGroup []map[string]interface{} `yaml:"proxy-groups"`
|
ProxyGroup []map[string]interface{} `yaml:"proxy-groups"`
|
||||||
Rule []string `yaml:"rules"`
|
Rule []string `yaml:"rules"`
|
||||||
|
|
||||||
// remove after 1.0
|
|
||||||
ProxyProviderOld map[string]map[string]interface{} `yaml:"proxy-provider"`
|
|
||||||
ProxyOld []map[string]interface{} `yaml:"Proxy"`
|
|
||||||
ProxyGroupOld []map[string]interface{} `yaml:"Proxy Group"`
|
|
||||||
RuleOld []string `yaml:"Rule"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse config
|
// Parse config
|
||||||
|
@ -168,11 +162,6 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
||||||
"8.8.8.8",
|
"8.8.8.8",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// remove after 1.0
|
|
||||||
RuleOld: []string{},
|
|
||||||
ProxyOld: []map[string]interface{}{},
|
|
||||||
ProxyGroupOld: []map[string]interface{}{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := yaml.Unmarshal(buf, &rawCfg); err != nil {
|
if err := yaml.Unmarshal(buf, &rawCfg); err != nil {
|
||||||
|
@ -264,18 +253,6 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
||||||
groupsConfig := cfg.ProxyGroup
|
groupsConfig := cfg.ProxyGroup
|
||||||
providersConfig := cfg.ProxyProvider
|
providersConfig := cfg.ProxyProvider
|
||||||
|
|
||||||
if len(proxiesConfig) == 0 {
|
|
||||||
proxiesConfig = cfg.ProxyOld
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(groupsConfig) == 0 {
|
|
||||||
groupsConfig = cfg.ProxyGroupOld
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(providersConfig) == 0 {
|
|
||||||
providersConfig = cfg.ProxyProviderOld
|
|
||||||
}
|
|
||||||
|
|
||||||
proxies["DIRECT"] = outbound.NewProxy(outbound.NewDirect())
|
proxies["DIRECT"] = outbound.NewProxy(outbound.NewDirect())
|
||||||
proxies["REJECT"] = outbound.NewProxy(outbound.NewReject())
|
proxies["REJECT"] = outbound.NewProxy(outbound.NewReject())
|
||||||
proxyList = append(proxyList, "DIRECT", "REJECT")
|
proxyList = append(proxyList, "DIRECT", "REJECT")
|
||||||
|
@ -371,14 +348,8 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
||||||
|
|
||||||
func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, error) {
|
func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, error) {
|
||||||
rules := []C.Rule{}
|
rules := []C.Rule{}
|
||||||
|
|
||||||
rulesConfig := cfg.Rule
|
rulesConfig := cfg.Rule
|
||||||
|
|
||||||
// remove after 1.0
|
|
||||||
if len(rulesConfig) == 0 {
|
|
||||||
rulesConfig = cfg.RuleOld
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse rules
|
// parse rules
|
||||||
for idx, line := range rulesConfig {
|
for idx, line := range rulesConfig {
|
||||||
rule := trimArr(strings.Split(line, ","))
|
rule := trimArr(strings.Split(line, ","))
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/adapters/provider"
|
"github.com/Dreamacro/clash/adapters/provider"
|
||||||
|
@ -25,30 +24,11 @@ var (
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
// forward compatibility before 1.0
|
|
||||||
func readRawConfig(path string) ([]byte, error) {
|
|
||||||
data, err := ioutil.ReadFile(path)
|
|
||||||
if err == nil && len(data) != 0 {
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if filepath.Ext(path) != ".yaml" {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
path = path[:len(path)-5] + ".yml"
|
|
||||||
if _, fallbackErr := os.Stat(path); fallbackErr == nil {
|
|
||||||
return ioutil.ReadFile(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
return data, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func readConfig(path string) ([]byte, error) {
|
func readConfig(path string) ([]byte, error) {
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := readRawConfig(path)
|
data, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -168,9 +148,9 @@ func updateGeneral(general *config.General, force bool) {
|
||||||
tunnel.SetMode(general.Mode)
|
tunnel.SetMode(general.Mode)
|
||||||
resolver.DisableIPv6 = !general.IPv6
|
resolver.DisableIPv6 = !general.IPv6
|
||||||
|
|
||||||
if cfg.Interface != "" {
|
if general.Interface != "" {
|
||||||
dialer.DialHook = dialer.DialerWithInterface(cfg.Interface)
|
dialer.DialHook = dialer.DialerWithInterface(general.Interface)
|
||||||
dialer.ListenPacketHook = dialer.ListenPacketWithInterface(cfg.Interface)
|
dialer.ListenPacketHook = dialer.ListenPacketWithInterface(general.Interface)
|
||||||
} else {
|
} else {
|
||||||
dialer.DialHook = nil
|
dialer.DialHook = nil
|
||||||
dialer.ListenPacketHook = nil
|
dialer.ListenPacketHook = nil
|
||||||
|
|
|
@ -25,9 +25,6 @@ func ParseRule(tp, payload, target string, params []string) (C.Rule, error) {
|
||||||
case "IP-CIDR", "IP-CIDR6":
|
case "IP-CIDR", "IP-CIDR6":
|
||||||
noResolve := HasNoResolve(params)
|
noResolve := HasNoResolve(params)
|
||||||
parsed, parseErr = NewIPCIDR(payload, target, WithIPCIDRNoResolve(noResolve))
|
parsed, parseErr = NewIPCIDR(payload, target, WithIPCIDRNoResolve(noResolve))
|
||||||
// deprecated when bump to 1.0
|
|
||||||
case "SOURCE-IP-CIDR":
|
|
||||||
fallthrough
|
|
||||||
case "SRC-IP-CIDR":
|
case "SRC-IP-CIDR":
|
||||||
parsed, parseErr = NewIPCIDR(payload, target, WithIPCIDRSourceIP(true), WithIPCIDRNoResolve(true))
|
parsed, parseErr = NewIPCIDR(payload, target, WithIPCIDRSourceIP(true), WithIPCIDRNoResolve(true))
|
||||||
case "SRC-PORT":
|
case "SRC-PORT":
|
||||||
|
@ -35,9 +32,6 @@ func ParseRule(tp, payload, target string, params []string) (C.Rule, error) {
|
||||||
case "DST-PORT":
|
case "DST-PORT":
|
||||||
parsed, parseErr = NewPort(payload, target, false)
|
parsed, parseErr = NewPort(payload, target, false)
|
||||||
case "MATCH":
|
case "MATCH":
|
||||||
fallthrough
|
|
||||||
// deprecated when bump to 1.0
|
|
||||||
case "FINAL":
|
|
||||||
parsed = NewMatch(target)
|
parsed = NewMatch(target)
|
||||||
default:
|
default:
|
||||||
parseErr = fmt.Errorf("unsupported rule type %s", tp)
|
parseErr = fmt.Errorf("unsupported rule type %s", tp)
|
||||||
|
|
Loading…
Reference in a new issue