use crate::{Connection, ConnectionReader, Pea2Pea};
use tokio::sync::{mpsc, oneshot};
use std::io;
pub trait Handshaking: Pea2Pea {
fn enable_handshaking(&self);
}
pub type HandshakeObjects = (
ConnectionReader,
Connection,
oneshot::Sender<io::Result<(ConnectionReader, Connection)>>,
);
pub struct HandshakeHandler(mpsc::Sender<HandshakeObjects>);
impl HandshakeHandler {
pub async fn send(&self, handshake_objects: HandshakeObjects) {
if self.0.send(handshake_objects).await.is_err() {
panic!("the handshake handling task is down or its Receiver is closed")
}
}
}
impl From<mpsc::Sender<HandshakeObjects>> for HandshakeHandler {
fn from(sender: mpsc::Sender<HandshakeObjects>) -> Self {
Self(sender)
}
}