feat: tcp/icmp ping 提前取 IP
This commit is contained in:
@@ -153,9 +153,6 @@ func GetHost() *model.Host {
|
||||
ret.IP = CachedIP
|
||||
ret.Version = Version
|
||||
|
||||
// stub
|
||||
ret.CountryCode = ""
|
||||
|
||||
return &ret
|
||||
}
|
||||
|
||||
|
||||
+9
-5
@@ -18,9 +18,10 @@ var (
|
||||
"https://dash.cloudflare.com/cdn-cgi/trace",
|
||||
"https://cf-ns.com/cdn-cgi/trace", // 有国内节点
|
||||
}
|
||||
CachedIP, QueryIP string
|
||||
httpClientV4 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, false)
|
||||
httpClientV6 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, true)
|
||||
CachedIP, GeoQueryIP, CachedCountryCode string
|
||||
GeoQueryIPChanged bool
|
||||
httpClientV4 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, false)
|
||||
httpClientV6 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, true)
|
||||
)
|
||||
|
||||
// UpdateIP 按设置时间间隔更新IP地址的缓存
|
||||
@@ -44,11 +45,14 @@ func UpdateIP(useIPv6CountryCode bool, period uint32) {
|
||||
CachedIP = fmt.Sprintf("%s/%s", ipv4, ipv6)
|
||||
}
|
||||
|
||||
var newIP string
|
||||
if !useIPv6CountryCode {
|
||||
QueryIP = ipv4
|
||||
newIP = ipv4
|
||||
} else {
|
||||
QueryIP = ipv6
|
||||
newIP = ipv6
|
||||
}
|
||||
GeoQueryIPChanged = newIP != GeoQueryIP
|
||||
GeoQueryIP = newIP
|
||||
|
||||
time.Sleep(time.Second * time.Duration(period))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user