blob: fbf871a73f67662e8d26661c14f0e7f20ca665fb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
"""
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
CHAT_HISTORY = "chat_hist" # request message history
CHAT_HISTORY_RESPONSE = "chat_hist_resp" # history response with messages
GEK_REQUEST = "gek_req" # browser requests group GEK
GEK_RESPONSE = "gek_resp" # node delivers GEK over secure channel
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
|