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/// Which side of the handshake the local peer plays.
7///
8/// In a relay handshake, the side with the smaller [`crate::PeerID`] becomes
9/// `Host`, the larger becomes `Joiner` — both choose independently and
10/// always agree.
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12pub enum HandshakeStrategy {
13    /// Sends the SDP offer first, then accepts the answer.
14    Host,
15    /// Receives the offer, returns an answer, awaits the data channel.
16    Joiner,
17}
18
19pub enum StrategyFSM {
20    Host(Host),
21    Joiner(Joiner),
22}
23
24impl StrategyFSM {
25    pub fn state(&self) -> &HandshakeState {
26        match self {
27            Self::Host(host) => host.state(),
28            Self::Joiner(joiner) => joiner.state(),
29        }
30    }
31
32    pub fn process(&mut self, input: HandshakeInput) -> Result<Option<HandshakeOutput>> {
33        match self {
34            Self::Host(host) => host.process(input),
35            Self::Joiner(joiner) => joiner.process(input),
36        }
37    }
38}