fix(lib): give each search its own token

A search token was the first five hex digits of the query's MD5, so two
queries could share one, and a peer's answer to either landed in whichever
search the map handed back first. Tokens now come from a counter, which
no two live searches can share.

The e2e test uses two queries that collide under the old scheme.
This commit is contained in:
Michel de Graaf
2026-09-07 14:52:25 +02:00
parent a99e848eda
commit 0458b24898
3 changed files with 49 additions and 4 deletions
+2 -3
View File
@@ -1,7 +1,7 @@
use super::{
Arc, AtomicBool, Client, DEFAULT_WISHLIST_INTERVAL, Duration, HashMap,
Instant, Ordering, Result, RwLockExt, Search, SearchResult, ServerMessage,
SoulseekRs, info, md5, sleep,
SoulseekRs, info, next_search_token, sleep,
};
impl Client {
@@ -62,8 +62,7 @@ impl Client {
let Some(handle) = &self.server_handle else {
return Err(SoulseekRs::NotConnected);
};
let hash = md5::md5(query);
let token = u32::from_str_radix(&hash[0..5], 16)?;
let token = next_search_token();
self.context.write_safe()?.searches.insert(
query.to_string(),