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

Method Add

internal/waf/ip_list.go:88–112  ·  view source on GitHub ↗

Add 添加IP

(ipType string, scope firewallconfigs.FirewallScope, serverId int64, ip string, expiresAt int64)

Source from the content-addressed store, hash-verified

86
87// Add 添加IP
88func (this *IPList) Add(ipType string, scope firewallconfigs.FirewallScope, serverId int64, ip string, expiresAt int64) {
89 switch scope {
90 case firewallconfigs.FirewallScopeGlobal:
91 ip = "*@" + ip + "@" + ipType
92 case firewallconfigs.FirewallScopeServer:
93 ip = types.String(serverId) + "@" + ip + "@" + ipType
94 default:
95 ip = "*@" + ip + "@" + ipType
96 }
97
98 var id = this.nextId()
99 this.expireList.Add(id, expiresAt)
100 this.locker.Lock()
101
102 // 删除以前
103 oldId, ok := this.ipMap[ip]
104 if ok {
105 delete(this.idMap, oldId)
106 this.expireList.Remove(oldId)
107 }
108
109 this.ipMap[ip] = id
110 this.idMap[id] = ip
111 this.locker.Unlock()
112}
113
114// RecordIP 记录IP
115func (this *IPList) RecordIP(ipType string,

Callers 1

RecordIPMethod · 0.95

Calls 6

nextIdMethod · 0.95
AddMethod · 0.65
RemoveMethod · 0.65
StringMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected