mesh_node/local_node/
protocol.rs1use bitfield_struct::bitfield;
7use zerocopy::FromBytes;
8use zerocopy::Immutable;
9use zerocopy::IntoBytes;
10use zerocopy::KnownLayout;
11
12#[repr(C)]
13#[derive(Copy, Clone, IntoBytes, Immutable, KnownLayout, FromBytes)]
14pub struct Uuid([u8; 16]);
15
16impl Uuid {
17 pub const ZERO: Self = Self([0; 16]);
18
19 pub fn is_zero(&self) -> bool {
20 self.0 == [0; 16]
21 }
22}
23
24impl From<crate::common::Uuid> for Uuid {
25 fn from(value: crate::common::Uuid) -> Self {
26 Self(value.0)
27 }
28}
29
30impl From<Uuid> for crate::common::Uuid {
31 fn from(value: Uuid) -> Self {
32 Self(value.0)
33 }
34}
35
36#[repr(C)]
37#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
38pub struct Event {
39 pub port_id: Uuid,
40 pub event_type: EventType,
41 pub flags: EventFlags,
42 pub reserved: [u8; 6],
43 pub seq: u64,
44 pub resource_count: u32,
45 pub message_size: u32,
46}
47
48open_enum::open_enum! {
49 #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
50 pub enum EventType: u8 {
51 MESSAGE = 1,
52 CHANGE_PEER = 3,
53 ACKNOWLEDGE_CHANGE_PEER = 4,
54 ACKNOWLEDGE_PORT = 5,
55 FAIL_PORT = 6,
56 }
57}
58
59#[bitfield(u8)]
60#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
61pub struct EventFlags {
62 pub message: bool,
64 pub close: bool,
66 #[bits(6)]
67 _reserved: u8,
68}
69
70#[repr(C)]
71#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
72pub struct ChangePeerData {
73 pub node: Uuid,
74 pub port: Uuid,
75 pub seq_delta: u64,
76 pub reserved: u64,
77}
78
79#[repr(C)]
80#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
81pub struct FailPortData {
82 pub node: Uuid,
83}
84
85#[repr(C)]
86#[derive(Copy, Clone, IntoBytes, Immutable, KnownLayout, FromBytes)]
87pub struct ResourceData {
88 pub id: Uuid,
90 pub next_local_seq: u64,
91 pub reserved: u64,
92 pub old_node: Uuid,
93 pub old_port: Uuid,
94 pub peer_node: Uuid,
96 pub peer_port: Uuid,
98}