3.1 KiB
3.1 KiB
OTP Dynamic Partitioning & Rebalancing Protocol Plan
1. Core Design Principles
- Strictly One
.stateFile Per Pad (<chksum>.state):- Every app/device maintains a single
<chksum>.statefile alongside<chksum>.pad. - No
.split.statefiles or device names/IDs are ever created.
- Every app/device maintains a single
- All Splits Emit a Pure-OTP Grant Message (
OTP-GRANT-V1):- Onboarding a brand-new device and rebalancing space to an existing device are the exact same operation (
split). - When
splitruns, the donor device cuts its remaining unused[offset, end_offset)in half atmid(aligned to 256-byte chunks), updates its own<chksum>.state(end_offset=midandpeer_extent=mid:old_end) first (fsync), and outputs a 256-byte ASCII-armored Pure-OTP message (OTP-GRANT-V1) encrypted at offsetmid. - Because the
OTP-GRANT-V1message is encrypted atmid(256 bytes), the recipient's usable partition starts atmid + 256(Grant-Start: mid + 256), guaranteeing even the 256 bytes used to encrypt the grant itself are never reused!
- Onboarding a brand-new device and rebalancing space to an existing device are the exact same operation (
- Nameless, Byte-Range Partition Tracking (
peer_extent=start:end):- Partitions are identified purely by their byte ranges
start:end. - When a donor splits off
[mid, old_end), it recordspeer_extent=mid+256:old_endin its<chksum>.statefile. - Whenever any app decrypts a regular OTP message at
Pad-Offset: Pof lengthL(P + L), ifPfalls within a knownpeer_extent=start:end(start <= P < end), the app automatically updates thatpeer_extentto(P + L):end! - Thus, simply by exchanging normal OTP messages, an app passively sees how much space its peer partitions have left.
- Partitions are identified purely by their byte ranges
2. Single .state File Format
offset=10485760
end_offset=40000000
next_extent=95000000:120000000
peer_extent=40000256:65000000
peer_extent=70002048:95000000
offset: Current write cursor for this app's active partition.end_offset: Exclusive upper bound of this app's active partition (defaults topad_sizeif omitted in legacy.statefiles).next_extent: Zero or morestart:endextents queued for this app (from receivedOTP-GRANT-V1messages). Automatically popped intooffset/end_offsetwhen the active partition runs out.peer_extent: Zero or morestart:endextents known to belong to other apps/devices. Automatically advanced when decrypting messages whosePad-Offsetfalls inside[start, end).
3. Pure-OTP Grant Message Flow
sequenceDiagram
participant AppA as App 1 - Donor
participant AppB as App 2 - Recipient
Note over AppA: Owns [offset, end_offset)
AppA->>AppA: mid = align_256((offset + end_offset) / 2)
AppA->>AppA: grant_start = mid + 256, grant_end = old_end
AppA->>AppA: Save end_offset=mid & peer_extent=grant_start:grant_end to .state FIRST
AppA->>AppA: Encrypt OTP-GRANT-V1(grant_start, grant_end) using 256B at mid
AppA->>AppB: Send standard -----BEGIN OTP MESSAGE----- block
AppB->>AppB: Decrypt message at mid -> parse OTP-GRANT-V1
AppB->>AppB: Update single <chksum>.state with [grant_start, grant_end)