mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
refactor: remove useless code
This commit is contained in:
parent
aa0d174ccb
commit
d52b00bd34
|
@ -99,12 +99,6 @@ type FallbackFilter struct {
|
||||||
GeoSite []*router.DomainMatcher `yaml:"geosite"`
|
GeoSite []*router.DomainMatcher `yaml:"geosite"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
GroupsList = list.New()
|
|
||||||
ProxiesList = list.New()
|
|
||||||
ParsingProxiesCallback func(groupsList *list.List, proxiesList *list.List)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Profile config
|
// Profile config
|
||||||
type Profile struct {
|
type Profile struct {
|
||||||
StoreSelected bool `yaml:"store-selected"`
|
StoreSelected bool `yaml:"store-selected"`
|
||||||
|
@ -130,7 +124,6 @@ type IPTables struct {
|
||||||
|
|
||||||
type Sniffer struct {
|
type Sniffer struct {
|
||||||
Enable bool
|
Enable bool
|
||||||
Force bool
|
|
||||||
Sniffers []sniffer.Type
|
Sniffers []sniffer.Type
|
||||||
Reverses *trie.DomainTrie[bool]
|
Reverses *trie.DomainTrie[bool]
|
||||||
ForceDomain *trie.DomainTrie[bool]
|
ForceDomain *trie.DomainTrie[bool]
|
||||||
|
@ -213,7 +206,7 @@ type RawConfig struct {
|
||||||
GeodataLoader string `yaml:"geodata-loader"`
|
GeodataLoader string `yaml:"geodata-loader"`
|
||||||
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
|
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
|
||||||
|
|
||||||
Sniffer SnifferRaw `yaml:"sniffer"`
|
Sniffer RawSniffer `yaml:"sniffer"`
|
||||||
ProxyProvider map[string]map[string]any `yaml:"proxy-providers"`
|
ProxyProvider map[string]map[string]any `yaml:"proxy-providers"`
|
||||||
RuleProvider map[string]map[string]any `yaml:"rule-providers"`
|
RuleProvider map[string]map[string]any `yaml:"rule-providers"`
|
||||||
Hosts map[string]string `yaml:"hosts"`
|
Hosts map[string]string `yaml:"hosts"`
|
||||||
|
@ -227,14 +220,11 @@ type RawConfig struct {
|
||||||
Rule []string `yaml:"rules"`
|
Rule []string `yaml:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SnifferRaw struct {
|
type RawSniffer struct {
|
||||||
Enable bool `yaml:"enable" json:"enable"`
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
Sniffing []string `yaml:"sniffing" json:"sniffing"`
|
Sniffing []string `yaml:"sniffing" json:"sniffing"`
|
||||||
Force bool `yaml:"force" json:"force"`
|
|
||||||
Reverse []string `yaml:"reverses" json:"reverses"`
|
|
||||||
ForceDomain []string `yaml:"force-domain" json:"force-domain"`
|
ForceDomain []string `yaml:"force-domain" json:"force-domain"`
|
||||||
SkipDomain []string `yaml:"skip-domain" json:"skip-domain"`
|
SkipDomain []string `yaml:"skip-domain" json:"skip-domain"`
|
||||||
SkipSNI []string `yaml:"skip-sni" json:"skip-sni"`
|
|
||||||
Ports []string `yaml:"port-whitelist" json:"port-whitelist"`
|
Ports []string `yaml:"port-whitelist" json:"port-whitelist"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,11 +294,9 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
||||||
"www.msftconnecttest.com",
|
"www.msftconnecttest.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Sniffer: SnifferRaw{
|
Sniffer: RawSniffer{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
Force: false,
|
|
||||||
Sniffing: []string{},
|
Sniffing: []string{},
|
||||||
Reverse: []string{},
|
|
||||||
ForceDomain: []string{},
|
ForceDomain: []string{},
|
||||||
SkipDomain: []string{},
|
SkipDomain: []string{},
|
||||||
Ports: []string{},
|
Ports: []string{},
|
||||||
|
@ -432,8 +420,8 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
||||||
providersConfig := cfg.ProxyProvider
|
providersConfig := cfg.ProxyProvider
|
||||||
|
|
||||||
var proxyList []string
|
var proxyList []string
|
||||||
_proxiesList := list.New()
|
proxiesList := list.New()
|
||||||
_groupsList := list.New()
|
groupsList := list.New()
|
||||||
|
|
||||||
proxies["DIRECT"] = adapter.NewProxy(outbound.NewDirect())
|
proxies["DIRECT"] = adapter.NewProxy(outbound.NewDirect())
|
||||||
proxies["REJECT"] = adapter.NewProxy(outbound.NewReject())
|
proxies["REJECT"] = adapter.NewProxy(outbound.NewReject())
|
||||||
|
@ -453,7 +441,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
||||||
}
|
}
|
||||||
proxies[proxy.Name()] = proxy
|
proxies[proxy.Name()] = proxy
|
||||||
proxyList = append(proxyList, proxy.Name())
|
proxyList = append(proxyList, proxy.Name())
|
||||||
_proxiesList.PushBack(mapping)
|
proxiesList.PushBack(mapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep the original order of ProxyGroups in config file
|
// keep the original order of ProxyGroups in config file
|
||||||
|
@ -463,7 +451,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
||||||
return nil, nil, fmt.Errorf("proxy group %d: missing name", idx)
|
return nil, nil, fmt.Errorf("proxy group %d: missing name", idx)
|
||||||
}
|
}
|
||||||
proxyList = append(proxyList, groupName)
|
proxyList = append(proxyList, groupName)
|
||||||
_groupsList.PushBack(mapping)
|
groupsList.PushBack(mapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if any loop exists and sort the ProxyGroups
|
// check if any loop exists and sort the ProxyGroups
|
||||||
|
@ -518,12 +506,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
||||||
[]providerTypes.ProxyProvider{pd},
|
[]providerTypes.ProxyProvider{pd},
|
||||||
)
|
)
|
||||||
proxies["GLOBAL"] = adapter.NewProxy(global)
|
proxies["GLOBAL"] = adapter.NewProxy(global)
|
||||||
ProxiesList = _proxiesList
|
|
||||||
GroupsList = _groupsList
|
|
||||||
if ParsingProxiesCallback != nil {
|
|
||||||
// refresh tray menu
|
|
||||||
go ParsingProxiesCallback(GroupsList, ProxiesList)
|
|
||||||
}
|
|
||||||
return proxies, providersMap, nil
|
return proxies, providersMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,10 +902,9 @@ func parseTun(rawTun RawTun, general *General) (*Tun, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSniffer(snifferRaw SnifferRaw) (*Sniffer, error) {
|
func parseSniffer(snifferRaw RawSniffer) (*Sniffer, error) {
|
||||||
sniffer := &Sniffer{
|
sniffer := &Sniffer{
|
||||||
Enable: snifferRaw.Enable,
|
Enable: snifferRaw.Enable,
|
||||||
Force: snifferRaw.Force,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ports []utils.Range[uint16]
|
var ports []utils.Range[uint16]
|
||||||
|
@ -979,10 +961,7 @@ func parseSniffer(snifferRaw SnifferRaw) (*Sniffer, error) {
|
||||||
return nil, fmt.Errorf("error domian[%s] in force-domain, error:%v", domain, err)
|
return nil, fmt.Errorf("error domian[%s] in force-domain, error:%v", domain, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if snifferRaw.SkipSNI != nil {
|
|
||||||
log.Warnln("Sniffer param skip-sni renamed to ship-domain, old param will be removed in the release version")
|
|
||||||
snifferRaw.SkipDomain = snifferRaw.SkipSNI
|
|
||||||
}
|
|
||||||
sniffer.SkipDomain = trie.New[bool]()
|
sniffer.SkipDomain = trie.New[bool]()
|
||||||
for _, domain := range snifferRaw.SkipDomain {
|
for _, domain := range snifferRaw.SkipDomain {
|
||||||
err := sniffer.SkipDomain.Insert(domain, true)
|
err := sniffer.SkipDomain.Insert(domain, true)
|
||||||
|
@ -991,27 +970,5 @@ func parseSniffer(snifferRaw SnifferRaw) (*Sniffer, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compatibility, remove it when release
|
|
||||||
if strings.Contains(C.Version, "alpha") || strings.Contains(C.Version, "develop") || strings.Contains(C.Version, "1.10.0") {
|
|
||||||
log.Warnln("Sniffer param force and reverses deprecated, will be removed in the release version, see https://github.com/MetaCubeX/Clash.Meta/commit/48a01adb7a4f38974b9d9639f931d0d245aebf28")
|
|
||||||
if snifferRaw.Force {
|
|
||||||
// match all domain
|
|
||||||
sniffer.ForceDomain.Insert("+", true)
|
|
||||||
for _, domain := range snifferRaw.Reverse {
|
|
||||||
err := sniffer.SkipDomain.Insert(domain, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error domian[%s], error:%v", domain, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, domain := range snifferRaw.Reverse {
|
|
||||||
err := sniffer.ForceDomain.Insert(domain, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error domian[%s], error:%v", domain, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sniffer, nil
|
return sniffer, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ func GetAutoDetectInterface(tunName string) (ifn string, err error) {
|
||||||
return "", fmt.Errorf("interface not found")
|
return "", fmt.Errorf("interface not found")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
//err = fmt.Errorf("interface not found")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int, autoRoute, autoDetectInterface bool) error {
|
func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int, autoRoute, autoDetectInterface bool) error {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user