Fix: ignore dublicated uuids

This commit is contained in:
Dorian Zedler 2023-02-17 12:15:04 +01:00
parent e9f72cf791
commit 5b2aefe659
Signed by: dorian
GPG key ID: 989DE36109AFA354

View file

@ -25,6 +25,7 @@ pub struct Comm {
handler: TimeCallback, handler: TimeCallback,
crypto: Crypto, crypto: Crypto,
topic: String, topic: String,
last_uuids: RefCell<Vec<uuid::Uuid>>
} }
impl Comm { impl Comm {
@ -36,8 +37,10 @@ impl Comm {
let mut create_opts = let mut create_opts =
mqtt::MqttOptions::new(uuid::Uuid::new_v4().to_string(), broker_domain, 8883); mqtt::MqttOptions::new(uuid::Uuid::new_v4().to_string(), broker_domain, 8883);
create_opts.set_keep_alive(Duration::from_secs(5)); create_opts.set_keep_alive(Duration::from_secs(5));
let transport = mqtt::Transport::Tls(mqtt::TlsConfiguration::default()); let transport = mqtt::Transport::Tls(mqtt::TlsConfiguration::default());
create_opts.set_transport(transport); 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); let crypto = Crypto::new(password, broker_domain);
@ -53,6 +56,7 @@ impl Comm {
handler, handler,
crypto, crypto,
topic, topic,
last_uuids: RefCell::new(Vec::new())
}) })
} }
@ -95,6 +99,12 @@ impl Comm {
return; 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() { if (self.handler)(msg.time).is_err() {
println!("[WARN] error in time handler -> not sending confirmation"); println!("[WARN] error in time handler -> not sending confirmation");
return; return;