mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package memconservative
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/app/router"
|
|
"github.com/v2fly/v2ray-core/v4/infra/conf/geodata"
|
|
)
|
|
|
|
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
|
|
|
|
type memConservativeLoader struct {
|
|
geoipcache GeoIPCache
|
|
geositecache GeoSiteCache
|
|
}
|
|
|
|
func (m *memConservativeLoader) LoadIP(filename, country string) ([]*router.CIDR, error) {
|
|
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
|
|
}
|
|
|
|
func (m *memConservativeLoader) LoadSite(filename, list string) ([]*router.Domain, error) {
|
|
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 {
|
|
return &memConservativeLoader{make(map[string]*router.GeoIP), make(map[string]*router.GeoSite)}
|
|
}
|
|
|
|
func init() {
|
|
geodata.RegisterGeoDataLoaderImplementationCreator("memconservative", newMemConservativeLoader)
|
|
}
|