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

Method SetServerId

internal/nodes/client_conn_base.go:58–87  ·  view source on GitHub ↗

SetServerId 设置服务ID

(serverId int64)

Source from the content-addressed store, hash-verified

56
57// SetServerId 设置服务ID
58func (this *BaseClientConn) SetServerId(serverId int64) (goNext bool) {
59 goNext = true
60
61 // 检查服务相关IP黑名单
62 var rawIP = this.RawIP()
63 if serverId > 0 && len(rawIP) > 0 {
64 // 是否在白名单中
65 ok, _, expiresAt := iplibrary.AllowIP(rawIP, serverId)
66 if !ok {
67 _ = this.rawConn.Close()
68 firewalls.DropTemporaryTo(rawIP, expiresAt)
69 return false
70 }
71 }
72
73 this.serverId = serverId
74
75 // 设置包装前连接
76 switch conn := this.rawConn.(type) {
77 case *tls.Conn:
78 nativeConn, ok := conn.NetConn().(ClientConnInterface)
79 if ok {
80 nativeConn.SetServerId(serverId)
81 }
82 case *ClientConn:
83 conn.SetServerId(serverId)
84 }
85
86 return true
87}
88
89// ServerId 读取当前连接绑定的服务ID
90func (this *BaseClientConn) ServerId() int64 {

Callers

nothing calls this directly

Calls 5

RawIPMethod · 0.95
AllowIPFunction · 0.92
DropTemporaryToFunction · 0.92
CloseMethod · 0.65
SetServerIdMethod · 0.65

Tested by

no test coverage detected