Commit graph

33 commits

Author SHA1 Message Date
Claude
0ef766ee36
ax(node): rename Controller.node field to nodeManager for AX Principle 1
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
`node` is ambiguous in the `node` package — callers cannot distinguish the
field from the package name without tracing. `nodeManager` names the type
it holds and removes all mapping overhead.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 17:46:35 +01:00
Claude
406005b21a
ax(node): rename abbreviated msg locals to message in controller
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle 1 — predictable names over short names. Local variables
declared as `msg` in GetRemoteStats, StartRemoteMiner, StopRemoteMiner,
GetRemoteLogs, and PingPeer renamed to `message`.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 16:59:58 +01:00
Claude
695a62b61a
ax(node): remove banned fmt import from controller.go
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Replace all fmt.Errorf calls with typed *ProtocolError values using the
native node error type — consistent with how protocol.go was cleaned up.
Error wrapping cases (failed to create message) now surface the original
error directly, preserving the call chain without fmt.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 16:41:30 +01:00
Claude
68fbe70c54
ax(node): rename ack to acknowledgement in controller (AX Principle 1)
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 16:38:18 +01:00
Claude
956f8de643
ax(node): replace prose comment with usage example in NewController
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX-2: comments must show concrete usage, not restate what the code does.
The "Register message handler for responses" prose comment was replaced
with a usage-example comment that shows the actual call pattern.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 16:18:23 +01:00
Claude
ea5996ce40
ax(node): rename ctx→cancelContext/requestContext/shutdownContext
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle 1: predictable names over short names.
`ctx` is an abbreviation that requires prior knowledge to decode;
renamed to describe intent at each call site.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:28:07 +01:00
Claude
d0b37bf57f
ax(node): rename resp to response in controller.go
AX Principle 1 — predictable names over short names.
`resp` is an abbreviation that requires context to interpret;
`response` is self-describing at any reading distance.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:18:01 +01:00
Claude
cd8d17cc78
ax(node): expand ctrl receiver to controller in Controller methods
AX Principle 1 — predictable names over short names. `ctrl` is an
abbreviation that requires a comment to explain; `controller` is
self-documenting and consistent with the `manager` pattern used in
NodeManager and PeerRegistry receivers.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 12:54:19 +01:00
Claude
ca3faa0144
ax(node): rename channel to responseChannel in handleResponse
AX Principle 1 — predictable names over short names. The variable
`channel` in handleResponse required context to understand its role;
`responseChannel` is self-describing on first read.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 12:49:30 +01:00
Claude
2792db3919
ax(node): rename pending to pendingRequests for AX Principle 1 compliance
The field name `pending` required an inline comment to explain its
purpose ("message ID -> response channel"). Per AX Principle 1,
names that require a comment to explain are too short — rename to
`pendingRequests` so the field is self-describing without annotation.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 12:46:55 +01:00
Claude
274cb73ab6
ax(node): rename local var c to controller in NewController
Single-letter c is reserved for *core.Core (AX Principle 1 — predictable
names over short names). Using c for a *Controller introduces semantic
ambiguity; controller makes the type intent self-evident.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 10:34:19 +01:00
Claude
d9f45773b4
ax(node): rename Controller receiver from c to ctrl
AX-1: c is reserved for *core.Core receivers per RFC-CORE-008.
Controller methods used c as the receiver name which creates
semantic ambiguity. Renamed to ctrl to match the usage examples
already present in the comment blocks.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 10:32:07 +01:00
Claude
cbc876fdaf
ax(node): rename single-letter goroutine parameter p to connectedPeer
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle 1: predictable names over short names. The goroutine
parameter in GetAllStats used `p *Peer` — a single-letter abbreviation
with no justification under the AX exception list (i, _, t, c only).
Renamed to `connectedPeer` to match the variable's semantic role.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 09:41:18 +01:00
Claude
f18991470d
ax(node): replace prose comments with usage examples on Controller
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Controller type and sendRequest had comments that restated the type
signature in prose. RFC-025 §2: if a comment restates what the type
signature says, delete it; show a concrete call instead.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 09:28:02 +01:00
Claude
32290b839b
ax(node): replace prose comment with usage example on GetRemoteLogs
Some checks failed
Test / test (push) Waiting to run
Security Scan / security (push) Has been cancelled
AX Principle 2 — comments must show HOW with real values, not restate
the signature in prose. "GetRemoteLogs requests console logs from a
remote miner" added zero information; replaced with a concrete call
showing peerID, minerName, lines, and result handling.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 09:15:35 +01:00
Claude
05fb333686
ax(node): replace prose comment with usage example on StopRemoteMiner
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle 2 — comments must show HOW with real values, not restate
what the type signature already says.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 09:11:34 +01:00
Claude
0c77689877
ax(node): rename mu to mutex in Controller (AX-1 predictable names)
Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 09:05:26 +01:00
Claude
89100776e9
ax(node): replace prose comment with usage example on StartRemoteMiner
RFC-CORE-008 Principle 2: comments show HOW with real values, not restate the signature.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 08:57:07 +01:00
Claude
0979fd1aea
ax(node): replace prose comment with usage example on GetRemoteStats
Some checks failed
Security Scan / security (push) Successful in 31s
Test / test (push) Has been cancelled
AX Principle 2 — comments must show HOW with real values, not restate
what the type signature already says.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 08:54:44 +01:00
Claude
0c69d095de
ax(node): replace prose comment with usage example, rename ch to channel
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle 1: ch is an opaque abbreviation for a response channel — rename
to channel so the variable's role is predictable without tracing the map type.

