From 298a01d710f85eb56f3802e9d41657d50f5bcd6d Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 9 Mar 2023 12:11:36 +0100 Subject: also set up peers if endpoint is not known --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 15896a4..855cb39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -379,8 +379,7 @@ impl State { } } endpoints.sort(); - if !endpoints.is_empty() { - let endpoint = endpoints[i % endpoints.len()]; + if let Some(endpoint) = endpoints.get(i % endpoints.len()) { info!("Configure {} with endpoint {}", peer.pubkey, endpoint.0); Command::new("wg") .args([ @@ -396,6 +395,20 @@ impl State { &format!("{}/32", peer.address), ]) .output()?; + } else { + info!("Configure {} with no known endpoint", peer.pubkey); + Command::new("wg") + .args([ + "set", + &daemon.config.interface, + "peer", + &peer.pubkey, + "persistent-keepalive", + "20", + "allowed-ips", + &format!("{}/32", peer.address), + ]) + .output()?; } } Ok(()) -- cgit v1.2.3