Files
soulseek-rs-modded/soulseek-rs-lib/src/dispatcher.rs
T
Michel de Graaf 543e9ee865 fix(peer): wait for the transfer token before the download lookup
The listener looked the download up immediately after the PeerInit(F),
but the 4-byte transfer token routinely arrives in a separate TCP
segment, so every firewalled peer download failed with "Download info
missing". Wait for the token within the handshake deadline and give up
on the connection when it never arrives.

Also quiets the dispatcher's unhandled-message-code log to debug; the
server routinely sends codes the library doesn't implement.

Fixes #41
2026-08-17 09:22:03 +02:00

40 lines
925 B
Rust

use crate::message::{Message, handlers::Handlers};
use std::sync::mpsc::Sender;
use crate::debug;
pub struct MessageDispatcher<Op> {
owner_name: String,
sender: Sender<Op>,
handlers: Handlers<Op>,
}
impl<Op> MessageDispatcher<Op> {
#[must_use]
pub const fn new(
owner_name: String,
sender: Sender<Op>,
handlers: Handlers<Op>,
) -> Self {
Self {
owner_name,
sender,
handlers,
}
}
pub fn dispatch(&self, message: &mut Message) {
let code = message.get_message_code();
if let Some(handler) = self.handlers.get_handler(code) {
message.set_pointer(8);
handler.handle(message, self.sender.clone());
} else {
debug!(
"[{}:dispatcher] No handler found for message code: {code}",
self.owner_name
);
}
}
}