mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
[build]
This commit is contained in:
parent
b75e8f9500
commit
f5933b91f1
|
@ -3,6 +3,7 @@ package geodata
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"strings"
|
||||
|
||||
"github.com/Dreamacro/clash/component/geodata/router"
|
||||
|
@ -14,7 +15,7 @@ type loader struct {
|
|||
}
|
||||
|
||||
func (l *loader) LoadGeoSite(list string) ([]*router.Domain, error) {
|
||||
return l.LoadGeoSiteWithAttr("GeoSite.dat", list)
|
||||
return l.LoadGeoSiteWithAttr(C.GeositeName, list)
|
||||
}
|
||||
|
||||
func (l *loader) LoadGeoSiteWithAttr(file string, siteWithAttr string) ([]*router.Domain, error) {
|
||||
|
@ -58,7 +59,7 @@ func (l *loader) LoadGeoSiteWithAttr(file string, siteWithAttr string) ([]*route
|
|||
}
|
||||
|
||||
func (l *loader) LoadGeoIP(country string) ([]*router.CIDR, error) {
|
||||
return l.LoadIP("GeoIP.dat", country)
|
||||
return l.LoadIP(C.GeoipName, country)
|
||||
}
|
||||
|
||||
var loaders map[string]func() LoaderImplementation
|
||||
|
|
|
@ -42,6 +42,7 @@ type General struct {
|
|||
IPv6 bool `json:"ipv6"`
|
||||
Interface string `json:"-"`
|
||||
GeodataLoader string `json:"geodata-loader"`
|
||||
AutoIptables bool `json:"auto-iptables"`
|
||||
}
|
||||
|
||||
// Inbound
|
||||
|
@ -172,6 +173,7 @@ type RawConfig struct {
|
|||
Secret string `yaml:"secret"`
|
||||
Interface string `yaml:"interface-name"`
|
||||
GeodataLoader string `yaml:"geodata-loader"`
|
||||
AutoIptables bool `yaml:"auto-iptables"`
|
||||
|
||||
ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"`
|
||||
RuleProvider map[string]map[string]interface{} `yaml:"rule-providers"`
|
||||
|
@ -203,6 +205,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||
BindAddress: "*",
|
||||
Mode: T.Rule,
|
||||
GeodataLoader: "memconservative",
|
||||
AutoIptables: false,
|
||||
UnifiedDelay: false,
|
||||
Authentication: []string{},
|
||||
LogLevel: log.INFO,
|
||||
|
@ -260,7 +263,8 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||
|
||||
func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
||||
config := &Config{}
|
||||
|
||||
log.Infoln("Start initial configuration in progress") //Segment finished in xxm
|
||||
startTime := time.Now()
|
||||
config.Experimental = &rawCfg.Experimental
|
||||
config.Profile = &rawCfg.Profile
|
||||
|
||||
|
@ -305,6 +309,8 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
|||
|
||||
config.Users = parseAuthentication(rawCfg.Authentication)
|
||||
|
||||
elapsedTime := time.Since(startTime) / time.Millisecond // duration in ms
|
||||
log.Infoln("Initial configuration complete, total time: %dms", elapsedTime) //Segment finished in xxm
|
||||
return config, nil
|
||||
}
|
||||
|
||||
|
@ -341,6 +347,7 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
|||
IPv6: cfg.IPv6,
|
||||
Interface: cfg.Interface,
|
||||
GeodataLoader: cfg.GeodataLoader,
|
||||
AutoIptables: cfg.AutoIptables,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -487,8 +494,7 @@ time = ClashTime()
|
|||
|
||||
func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[string]*providerTypes.RuleProvider, error) {
|
||||
ruleProviders := map[string]*providerTypes.RuleProvider{}
|
||||
|
||||
startTime := time.Now()
|
||||
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
|
||||
// parse rule provider
|
||||
for name, mapping := range cfg.RuleProvider {
|
||||
rp, err := RP.ParseRuleProvider(name, mapping)
|
||||
|
@ -563,9 +569,7 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[strin
|
|||
rules = append(rules, parsed)
|
||||
}
|
||||
}
|
||||
elapsedTime := time.Since(startTime) / time.Millisecond // duration in ms
|
||||
log.Infoln("Initialization time consuming %dms", elapsedTime) //Segment finished in xxm
|
||||
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
|
||||
|
||||
runtime.GC()
|
||||
|
||||
return rules, ruleProviders, nil
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
package constant
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
P "path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const Name = "clash"
|
||||
|
||||
var (
|
||||
GeositeName = "GeoSite.dat"
|
||||
GeoipName = "GeoIP.dat"
|
||||
)
|
||||
|
||||
// Path is used to get the configuration path
|
||||
var Path = func() *path {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
|
@ -65,10 +72,40 @@ func (p *path) Cache() string {
|
|||
}
|
||||
|
||||
func (p *path) GeoIP() string {
|
||||
files, err := ioutil.ReadDir(p.homeDir)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, fi := range files {
|
||||
if fi.IsDir() {
|
||||
// 目录则直接跳过
|
||||
continue
|
||||
} else {
|
||||
if strings.EqualFold(fi.Name(), "GeoIP.dat") {
|
||||
GeoipName = fi.Name()
|
||||
return P.Join(p.homeDir, fi.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
return P.Join(p.homeDir, "GeoIP.dat")
|
||||
}
|
||||
|
||||
func (p *path) GeoSite() string {
|
||||
files, err := ioutil.ReadDir(p.homeDir)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, fi := range files {
|
||||
if fi.IsDir() {
|
||||
// 目录则直接跳过
|
||||
continue
|
||||
} else {
|
||||
if strings.EqualFold(fi.Name(), "GeoSite.dat") {
|
||||
GeositeName = fi.Name()
|
||||
return P.Join(p.homeDir, fi.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
return P.Join(p.homeDir, "GeoSite.dat")
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ package constant
|
|||
|
||||
var (
|
||||
Meta = true
|
||||
Version = "1.9.0"
|
||||
Version = "1.9.1"
|
||||
BuildTime = "unknown time"
|
||||
AutoIptables string
|
||||
ClashName = "Clash.Meta"
|
||||
)
|
||||
|
|
|
@ -314,8 +314,7 @@ func patchSelectGroup(proxies map[string]C.Proxy) {
|
|||
}
|
||||
|
||||
func updateIPTables(dns *config.DNS, general *config.General, tun *config.Tun) {
|
||||
AutoIptables := C.AutoIptables
|
||||
if runtime.GOOS != "linux" || dns.Listen == "" || general.TProxyPort == 0 || tun.Enable || AutoIptables != "Enable" {
|
||||
if runtime.GOOS != "linux" || dns.Listen == "" || general.TProxyPort == 0 || tun.Enable || !general.AutoIptables {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -342,8 +341,7 @@ func updateIPTables(dns *config.DNS, general *config.General, tun *config.Tun) {
|
|||
|
||||
func CleanUp() {
|
||||
P.CleanUp()
|
||||
AutoIptables := C.AutoIptables
|
||||
if runtime.GOOS == "linux" && AutoIptables == "Enable" {
|
||||
if runtime.GOOS == "linux" {
|
||||
tproxy.CleanUpTProxyLinuxIPTables()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,6 @@ func (ps *Process) Match(metadata *C.Metadata) bool {
|
|||
return strings.EqualFold(metadata.Process, ps.process)
|
||||
}
|
||||
|
||||
if C.AutoIptables == "Enable" {
|
||||
return false
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%s:%s:%s", metadata.NetWork.String(), metadata.SrcIP.String(), metadata.SrcPort)
|
||||
if strings.TrimSpace(metadata.Process) == "" {
|
||||
cached, hit := processCache.Get(key)
|
||||
|
|
Loading…
Reference in New Issue
Block a user