Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 89 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/librqbit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ librqbit-dualstack-sockets = { version = "0.6.11", features = ["axum"] }
socket2 = "0.6"
nix = { version = "0.30.1", features = ["uio"] }
thiserror = "2.0.12"
# https://lib.rs/crates/async_ftp
async_ftp = { version = "6.0.0", features = ["secure"] }

[target.'cfg(windows)'.dependencies]
windows = { version = "0.62.1", features = [
Expand Down
18 changes: 10 additions & 8 deletions crates/librqbit/src/file_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
type_aliases::{BF, FileInfos, PeerHandle},
};

pub fn update_hash_from_file<Sha1: ISha1>(
pub async fn update_hash_from_file<Sha1: ISha1>(
file_id: usize,
file_info: &FileInfo,
mut pos: u64,
Expand All @@ -35,7 +35,7 @@ pub fn update_hash_from_file<Sha1: ISha1>(
buf[..chunk].fill(0);
} else {
files
.pread_exact(file_id, pos, &mut buf[..chunk])
.pread_exact(file_id, pos, &mut buf[..chunk]).await
.with_context(|| {
format!("failed reading chunk of size {chunk}, read so far {read}")
})?;
Expand Down Expand Up @@ -70,7 +70,7 @@ impl<'a> FileOps<'a> {
}

// Returns the bitvector with pieces we have.
pub fn initial_check(&self, progress: &AtomicU64) -> anyhow::Result<BF> {
pub async fn initial_check(&self, progress: &AtomicU64) -> anyhow::Result<BF> {
let mut have_pieces =
BF::from_boxed_slice(vec![0u8; self.torrent.lengths().piece_bitfield_bytes()].into());
let mut piece_files = Vec::<usize>::new();
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<'a> FileOps<'a> {
&mut computed_hash,
&mut read_buffer,
to_read_in_file,
) {
).await {
debug!(
"error reading from file {} ({:?}) at {}: {:#}",
current_file.index, current_file.fi.relative_filename, pos, &err
Expand Down Expand Up @@ -175,7 +175,7 @@ impl<'a> FileOps<'a> {
Ok(have_pieces)
}

pub fn check_piece(&self, piece_index: ValidPieceIndex) -> anyhow::Result<bool> {
pub async fn check_piece(&self, piece_index: ValidPieceIndex) -> anyhow::Result<bool> {
if cfg!(feature = "_disable_disk_write_net_benchmark") {
return Ok(true);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ impl<'a> FileOps<'a> {
&mut h,
&mut buf,
to_read_in_file,
)
).await
.with_context(|| {
format!(
"error reading {to_read_in_file} bytes, file_id: {file_idx} (\"{:?}\")",
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<'a> FileOps<'a> {
}
}

pub fn read_chunk(
pub async fn read_chunk(
&self,
who_sent: PeerHandle,
chunk_info: &ChunkInfo,
Expand Down Expand Up @@ -282,6 +282,7 @@ impl<'a> FileOps<'a> {
} else {
self.files
.pread_exact(file_idx, absolute_offset, &mut buf[..to_read_in_file])
.await
.with_context(|| {
format!("error reading {file_idx} bytes, file_id: {to_read_in_file}")
})?;
Expand All @@ -299,7 +300,7 @@ impl<'a> FileOps<'a> {
Ok(())
}

pub fn write_chunk(
pub async fn write_chunk(
&self,
who_sent: PeerHandle,
data: &Piece<ByteBuf<'a>>,
Expand Down Expand Up @@ -334,6 +335,7 @@ impl<'a> FileOps<'a> {
let written = self
.files
.pwrite_all_vectored(file_idx, absolute_offset, slices)
.await
.with_context(|| {
format!(
"error writing to file {file_idx} (\"{:?}\")",
Expand Down
Loading