umsh_node/
app_owned.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3
4use umsh_core::PublicKey;
5
6use crate::{Capabilities, MacCommand, NodeIdentityPayload, NodeRole};
7
8#[derive(Clone, Debug, PartialEq, Eq)]
9pub struct OwnedNodeIdentityPayload {
10    pub timestamp: u32,
11    pub role: NodeRole,
12    pub capabilities: Capabilities,
13    pub name: Option<String>,
14    pub options: Option<Vec<u8>>,
15    pub signature: Option<[u8; 64]>,
16}
17
18impl OwnedNodeIdentityPayload {
19    pub fn as_borrowed(&self) -> NodeIdentityPayload<'_> {
20        NodeIdentityPayload {
21            timestamp: self.timestamp,
22            role: self.role,
23            capabilities: self.capabilities,
24            name: self.name.as_deref(),
25            options: self.options.as_deref(),
26            signature: self.signature.as_ref(),
27        }
28    }
29}
30
31impl From<NodeIdentityPayload<'_>> for OwnedNodeIdentityPayload {
32    fn from(value: NodeIdentityPayload<'_>) -> Self {
33        Self {
34            timestamp: value.timestamp,
35            role: value.role,
36            capabilities: value.capabilities,
37            name: value.name.map(String::from),
38            options: value.options.map(Vec::from),
39            signature: value.signature.copied(),
40        }
41    }
42}
43
44#[derive(Clone, Debug, PartialEq, Eq)]
45pub enum OwnedMacCommand {
46    BeaconRequest {
47        nonce: Option<u32>,
48    },
49    IdentityRequest,
50    SignalReportRequest,
51    SignalReportResponse {
52        rssi: u8,
53        snr: i8,
54    },
55    EchoRequest {
56        data: Vec<u8>,
57    },
58    EchoResponse {
59        data: Vec<u8>,
60    },
61    PfsSessionRequest {
62        ephemeral_key: PublicKey,
63        duration_minutes: u16,
64    },
65    PfsSessionResponse {
66        ephemeral_key: PublicKey,
67        duration_minutes: u16,
68    },
69    EndPfsSession,
70}
71
72impl From<MacCommand<'_>> for OwnedMacCommand {
73    fn from(value: MacCommand<'_>) -> Self {
74        match value {
75            MacCommand::BeaconRequest { nonce } => Self::BeaconRequest { nonce },
76            MacCommand::IdentityRequest => Self::IdentityRequest,
77            MacCommand::SignalReportRequest => Self::SignalReportRequest,
78            MacCommand::SignalReportResponse { rssi, snr } => {
79                Self::SignalReportResponse { rssi, snr }
80            }
81            MacCommand::EchoRequest { data } => Self::EchoRequest {
82                data: Vec::from(data),
83            },
84            MacCommand::EchoResponse { data } => Self::EchoResponse {
85                data: Vec::from(data),
86            },
87            MacCommand::PfsSessionRequest {
88                ephemeral_key,
89                duration_minutes,
90            } => Self::PfsSessionRequest {
91                ephemeral_key,
92                duration_minutes,
93            },
94            MacCommand::PfsSessionResponse {
95                ephemeral_key,
96                duration_minutes,
97            } => Self::PfsSessionResponse {
98                ephemeral_key,
99                duration_minutes,
100            },
101            MacCommand::EndPfsSession => Self::EndPfsSession,
102        }
103    }
104}