mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
2bf34c766e
support trojan xtls change geodataloader mode as memconservative
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package geodata
|
||
|
||
import (
|
||
"github.com/Dreamacro/clash/component/geodata/router"
|
||
"strings"
|
||
)
|
||
|
||
func LoadGeoSiteMatcher(countryCode string) (*router.DomainMatcher, int, error) {
|
||
geoLoaderName := "memconservative"
|
||
geoLoader, err := GetGeoDataLoader(geoLoaderName)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
|
||
domains, err := geoLoader.LoadGeoSite(countryCode)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
|
||
/**
|
||
linear: linear algorithm
|
||
matcher, err := router.NewDomainMatcher(domains)
|
||
mph:minimal perfect hash algorithm
|
||
*/
|
||
matcher, err := router.NewMphMatcherGroup(domains)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
|
||
return matcher, len(domains), nil
|
||
}
|
||
|
||
func LoadGeoIPMatcher(country string) (*router.GeoIPMatcher, int, error) {
|
||
geoLoaderName := "memconservative"
|
||
geoLoader, err := GetGeoDataLoader(geoLoaderName)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
|
||
records, err := geoLoader.LoadGeoIP(strings.ReplaceAll(country, "!", ""))
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
|
||
geoIP := &router.GeoIP{
|
||
CountryCode: country,
|
||
Cidr: records,
|
||
ReverseMatch: strings.Contains(country, "!"),
|
||
}
|
||
|
||
matcher, err := router.NewGeoIPMatcher(geoIP)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
|
||
return matcher, len(records), nil
|
||
}
|