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

Method checkLatestIP

internal/firewalls/firewall_base.go:18–47  ·  view source on GitHub ↗

检查是否在最近添加过

(ip string)

Source from the content-addressed store, hash-verified

16
17// 检查是否在最近添加过
18func (this *BaseFirewall) checkLatestIP(ip string) bool {
19 this.locker.Lock()
20 defer this.locker.Unlock()
21
22 var expiredIndex = -1
23 for index, ipTime := range this.latestIPTimes {
24 var pieces = strings.Split(ipTime, "@")
25 var oldIP = pieces[0]
26 var oldTimestamp = pieces[1]
27 if types.Int64(oldTimestamp) < time.Now().Unix()-3 /** 3秒外表示过期 **/ {
28 expiredIndex = index
29 continue
30 }
31 if oldIP == ip {
32 return true
33 }
34 }
35
36 if expiredIndex > -1 {
37 this.latestIPTimes = this.latestIPTimes[expiredIndex+1:]
38 }
39
40 this.latestIPTimes = append(this.latestIPTimes, ip+"@"+types.String(time.Now().Unix()))
41 const maxLen = 128
42 if len(this.latestIPTimes) > maxLen {
43 this.latestIPTimes = this.latestIPTimes[1:]
44 }
45
46 return false
47}

Callers 3

RejectSourceIPMethod · 0.80
DropSourceIPMethod · 0.80
DropSourceIPMethod · 0.80

Calls 4

UnixMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected