1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use session::SessionState;

/// Used to report the state of the connection at a given time.
#[derive(Eq)]
#[derive(PartialEq)]
#[derive(Clone)]
#[derive(Debug)]
pub enum ConnectionState {
    /// No packet has been sent or received yet.
    Uninitialized,
    /// We are in the handshake phase. `wrap_message` will drop messages.
    Handshake,
    /// We are in the normal phase.
    Established,
}

impl<'a> From<&'a SessionState> for ConnectionState {
    fn from(ss: &SessionState) -> ConnectionState {
        match *ss {
            SessionState::UninitializedUnknownPeer |
            SessionState::UninitializedKnownPeer => {
                ConnectionState::Uninitialized
            },
            SessionState::SentHello { .. } |
            SessionState::WaitingKey { .. } |
            SessionState::ReceivedHello { .. } |
            SessionState::SentKey { .. } => {
                ConnectionState::Handshake
            },
            SessionState::Established { .. } => {
                ConnectionState::Established
            },
        }
    }
}