mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 15:24:32 +01:00
only store cid in current
This commit is contained in:
@@ -8,7 +8,7 @@ use std::collections::HashMap;
|
|||||||
pub struct Connections {
|
pub struct Connections {
|
||||||
pub pubkey: Option<String>,
|
pub pubkey: Option<String>,
|
||||||
pub clients: HashMap<String, SignerType>,
|
pub clients: HashMap<String, SignerType>,
|
||||||
pub current: Option<(String, SignerType)>,
|
pub current: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connections {
|
impl Connections {
|
||||||
@@ -25,16 +25,16 @@ impl Connections {
|
|||||||
pub fn set_pubkey(&mut self, pk: &str) {
|
pub fn set_pubkey(&mut self, pk: &str) {
|
||||||
self.pubkey = Some(pk.to_string())
|
self.pubkey = Some(pk.to_string())
|
||||||
}
|
}
|
||||||
pub fn set_current(&mut self, cid: String, signer_type: SignerType) {
|
pub fn set_current(&mut self, cid: String) {
|
||||||
self.current = Some((cid, signer_type));
|
self.current = Some(cid);
|
||||||
}
|
}
|
||||||
pub fn add_client(&mut self, cid: &str, signer_type: SignerType) {
|
pub fn add_client(&mut self, cid: &str, signer_type: SignerType) {
|
||||||
self.clients.insert(cid.to_string(), signer_type);
|
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) {
|
pub fn remove_client(&mut self, cid: &str) {
|
||||||
self.clients.remove(cid);
|
self.clients.remove(cid);
|
||||||
if let Some((id, _)) = &self.current {
|
if let Some(id) = &self.current {
|
||||||
if id == cid {
|
if id == cid {
|
||||||
self.current = None;
|
self.current = None;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,8 +193,13 @@ fn pub_and_wait(
|
|||||||
// Try the current connection
|
// Try the current connection
|
||||||
// This returns None if 1) signer_type is set, and not equal to the current signer
|
// This returns None if 1) signer_type is set, and not equal to the current signer
|
||||||
// 2) If pub_timeout times out
|
// 2) If pub_timeout times out
|
||||||
let mut rep = if current.1 == msg.signer_type.unwrap_or(current.1) {
|
let mut rep = if client_list.get(¤t).unwrap()
|
||||||
pub_timeout(¤t.0, &msg.topic, &msg.message, &msg_rx, link_tx)
|
== msg
|
||||||
|
.signer_type
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(client_list.get(¤t).unwrap())
|
||||||
|
{
|
||||||
|
pub_timeout(¤t, &msg.topic, &msg.message, &msg_rx, link_tx)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -202,14 +207,14 @@ fn pub_and_wait(
|
|||||||
// If that failed, try looking for some other signer
|
// If that failed, try looking for some other signer
|
||||||
if rep.is_none() {
|
if rep.is_none() {
|
||||||
// If signer_type is set, we also filter for only these types
|
// If signer_type is set, we also filter for only these types
|
||||||
for (cid, signer_type) in client_list.into_iter().filter(|(k, v)| {
|
for (cid, _) in client_list.into_iter().filter(|(k, v)| {
|
||||||
k != ¤t.0 && v == msg.signer_type.as_ref().unwrap_or(v)
|
k != ¤t && v == msg.signer_type.as_ref().unwrap_or(v)
|
||||||
}) {
|
}) {
|
||||||
rep = pub_timeout(&cid, &msg.topic, &msg.message, &msg_rx, link_tx);
|
rep = pub_timeout(&cid, &msg.topic, &msg.message, &msg_rx, link_tx);
|
||||||
if rep.is_some() {
|
if rep.is_some() {
|
||||||
let mut cs = conns_.lock().unwrap();
|
let mut cs = conns_.lock().unwrap();
|
||||||
log::debug!("got the list lock!");
|
log::debug!("got the list lock!");
|
||||||
cs.set_current(cid.to_string(), signer_type);
|
cs.set_current(cid.to_string());
|
||||||
drop(cs);
|
drop(cs);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user