aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-common/src/meshbay_common/protocol.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-common/src/meshbay_common/protocol.py')
-rw-r--r--packages/meshbay-common/src/meshbay_common/protocol.py72
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