Fail a transfer the TeamSpeak link is given, not its connection
ts::voice::Voice::command answered LinkCmd::Download, Upload and CancelTransfer with anyhow::bail!, which ends the whole TeamSpeak connection: chat, voice, presence and the stream task with it. SessionLink copies the bytes of a transfer itself and never sends them, but a command that does arrive is that transfer's failure, not the connection's. Download and Upload answer their report with TransferState::Failed and the connection goes on; CancelTransfer has no report and nothing to cancel, so it is logged at debug. A unit test gives an unconnected Voice the three commands: each returns Ok, the two reports see Failed, nothing is pending. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
76a884a779
commit
f1df88690b
1 file changed
+47
-4
@@ -36,7 +36,7 @@ use voelin_stream::{ClientState, Request, StreamNotification};
|
||||
|
||||
use super::book::presence_from_book;
|
||||
use super::ts_link::{ConnectOptions, Watches};
|
||||
use crate::files::{self, FileEntry, RequestId};
|
||||
use crate::files::{self, FileEntry, RequestId, TransferState};
|
||||
use crate::link::{BoxDuplex, BoxRead, LinkCmd, LinkCtx, LinkEvent, Remote};
|
||||
use crate::offline::{OfflineMessage, OfflineMessageInfo};
|
||||
use crate::stream::{StreamCmd, StreamHandle, StreamInput};
|
||||
@@ -1004,10 +1004,13 @@ impl Voice {
|
||||
}
|
||||
// SessionLink copies the bytes itself, over the connections OpenRead and
|
||||
// OpenWrite open (`docs/session-seam.md` section 8): this link is never
|
||||
// given a transfer to run.
|
||||
LinkCmd::Download { .. } | LinkCmd::Upload { .. } | LinkCmd::CancelTransfer(_) => {
|
||||
anyhow::bail!("this link does not run transfers itself");
|
||||
// given a transfer to run. One that is given anyway fails (its report
|
||||
// is the answer), and the connection, which other things ride on, goes
|
||||
// on; there is nothing to cancel.
|
||||
LinkCmd::Download { report, .. } | LinkCmd::Upload { report, .. } => {
|
||||
report(TransferState::Failed("this link does not run transfers itself".into()));
|
||||
}
|
||||
LinkCmd::CancelTransfer(id) => debug!(transfer = id, "no transfer runs on this link"),
|
||||
LinkCmd::DeleteFiles { request, channel, password, paths } => {
|
||||
let cpw = encode_password(password.as_deref());
|
||||
let mut parts = paths.iter().map(|p| c2s::OutDeleteFilePart {
|
||||
@@ -1570,6 +1573,46 @@ mod account_tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// `SessionLink` copies the bytes of a transfer itself. A transfer command
|
||||
/// that reaches this link anyway fails that transfer with its report, and
|
||||
/// not the connection, which every other request of the session rides on.
|
||||
#[tokio::test]
|
||||
async fn a_transfer_command_fails_the_transfer_and_not_the_connection() {
|
||||
let server = tokio::net::UdpSocket::bind("127.0.0.1:0").await.unwrap();
|
||||
let mut voice = unconnected(&server, account_data(&[1; 33]));
|
||||
let states = Arc::new(std::sync::Mutex::new(Vec::new()));
|
||||
let report: crate::files::Report = {
|
||||
let states = states.clone();
|
||||
Arc::new(move |state| states.lock().unwrap().push(state))
|
||||
};
|
||||
let file = || Remote { channel: 1, password: None, path: "/a".into() };
|
||||
let kept = "the connection goes on";
|
||||
voice
|
||||
.command(LinkCmd::Download {
|
||||
transfer: Some(1),
|
||||
file: file(),
|
||||
sink: crate::files::Sink::Memory,
|
||||
report: report.clone(),
|
||||
})
|
||||
.expect(kept);
|
||||
voice
|
||||
.command(LinkCmd::Upload {
|
||||
transfer: None,
|
||||
file: file(),
|
||||
from: "a".into(),
|
||||
overwrite: false,
|
||||
resume: false,
|
||||
report,
|
||||
})
|
||||
.expect(kept);
|
||||
// Nothing runs, so there is nothing to cancel and nobody to tell.
|
||||
voice.command(LinkCmd::CancelTransfer(1)).expect(kept);
|
||||
let failed = TransferState::Failed("this link does not run transfers itself".into());
|
||||
assert_eq!(*states.lock().unwrap(), [failed.clone(), failed]);
|
||||
assert!(voice.jobs.is_empty() && voice.pending.is_empty());
|
||||
timeout(Duration::from_millis(100), shutdown_connection(voice.con)).await.unwrap().unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn shutdown_never_polls_a_connecting_connection() {
|
||||
let server = tokio::net::UdpSocket::bind("127.0.0.1:0").await.unwrap();
|
||||
|
||||
Reference in new issue
Block a user