From 67cf4bc88848c64dadd1bdbf0ed1b0f4df90d260 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sat, 22 Dec 2018 03:30:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=9C=9F=E6=B8=85?= =?UTF-8?q?=E7=90=86=E8=BF=87=E6=9C=9FReady=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dip.go | 23 +++++++++++++---------- switch.go | 18 ++++++++++++++++++ switch_test.go | 1 - 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/dip.go b/dip.go index f75d4b8..7fb1f03 100644 --- a/dip.go +++ b/dip.go @@ -73,17 +73,20 @@ func (group *DIPGroup) Choose(addr string) { group.Current.ActiveTime = now SetAddrForward(group.IPTableNum, addr, ip) } else { - restartAddr := "http://" + group.Current.Host + ":8800/pppoe/restart" - if _, err := requests.NewSession().Get(restartAddr).Execute(); err != nil { - log.Println(err) - group.Current.ActiveTime += 12 - return - } else { - group.Current = dhost - group.Current.ActiveTime = now - // log.Println("new set addr:", group.Current.Host, "restartAddr:", restartAddr, "resp", resp.Content()) - SetAddrForward(group.IPTableNum, addr, ip) + + for i := 0; i < 3; i++ { + restartAddr := "http://" + group.Current.Host + ":8800/pppoe/restart" + if _, err := requests.NewSession().Get(restartAddr).Execute(); err != nil { + log.Println(err) + } else { + break + } } + + group.Current = dhost + group.Current.ActiveTime = now + SetAddrForward(group.IPTableNum, addr, ip) + } group.Waitor[ip] = group.Ready[ip] diff --git a/switch.go b/switch.go index 92c89db..4ab4120 100644 --- a/switch.go +++ b/switch.go @@ -96,6 +96,23 @@ func (swi *Switch) timeToSwitch(now int64) { } } +func (swi *Switch) clearReady(now int64) { + + for _, dipg := range swi.Worker.ForMatch { + var delIPList []string + + for ip, dhost := range dipg.Ready { + if now >= dhost.ActiveTime+150 { + delIPList = append(delIPList, ip) + } + } + + for _, ip := range delIPList { + delete(dipg.Ready, ip) + } + } +} + // checkInReady 签到的IP(vps的vpn节点IP)) func (swi *Switch) checkInReady(ip string, now int64) { @@ -146,6 +163,7 @@ func (swi *Switch) imActive(w http.ResponseWriter, req *http.Request) { // 60秒show一次日志 if now >= swi.lastShow+60 { + swi.clearReady(now) swi.lastShow = now log.Println("\n" + swi.Worker.ShowGroupInfo()) } diff --git a/switch_test.go b/switch_test.go index a5760d9..98b7b16 100644 --- a/switch_test.go +++ b/switch_test.go @@ -5,7 +5,6 @@ import ( ) func TestSwitchYaml(t *testing.T) { - t.Error() swi := NewSwitch() if swi == nil {