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

View File

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

View File

@ -19,7 +19,8 @@ const (
) )
var ( 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. // Get returns the edge node that should be used for client.
@ -29,6 +30,9 @@ func Get(ip string) string {
if err != nil { if err != nil {
return default_server + default_suffix return default_server + default_suffix
} }
if *enableCMExperiment && info_en.IspDomain == "ChinaMobile" {
return HETZNER_FSN_1GE + CHINA_MAINLAND_SUFFIX
}
if *enableCNDomain && info_en.CountryCode == "CN" { if *enableCNDomain && info_en.CountryCode == "CN" {
return default_server + CHINA_MAINLAND_SUFFIX return default_server + CHINA_MAINLAND_SUFFIX
} }