AX Principle 2: "handleResponse processes incoming messages…" restates the
signature. Replaced with a concrete usage example showing how it is wired.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 08:32:39 +01:00
Claude
31ef201ff4
ax(node): replace prose comments with usage examples on Controller methods
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
PingPeer, ConnectToPeer, and DisconnectFromPeer had comments that
restated the signature in prose. AX-2 requires concrete call examples,
not descriptions. Replaced all three with usage-example comments.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 07:56:16 +01:00
Claude
4a586f4dad
ax(node): replace prose comment on GetAllStats with usage example
AX Principle 2: comments that restate the function name add zero
information. Replace with a concrete call pattern showing iteration
over the returned map.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 07:50:36 +01:00
Claude
c0856259cd
ax(node): rename abbreviated mu/wg to resultsMutex/waitGroup in GetAllStats
Some checks failed
Test / test (push) Waiting to run
Security Scan / security (push) Has been cancelled
AX Principle 1 — predictable names over short names. `mu` and `wg` require
mental mapping; `resultsMutex` and `waitGroup` state their purpose directly.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 07:49:17 +01:00
Claude
725960d915
ax(node): rename respCh to responseChannel in sendRequest
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle 1 — predictable names over short names.
`respCh` is an abbreviated compound; `responseChannel` is
unambiguous without context.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 07:45:03 +01:00
Claude
c85217dfca
ax(node): rename rtt to roundTripTime in PingPeer
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle #1: names must not require a comment to explain.
The comment "Calculate round-trip time" existed solely to decode
the abbreviation rtt — proof the name was too short.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 07:41:15 +01:00
Claude
b93b19fac7
ax(node): replace prose comment on NewController with usage example
AX principle 2: comments show HOW with real values, not WHAT the
signature already says.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 07:25:42 +01:00
Claude
140f038f37
chore: migrate module path from github.com to forge.lthn.ai
Some checks failed
E2E Tests / E2E Tests (push) Failing after 1m23s
Tests / Go Tests (push) Failing after 39s
Desktop Release / Build linux (push) Failing after 46s
Release / Test (push) Failing after 2s
Tests / C++ Tests (push) Failing after 1m12s
Release / Release (push) Has been cancelled
Desktop Release / Build darwin (push) Has been cancelled
Desktop Release / Build windows (push) Has been cancelled
Desktop Release / Create Release (push) Has been cancelled
Move module declaration and all internal imports from
github.com/Snider/Mining to forge.lthn.ai/Snider/Mining. Also updates
Borg, Enchantrix, and Poindexter dependency paths to forge.lthn.ai.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 21:39:01 +00:00
snider
d533164893 fix: Comprehensive code hardening from 4-domain Opus review
Error Handling:
- Fix silent Write() error in WebSocket (events.go)
- Add error context to transport handshake messages
- Check os.MkdirAll error in zip extraction (miner.go)
- Explicitly ignore io.Copy errors on drain with comments
- Add retry logic (2 attempts) for transient stats collection failures

Resource Lifecycle:
- Add shutdown mechanism to DigestAuth goroutine
- Call Service.Stop() on context cancellation
- Add NodeService transport cleanup to Service.Stop()
- Fix WriteStdin goroutine leak on timeout with non-blocking send

API Design:
- Add profile validation (name, miner type required)
- Return 404 instead of 500 for missing profile PUT
- Make DELETE profile idempotent (return success if not found)
- Standardize error responses in node_service.go handlers

Observability:
- Add logging for P2P GetAllStats failures
- Add request ID correlation helper for handler logs
- Add logging for miner process exits (xmrig_start.go)
- Rate limit debug logs in transport hot path (1 in 100)
- Add metrics infrastructure with /metrics endpoint

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 14:33:30 +00:00
snider
34f860309f refactor: Add reliability fixes and architecture improvements
Reliability fixes:
- Fix HTTP response body drainage in xmrig, ttminer, miner
- Fix database init race condition (nil before close)
- Fix empty minerType bug in P2P StartMinerPayload
- Add context timeout to InsertHashratePoint (5s default)

Architecture improvements:
- Extract HashrateStore interface with DefaultStore/NopStore
- Create ServiceContainer for centralized initialization
- Extract protocol response handler (ValidateResponse, ParseResponse)
- Create generic FileRepository[T] with atomic writes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 12:43:46 +00:00
snider
d61a8aff8b refactor: Remove unused code and fix nil dereference issues
- Remove unused exported functions from pkg/database (session tracking,
  bulk hashrate inserts, various query helpers)
- Remove unused exported functions from pkg/node (identity management,
  bundle operations, controller methods)
- Make internal-only functions unexported in config_manager.go and database.go
- Remove unused EventProfile* constants from events.go
- Add GetCommit() and GetBuildDate() to expose version.go variables
- Fix potential nil dereference issues flagged by Qodana:
  - Add nil checks for GetIdentity() in controller.go, transport.go, worker.go
  - Add nil checks for GetPeer() in peer_test.go
  - Add nil checks in worker_test.go

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 09:24:12 +00:00
snider
74bbf14de4 fix: Address networking, memory leak, and segfault issues from code review
Networking/Protocol fixes:
- Add HTTP server timeouts (Read/Write/Idle/ReadHeader) in service.go
- Fix CORS address parsing to use net.SplitHostPort safely
- Add request body size limit middleware (1MB max)
- Enforce MaxConns limit in WebSocket upgrade handler
- Fix WebSocket origin validation to only allow localhost
- Add read/write deadlines to WebSocket connections

Memory leak fixes:
- Add sync.Once to Manager.Stop() to prevent double-close panic
- Fix controller pending map leak by closing response channel
- Add memory reallocation for hashrate history slices when oversized
- Fix LogBuffer to truncate long lines and force reallocation on trim
- Add process wait timeout to prevent goroutine leaks on zombie processes
- Drain HTTP response body on copy error to allow connection reuse

Segfault/panic prevention:
- Add nil check in GetTotalHashrate for stats pointer
- Fix hashrate history slice reallocation to prevent capacity bloat

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 02:26:46 +00:00
snider
e0c9c92244 feat: Implement logging functionality for miners with log buffer and retrieval endpoint 2025-12-29 22:10:45 +00:00
snider
9a781ae3f0 feat: Add multi-node P2P mining management system
Implement secure peer-to-peer communication between Mining CLI instances
for remote control of mining rigs. Uses Borg library for encryption
(SMSG, STMF, TIM) and Poindexter for KD-tree based peer selection.

Features:
- Node identity management with X25519 keypairs
- Peer registry with multi-factor optimization (ping/hops/geo/score)
- WebSocket transport with SMSG encryption
- Controller/Worker architecture for remote operations
- TIM/STIM encrypted bundles for profile/miner deployment
- CLI commands: node, peer, remote
- REST API endpoints for node/peer/remote operations
- Docker support for P2P testing with multiple nodes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 19:49:33 +00:00