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 {