fix: 携程溢出、优化若干

This commit is contained in:
Mmx
2022-01-11 12:30:32 +08:00
parent a240165eed
commit 8b006e77af
12 changed files with 77 additions and 32 deletions

View File

@@ -12,6 +12,7 @@ import (
// Guardian 守护模式逻辑
func Guardian(output bool) {
util.Log.OutPut = output
GuardianDuration := time.Duration(global.Config.Settings.Guardian.Duration) * time.Second
if global.Config.Settings.Daemon.Enable {
go Daemon.DaemonChan()
@@ -29,7 +30,7 @@ func Guardian(output bool) {
_ = recover()
}()
if global.Config.Settings.Interfaces == "" { //单网卡
if !util.Checker.NetOk(global.Config.Settings.Timeout, nil) {
if !util.Checker.NetOk(global.Transports(nil)) {
util.Log.Println("Network down, trying to login")
e := Login(output, true, nil)
if e != nil {
@@ -45,13 +46,14 @@ func Guardian(output bool) {
if e == nil {
var down []srunModels.Eth
for _, eth := range interfaces {
if !util.Checker.NetOk(global.Config.Settings.Timeout, eth.Addr) {
if !util.Checker.NetOk(global.Transports(eth.Addr)) {
util.Log.Println(eth.Name + " network down")
down = append(down, eth)
}
}
for _, eth := range down {
util.Log.Println(eth.Name)
e := Login(output, true, eth.Addr)
if e != nil {
util.Log.Println(eth.Name+" login error: ", e)
@@ -63,13 +65,12 @@ func Guardian(output bool) {
c <- false
}()
<-c
time.Sleep(time.Duration(global.Config.Settings.Guardian.Duration) * time.Second)
time.Sleep(GuardianDuration)
}
}
// EnterGuardian 守护模式入口控制是否进入daemon
func EnterGuardian() {
util.Log.OutPut = true
util.Log.Println("[Guardian mode]")
if global.Config.Settings.Daemon.Enable || global.Flags.Daemon {
if err := exec.Command(os.Args[0], append(os.Args[1:], "--running-daemon")...).Start(); err != nil {

View File

@@ -13,11 +13,10 @@ func Login(output bool, skipCheck bool, localAddr net.Addr) error {
Demo: global.Config.Settings.DemoMode,
OutPut: output,
CheckNet: !skipCheck,
Timeout: global.Config.Settings.Timeout,
LoginInfo: srunTransfer.LoginInfo{
Form: &global.Config.Form,
Meta: &global.Config.Meta,
},
LocalAddr: localAddr,
Transport: global.Transports(localAddr),
})
}