diff --git a/Cargo.lock b/Cargo.lock index 423ec791..97cadbef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -712,6 +712,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + [[package]] name = "crc32c" version = "0.6.8" @@ -923,7 +938,7 @@ dependencies = [ [[package]] name = "dragonfly-client" -version = "0.2.2" +version = "0.2.3" dependencies = [ "anyhow", "blake3", @@ -996,7 +1011,7 @@ dependencies = [ [[package]] name = "dragonfly-client-backend" -version = "0.2.2" +version = "0.2.3" dependencies = [ "dragonfly-api", "dragonfly-client-core", @@ -1027,7 +1042,7 @@ dependencies = [ [[package]] name = "dragonfly-client-config" -version = "0.2.2" +version = "0.2.3" dependencies = [ "bytesize", "bytesize-serde", @@ -1053,7 +1068,7 @@ dependencies = [ [[package]] name = "dragonfly-client-core" -version = "0.2.2" +version = "0.2.3" dependencies = [ "headers 0.4.0", "hyper 1.5.2", @@ -1072,7 +1087,7 @@ dependencies = [ [[package]] name = "dragonfly-client-init" -version = "0.2.2" +version = "0.2.3" dependencies = [ "anyhow", "clap", @@ -1090,12 +1105,12 @@ dependencies = [ [[package]] name = "dragonfly-client-storage" -version = "0.2.2" +version = "0.2.3" dependencies = [ "base16ct", "bincode", "chrono", - "crc32c", + "crc", "dragonfly-api", "dragonfly-client-config", "dragonfly-client-core", @@ -1115,12 +1130,12 @@ dependencies = [ [[package]] name = "dragonfly-client-util" -version = "0.2.2" +version = "0.2.3" dependencies = [ "base16ct", "base64 0.22.1", "blake3", - "crc32c", + "crc", "crc32fast", "dragonfly-api", "dragonfly-client-core", @@ -1505,7 +1520,7 @@ dependencies = [ [[package]] name = "hdfs" -version = "0.2.2" +version = "0.2.3" dependencies = [ "dragonfly-client-backend", "dragonfly-client-core", diff --git a/Cargo.toml b/Cargo.toml index 5318735b..b96c197c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ ] [workspace.package] -version = "0.2.2" +version = "0.2.3" authors = ["The Dragonfly Developers"] homepage = "https://d7y.io/" repository = "https://github.com/dragonflyoss/client.git" @@ -22,13 +22,13 @@ readme = "README.md" edition = "2021" [workspace.dependencies] -dragonfly-client = { path = "dragonfly-client", version = "0.2.2" } -dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.2" } -dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.2" } -dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.2" } -dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.2" } -dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.2" } -dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.2" } +dragonfly-client = { path = "dragonfly-client", version = "0.2.3" } +dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.3" } +dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.3" } +dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.3" } +dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.3" } +dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.3" } +dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.3" } thiserror = "1.0" dragonfly-api = "=2.1.3" reqwest = { version = "0.12.4", features = [ @@ -61,7 +61,7 @@ rustls-pki-types = "1.10.1" rustls-pemfile = "2.2.0" sha2 = "0.10" blake3 = "1.5.5" -crc32c = "0.6.8" +crc = "3.2.1" uuid = { version = "1.11", features = ["v4"] } hex = "0.4" rocksdb = "0.22.0" diff --git a/dragonfly-client-config/build.rs b/dragonfly-client-config/build.rs index 55af8951..d3cb00c7 100644 --- a/dragonfly-client-config/build.rs +++ b/dragonfly-client-config/build.rs @@ -64,24 +64,6 @@ fn main() { let target = env::var("TARGET").unwrap_or_default(); println!("cargo:rustc-env=BUILD_PLATFORM={}", target); - // Get the RUSTFLAGS environment variable. - let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default(); - - // Set the environment variables for the RUSTFLAGS. - let additional_rustflags = if target.contains("x86_64") { - "-C target-feature=+sse4.2" - } else { - "" - }; - - if !additional_rustflags.is_empty() { - if !rustflags.is_empty() { - rustflags.push(' '); - } - rustflags.push_str(additional_rustflags); - println!("cargo:rustc-env=RUSTFLAGS={}", rustflags); - } - // Set the environment variables for the build time. if let Ok(build_time) = SystemTime::now().duration_since(UNIX_EPOCH) { println!("cargo:rustc-env=BUILD_TIMESTAMP={}", build_time.as_secs()); diff --git a/dragonfly-client-storage/Cargo.toml b/dragonfly-client-storage/Cargo.toml index cd62b45b..a9fb6e9f 100644 --- a/dragonfly-client-storage/Cargo.toml +++ b/dragonfly-client-storage/Cargo.toml @@ -23,7 +23,7 @@ prost-wkt-types.workspace = true tokio.workspace = true tokio-util.workspace = true sha2.workspace = true -crc32c.workspace = true +crc.workspace = true base16ct.workspace = true num_cpus = "1.0" bincode = "1.3.3" diff --git a/dragonfly-client-storage/src/content.rs b/dragonfly-client-storage/src/content.rs index ace610ca..6c948c05 100644 --- a/dragonfly-client-storage/src/content.rs +++ b/dragonfly-client-storage/src/content.rs @@ -14,6 +14,7 @@ * limitations under the License. */ +use crc::*; use dragonfly_api::common::v2::Range; use dragonfly_client_config::dfdaemon::Config; use dragonfly_client_core::Result; @@ -335,8 +336,9 @@ impl Content { error!("seek {:?} failed: {}", task_path, err); })?; - // Copy the piece to the file while updating the CRC32C value. - let mut crc: u32 = 0; + // Copy the piece to the file while updating the CRC32 value. + let crc = Crc::>::new(&CRC_32_ISCSI); + let mut digest = crc.digest(); let mut length = 0; let mut buffer = vec![0; self.config.storage.write_buffer_size]; let mut writer = BufWriter::with_capacity(self.config.storage.write_buffer_size, f); @@ -348,7 +350,7 @@ impl Content { break; } - crc = crc32c::crc32c_append(crc, &buffer[..n]); + digest.update(&buffer[..n]); writer.write_all(&buffer[..n]).await?; length += n as u64; } @@ -357,7 +359,7 @@ impl Content { // Calculate the hash of the piece. Ok(WritePieceResponse { length, - hash: crc.to_string(), + hash: digest.finalize().to_string(), }) } @@ -455,8 +457,9 @@ impl Content { error!("open {:?} failed: {}", task_path, err); })?; - // Copy the content to the file while updating the CRC32C value. - let mut crc: u32 = 0; + // Copy the content to the file while updating the CRC32 value. + let crc = Crc::>::new(&CRC_32_ISCSI); + let mut digest = crc.digest(); let mut length = 0; let mut buffer = vec![0; self.config.storage.write_buffer_size]; let mut writer = BufWriter::with_capacity(self.config.storage.write_buffer_size, to_f); @@ -468,7 +471,7 @@ impl Content { break; } - crc = crc32c::crc32c_append(crc, &buffer[..n]); + digest.update(&buffer[..n]); writer.write_all(&buffer[..n]).await?; length += n as u64; } @@ -476,7 +479,7 @@ impl Content { Ok(WritePersistentCacheTaskResponse { length, - hash: crc.to_string(), + hash: digest.finalize().to_string(), }) } diff --git a/dragonfly-client-util/Cargo.toml b/dragonfly-client-util/Cargo.toml index 97a76cc9..34a9f397 100644 --- a/dragonfly-client-util/Cargo.toml +++ b/dragonfly-client-util/Cargo.toml @@ -27,7 +27,7 @@ uuid.workspace = true hex.workspace = true openssl.workspace = true blake3.workspace = true -crc32c.workspace = true +crc.workspace = true base16ct.workspace = true base64 = "0.22.1" crc32fast = "1.4.2" diff --git a/dragonfly-client-util/src/digest/mod.rs b/dragonfly-client-util/src/digest/mod.rs index 1e3a6423..5edab34c 100644 --- a/dragonfly-client-util/src/digest/mod.rs +++ b/dragonfly-client-util/src/digest/mod.rs @@ -14,6 +14,7 @@ * limitations under the License. */ +use crc::*; use dragonfly_client_core::Result as ClientResult; use sha2::Digest as Sha2Digest; use std::fmt; @@ -135,17 +136,18 @@ pub fn calculate_file_hash(algorithm: Algorithm, path: &Path) -> ClientResult { - let mut crc: u32 = 0; let mut buffer = [0; 4096]; + let crc = Crc::>::new(&CRC_32_ISCSI); + let mut digest = crc.digest(); loop { let n = reader.read(&mut buffer)?; if n == 0 { break; } - crc = crc32c::crc32c_append(crc, &buffer[..n]); + digest.update(&buffer[..n]); } - Ok(Digest::new(algorithm, crc.to_string())) + Ok(Digest::new(algorithm, digest.finalize().to_string())) } Algorithm::Blake3 => { let mut hasher = blake3::Hasher::new();