Merge pull request #1 from zerotier/library-iblt

Move iblt routines to a separate library
This commit is contained in:
Adam Ierymenko 2022-04-11 16:32:23 -04:00 committed by GitHub
commit 6d40f7924b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 4 deletions

7
iblt/Cargo.lock generated Normal file
View file

@ -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"

16
iblt/Cargo.toml Normal file
View file

@ -0,0 +1,16 @@
[package]
name = "iblt"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"
authors = ["Adam Ierymenko <adam.ierymenko@zerotier.com>"]
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
panic = 'abort'
[dependencies]
[lib]

View file

@ -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;

View file

@ -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"]

View file

@ -6,7 +6,6 @@
* https://www.zerotier.com/
*/
pub(crate) mod iblt;
pub(crate) mod protocol;
pub(crate) mod varint;

View file

@ -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;