fix(lib): cap a search reply at 150 files

A broad query against a big share was answered with every match, so one
search could hand the whole index to a stranger, and every such search
did it again. A reply now carries at most MAX_SEARCH_REPLY_FILES (150,
Nicotine+'s default), which is more sources than any searcher scrolls
through.
This commit is contained in:
Michel de Graaf
2026-09-07 14:44:16 +02:00
parent ef563fbb7e
commit b9d3d7fcd5
3 changed files with 99 additions and 38 deletions
+1
View File
@@ -146,6 +146,7 @@ fn build_search_response(
}
let entries: Vec<FileEntry> = matches
.iter()
.take(crate::types::MAX_SEARCH_REPLY_FILES)
.map(|f| FileEntry {
name: &f.virtual_path,
size: f.size,
+7
View File
@@ -84,6 +84,13 @@ pub const MAX_SEARCH_RESPONSES: usize = 500;
/// matching collections cannot blow past the response cap.
pub const MAX_SEARCH_FILES: usize = 10_000;
/// Files one reply to a peer's search carries at most.
///
/// A broad query against a big share would otherwise hand the whole index
/// to whoever typed it, on every such search that arrives. Nicotine+ sends
/// 150 by default; a searcher with more sources than that has plenty.
pub const MAX_SEARCH_REPLY_FILES: usize = 150;
impl Search {
/// Store one peer's response, unless this search already holds enough.
///