antenna_protocol/state/message.rs
1use serde::{Deserialize, Serialize, de::DeserializeOwned};
2
3use crate::{PeerID, SignalingPayload};
4
5/// Marker trait for application message types carried over the mesh.
6///
7/// Auto-implemented for any `Serialize + DeserializeOwned + Clone` — users
8/// don't implement it manually.
9pub trait UserMsgPayload: Serialize + DeserializeOwned + Clone {}
10
11impl<T> UserMsgPayload for T where T: Serialize + DeserializeOwned + Clone {}
12
13/// Inner payload of a relay-signaling frame between two peers via an intermediary.
14#[derive(Clone, Serialize, Deserialize, Debug)]
15pub enum RelayPayload {
16 /// Invitation to start a relay handshake with the given peer.
17 InitConnect(PeerID),
18 /// Forwarded SDP offer.
19 Offer(SignalingPayload),
20 /// Forwarded SDP answer.
21 Answer(SignalingPayload),
22}
23
24/// Every frame that crosses a data channel.
25///
26/// `User` is the only variant that surfaces to the application; the rest
27/// are protocol-internal and consumed by [`crate::MeshNodeFSM`].
28#[derive(Clone, Serialize, Deserialize, Debug)]
29#[serde(bound(serialize = "Msg: Serialize", deserialize = "Msg: DeserializeOwned"))]
30pub enum MsgPayload<Msg: UserMsgPayload> {
31 /// Application payload sent via `Peer::send` / `Peer::broadcast`.
32 User(Msg),
33 /// "Forward this to `dst`" — sent to a relay intermediary.
34 RelaySignalingTo { dst: PeerID, data: RelayPayload },
35 /// "Here is a frame from `src`" — emitted by a relay intermediary to the destination.
36 RelaySignalingFrom { src: PeerID, data: RelayPayload },
37 /// Graceful-disconnect notice broadcast by a leaving peer.
38 Disconnect,
39}