Skip to content

Commit

Permalink
Cargo fmt and better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelYvon committed Mar 2, 2024
1 parent f11edfe commit df92a26
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions onvif/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl DiscoveryBuilder {
let probe = Arc::new(build_probe());
let probe_xml = yaserde::ser::to_string(probe.as_ref()).map_err(Error::Serde)?;

debug!("Probe XML: {}", probe_xml);
debug!("Unicast Probe XML: {}. Since you are using unicast, some devices might not be detected", probe_xml);

let message_id = Arc::new(probe.header.message_id.clone());
let payload = Arc::new(probe_xml.as_bytes().to_vec());
Expand Down Expand Up @@ -182,7 +182,7 @@ impl DiscoveryBuilder {
}
},
))
.await
.await
};

tokio::spawn(timeout(*duration, produce_devices));
Expand All @@ -202,12 +202,17 @@ impl DiscoveryBuilder {

let socket = {
let local_socket_addr = SocketAddr::new(*listen_address, Self::LOCAL_PORT);
let multi_socket_addr = SocketAddr::new(IpAddr::V4(Self::WS_DISCOVERY_BROADCAST_ADDR), Self::MULTI_PORT);
let multi_socket_addr = SocketAddr::new(
IpAddr::V4(Self::WS_DISCOVERY_BROADCAST_ADDR),
Self::MULTI_PORT,
);

let socket = UdpSocket::bind(local_socket_addr).await?;

match listen_address {
IpAddr::V4(addr) => socket.join_multicast_v4(Self::WS_DISCOVERY_BROADCAST_ADDR, *addr)?,
IpAddr::V4(addr) => {
socket.join_multicast_v4(Self::WS_DISCOVERY_BROADCAST_ADDR, *addr)?
}
IpAddr::V6(_) => return Err(Error::Unsupported("Discovery with IPv6".to_owned())),
}

Expand Down Expand Up @@ -314,7 +319,7 @@ impl DiscoveryBuilder {
/// println!("Devices found: {:?}", devices);
/// };
/// ```
pub async fn run(&self) -> Result<impl Stream<Item=Device>, Error> {
pub async fn run(&self) -> Result<impl Stream<Item = Device>, Error> {
let Self {
duration,
listen_address,
Expand All @@ -326,10 +331,9 @@ impl DiscoveryBuilder {
DiscoveryMode::Unicast {
network,
network_mask,
} => {
self.run_unicast(duration, listen_address, network, network_mask)
}
}.await
} => self.run_unicast(duration, listen_address, network, network_mask),

Check failure on line 334 in onvif/src/discovery/mod.rs

View workflow job for this annotation

GitHub Actions / build

`match` arms have incompatible types
}
.await
}
}

Expand Down Expand Up @@ -384,10 +388,10 @@ fn build_probe() -> probe::Envelope {
}
}

use crate::discovery::network_enumeration::enumerate_network_v4;
use std::iter::Iterator;
use std::net::Ipv6Addr;

Check warning on line 393 in onvif/src/discovery/mod.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `std::net::Ipv6Addr`
use tokio_stream::StreamExt;

Check warning on line 394 in onvif/src/discovery/mod.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `tokio_stream::StreamExt`
use crate::discovery::network_enumeration::enumerate_network_v4;

#[tokio::test]
async fn test_unicast() {
Expand Down

0 comments on commit df92a26

Please sign in to comment.