fix: sync temp auth key expiry boundaries

This commit is contained in:
A 2026-07-13 23:04:15 +08:00
parent 305e8a0008
commit 20a310f6ca
50 changed files with 3626 additions and 335 deletions

View file

@ -50,14 +50,21 @@ type Conn struct {
msgID *proto.MessageIDGen
writeTimeout time.Duration
metrics Metrics
// now shares the Server protocol clock with inbound expiry admission. Tests may
// advance it without sleeping; construction-only Conns fall back to time.Now.
now func() time.Time
authKeyID [8]byte
// authKeyHex 是 authKeyID 的 hex 缓存:每条 RPC 的结构化日志都会带它,
// 建连时算一次,避免热路径反复 hex 编码分配。
authKeyHex string
sessionID int64
salt int64
key crypto.AuthKey
// authKeyExpiresAt=0 表示 permanent key;正值是 temporary/media-temporary
// key 在握手时确定的绝对协议失效时间;-1 是仅供迁移的 legacy-unknown
// sentinel(edge 会在创建 Conn 前以 -404 拒绝)。Conn 创建后不可变。
authKeyExpiresAt int
sessionID int64
salt int64
key crypto.AuthKey
outbound chan outboundOp
outboundControl chan outboundOp
@ -243,6 +250,20 @@ func (c *Conn) SetClientLayer(layer int) { c.clientLayer.Store(int32(layer)) }
// AuthKeyID 返回连接的 auth_key_id。
func (c *Conn) AuthKeyID() [8]byte { return c.authKeyID }
// AuthKeyExpiresAt 返回 raw 协议 key 的失效时间;0 表示 permanent key。
func (c *Conn) AuthKeyExpiresAt() int { return c.authKeyExpiresAt }
func (c *Conn) authKeyProtocolUnavailableNow() bool {
if c == nil {
return true
}
now := time.Now()
if c.now != nil {
now = c.now()
}
return authKeyProtocolUnavailable(c.authKeyExpiresAt, now)
}
// BusinessAuthKeyID 返回业务视角的 auth_key_id。
//
// temp auth_key 绑定后解析为 perm auth_key;第二个返回值表示本连接是否已完成解析,