mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 02:05:30 +00:00
udp scrape improvements (#43)
* udp_protocol: forbid full scrapes * udp: improve PendingScrapeResponseMap logging * udp: PendingScrapeResponseMap: store less data, improve logging * udp: PendingScrapeResponseMap: log if replacing entry on insert * udp: PendingScrapeResponseMap: use remote addr in key * Run cargo fmt * README: update copyright end year * udp: move scrape request splitting logic into PendingScrapeResponseMap * udp: add quickcheck test test_pending_scrape_response_map * udp protocol: fix failing test_scrape_request_convert_identity
This commit is contained in:
parent
e5a1461613
commit
700dd68d2c
3 changed files with 217 additions and 59 deletions
|
|
@ -271,18 +271,26 @@ impl Request {
|
|||
let position = cursor.position() as usize;
|
||||
let inner = cursor.into_inner();
|
||||
|
||||
let info_hashes = (&inner[position..])
|
||||
let info_hashes: Vec<InfoHash> = (&inner[position..])
|
||||
.chunks_exact(20)
|
||||
.take(max_scrape_torrents as usize)
|
||||
.map(|chunk| InfoHash(chunk.try_into().unwrap()))
|
||||
.collect();
|
||||
|
||||
Ok((ScrapeRequest {
|
||||
connection_id: ConnectionId(connection_id),
|
||||
transaction_id: TransactionId(transaction_id),
|
||||
info_hashes,
|
||||
})
|
||||
.into())
|
||||
if info_hashes.is_empty() {
|
||||
Err(RequestParseError::sendable_text(
|
||||
"Full scrapes are not allowed",
|
||||
connection_id,
|
||||
transaction_id,
|
||||
))
|
||||
} else {
|
||||
Ok((ScrapeRequest {
|
||||
connection_id: ConnectionId(connection_id),
|
||||
transaction_id: TransactionId(transaction_id),
|
||||
info_hashes,
|
||||
})
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
_ => Err(RequestParseError::sendable_text(
|
||||
|
|
@ -296,6 +304,7 @@ impl Request {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use quickcheck::TestResult;
|
||||
use quickcheck_macros::quickcheck;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -378,7 +387,11 @@ mod tests {
|
|||
}
|
||||
|
||||
#[quickcheck]
|
||||
fn test_scrape_request_convert_identity(request: ScrapeRequest) -> bool {
|
||||
same_after_conversion(request.into())
|
||||
fn test_scrape_request_convert_identity(request: ScrapeRequest) -> TestResult {
|
||||
if request.info_hashes.is_empty() {
|
||||
return TestResult::discard();
|
||||
}
|
||||
|
||||
TestResult::from_bool(same_after_conversion(request.into()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue