[FEAT] Add geodata loader mode switch
This commit is contained in:
parent
2bf34c766e
commit
c28f42d823
5 changed files with 31 additions and 17 deletions
|
@ -5,8 +5,19 @@ import (
|
|||
"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) {
|
||||
geoLoaderName := "memconservative"
|
||||
geoLoader, err := GetGeoDataLoader(geoLoaderName)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
@ -31,7 +42,6 @@ func LoadGeoSiteMatcher(countryCode string) (*router.DomainMatcher, int, error)
|
|||
}
|
||||
|
||||
func LoadGeoIPMatcher(country string) (*router.GeoIPMatcher, int, error) {
|
||||
geoLoaderName := "memconservative"
|
||||
geoLoader, err := GetGeoDataLoader(geoLoaderName)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
|
|
@ -35,12 +35,12 @@ import (
|
|||
type General struct {
|
||||
Inbound
|
||||
Controller
|
||||
Mode T.TunnelMode `json:"mode"`
|
||||
UnifiedDelay bool
|
||||
LogLevel log.LogLevel `json:"log-level"`
|
||||
IPv6 bool `json:"ipv6"`
|
||||
Interface string `json:"-"`
|
||||
Geodataload string `json:"geodataload"`
|
||||
Mode T.TunnelMode `json:"mode"`
|
||||
UnifiedDelay bool
|
||||
LogLevel log.LogLevel `json:"log-level"`
|
||||
IPv6 bool `json:"ipv6"`
|
||||
Interface string `json:"-"`
|
||||
GeodataLoader string `json:"geodata-loader"`
|
||||
}
|
||||
|
||||
// Inbound
|
||||
|
@ -170,7 +170,7 @@ type RawConfig struct {
|
|||
ExternalUI string `yaml:"external-ui"`
|
||||
Secret string `yaml:"secret"`
|
||||
Interface string `yaml:"interface-name"`
|
||||
Geodataloader string `yaml:"geodata-loader"`
|
||||
GeodataLoader string `yaml:"geodata-loader"`
|
||||
|
||||
ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"`
|
||||
RuleProvider map[string]map[string]interface{} `yaml:"rule-providers"`
|
||||
|
@ -201,7 +201,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||
AllowLan: false,
|
||||
BindAddress: "*",
|
||||
Mode: T.Rule,
|
||||
Geodataloader: "standard",
|
||||
GeodataLoader: "memconservative",
|
||||
UnifiedDelay: false,
|
||||
Authentication: []string{},
|
||||
LogLevel: log.INFO,
|
||||
|
|
|
@ -21,7 +21,7 @@ var geoIPMatcher *router.GeoIPMatcher
|
|||
func (gf *geoipFilter) Match(ip net.IP) bool {
|
||||
if geoIPMatcher == nil {
|
||||
countryCode := "cn"
|
||||
geoLoader, err := geodata.GetGeoDataLoader("standard")
|
||||
geoLoader, err := geodata.GetGeoDataLoader(geodata.LoaderName())
|
||||
if err != nil {
|
||||
log.Errorln("[GeoIPFilter] GetGeoDataLoader error: %s", err.Error())
|
||||
return false
|
||||
|
|
|
@ -2,6 +2,7 @@ package executor
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
|
@ -15,6 +16,7 @@ import (
|
|||
"github.com/Dreamacro/clash/adapter/outboundgroup"
|
||||
"github.com/Dreamacro/clash/component/auth"
|
||||
"github.com/Dreamacro/clash/component/dialer"
|
||||
G "github.com/Dreamacro/clash/component/geodata"
|
||||
"github.com/Dreamacro/clash/component/iface"
|
||||
"github.com/Dreamacro/clash/component/profile"
|
||||
"github.com/Dreamacro/clash/component/profile/cachefile"
|
||||
|
@ -106,9 +108,10 @@ func GetGeneral() *config.General {
|
|||
AllowLan: P.AllowLan(),
|
||||
BindAddress: P.BindAddress(),
|
||||
},
|
||||
Mode: tunnel.Mode(),
|
||||
LogLevel: log.Level(),
|
||||
IPv6: !resolver.DisableIPv6,
|
||||
Mode: tunnel.Mode(),
|
||||
LogLevel: log.Level(),
|
||||
IPv6: !resolver.DisableIPv6,
|
||||
GeodataLoader: G.LoaderName(),
|
||||
}
|
||||
|
||||
return general
|
||||
|
@ -239,6 +242,9 @@ func updateGeneral(general *config.General, Tun *config.Tun, force bool) {
|
|||
return
|
||||
}
|
||||
|
||||
geodataLoader := general.GeodataLoader
|
||||
G.SetLoader(geodataLoader)
|
||||
|
||||
allowLan := general.AllowLan
|
||||
P.SetAllowLan(allowLan)
|
||||
|
||||
|
|
|
@ -27,10 +27,8 @@ func (ps *Process) Match(metadata *C.Metadata) bool {
|
|||
if metadata.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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue