mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
style(net): use pin_project on eceis stream (#338)
This commit is contained in:
committed by
Georgios Konstantopoulos
parent
0b8d50127c
commit
5e37ef8226
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3211,6 +3211,7 @@ dependencies = [
|
|||||||
"hex",
|
"hex",
|
||||||
"hex-literal",
|
"hex-literal",
|
||||||
"hmac",
|
"hmac",
|
||||||
|
"pin-project",
|
||||||
"proptest",
|
"proptest",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"reth-primitives",
|
"reth-primitives",
|
||||||
|
|||||||
@ -15,6 +15,7 @@ thiserror = "1.0.37"
|
|||||||
tokio = { version = "1.21.2", features = ["full"] }
|
tokio = { version = "1.21.2", features = ["full"] }
|
||||||
tokio-stream = "0.1.11"
|
tokio-stream = "0.1.11"
|
||||||
tokio-util = { version = "0.7.4", features = ["codec"] }
|
tokio-util = { version = "0.7.4", features = ["codec"] }
|
||||||
|
pin-project = "1.0"
|
||||||
|
|
||||||
educe = "0.4.19"
|
educe = "0.4.19"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
|
|||||||
@ -23,7 +23,9 @@ use tracing::{debug, instrument, trace};
|
|||||||
|
|
||||||
/// `ECIES` stream over TCP exchanging raw bytes
|
/// `ECIES` stream over TCP exchanging raw bytes
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[pin_project::pin_project]
|
||||||
pub struct ECIESStream<Io> {
|
pub struct ECIESStream<Io> {
|
||||||
|
#[pin]
|
||||||
stream: Framed<Io, ECIESCodec>,
|
stream: Framed<Io, ECIESCodec>,
|
||||||
remote_id: PeerId,
|
remote_id: PeerId,
|
||||||
}
|
}
|
||||||
@ -110,7 +112,7 @@ where
|
|||||||
type Item = Result<bytes::BytesMut, io::Error>;
|
type Item = Result<bytes::BytesMut, io::Error>;
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
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(Ok(IngressECIESValue::Message(body))) => Poll::Ready(Some(Ok(body))),
|
||||||
Some(other) => Poll::Ready(Some(Err(io::Error::new(
|
Some(other) => Poll::Ready(Some(Err(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
@ -128,22 +130,20 @@ where
|
|||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
|
||||||
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
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> {
|
fn start_send(self: Pin<&mut Self>, item: Bytes) -> Result<(), Self::Error> {
|
||||||
let this = self.get_mut();
|
self.project().stream.start_send(EgressECIESValue::Message(item))?;
|
||||||
Pin::new(&mut this.stream).start_send(EgressECIESValue::Message(item))?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
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<Result<(), Self::Error>> {
|
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
Pin::new(&mut self.get_mut().stream).poll_close(cx)
|
self.project().stream.poll_close(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user