fix(peer): forward UploadFailed to the download store
The code 46 handler parsed the filename and only logged it, so a queued download whose peer reported an upload failure never received DownloadStatus::Failed and hung until the caller's own timeout. The handler now sends PeerMessage::UploadFailed through the dispatcher and the actor stamps the peer's username on it before forwarding ClientOperation::UploadFailed into the existing failure path. The variant's username field stays for API compatibility; the wire message cannot name anyone but the connected peer, so the actor supplies it. Fixes #30
This commit is contained in:
@@ -10,8 +10,31 @@ impl MessageHandler<PeerMessage> for UploadFailedHandler {
|
||||
fn get_code(&self) -> u8 {
|
||||
46
|
||||
}
|
||||
fn handle(&self, message: &mut Message, _sender: Sender<PeerMessage>) {
|
||||
fn handle(&self, message: &mut Message, sender: Sender<PeerMessage>) {
|
||||
let filename = message.read_string();
|
||||
info!("Upload failed for {}", filename);
|
||||
let _ = sender.send(PeerMessage::UploadFailed(String::new(), filename));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::message::framed;
|
||||
|
||||
#[test]
|
||||
fn the_failed_filename_is_forwarded() {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let mut message = framed(|m| {
|
||||
m.write_string("@@share\\gone.mp3");
|
||||
});
|
||||
|
||||
UploadFailedHandler.handle(&mut message, tx);
|
||||
match rx.try_recv() {
|
||||
Ok(PeerMessage::UploadFailed(_, filename)) => {
|
||||
assert_eq!(filename, "@@share\\gone.mp3");
|
||||
}
|
||||
other => panic!("unexpected: {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user