-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor: geodata loader * Feat: add membench & benchmark for geodata decoder * Feat: log router memory usage when initialization
- Loading branch information
1 parent
9c437b9
commit a9ce6d4
Showing
4 changed files
with
118 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package geodata | ||
|
||
import ( | ||
"runtime" | ||
|
||
v2router "github.com/v2fly/v2ray-core/v4/app/router" | ||
) | ||
|
||
type geodataLoader interface { | ||
LoadIP(filename, country string) ([]*v2router.CIDR, error) | ||
LoadSite(filename, list string) ([]*v2router.Domain, error) | ||
LoadGeoIP(country string) ([]*v2router.CIDR, error) | ||
LoadGeoSite(list string) ([]*v2router.Domain, error) | ||
} | ||
|
||
func GetGeodataLoader() geodataLoader { | ||
return &geodataCache{ | ||
make(map[string]*v2router.GeoIP), | ||
make(map[string]*v2router.GeoSite), | ||
} | ||
} | ||
|
||
type geodataCache struct { | ||
GeoIPCache | ||
GeoSiteCache | ||
} | ||
|
||
func (g *geodataCache) LoadIP(filename, country string) ([]*v2router.CIDR, error) { | ||
geoip, err := g.GeoIPCache.Unmarshal(filename, country) | ||
if err != nil { | ||
return nil, err | ||
} | ||
runtime.GC() | ||
return geoip.Cidr, nil | ||
} | ||
|
||
func (g *geodataCache) LoadSite(filename, list string) ([]*v2router.Domain, error) { | ||
geosite, err := g.GeoSiteCache.Unmarshal(filename, list) | ||
if err != nil { | ||
return nil, err | ||
} | ||
runtime.GC() | ||
return geosite.Domain, nil | ||
} | ||
|
||
func (g *geodataCache) LoadGeoIP(country string) ([]*v2router.CIDR, error) { | ||
return g.LoadIP("geoip.dat", country) | ||
} | ||
|
||
func (g *geodataCache) LoadGeoSite(list string) ([]*v2router.Domain, error) { | ||
return g.LoadSite("geosite.dat", list) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters