mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-02 17:32:50 +08:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
d0fc97d921
commit
bc2d1f65a0
4 files changed
+52
-26
No files matched your search
+37
-12
@@ -334,6 +334,9 @@ enum Event {
|
|||||||
Reconnected,
|
Reconnected,
|
||||||
#[serde(rename = "error")]
|
#[serde(rename = "error")]
|
||||||
Error { message: String },
|
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
|
/// A "switch" to a password-protected channel was rejected because no (or
|
||||||
/// the wrong) password was supplied. The frontend should prompt for a
|
/// the wrong) password was supplied. The frontend should prompt for a
|
||||||
/// password and retry with it rather than showing a generic error.
|
/// password and retry with it rather than showing a generic error.
|
||||||
@@ -2252,7 +2255,11 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
Ok(handle) => {
|
Ok(handle) => {
|
||||||
pending_downloads.insert(handle.0, (cid, path.to_string()));
|
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}") }),
|
Err(_) => emit(&Event::Error { message: format!("Invalid channel id: {cid_str}") }),
|
||||||
}
|
}
|
||||||
@@ -2271,7 +2278,11 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
Ok(handle) => {
|
Ok(handle) => {
|
||||||
pending_uploads.insert(handle.0, (cid, path.to_string(), bytes));
|
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() }),
|
_ => emit(&Event::Error { message: "Invalid ftupload args".into() }),
|
||||||
@@ -2283,11 +2294,20 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
Ok(handle) => {
|
Ok(handle) => {
|
||||||
pending_uploads.insert(handle.0, (cid, path, bytes));
|
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) => {}
|
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::<u64>(), fields.get(3)) {
|
||||||
|
(Ok(cid), Some(path)) => {
|
||||||
|
emit(&Event::TransferError { message, cid, path: path.to_string() })
|
||||||
|
}
|
||||||
|
_ => emit(&Event::Error { message }),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if l == "permissionlist" {
|
} else if l == "permissionlist" {
|
||||||
if pending_permission_list {
|
if pending_permission_list {
|
||||||
@@ -3105,8 +3125,10 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
};
|
};
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if announced_size > limit {
|
if announced_size > limit {
|
||||||
emit(&Event::Error {
|
emit(&Event::TransferError {
|
||||||
message: format!("Download refused: {path} is larger than {} KiB", limit >> 10),
|
message: format!("Download refused: {path} is larger than {} KiB", limit >> 10),
|
||||||
|
cid,
|
||||||
|
path,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3131,12 +3153,14 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(e) = read {
|
if let Err(e) = read {
|
||||||
emit(&Event::Error { message: format!("Download failed: {e}") });
|
emit(&Event::TransferError { message: format!("Download failed: {e}"), cid, path });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if offset + filled as u64 > limit {
|
if offset + filled as u64 > limit {
|
||||||
emit(&Event::Error {
|
emit(&Event::TransferError {
|
||||||
message: format!("Download aborted: {path} is larger than {} KiB", limit >> 10),
|
message: format!("Download aborted: {path} is larger than {} KiB", limit >> 10),
|
||||||
|
cid,
|
||||||
|
path,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3161,7 +3185,7 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
for piece in slice.chunks(TRANSFER_CHUNK_BYTES) {
|
for piece in slice.chunks(TRANSFER_CHUNK_BYTES) {
|
||||||
let started = std::time::Instant::now();
|
let started = std::time::Instant::now();
|
||||||
if let Err(e) = stream.write_all(piece).await {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
ft_pace(&FT_LIMIT_UP, piece.len(), started).await;
|
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))) => {
|
Some(Ok(StreamItem::FiletransferFailed(handle, e))) => {
|
||||||
let was_pending = pending_downloads.remove(&handle.0).is_some()
|
let failed = pending_downloads
|
||||||
|| pending_uploads.remove(&handle.0).is_some();
|
.remove(&handle.0)
|
||||||
if was_pending {
|
.or_else(|| pending_uploads.remove(&handle.0).map(|(cid, path, _)| (cid, path)));
|
||||||
emit(&Event::Error { message: format!("File transfer failed: {e}") });
|
if let Some((cid, path)) = failed {
|
||||||
|
emit(&Event::TransferError { message: format!("File transfer failed: {e}"), cid, path });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Ok(StreamItem::DisconnectedTemporarily(reason))) => {
|
Some(Ok(StreamItem::DisconnectedTemporarily(reason))) => {
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ const WEB_DIST = process.env.WEB_DIST ?? path.resolve(__dirname, "../../web/dist
|
|||||||
const SERVE_STATIC = process.env.WEB_STATIC !== "0";
|
const SERVE_STATIC = process.env.WEB_STATIC !== "0";
|
||||||
|
|
||||||
// Sent to every browser in the "hello" message on socket open; see there.
|
// 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
|
// 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,
|
// TURN_SECRET (coturn's use-auth-secret) every socket gets its own credential,
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ export type Ts3ConnectionEvent =
|
|||||||
| { type: "disconnected"; reason: string }
|
| { type: "disconnected"; reason: string }
|
||||||
| { type: "reconnecting"; reason: string }
|
| { type: "reconnecting"; reason: string }
|
||||||
| { type: "reconnected" }
|
| { type: "reconnected" }
|
||||||
| { type: "error"; message: string }
|
| { type: "error"; message: string; cid?: number; path?: string }
|
||||||
| { type: "channelPasswordRequired"; channelId: number }
|
| { type: "channelPasswordRequired"; channelId: number }
|
||||||
| ({ type: "serverLog" } & ServerLogEntry)
|
| ({ type: "serverLog" } & ServerLogEntry)
|
||||||
| {
|
| {
|
||||||
@@ -368,7 +368,7 @@ export class Ts3Connection {
|
|||||||
| { type: "disconnected"; reason: string }
|
| { type: "disconnected"; reason: string }
|
||||||
| { type: "reconnecting"; reason: string }
|
| { type: "reconnecting"; reason: string }
|
||||||
| { type: "reconnected" }
|
| { type: "reconnected" }
|
||||||
| { type: "error"; message: string }
|
| { type: "error"; message: string; cid?: number; path?: string }
|
||||||
| { type: "channelPasswordRequired"; channel_id: number }
|
| { type: "channelPasswordRequired"; channel_id: number }
|
||||||
| ({ type: "serverLog" } & ServerLogEntry)
|
| ({ type: "serverLog" } & ServerLogEntry)
|
||||||
| {
|
| {
|
||||||
|
|||||||
+12
-11
@@ -9038,13 +9038,13 @@ function AppInner() {
|
|||||||
}
|
}
|
||||||
case "error": {
|
case "error": {
|
||||||
logClient("error", "Connection", data.message);
|
logClient("error", "Connection", data.message);
|
||||||
// ponytail: connector errors carry no transfer id, so the oldest running
|
// Transfer errors carry the transfer's channel + path.
|
||||||
// transfer of that kind takes the blame. Add an id when that misfires.
|
if (typeof data.path === "string") {
|
||||||
const msg = String(data.message);
|
const failed = transfersRef.current.find(
|
||||||
const kind = /^download/i.test(msg) ? "down" : /^upload/i.test(msg) ? "up" : /^file transfer/i.test(msg) ? "any" : null;
|
(x) => x.status === "running" && x.cid === data.cid && x.path === data.path
|
||||||
const failed =
|
);
|
||||||
kind && transfersRef.current.find((x) => x.status === "running" && (kind === "any" || x.dir === kind));
|
if (failed) finishTransfer(failed, false);
|
||||||
if (failed) finishTransfer(failed, false);
|
}
|
||||||
if (hasConnectedRef.current) {
|
if (hasConnectedRef.current) {
|
||||||
appendLog({ text: data.message, kind: "error" });
|
appendLog({ text: data.message, kind: "error" });
|
||||||
} else {
|
} else {
|
||||||
@@ -9883,7 +9883,8 @@ function AppInner() {
|
|||||||
const sentWhisperPolicyRef = useRef<{ socket: WebSocket | DemoSocket | null; payload: string }>({ socket: null, payload: "" });
|
const sentWhisperPolicyRef = useRef<{ socket: WebSocket | DemoSocket | null; payload: string }>({ socket: null, payload: "" });
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = socketRef.current;
|
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 block = whisperSettings.mode !== "allow";
|
||||||
const exceptionMode = block ? "allow" : "block";
|
const exceptionMode = block ? "allow" : "block";
|
||||||
const exceptions =
|
const exceptions =
|
||||||
@@ -9898,7 +9899,7 @@ function AppInner() {
|
|||||||
if (sent.socket === socket && sent.payload === payload) return;
|
if (sent.socket === socket && sent.payload === payload) return;
|
||||||
socket.send(payload);
|
socket.send(payload);
|
||||||
sentWhisperPolicyRef.current = { socket, 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.
|
// "Clients in Whisper Verlauf löschen nach": drop old incoming entries.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -11100,7 +11101,7 @@ function AppInner() {
|
|||||||
});
|
});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = socketRef.current;
|
const socket = socketRef.current;
|
||||||
if (!connected || !socket) return;
|
if (!connected || !socket || !gatewayFeatures.has("transferLimit")) return;
|
||||||
const payload = JSON.stringify({
|
const payload = JSON.stringify({
|
||||||
type: "setTransferLimit",
|
type: "setTransferLimit",
|
||||||
up: downloadSettings.uploadLimit * 1024,
|
up: downloadSettings.uploadLimit * 1024,
|
||||||
@@ -11110,7 +11111,7 @@ function AppInner() {
|
|||||||
if (sent.socket === socket && sent.payload === payload) return;
|
if (sent.socket === socket && sent.payload === payload) return;
|
||||||
socket.send(payload);
|
socket.send(payload);
|
||||||
sentTransferLimitRef.current = { socket, payload };
|
sentTransferLimitRef.current = { socket, payload };
|
||||||
}, [connected, activeSessionId, downloadSettings.uploadLimit, downloadSettings.downloadLimit]);
|
}, [connected, activeSessionId, gatewayFeatures, downloadSettings.uploadLimit, downloadSettings.downloadLimit]);
|
||||||
|
|
||||||
const handleFileBrowserDownload = async (entry: FileListEntry) => {
|
const handleFileBrowserDownload = async (entry: FileListEntry) => {
|
||||||
if (!fileBrowserTarget) return;
|
if (!fileBrowserTarget) return;
|
||||||
|
|||||||
Reference in new issue
Block a user