Can now try to unpause errored torrent

This commit is contained in:
Igor Katson 2023-11-25 18:42:43 +00:00
parent e3a3f71064
commit 3de67d0902
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
4 changed files with 33 additions and 16 deletions

14
TODO.md
View file

@ -14,16 +14,20 @@
- [x] pause/unpause
- [x] remove including from disk
- [ ] DHT
- [ ] for torrents with a few seeds might be cool to re-query DHT once in a while
- [ ] for torrents with a few seeds might be cool to re-query DHT once in a while.
- [x] it's sending many requests now way too fast, locks up Mac OS UI annoyingly
someday:
- [ ] cancellation from the client-side for the lib (i.e. stop the torrent manager)
- [x] cancellation from the client-side for the lib (i.e. stop the torrent manager)
refactor:
- [x] where are peers stored
- [x] http api pause/unpause etc
- [ ] when a live torrent fails writing to disk, it should transition to error state
- [ ] something is wrong when unpausing - can't finish. Recalculate needed/have from chunk tracker.
- [ ] silence this: WARN torrent{id=0}:external_peer_adder: librqbit::spawn_utils: finished with error: no longer live
- [x] when a live torrent fails writing to disk, it should transition to error state
- [x] something is wrong when unpausing - can't finish. Recalculate needed/have from chunk tracker.
- [x] silence this: WARN torrent{id=0}:external_peer_adder: librqbit::spawn_utils: finished with error: no longer live
- [x] start from error state should be possible from UI
- [ ] if the torrent was completed, not need to re-check it
- [ ] checking is very slow on raspberry

View file

@ -192,7 +192,11 @@ impl ManagedTorrent {
);
};
let spawn_peer_adder = |live: &Arc<TorrentStateLive>| {
fn spawn_peer_adder(
live: &Arc<TorrentStateLive>,
initial_peers: Vec<SocketAddr>,
peer_rx: Option<impl StreamExt<Item = SocketAddr> + Unpin + Send + Sync + 'static>,
) {
let span = live.meta().span.clone();
let live = Arc::downgrade(live);
spawn(
@ -209,10 +213,11 @@ impl ManagedTorrent {
if let Some(mut peer_rx) = peer_rx {
while let Some(peer) = peer_rx.next().await {
live.upgrade()
.context("no longer live")?
.add_peer_if_not_seen(peer)
.context("torrent closed")?;
let live = match live.upgrade() {
Some(live) => live,
None => return Ok(()),
};
live.add_peer_if_not_seen(peer).context("torrent closed")?;
}
} else {
error!("peer rx is not set");
@ -221,7 +226,7 @@ impl ManagedTorrent {
Ok(())
},
);
};
}
match &g.state {
ManagedTorrentState::Live(_) => {
@ -254,7 +259,7 @@ impl ManagedTorrent {
g.state = ManagedTorrentState::Live(live.clone());
spawn_fatal_errors_receiver(&t, rx);
spawn_peer_adder(&live);
spawn_peer_adder(&live, initial_peers, peer_rx);
Ok(())
}
@ -274,11 +279,19 @@ impl ManagedTorrent {
let live = TorrentStateLive::new(paused, tx);
g.state = ManagedTorrentState::Live(live.clone());
spawn_fatal_errors_receiver(self, rx);
spawn_peer_adder(&live);
spawn_peer_adder(&live, initial_peers, peer_rx);
Ok(())
}
ManagedTorrentState::Error(_) => {
bail!("starting torrents from error state not implemented")
let initializing = Arc::new(TorrentStateInitializing::new(
self.info.clone(),
self.only_files.clone(),
));
g.state = ManagedTorrentState::Initializing(initializing.clone());
drop(g);
// Recurse.
self.start(initial_peers, peer_rx, start_paused)
}
ManagedTorrentState::None => bail!("bug: torrent is in empty state"),
}

File diff suppressed because one or more lines are too long

View file

@ -106,7 +106,7 @@ const TorrentActions: React.FC<{
let refreshCtx = useContext(RefreshTorrentStatsContext);
const canPause = state == 'live';
const canUnpause = state == 'paused';
const canUnpause = state == 'paused' || state == 'error';
const ctx = useContext(AppContext);