parent
8e77f20a5a
commit
07bd9dec83
12 changed files with 11 additions and 112 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1406,8 +1406,6 @@ name = "librqbit-sha1-wrapper"
|
||||||
version = "2.2.1"
|
version = "2.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crypto-hash",
|
"crypto-hash",
|
||||||
"openssl",
|
|
||||||
"sha1",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,6 @@ readme = "README.md"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["sha1-system"]
|
|
||||||
sha1-system = ["sha1w/sha1-system"]
|
|
||||||
sha1-openssl = ["sha1w/sha1-openssl"]
|
|
||||||
sha1-rust = ["sha1w/sha1-rust"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
buffers = { path = "../buffers", package = "librqbit-buffers", version = "2.2.1" }
|
buffers = { path = "../buffers", package = "librqbit-buffers", version = "2.2.1" }
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,6 @@ readme = "README.md"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["sha1-system"]
|
|
||||||
sha1-system = ["bencode/sha1-system", "librqbit-core/sha1-system"]
|
|
||||||
sha1-openssl = ["bencode/sha1-openssl", "librqbit-core/sha1-openssl"]
|
|
||||||
sha1-rust = ["bencode/sha1-rust", "librqbit-core/sha1-rust"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = {version = "1", features = ["macros", "rt-multi-thread", "net", "sync"]}
|
tokio = {version = "1", features = ["macros", "rt-multi-thread", "net", "sync"]}
|
||||||
tokio-stream = {version = "0.1", features = ["sync"]}
|
tokio-stream = {version = "0.1", features = ["sync"]}
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,9 @@ readme = "README.md"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["sha1-system", "default-tls"]
|
default = ["default-tls"]
|
||||||
webui = []
|
webui = []
|
||||||
timed_existence = []
|
timed_existence = []
|
||||||
sha1-system = ["sha1w/sha1-system"]
|
|
||||||
sha1-openssl = ["sha1w/sha1-openssl"]
|
|
||||||
sha1-rust = ["sha1w/sha1-rust"]
|
|
||||||
default-tls = ["reqwest/default-tls"]
|
default-tls = ["reqwest/default-tls"]
|
||||||
rust-tls = ["reqwest/rustls-tls"]
|
rust-tls = ["reqwest/rustls-tls"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use librqbit_core::{
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use peer_binary_protocol::Piece;
|
use peer_binary_protocol::Piece;
|
||||||
use sha1w::ISha1;
|
use sha1w::{ISha1, Sha1};
|
||||||
use tracing::{debug, trace, warn};
|
use tracing::{debug, trace, warn};
|
||||||
|
|
||||||
use crate::type_aliases::{PeerHandle, BF};
|
use crate::type_aliases::{PeerHandle, BF};
|
||||||
|
|
@ -54,14 +54,14 @@ pub fn update_hash_from_file<Sha1: ISha1>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct FileOps<'a, Sha1> {
|
pub(crate) struct FileOps<'a> {
|
||||||
torrent: &'a TorrentMetaV1Info<ByteBufOwned>,
|
torrent: &'a TorrentMetaV1Info<ByteBufOwned>,
|
||||||
files: &'a [Arc<Mutex<File>>],
|
files: &'a [Arc<Mutex<File>>],
|
||||||
lengths: &'a Lengths,
|
lengths: &'a Lengths,
|
||||||
phantom_data: PhantomData<Sha1>,
|
phantom_data: PhantomData<Sha1>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
|
impl<'a> FileOps<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
torrent: &'a TorrentMetaV1Info<ByteBufOwned>,
|
torrent: &'a TorrentMetaV1Info<ByteBufOwned>,
|
||||||
files: &'a [Arc<Mutex<File>>],
|
files: &'a [Arc<Mutex<File>>],
|
||||||
|
|
@ -136,7 +136,7 @@ impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
|
||||||
let mut read_buffer = vec![0u8; 65536];
|
let mut read_buffer = vec![0u8; 65536];
|
||||||
|
|
||||||
for piece_info in self.lengths.iter_piece_infos() {
|
for piece_info in self.lengths.iter_piece_infos() {
|
||||||
let mut computed_hash = Sha1Impl::new();
|
let mut computed_hash = Sha1::new();
|
||||||
let mut piece_remaining = piece_info.len as usize;
|
let mut piece_remaining = piece_info.len as usize;
|
||||||
let mut some_files_broken = false;
|
let mut some_files_broken = false;
|
||||||
let mut at_least_one_file_required = current_file.full_file_required;
|
let mut at_least_one_file_required = current_file.full_file_required;
|
||||||
|
|
@ -242,7 +242,7 @@ impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
|
||||||
piece_index: ValidPieceIndex,
|
piece_index: ValidPieceIndex,
|
||||||
last_received_chunk: &ChunkInfo,
|
last_received_chunk: &ChunkInfo,
|
||||||
) -> anyhow::Result<bool> {
|
) -> anyhow::Result<bool> {
|
||||||
let mut h = Sha1Impl::new();
|
let mut h = Sha1::new();
|
||||||
let piece_length = self.lengths.piece_length(piece_index);
|
let piece_length = self.lengths.piece_length(piece_index);
|
||||||
let mut absolute_offset = self.lengths.piece_offset(piece_index);
|
let mut absolute_offset = self.lengths.piece_offset(piece_index);
|
||||||
let mut buf = vec![0u8; std::cmp::min(65536, piece_length as usize)];
|
let mut buf = vec![0u8; std::cmp::min(65536, piece_length as usize)];
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ use anyhow::Context;
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use sha1w::Sha1;
|
|
||||||
use size_format::SizeFormatterBinary as SF;
|
use size_format::SizeFormatterBinary as SF;
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
|
|
@ -81,7 +80,7 @@ impl TorrentStateInitializing {
|
||||||
|
|
||||||
info!("Doing initial checksum validation, this might take a while...");
|
info!("Doing initial checksum validation, this might take a while...");
|
||||||
let initial_check_results = self.meta.spawner.spawn_block_in_place(|| {
|
let initial_check_results = self.meta.spawner.spawn_block_in_place(|| {
|
||||||
FileOps::<Sha1>::new(&self.meta.info, &files, &self.meta.lengths)
|
FileOps::new(&self.meta.info, &files, &self.meta.lengths)
|
||||||
.initial_check(self.only_files.as_deref(), &self.checked_bytes)
|
.initial_check(self.only_files.as_deref(), &self.checked_bytes)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,6 @@ use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||||
use peer_binary_protocol::{
|
use peer_binary_protocol::{
|
||||||
extended::handshake::ExtendedHandshake, Handshake, Message, MessageOwned, Piece, Request,
|
extended::handshake::ExtendedHandshake, Handshake, Message, MessageOwned, Piece, Request,
|
||||||
};
|
};
|
||||||
use sha1w::Sha1;
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::{
|
sync::{
|
||||||
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
||||||
|
|
@ -492,7 +491,7 @@ impl TorrentStateLive {
|
||||||
pub fn peer_id(&self) -> Id20 {
|
pub fn peer_id(&self) -> Id20 {
|
||||||
self.meta.peer_id
|
self.meta.peer_id
|
||||||
}
|
}
|
||||||
pub(crate) fn file_ops(&self) -> FileOps<'_, Sha1> {
|
pub(crate) fn file_ops(&self) -> FileOps<'_> {
|
||||||
FileOps::new(&self.meta.info, &self.files, &self.lengths)
|
FileOps::new(&self.meta.info, &self.files, &self.lengths)
|
||||||
}
|
}
|
||||||
pub fn initially_needed(&self) -> u64 {
|
pub fn initially_needed(&self) -> u64 {
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,6 @@ readme = "README.md"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["sha1-system"]
|
|
||||||
sha1-system = ["bencode/sha1-system"]
|
|
||||||
sha1-openssl = ["bencode/sha1-openssl"]
|
|
||||||
sha1-rust = ["bencode/sha1-rust"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"] }
|
tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"] }
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,6 @@ readme = "README.md"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["sha1-system"]
|
|
||||||
sha1-system = ["bencode/sha1-system", "librqbit-core/sha1-system"]
|
|
||||||
sha1-openssl = ["bencode/sha1-openssl", "librqbit-core/sha1-openssl"]
|
|
||||||
sha1-rust = ["bencode/sha1-rust", "librqbit-core/sha1-rust"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = {version = "1", features = ["derive"]}
|
serde = {version = "1", features = ["derive"]}
|
||||||
bincode = "1"
|
bincode = "1"
|
||||||
|
|
@ -25,4 +19,4 @@ bencode = {path = "../bencode", default-features=false, package="librqbit-bencod
|
||||||
clone_to_owned = {path="../clone_to_owned", package="librqbit-clone-to-owned", version = "2.2.1"}
|
clone_to_owned = {path="../clone_to_owned", package="librqbit-clone-to-owned", version = "2.2.1"}
|
||||||
librqbit-core = {path="../librqbit_core", version = "3.6.0"}
|
librqbit-core = {path="../librqbit_core", version = "3.6.0"}
|
||||||
bitvec = "1"
|
bitvec = "1"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,11 @@ readme = "README.md"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["sha1-system", "default-tls", "webui"]
|
default = ["default-tls", "webui"]
|
||||||
openssl-vendored = ["openssl/vendored"]
|
openssl-vendored = ["openssl/vendored"]
|
||||||
tokio-console = ["console-subscriber", "tokio/tracing"]
|
tokio-console = ["console-subscriber", "tokio/tracing"]
|
||||||
webui = ["librqbit/webui"]
|
webui = ["librqbit/webui"]
|
||||||
timed_existence = ["librqbit/timed_existence"]
|
timed_existence = ["librqbit/timed_existence"]
|
||||||
sha1-system = ["librqbit/sha1-system"]
|
|
||||||
sha1-openssl = ["librqbit/sha1-openssl"]
|
|
||||||
sha1-rust = ["librqbit/sha1-rust"]
|
|
||||||
default-tls = ["librqbit/default-tls"]
|
default-tls = ["librqbit/default-tls"]
|
||||||
rust-tls = ["librqbit/rust-tls"]
|
rust-tls = ["librqbit/rust-tls"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,5 @@ readme = "README.md"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["sha1-system"]
|
|
||||||
sha1-system = ["crypto-hash"]
|
|
||||||
sha1-openssl = ["openssl"]
|
|
||||||
sha1-rust = ["sha1"]
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
openssl = {version="0.10", optional=true}
|
crypto-hash = "0.3"
|
||||||
crypto-hash = {version="0.3", optional=true}
|
|
||||||
sha1 = {version = "0.10", optional=true}
|
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,6 @@
|
||||||
// openssl is 2-3x faster than rust's sha1.
|
// openssl is 2-3x faster than rust's sha1.
|
||||||
// system library is the best choice probably (it's the default anyway).
|
// system library is the best choice probably (it's the default anyway).
|
||||||
|
|
||||||
#[cfg(feature = "sha1-openssl")]
|
|
||||||
pub type Sha1 = Sha1Openssl;
|
|
||||||
|
|
||||||
#[cfg(feature = "sha1-rust")]
|
|
||||||
pub type Sha1 = Sha1Rust;
|
|
||||||
|
|
||||||
#[cfg(feature = "sha1-system")]
|
|
||||||
pub type Sha1 = Sha1System;
|
pub type Sha1 = Sha1System;
|
||||||
|
|
||||||
pub trait ISha1 {
|
pub trait ISha1 {
|
||||||
|
|
@ -20,60 +13,10 @@ pub trait ISha1 {
|
||||||
fn finish(self) -> [u8; 20];
|
fn finish(self) -> [u8; 20];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sha1-rust")]
|
|
||||||
pub struct Sha1Rust {
|
|
||||||
inner: sha1::Sha1,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "sha1-rust")]
|
|
||||||
impl ISha1 for Sha1Rust {
|
|
||||||
fn new() -> Self {
|
|
||||||
Sha1Rust {
|
|
||||||
inner: sha1::Sha1::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, buf: &[u8]) {
|
|
||||||
use sha1::Digest;
|
|
||||||
sha1::Sha1::update(&mut self.inner, buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finish(self) -> [u8; 20] {
|
|
||||||
use sha1::Digest;
|
|
||||||
let mut output = [0u8; 20];
|
|
||||||
sha1::Sha1::finalize_into(self.inner, (&mut output[..]).into());
|
|
||||||
output
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "sha1-openssl")]
|
|
||||||
pub struct Sha1Openssl {
|
|
||||||
inner: openssl::sha::Sha1,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "sha1-openssl")]
|
|
||||||
impl ISha1 for Sha1Openssl {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
inner: openssl::sha::Sha1::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, buf: &[u8]) {
|
|
||||||
self.inner.update(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finish(self) -> [u8; 20] {
|
|
||||||
self.inner.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "sha1-system")]
|
|
||||||
pub struct Sha1System {
|
pub struct Sha1System {
|
||||||
inner: crypto_hash::Hasher,
|
inner: crypto_hash::Hasher,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sha1-system")]
|
|
||||||
impl ISha1 for Sha1System {
|
impl ISha1 for Sha1System {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue