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 {
24 strategy: HandshakeStrategy,
25 fsm: StrategyFSM,
26}
27
28impl HandshakeFSM {
29 pub fn new(strategy: HandshakeStrategy) -> Self {
30 match strategy {
31 HandshakeStrategy::Host => Self::host(),
32 HandshakeStrategy::Joiner => Self::joiner(),
33 }
34 }
35
36 pub fn host() -> Self {
38 Self {
39 strategy: HandshakeStrategy::Host,
40 fsm: StrategyFSM::Host(Host::new()),
41 }
42 }
43
44 pub fn joiner() -> Self {
45 Self {
46 strategy: HandshakeStrategy::Joiner,
47 fsm: StrategyFSM::Joiner(Joiner::new()),
48 }
49 }
50
51 pub fn state(&self) -> &HandshakeState {
53 self.fsm.state()
54 }
55
56 pub fn strategy(&self) -> &HandshakeStrategy {
57 &self.strategy
58 }
59
60 pub fn process(&mut self, input: HandshakeInput) -> Result<Option<HandshakeOutput>> {
62 self.fsm.process(input)
63 }
64}
65
66#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
67pub enum HandshakeMode {
68 Bootstrap,
70
71 Relay(PeerID),
73}