aboutsummaryrefslogtreecommitdiffstats
path: root/src/wireguard
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-03 18:33:49 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-03 18:33:49 +0100
commita0fa261a8a9542418072c42cfe73807d8d30cf88 (patch)
tree550af2cf98219323cda009fe76b81655d65719a8 /src/wireguard
parentWork on configuration interface (diff)
downloadwireguard-rs-a0fa261a8a9542418072c42cfe73807d8d30cf88.tar.xz
wireguard-rs-a0fa261a8a9542418072c42cfe73807d8d30cf88.zip
Work on UAPI parser
Diffstat (limited to 'src/wireguard')
-rw-r--r--src/wireguard/tests.rs4
-rw-r--r--src/wireguard/wireguard.rs22
2 files changed, 10 insertions, 16 deletions
diff --git a/src/wireguard/tests.rs b/src/wireguard/tests.rs
index 6a02e1f..83ef594 100644
--- a/src/wireguard/tests.rs
+++ b/src/wireguard/tests.rs
@@ -120,8 +120,8 @@ fn test_pure_wireguard() {
let pk2 = PublicKey::from(&sk2);
- wg1.new_peer(pk2);
- wg2.new_peer(pk1);
+ wg1.add_peer(pk2);
+ wg2.add_peer(pk1);
wg1.set_key(Some(sk1));
wg2.set_key(Some(sk2));
diff --git a/src/wireguard/wireguard.rs b/src/wireguard/wireguard.rs
index 78f24da..6cdae6c 100644
--- a/src/wireguard/wireguard.rs
+++ b/src/wireguard/wireguard.rs
@@ -148,16 +148,6 @@ 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 {
@@ -260,7 +250,11 @@ impl<T: Tun, B: Bind> Wireguard<T, B> {
self.state.handshake.write().device.set_psk(pk, psk).is_ok()
}
- pub fn new_peer(&self, pk: PublicKey) {
+ pub fn add_peer(&self, pk: PublicKey) {
+ if self.state.peers.read().contains_key(pk.as_bytes()) {
+ return;
+ }
+
let mut rng = OsRng::new().unwrap();
let state = Arc::new(PeerInner {
id: rng.gen(),
@@ -278,9 +272,6 @@ impl<T: Tun, B: Bind> Wireguard<T, B> {
// create a router peer
let router = Arc::new(self.state.router.new_peer(state.clone()));
- // add to the handshake device
- self.state.handshake.write().device.add(pk).unwrap(); // TODO: handle adding of public key for interface
-
// form WireGuard peer
let peer = Peer { router, state };
@@ -295,6 +286,9 @@ impl<T: Tun, B: Bind> Wireguard<T, B> {
// finally, add the peer to the wireguard device
let mut peers = self.state.peers.write();
peers.entry(*pk.as_bytes()).or_insert(peer);
+
+ // add to the handshake device
+ self.state.handshake.write().device.add(pk).unwrap(); // TODO: handle adding of public key for interface
}
/* Begin consuming messages from the reader.