mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 21:13:44 +02:00
improved test
This commit is contained in:
parent
46a0c48745
commit
4b6bf0a4ad
2 changed files with 14 additions and 6 deletions
|
@ -142,6 +142,7 @@ impl CounterWindow {
|
||||||
//atomic instructions are only ever atomic within themselves;
|
//atomic instructions are only ever atomic within themselves;
|
||||||
//sequentially consistent atomics do not guarantee that the thread is not preempted between individual atomic instructions
|
//sequentially consistent atomics do not guarantee that the thread is not preempted between individual atomic instructions
|
||||||
if let Some(history) = self.0.lock().unwrap().as_mut() {
|
if let Some(history) = self.0.lock().unwrap().as_mut() {
|
||||||
|
const NONCE_MAX_DELTA: i64 = (2*COUNTER_MAX_ALLOWED_OOO as i64).wrapping_shl(32);
|
||||||
let mut is_in = false;
|
let mut is_in = false;
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
let mut smallest = fragment_nonce;
|
let mut smallest = fragment_nonce;
|
||||||
|
@ -154,7 +155,7 @@ impl CounterWindow {
|
||||||
idx = i;
|
idx = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !is_in & (smallest != fragment_nonce) {
|
if !is_in & (smallest != fragment_nonce) & ((fragment_nonce as i64).wrapping_sub(smallest as i64) < NONCE_MAX_DELTA) {
|
||||||
history[idx] = fragment_nonce;
|
history[idx] = fragment_nonce;
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn counter_window() {
|
fn counter_window() {
|
||||||
let sqrt_out_of_order_max = (COUNTER_MAX_ALLOWED_OOO as f32).sqrt() as u32;
|
let sqrt_out_of_order_max = (COUNTER_MAX_ALLOWED_OOO as f32).sqrt() as u32;
|
||||||
let mut rng = 8234;
|
let mut rng = 1027;//8234
|
||||||
let mut counter = u32::MAX - 16;
|
let mut counter = u32::MAX - 16;
|
||||||
let mut fragment_no: u8 = 0;
|
let mut fragment_no: u8 = 0;
|
||||||
let mut history = Vec::<(u32, u8)>::new();
|
let mut history = Vec::<(u32, u8)>::new();
|
||||||
|
@ -239,26 +239,33 @@ mod tests {
|
||||||
let p = xorshift64(&mut rng)%1000;
|
let p = xorshift64(&mut rng)%1000;
|
||||||
let c;
|
let c;
|
||||||
let f;
|
let f;
|
||||||
if p < 250 {
|
if p < 200 {
|
||||||
let r = xorshift64(&mut rng);
|
let r = xorshift64(&mut rng);
|
||||||
c = counter.wrapping_add(r%sqrt_out_of_order_max);
|
c = counter.wrapping_add(r%sqrt_out_of_order_max);
|
||||||
f = fragment_no + 1 + ((r/sqrt_out_of_order_max)%sqrt_out_of_order_max) as u8;
|
f = fragment_no + 1 + ((r/sqrt_out_of_order_max)%sqrt_out_of_order_max) as u8;
|
||||||
} else if p < 500 {
|
} else if p < 400 {
|
||||||
if history.len() > 0 {
|
if history.len() > 0 {
|
||||||
let idx = xorshift64(&mut rng) as usize%history.len();
|
let idx = xorshift64(&mut rng) as usize%history.len();
|
||||||
let (c, f) = history[idx];
|
let (c, f) = history[idx];
|
||||||
assert!(!w.message_received(c, f));
|
assert!(!w.message_received(c, f));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if p < 750 {
|
} else if p < 650 {
|
||||||
fragment_no = u8::min(fragment_no + 1, 63);
|
fragment_no = u8::min(fragment_no + 1, 63);
|
||||||
c = counter;
|
c = counter;
|
||||||
f = fragment_no;
|
f = fragment_no;
|
||||||
} else if p < 999 {
|
} else if p < 900 {
|
||||||
counter = counter.wrapping_add(1);
|
counter = counter.wrapping_add(1);
|
||||||
fragment_no = 0;
|
fragment_no = 0;
|
||||||
c = counter;
|
c = counter;
|
||||||
f = fragment_no;
|
f = fragment_no;
|
||||||
|
} else if p < 999 {
|
||||||
|
c = xorshift64(&mut rng);
|
||||||
|
f = (xorshift64(&mut rng)%64) as u8;
|
||||||
|
if w.message_received(c, f) {
|
||||||
|
history.push((c, f));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
//simulate rekeying
|
//simulate rekeying
|
||||||
counter = xorshift64(&mut rng);
|
counter = xorshift64(&mut rng);
|
||||||
|
|
Loading…
Add table
Reference in a new issue