MacLustr Storage Protocol — MSP/1
Application protocol between a mobile storage node (the iOS app) and the storage coordinator. JSON over HTTPS for control, raw bytes for fragments. Every connection is opened by the device: nothing listens on the iPhone, so it works behind NAT, cellular carriers and firewalls.
Reference implementations: server/src/msp.ts (coordinator), MacLustrStorageNode/Core/Networking/MSPClient.swift and
Core/Synchronization/NodeEngine.swift (device), server/test/device.ts (scripted test device).
1. Transports
| Path | URL | TLS trust | When |
|---|---|---|---|
| Gateway | https://storage.spboucher.ai (MacLustr Tunnel: Caddy on BHS64 → WireGuard → coordinator) |
system trust (public certificate) | always available; the only path used in the background |
| Local network | https://<coordinator-ip>:8871, found with Bonjour _maclustr-msp._tcp |
self-signed certificate, accepted only if its SHA-256 equals the pin the device received through the gateway (lan.pin_sha256) |
app in the foreground, device on the coordinator's network, option enabled |
A Bonjour announcement is never trusted by itself: the device calls GET /msp/1/hello on the announced address and the TLS
handshake fails unless the certificate matches the pin. The admin API is not served on the local listener.
Time is Unix seconds. Sizes are bytes. Errors: HTTP status + {"error": "<code>"}.
2. Identity and request signature
At pairing the device generates a P-256 key pair (Secure Enclave when the hardware has one; the private key cannot be exported) and registers the public key (uncompressed X9.63, 65 bytes, base64).
Every control request is a POST /msp/1/<route> with a JSON body and four headers:
MSP-Device: <device id> ("pair" for the pairing request)
MSP-Timestamp: <unix seconds>
MSP-Nonce: <16–64 url-safe characters, never reused>
MSP-Signature: base64( ECDSA-P256-SHA256, DER ) over the canonical requestCanonical request (UTF-8, \n separators):
MSP1
POST
/msp/1/<route> (path and query exactly as sent)
<MSP-Timestamp>
<MSP-Nonce>
<hex SHA-256 of the body>The coordinator refuses a request when: the device is unknown (401 unknown_device), the timestamp is more than 300 s off
(401 clock_skew — the device then reads server_time from /hello and retries once with an offset), the signature does
not verify (401 bad_signature), the nonce was already seen for this device (401 replayed_request; nonces are kept
600 s), the device is revoked or removed (403 device_revoked / 403 device_removed). There is no bearer token and no
session: nothing replayable is ever transmitted.
3. Routes
GET /msp/1/hello (no authentication)
{ protocol: "MSP/1", version, host, heartbeat_seconds, fragment_size, lan: { service, port, pin_sha256 } | null, server_time, via: "gateway" | "lan" }
POST /msp/1/pair
Body { code, public_key, name, model, os_version, app_version }, signed with the key being registered (proof of possession).
The code comes from the dashboard: 12 characters (alphabet without I, L, O, U, 0, 1), valid 10 minutes by default, single
use, revocable; only its SHA-256 is stored. Case, spaces and dashes are ignored. QR payload: msp1://pair?h=<host>&c=<code>
(the app only accepts hosts of the MacLustr domain). 10 attempts per address per 10 minutes.
Response { device_id, …hello fields }. 403 invalid_pairing_code for unknown, used, revoked or expired codes.
POST /msp/1/heartbeat
Sent every heartbeat_seconds (30) while the app runs, and whenever iOS grants background time.
{
"state": "active" | "suspended", "mode": "active" | "station" | "background",
"accepting": true, "reason": "", // why not, when false: wifi_only, charging_only, thermal, low_battery, low_power_mode,
// low_data_mode, low_space, quota_full, no_quota, suspended, offline
"capacity": { "total", "free", "reserve", "quota", "used", "fragments", "writable" }, // measured on the device
"device": { "name", "model", "os_version", "app_version" },
"power": { "battery": 0.82 | null, "charging": true, "low_power": false },
"thermal": "nominal" | "fair" | "serious" | "critical", "network": "wifi" | "cellular" | "wired" | "none",
"policy": { "wifi_only", "charging_only", "cellular", "rate_limit_bps" },
"rates": { "rx_bps", "tx_bps" }, "local": { "verify_ok", "verify_fail", "errors", "last_scrub" },
"bench": { … } // optional: last on-device benchmark, sent once
}capacity.quota is the inventory/allocation message: the coordinator never allocates more than the quota, and never more
than writable at a time. Lowering the quota under what is stored makes the coordinator release fragments (delete tasks).
Response { server_time, status, pending_tasks, expected: { fragments, bytes }, drain: {…} | null, …hello fields }.
status is the coordinator's view: active, suspended, draining, drained. When expected.fragments differs from
what the device holds, the device sends its inventory.
POST /msp/1/work
Body { max, wait, active: [task ids still in transfer] }. Long poll: answers at once when work exists, otherwise holds
the request up to wait seconds (≤ 25) and answers as soon as work appears. active extends the leases of running transfers.
Response { tasks: [ { task, op, fragment, size, reason, ticket?, ticket_expires?, nonce? } ], status }.
There are exactly four operations. The device executes nothing else, whatever the coordinator sends.
op |
Device does | Completes with |
|---|---|---|
store |
downloads the fragment (ticket), checks size and SHA-256 = fragment, commits it atomically |
ack with proof |
verify |
re-hashes the fragment it holds | ack with proof, or `ok:false, error: missing |
retrieve |
re-hashes, then uploads the fragment (ticket) |
the upload itself (the coordinator checks the digest) |
delete |
deletes the fragment | ack |
A task is leased for 15 minutes; an expired lease returns to the queue; after 8 leases it is abandoned. Store tasks are
only leased to a node that reported accepting: true; the three others are always served.
POST /msp/1/ack
Body { results: [ { task, ok, proof?, error? } ] }. Proof of possession: hex SHA-256( nonce ‖ fragment bytes ) with
the task's nonce — it cannot be computed without reading the whole fragment, and cannot be replayed because the nonce is
new for each task. The coordinator computes the same value from its stable copy. A wrong proof counts as an integrity
failure: the placement is dropped, the device is told to delete, and the fragment is placed again.
Fragment transfers
Authenticated by a ticket in the URL instead of a signature, because iOS may run a background transfer hours after the
request was created: …/msp/1/fragments/<fragment id>?d=<device>&t=<task>&k=<ticket>. A ticket is
<expiry>.<HMAC-SHA256(ticket key, device|op|fragment|task|expiry)>, valid 24 h, bound to one device, one task, one
fragment and one direction, and dead as soon as the task closes or the device is revoked. What it gives access to is one
opaque encrypted fragment.
- Download
GET—200whole fragment, or206withRange: bytes=N-(resume).ETagis the fragment id. - Upload
PUT— whole fragment, or the rest of an interrupted upload withContent-Range: bytes N-M/TOTAL.HEAD …&op=retrievereturnsMSP-Offset: <bytes already received>.202while incomplete,200 { complete, verified, restored_stable_copy }when the digest matches,422 digest_mismatchotherwise,409+MSP-Offsetwhen the offset is wrong,410 task_closedwhen the fragment is no longer wanted.
The device's rate_limit_bps is applied by the coordinator on both directions.
POST /msp/1/inventory
Body { fragments: [ids held] }. Response { delete: [ids the cluster does not expect here], missing: <count of expected fragments that are absent> }. The device deletes the first list (orphans); the coordinator forgets the placements of the
second and replicates again. Sent after pairing, at launch when the counts differ, after a local corruption, and daily.
POST /msp/1/drain
| Body | Effect |
|---|---|
{ mode: "graceful", remove: false } |
status draining: no new fragment; each fragment is deleted from the device only after its stable copy is confirmed (pulled back with retrieve first if it is missing); ends drained, or removed when remove |
{ mode: "emergency", remove } |
the device already erased everything: placements are dropped at once, redundancy is rebuilt elsewhere |
{ cancel: true } / { rejoin: true } |
back to active from draining / drained |
POST /msp/1/rekey
Body { new_public_key, new_key_signature }, where new_key_signature is the new key's signature over
MSP1-REKEY\n<device id>\n<new_public_key>; the request itself is signed by the current key. The old key stops working
at once. The app rotates its key every 30 days and on demand.
4. Lifecycle
pair ──► active ──► draining ──► drained ──► (rejoin) active
│ └──────────────────► removed
├── suspended (by the cluster) ◄──► active
├── emergency release ──► drained | removed
└── revoked (by the cluster): every request and ticket refusedA device that receives device_revoked, device_removed or unknown_device erases its fragments and its key and returns
to the pairing screen.
5. What the protocol guarantees
- The coordinator cannot make a device do anything but store, prove, return or delete an opaque fragment.
- A fragment is accepted by either side only if its SHA-256 equals its id.
- A captured request cannot be replayed (nonce + timestamp); a captured ticket only yields one ciphertext fragment.
- The device never receives a key able to decrypt what it stores.
- Redundancy on mobile nodes is in addition to the stable copy: the scheduler only places fragments whose stable copy is healthy, and a drain never deletes a fragment whose stable copy is not confirmed.