|
1 | 1 | use serde::{Deserialize, Serialize}; |
2 | 2 | use serde_with::{serde_as, DisplayFromStr}; |
3 | 3 |
|
| 4 | +use crate::types::FederationId; |
| 5 | + |
4 | 6 | use super::Payload; |
5 | 7 |
|
6 | 8 | #[serde_as] |
7 | 9 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
8 | 10 | #[serde(rename_all = "camelCase")] |
| 11 | +/// Sent by clients to the server to keep the WebSocket connection alive. |
| 12 | +/// |
| 13 | +/// ## Reference |
| 14 | +/// |
| 15 | +/// See sections [3.2.3.8](https://docs.polyphony.chat/Protocol%20Specifications/core/#3238-heartbeat-and-heartbeat-ack-events) |
| 16 | +/// or [3.2.2](https://docs.polyphony.chat/Protocol%20Specifications/core/#322-heartbeats) of the |
| 17 | +/// polyproto specification. |
9 | 18 | pub struct Heartbeat { |
10 | 19 | #[serde_as(as = "DisplayFromStr")] |
| 20 | + /// The lowest received sequence number. |
11 | 21 | pub from: u64, |
12 | 22 | #[serde_as(as = "DisplayFromStr")] |
| 23 | + /// The highest received sequence number. |
13 | 24 | pub to: u64, |
14 | 25 | #[serde_as(as = "Vec<DisplayFromStr>")] |
15 | 26 | #[serde(skip_serializing_if = "Vec::is_empty")] |
16 | 27 | #[serde(default)] |
| 28 | + /// Sequence numbers in range `> from` and `< to`, which were not received by the client. |
17 | 29 | pub except: Vec<u64>, |
18 | 30 | } |
19 | 31 |
|
20 | 32 | #[serde_as] |
21 | 33 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
22 | 34 | #[serde(rename_all = "camelCase")] |
| 35 | +/// Sent by the server upon establishing a WebSocket connection. |
| 36 | +/// |
| 37 | +/// ## Reference |
| 38 | +/// |
| 39 | +/// See section [3.2.3.1](https://docs.polyphony.chat/Protocol%20Specifications/core/#3231-hello-event) |
| 40 | +/// of the polyproto specification. |
23 | 41 | pub struct Hello { |
| 42 | + /// Heartbeat interval, in milliseconds |
24 | 43 | #[serde_as(as = "DisplayFromStr")] |
25 | 44 | pub heartbeat_interval: u32, |
| 45 | + #[serde(default)] |
26 | 46 | #[serde(skip_serializing_if = "Option::is_none")] |
| 47 | + /// Whether there is an unfinished migration which can be resumed. |
| 48 | + /// |
| 49 | + /// ## Warning |
| 50 | + /// |
| 51 | + /// Read [security information regarding this object](https://docs.polyphony.chat/Protocol%20Specifications/core/#:~:text=of%20the%20migration.-,danger,-User-operated%20clients) |
| 52 | + /// before working with it. |
27 | 53 | pub active_migration: Option<ActiveMigration>, |
28 | 54 | } |
29 | 55 |
|
30 | 56 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
31 | 57 | #[serde(rename_all = "camelCase")] |
| 58 | +/// Supplementary information about an unfinished, resumeable migration process. |
32 | 59 | pub struct ActiveMigration { |
33 | | - pub from: String, |
34 | | - pub to: String, |
| 60 | + /// Migration source; Federation ID |
| 61 | + pub from: FederationId, |
| 62 | + /// Migration target; Federation ID |
| 63 | + pub to: FederationId, |
35 | 64 | } |
36 | 65 |
|
37 | 66 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
38 | 67 | #[serde(rename_all = "camelCase")] |
| 68 | +/// Identifying information about the client, namely a session token. |
39 | 69 | pub struct Identify { |
| 70 | + /// Session token. |
40 | 71 | pub token: String, |
41 | 72 | } |
42 | 73 |
|
43 | 74 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
44 | 75 | #[serde(rename_all = "camelCase")] |
| 76 | +/// Information about a new session that has logged in on the server. |
| 77 | +/// |
| 78 | +/// ## Reference |
| 79 | +/// |
| 80 | +/// See chapters [3.2.3.4](https://docs.polyphony.chat/Protocol%20Specifications/core/#3234-new-session-event) |
| 81 | +/// and [4.3](https://docs.polyphony.chat/Protocol%20Specifications/core/#43-protection-against-misuse-by-malicious-home-servers) |
| 82 | +/// of the polyproto specification. |
45 | 83 | pub struct NewSession { |
| 84 | + /// PEM encoded certificate of the new session |
46 | 85 | pub cert: String, |
47 | 86 | } |
48 | 87 |
|
49 | 88 | #[serde_as] |
50 | 89 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
51 | 90 | #[serde(rename_all = "camelCase")] |
| 91 | +/// Information from a server informing clients about the fact that an actor certificate has been |
| 92 | +/// prematurely revoked. |
| 93 | +// TODO this seems useless. should likely be an updated certificate instead. |
52 | 94 | pub struct ActorCertificateInvalidation { |
53 | | - #[serde_as(as = "DisplayFromStr")] |
54 | | - pub serial: u64, |
55 | | - #[serde_as(as = "DisplayFromStr")] |
56 | | - pub invalid_since: u64, |
57 | | - pub signature: String, |
| 95 | + #[serde(flatten)] |
| 96 | + pub certificate: CachedIdCert, |
58 | 97 | } |
59 | 98 |
|
60 | 99 | #[serde_as] |
|
0 commit comments