diff --git a/crates/librqbit/src/lib.rs b/crates/librqbit/src/lib.rs index 39c7dbf..53501eb 100644 --- a/crates/librqbit/src/lib.rs +++ b/crates/librqbit/src/lib.rs @@ -2,7 +2,7 @@ pub mod buffers; pub mod chunk_tracker; pub mod clone_to_owned; pub mod constants; -pub mod files_ops; +pub mod file_ops; pub mod lengths; pub mod peer_binary_protocol; pub mod peer_connection; diff --git a/crates/librqbit/src/peer_connection.rs b/crates/librqbit/src/peer_connection.rs index 8a317f2..055405f 100644 --- a/crates/librqbit/src/peer_connection.rs +++ b/crates/librqbit/src/peer_connection.rs @@ -249,7 +249,7 @@ impl PeerConnection { "read_chunk_blocking(peer={}, chunk_info={:?}", peer_handle, &chunk_info ), - move || state.read_chunk_blocking(peer_handle, chunk_info), + move || state.file_ops().read_chunk(peer_handle, chunk_info), ) .await??; @@ -529,7 +529,8 @@ impl PeerConnection { // TODO: in theory we should unmark the piece as downloaded here. But if there was a disk error, what // should we really do? If we unmark it, it will get requested forever... this.state - .write_chunk_blocking(handle, &piece, &chunk_info)?; + .file_ops() + .write_chunk(handle, &piece, &chunk_info)?; if !should_checksum { return Ok(()); @@ -537,7 +538,8 @@ impl PeerConnection { match this .state - .check_piece_blocking(handle, chunk_info.piece_index, &chunk_info) + .file_ops() + .check_piece(handle, chunk_info.piece_index, &chunk_info) .with_context(|| format!("error checking piece={}", index))? { true => { diff --git a/crates/librqbit/src/torrent_manager.rs b/crates/librqbit/src/torrent_manager.rs index 78f3dc6..1b8bf6f 100644 --- a/crates/librqbit/src/torrent_manager.rs +++ b/crates/librqbit/src/torrent_manager.rs @@ -19,7 +19,7 @@ use size_format::SizeFormatterBinary as SF; use crate::{ chunk_tracker::ChunkTracker, - files_ops::initial_check, + file_ops::FileOps, lengths::Lengths, peer_binary_protocol::MessageOwned, peer_connection::PeerConnection, @@ -146,7 +146,7 @@ impl TorrentManager { info!("Doing initial checksum validation, this might take a while..."); let initial_check_results = - initial_check(&torrent, &files, only_files.as_deref(), &lengths)?; + FileOps::new(&torrent, &files, &lengths).initial_check(only_files.as_deref())?; info!( "Initial check results: have {}, needed {}", diff --git a/crates/librqbit/src/torrent_state.rs b/crates/librqbit/src/torrent_state.rs index 6a59720..8dd7f41 100644 --- a/crates/librqbit/src/torrent_state.rs +++ b/crates/librqbit/src/torrent_state.rs @@ -14,11 +14,10 @@ use parking_lot::{Mutex, RwLock}; use tokio::sync::mpsc::Sender; use crate::{ - buffers::ByteString, chunk_tracker::ChunkTracker, - files_ops::{check_piece, read_chunk, write_chunk}, + file_ops::FileOps, lengths::{ChunkInfo, Lengths, ValidPieceIndex}, - peer_binary_protocol::{Handshake, Message, MessageOwned, Piece}, + peer_binary_protocol::{Handshake, Message, MessageOwned}, peer_state::{LivePeerState, PeerState}, torrent_metainfo::TorrentMetaV1Owned, type_aliases::{PeerHandle, BF}, @@ -160,50 +159,8 @@ pub struct TorrentState { } impl TorrentState { - pub fn check_piece_blocking( - &self, - who_sent: PeerHandle, - piece_index: ValidPieceIndex, - last_received_chunk: &ChunkInfo, - ) -> anyhow::Result { - check_piece( - &self.torrent, - &self.files, - &self.lengths, - who_sent, - piece_index, - last_received_chunk, - ) - } - - pub fn read_chunk_blocking( - &self, - who_sent: PeerHandle, - chunk_info: ChunkInfo, - ) -> anyhow::Result> { - read_chunk( - &self.torrent, - &self.files, - &self.lengths, - who_sent, - chunk_info, - ) - } - - pub fn write_chunk_blocking( - &self, - who_sent: PeerHandle, - data: &Piece, - chunk_info: &ChunkInfo, - ) -> anyhow::Result<()> { - write_chunk( - &self.torrent, - &self.files, - &self.lengths, - who_sent, - data, - chunk_info, - ) + pub fn file_ops(&self) -> FileOps<'_> { + FileOps::new(&self.torrent, &self.files, &self.lengths) } pub fn get_next_needed_piece(&self, peer_handle: PeerHandle) -> Option {