webrtc_dtls/flight/mod.rs
1pub(crate) mod flight0;
2pub(crate) mod flight1;
3pub(crate) mod flight2;
4pub(crate) mod flight3;
5pub(crate) mod flight4;
6pub(crate) mod flight5;
7pub(crate) mod flight6;
8
9use std::fmt;
10
11use async_trait::async_trait;
12use tokio::sync::mpsc;
13
14use crate::alert::*;
15use crate::error::Error;
16use crate::handshake::handshake_cache::*;
17use crate::handshaker::*;
18use crate::record_layer::*;
19use crate::state::*;
20
21/*
22 DTLS messages are grouped into a series of message flights, according
23 to the diagrams below. Although each Flight of messages may consist
24 of a number of messages, they should be viewed as monolithic for the
25 purpose of timeout and retransmission.
26 https://tools.ietf.org/html/rfc4347#section-4.2.4
27 Client Server
28 ------ ------
29 Waiting Flight 0
30
31 ClientHello --------> Flight 1
32
33 <------- HelloVerifyRequest Flight 2
34
35 ClientHello --------> Flight 3
36
37 ServerHello \
38 Certificate* \
39 ServerKeyExchange* Flight 4
40 CertificateRequest* /
41 <-------- ServerHelloDone /
42
43 Certificate* \
44 ClientKeyExchange \
45 CertificateVerify* Flight 5
46 [ChangeCipherSpec] /
47 Finished --------> /
48
49 [ChangeCipherSpec] \ Flight 6
50 <-------- Finished /
51
52*/
53
54#[derive(Clone, Debug)]
55pub(crate) struct Packet {
56 pub(crate) record: RecordLayer,
57 pub(crate) should_encrypt: bool,
58 pub(crate) reset_local_sequence_number: bool,
59}
60
61#[async_trait]
62pub(crate) trait Flight: fmt::Display + fmt::Debug {
63 fn is_last_send_flight(&self) -> bool {
64 false
65 }
66 fn is_last_recv_flight(&self) -> bool {
67 false
68 }
69 fn has_retransmit(&self) -> bool {
70 true
71 }
72
73 async fn parse(
74 &self,
75 tx: &mut mpsc::Sender<mpsc::Sender<()>>,
76 state: &mut State,
77 cache: &HandshakeCache,
78 cfg: &HandshakeConfig,
79 ) -> Result<Box<dyn Flight + Send + Sync>, (Option<Alert>, Option<Error>)>;
80
81 async fn generate(
82 &self,
83 state: &mut State,
84 cache: &HandshakeCache,
85 cfg: &HandshakeConfig,
86 ) -> Result<Vec<Packet>, (Option<Alert>, Option<Error>)>;
87}