Skip to main content

gbp_core/
control.rs

1//! GBP control plane opcode registry.
2
3/// Control plane opcode. Width: u16.
4#[repr(u16)]
5#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
6pub enum ControlOpcode {
7    /// Coordinator announces an upcoming epoch change.
8    PrepareTransition = 0x0001,
9    /// Member acknowledges that it is ready to apply the commit.
10    ReadyForTransition = 0x0002,
11    /// Coordinator: apply the new epoch.
12    ExecuteTransition = 0x0003,
13    /// Coordinator: abort the pending transition.
14    AbortTransition = 0x0004,
15    /// Request a digest of the current group state.
16    GroupStateDigestRequest = 0x0005,
17    /// Response to a [`GroupStateDigestRequest`](Self::GroupStateDigestRequest).
18    GroupStateDigestResponse = 0x0006,
19    /// Report an invalid MLS commit.
20    ReportInvalidCommit = 0x0007,
21    /// Capability advertisement (interoperability profile).
22    CapabilitiesAdvertise = 0x0008,
23    /// Positive acknowledgement.
24    Ack = 0x0009,
25    /// Negative acknowledgement carrying an `ErrorObject`.
26    Nack = 0x000A,
27}
28
29impl ControlOpcode {
30    /// Stable human-readable name suitable for logs and dumps.
31    pub fn name(self) -> &'static str {
32        use ControlOpcode::*;
33        match self {
34            PrepareTransition => "PREPARE_TRANSITION",
35            ReadyForTransition => "READY_FOR_TRANSITION",
36            ExecuteTransition => "EXECUTE_TRANSITION",
37            AbortTransition => "ABORT_TRANSITION",
38            GroupStateDigestRequest => "GROUP_STATE_DIGEST_REQUEST",
39            GroupStateDigestResponse => "GROUP_STATE_DIGEST_RESPONSE",
40            ReportInvalidCommit => "REPORT_INVALID_COMMIT",
41            CapabilitiesAdvertise => "CAPABILITIES_ADVERTISE",
42            Ack => "ACK",
43            Nack => "NACK",
44        }
45    }
46}
47
48impl TryFrom<u16> for ControlOpcode {
49    type Error = u16;
50    fn try_from(v: u16) -> Result<Self, u16> {
51        use ControlOpcode::*;
52        Ok(match v {
53            0x0001 => PrepareTransition,
54            0x0002 => ReadyForTransition,
55            0x0003 => ExecuteTransition,
56            0x0004 => AbortTransition,
57            0x0005 => GroupStateDigestRequest,
58            0x0006 => GroupStateDigestResponse,
59            0x0007 => ReportInvalidCommit,
60            0x0008 => CapabilitiesAdvertise,
61            0x0009 => Ack,
62            0x000A => Nack,
63            other => return Err(other),
64        })
65    }
66}