This commit is contained in:
2026-02-02 11:07:11 +08:00
parent f12d4d9a31
commit 6ef0dd448a

View File

@@ -232,6 +232,7 @@ func (c *CodexAPIAuth) getConfig() []interface{} {
// solvePow 解决 PoW 挑战 // solvePow 解决 PoW 挑战
func (c *CodexAPIAuth) solvePow(seed, difficulty string, cfg []interface{}, maxIterations int) string { func (c *CodexAPIAuth) solvePow(seed, difficulty string, cfg []interface{}, maxIterations int) string {
startTime := time.Now()
seedBytes := []byte(seed) seedBytes := []byte(seed)
for i := 0; i < maxIterations; i++ { for i := 0; i < maxIterations; i++ {
@@ -246,6 +247,8 @@ func (c *CodexAPIAuth) solvePow(seed, difficulty string, cfg []interface{}, maxI
hexHash := fmt.Sprintf("%08x", h) hexHash := fmt.Sprintf("%08x", h)
if hexHash[:len(difficulty)] <= difficulty { if hexHash[:len(difficulty)] <= difficulty {
elapsed := time.Since(startTime).Seconds()
c.logStep(StepNavigate, "[PoW] Solved in %.2fs (iteration %d, difficulty=%s)", elapsed, i, difficulty)
return encoded + "~S" return encoded + "~S"
} }
} }
@@ -328,6 +331,7 @@ func (c *CodexAPIAuth) callSentinelReq(flow string) bool {
if required, ok := powReq["required"].(bool); ok && required { if required, ok := powReq["required"].(bool); ok && required {
seed, _ := powReq["seed"].(string) seed, _ := powReq["seed"].(string)
difficulty, _ := powReq["difficulty"].(string) difficulty, _ := powReq["difficulty"].(string)
c.logStep(StepNavigate, "[Sentinel] flow=%s, PoW required, difficulty=%s", flow, difficulty)
config := c.getConfig() config := c.getConfig()
solved := c.solvePow(seed, difficulty, config, 5000000) solved := c.solvePow(seed, difficulty, config, 5000000)
if solved != "" { if solved != "" {
@@ -337,9 +341,11 @@ func (c *CodexAPIAuth) callSentinelReq(flow string) bool {
return false return false
} }
} else { } else {
c.logStep(StepNavigate, "[Sentinel] flow=%s, PoW not required", flow)
c.solvedPow = initToken c.solvedPow = initToken
} }
} else { } else {
c.logStep(StepNavigate, "[Sentinel] flow=%s, no PoW in response", flow)
c.solvedPow = initToken c.solvedPow = initToken
} }