阶段十:完成 Go Engine 注释基线清零

This commit is contained in:
Christ committed 2026-08-15 05:12:37 +08:00
1 parent 9255c233aa
commit 64e7868444
22 files changed
+1355 -8557

No files matched your search

+19 -1
View File
@@ -10,18 +10,23 @@ import (
"xianyu-go/internal/xianyu/cookierefresh"
)
// tokenExpirySafetyMargin 保存令牌ExpirySafetyMargin,供当前处理流程使用
const tokenExpirySafetyMargin = time.Minute
// tokenFallbackLifetime 保存令牌FallbackLifetime,供当前处理流程使用
const (
tokenFallbackLifetime = 30 * time.Minute
tokenRefreshLeadTime = 10 * time.Minute
)
// effectiveTokenExpireAt 负责effective令牌ExpireAt相关处理。
func effectiveTokenExpireAt(serverExpireAt int64, now time.Time) int64 {
// ttl 保存ttl,供当前处理流程使用
ttl := time.Unix(serverExpireAt, 0).Sub(now)
if ttl <= 0 {
return 0
}
// margin 保存margin,供当前处理流程使用
margin := tokenExpirySafetyMargin
if ttl <= 2*margin {
margin = ttl / 10
@@ -29,12 +34,15 @@ func effectiveTokenExpireAt(serverExpireAt int64, now time.Time) int64 {
return now.Add(ttl - margin).Unix()
}
// tokenRotationSchedule 负责令牌RotationSchedule相关处理。
func tokenRotationSchedule(serverExpireAt int64, now time.Time) (expiresAt, refreshAt time.Time) {
expiresAt = time.Unix(serverExpireAt, 0)
if serverExpireAt <= now.Unix() {
expiresAt = now.Add(tokenFallbackLifetime)
}
// ttl 保存ttl,供当前处理流程使用
ttl := expiresAt.Sub(now)
// lead 保存lead,供当前处理流程使用
lead := ttl / 10
if lead < tokenRefreshLeadTime {
lead = tokenRefreshLeadTime
@@ -46,9 +54,13 @@ func tokenRotationSchedule(serverExpireAt int64, now time.Time) (expiresAt, refr
return expiresAt, refreshAt
}
// credentialCookieFingerprint 负责credential登录凭证Fingerprint相关处理。
func credentialCookieFingerprint(cookieStr string) string {
// canonical 保存canonical,供当前处理流程使用
var canonical strings.Builder
// part 表示当前遍历过程中的part
for _, part := range strings.Split(cookieStr, ";") {
// key、value、ok 保存key、value、ok,供当前处理流程使用
key, value, ok := strings.Cut(strings.TrimSpace(part), "=")
key = strings.TrimSpace(key)
if !ok || key == "" {
@@ -59,6 +71,7 @@ func credentialCookieFingerprint(cookieStr string) string {
canonical.WriteString(strings.TrimSpace(value))
canonical.WriteByte(0)
}
// sum 保存sum,供当前处理流程使用
sum := sha256.Sum256([]byte(canonical.String()))
return hex.EncodeToString(sum[:])
}
@@ -68,18 +81,23 @@ func credentialCookieFingerprint(cookieStr string) string {
// fingerprint deliberately retains duplicate names and their order because
// lib-mtop reads the first path-ordered _m_h5_tk entry. A present empty Jar is
// distinct from legacy metadata that has no complete snapshot.
// credentialStateFingerprint 负责credential状态Fingerprint相关处理。
func credentialStateFingerprint(cookieStr, metadataJSON string) string {
// canonical 保存canonical,供当前处理流程使用
var canonical strings.Builder
canonical.WriteString("flat\x00")
canonical.WriteString(credentialCookieFingerprint(cookieStr))
canonical.WriteString("\x00snapshot\x00")
if snapshot, complete := cookierefresh.SnapshotFromMetadataOK(metadataJSON); complete {
if // snapshot、complete 保存snapshot、complete,供当前处理流程使用
snapshot, complete := cookierefresh.SnapshotFromMetadataOK(metadataJSON); complete {
canonical.WriteByte('1')
// raw 保存原始,供当前处理流程使用
raw, _ := json.Marshal(cookierefresh.NormalizeSnapshot(snapshot))
canonical.Write(raw)
} else {
canonical.WriteByte('0')
}
// sum 保存sum,供当前处理流程使用
sum := sha256.Sum256([]byte(canonical.String()))
return hex.EncodeToString(sum[:])
}