Skip to content

Commit

Permalink
Simplify logic in the inject_endpoints() function
Browse files Browse the repository at this point in the history
Co-authored-by: Matěj Laitl <[email protected]>
  • Loading branch information
bschwind and strohel authored Mar 19, 2024
1 parent d2292e4 commit 24d5bbb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions server/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ pub mod user;
pub fn inject_endpoints(session: &Session, peers: &mut Vec<Peer>) {
for peer in peers {
let endpoints = session.context.endpoints.read();
let wg_endpoint = endpoints.get(&peer.public_key);

if peer.contents.endpoint.is_some() {
if let Some(wg_endpoint) = wg_endpoint {
if let Some(wg_endpoint) = endpoints.get(&peer.public_key) {
if peer.contents.endpoint.is_none() {
peer.contents.endpoint = Some(wg_endpoint.to_owned().into());
} else {
// The peer already has an endpoint specified, but it might be stale.
// If there is an endpoint reported from wireguard, we should add it
// to the list of candidates so others can try to connect using it.
peer.contents.candidates.push(wg_endpoint.to_owned().into());
}
} else if let Some(wg_endpoint) = wg_endpoint {
peer.contents.endpoint = Some(wg_endpoint.to_owned().into());
}
}
}

0 comments on commit 24d5bbb

Please sign in to comment.