SPB Git

Repository Public

API.md 7.2 KB 116 lines markdown

1<!--2MacLustr Storage Node3File: docs/API.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Storage coordinator — admin API (`/admin/v1`)89Base URL: `https://storage.spboucher.ai` (MacLustr Tunnel → `m4mn:8870`). Used by the dashboard (clustr.spboucher.ai) and by10the `mlstore` CLI. The device-facing protocol is documented in [MSP-1.md](MSP-1.md).1112Authentication: `Authorization: Bearer <token>`; the token is the content of `m4mn:~/.config/maclustr-storage/admin.token`13(64 hex characters, generated on the node at first start, never in git). 20 failed attempts per address per 10 minutes, then14`429`. The admin API is not served on the LAN listener. Errors: `{"error": "<code>", "message": "..."}`.1516All sizes are bytes, all times are Unix seconds.1718## Overview1920`GET /admin/v1/overview`2122```jsonc23{24  "coordinator": { "version": "1.0.0", "protocol": "MSP/1", "host": "storage.spboucher.ai", "uptime_seconds": 120,25                   "fragment_size": 8388608, "mobile_replicas_target": 2, "server_time": 1796141113,26                   "storage_class": "mobile_opportunistic" },27  "totals": {28    "nodes": 2, "nodes_online": 1,29    "capacity_registered": 107374182400,   // sum of the quotas chosen on the devices30    "capacity_accessible": 53687091200,    // quotas of the nodes reachable right now31    "capacity_offline": 53687091200,       // quotas of the nodes that are not reachable32    "capacity_available_now": 41234567890, // what could really be written now: min(quota left, space the device reports writable), online + accepting nodes only33    "used": 1234567890,                    // bytes of fragments confirmed stored on mobile nodes34    "redundant_bytes": 617283945,          // distinct stable fragments that also live on at least one mobile node35    "redundant_fragments": 74,36    "fragments_on_mobile": 148,37    "transferred_to_devices": 2469135780, "transferred_from_devices": 16777232,38    "availability_24h": 0.61,              // mean over nodes of (minutes seen / minutes since pairing, 24 h window); null without data39    "integrity_rate": 1,                   // possession proofs passed / proofs checked; null before the first check40    "integrity_checks": 16041  },42  "stable": { "objects": 3, "object_bytes": 617280000, "fragments": 74, "fragment_bytes": 617283945,43              "fragments_unhealthy": 0, "fragments_only_on_mobile": 0, "disk_free": 357000000000, "disk_total": 494000000000 },44  "nodes": [ /* node objects, see below */ ]45}46```4748Node object (also `GET /admin/v1/nodes/{id|name}` → `{ node, events[], transfers[], tasks[] }`):4950```jsonc51{52  "id": "5f0c…", "name": "iPhone de Simon", "model": "iPhone18,2", "os_version": "27.1", "app_version": "1.0.0 (1)",53  "status": "active",            // active | suspended | draining | drained | revoked   (removed nodes are not listed)54  "online": true,                // heard from within the last 100 s55  "health": "healthy",           // healthy | paused | offline | hot | degraded | suspended | draining | drained | revoked56  "accepting": true, "accepting_reason": null,   // device-side reason when it refuses new fragments: wifi_only, charging_only, low_space, thermal, low_battery, suspended…57  "paired_at": 1796140000, "last_seen": 1796141100, "last_via": "lan",   // lan | gateway58  "capacity": { "allocated": 53687091200, "used": 617283945, "pending": 16777248, "available": 41234567890,59                "device_total": 256000000000, "device_free": 120000000000, "device_reserve": 25600000000, "device_reported_used": 617283945 },60  "fragments": 74, "fragments_pending": 2,61  "rates": { "rx_bps": 31457280, "tx_bps": 0 },          // measured on the device, last heartbeat62  "power": { "battery": 0.82, "charging": true, "low_power": false },   // null fields when unknown63  "thermal": "nominal",          // nominal | fair | serious | critical64  "network": "wifi",             // wifi | cellular | wired | none65  "mode": "active",              // active | station | background66  "policy": { "wifi_only": true, "charging_only": false, "cellular": false, "rate_limit_bps": 0 },67  "transferred": { "to_device": 1234567890, "from_device": 8388624 },   // measured by the coordinator68  "integrity": { "ok": 80, "failed": 0, "rate": 1 },69  "availability": { "h24": 0.61, "d7": 0.4 },70  "drain": null,                 // { remaining_fragments, remaining_bytes, awaiting_stable_copy } while draining71  "key_rotated_at": null, "bench": null   // last on-device benchmark report, when the user ran one72}73```7475## Pairing7677| Call | Effect |78|---|---|79| `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. |80| `GET /admin/v1/pairing` | `{ codes: [{ id, label, created_at, expires_at, used_at, device_id, revoked_at, state }] }`, state `pending`/`used`/`revoked`/`expired` |81| `DELETE /admin/v1/pairing/{id}` | `{ revoked: true }` when a pending code was revoked |8283The dashboard renders `qr_payload` as a QR code; the app scans it, or the user types `code`.8485## Node actions8687`POST /admin/v1/nodes/{id|name}/{action}` → `{ node }` unless noted.8889| Action | Effect |90|---|---|91| `suspend` / `resume` | Stops / restarts every exchange of work with the node (fragments stay on it). `resume` also returns a drained node to service. |92| `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). |93| `revoke` | Immediate: the device key and its tickets are refused, placements dropped. The fragments it held are opaque ciphertext. |94| `verify` | Queues a possession proof for every fragment on the node → `{ queued }` |95| `retrieve` `{ "count": 1 }` or `{ "fragments": [ids] }` | Asks the node to send fragments back; each is checked against its SHA-256 → `{ tasks: [{ fragment, task }] }` |9697`DELETE /admin/v1/nodes/{id|name}` forgets a node that is `revoked` or `drained` (it leaves the list; `409 node_still_in_service` otherwise).9899## Objects (what the cluster stores)100101| Call | Effect |102|---|---|103| `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 }` |104| `GET /admin/v1/objects` | List with mobile coverage per object |105| `GET /admin/v1/objects/{id}` | Fragment map: stable state and the mobile nodes holding each fragment |106| `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. |107| `DELETE /admin/v1/objects/{id}` | Unreferenced fragments leave the stable store and are deleted from the devices |108109## Journal110111`GET /admin/v1/events?limit=` → `{ events: [{ id, ts, device_id, device_name, kind, detail }] }` (pairing, quota, integrity112failures, repairs, drain, revocation…). `GET /admin/v1/transfers?limit=` → `{ transfers: [{ ts, device_id, device_name,113fragment_id, direction, bytes, ms, ok, via, resumed_from }] }`.114115`GET /healthz` (no token) → `{ ok, service, version, protocol, devices, time }`.116
Files main
Menu

Theme