fix(lib): advertise real slot, speed and queue figures in search replies

Every reply to a peer's search claimed a free upload slot, no speed and
an empty queue, whatever the sharer was doing, and searchers rank
sources on exactly those fields. A reply now says whether a slot is
free, the bytes per second of the last completed upload, and how many
uploads are waiting.
This commit is contained in:
Michel de Graaf
2026-09-07 15:16:20 +02:00
parent 049deee5a7
commit 352816cc1e
9 changed files with 114 additions and 13 deletions
+10 -2
View File
@@ -150,6 +150,9 @@ fn build_search_response(
own_username: &str,
token: u32,
query: &str,
free_slot: bool,
speed: u32,
queue_length: u32,
) -> Option<crate::message::Message> {
let matches = shares.search(query);
if matches.is_empty() {
@@ -168,8 +171,9 @@ fn build_search_response(
own_username,
token,
&entries,
1,
0,
u8::from(free_slot),
speed,
queue_length,
))
}
@@ -376,6 +380,9 @@ pub struct ClientContext {
upload_seq: u64,
/// How many uploads may be in flight at once.
upload_slots: usize,
/// Bytes per second of the last completed upload, advertised in search
/// replies; zero until one has finished.
last_upload_speed: u32,
/// Queued-upload states that came and went between two polls of
/// [`Client::uploads`]. A caller sampling that snapshot would otherwise
/// never see a peer that queued and was served inside one poll interval,
@@ -458,6 +465,7 @@ impl ClientContext {
upload_queue: Vec::new(),
upload_seq: 0,
upload_slots: DEFAULT_UPLOAD_SLOTS,
last_upload_speed: 0,
upload_events: Vec::new(),
downloads: DownloadStore::new(),
actor_system,