Update healthcheck policy

This commit is contained in:
chen08209
2024-05-06 10:32:39 +08:00
parent feb9688a29
commit 9aa9180f1f
13 changed files with 273 additions and 68 deletions

View File

@@ -7,14 +7,17 @@ import (
"github.com/metacubex/mihomo/component/process"
"github.com/metacubex/mihomo/component/resolver"
"github.com/metacubex/mihomo/config"
"github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/dns"
"github.com/metacubex/mihomo/hub/executor"
"github.com/metacubex/mihomo/listener"
"github.com/metacubex/mihomo/log"
"github.com/metacubex/mihomo/tunnel"
"math"
"os"
"os/exec"
"runtime"
"sync"
"syscall"
)
@@ -170,6 +173,29 @@ func patchConfig(general *config.General) {
resolver.DisableIPv6 = !general.IPv6
}
const concurrentCount = math.MaxInt
func hcCompatibleProvider(proxyProviders map[string]provider.ProxyProvider) {
wg := sync.WaitGroup{}
ch := make(chan struct{}, concurrentCount)
for _, proxyProvider := range proxyProviders {
proxyProvider := proxyProvider
if proxyProvider.VehicleType() == provider.Compatible {
log.Infoln("Start initial Compatible provider %s", proxyProvider.Name())
wg.Add(1)
ch <- struct{}{}
go func() {
defer func() { <-ch; wg.Done() }()
if err := proxyProvider.Initial(); err != nil {
log.Errorln("initial Compatible provider %s error: %v", proxyProvider.Name(), err)
}
}()
}
}
}
func applyConfig(isPatch bool) {
cfg, err := config.ParseRawConfig(currentConfig)
if err != nil {

View File

@@ -251,6 +251,11 @@ func getProvider(name *C.char) *C.char {
return C.CString(string(data))
}
//export healthcheck
func healthcheck() {
hcCompatibleProvider(tunnel.Providers())
}
//export initNativeApiBridge
func initNativeApiBridge(api unsafe.Pointer, port C.longlong) {
bridge.InitDartApi(api)
@@ -273,13 +278,4 @@ func init() {
Data: delayData,
})
}
adapter.NowChangeHook = func(name, value string) {
bridge.SendMessage(bridge.Message{
Type: bridge.Now,
Data: Now{
Name: name,
Value: value,
},
})
}
}