hopr_lib/
state.rs

1use crate::exports::transport::HoprTransportProcess;
2
3/// An enum representing the current state of the HOPR node
4#[atomic_enum::atomic_enum]
5#[derive(PartialEq, Eq)]
6pub enum HoprState {
7    Uninitialized = 0,
8    Initializing = 1,
9    Indexing = 2,
10    Starting = 3,
11    Running = 4,
12}
13
14impl std::fmt::Display for HoprState {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        write!(f, "{self:?}")
17    }
18}
19
20/// Enum differentiator for loop component futures.
21///
22/// Used to differentiate the type of the future that exits the loop premateruly
23/// by tagging it as an enum.
24#[derive(Debug, Clone, PartialEq, Eq, Hash, strum::Display)]
25pub enum HoprLibProcesses {
26    #[strum(to_string = "transport: {0}")]
27    Transport(HoprTransportProcess),
28    #[cfg(feature = "session-server")]
29    #[strum(to_string = "session server providing the exit node session stream functionality")]
30    SessionServer,
31    #[strum(to_string = "tick wake up the strategies to perform an action")]
32    StrategyTick,
33    #[strum(to_string = "initial indexing operation into the DB")]
34    Indexing,
35    #[strum(to_string = "processing of indexed operations in internal components")]
36    IndexReflection,
37    #[strum(to_string = "on-chain transaction queue component for outgoing transactions")]
38    OutgoingOnchainActionQueue,
39    #[strum(to_string = "flush operation of outgoing ticket indices to the DB")]
40    TicketIndexFlush,
41    #[strum(to_string = "on received ack ticket trigger")]
42    OnReceivedAcknowledgement,
43}
44
45impl HoprLibProcesses {
46    /// Identifies whether a loop is allowed to finish or should
47    /// run indefinitely.
48    pub fn can_finish(&self) -> bool {
49        matches!(self, HoprLibProcesses::Indexing)
50    }
51}
52
53impl From<HoprTransportProcess> for HoprLibProcesses {
54    fn from(value: HoprTransportProcess) -> Self {
55        HoprLibProcesses::Transport(value)
56    }
57}