feat(shares): reply to browse requests with a SharedFileListResponse (code 5)

GetShareFileList (peer code 4) previously replied with a malformed message (a
server SharedFolders stats message over a peer connection). It now emits
ShareListRequested, and the client builds a real SharedFileListResponse
(code 5) from its shares grouped by directory. Adds a std-only code-5
encoder/decoder (build_shared_file_list / parse_shared_file_list) with a
roundtrip test, and Shares::directories() to group files. The decoder is the
foundation for the Browse feature.
This commit is contained in:
michel
2026-07-19 18:51:55 +02:00
parent 54d7d8f8a3
commit f3b24f34c0
6 changed files with 177 additions and 4 deletions
+20
View File
@@ -128,6 +128,26 @@ impl Shares {
&self.files
}
/// Files grouped by their virtual directory (everything before the final
/// backslash), as `(directory, [(basename, size)])`. Used to build a
/// SharedFileListResponse.
#[must_use]
pub fn directories(&self) -> Vec<(String, Vec<(String, u64)>)> {
let mut by_dir: std::collections::BTreeMap<String, Vec<(String, u64)>> =
std::collections::BTreeMap::new();
for file in &self.files {
let (dir, base) = file
.virtual_path
.rsplit_once('\\')
.unwrap_or(("", file.virtual_path.as_str()));
by_dir
.entry(dir.to_string())
.or_default()
.push((base.to_string(), file.size));
}
by_dir.into_iter().collect()
}
#[must_use]
pub const fn file_count(&self) -> u32 {
self.files.len() as u32