diff options
author | Sunil Nimmagadda <sunil@nimmagadda.net> | 2024-11-26 21:59:19 +0530 |
---|---|---|
committer | Sunil Nimmagadda <sunil@nimmagadda.net> | 2024-11-26 21:59:19 +0530 |
commit | 474e2a394638b8bf0dddc43ad8e808bd8c04d8a1 (patch) | |
tree | ea9bdf3d3c36725139dbc94b47e49e335c1db188 /src/main.rs | |
parent | 8d2b197f70657d1c5b6ef6910cef18caadf80358 (diff) |
Skeletal state machine, wip.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/src/main.rs b/src/main.rs index f7eba0b..bc1e6a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,28 +1,48 @@ -// #[derive(Debug)] -// enum VRRPv2State { -// Initialize, -// Backup, -// Master, -// } - -// struct StateMachine { -// state: VRRPv2State, -// } - -// impl StateMachine { -// fn new() -> Self { -// StateMachine { -// state: VRRPv2State::Initialize, -// } -// } -// fn transit_to(&mut self, new_state: VRRPv2State) { -// std::println!("vvrpd: {:?} -> {:?}", self.state, new_state); -// self.state = new_state; -// } -// } +use socket2::{Domain, Protocol, Socket, Type}; + +struct Init; +struct Master; +struct Backup; + +impl Init { + fn new() -> Init { + Init {} + } +} + +trait VRRPv2StateMachine { + fn next(&self) -> impl VRRPv2StateMachine; +} + +impl VRRPv2StateMachine for Init { + fn next(&self) -> impl VRRPv2StateMachine { + Master {} + } +} + +impl VRRPv2StateMachine for Master { + fn next(&self) -> impl VRRPv2StateMachine { + Backup {} + } +} + +impl VRRPv2StateMachine for Backup { + fn next(&self) -> impl VRRPv2StateMachine { + Init {} + } +} + +fn run() { + let sm = Init::new(); + loop { + let _ = sm.next(); + } +} fn main() { - // let mut sm = StateMachine::new(); - // sm.transit_to(VRRPv2State::Master); - // sm.transit_to(VRRPv2State::Backup); + let res = Socket::new(Domain::IPV4, Type::RAW, Some(Protocol::from(112))); + let Ok(_sock) = res else { + eprintln!("Socket::new(): {}", res.err().unwrap()); + std::process::exit(1); + }; } |