2021-05-04 06:19:03 -04:00
|
|
|
package memconservative
|
|
|
|
|
|
|
|
import (
|
2021-05-04 06:21:49 -04:00
|
|
|
"runtime"
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/app/router/routercommon"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/infra/conf/geodata"
|
2021-05-04 06:19:03 -04:00
|
|
|
)
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
|
2021-05-04 06:19:03 -04:00
|
|
|
|
|
|
|
type memConservativeLoader struct {
|
|
|
|
geoipcache GeoIPCache
|
|
|
|
geositecache GeoSiteCache
|
|
|
|
}
|
|
|
|
|
2021-09-07 04:13:58 -04:00
|
|
|
func (m *memConservativeLoader) LoadIP(filename, country string) ([]*routercommon.CIDR, error) {
|
2021-05-04 06:19:03 -04:00
|
|
|
defer runtime.GC()
|
|
|
|
geoip, err := m.geoipcache.Unmarshal(filename, country)
|
|
|
|
if err != nil {
|
|
|
|
return nil, newError("failed to decode geodata file: ", filename).Base(err)
|
|
|
|
}
|
|
|
|
return geoip.Cidr, nil
|
|
|
|
}
|
|
|
|
|
2021-09-07 04:13:58 -04:00
|
|
|
func (m *memConservativeLoader) LoadSite(filename, list string) ([]*routercommon.Domain, error) {
|
2021-05-04 06:19:03 -04:00
|
|
|
defer runtime.GC()
|
|
|
|
geosite, err := m.geositecache.Unmarshal(filename, list)
|
|
|
|
if err != nil {
|
|
|
|
return nil, newError("failed to decode geodata file: ", filename).Base(err)
|
|
|
|
}
|
|
|
|
return geosite.Domain, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMemConservativeLoader() geodata.LoaderImplementation {
|
2021-09-07 04:13:58 -04:00
|
|
|
return &memConservativeLoader{make(map[string]*routercommon.GeoIP), make(map[string]*routercommon.GeoSite)}
|
2021-05-04 06:19:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-05-04 06:21:49 -04:00
|
|
|
geodata.RegisterGeoDataLoaderImplementationCreator("memconservative", newMemConservativeLoader)
|
2021-05-04 06:19:03 -04:00
|
|
|
}
|