also set up peers if endpoint is not known

This commit is contained in:
Alex 2023-03-09 12:11:36 +01:00
parent c2940724de
commit 298a01d710
1 changed files with 15 additions and 2 deletions

View File

@ -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(())