From 5e37ef82266b396921e1e45f1ec89603e22ec369 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 5 Dec 2022 23:58:10 +0100 Subject: [PATCH] style(net): use pin_project on eceis stream (#338) --- Cargo.lock | 1 + crates/net/ecies/Cargo.toml | 1 + crates/net/ecies/src/stream.rs | 14 +++++++------- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c450331f..19bf04abc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3211,6 +3211,7 @@ dependencies = [ "hex", "hex-literal", "hmac", + "pin-project", "proptest", "rand 0.8.5", "reth-primitives", diff --git a/crates/net/ecies/Cargo.toml b/crates/net/ecies/Cargo.toml index bbf14c2f1..0df0e2627 100644 --- a/crates/net/ecies/Cargo.toml +++ b/crates/net/ecies/Cargo.toml @@ -15,6 +15,7 @@ thiserror = "1.0.37" tokio = { version = "1.21.2", features = ["full"] } tokio-stream = "0.1.11" tokio-util = { version = "0.7.4", features = ["codec"] } +pin-project = "1.0" educe = "0.4.19" hex = "0.4.3" diff --git a/crates/net/ecies/src/stream.rs b/crates/net/ecies/src/stream.rs index 21a3cdadf..f4d31ee74 100644 --- a/crates/net/ecies/src/stream.rs +++ b/crates/net/ecies/src/stream.rs @@ -23,7 +23,9 @@ use tracing::{debug, instrument, trace}; /// `ECIES` stream over TCP exchanging raw bytes #[derive(Debug)] +#[pin_project::pin_project] pub struct ECIESStream { + #[pin] stream: Framed, remote_id: PeerId, } @@ -110,7 +112,7 @@ where type Item = Result; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - match ready!(Pin::new(&mut self.get_mut().stream).poll_next(cx)) { + match ready!(self.project().stream.poll_next(cx)) { Some(Ok(IngressECIESValue::Message(body))) => Poll::Ready(Some(Ok(body))), Some(other) => Poll::Ready(Some(Err(io::Error::new( io::ErrorKind::Other, @@ -128,22 +130,20 @@ where type Error = io::Error; fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.get_mut().stream).poll_ready(cx) + self.project().stream.poll_ready(cx) } fn start_send(self: Pin<&mut Self>, item: Bytes) -> Result<(), Self::Error> { - let this = self.get_mut(); - Pin::new(&mut this.stream).start_send(EgressECIESValue::Message(item))?; - + self.project().stream.start_send(EgressECIESValue::Message(item))?; Ok(()) } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.get_mut().stream).poll_flush(cx) + self.project().stream.poll_flush(cx) } fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.get_mut().stream).poll_close(cx) + self.project().stream.poll_close(cx) } }