Refactored some debug functionality, and added CM-to-FSN flag.
This commit is contained in:
parent
a3bf6f3d76
commit
2740b7119e
14
main.go
14
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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue