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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>