From b418670ce83d4ce7eab18911ccd320e1cda45860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Florkiewicz?= Date: Mon, 2 Oct 2023 16:05:18 +0200 Subject: [PATCH] fix wasm32, cleanup --- node/src/exchange/server.rs | 16 ++++------------ node/src/exchange/utils.rs | 3 ++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/node/src/exchange/server.rs b/node/src/exchange/server.rs index f1615290e..d78dbe666 100644 --- a/node/src/exchange/server.rs +++ b/node/src/exchange/server.rs @@ -14,6 +14,7 @@ use tracing::{instrument, trace}; use crate::exchange::utils::{ExtendedHeaderExt, HeaderRequestExt, HeaderResponseExt}; use crate::exchange::{ReqRespBehaviour, ResponseType}; +use crate::executor::spawn; use crate::store::Store; pub(super) struct ExchangeServerHandler @@ -96,11 +97,8 @@ where } pub fn poll(&mut self, _: &mut Context<'_>, sender: &mut R) -> Poll<()> { - println!("."); - while let Ok((channel, response)) = self.rx.try_recv() { sender.send_response(channel, response); - //return Poll::Ready(()); } Poll::Pending @@ -109,27 +107,22 @@ where fn handle_request_current_head(&mut self, channel: R::Channel) { let store = self.store.clone(); let tx = self.tx.clone(); - println!("head"); - let j = tokio::spawn(async move { - println!("inhead"); + spawn(async move { let response = store .get_head() .await .map(|head| head.to_header_response()) .unwrap_or_else(|_| HeaderResponse::not_found()); - println!("got res"); let _ = tx.send((channel, vec![response])); }); - - println!("{j:?}"); } fn handle_request_by_hash(&mut self, channel: R::Channel, hash: Vec) { let store = self.store.clone(); let tx = self.tx.clone(); - tokio::spawn(async move { + spawn(async move { let response = if let Ok(hash) = Hash::from_bytes(Algorithm::Sha256, &hash) { store .get_by_hash(&hash) @@ -148,7 +141,7 @@ where let store = self.store.clone(); let tx = self.tx.clone(); - tokio::spawn(async move { + spawn(async move { let mut responses = vec![]; for i in origin..origin + amount { let response = store @@ -382,7 +375,6 @@ mod tests { type Channel = (); fn send_response(&mut self, _channel: Self::Channel, response: ResponseType) { - println!("sending"); if let Some(sender) = self.0.take() { let _ = sender.send(response); } diff --git a/node/src/exchange/utils.rs b/node/src/exchange/utils.rs index 7c39e0ac4..d13e80ac3 100644 --- a/node/src/exchange/utils.rs +++ b/node/src/exchange/utils.rs @@ -52,6 +52,7 @@ pub(super) trait HeaderResponseExt { fn to_extended_header(&self) -> Result; fn not_found() -> HeaderResponse; + fn invalid() -> HeaderResponse; } @@ -65,13 +66,13 @@ impl HeaderResponseExt for HeaderResponse { } } - // TODO: how forthcoming should we be with errors and description? fn not_found() -> HeaderResponse { HeaderResponse { status_code: StatusCode::NotFound.into(), body: vec![], } } + fn invalid() -> HeaderResponse { HeaderResponse { status_code: StatusCode::Invalid.into(),