From f767e8a6fa1faca1a84825e7edb35fad7d74e59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Mon, 1 Nov 2021 02:01:48 +0100 Subject: [PATCH] aquatic_http: glommio: call wait_for_response in handle_request --- aquatic_http/src/lib/network.rs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/aquatic_http/src/lib/network.rs b/aquatic_http/src/lib/network.rs index 966495c..d26febe 100644 --- a/aquatic_http/src/lib/network.rs +++ b/aquatic_http/src/lib/network.rs @@ -207,12 +207,7 @@ impl Connection { loop { let response = match self.read_request().await? { Either::Left(response) => Response::Failure(response), - Either::Right(request) => match self.handle_request(request).await? { - Either::Left(response) => Response::Failure(response), - Either::Right(opt_pending_scrape_response) => { - self.wait_for_response(opt_pending_scrape_response).await? - } - }, + Either::Right(request) => self.handle_request(request).await?, }; self.write_response(&response).await?; @@ -281,13 +276,11 @@ impl Connection { /// Take a request and: /// - Return error response if request is not allowed - /// - If it is an announce requests, pass it on to request workers and return Either::Right(None) - /// - If it is a scrape requests, split it up and pass on parts to - /// relevant request workers, and return Either::Right(Some(PendingScrapeResponse)). - async fn handle_request( - &self, - request: Request, - ) -> anyhow::Result>> { + /// - If it is an announce request, send it to request workers an await a + /// response + /// - If it is a scrape requests, split it up, pass on the parts to + /// relevant request workers and await a response + async fn handle_request(&self, request: Request) -> anyhow::Result { match request { Request::Announce(request) => { let info_hash = request.info_hash; @@ -312,13 +305,13 @@ impl Connection { .await .unwrap(); - Ok(Either::Right(None)) + self.wait_for_response(None).await } else { - let response = FailureResponse { + let response = Response::Failure(FailureResponse { failure_reason: "Info hash not allowed".into(), - }; + }); - Ok(Either::Left(response)) + Ok(response) } } Request::Scrape(ScrapeRequest { info_hashes }) => { @@ -354,7 +347,7 @@ impl Connection { stats: Default::default(), }; - Ok(Either::Right(Some(pending_scrape_response))) + self.wait_for_response(Some(pending_scrape_response)).await } } }