mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 17:03:43 +02:00
Merge pull request #1 from zerotier/library-iblt
Move iblt routines to a separate library
This commit is contained in:
commit
6d40f7924b
6 changed files with 45 additions and 4 deletions
7
iblt/Cargo.lock
generated
Normal file
7
iblt/Cargo.lock
generated
Normal 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
16
iblt/Cargo.toml
Normal 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]
|
|
@ -11,6 +11,24 @@ use std::borrow::Cow;
|
||||||
/// Total memory overhead of each bucket in bytes.
|
/// Total memory overhead of each bucket in bytes.
|
||||||
const BUCKET_SIZE_BYTES: usize = 13; // u64 key + u32 check + i8 count
|
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.
|
/// Based on xorshift64 with endian conversion for BE systems.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn get_check_hash(mut x: u64) -> u32 {
|
fn get_check_hash(mut x: u64) -> u32 {
|
||||||
|
@ -215,9 +233,9 @@ mod tests {
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use crate::iblt::*;
|
use super::*;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use crate::utils::{splitmix64, xorshift64};
|
use super::{splitmix64, xorshift64};
|
||||||
|
|
||||||
const HASHES: usize = 3;
|
const HASHES: usize = 3;
|
||||||
|
|
|
@ -31,6 +31,7 @@ rmp-serde = "^1"
|
||||||
sha2 = { version = "^0", optional = true }
|
sha2 = { version = "^0", optional = true }
|
||||||
async-trait = "^0"
|
async-trait = "^0"
|
||||||
futures-core = "^0"
|
futures-core = "^0"
|
||||||
|
iblt = { version = "^0", path = "../iblt" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
include_sha2_lib = ["sha2"]
|
include_sha2_lib = ["sha2"]
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* https://www.zerotier.com/
|
* https://www.zerotier.com/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub(crate) mod iblt;
|
|
||||||
pub(crate) mod protocol;
|
pub(crate) mod protocol;
|
||||||
pub(crate) mod varint;
|
pub(crate) mod varint;
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,10 @@ use tokio::time::{Duration, Instant};
|
||||||
|
|
||||||
use crate::datastore::*;
|
use crate::datastore::*;
|
||||||
use crate::host::Host;
|
use crate::host::Host;
|
||||||
use crate::iblt::IBLT;
|
|
||||||
use crate::protocol::*;
|
use crate::protocol::*;
|
||||||
use crate::utils::*;
|
use crate::utils::*;
|
||||||
use crate::varint;
|
use crate::varint;
|
||||||
|
use iblt::IBLT;
|
||||||
|
|
||||||
/// Period for running main housekeeping pass.
|
/// Period for running main housekeeping pass.
|
||||||
const HOUSEKEEPING_PERIOD: i64 = SYNC_STATUS_PERIOD;
|
const HOUSEKEEPING_PERIOD: i64 = SYNC_STATUS_PERIOD;
|
||||||
|
|
Loading…
Add table
Reference in a new issue