diff --git a/main.go b/main.go index 9327b56..afdb0e7 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/mapping/map.go b/mapping/map.go index 9d1ed7d..17e9e83 100644 --- a/mapping/map.go +++ b/mapping/map.go @@ -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 }