Skip to content

Commit

Permalink
monitor: use only TLS connections.
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Perchanov <[email protected]>
  • Loading branch information
demisrael committed Jul 31, 2024
1 parent 5667130 commit 4d7f157
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,25 @@ impl Monitor {
// /// Get JSON string representing node information (id, url, provider, link)
pub fn election(&self, params: &PathParams) -> Option<String> {
let connections = self.connections.read().unwrap();
let connections = connections
.get(params)
.expect("Monitor: expecting existing connection params")
.iter()
.filter(|connection| connection.is_available())
.collect::<Vec<_>>();

if !connections.is_empty() {
let node = select_with_weighted_rng(connections);
serde_json::to_string(&Output::from(node)).ok()
} else {
None
}
if params.tls == TlsKind::Tls {
let connections = connections
.get(params)
.expect("Monitor: expecting existing connection params")
.iter()
.filter(|connection| connection.is_available())
.collect::<Vec<_>>();

if !connections.is_empty() {
let node = select_with_weighted_rng(connections);
serde_json::to_string(&Output::from(node)).ok()
} else {
None
}
} else {
None
}
}
}

fn select_with_weighted_rng(nodes: Vec<&Arc<Connection>>) -> &Arc<Connection> {
// Calculate total weight based on the position in the sorted list
Expand Down

0 comments on commit 4d7f157

Please sign in to comment.