添加定期清理过期Ready列表

This commit is contained in:
eson 2018-12-22 03:30:25 +08:00
parent 4149ea8d0f
commit 67cf4bc888
3 changed files with 31 additions and 11 deletions

23
dip.go
View File

@ -73,17 +73,20 @@ func (group *DIPGroup) Choose(addr string) {
group.Current.ActiveTime = now group.Current.ActiveTime = now
SetAddrForward(group.IPTableNum, addr, ip) SetAddrForward(group.IPTableNum, addr, ip)
} else { } else {
restartAddr := "http://" + group.Current.Host + ":8800/pppoe/restart"
if _, err := requests.NewSession().Get(restartAddr).Execute(); err != nil { for i := 0; i < 3; i++ {
log.Println(err) restartAddr := "http://" + group.Current.Host + ":8800/pppoe/restart"
group.Current.ActiveTime += 12 if _, err := requests.NewSession().Get(restartAddr).Execute(); err != nil {
return log.Println(err)
} else { } else {
group.Current = dhost break
group.Current.ActiveTime = now }
// log.Println("new set addr:", group.Current.Host, "restartAddr:", restartAddr, "resp", resp.Content())
SetAddrForward(group.IPTableNum, addr, ip)
} }
group.Current = dhost
group.Current.ActiveTime = now
SetAddrForward(group.IPTableNum, addr, ip)
} }
group.Waitor[ip] = group.Ready[ip] group.Waitor[ip] = group.Ready[ip]

View File

@ -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)) // checkInReady 签到的IP(vps的vpn节点IP))
func (swi *Switch) checkInReady(ip string, now int64) { func (swi *Switch) checkInReady(ip string, now int64) {
@ -146,6 +163,7 @@ func (swi *Switch) imActive(w http.ResponseWriter, req *http.Request) {
// 60秒show一次日志 // 60秒show一次日志
if now >= swi.lastShow+60 { if now >= swi.lastShow+60 {
swi.clearReady(now)
swi.lastShow = now swi.lastShow = now
log.Println("\n" + swi.Worker.ShowGroupInfo()) log.Println("\n" + swi.Worker.ShowGroupInfo())
} }

View File

@ -5,7 +5,6 @@ import (
) )
func TestSwitchYaml(t *testing.T) { func TestSwitchYaml(t *testing.T) {
t.Error()
swi := NewSwitch() swi := NewSwitch()
if swi == nil { if swi == nil {