From 5b2aefe659f26d839a29a36a4bdbc675a10c4b90 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 17 Feb 2023 12:15:04 +0100 Subject: [PATCH] Fix: ignore dublicated uuids --- receiver/src/comm.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/receiver/src/comm.rs b/receiver/src/comm.rs index 32b3347..00ff9a9 100644 --- a/receiver/src/comm.rs +++ b/receiver/src/comm.rs @@ -25,6 +25,7 @@ pub struct Comm { handler: TimeCallback, crypto: Crypto, topic: String, + last_uuids: RefCell> } impl Comm { @@ -36,9 +37,11 @@ impl Comm { let mut create_opts = mqtt::MqttOptions::new(uuid::Uuid::new_v4().to_string(), broker_domain, 8883); create_opts.set_keep_alive(Duration::from_secs(5)); + let transport = mqtt::Transport::Tls(mqtt::TlsConfiguration::default()); create_opts.set_transport(transport); - let (mut cli, conn) = mqtt::Client::new(create_opts, 10); + + let (mut cli, conn) = mqtt::Client::new(create_opts, 10); let crypto = Crypto::new(password, broker_domain); @@ -53,6 +56,7 @@ impl Comm { handler, crypto, topic, + last_uuids: RefCell::new(Vec::new()) }) } @@ -95,6 +99,12 @@ impl Comm { return; } + if self.last_uuids.borrow().contains(&msg.id) { + return; + } + + self.last_uuids.borrow_mut().push(msg.id); + if (self.handler)(msg.time).is_err() { println!("[WARN] error in time handler -> not sending confirmation"); return;