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