use crate::ConnectionId;
use super::{ConnectionOwner, PeerInfo, connection_info::ConnectionInfo};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConnectionEvent {
HandshakeCompleted {
connection_id: ConnectionId,
owner: ConnectionOwner,
peer_info: PeerInfo,
},
ConnectionFailed {
connection_id: ConnectionId,
owner: ConnectionOwner,
error: String,
},
StateChanged {
connection_id: ConnectionId,
owner: ConnectionOwner,
new_state: ConnectionInfo,
},
}
impl ConnectionEvent {
pub fn connection_id(&self) -> ConnectionId {
match self {
ConnectionEvent::HandshakeCompleted { connection_id, .. } => *connection_id,
ConnectionEvent::ConnectionFailed { connection_id, .. } => *connection_id,
ConnectionEvent::StateChanged { connection_id, .. } => *connection_id,
}
}
pub fn owner(&self) -> ConnectionOwner {
match self {
ConnectionEvent::HandshakeCompleted { owner, .. } => *owner,
ConnectionEvent::ConnectionFailed { owner, .. } => *owner,
ConnectionEvent::StateChanged { owner, .. } => *owner,
}
}
}