diff --git a/iblt/Cargo.lock b/iblt/Cargo.lock new file mode 100644 index 000000000..0a5b10ac2 --- /dev/null +++ b/iblt/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "iblt" +version = "0.1.0" diff --git a/iblt/Cargo.toml b/iblt/Cargo.toml new file mode 100644 index 000000000..09c17d5ff --- /dev/null +++ b/iblt/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "iblt" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" +authors = ["Adam Ierymenko "] + +[profile.release] +opt-level = 3 +lto = true +codegen-units = 1 +panic = 'abort' + +[dependencies] + +[lib] diff --git a/syncwhole/src/iblt.rs b/iblt/src/lib.rs similarity index 96% rename from syncwhole/src/iblt.rs rename to iblt/src/lib.rs index 8c99b2d6a..da8fafcab 100644 --- a/syncwhole/src/iblt.rs +++ b/iblt/src/lib.rs @@ -11,6 +11,24 @@ use std::borrow::Cow; /// Total memory overhead of each bucket in bytes. const BUCKET_SIZE_BYTES: usize = 13; // u64 key + u32 check + i8 count +#[inline(always)] +pub fn xorshift64(mut x: u64) -> u64 { + x ^= x.wrapping_shl(13); + x ^= x.wrapping_shr(7); + x ^= x.wrapping_shl(17); + x +} + +#[inline(always)] +pub fn splitmix64(mut x: u64) -> u64 { + x ^= x.wrapping_shr(30); + x = x.wrapping_mul(0xbf58476d1ce4e5b9); + x ^= x.wrapping_shr(27); + x = x.wrapping_mul(0x94d049bb133111eb); + x ^= x.wrapping_shr(31); + x +} + /// Based on xorshift64 with endian conversion for BE systems. #[inline(always)] fn get_check_hash(mut x: u64) -> u32 { @@ -215,9 +233,9 @@ mod tests { #[allow(unused_imports)] use std::time::SystemTime; - use crate::iblt::*; + use super::*; #[allow(unused_imports)] - use crate::utils::{splitmix64, xorshift64}; + use super::{splitmix64, xorshift64}; const HASHES: usize = 3; diff --git a/syncwhole/Cargo.toml b/syncwhole/Cargo.toml index 1e7e19350..01203e812 100644 --- a/syncwhole/Cargo.toml +++ b/syncwhole/Cargo.toml @@ -31,6 +31,7 @@ rmp-serde = "^1" sha2 = { version = "^0", optional = true } async-trait = "^0" futures-core = "^0" +iblt = { version = "^0", path = "../iblt" } [features] include_sha2_lib = ["sha2"] diff --git a/syncwhole/src/lib.rs b/syncwhole/src/lib.rs index 030bf48c3..36c1c6115 100644 --- a/syncwhole/src/lib.rs +++ b/syncwhole/src/lib.rs @@ -6,7 +6,6 @@ * https://www.zerotier.com/ */ -pub(crate) mod iblt; pub(crate) mod protocol; pub(crate) mod varint; diff --git a/syncwhole/src/node.rs b/syncwhole/src/node.rs index 32f421b1d..f7c8a1674 100644 --- a/syncwhole/src/node.rs +++ b/syncwhole/src/node.rs @@ -24,10 +24,10 @@ use tokio::time::{Duration, Instant}; use crate::datastore::*; use crate::host::Host; -use crate::iblt::IBLT; use crate::protocol::*; use crate::utils::*; use crate::varint; +use iblt::IBLT; /// Period for running main housekeeping pass. const HOUSEKEEPING_PERIOD: i64 = SYNC_STATUS_PERIOD;