mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 07:14:23 +01:00
only store cid in current
This commit is contained in:
@@ -8,7 +8,7 @@ use std::collections::HashMap;
|
||||
pub struct Connections {
|
||||
pub pubkey: Option<String>,
|
||||
pub clients: HashMap<String, SignerType>,
|
||||
pub current: Option<(String, SignerType)>,
|
||||
pub current: Option<String>,
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user