From d722e9a4481ac5b41e3ef45cb015f10bac4bbbbf Mon Sep 17 00:00:00 2001 From: Shahak Shama Date: Tue, 16 Jul 2024 16:24:51 +0300 Subject: [PATCH] feat(network): add implementation from SqmrClientPayload to SqmrClientPayloadForNetwork --- .../src/network_manager/mod.rs | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/papyrus_network/src/network_manager/mod.rs b/crates/papyrus_network/src/network_manager/mod.rs index d754195e63..b058d9c339 100644 --- a/crates/papyrus_network/src/network_manager/mod.rs +++ b/crates/papyrus_network/src/network_manager/mod.rs @@ -613,7 +613,7 @@ pub fn dummy_report_sender() -> ReportSender { Box::new(|| {}) } -pub type GenericSender = Box>; +pub type GenericSender = Box + Unpin>; // Box implements Stream only if S: Stream + Unpin pub type GenericReceiver = Box + Unpin>; @@ -631,7 +631,14 @@ pub struct SqmrServerPayload> { #[allow(dead_code)] struct SqmrClientPayloadForNetwork { pub query: Bytes, - pub report_receiver: BoxFuture<'static, SessionId>, + pub report_receiver: oneshot::Receiver<()>, + pub responses_sender: GenericSender, +} + +#[allow(dead_code)] +struct SqmrServerPayloadForNetwork { + pub query: Bytes, + pub report_sender: oneshot::Sender<()>, pub responses_sender: GenericSender, } @@ -645,11 +652,18 @@ pub type SqmrServerReceiver = GenericReceiver; -impl> From> - for SqmrClientPayloadForNetwork +impl From> for SqmrClientPayloadForNetwork +where + Bytes: From, + Response: TryFrom + 'static, + >::Error: 'static, { - fn from(_query: SqmrClientPayload) -> Self { - unimplemented!() + fn from(payload: SqmrClientPayload) -> Self { + let SqmrClientPayload { query, report_receiver, responses_sender } = payload; + let query = Bytes::from(query); + let responses_sender = + Box::new(responses_sender.with(|response| ready(Ok(Response::try_from(response))))); + Self { query, report_receiver, responses_sender } } } @@ -661,13 +675,6 @@ impl> From } } -#[allow(dead_code)] -struct SqmrServerPayloadForNetwork { - pub query: Bytes, - pub report_sender: oneshot::Sender<()>, - pub responses_sender: GenericSender, -} - // TODO(shahak): Create a custom struct if Box dyn becomes an overhead. // TODO(eitan): Change type to oneshot::Sender<()> pub type ReportSender = Box;