aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-03-09 12:11:36 +0100
committerAlex Auvolat <alex@adnab.me>2023-03-09 12:11:36 +0100
commit298a01d710f85eb56f3802e9d41657d50f5bcd6d (patch)
tree792aa4e0d3ec93bdaeb77be03a4205aacfe3e6db
parentc2940724de4f1072c26ce2a4e856ab671e930620 (diff)
downloadwgautomesh-298a01d710f85eb56f3802e9d41657d50f5bcd6d.tar.gz
wgautomesh-298a01d710f85eb56f3802e9d41657d50f5bcd6d.zip
also set up peers if endpoint is not known
-rw-r--r--src/main.rs17
1 files 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(())