From bc2d1f65a03c42e80509b59bed1b44d8ee38d88d Mon Sep 17 00:00:00 2001 From: Moepchi Date: Fri, 23 Oct 2026 19:47:15 +0000 Subject: [PATCH] Tag file transfer errors with channel + path; feature-gate new gateway messages Connector transfer errors stay type "error" (old clients unchanged) but now carry cid/path, so the transfer window marks the right transfer as failed. setWhisperPolicy/setTransferLimit are only sent to gateways that announce whisperPolicy/transferLimit, so older gateways don't log "Unknown message type". Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- connector/src/main.rs | 49 ++++++++++++++++++++++++++--------- gateway/src/index.ts | 2 +- gateway/src/ts3/connection.ts | 4 +-- web/src/App.tsx | 23 ++++++++-------- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/connector/src/main.rs b/connector/src/main.rs index 2b4a999..55e4224 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -334,6 +334,9 @@ enum Event { Reconnected, #[serde(rename = "error")] Error { message: String }, + /// An "error" that belongs to one file transfer, so the frontend can mark the right one. + #[serde(rename = "error")] + TransferError { message: String, cid: u64, path: String }, /// A "switch" to a password-protected channel was rejected because no (or /// the wrong) password was supplied. The frontend should prompt for a /// password and retry with it rather than showing a generic error. @@ -2252,7 +2255,11 @@ async fn run(args: Args) -> Result<()> { Ok(handle) => { pending_downloads.insert(handle.0, (cid, path.to_string())); } - Err(e) => emit(&Event::Error { message: format!("Download failed: {e}") }), + Err(e) => emit(&Event::TransferError { + message: format!("Download failed: {e}"), + cid, + path: path.to_string(), + }), }, Err(_) => emit(&Event::Error { message: format!("Invalid channel id: {cid_str}") }), } @@ -2271,7 +2278,11 @@ async fn run(args: Args) -> Result<()> { Ok(handle) => { pending_uploads.insert(handle.0, (cid, path.to_string(), bytes)); } - Err(e) => emit(&Event::Error { message: format!("Upload failed: {e}") }), + Err(e) => emit(&Event::TransferError { + message: format!("Upload failed: {e}"), + cid, + path: path.to_string(), + }), } } _ => emit(&Event::Error { message: "Invalid ftupload args".into() }), @@ -2283,11 +2294,20 @@ async fn run(args: Args) -> Result<()> { Ok(handle) => { pending_uploads.insert(handle.0, (cid, path, bytes)); } - Err(e) => emit(&Event::Error { message: format!("Upload failed: {e}") }), + Err(e) => emit(&Event::TransferError { message: format!("Upload failed: {e}"), cid, path }), } } Ok(None) => {} - Err(message) => emit(&Event::Error { message }), + Err(message) => { + // Same field order as take_upload_chunk: cid, offset, total, path, data. + let fields: Vec<&str> = rest.splitn(5, '\t').collect(); + match (fields[0].trim().parse::(), fields.get(3)) { + (Ok(cid), Some(path)) => { + emit(&Event::TransferError { message, cid, path: path.to_string() }) + } + _ => emit(&Event::Error { message }), + } + } } } else if l == "permissionlist" { if pending_permission_list { @@ -3105,8 +3125,10 @@ async fn run(args: Args) -> Result<()> { }; tokio::spawn(async move { if announced_size > limit { - emit(&Event::Error { + emit(&Event::TransferError { message: format!("Download refused: {path} is larger than {} KiB", limit >> 10), + cid, + path, }); return; } @@ -3131,12 +3153,14 @@ async fn run(args: Args) -> Result<()> { } }; if let Err(e) = read { - emit(&Event::Error { message: format!("Download failed: {e}") }); + emit(&Event::TransferError { message: format!("Download failed: {e}"), cid, path }); return; } if offset + filled as u64 > limit { - emit(&Event::Error { + emit(&Event::TransferError { message: format!("Download aborted: {path} is larger than {} KiB", limit >> 10), + cid, + path, }); return; } @@ -3161,7 +3185,7 @@ async fn run(args: Args) -> Result<()> { for piece in slice.chunks(TRANSFER_CHUNK_BYTES) { let started = std::time::Instant::now(); if let Err(e) = stream.write_all(piece).await { - emit(&Event::Error { message: format!("Upload failed: {e}") }); + emit(&Event::TransferError { message: format!("Upload failed: {e}"), cid, path }); return; } ft_pace(&FT_LIMIT_UP, piece.len(), started).await; @@ -3171,10 +3195,11 @@ async fn run(args: Args) -> Result<()> { } } Some(Ok(StreamItem::FiletransferFailed(handle, e))) => { - let was_pending = pending_downloads.remove(&handle.0).is_some() - || pending_uploads.remove(&handle.0).is_some(); - if was_pending { - emit(&Event::Error { message: format!("File transfer failed: {e}") }); + let failed = pending_downloads + .remove(&handle.0) + .or_else(|| pending_uploads.remove(&handle.0).map(|(cid, path, _)| (cid, path))); + if let Some((cid, path)) = failed { + emit(&Event::TransferError { message: format!("File transfer failed: {e}"), cid, path }); } } Some(Ok(StreamItem::DisconnectedTemporarily(reason))) => { diff --git a/gateway/src/index.ts b/gateway/src/index.ts index 87bc53c..2a46985 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -122,7 +122,7 @@ const WEB_DIST = process.env.WEB_DIST ?? path.resolve(__dirname, "../../web/dist const SERVE_STATIC = process.env.WEB_STATIC !== "0"; // Sent to every browser in the "hello" message on socket open; see there. -const GATEWAY_FEATURES = ["clientVolume", "keepalive", "chunkedUpload"]; +const GATEWAY_FEATURES = ["clientVolume", "keepalive", "chunkedUpload", "whisperPolicy", "transferLimit"]; // Optional TURN relay for screen streams, also handed out in "hello". With // TURN_SECRET (coturn's use-auth-secret) every socket gets its own credential, diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index 85f06d4..f3528de 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -157,7 +157,7 @@ export type Ts3ConnectionEvent = | { type: "disconnected"; reason: string } | { type: "reconnecting"; reason: string } | { type: "reconnected" } - | { type: "error"; message: string } + | { type: "error"; message: string; cid?: number; path?: string } | { type: "channelPasswordRequired"; channelId: number } | ({ type: "serverLog" } & ServerLogEntry) | { @@ -368,7 +368,7 @@ export class Ts3Connection { | { type: "disconnected"; reason: string } | { type: "reconnecting"; reason: string } | { type: "reconnected" } - | { type: "error"; message: string } + | { type: "error"; message: string; cid?: number; path?: string } | { type: "channelPasswordRequired"; channel_id: number } | ({ type: "serverLog" } & ServerLogEntry) | { diff --git a/web/src/App.tsx b/web/src/App.tsx index ca5e4f2..42b537c 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -9038,13 +9038,13 @@ function AppInner() { } case "error": { logClient("error", "Connection", data.message); - // ponytail: connector errors carry no transfer id, so the oldest running - // transfer of that kind takes the blame. Add an id when that misfires. - const msg = String(data.message); - const kind = /^download/i.test(msg) ? "down" : /^upload/i.test(msg) ? "up" : /^file transfer/i.test(msg) ? "any" : null; - const failed = - kind && transfersRef.current.find((x) => x.status === "running" && (kind === "any" || x.dir === kind)); - if (failed) finishTransfer(failed, false); + // Transfer errors carry the transfer's channel + path. + if (typeof data.path === "string") { + const failed = transfersRef.current.find( + (x) => x.status === "running" && x.cid === data.cid && x.path === data.path + ); + if (failed) finishTransfer(failed, false); + } if (hasConnectedRef.current) { appendLog({ text: data.message, kind: "error" }); } else { @@ -9883,7 +9883,8 @@ function AppInner() { const sentWhisperPolicyRef = useRef<{ socket: WebSocket | DemoSocket | null; payload: string }>({ socket: null, payload: "" }); useEffect(() => { const socket = socketRef.current; - if (!connected || !socket) return; + // Older gateways answer unknown messages with an error line. + if (!connected || !socket || !gatewayFeatures.has("whisperPolicy")) return; const block = whisperSettings.mode !== "allow"; const exceptionMode = block ? "allow" : "block"; const exceptions = @@ -9898,7 +9899,7 @@ function AppInner() { if (sent.socket === socket && sent.payload === payload) return; socket.send(payload); sentWhisperPolicyRef.current = { socket, payload }; - }, [connected, clients, contacts, whisperSettings.mode]); + }, [connected, clients, contacts, whisperSettings.mode, gatewayFeatures]); // "Clients in Whisper Verlauf löschen nach": drop old incoming entries. useEffect(() => { @@ -11100,7 +11101,7 @@ function AppInner() { }); useEffect(() => { const socket = socketRef.current; - if (!connected || !socket) return; + if (!connected || !socket || !gatewayFeatures.has("transferLimit")) return; const payload = JSON.stringify({ type: "setTransferLimit", up: downloadSettings.uploadLimit * 1024, @@ -11110,7 +11111,7 @@ function AppInner() { if (sent.socket === socket && sent.payload === payload) return; socket.send(payload); sentTransferLimitRef.current = { socket, payload }; - }, [connected, activeSessionId, downloadSettings.uploadLimit, downloadSettings.downloadLimit]); + }, [connected, activeSessionId, gatewayFeatures, downloadSettings.uploadLimit, downloadSettings.downloadLimit]); const handleFileBrowserDownload = async (entry: FileListEntry) => { if (!fileBrowserTarget) return;