2019-10-27 16:54:23 +08:00
|
|
|
package mapping
|
|
|
|
|
|
|
|
import (
|
2019-11-07 15:18:44 +08:00
|
|
|
"flag"
|
2019-10-27 16:54:23 +08:00
|
|
|
"git.eve.moe/jackyyf/navigator/ipgeo"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Server IDs
|
|
|
|
WHOLESALE_INTERNET_10GE = "xe-mci1-us"
|
|
|
|
HETZNER_FSN_1GE = "ge-fsn1-de"
|
|
|
|
HETZNER_HEL_1GE = "ge-hel1-fi"
|
|
|
|
default_server = WHOLESALE_INTERNET_10GE
|
|
|
|
|
|
|
|
// Served domain suffix
|
|
|
|
CHINA_MAINLAND_SUFFIX = ".eveedge.link"
|
|
|
|
GLOBAL_SUFFIX = ".edge.eve.network"
|
|
|
|
default_suffix = GLOBAL_SUFFIX
|
|
|
|
)
|
|
|
|
|
2019-11-07 15:18:44 +08:00
|
|
|
var (
|
2019-11-12 02:44:15 +08:00
|
|
|
enableCNDomain = flag.Bool("enable-cn-domain", true, "Enable china mainland specific domain")
|
|
|
|
enableCMExperiment = flag.Bool("cm-to-fsn", false, "Redirect all CM users to Hetzner FSN")
|
2019-11-07 15:18:44 +08:00
|
|
|
)
|
|
|
|
|
2019-10-27 16:54:23 +08:00
|
|
|
// Get returns the edge node that should be used for client.
|
|
|
|
func Get(ip string) string {
|
|
|
|
db := ipgeo.Get()
|
|
|
|
info_en, err := db.FindInfo(ip, "EN")
|
|
|
|
if err != nil {
|
|
|
|
return default_server + default_suffix
|
|
|
|
}
|
2019-11-12 02:44:15 +08:00
|
|
|
if *enableCMExperiment && info_en.IspDomain == "ChinaMobile" {
|
|
|
|
return HETZNER_FSN_1GE + CHINA_MAINLAND_SUFFIX
|
|
|
|
}
|
2019-11-07 15:18:44 +08:00
|
|
|
if *enableCNDomain && info_en.CountryCode == "CN" {
|
2019-10-27 16:54:23 +08:00
|
|
|
return default_server + CHINA_MAINLAND_SUFFIX
|
|
|
|
}
|
|
|
|
return default_server + GLOBAL_SUFFIX
|
|
|
|
}
|