feat(shares): reply to distributed searches with our matching files

Wire the incoming server FileSearch (code 26): the handler now forwards
ServerMessage::FileSearchRequest -> ClientOperation::IncomingSearch instead of
just logging. The client matches the query against its shares and, if anything
matches, sends a FileSearchResponse to the searcher — connecting to them first
(GetPeerAddress -> outbound P) and flushing the response on PeerConnected when
not already connected. GetPeerAddressResponse now also caches peer addresses
for the serve path. Adds build_search_response + a unit test.
This commit is contained in:
michel
2026-07-19 18:39:05 +02:00
parent bcfe56e74f
commit 9b6e533bed
3 changed files with 231 additions and 8 deletions
@@ -1,4 +1,4 @@
use crate::{debug, info};
use crate::trace;
use std::sync::mpsc::Sender;
use crate::{
@@ -12,14 +12,16 @@ impl MessageHandler<ServerMessage> for FileSearchHandler {
fn get_code(&self) -> u8 {
26
}
fn handle(&self, message: &mut Message, _sender: Sender<ServerMessage>) {
debug!("Handling file search message");
fn handle(&self, message: &mut Message, sender: Sender<ServerMessage>) {
// The server distributes another user's search to us: [user][token][query].
let username = message.read_string();
let token = message.read_int32();
let query = message.read_string();
info!(
"Message search username:{}, token: {}, query: {}",
username, token, query
);
trace!("[server] search from {}: {} ({})", username, query, token);
let _ = sender.send(ServerMessage::FileSearchRequest {
username,
token,
query,
});
}
}