diff --git a/crates/librqbit/src/bitv_factory.rs b/crates/librqbit/src/bitv_factory.rs index c6dc41c..57f0791 100644 --- a/crates/librqbit/src/bitv_factory.rs +++ b/crates/librqbit/src/bitv_factory.rs @@ -17,6 +17,7 @@ impl BitVFactory for NonPersistentBitVFactory { async fn load(&self, _: TorrentIdOrHash) -> anyhow::Result>> { Ok(None) } + async fn store_initial_check( &self, _id: TorrentIdOrHash, diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index edc81bc..01ac3ef 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -371,6 +371,9 @@ pub struct SessionOptions { /// librqbit instances at a time. pub dht_config: Option, + /// Enable fastresume, to restore state quickly after restart. + pub fastresume: bool, + /// Turn on to dump session contents into a file periodically, so that on next start /// all remembered torrents will continue where they left off. pub persistence: Option, @@ -507,6 +510,17 @@ impl Session { async fn persistence_factory( opts: &SessionOptions, ) -> anyhow::Result<(Option>, Arc)> { + + macro_rules! make_result { + ($store:expr) => { + if opts.fastresume { + Ok((Some($store.clone()), $store)) + } else { + Ok((Some($store), Arc::new(NonPersistentBitVFactory {}))) + } + }; + } + match &opts.persistence { Some(SessionPersistenceConfig::Json { folder }) => { let folder = match folder.as_ref() { @@ -520,13 +534,13 @@ impl Session { .context("error initializing JsonSessionPersistenceStore")?, ); - Ok((Some(s.clone()), s)) + make_result!(s) }, #[cfg(feature = "postgres")] Some(SessionPersistenceConfig::Postgres { connection_string }) => { use crate::session_persistence::postgres::PostgresSessionStorage; let p = Arc::new(PostgresSessionStorage::new(connection_string).await?); - Ok((Some(p.clone()), p)) + make_result!(p) } None => Ok((None, Arc::new(NonPersistentBitVFactory {}))), } diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index 02fcb90..a697f32 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -341,6 +341,7 @@ async fn async_main(opts: Opts) -> anyhow::Result<()> { socks_proxy_url: socks_url, concurrent_init_limit: Some(opts.concurrent_init_limit), root_span: None, + fastresume: false, }; let stats_printer = |session: Arc| async move {