navigator/mapping/map.go

41 lines
1.1 KiB
Go

package mapping
import (
"flag"
"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
)
var (
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")
)
// 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
}
if *enableCMExperiment && info_en.IspDomain == "ChinaMobile" {
return HETZNER_FSN_1GE + CHINA_MAINLAND_SUFFIX
}
if *enableCNDomain && info_en.CountryCode == "CN" {
return default_server + CHINA_MAINLAND_SUFFIX
}
return default_server + GLOBAL_SUFFIX
}