Skip to content

Commit

Permalink
Chore: remove forward compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamacro committed Jun 27, 2020
1 parent 2781090 commit 7c62fe4
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 77 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ proxies:
password: "password"
# udp: true

# old obfs configuration format remove after prerelease
- name: "ss2"
type: ss
server: server
Expand Down Expand Up @@ -368,8 +367,6 @@ rules:
- GEOIP,CN,DIRECT
- DST-PORT,80,DIRECT
- SRC-PORT,7777,DIRECT
# FINAL would remove after prerelease
# you also can use `FINAL,Proxy` or `FINAL,,Proxy` now
- MATCH,auto
```
</details>
Expand Down
15 changes: 0 additions & 15 deletions adapters/outbound/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ type ShadowSocksOption struct {
UDP bool `proxy:"udp,omitempty"`
Plugin string `proxy:"plugin,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 {
Expand Down Expand Up @@ -122,17 +118,6 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
var obfsOption *simpleObfsOption
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})
if option.Plugin == "obfs" {
opts := simpleObfsOption{Host: "bing.com"}
Expand Down
29 changes: 0 additions & 29 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ type RawConfig struct {
Proxy []map[string]interface{} `yaml:"proxies"`
ProxyGroup []map[string]interface{} `yaml:"proxy-groups"`
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
Expand Down Expand Up @@ -168,11 +162,6 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
"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 {
Expand Down Expand Up @@ -264,18 +253,6 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
groupsConfig := cfg.ProxyGroup
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["REJECT"] = outbound.NewProxy(outbound.NewReject())
proxyList = append(proxyList, "DIRECT", "REJECT")
Expand Down Expand Up @@ -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) {
rules := []C.Rule{}

rulesConfig := cfg.Rule

// remove after 1.0
if len(rulesConfig) == 0 {
rulesConfig = cfg.RuleOld
}

// parse rules
for idx, line := range rulesConfig {
rule := trimArr(strings.Split(line, ","))
Expand Down
28 changes: 4 additions & 24 deletions hub/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"

"github.com/Dreamacro/clash/adapters/provider"
Expand All @@ -25,30 +24,11 @@ var (
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) {
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, err
}
data, err := readRawConfig(path)
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -168,9 +148,9 @@ func updateGeneral(general *config.General, force bool) {
tunnel.SetMode(general.Mode)
resolver.DisableIPv6 = !general.IPv6

if cfg.Interface != "" {
dialer.DialHook = dialer.DialerWithInterface(cfg.Interface)
dialer.ListenPacketHook = dialer.ListenPacketWithInterface(cfg.Interface)
if general.Interface != "" {
dialer.DialHook = dialer.DialerWithInterface(general.Interface)
dialer.ListenPacketHook = dialer.ListenPacketWithInterface(general.Interface)
} else {
dialer.DialHook = nil
dialer.ListenPacketHook = nil
Expand Down
6 changes: 0 additions & 6 deletions rules/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ func ParseRule(tp, payload, target string, params []string) (C.Rule, error) {
case "IP-CIDR", "IP-CIDR6":
noResolve := HasNoResolve(params)
parsed, parseErr = NewIPCIDR(payload, target, WithIPCIDRNoResolve(noResolve))
// deprecated when bump to 1.0
case "SOURCE-IP-CIDR":
fallthrough
case "SRC-IP-CIDR":
parsed, parseErr = NewIPCIDR(payload, target, WithIPCIDRSourceIP(true), WithIPCIDRNoResolve(true))
case "SRC-PORT":
parsed, parseErr = NewPort(payload, target, true)
case "DST-PORT":
parsed, parseErr = NewPort(payload, target, false)
case "MATCH":
fallthrough
// deprecated when bump to 1.0
case "FINAL":
parsed = NewMatch(target)
default:
parseErr = fmt.Errorf("unsupported rule type %s", tp)
Expand Down

0 comments on commit 7c62fe4

Please sign in to comment.