diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-08-09 03:52:58 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-08-09 03:52:58 +0200 |
| commit | 271adc8504aad32075d75d06fd42023877a649ec (patch) | |
| tree | fe8697761d635a5cac7e0693f2e588a38a7968b9 /packages/meshbay-common/src/meshbay_common/protocol.py | |
| download | meshbay-271adc8504aad32075d75d06fd42023877a649ec.tar.gz | |
chore: initialize monorepo structure for MeshBay
3-package layout: meshbay-common (shared crypto/protocol),
meshbay-hub (FastAPI server), meshbay-node (local daemon).
Includes validated POC spikes 1-6 in poc/, architecture drafts
v1/v2 in docs/, and CLAUDE.md project conventions.
All cryptographic primitives extracted from POC into
meshbay_common/crypto.py (GEK wrap/unwrap, chunk key derivation,
keystore encryption, chunk signing).
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-common/src/meshbay_common/protocol.py')
| -rw-r--r-- | packages/meshbay-common/src/meshbay_common/protocol.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/packages/meshbay-common/src/meshbay_common/protocol.py b/packages/meshbay-common/src/meshbay_common/protocol.py new file mode 100644 index 0000000..c3f2b1a --- /dev/null +++ b/packages/meshbay-common/src/meshbay_common/protocol.py @@ -0,0 +1,72 @@ +""" +MeshBay protocol constants and message type definitions. + +MNP (Mesh Node Protocol) — v0.1 +MHP (Mesh Bay Hub Protocol) — v0.1 + +All wire messages are length-prefixed msgpack (4-byte big-endian length header). +Every message carries a "v" field for protocol version. +""" + +from dataclasses import dataclass, field +from typing import Any + +MNP_VERSION = "0.1" +MHP_VERSION = "0.1" + + +# ── MNP message types ───────────────────────────────────────────────────────── + +class MNP: + HANDSHAKE = "handshake" + HANDSHAKE_ACK = "handshake_ack" + INDEX_SYNC = "index_sync" # full Mesh Group Index + INDEX_DELTA = "index_delta" # incremental update + FILE_REQUEST = "file_req" # request chunk(s) + FILE_CHUNK = "file_chunk" # encrypted chunk response + STREAM_SEGMENT = "stream_seg" # HLS/DASH segment + CHAT_MESSAGE = "chat_msg" # Double Ratchet message + CHAT_ATTACHMENT = "chat_attach" # attachment metadata + EPHEMERAL_STREAM = "ephemeral_stream" # reserved — mobile live push + + +# ── Index entry ─────────────────────────────────────────────────────────────── + +@dataclass +class IndexEntry: + id: str # blake3 hash of file (hex) + name: str # filename + path: str # path relative to shared directory + size: int # bytes + type: str # video | audio | image | document | archive | other + added_at: int # unix timestamp + duration: int | None = None # seconds, for media + thumb_hash: str | None = None # blake3 of thumbnail + + +@dataclass +class IndexDelta: + base_version: int + version: int + additions: list[IndexEntry] = field(default_factory=list) + deletions: list[str] = field(default_factory=list) # list of ids + + +# ── Chunk request/response ──────────────────────────────────────────────────── + +@dataclass +class ChunkRequest: + file_id: str # blake3 hash of file (hex) + chunk_index: int + +@dataclass +class ChunkResponse: + chunk_index: int + plaintext_size: int + nonce_b64: str + ct_b64: str + ct_hash_b64: str + pt_hash_b64: str + sig_b64: str + pk_node_b64: str + file_hash_b64: str |