Added `ESock::transfer_state()`: Change the `tx` and `rx` types in a encrypted socket while maintaining its keys and other encryption state.

Fortune for rsh's current commit: Half blessing − 半吉
pipelined-socket-buffering
Avril 3 years ago
parent 30522ec96f
commit 444f3f38dc
Signed by: flanchan
GPG Key ID: 284488987C31F630

11
Cargo.lock generated

@ -23,6 +23,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "atomic_refcell"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "681b971236e0f76b20fcafca0236b8718c9186ee778d67cd78bd5f28fd85427f"
[[package]]
name = "autocfg"
version = "1.0.1"
@ -112,9 +118,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chacha20stream"
version = "2.1.0"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54c8d48b47fa0a89a94b80d32b1b3fc9ffc1a232a5201ff5a2d14ac77bc7561d"
checksum = "87df7ca03a990f2bb57c659b78c8f2fbc48fd2c6ed5ecc764e239a7ad7e9cfa1"
dependencies = [
"base64 0.13.0",
"getrandom 0.2.3",
@ -800,6 +806,7 @@ name = "rsh"
version = "0.1.0"
dependencies = [
"ad-hoc-iter",
"atomic_refcell",
"base64 0.13.0",
"bytes 1.0.1",
"chacha20stream",

@ -7,9 +7,10 @@ edition = "2018"
[dependencies]
ad-hoc-iter = "0.2.3"
atomic_refcell = "0.1.7"
base64 = "0.13.0"
bytes = { version = "1.0.1", features = ["serde"] }
chacha20stream = { version = "2.1.0", features = ["async", "serde"] }
chacha20stream = { version = "2.2.1", features = ["async", "serde"] }
color-eyre = "0.5.11"
cryptohelpers = { version = "1.8.2" , features = ["serialise", "full"] }
futures = "0.3.16"

@ -13,6 +13,8 @@ pub use hex::*;
mod base64;
pub use self::base64::*;
pub mod sync;
/// A maybe-atom that can spill into a vector.
pub type MaybeVec<T> = SmallVec<[T; 1]>;

@ -0,0 +1,2 @@
//! Syncronisation helpers

@ -182,6 +182,29 @@ pub struct ESock<W, R> {
impl<W: AsyncWrite, R: AsyncRead> ESock<W, R>
{
/// Move this `ESock`'s state into another, returning the new `ESock` and the old streams
pub fn transfer_state<Wx, Rx>(self, tx: Wx, rx: Rx) -> (ESock<Wx, Rx>, (W, R))
where Wx: AsyncWrite,
Rx: AsyncRead
{
let ESock { info, state, tx: otx, rx: orx } = self;
let (otx, tx) = {
let (s, c) = otx.into_parts();
(s, AsyncSink::from_parts(tx, c))
};
let (orx, rx) = {
let (s, c) = orx.into_parts();
(s, AsyncSource::from_parts(rx, c))
};
(ESock {
info, state, tx, rx
}, (otx, orx))
}
fn inner(&self) -> (&W, &R)
{
(self.tx.inner(), self.rx.inner())

@ -11,6 +11,9 @@ use std::{
PhantomData,
},
};
use futures::{
Future,
};
use tokio::sync::{
mpsc,
};
@ -27,10 +30,22 @@ pub const DEFAULT_BUFFER_SIZE: usize = 32;
/// Task-based buffered piping to/from encrypted sockets.
pub struct BufferedESock<W, R>
{
bufsz: usize,
_backing: PhantomData<ESock<W, R>>,
}
/// `tx`: ESock-wrapped network output socket.
/// `rx`: Reading half of the user's fake stream
fn bsock_writer<'a, Raw, Fake>(mut tx: ESockWriteHalf<Raw>, mut rx: Fake) -> impl Future<Output = ()> + 'a
where Raw: AsyncWrite + Unpin + 'a,
Fake: AsyncRead + Unpin + 'a,
{
async move {
}
}
impl<W, R> BufferedESock<W, R>
where W: AsyncWrite + Unpin + Send + 'static,
R: AsyncRead + Unpin + Send + 'static

Loading…
Cancel
Save