break out massive loop
This commit is contained in:
parent
e535c66b50
commit
ba401ccdc5
@ -1,13 +1,13 @@
|
||||
mod cloudflare;
|
||||
mod config;
|
||||
mod logging;
|
||||
mod public_ip;
|
||||
pub mod utils;
|
||||
mod logging;
|
||||
|
||||
pub use cloudflare::CloudflareClient;
|
||||
pub use config::{get_config_path, read_config, Config};
|
||||
pub use public_ip::get_current_public_ipv4;
|
||||
pub use logging::init_logger;
|
||||
pub use public_ip::get_current_public_ipv4;
|
||||
|
||||
pub const PROGRAM_NAME: &'static str = "dynip-cloudflare";
|
||||
pub const MAX_ERORS_IN_ROW_DEFAULT: usize = 10;
|
||||
|
33
src/main.rs
33
src/main.rs
@ -5,7 +5,7 @@ use std::sync::{
|
||||
|
||||
use futures::stream::StreamExt;
|
||||
use log::{debug, error, info, log_enabled, Level};
|
||||
use netlink_packet_core::NetlinkPayload;
|
||||
use netlink_packet_core::{NetlinkMessage, NetlinkPayload};
|
||||
use netlink_packet_route::RouteNetlinkMessage as RtnlMessage;
|
||||
use netlink_sys::{AsyncSocket, SocketAddr};
|
||||
use rtnetlink::new_connection;
|
||||
@ -81,25 +81,35 @@ async fn main() {
|
||||
|
||||
while !should_exit.load(Ordering::SeqCst) {
|
||||
tokio::select! {
|
||||
_ = notify.notified() => {
|
||||
break;
|
||||
}
|
||||
_ = notify.notified() => break,
|
||||
message = messages.next() => {
|
||||
if let Some((message, _)) = message {
|
||||
handle_message(message, &mut cloudflare, &mut errs_counter, errs_max).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_message(
|
||||
message: NetlinkMessage<RtnlMessage>,
|
||||
cloudflare: &mut CloudflareClient,
|
||||
errs_counter: &mut usize,
|
||||
errs_max: usize,
|
||||
) {
|
||||
match message.payload {
|
||||
NetlinkPayload::InnerMessage(RtnlMessage::NewAddress(msg)) => {
|
||||
if log_enabled!(Level::Debug) {
|
||||
debug!("New IPv4 address message: {:?}", msg);
|
||||
} else {
|
||||
info!("New IPv4 address");
|
||||
|
||||
if let Err(e) = cloudflare.check().await {
|
||||
errs_counter += 1;
|
||||
*errs_counter += 1;
|
||||
error!(
|
||||
"Failed to check cloudflare ({}/{}): {:?}",
|
||||
errs_counter, errs_max, &e
|
||||
);
|
||||
if errs_counter >= errs_max {
|
||||
if *errs_counter >= errs_max {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -117,14 +127,13 @@ async fn main() {
|
||||
debug!("New link message (interface connected): {:?}", link);
|
||||
} else {
|
||||
info!("New link (interface connected)");
|
||||
|
||||
if let Err(e) = cloudflare.check().await {
|
||||
errs_counter += 1;
|
||||
*errs_counter += 1;
|
||||
error!(
|
||||
"Failed to check cloudflare ({}/{}): {:?}",
|
||||
errs_counter, errs_max, &e
|
||||
);
|
||||
if errs_counter >= errs_max {
|
||||
if *errs_counter >= errs_max {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -143,8 +152,4 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user