From 07a5b69a253b164388ec474eb10ba8aed29ca4e3 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Thu, 2 May 2024 19:43:09 +0100 Subject: [PATCH] Hacked in mmap default --- crates/librqbit/src/peer_connection.rs | 12 ++++++------ crates/librqbit/src/session.rs | 12 ++++++++++-- crates/librqbit/src/storage/filesystem/mod.rs | 1 + crates/rqbit/src/main.rs | 14 +------------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/crates/librqbit/src/peer_connection.rs b/crates/librqbit/src/peer_connection.rs index d0fac39..daad454 100644 --- a/crates/librqbit/src/peer_connection.rs +++ b/crates/librqbit/src/peer_connection.rs @@ -103,9 +103,9 @@ impl PeerConnection { handshake: Handshake, mut conn: tokio::net::TcpStream, ) -> anyhow::Result<()> { - if self.addr.ip().to_string() != "213.189.217.38" { - bail!("DEBUG, NOT MY PEER") - } + // if self.addr.ip().to_string() != "213.189.217.38" { + // bail!("DEBUG, NOT MY PEER") + // } use tokio::io::AsyncWriteExt; let rwtimeout = self @@ -153,9 +153,9 @@ impl PeerConnection { outgoing_chan: tokio::sync::mpsc::UnboundedReceiver, ) -> anyhow::Result<()> { use tokio::io::AsyncWriteExt; - if self.addr.ip().to_string() != "213.189.217.38" { - bail!("DEBUG, NOT MY PEER") - } + // if self.addr.ip().to_string() != "213.189.217.38" { + // bail!("DEBUG, NOT MY PEER") + // } let rwtimeout = self .options diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index f9898fe..2d38ccf 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -16,7 +16,10 @@ use crate::{ peer_connection::PeerConnectionOptions, read_buf::ReadBuf, spawn_utils::BlockingSpawner, - storage::{filesystem::FilesystemStorageFactory, BoxStorageFactory, StorageFactoryExt}, + storage::{ + filesystem::{FilesystemStorageFactory, MmapFilesystemStorageFactory}, + BoxStorageFactory, StorageFactoryExt, + }, torrent_state::{ ManagedTorrentBuilder, ManagedTorrentHandle, ManagedTorrentState, TorrentStateLive, }, @@ -190,6 +193,8 @@ pub struct Session { default_defer_writes: bool, + // default_storage_factory: Option, + // This is stored for all tasks to stop when session is dropped. _cancellation_token_drop_guard: DropGuard, } @@ -425,6 +430,7 @@ pub struct SessionOptions { // If true, will write to disk in separate threads. The downside is additional allocations. // May be useful if the disk is slow. pub default_defer_writes: bool, + // pub default_storage_factory: Option, } async fn create_tcp_listener( @@ -1017,7 +1023,9 @@ impl Session { let storage_factory = opts .storage_factory .take() - .unwrap_or_else(|| FilesystemStorageFactory::default().boxed()); + // .unwrap_or_else(|| self.default_storage_factory.clone()) + // .unwrap_or_else(|| FilesystemStorageFactory::default().boxed()); + .unwrap_or_else(|| MmapFilesystemStorageFactory::default().boxed()); if opts.list_only { return Ok(AddTorrentResponse::ListOnly(ListOnlyResponse { diff --git a/crates/librqbit/src/storage/filesystem/mod.rs b/crates/librqbit/src/storage/filesystem/mod.rs index 9b3df6b..6a35550 100644 --- a/crates/librqbit/src/storage/filesystem/mod.rs +++ b/crates/librqbit/src/storage/filesystem/mod.rs @@ -3,3 +3,4 @@ mod mmap; mod opened_file; pub use fs::{FilesystemStorage, FilesystemStorageFactory}; +pub use mmap::{MmapFilesystemStorage, MmapFilesystemStorageFactory}; diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index 951f6f5..28471ff 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -7,15 +7,10 @@ use librqbit::{ api::ApiAddTorrentResponse, http_api::{HttpApi, HttpApiOptions}, http_api_client, librqbit_spawn, -<<<<<<< HEAD storage::{ - filesystem::FilesystemStorageFactory, - middleware::{slow::SlowStorageFactory, timing::TimingStorageFactory}, + filesystem::{FilesystemStorageFactory, MmapFilesystemStorageFactory}, StorageFactoryExt, }, -======= - storage::mmap::MmapStorageFactory, ->>>>>>> a557afc (Add --experimental-mmap-storage) tracing_subscriber_config_utils::{init_logging, InitLoggingOptions}, AddTorrent, AddTorrentOptions, AddTorrentResponse, Api, ListOnlyResponse, PeerConnectionOptions, Session, SessionOptions, TorrentStatsState, @@ -401,13 +396,6 @@ async fn async_main(opts: Opts) -> anyhow::Result<()> { sub_folder: download_opts.sub_folder.clone(), initial_peers: download_opts.initial_peers.clone().map(|p| p.0), disable_trackers: download_opts.disable_trackers, - - storage_factory: Some({ - let sf = FilesystemStorageFactory::default(); - let sf = SlowStorageFactory::new(sf); - TimingStorageFactory::new("fs".to_owned(), sf).boxed() - }), - ..Default::default() }; let connect_to_existing = match client.validate_rqbit_server().await {