Skip to main content

antenna_protocol/handshake/
strategy.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{HandshakeInput, HandshakeOutput, HandshakeState, Host, Joiner};
4use anyhow::Result;
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7pub enum HandshakeStrategy {
8    Host,
9    Joiner,
10}
11
12pub enum StrategyFSM {
13    Host(Host),
14    Joiner(Joiner),
15}
16
17impl StrategyFSM {
18    pub fn state(&self) -> &HandshakeState {
19        match self {
20            Self::Host(host) => host.state(),
21            Self::Joiner(joiner) => joiner.state(),
22        }
23    }
24
25    pub fn process(&mut self, input: HandshakeInput) -> Result<Option<HandshakeOutput>> {
26        match self {
27            Self::Host(host) => host.process(input),
28            Self::Joiner(joiner) => joiner.process(input),
29        }
30    }
31}