mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_http: glommio: call wait_for_response in handle_request
This commit is contained in:
parent
edec526d41
commit
f767e8a6fa
1 changed files with 11 additions and 18 deletions
|
|
@ -207,12 +207,7 @@ impl Connection {
|
||||||
loop {
|
loop {
|
||||||
let response = match self.read_request().await? {
|
let response = match self.read_request().await? {
|
||||||
Either::Left(response) => Response::Failure(response),
|
Either::Left(response) => Response::Failure(response),
|
||||||
Either::Right(request) => match self.handle_request(request).await? {
|
Either::Right(request) => 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?
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.write_response(&response).await?;
|
self.write_response(&response).await?;
|
||||||
|
|
@ -281,13 +276,11 @@ impl Connection {
|
||||||
|
|
||||||
/// Take a request and:
|
/// Take a request and:
|
||||||
/// - Return error response if request is not allowed
|
/// - 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 an announce request, send it to request workers an await a
|
||||||
/// - If it is a scrape requests, split it up and pass on parts to
|
/// response
|
||||||
/// relevant request workers, and return Either::Right(Some(PendingScrapeResponse)).
|
/// - If it is a scrape requests, split it up, pass on the parts to
|
||||||
async fn handle_request(
|
/// relevant request workers and await a response
|
||||||
&self,
|
async fn handle_request(&self, request: Request) -> anyhow::Result<Response> {
|
||||||
request: Request,
|
|
||||||
) -> anyhow::Result<Either<FailureResponse, Option<PendingScrapeResponse>>> {
|
|
||||||
match request {
|
match request {
|
||||||
Request::Announce(request) => {
|
Request::Announce(request) => {
|
||||||
let info_hash = request.info_hash;
|
let info_hash = request.info_hash;
|
||||||
|
|
@ -312,13 +305,13 @@ impl Connection {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Ok(Either::Right(None))
|
self.wait_for_response(None).await
|
||||||
} else {
|
} else {
|
||||||
let response = FailureResponse {
|
let response = Response::Failure(FailureResponse {
|
||||||
failure_reason: "Info hash not allowed".into(),
|
failure_reason: "Info hash not allowed".into(),
|
||||||
};
|
});
|
||||||
|
|
||||||
Ok(Either::Left(response))
|
Ok(response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Request::Scrape(ScrapeRequest { info_hashes }) => {
|
Request::Scrape(ScrapeRequest { info_hashes }) => {
|
||||||
|
|
@ -354,7 +347,7 @@ impl Connection {
|
||||||
stats: Default::default(),
|
stats: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Either::Right(Some(pending_scrape_response)))
|
self.wait_for_response(Some(pending_scrape_response)).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue