mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 09:45:31 +00:00
on invalid requests, return error response; simplify Request type
This commit is contained in:
parent
8cf3644e78
commit
8426e8f3f7
4 changed files with 14 additions and 22 deletions
|
|
@ -90,18 +90,26 @@ pub fn run_event_loop(
|
|||
);
|
||||
|
||||
match request {
|
||||
Request::Connect(r) => {
|
||||
Ok(Request::Connect(r)) => {
|
||||
connect_requests.push((r, src));
|
||||
},
|
||||
Request::Announce(r) => {
|
||||
Ok(Request::Announce(r)) => {
|
||||
announce_requests.push((r, src));
|
||||
},
|
||||
Request::Scrape(r) => {
|
||||
Ok(Request::Scrape(r)) => {
|
||||
scrape_requests.push((r, src));
|
||||
},
|
||||
_ => {
|
||||
// FIXME
|
||||
}
|
||||
Ok(Request::Invalid(r)) => {
|
||||
let response = Response::Error(ErrorResponse {
|
||||
transaction_id: r.transaction_id,
|
||||
message: "Invalid request".to_string(),
|
||||
});
|
||||
|
||||
responses.push((response, src));
|
||||
},
|
||||
Err(err) => {
|
||||
eprintln!("Request parse error: {:?}", err);
|
||||
},
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
|
|
|
|||
|
|
@ -64,18 +64,6 @@ pub fn request_to_bytes(request: &types::Request) -> Vec<u8> {
|
|||
pub fn request_from_bytes(
|
||||
bytes: &[u8],
|
||||
max_scrape_torrents: u8,
|
||||
) -> types::Request {
|
||||
|
||||
match try_request_from_bytes(bytes, max_scrape_torrents){
|
||||
Ok(request) => request,
|
||||
Err(_) => types::Request::Error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn try_request_from_bytes(
|
||||
bytes: &[u8],
|
||||
max_scrape_torrents: u8,
|
||||
) -> Result<types::Request,io::Error> {
|
||||
|
||||
let mut bytes = io::Cursor::new(bytes);
|
||||
|
|
|
|||
|
|
@ -52,8 +52,4 @@ pub enum Request {
|
|||
Announce(AnnounceRequest),
|
||||
Scrape(ScrapeRequest),
|
||||
Invalid(InvalidRequest),
|
||||
|
||||
/// Should ideally only be used when no transaction id can be parsed,
|
||||
/// but is currently also used as a catch-all for non-specific errors
|
||||
Error,
|
||||
}
|
||||
0
scripts/run-server.sh
Normal file → Executable file
0
scripts/run-server.sh
Normal file → Executable file
Loading…
Add table
Add a link
Reference in a new issue