feat(secubox-core): Add P2P mesh API endpoints for console discovery

- Add /chain/tip endpoint for blockchain tip query
- Add /catalog/console endpoint for version info
- Add symlinks for /api/ prefix compatibility
- Fix chain.json malformed JSON structure

Enables console to discover C3BOX device via mesh API

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2026-01-31 05:40:03 +01:00
parent 8f6eeede06
commit 45f222e72c
8 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1 @@
../catalog

View File

@ -0,0 +1 @@
../chain

View File

@ -0,0 +1 @@
../peers

View File

@ -0,0 +1 @@
../status

View File

@ -0,0 +1,6 @@
#!/bin/sh
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo ""
VERSION=$(cat /etc/secubox-version 2>/dev/null || echo "1.0.0")
echo "{\"version\":\"$VERSION\",\"name\":\"secubox-console\"}"

View File

@ -0,0 +1,36 @@
#!/bin/sh
# P2P API - Chain endpoint
# Returns chain tip or specific operations
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo ""
CHAIN_FILE="/srv/secubox/mesh/chain.json"
NODE_ID=$(cat /srv/secubox/mesh/node.id 2>/dev/null || echo "unknown")
# Parse PATH_INFO for sub-routes: /chain/tip, /chain/since/<hash>
case "$PATH_INFO" in
/tip|"")
# Get the latest block hash and return chain tip info
if [ -f "$CHAIN_FILE" ]; then
LATEST_HASH=$(jsonfilter -i "$CHAIN_FILE" -e "@.blocks[-1].hash" 2>/dev/null)
LATEST_INDEX=$(jsonfilter -i "$CHAIN_FILE" -e "@.blocks[-1].index" 2>/dev/null)
echo "{\"node\":\"$NODE_ID\",\"hash\":\"$LATEST_HASH\",\"height\":$LATEST_INDEX}"
else
echo "{\"node\":\"$NODE_ID\",\"hash\":\"\",\"height\":0}"
fi
;;
/since/*)
SINCE_HASH=${PATH_INFO#/since/}
# Return blocks since given hash (for sync)
if [ -f "$CHAIN_FILE" ]; then
cat "$CHAIN_FILE"
else
echo "{\"blocks\":[]}"
fi
;;
*)
echo "{\"error\":\"unknown_route\",\"path\":\"$PATH_INFO\"}"
;;
esac

View File

@ -0,0 +1,10 @@
#!/bin/sh
# P2P API - List peers endpoint
# Responds to requests on port 7331
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo ""
# Get peers from secubox-p2p
/usr/sbin/secubox-p2p peers 2>/dev/null || echo '{"peers":[],"error":"daemon_unavailable"}'

View File

@ -0,0 +1,10 @@
#!/bin/sh
# P2P API - Node status endpoint
# Responds to requests on port 7331
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo ""
# Get node status from secubox-p2p
/usr/sbin/secubox-p2p status 2>/dev/null || echo '{"error":"daemon_unavailable"}'