antenna_protocol/handshake/
mod.rs1mod host;
2mod input;
3mod joiner;
4mod output;
5mod signaling;
6mod state;
7mod strategy;
8mod test;
9
10use anyhow::Result;
11use serde::{Deserialize, Serialize};
12
13pub use host::Host;
14pub use input::HandshakeInput;
15pub use joiner::Joiner;
16pub use output::HandshakeOutput;
17pub use signaling::SignalingPayload;
18pub use state::HandshakeState;
19pub use strategy::{HandshakeStrategy, StrategyFSM};
20
21use crate::PeerID;
22
23pub struct HandshakeFSM {
29 strategy: HandshakeStrategy,
30 fsm: StrategyFSM,
31}
32
33impl HandshakeFSM {
34 pub fn new(strategy: HandshakeStrategy) -> Self {
35 match strategy {
36 HandshakeStrategy::Host => Self::host(),
37 HandshakeStrategy::Joiner => Self::joiner(),
38 }
39 }
40
41 pub fn host() -> Self {
43 Self {
44 strategy: HandshakeStrategy::Host,
45 fsm: StrategyFSM::Host(Host::new()),
46 }
47 }
48
49 pub fn joiner() -> Self {
50 Self {
51 strategy: HandshakeStrategy::Joiner,
52 fsm: StrategyFSM::Joiner(Joiner::new()),
53 }
54 }
55
56 pub fn state(&self) -> &HandshakeState {
58 self.fsm.state()
59 }
60
61 pub fn strategy(&self) -> &HandshakeStrategy {
62 &self.strategy
63 }
64
65 pub fn process(&mut self, input: HandshakeInput) -> Result<Option<HandshakeOutput>> {
67 self.fsm.process(input)
68 }
69}
70
71#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
73pub enum HandshakeMode {
74 Bootstrap,
77
78 Relay(PeerID),
81}