aboutsummaryrefslogtreecommitdiffstats
path: root/src/wireguard/wireguard.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/wireguard/wireguard.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/wireguard/wireguard.rs b/src/wireguard/wireguard.rs
index 674c96f..78f24da 100644
--- a/src/wireguard/wireguard.rs
+++ b/src/wireguard/wireguard.rs
@@ -148,6 +148,16 @@ impl<B: Bind> PeerInner<B> {
self.queue.lock().send(HandshakeJob::New(self.pk)).unwrap();
}
}
+
+ pub fn set_persistent_keepalive_interval(&self, interval: usize) {
+ self.timers().send_persistent_keepalive.stop();
+ self.keepalive.store(interval, Ordering::SeqCst);
+ if interval > 0 {
+ self.timers()
+ .send_persistent_keepalive
+ .start(Duration::from_secs(internal as u64));
+ }
+ }
}
struct Handshake {
@@ -161,6 +171,12 @@ impl<T: Tun, B: Bind> Deref for WireguardHandle<T, B> {
&self.inner
}
}
+impl<T: Tun, B: Bind> Deref for Wireguard<T, B> {
+ type Target = Arc<WireguardInner<T, B>>;
+ fn deref(&self) -> &Self::Target {
+ &self.state
+ }
+}
pub struct Wireguard<T: Tun, B: Bind> {
runner: Runner,
@@ -240,6 +256,10 @@ impl<T: Tun, B: Bind> Wireguard<T, B> {
}
}
+ pub fn set_psk(&self, pk: PublicKey, psk: Option<[u8; 32]>) -> bool {
+ self.state.handshake.write().device.set_psk(pk, psk).is_ok()
+ }
+
pub fn new_peer(&self, pk: PublicKey) {
let mut rng = OsRng::new().unwrap();
let state = Arc::new(PeerInner {