mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 23:20:25 +08:00
waf/ip名单有变更立即发送通知
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
)
|
||||
|
||||
var SharedIPListManager = NewIPListManager()
|
||||
var IPListUpdateNotify = make(chan bool, 1)
|
||||
|
||||
func init() {
|
||||
events.On(events.EventStart, func() {
|
||||
@@ -52,10 +53,21 @@ func (this *IPListManager) Start() {
|
||||
events.On(events.EventQuit, func() {
|
||||
ticker.Stop()
|
||||
})
|
||||
for range ticker.C {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
case <-IPListUpdateNotify:
|
||||
}
|
||||
err := this.loop()
|
||||
if err != nil {
|
||||
logs.Println("IP_LIST_MANAGER", err.Error())
|
||||
|
||||
// 方便立即重试
|
||||
select {
|
||||
case IPListUpdateNotify <- true:
|
||||
default:
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/events"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/iplibrary"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/logs"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||
"io"
|
||||
@@ -95,6 +96,8 @@ func (this *APIStream) loop() error {
|
||||
err = this.handlePreheatCache(message)
|
||||
case messageconfigs.MessageCodeConfigChanged: // 配置变化
|
||||
err = this.handleConfigChanged(message)
|
||||
case messageconfigs.MessageCodeIPListChanged: // IPList变化
|
||||
err = this.handleIPListChanged(message)
|
||||
default:
|
||||
err = this.handleUnknownMessage(message)
|
||||
}
|
||||
@@ -438,6 +441,17 @@ func (this *APIStream) handleConfigChanged(message *pb.NodeStreamMessage) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// 处理IPList变化
|
||||
func (this *APIStream) handleIPListChanged(message *pb.NodeStreamMessage) error {
|
||||
select {
|
||||
case iplibrary.IPListUpdateNotify <- true:
|
||||
default:
|
||||
|
||||
}
|
||||
this.replyOk(message.RequestId, "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
// 处理未知消息
|
||||
func (this *APIStream) handleUnknownMessage(message *pb.NodeStreamMessage) error {
|
||||
this.replyFail(message.RequestId, "unknown message code '"+message.Code+"'")
|
||||
|
||||
Reference in New Issue
Block a user