SetServerId 设置服务ID
(serverId int64)
| 56 | |
| 57 | // SetServerId 设置服务ID |
| 58 | func (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 |
| 90 | func (this *BaseClientConn) ServerId() int64 { |
nothing calls this directly
no test coverage detected