Refactored some debug functionality, and added CM-to-FSN flag.

This commit is contained in:
Yifu Yu 2019-11-12 02:44:15 +08:00
parent a3bf6f3d76
commit 2740b7119e
2 changed files with 15 additions and 5 deletions

14
main.go
View File

@ -71,10 +71,16 @@ func main() {
})
http.HandleFunc("/info", func(resp http.ResponseWriter, req *http.Request) {
host, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
responseWithError(resp, http.StatusPreconditionFailed, errIPv4Only)
return
var host string
if argIp := req.FormValue("ip"); argIp != "" {
host = argIp
} else {
ip, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
responseWithError(resp, http.StatusPreconditionFailed, errIPv4Only)
return
}
host = ip
}
if net.ParseIP(host).To4() == nil {
responseWithError(resp, http.StatusPreconditionFailed, errIPv4Only)

View File

@ -19,7 +19,8 @@ const (
)
var (
enableCNDomain = flag.Bool("enable-cn-domain", false, "Enable china mainland specific domain")
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.
@ -29,6 +30,9 @@ func Get(ip string) string {
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
}