mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-29 09:16:35 +08:00
WAF规则匹配后的IP也会上报/实现IP全局名单/将名单存储到本地数据库,提升读写速度
This commit is contained in:
61
internal/iplibrary/server_list_manager.go
Normal file
61
internal/iplibrary/server_list_manager.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package iplibrary
|
||||
|
||||
import "sync"
|
||||
|
||||
var SharedServerListManager = NewServerListManager()
|
||||
|
||||
// ServerListManager 服务相关名单
|
||||
type ServerListManager struct {
|
||||
whiteMap map[int64]*IPList // serverId => *List
|
||||
blackMap map[int64]*IPList // serverId => *List
|
||||
|
||||
locker sync.RWMutex
|
||||
}
|
||||
|
||||
func NewServerListManager() *ServerListManager {
|
||||
return &ServerListManager{
|
||||
whiteMap: map[int64]*IPList{},
|
||||
blackMap: map[int64]*IPList{},
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ServerListManager) FindWhiteList(serverId int64, autoCreate bool) *IPList {
|
||||
this.locker.RLock()
|
||||
list, ok := this.whiteMap[serverId]
|
||||
this.locker.RUnlock()
|
||||
if ok {
|
||||
return list
|
||||
}
|
||||
|
||||
if autoCreate {
|
||||
list = NewIPList()
|
||||
this.locker.Lock()
|
||||
this.whiteMap[serverId] = list
|
||||
this.locker.Unlock()
|
||||
|
||||
return list
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *ServerListManager) FindBlackList(serverId int64, autoCreate bool) *IPList {
|
||||
this.locker.RLock()
|
||||
list, ok := this.blackMap[serverId]
|
||||
this.locker.RUnlock()
|
||||
if ok {
|
||||
return list
|
||||
}
|
||||
|
||||
if autoCreate {
|
||||
list = NewIPList()
|
||||
this.locker.Lock()
|
||||
this.blackMap[serverId] = list
|
||||
this.locker.Unlock()
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user