SPB Git

Repository Public

API.md 7.2 KB

# Storage coordinator — admin API (/admin/v1)

Base URL: https://storage.spboucher.ai (MacLustr Tunnel → m4mn:8870). Used by the dashboard (clustr.spboucher.ai) and by the mlstore CLI. The device-facing protocol is documented in MSP-1.md.

Authentication: Authorization: Bearer <token>; the token is the content of m4mn:~/.config/maclustr-storage/admin.token (64 hex characters, generated on the node at first start, never in git). 20 failed attempts per address per 10 minutes, then 429. The admin API is not served on the LAN listener. Errors: {"error": "<code>", "message": "..."}.

All sizes are bytes, all times are Unix seconds.

# Overview

GET /admin/v1/overview

jsonc
{
  "coordinator": { "version": "1.0.0", "protocol": "MSP/1", "host": "storage.spboucher.ai", "uptime_seconds": 120,
                   "fragment_size": 8388608, "mobile_replicas_target": 2, "server_time": 1796141113,
                   "storage_class": "mobile_opportunistic" },
  "totals": {
    "nodes": 2, "nodes_online": 1,
    "capacity_registered": 107374182400,   // sum of the quotas chosen on the devices
    "capacity_accessible": 53687091200,    // quotas of the nodes reachable right now
    "capacity_offline": 53687091200,       // quotas of the nodes that are not reachable
    "capacity_available_now": 41234567890, // what could really be written now: min(quota left, space the device reports writable), online + accepting nodes only
    "used": 1234567890,                    // bytes of fragments confirmed stored on mobile nodes
    "redundant_bytes": 617283945,          // distinct stable fragments that also live on at least one mobile node
    "redundant_fragments": 74,
    "fragments_on_mobile": 148,
    "transferred_to_devices": 2469135780, "transferred_from_devices": 16777232,
    "availability_24h": 0.61,              // mean over nodes of (minutes seen / minutes since pairing, 24 h window); null without data
    "integrity_rate": 1,                   // possession proofs passed / proofs checked; null before the first check
    "integrity_checks": 160
  },
  "stable": { "objects": 3, "object_bytes": 617280000, "fragments": 74, "fragment_bytes": 617283945,
              "fragments_unhealthy": 0, "fragments_only_on_mobile": 0, "disk_free": 357000000000, "disk_total": 494000000000 },
  "nodes": [ /* node objects, see below */ ]
}

Node object (also GET /admin/v1/nodes/{id|name} → { node, events[], transfers[], tasks[] }):

jsonc
{
  "id": "5f0c…", "name": "iPhone de Simon", "model": "iPhone18,2", "os_version": "27.1", "app_version": "1.0.0 (1)",
  "status": "active",            // active | suspended | draining | drained | revoked   (removed nodes are not listed)
  "online": true,                // heard from within the last 100 s
  "health": "healthy",           // healthy | paused | offline | hot | degraded | suspended | draining | drained | revoked
  "accepting": true, "accepting_reason": null,   // device-side reason when it refuses new fragments: wifi_only, charging_only, low_space, thermal, low_battery, suspended…
  "paired_at": 1796140000, "last_seen": 1796141100, "last_via": "lan",   // lan | gateway
  "capacity": { "allocated": 53687091200, "used": 617283945, "pending": 16777248, "available": 41234567890,
                "device_total": 256000000000, "device_free": 120000000000, "device_reserve": 25600000000, "device_reported_used": 617283945 },
  "fragments": 74, "fragments_pending": 2,
  "rates": { "rx_bps": 31457280, "tx_bps": 0 },          // measured on the device, last heartbeat
  "power": { "battery": 0.82, "charging": true, "low_power": false },   // null fields when unknown
  "thermal": "nominal",          // nominal | fair | serious | critical
  "network": "wifi",             // wifi | cellular | wired | none
  "mode": "active",              // active | station | background
  "policy": { "wifi_only": true, "charging_only": false, "cellular": false, "rate_limit_bps": 0 },
  "transferred": { "to_device": 1234567890, "from_device": 8388624 },   // measured by the coordinator
  "integrity": { "ok": 80, "failed": 0, "rate": 1 },
  "availability": { "h24": 0.61, "d7": 0.4 },
  "drain": null,                 // { remaining_fragments, remaining_bytes, awaiting_stable_copy } while draining
  "key_rotated_at": null, "bench": null   // last on-device benchmark report, when the user ran one
}

# Pairing

Call Effect
POST /admin/v1/pairing { "label": "…", "ttl_seconds": 600 } 201 { code: "ABCD-EFGH-JKMN", expires_at, ttl_seconds, qr_payload: "msp1://pair?h=storage.spboucher.ai&c=ABCD-EFGH-JKMN", id }. Single use, 60 s–1 h (default 10 min). Only its SHA-256 is stored: the code is shown once.
GET /admin/v1/pairing { codes: [{ id, label, created_at, expires_at, used_at, device_id, revoked_at, state }] }, state pending/used/revoked/expired
DELETE /admin/v1/pairing/{id} { revoked: true } when a pending code was revoked

The dashboard renders qr_payload as a QR code; the app scans it, or the user types code.

# Node actions

POST /admin/v1/nodes/{id|name}/{action} → { node } unless noted.

Action Effect
suspend / resume Stops / restarts every exchange of work with the node (fragments stay on it). resume also returns a drained node to service.
drain { "remove": false } Graceful drain: no new fragment; each fragment's stable copy is confirmed (pulled back from the device first if missing), then deleted from the device; ends drained (or removed).
revoke Immediate: the device key and its tickets are refused, placements dropped. The fragments it held are opaque ciphertext.
verify Queues a possession proof for every fragment on the node → { queued }
retrieve { "count": 1 } or { "fragments": [ids] } Asks the node to send fragments back; each is checked against its SHA-256 → { tasks: [{ fragment, task }] }

DELETE /admin/v1/nodes/{id|name} forgets a node that is revoked or drained (it leaves the list; 409 node_still_in_service otherwise).

# Objects (what the cluster stores)

Call Effect
PUT /admin/v1/objects?name=&class= (raw body, streamed) Chunks, encrypts (AES-256-GCM), writes the stable copy → 201 { id, size, sha256, fragments, new_fragments, deduplicated }
GET /admin/v1/objects List with mobile coverage per object
GET /admin/v1/objects/{id} Fragment map: stable state and the mobile nodes holding each fragment
GET /admin/v1/objects/{id}/content Decrypted stream, every fragment and the whole digest verified (X-Object-SHA256). 503 stable_copy_unavailable lists fragments being recovered from mobile nodes.
DELETE /admin/v1/objects/{id} Unreferenced fragments leave the stable store and are deleted from the devices

# Journal

GET /admin/v1/events?limit= → { events: [{ id, ts, device_id, device_name, kind, detail }] } (pairing, quota, integrity failures, repairs, drain, revocation…). GET /admin/v1/transfers?limit= → { transfers: [{ ts, device_id, device_name, fragment_id, direction, bytes, ms, ok, via, resumed_from }] }.

GET /healthz (no token) → { ok, service, version, protocol, devices, time }.

Files main
Menu

Theme