Remove unused under_load code

This commit is contained in:
Mathias Hall-Andersen
2019-12-26 23:45:34 +01:00
parent bb0a8acea3
commit 956c3f02d4
2 changed files with 10 additions and 18 deletions

View File

@@ -45,7 +45,7 @@ pub const TIMERS_TICK: Duration = Duration::from_millis(100);
pub const TIMERS_SLOTS: usize = (TIMER_MAX_DURATION.as_micros() / TIMERS_TICK.as_micros()) as usize; pub const TIMERS_SLOTS: usize = (TIMER_MAX_DURATION.as_micros() / TIMERS_TICK.as_micros()) as usize;
// Performance: // Performance:
// Initial capacity of timer-wheel (grows to accommodate more timers) // Initial capacity of timer-wheel (grows to accommodate more timers).
pub const TIMERS_CAPACITY: usize = 16; pub const TIMERS_CAPACITY: usize = 16;
/* A long duration (compared to the WireGuard time constants), /* A long duration (compared to the WireGuard time constants),

View File

@@ -19,7 +19,8 @@ use super::udp::UDP;
// constants // constants
use super::constants::{ use super::constants::{
DURATION_UNDER_LOAD, MESSAGE_PADDING_MULTIPLE, THRESHOLD_UNDER_LOAD, TIME_HORIZON, DURATION_UNDER_LOAD, MAX_QUEUED_INCOMING_HANDSHAKES, MESSAGE_PADDING_MULTIPLE,
THRESHOLD_UNDER_LOAD, TIME_HORIZON,
}; };
use super::handshake::MAX_HANDSHAKE_MSG_SIZE; use super::handshake::MAX_HANDSHAKE_MSG_SIZE;
use super::handshake::{TYPE_COOKIE_REPLY, TYPE_INITIATION, TYPE_RESPONSE}; use super::handshake::{TYPE_COOKIE_REPLY, TYPE_INITIATION, TYPE_RESPONSE};
@@ -131,19 +132,7 @@ pub fn udp_worker<T: Tun, B: UDP>(wg: &WireGuard<T, B>, reader: B::Reader) {
match LittleEndian::read_u32(&msg[..]) { match LittleEndian::read_u32(&msg[..]) {
TYPE_COOKIE_REPLY | TYPE_INITIATION | TYPE_RESPONSE => { TYPE_COOKIE_REPLY | TYPE_INITIATION | TYPE_RESPONSE => {
debug!("{} : reader, received handshake message", wg); debug!("{} : reader, received handshake message", wg);
wg.pending.fetch_add(1, Ordering::SeqCst);
// add one to pending
let pending = wg.pending.fetch_add(1, Ordering::SeqCst);
// update under_load flag
if pending > THRESHOLD_UNDER_LOAD {
debug!("{} : reader, set under load (pending = {})", wg, pending);
last_under_load = Instant::now();
} else if last_under_load.elapsed() > DURATION_UNDER_LOAD {
debug!("{} : reader, clear under load", wg);
}
// add to handshake queue
wg.queue.send(HandshakeJob::Message(msg, src)); wg.queue.send(HandshakeJob::Message(msg, src));
} }
TYPE_TRANSPORT => { TYPE_TRANSPORT => {
@@ -175,6 +164,8 @@ pub fn handshake_worker<T: Tun, B: UDP>(
let pending = wg.pending.fetch_sub(1, Ordering::SeqCst); let pending = wg.pending.fetch_sub(1, Ordering::SeqCst);
let mut under_load = false; let mut under_load = false;
debug_assert!(pending < MAX_QUEUED_INCOMING_HANDSHAKES + (1 << 16));
// immediate go under load if too many handshakes pending // immediate go under load if too many handshakes pending
if pending > THRESHOLD_UNDER_LOAD { if pending > THRESHOLD_UNDER_LOAD {
*wg.last_under_load.lock() = Instant::now(); *wg.last_under_load.lock() = Instant::now();
@@ -188,6 +179,7 @@ pub fn handshake_worker<T: Tun, B: UDP>(
under_load = true; under_load = true;
} }
} }
log::trace!("{} : handshake worker, under_load = {}", wg, under_load);
// de-multiplex staged handshake jobs and handshake messages // de-multiplex staged handshake jobs and handshake messages
match job { match job {
@@ -201,7 +193,7 @@ pub fn handshake_worker<T: Tun, B: UDP>(
Some(src.into_address()) Some(src.into_address())
} else { } else {
None None
} },
) { ) {
Ok((pk, resp, keypair)) => { Ok((pk, resp, keypair)) => {
// send response (might be cookie reply or handshake response) // send response (might be cookie reply or handshake response)