Dispatch read one byte of the code, so a code with a non-zero high byte was handled as its low byte. Message::get_message_code now reads the whole little-endian uint32 and handlers register by u32. PeerInit and PierceFirewall, the only frames with a one-byte code, get their own accessor for the listener's first frame.
28 lines
813 B
Rust
28 lines
813 B
Rust
use crate::trace;
|
|
use std::sync::mpsc::Sender;
|
|
|
|
use crate::{
|
|
actor::server_actor::ServerMessage, message::Message,
|
|
message::handlers::MessageHandler,
|
|
};
|
|
|
|
pub struct FileSearchHandler;
|
|
|
|
impl MessageHandler<ServerMessage> for FileSearchHandler {
|
|
fn get_code(&self) -> u32 {
|
|
26
|
|
}
|
|
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();
|
|
trace!("[server] search from {}: {} ({})", username, query, token);
|
|
let _ = sender.send(ServerMessage::FileSearchRequest {
|
|
username,
|
|
token,
|
|
query,
|
|
});
|
|
}
|
|
}
|