feat: 变更解析方式,打包Srun请求包

This commit is contained in:
Mmx233
2022-03-11 17:47:13 +08:00
parent 371e774cc1
commit 0613dc6311
13 changed files with 165 additions and 188 deletions

View File

@@ -2,7 +2,6 @@ package controllers
import (
"github.com/Mmx233/BitSrunLoginGo/global"
srunModels "github.com/Mmx233/BitSrunLoginGo/models"
"github.com/Mmx233/BitSrunLoginGo/util"
"os"
"os/exec"
@@ -13,7 +12,6 @@ import (
func Guardian(output bool) {
util.Log.OutPut = output
GuardianDuration := time.Duration(global.Config.Settings.Guardian.Duration) * time.Second
util.Checker.SetUrl(global.Config.Settings.Basic.NetCheckUrl)
if global.Config.Settings.Daemon.Enable {
go Daemon.DaemonChan()
@@ -31,31 +29,16 @@ func Guardian(output bool) {
_ = recover()
}()
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
if !util.Checker.NetOk(global.Transports(nil)) {
util.Log.Info("检测到掉线, trying to login")
e := Login(output, true, nil)
if e != nil {
util.Log.Warn("登陆失败: ", e)
}
} else {
if global.Config.Settings.Debug.Enable {
util.Log.Debug("Network ok")
}
e := Login(output, nil)
if e != nil {
util.Log.Warn("登陆失败: ", e)
}
} else { //多网卡
interfaces, e := util.GetInterfaceAddr()
if e == nil {
var down []srunModels.Eth
for _, eth := range interfaces {
if !util.Checker.NetOk(global.Transports(eth.Addr)) {
util.Log.Info("检测到掉线网口 ", eth.Name)
down = append(down, eth)
}
}
for _, eth := range down {
util.Log.Info(eth.Name)
e := Login(output, true, eth.Addr)
e := Login(output, eth.Addr)
if e != nil {
util.Log.Warn("网口 ", eth.Name+" 登录失败: ", e)
}

View File

@@ -8,14 +8,12 @@ import (
)
// Login 登录逻辑
func Login(output bool, skipCheck bool, localAddr net.Addr) error {
func Login(output bool, localAddr net.Addr) error {
return BitSrun.Login(&srunTransfer.Login{
Https: global.Config.Settings.Basic.Https,
Debug: global.Config.Settings.Debug.Enable,
WriteLog: global.Config.Settings.Debug.WriteLog,
OutPut: output,
CheckNet: !skipCheck,
CheckNetUrl: global.Config.Settings.Basic.NetCheckUrl,
Https: global.Config.Settings.Basic.Https,
Debug: global.Config.Settings.Debug.Enable,
WriteLog: global.Config.Settings.Debug.WriteLog,
OutPut: output,
LoginInfo: srunTransfer.LoginInfo{
Form: &global.Config.Form,
Meta: &global.Config.Meta,