Skip to content

Commit

Permalink
Fix how duplicates are handled in ONVIF (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-goldenring authored Sep 30, 2021
1 parent 49722c5 commit d1494d6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions discovery-handlers/onvif/src/discovery_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub mod util {
use super::{common, probe_types, to_deserialize, to_serialize};
use akri_discovery_utils::filtering::{FilterList, FilterType};
use log::{error, info, trace};
use std::collections::HashSet;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use tokio::{
io::ErrorKind,
Expand Down Expand Up @@ -202,7 +203,10 @@ pub mod util {
.collect::<Vec<String>>()
}

async fn get_responsive_uris(uris: Vec<String>, onvif_query: &impl OnvifQuery) -> Vec<String> {
async fn get_responsive_uris(
uris: HashSet<String>,
onvif_query: &impl OnvifQuery,
) -> Vec<String> {
let futures: Vec<_> = uris
.iter()
.map(|uri| onvif_query.is_device_responding(uri))
Expand Down Expand Up @@ -310,7 +314,7 @@ pub mod util {
scopes_filters: Option<&FilterList>,
timeout: Duration,
) -> Result<Vec<String>, anyhow::Error> {
let mut broadcast_responses = std::collections::HashSet::new();
let mut broadcast_responses = Vec::new();

let start = Instant::now();
loop {
Expand All @@ -323,7 +327,7 @@ pub mod util {

match try_recv_string(socket, time_left).await {
Ok(s) => {
broadcast_responses.insert(s.to_lowercase());
broadcast_responses.push(s);
}
Err(e) => match e.kind() {
ErrorKind::WouldBlock | ErrorKind::TimedOut => {
Expand All @@ -341,7 +345,7 @@ pub mod util {
"simple_onvif_discover - uris discovered by udp broadcast {:?}",
broadcast_responses
);
let mut filtered_uris = Vec::new();
let mut filtered_uris = std::collections::HashSet::new();
broadcast_responses.into_iter().for_each(|r| {
filtered_uris.extend(get_scope_filtered_uris_from_discovery_response(
&r,
Expand Down

0 comments on commit d1494d6

Please sign in to comment.