2
This commit is contained in:
@@ -232,6 +232,7 @@ func (c *CodexAPIAuth) getConfig() []interface{} {
|
||||
|
||||
// solvePow 解决 PoW 挑战
|
||||
func (c *CodexAPIAuth) solvePow(seed, difficulty string, cfg []interface{}, maxIterations int) string {
|
||||
startTime := time.Now()
|
||||
seedBytes := []byte(seed)
|
||||
|
||||
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)
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
@@ -328,6 +331,7 @@ func (c *CodexAPIAuth) callSentinelReq(flow string) bool {
|
||||
if required, ok := powReq["required"].(bool); ok && required {
|
||||
seed, _ := powReq["seed"].(string)
|
||||
difficulty, _ := powReq["difficulty"].(string)
|
||||
c.logStep(StepNavigate, "[Sentinel] flow=%s, PoW required, difficulty=%s", flow, difficulty)
|
||||
config := c.getConfig()
|
||||
solved := c.solvePow(seed, difficulty, config, 5000000)
|
||||
if solved != "" {
|
||||
@@ -337,9 +341,11 @@ func (c *CodexAPIAuth) callSentinelReq(flow string) bool {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
c.logStep(StepNavigate, "[Sentinel] flow=%s, PoW not required", flow)
|
||||
c.solvedPow = initToken
|
||||
}
|
||||
} else {
|
||||
c.logStep(StepNavigate, "[Sentinel] flow=%s, no PoW in response", flow)
|
||||
c.solvedPow = initToken
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user