Daemonization

This commit is contained in:
Mathias Hall-Andersen
2019-11-21 17:12:00 +01:00
parent 92dbb4c46a
commit dee23969f5
8 changed files with 94 additions and 37 deletions

View File

@@ -30,7 +30,7 @@ pub struct PeerInner<T: Tun, B: Bind> {
pub wg: Arc<WireguardInner<T, B>>,
// handshake state
pub walltime_last_handshake: Mutex<SystemTime>,
pub walltime_last_handshake: Mutex<Option<SystemTime>>,
pub last_handshake_sent: Mutex<Instant>, // instant for last handshake
pub handshake_queued: AtomicBool, // is a handshake job currently queued for the peer?
pub queue: Mutex<Sender<HandshakeJob<B::Endpoint>>>, // handshake queue

View File

@@ -139,7 +139,7 @@ impl<T: tun::Tun, B: bind::Bind> PeerInner<T, B> {
if timers.enabled {
timers.handshake_attempts.store(0, Ordering::SeqCst);
timers.sent_lastminute_handshake.store(false, Ordering::SeqCst);
*self.walltime_last_handshake.lock() = SystemTime::now();
*self.walltime_last_handshake.lock() = Some(SystemTime::now());
}
}

View File

@@ -16,7 +16,7 @@ use std::ops::Deref;
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant, SystemTime};
use std::time::{Duration, Instant};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
@@ -219,7 +219,7 @@ impl<T: Tun, B: Bind> Wireguard<T, B> {
id: rng.gen(),
pk,
wg: self.state.clone(),
walltime_last_handshake: Mutex::new(SystemTime::UNIX_EPOCH),
walltime_last_handshake: Mutex::new(None),
last_handshake_sent: Mutex::new(self.state.start - TIME_HORIZON),
handshake_queued: AtomicBool::new(false),
queue: Mutex::new(self.state.queue.lock().clone()),