Merge branch 'master' into refractor/neo_reactor
This commit is contained in:
4 files changed
+35
-12
No files matched your search
@@ -90,6 +90,8 @@ pub struct BcCameraOpt {
|
||||
pub protocol: ConnectionProtocol,
|
||||
/// Discovery method to allow
|
||||
pub discovery: DiscoveryMethods,
|
||||
/// Maximum number of retries for discovery
|
||||
pub max_discovery_retries: usize,
|
||||
/// Credentials for login
|
||||
pub credentials: Credentials,
|
||||
/// Toggle debug print of underlying data
|
||||
@@ -219,17 +221,17 @@ impl BcCamera {
|
||||
// We loop infinitly and allow the caller to timeout at the
|
||||
// interval they desire
|
||||
let mut retry = 0;
|
||||
const MAX_RETRY: usize = 10;
|
||||
let max_retry: usize = options.max_discovery_retries;
|
||||
loop {
|
||||
tokio::task::yield_now().await;
|
||||
if let Ok(result) = discovery.get_registration(uid).await {
|
||||
reg_result = result;
|
||||
break;
|
||||
}
|
||||
if retry >= MAX_RETRY {
|
||||
if retry >= max_retry && max_retry > 0 {
|
||||
return Err(Error::DiscoveryTimeout);
|
||||
}
|
||||
log::info!("{}: Registration with reolink servers failed. Retrying: {}/{}", options.name, retry + 1, MAX_RETRY);
|
||||
log::info!("{}: Registration with reolink servers failed. Retrying: {}/{}", options.name, retry + 1, if max_retry > 0 {format!("{}", max_retry)} else {"infinite".to_string()});
|
||||
retry += 1;
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
// New discovery to get new client IDs
|
||||
|
||||
@@ -17,7 +17,7 @@ use lazy_static::lazy_static;
|
||||
use local_ip_address::local_ip;
|
||||
use log::*;
|
||||
use rand::{seq::SliceRandom, thread_rng, Rng};
|
||||
use std::collections::{btree_map::Entry, BTreeMap};
|
||||
use std::collections::{btree_map::Entry, BTreeMap, HashSet};
|
||||
use std::convert::TryInto;
|
||||
use std::net::{Ipv4Addr, SocketAddr, ToSocketAddrs};
|
||||
use std::sync::Arc;
|
||||
@@ -487,9 +487,9 @@ impl Discoverer {
|
||||
}),
|
||||
..
|
||||
},
|
||||
} if (dev.as_ref().map(|d| valid_addr(d)).unwrap_or(false)
|
||||
|| dmap.as_ref().map(|d| valid_addr(d)).unwrap_or(false)
|
||||
|| relay.as_ref().map(|d| valid_addr(d)).unwrap_or(false))
|
||||
} if (dev.as_ref().map(valid_addr).unwrap_or(false)
|
||||
|| dmap.as_ref().map(valid_addr).unwrap_or(false)
|
||||
|| relay.as_ref().map(valid_addr).unwrap_or(false))
|
||||
&& rsp != -1 =>
|
||||
{
|
||||
Some(Ok((sid, dev, dmap, relay)))
|
||||
@@ -511,11 +511,11 @@ impl Discoverer {
|
||||
// },
|
||||
// } if (dev
|
||||
// .as_ref()
|
||||
// .map(|d| valid_addr(d))
|
||||
// .map(valid_addr)
|
||||
// .unwrap_or(false)
|
||||
// || dmap
|
||||
// .as_ref()
|
||||
// .map(|d| valid_addr(d))
|
||||
// .map(valid_addr)
|
||||
// .unwrap_or(false)
|
||||
// || (relay.ip == format!("{}", socket.ip()) && relay.port == 0))
|
||||
// && rsp != -1 =>
|
||||
@@ -539,9 +539,9 @@ impl Discoverer {
|
||||
}),
|
||||
..
|
||||
},
|
||||
} if (dev.as_ref().map(|d| valid_addr(d)).unwrap_or(false)
|
||||
|| dmap.as_ref().map(|d| valid_addr(d)).unwrap_or(false)
|
||||
|| relay.as_ref().map(|d| valid_addr(d)).unwrap_or(false))
|
||||
} if (dev.as_ref().map(valid_addr).unwrap_or(false)
|
||||
|| dmap.as_ref().map(valid_addr).unwrap_or(false)
|
||||
|| relay.as_ref().map(valid_addr).unwrap_or(false))
|
||||
&& rsp == -1 =>
|
||||
{
|
||||
Some(Err(Error::RegisterError))
|
||||
@@ -1010,12 +1010,21 @@ impl Discovery {
|
||||
pub(crate) async fn get_registration(&self, uid: &str) -> Result<RegisterResult> {
|
||||
let lookups = self.discoverer.uid_lookup_all(uid).await?;
|
||||
|
||||
let checked_reg = Arc::new(RwLock::new(HashSet::new()));
|
||||
let reg_result = Box::pin(
|
||||
lookups
|
||||
.then(|lookup| {
|
||||
let discoverer = &self.discoverer;
|
||||
let client_id = self.client_id;
|
||||
|
||||
let thread_checked_reg = checked_reg.clone();
|
||||
async move {
|
||||
let mut locked_checked_reg = thread_checked_reg.write().await;
|
||||
if locked_checked_reg.contains(&lookup.reg) {
|
||||
return Result::Err(Error::Other("Already checked."));
|
||||
}
|
||||
locked_checked_reg.insert(lookup.reg);
|
||||
drop(locked_checked_reg);
|
||||
trace!("lookup: {:?}", lookup);
|
||||
let reg_result = discoverer.register_address(uid, client_id, &lookup).await;
|
||||
trace!("reg_result: {:?}", reg_result);
|
||||
|
||||
@@ -191,6 +191,13 @@ pub(crate) struct CameraConfig {
|
||||
|
||||
#[serde(default = "default_false", alias = "verbose")]
|
||||
pub(crate) debug: bool,
|
||||
|
||||
#[serde(
|
||||
default = "default_max_discovery_retries",
|
||||
alias = "retries",
|
||||
alias = "max_retries"
|
||||
)]
|
||||
pub(crate) max_discovery_retries: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Validate, Clone)]
|
||||
@@ -365,6 +372,10 @@ fn default_buffer_size() -> usize {
|
||||
25
|
||||
}
|
||||
|
||||
fn default_max_discovery_retries() -> usize {
|
||||
10
|
||||
}
|
||||
|
||||
pub(crate) static RESERVED_NAMES: &[&str] = &["anyone", "anonymous"];
|
||||
fn validate_username(name: &str) -> Result<(), ValidationError> {
|
||||
if name.trim().is_empty() {
|
||||
|
||||
@@ -98,6 +98,7 @@ impl AddressOrUid {
|
||||
password: camera_config.password.clone(),
|
||||
},
|
||||
debug: camera_config.debug,
|
||||
max_discovery_retries: camera_config.max_discovery_retries,
|
||||
};
|
||||
|
||||
trace!("Camera Info: {:?}", options);
|
||||
|
||||
Reference in new issue
Block a user