[FEAT] Add geodata loader mode switch

This commit is contained in:
gVisor bot 2022-02-05 00:51:06 +08:00
parent c57d92d7c1
commit e3a61dbbd3
5 changed files with 31 additions and 17 deletions

View File

@ -5,8 +5,19 @@ import (
"strings" "strings"
) )
var geoLoaderName = "memconservative"
// geoLoaderName = "standard"
func LoaderName() string {
return geoLoaderName
}
func SetLoader(newLoader string) {
geoLoaderName = newLoader
}
func LoadGeoSiteMatcher(countryCode string) (*router.DomainMatcher, int, error) { func LoadGeoSiteMatcher(countryCode string) (*router.DomainMatcher, int, error) {
geoLoaderName := "memconservative"
geoLoader, err := GetGeoDataLoader(geoLoaderName) geoLoader, err := GetGeoDataLoader(geoLoaderName)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
@ -31,7 +42,6 @@ func LoadGeoSiteMatcher(countryCode string) (*router.DomainMatcher, int, error)
} }
func LoadGeoIPMatcher(country string) (*router.GeoIPMatcher, int, error) { func LoadGeoIPMatcher(country string) (*router.GeoIPMatcher, int, error) {
geoLoaderName := "memconservative"
geoLoader, err := GetGeoDataLoader(geoLoaderName) geoLoader, err := GetGeoDataLoader(geoLoaderName)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err

View File

@ -35,12 +35,12 @@ import (
type General struct { type General struct {
Inbound Inbound
Controller Controller
Mode T.TunnelMode `json:"mode"` Mode T.TunnelMode `json:"mode"`
UnifiedDelay bool UnifiedDelay bool
LogLevel log.LogLevel `json:"log-level"` LogLevel log.LogLevel `json:"log-level"`
IPv6 bool `json:"ipv6"` IPv6 bool `json:"ipv6"`
Interface string `json:"-"` Interface string `json:"-"`
Geodataload string `json:"geodataload"` GeodataLoader string `json:"geodata-loader"`
} }
// Inbound // Inbound
@ -170,7 +170,7 @@ type RawConfig struct {
ExternalUI string `yaml:"external-ui"` ExternalUI string `yaml:"external-ui"`
Secret string `yaml:"secret"` Secret string `yaml:"secret"`
Interface string `yaml:"interface-name"` Interface string `yaml:"interface-name"`
Geodataloader string `yaml:"geodata-loader"` GeodataLoader string `yaml:"geodata-loader"`
ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"` ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"`
RuleProvider map[string]map[string]interface{} `yaml:"rule-providers"` RuleProvider map[string]map[string]interface{} `yaml:"rule-providers"`
@ -201,7 +201,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
AllowLan: false, AllowLan: false,
BindAddress: "*", BindAddress: "*",
Mode: T.Rule, Mode: T.Rule,
Geodataloader: "standard", GeodataLoader: "memconservative",
UnifiedDelay: false, UnifiedDelay: false,
Authentication: []string{}, Authentication: []string{},
LogLevel: log.INFO, LogLevel: log.INFO,

View File

@ -21,7 +21,7 @@ var geoIPMatcher *router.GeoIPMatcher
func (gf *geoipFilter) Match(ip net.IP) bool { func (gf *geoipFilter) Match(ip net.IP) bool {
if geoIPMatcher == nil { if geoIPMatcher == nil {
countryCode := "cn" countryCode := "cn"
geoLoader, err := geodata.GetGeoDataLoader("standard") geoLoader, err := geodata.GetGeoDataLoader(geodata.LoaderName())
if err != nil { if err != nil {
log.Errorln("[GeoIPFilter] GetGeoDataLoader error: %s", err.Error()) log.Errorln("[GeoIPFilter] GetGeoDataLoader error: %s", err.Error())
return false return false

View File

@ -2,6 +2,7 @@ package executor
import ( import (
"fmt" "fmt"
"net" "net"
"os" "os"
"runtime" "runtime"
@ -15,6 +16,7 @@ import (
"github.com/Dreamacro/clash/adapter/outboundgroup" "github.com/Dreamacro/clash/adapter/outboundgroup"
"github.com/Dreamacro/clash/component/auth" "github.com/Dreamacro/clash/component/auth"
"github.com/Dreamacro/clash/component/dialer" "github.com/Dreamacro/clash/component/dialer"
G "github.com/Dreamacro/clash/component/geodata"
"github.com/Dreamacro/clash/component/iface" "github.com/Dreamacro/clash/component/iface"
"github.com/Dreamacro/clash/component/profile" "github.com/Dreamacro/clash/component/profile"
"github.com/Dreamacro/clash/component/profile/cachefile" "github.com/Dreamacro/clash/component/profile/cachefile"
@ -106,9 +108,10 @@ func GetGeneral() *config.General {
AllowLan: P.AllowLan(), AllowLan: P.AllowLan(),
BindAddress: P.BindAddress(), BindAddress: P.BindAddress(),
}, },
Mode: tunnel.Mode(), Mode: tunnel.Mode(),
LogLevel: log.Level(), LogLevel: log.Level(),
IPv6: !resolver.DisableIPv6, IPv6: !resolver.DisableIPv6,
GeodataLoader: G.LoaderName(),
} }
return general return general
@ -239,6 +242,9 @@ func updateGeneral(general *config.General, Tun *config.Tun, force bool) {
return return
} }
geodataLoader := general.GeodataLoader
G.SetLoader(geodataLoader)
allowLan := general.AllowLan allowLan := general.AllowLan
P.SetAllowLan(allowLan) P.SetAllowLan(allowLan)

View File

@ -27,10 +27,8 @@ func (ps *Process) Match(metadata *C.Metadata) bool {
if metadata.Process != "" { if metadata.Process != "" {
return strings.EqualFold(metadata.Process, ps.process) return strings.EqualFold(metadata.Process, ps.process)
} }
// ignore match in proxy type "tproxy"
//if metadata.Type == C.TPROXY || !C.AutoIptables {
if metadata.Type == C.TPROXY || C.AutoIptables == "Enable" { if C.AutoIptables == "Enable" {
return false return false
} }