MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / processItems

Method processItems

internal/iplibrary/manager_ip_list.go:255–335  ·  view source on GitHub ↗

处理IP条目

(items []*pb.IPItem, fromRemote bool)

Source from the content-addressed store, hash-verified

253
254// 处理IP条目
255func (this *IPListManager) processItems(items []*pb.IPItem, fromRemote bool) {
256 var changedLists = map[*IPList]zero.Zero{}
257 for _, item := range items {
258 // 调试
259 if Tea.IsTesting() {
260 this.debugItem(item)
261 }
262
263 var list *IPList
264 // TODO 实现节点专有List
265 if item.ServerId > 0 { // 服务专有List
266 switch item.ListType {
267 case "black":
268 list = SharedServerListManager.FindBlackList(item.ServerId, true)
269 case "white":
270 list = SharedServerListManager.FindWhiteList(item.ServerId, true)
271 }
272 } else if item.IsGlobal { // 全局List
273 switch item.ListType {
274 case "black":
275 list = GlobalBlackIPList
276 case "white":
277 list = GlobalWhiteIPList
278 }
279 } else { // 其他List
280 this.mu.Lock()
281 list = this.listMap[item.ListId]
282 this.mu.Unlock()
283 }
284 if list == nil {
285 list = NewIPList()
286 this.mu.Lock()
287 this.listMap[item.ListId] = list
288 this.mu.Unlock()
289 }
290
291 changedLists[list] = zero.New()
292
293 if item.IsDeleted {
294 list.Delete(uint64(item.Id))
295
296 // 从WAF名单中删除
297 waf.SharedIPBlackList.RemoveIP(item.IpFrom, item.ServerId, fromRemote)
298
299 // 操作事件
300 if fromRemote {
301 SharedActionManager.DeleteItem(item.ListType, item)
302 }
303
304 continue
305 }
306
307 list.AddDelay(&IPItem{
308 Id: uint64(item.Id),
309 Type: item.Type,
310 IPFrom: iputils.ToBytes(item.IpFrom),
311 IPTo: iputils.ToBytes(item.IpTo),
312 ExpiredAt: item.ExpiredAt,

Callers 2

InitMethod · 0.95
fetchMethod · 0.95

Calls 13

debugItemMethod · 0.95
DeleteMethod · 0.95
AddDelayMethod · 0.95
NewFunction · 0.92
FindBlackListMethod · 0.80
FindWhiteListMethod · 0.80
RemoveIPMethod · 0.80
SortMethod · 0.80
NewIPListFunction · 0.70
DeleteItemMethod · 0.65
AddItemMethod · 0.65
LockMethod · 0.45

Tested by

no test coverage detected