aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-04-21 14:14:07 +0200
committerAlex Auvolat <alex@adnab.me>2023-04-21 14:17:20 +0200
commit49d94dae1d753c1f3349be7ea9bc7e7978c0af15 (patch)
treec6b355a755b34fa0d9db75d89b212aceea7e0944
parent6d0cb99b998a3a04562fa55d0a68cdda733e81cc (diff)
downloadD53-49d94dae1d753c1f3349be7ea9bc7e7978c0af15.tar.gz
D53-49d94dae1d753c1f3349be7ea9bc7e7978c0af15.zip
less noise
-rw-r--r--src/autodiscovery.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/autodiscovery.rs b/src/autodiscovery.rs
index 7b61da6..86276c1 100644
--- a/src/autodiscovery.rs
+++ b/src/autodiscovery.rs
@@ -13,13 +13,13 @@ use tracing::*;
use df_consul::*;
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct DiplonatAutodiscoveryResult<A> {
pub timestamp: u64,
pub address: Option<A>,
}
-#[derive(Default, Debug)]
+#[derive(Default, Debug, Eq, PartialEq)]
pub struct AutodiscoveredAddresses {
pub ipv4: HashMap<String, DiplonatAutodiscoveryResult<Ipv4Addr>>,
pub ipv6: HashMap<String, DiplonatAutodiscoveryResult<Ipv6Addr>>,
@@ -30,6 +30,7 @@ pub fn watch_autodiscovered_ips(
mut must_exit: watch::Receiver<bool>,
) -> watch::Receiver<Arc<AutodiscoveredAddresses>> {
let (tx, rx) = watch::channel(Arc::new(AutodiscoveredAddresses::default()));
+ let rx2 = rx.clone();
tokio::spawn(async move {
let mut last_index = None;
@@ -66,9 +67,13 @@ pub fn watch_autodiscovered_ips(
}
}
- debug!("Autodiscovered addresses fetched from Consul: {:?}", addresses);
+ if addresses.strip_timestamps() != rx2.borrow().strip_timestamps() {
+ addresses.dump();
+ }
+
if tx.send(Arc::new(addresses)).is_err() {
info!("Autodiscovered addresses watcher terminating");
+ return;
}
}
});
@@ -103,6 +108,24 @@ fn parse_autodiscovered_address(
Ok(())
}
+impl AutodiscoveredAddresses {
+ fn strip_timestamps(&self) -> (HashMap<&str, Option<Ipv4Addr>>, HashMap<&str, Option<Ipv6Addr>>) {
+ (self.ipv4.iter().map(|(k, v)| (k.as_str(), v.address)).collect(),
+ self.ipv6.iter().map(|(k, v)| (k.as_str(), v.address)).collect())
+ }
+
+ fn dump(&self) {
+ println!("---- Autodiscovered addresses (fetched from DiploNAT): ----");
+ for (k, v) in self.ipv4.iter() {
+ println!(" IPv4 {} {} {:?}", k, v.timestamp, v.address);
+ }
+ for (k, v) in self.ipv6.iter() {
+ println!(" IPv6 {} {} {:?}", k, v.timestamp, v.address);
+ }
+ println!("");
+ }
+}
+
pub fn timestamp() -> u64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)