optimize: add a new link for network check

This commit is contained in:
mzz2017 2023-03-19 12:26:09 +08:00
parent 300cb6928a
commit 6e1401e9a0
2 changed files with 15 additions and 3 deletions

View File

@ -20,7 +20,7 @@ ifeq ($(strip $(NOSTRIP)),y)
else ifeq ($(wildcard $(STRIP_PATH)),)
STRIP_FLAG := -no-strip
else
STRIP_FLAG := -strip=$(STRIP)
STRIP_FLAG := -strip=$(STRIP_PATH)
endif
# Get version from .git.

View File

@ -12,6 +12,7 @@ import (
"github.com/okzk/sdnotify"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"math/rand"
"net/http"
"os"
"os/signal"
@ -27,10 +28,21 @@ const (
PidFilePath = "/var/run/dae.pid"
)
var (
CheckNetworkLinks = []string{
"http://www.msftconnecttest.com/connecttest.txt",
"http://www.qualcomm.cn/generate_204",
}
)
func init() {
runCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file")
runCmd.PersistentFlags().BoolVarP(&disableTimestamp, "disable-timestamp", "", false, "disable timestamp")
runCmd.PersistentFlags().BoolVarP(&disableTimestamp, "disable-pidfile", "", false, "not generate /var/run/dae.pid")
rand.Shuffle(len(CheckNetworkLinks), func(i, j int) {
CheckNetworkLinks[i], CheckNetworkLinks[j] = CheckNetworkLinks[j], CheckNetworkLinks[i]
})
}
var (
@ -217,8 +229,8 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, dnsCache map[string]*c
resolvingfailed := false
if !conf.Global.DisableWaitingNetwork && len(conf.Subscription) > 0 {
log.Infoln("Waiting for network...")
for {
resp, err := http.Get("http://www.msftconnecttest.com/connecttest.txt")
for i := 0; ; i++ {
resp, err := http.Get(CheckNetworkLinks[i%len(CheckNetworkLinks)])
if err != nil {
time.Sleep(5 * time.Second)
continue