You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
//! Socket handlers
|
|
use super::*;
|
|
|
|
use std::net::{
|
|
SocketAddr,
|
|
};
|
|
use tokio::io::{
|
|
AsyncWrite,
|
|
AsyncRead
|
|
};
|
|
use tokio::task::JoinHandle;
|
|
use futures::Future;
|
|
use cancel::*;
|
|
|
|
|
|
/// Details of a newly accepted raw socket peer.
|
|
///
|
|
/// This connected will have been "accepted", but not yet trusted
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
pub struct RawSockPeerAccepted
|
|
{
|
|
/// Address of socket.
|
|
pub addr: SocketAddr,
|
|
/// Trust this peer from the start? This should almost always be false.
|
|
pub auto_trust: bool,
|
|
}
|
|
|
|
/// Details of a connected, set-up raw socket connection.
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct RawSockPeerTrusted
|
|
{
|
|
/// The socket's details
|
|
pub sock_details: RawSockPeerAccepted,
|
|
|
|
///
|
|
pub cap_allow: cap::RawSockCapabilities,
|
|
}
|
|
|
|
/// Handles a **newly connected** raw socket.
|
|
///
|
|
/// This will handle setting up socket peer encryption and validation.
|
|
pub fn handle_new_socket_with_shutdown<R, W, C: cancel::CancelFuture + 'static + Send>(sock_details: RawSockPeerAccepted, tx: W, rx: R, shutdown: C) -> JoinHandle<eyre::Result<()>>
|
|
where R: AsyncRead + Unpin + Send + 'static,
|
|
W: AsyncWrite + Unpin + Send + 'static
|
|
{
|
|
tokio::spawn(async move {
|
|
match {
|
|
with_cancel!(async move {
|
|
|
|
Ok(())
|
|
}, shutdown)
|
|
} {
|
|
Ok(v) => v,
|
|
Err(x) => Err(eyre::Report::from(x)),
|
|
}
|
|
})
|
|
}
|