feat: Create error handling and logging audit
This commit introduces a new audit document, `AUDIT-ERROR-HANDLING.md`, which provides a comprehensive review of the project's error handling and logging practices.
The audit covers:
- **Error Handling:** Analyzes the inconsistency between the well-structured API error responses and the simpler, unstructured error handling at the application's entry points.
- **Logging:** Details the existing custom logger, its lack of JSON output, and its inconsistent use across the codebase.
- **Recommendations:** Provides actionable steps for improvement, including adopting structured JSON logging, centralizing logger configuration, and standardizing on the global logger.
Additionally, this commit includes minor, unrelated fixes to address pre-existing build failures:
- Adds a missing package declaration and imports in `pkg/node/dispatcher.go`.
- Removes an unused import in `pkg/ueps/packet.go`.
Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
2026-02-02 01:14:25 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/Snider/Mining/pkg/ueps"
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-03 16:03:40 +00:00
|
|
|
// pkg/node/dispatcher.go
|
|
|
|
|
|
|
|
|
|
func (n *NodeManager) DispatchUEPS(pkt *ueps.ParsedPacket) error {
|
feat: Create error handling and logging audit
This commit introduces a new audit document, `AUDIT-ERROR-HANDLING.md`, which provides a comprehensive review of the project's error handling and logging practices.
The audit covers:
- **Error Handling:** Analyzes the inconsistency between the well-structured API error responses and the simpler, unstructured error handling at the application's entry points.
- **Logging:** Details the existing custom logger, its lack of JSON output, and its inconsistent use across the codebase.
- **Recommendations:** Provides actionable steps for improvement, including adopting structured JSON logging, centralizing logger configuration, and standardizing on the global logger.
Additionally, this commit includes minor, unrelated fixes to address pre-existing build failures:
- Adds a missing package declaration and imports in `pkg/node/dispatcher.go`.
- Removes an unused import in `pkg/ueps/packet.go`.
Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
2026-02-02 01:14:25 +00:00
|
|
|
// 1. The "Threat" Circuit Breaker (L5 Guard)
|
|
|
|
|
if pkt.Header.ThreatScore > 50000 {
|
|
|
|
|
// High threat? Drop it. Don't even parse the payload.
|
|
|
|
|
// This protects the Agent from "semantic viruses"
|
|
|
|
|
return fmt.Errorf("packet rejected: threat score %d exceeds safety limit", pkt.Header.ThreatScore)
|
|
|
|
|
}
|
2026-01-03 16:03:40 +00:00
|
|
|
|
|
|
|
|
// 2. The "Intent" Router (L9 Semantic)
|
|
|
|
|
switch pkt.Header.IntentID {
|
|
|
|
|
|
|
|
|
|
case 0x01: // Handshake / Hello
|
|
|
|
|
return n.handleHandshake(pkt)
|
|
|
|
|
|
|
|
|
|
case 0x20: // Compute / Job Request
|
|
|
|
|
// "Hey, can you run this Docker container?"
|
|
|
|
|
// Check local resources first (Self-Validation)
|
|
|
|
|
return n.handleComputeRequest(pkt.Payload)
|
|
|
|
|
|
|
|
|
|
case 0x30: // Rehab / Intervention
|
|
|
|
|
// "Violet says you are hallucinating. Pause execution."
|
|
|
|
|
// This is the "Benevolent Intervention" Axiom.
|
|
|
|
|
return n.enterRehabMode(pkt.Payload)
|
|
|
|
|
|
|
|
|
|
case 0xFF: // Extended / Custom
|
|
|
|
|
// Check the payload for specific sub-protocols (e.g. your JSON blobs)
|
|
|
|
|
return n.handleApplicationData(pkt.Payload)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("unknown intent ID: 0x%X", pkt.Header.IntentID)
|
|
|
|
|
}
|
|
|
|
|
}
|