Skip to content

Conversation

@M2ABRAMSTANK
Copy link

Summary

  • Track total RAM (GB) and CPU cores across all connected peers in the P2P swarm
  • Hardware stats are broadcast via heartbeat messages and aggregated for display on the dashboard
  • Backwards compatible with peers that don't have this update yet

Changes Made

  • src/utils/hardware.js (new): Hardware detection utility using Node.js os module (cached at startup)
  • src/p2p/messaging.js: Added hardware to allowed HEARTBEAT fields with validation (max 2TB RAM, 256 cores), hardware included in signature verification
  • src/p2p/swarm.js: Include hardware stats in initial handshake and periodic heartbeats, hardware signed to prevent tampering
  • src/state/peers.js: O(1) swarm stats via incremental tracking (no iteration needed)
  • server.js: Register self node with hardware stats and include swarmStats in broadcasts
  • src/web/routes/stats.js: Expose swarmStats in /api/stats endpoint
  • src/web/routes/sse.js: Include swarmStats in SSE event stream

API Response Shape

{
  "swarmStats": {
    "totalRam": 256.4,
    "totalCores": 128,
    "peersWithHardware": 42
  }
}

Test plan

  • Built Docker image successfully
  • Ran container and verified /api/stats returns swarmStats
  • Confirmed peersWithHardware: 1 (self node) in isolated test
  • Verify SSE stream includes swarmStats in browser

🤖 Generated with Claude Code

Track total RAM (GB) and CPU cores across all connected peers in the P2P
swarm. Hardware stats are broadcast via heartbeat messages and aggregated
for display on the dashboard.

Changes:
- Add src/utils/hardware.js for local hardware detection (cached at startup)
- Update heartbeat messages to include hardware stats (backwards compatible)
- Include hardware in signature to prevent tampering
- Add hardware validation with realistic bounds (max 2TB RAM, 256 cores)
- Store per-peer hardware data with O(1) aggregation via incremental tracking
- Expose swarmStats via /api/stats endpoint and SSE stream

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant