Skip to content

Commit

Permalink
fix wasm32, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Oct 2, 2023
1 parent e542fdd commit 9435a78
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions node/src/exchange/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S, R = ReqRespBehaviour>
Expand Down Expand Up @@ -96,8 +97,6 @@ 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(());
Expand All @@ -109,27 +108,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<u8>) {
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)
Expand All @@ -148,7 +142,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
Expand Down Expand Up @@ -382,7 +376,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);
}
Expand Down

0 comments on commit 9435a78

Please sign in to comment.