fix(dl): take stalled from Transmission
A zero download rate is not a stalled torrent: one between peers reads zero for a poll or two and finishes fine, and at §9.8's 15s cadence that flicker would raise the one chip reserved for a download that never finishes. Transmission already decides this with its own stalled window; carry isStalled and use it.
This commit is contained in:
@@ -116,7 +116,10 @@ fn phase(torrent: &Torrent) -> DownloadPhase {
|
|||||||
} else {
|
} else {
|
||||||
match torrent.state {
|
match torrent.state {
|
||||||
TorrentState::Seeding => DownloadPhase::Seeding,
|
TorrentState::Seeding => DownloadPhase::Seeding,
|
||||||
TorrentState::Downloading if torrent.download_rate == 0 => DownloadPhase::Stalled,
|
// Transmission's own verdict, not a zero rate: a torrent between
|
||||||
|
// peers reads zero for a poll or two and finishes fine, and
|
||||||
|
// §9.8's stalled chip is for the case that never does.
|
||||||
|
TorrentState::Downloading if torrent.is_stalled => DownloadPhase::Stalled,
|
||||||
TorrentState::Downloading => DownloadPhase::Downloading,
|
TorrentState::Downloading => DownloadPhase::Downloading,
|
||||||
_ => DownloadPhase::Queued,
|
_ => DownloadPhase::Queued,
|
||||||
}
|
}
|
||||||
@@ -148,6 +151,7 @@ mod tests {
|
|||||||
download_rate: rate,
|
download_rate: rate,
|
||||||
eta: None,
|
eta: None,
|
||||||
error: error.map(str::to_owned),
|
error: error.map(str::to_owned),
|
||||||
|
is_stalled: rate == 0,
|
||||||
download_dir: PathBuf::from("/downloads"),
|
download_dir: PathBuf::from("/downloads"),
|
||||||
labels: Vec::new(),
|
labels: Vec::new(),
|
||||||
is_finished: false,
|
is_finished: false,
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ pub struct Torrent {
|
|||||||
pub eta: Option<i64>,
|
pub eta: Option<i64>,
|
||||||
/// Transmission's error message, when the torrent has errored.
|
/// Transmission's error message, when the torrent has errored.
|
||||||
pub error: Option<String>,
|
pub error: Option<String>,
|
||||||
|
/// Transmission's own verdict that this torrent has gone quiet for longer
|
||||||
|
/// than its configured stalled window. A rate of zero is not the same
|
||||||
|
/// fact: a torrent between peers reads zero for one poll and is fine.
|
||||||
|
pub is_stalled: bool,
|
||||||
pub download_dir: PathBuf,
|
pub download_dir: PathBuf,
|
||||||
pub labels: Vec<String>,
|
pub labels: Vec<String>,
|
||||||
/// Transmission has stopped this torrent because its configured seeding
|
/// Transmission has stopped this torrent because its configured seeding
|
||||||
@@ -237,8 +241,8 @@ impl TransmissionClient {
|
|||||||
json!({
|
json!({
|
||||||
"fields": [
|
"fields": [
|
||||||
"id", "name", "hashString", "status", "percentDone",
|
"id", "name", "hashString", "status", "percentDone",
|
||||||
"rateDownload", "eta", "errorString", "downloadDir",
|
"rateDownload", "eta", "errorString", "isStalled",
|
||||||
"labels", "isFinished"
|
"downloadDir", "labels", "isFinished"
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -398,6 +402,8 @@ struct RpcTorrent {
|
|||||||
eta: Option<i64>,
|
eta: Option<i64>,
|
||||||
#[serde(rename = "errorString", default)]
|
#[serde(rename = "errorString", default)]
|
||||||
error: String,
|
error: String,
|
||||||
|
#[serde(rename = "isStalled", default)]
|
||||||
|
is_stalled: bool,
|
||||||
#[serde(rename = "downloadDir")]
|
#[serde(rename = "downloadDir")]
|
||||||
download_dir: PathBuf,
|
download_dir: PathBuf,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@@ -428,6 +434,7 @@ impl From<RpcTorrent> for Torrent {
|
|||||||
download_rate: value.download_rate,
|
download_rate: value.download_rate,
|
||||||
eta: value.eta.filter(|eta| *eta >= 0),
|
eta: value.eta.filter(|eta| *eta >= 0),
|
||||||
error: (!value.error.is_empty()).then_some(value.error),
|
error: (!value.error.is_empty()).then_some(value.error),
|
||||||
|
is_stalled: value.is_stalled,
|
||||||
download_dir: value.download_dir,
|
download_dir: value.download_dir,
|
||||||
labels: value.labels,
|
labels: value.labels,
|
||||||
is_finished: value.is_finished,
|
is_finished: value.is_finished,
|
||||||
|
|||||||
Reference in New Issue
Block a user