deaddrop_core/protocol/
messages.rs1use crate::chunk::Manifest;
2use crate::{CapabilityDoc, ChunkId, DropEnvelope, ObjectId, PublicIdentity};
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6#[serde(tag = "type", rename_all = "snake_case")]
7#[allow(clippy::large_enum_variant)]
8pub enum Message {
9 ClientHello {
10 protocol: u16,
11 identity: PublicIdentity,
12 #[serde(with = "serde_bytes")]
13 eph_pk: [u8; 32],
14 nonce: u64,
15 caps: CapabilityDoc,
16 #[serde(with = "serde_bytes")]
17 identity_proof: [u8; 64],
18 },
19 ServerHello {
20 protocol: u16,
21 identity: PublicIdentity,
22 #[serde(with = "serde_bytes")]
23 eph_pk: [u8; 32],
24 nonce: u64,
25 caps: CapabilityDoc,
26 #[serde(with = "serde_bytes")]
27 transcript_sig: [u8; 64],
28 },
29 InventorySorted {
30 object_ids: Vec<ObjectId>,
31 },
32 InventoryBloom {
33 n: u32,
34 k: u8,
35 #[serde(with = "serde_bytes")]
36 bits: Vec<u8>,
37 },
38 Want {
39 object_ids: Vec<ObjectId>,
40 chunks: Vec<ChunkWant>,
41 },
42 Envelope {
43 envelope: DropEnvelope,
44 manifest: Manifest,
45 },
46 ChunkData {
47 object_id: ObjectId,
48 chunk_id: ChunkId,
49 index: u32,
50 #[serde(with = "serde_bytes")]
51 data: Vec<u8>,
52 },
53 Have {
54 object_id: ObjectId,
55 chunks_present: Vec<u32>,
56 },
57 ReceiptOffer {
58 object_id: ObjectId,
59 },
60 Error {
61 code: String,
62 message: String,
63 },
64 Done,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct ChunkWant {
69 pub object_id: ObjectId,
70 pub indices: Vec<u32>,
71}
72
73impl Message {
74 pub fn name(&self) -> &'static str {
75 match self {
76 Self::ClientHello { .. } => "client_hello",
77 Self::ServerHello { .. } => "server_hello",
78 Self::InventorySorted { .. } => "inventory_sorted",
79 Self::InventoryBloom { .. } => "inventory_bloom",
80 Self::Want { .. } => "want",
81 Self::Envelope { .. } => "envelope",
82 Self::ChunkData { .. } => "chunk_data",
83 Self::Have { .. } => "have",
84 Self::ReceiptOffer { .. } => "receipt_offer",
85 Self::Error { .. } => "error",
86 Self::Done => "done",
87 }
88 }
89}