添加定期清理过期Ready列表
This commit is contained in:
parent
4149ea8d0f
commit
67cf4bc888
23
dip.go
23
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]
|
||||
|
|
18
switch.go
18
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())
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
)
|
||||
|
||||
func TestSwitchYaml(t *testing.T) {
|
||||
t.Error()
|
||||
|
||||
swi := NewSwitch()
|
||||
if swi == nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user