IP名单优化

* 增加IP灰名单,用于仅记录并观察IP
* 优化IP名单同步版本号管理
* WAF记录IP动作优先记录到网站和策略相关的IP名单中
This commit is contained in:
刘祥超
2024-05-05 19:10:46 +08:00
parent 968eac6046
commit 216dacc348
6 changed files with 71 additions and 20 deletions

View File

@@ -8,6 +8,7 @@ type IPListDB interface {
Name() string
DeleteExpiredItems() error
ReadMaxVersion() (int64, error)
UpdateMaxVersion(version int64) error
ReadItems(offset int64, size int64) (items []*pb.IPItem, goNext bool, err error)
AddItem(item *pb.IPItem) error
}

View File

@@ -213,6 +213,18 @@ func (this *IPListManager) fetch() (hasNext bool, err error) {
}
return false, err
}
// 更新版本号
defer func() {
if itemsResp.Version > this.lastVersion {
this.lastVersion = itemsResp.Version
err = this.db.UpdateMaxVersion(itemsResp.Version)
if err != nil {
remotelogs.Error("IP_LIST_MANAGER", "update max version to database: "+err.Error())
}
}
}()
var items = itemsResp.IpItems
if len(items) == 0 {
return false, nil
@@ -325,13 +337,6 @@ func (this *IPListManager) processItems(items []*pb.IPItem, fromRemote bool) {
changedList.Sort()
}
}
if fromRemote {
var latestVersion = items[len(items)-1].Version
if latestVersion > this.lastVersion {
this.lastVersion = latestVersion
}
}
}
// 调试IP信息