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

Function DropTemporaryTo

internal/firewalls/utils.go:10–30  ·  view source on GitHub ↗

DropTemporaryTo 使用本地防火墙临时拦截IP数据包

(ip string, expiresAt int64)

Source from the content-addressed store, hash-verified

8
9// DropTemporaryTo 使用本地防火墙临时拦截IP数据包
10func DropTemporaryTo(ip string, expiresAt int64) {
11 // 如果为0,则表示是长期有效
12 if expiresAt <= 0 {
13 expiresAt = time.Now().Unix() + 3600
14 }
15
16 var timeout = expiresAt - time.Now().Unix()
17 if timeout < 1 {
18 return
19 }
20 if timeout > 3600 {
21 timeout = 3600
22 }
23
24 // 使用本地防火墙延长封禁
25 var fw = Firewall()
26 if fw != nil && !fw.IsMock() {
27 // 这里 int(int64) 转换的前提是限制了 timeout <= 3600,否则将有整型溢出的风险
28 _ = fw.DropSourceIP(ip, int(timeout), true)
29 }
30}

Callers 3

AcceptMethod · 0.92
SetServerIdMethod · 0.92
RecordIPMethod · 0.92

Calls 4

FirewallFunction · 0.85
UnixMethod · 0.80
IsMockMethod · 0.65
DropSourceIPMethod · 0.65

Tested by

no test coverage detected