diff --git a/broker/src/conn.rs b/broker/src/conn.rs index ee963da..b606b1b 100644 --- a/broker/src/conn.rs +++ b/broker/src/conn.rs @@ -8,7 +8,7 @@ use std::collections::HashMap; pub struct Connections { pub pubkey: Option, pub clients: HashMap, - pub current: Option<(String, SignerType)>, + pub current: Option, } impl Connections { @@ -25,16 +25,16 @@ impl Connections { pub fn set_pubkey(&mut self, pk: &str) { self.pubkey = Some(pk.to_string()) } - pub fn set_current(&mut self, cid: String, signer_type: SignerType) { - self.current = Some((cid, signer_type)); + pub fn set_current(&mut self, cid: String) { + self.current = Some(cid); } pub fn add_client(&mut self, cid: &str, signer_type: SignerType) { self.clients.insert(cid.to_string(), signer_type); - self.current = Some((cid.to_string(), signer_type)); + self.current = Some(cid.to_string()); } pub fn remove_client(&mut self, cid: &str) { self.clients.remove(cid); - if let Some((id, _)) = &self.current { + if let Some(id) = &self.current { if id == cid { self.current = None; } diff --git a/broker/src/mqtt.rs b/broker/src/mqtt.rs index fccb3f2..e758a93 100644 --- a/broker/src/mqtt.rs +++ b/broker/src/mqtt.rs @@ -193,8 +193,13 @@ fn pub_and_wait( // Try the current connection // This returns None if 1) signer_type is set, and not equal to the current signer // 2) If pub_timeout times out - let mut rep = if current.1 == msg.signer_type.unwrap_or(current.1) { - pub_timeout(¤t.0, &msg.topic, &msg.message, &msg_rx, link_tx) + let mut rep = if client_list.get(¤t).unwrap() + == msg + .signer_type + .as_ref() + .unwrap_or(client_list.get(¤t).unwrap()) + { + pub_timeout(¤t, &msg.topic, &msg.message, &msg_rx, link_tx) } else { None }; @@ -202,14 +207,14 @@ fn pub_and_wait( // If that failed, try looking for some other signer if rep.is_none() { // If signer_type is set, we also filter for only these types - for (cid, signer_type) in client_list.into_iter().filter(|(k, v)| { - k != ¤t.0 && v == msg.signer_type.as_ref().unwrap_or(v) + for (cid, _) in client_list.into_iter().filter(|(k, v)| { + k != ¤t && v == msg.signer_type.as_ref().unwrap_or(v) }) { rep = pub_timeout(&cid, &msg.topic, &msg.message, &msg_rx, link_tx); if rep.is_some() { let mut cs = conns_.lock().unwrap(); log::debug!("got the list lock!"); - cs.set_current(cid.to_string(), signer_type); + cs.set_current(cid.to_string()); drop(cs); break; }