1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-26 01:15:38 +00:00
This commit is contained in:
loyalsoldier 2021-05-04 21:51:38 +08:00 committed by Shelikhoo
parent 3ba9a5b4f5
commit 40f8e82204
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
8 changed files with 49 additions and 54 deletions

View File

@ -13,18 +13,22 @@ import (
"github.com/v2fly/v2ray-core/v4/app/router"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/common/platform"
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
)
func init() {
const (
geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
geositeURL = "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
)
wd, err := os.Getwd()
common.Must(err)
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
os.Setenv("v2ray.location.asset", tempPath)
geoipPath := filepath.Join(tempPath, "geoip.dat")
geoipPath := platform.GetAssetLocation("geoip.dat")
os.Setenv("v2ray.location.asset", tempPath)
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
common.Must(os.MkdirAll(tempPath, 0755))

View File

@ -14,7 +14,6 @@ import (
"github.com/v2fly/v2ray-core/v4/app/router"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/common/platform"
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
"github.com/v2fly/v2ray-core/v4/common/protocol"
"github.com/v2fly/v2ray-core/v4/common/protocol/http"
@ -24,14 +23,19 @@ import (
)
func init() {
const (
geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
geositeURL = "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
)
wd, err := os.Getwd()
common.Must(err)
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
os.Setenv("v2ray.location.asset", tempPath)
geoipPath := filepath.Join(tempPath, "geoip.dat")
geositePath := filepath.Join(tempPath, "geosite.dat")
geoipPath := platform.GetAssetLocation("geoip.dat")
geositePath := platform.GetAssetLocation("geosite.dat")
os.Setenv("v2ray.location.asset", tempPath)
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
common.Must(os.MkdirAll(tempPath, 0755))

View File

@ -1,6 +0,0 @@
package router_test
const (
geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
geositeURL = "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
)

View File

@ -1,6 +0,0 @@
package conf_test
const (
geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
geositeURL = "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
)

View File

@ -13,7 +13,6 @@ import (
"github.com/v2fly/v2ray-core/v4/app/dns"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/common/platform"
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
"github.com/v2fly/v2ray-core/v4/infra/conf"
@ -21,14 +20,19 @@ import (
)
func init() {
const (
geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
geositeURL = "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
)
wd, err := os.Getwd()
common.Must(err)
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
os.Setenv("v2ray.location.asset", tempPath)
geoipPath := filepath.Join(tempPath, "geoip.dat")
geositePath := filepath.Join(tempPath, "geosite.dat")
geoipPath := platform.GetAssetLocation("geoip.dat")
geositePath := platform.GetAssetLocation("geosite.dat")
os.Setenv("v2ray.location.asset", tempPath)
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
common.Must(os.MkdirAll(tempPath, 0755))

View File

@ -4,9 +4,9 @@ import (
"io/ioutil"
"strings"
"github.com/golang/protobuf/proto"
"github.com/v2fly/v2ray-core/v4/app/router"
"github.com/v2fly/v2ray-core/v4/common/platform"
"google.golang.org/protobuf/proto"
)
type GeoIPCache map[string]*router.GeoIP
@ -31,7 +31,7 @@ func (g GeoIPCache) Set(key string, value *router.GeoIP) {
func (g GeoIPCache) Unmarshal(filename, code string) (*router.GeoIP, error) {
asset := platform.GetAssetLocation(filename)
idx := strings.ToUpper(asset + "|" + code)
idx := strings.ToLower(asset + ":" + code)
if g.Has(idx) {
return g.Get(idx), nil
}
@ -47,11 +47,11 @@ func (g GeoIPCache) Unmarshal(filename, code string) (*router.GeoIP, error) {
return &geoip, nil
case errCodeNotFound:
return nil, newError(code, " not found in ", filename)
return nil, newError("country code ", code, " not found in ", filename)
case errFailedToReadBytes, errFailedToReadExpectedLenBytes,
errInvalidGeodataFile, errInvalidGeodataVarintLength:
newError("failed to decode geodata file: ", filename, ". Fallback to the original ReadFile method.").AtWarning().WriteToLog()
newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method")
geoipBytes, err = ioutil.ReadFile(asset)
if err != nil {
return nil, err
@ -71,7 +71,7 @@ func (g GeoIPCache) Unmarshal(filename, code string) (*router.GeoIP, error) {
return nil, err
}
return nil, newError(code, " not found in ", filename)
return nil, newError("country code ", code, " not found in ", filename)
}
type GeoSiteCache map[string]*router.GeoSite
@ -96,7 +96,7 @@ func (g GeoSiteCache) Set(key string, value *router.GeoSite) {
func (g GeoSiteCache) Unmarshal(filename, code string) (*router.GeoSite, error) {
asset := platform.GetAssetLocation(filename)
idx := strings.ToUpper(asset + "|" + code)
idx := strings.ToLower(asset + ":" + code)
if g.Has(idx) {
return g.Get(idx), nil
}
@ -112,11 +112,11 @@ func (g GeoSiteCache) Unmarshal(filename, code string) (*router.GeoSite, error)
return &geosite, nil
case errCodeNotFound:
return nil, newError(code, " not found in ", filename)
return nil, newError("list ", code, " not found in ", filename)
case errFailedToReadBytes, errFailedToReadExpectedLenBytes,
errInvalidGeodataFile, errInvalidGeodataVarintLength:
newError("failed to decode geodata file: ", filename, ". Fallback to the original ReadFile method.").AtWarning().WriteToLog()
newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method")
geositeBytes, err = ioutil.ReadFile(asset)
if err != nil {
return nil, err
@ -136,5 +136,5 @@ func (g GeoSiteCache) Unmarshal(filename, code string) (*router.GeoSite, error)
return nil, err
}
return nil, newError(code, " not found in ", filename)
return nil, newError("list ", code, " not found in ", filename)
}

View File

@ -13,20 +13,20 @@ import (
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
)
const (
geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
geositeURL = "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
)
func init() {
const (
geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
geositeURL = "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
)
wd, err := os.Getwd()
common.Must(err)
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
os.Setenv("v2ray.location.asset", tempPath)
tempPath := filepath.Join(wd, "..", "..", "..", "..", "testing", "temp")
geoipPath := filepath.Join(tempPath, "geoip.dat")
geositePath := filepath.Join(tempPath, "geosite.dat")
geoipPath := platform.GetAssetLocation("geoip.dat")
geositePath := platform.GetAssetLocation("geosite.dat")
os.Setenv("v2ray.location.asset", tempPath)
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
common.Must(os.MkdirAll(tempPath, 0755))

View File

@ -18,27 +18,22 @@ import (
_ "github.com/v2fly/v2ray-core/v4/infra/conf/geodata/standard"
)
const (
geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
)
func init() {
const geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
wd, err := os.Getwd()
common.Must(err)
tempPath := filepath.Join(wd, "..", "..", "testing", "temp")
tempPath := filepath.Join(wd, "..", "..", "..", "testing", "temp")
geoipPath := filepath.Join(tempPath, "geoip.dat")
os.Setenv("v2ray.location.asset", tempPath)
common.Must(os.MkdirAll(tempPath, 0755))
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && errors.Is(err, fs.ErrNotExist) {
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
geoipBytes, err := common.FetchHTTPContent(geoipURL)
common.Must(err)
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
}
if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) {
common.Must(os.MkdirAll(tempPath, 0755))
geoipBytes, err := common.FetchHTTPContent(geoipURL)
common.Must(err)
common.Must(filesystem.WriteFile(geoipPath, geoipBytes))
}
}