mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-19 00:04:25 +01:00
broker LSS integration, init, handle vls muts, connect to lss grpc, better chan msgs
This commit is contained in:
@@ -75,10 +75,9 @@ pub fn start_broker(
|
||||
});
|
||||
|
||||
// String is the client id
|
||||
let (msg_tx, msg_rx) = std::sync::mpsc::channel::<(String, Vec<u8>)>();
|
||||
let (lss_tx, lss_rx) = std::sync::mpsc::channel::<Vec<u8>>();
|
||||
let (msg_tx, msg_rx) = std::sync::mpsc::channel::<(String, String, Vec<u8>)>();
|
||||
|
||||
// receive from CLN, Frontend, or Controller
|
||||
// receive from CLN, Frontend, Controller, or LSS
|
||||
let conns_ = connections.clone();
|
||||
let _relay_task = std::thread::spawn(move || {
|
||||
while let Some(msg) = receiver.blocking_recv() {
|
||||
@@ -88,9 +87,8 @@ pub fn start_broker(
|
||||
if let Err(e) = link_tx.publish(pub_topic, msg.message.clone()) {
|
||||
log::error!("failed to pub to link_tx! {} {:?}", cid, e);
|
||||
}
|
||||
let rep = msg_rx.recv();
|
||||
if let Ok((cid, reply)) = rep {
|
||||
if let Err(_) = msg.reply_tx.send(ChannelReply { reply }) {
|
||||
if let Ok((cid, topic, reply)) = msg_rx.recv() {
|
||||
if let Err(_) = msg.reply_tx.send(ChannelReply { reply, topic }) {
|
||||
log::warn!("could not send on reply_tx {}", cid);
|
||||
}
|
||||
}
|
||||
@@ -107,15 +105,15 @@ pub fn start_broker(
|
||||
}
|
||||
for client in client_list.iter() {
|
||||
let pub_topic = format!("{}/{}", client, msg.topic);
|
||||
log::info!("SENDING TO {} on topic {}", client, msg.topic);
|
||||
if let Err(e) = link_tx.publish(pub_topic, msg.message.clone()) {
|
||||
log::error!("failed to pub to link_tx! {:?}", e);
|
||||
}
|
||||
// and receive from the correct client (or timeout to next)
|
||||
let dur = Duration::from_secs(9);
|
||||
let rep = msg_rx.recv_timeout(dur);
|
||||
if let Ok((cid, reply)) = rep {
|
||||
if let Ok((cid, topic, reply)) = msg_rx.recv_timeout(dur) {
|
||||
if &cid == client {
|
||||
if let Err(_) = msg.reply_tx.send(ChannelReply { reply }) {
|
||||
if let Err(_) = msg.reply_tx.send(ChannelReply { reply, topic }) {
|
||||
log::warn!("could not send on reply_tx");
|
||||
}
|
||||
break 'retry_loop;
|
||||
@@ -144,19 +142,15 @@ pub fn start_broker(
|
||||
let topic = topic_res.unwrap();
|
||||
if topic.ends_with(topics::ERROR) {
|
||||
let _ = error_sender.send(f.publish.payload.to_vec());
|
||||
} else if topic.ends_with(topics::LSS_PUB) {
|
||||
// send to LSS client here
|
||||
// get the hmac back, pub to the device
|
||||
if let Err(e) = lss_tx.send(f.publish.payload.to_vec()) {
|
||||
log::error!("failed to pub to lss_tx! {:?}", e);
|
||||
}
|
||||
} else {
|
||||
// VLS, CONTROL, LSS
|
||||
let ts: Vec<&str> = topic.split("/").collect();
|
||||
if ts.len() != 2 {
|
||||
continue;
|
||||
}
|
||||
let cid = ts[0].to_string();
|
||||
if let Err(e) = msg_tx.send((cid, f.publish.payload.to_vec())) {
|
||||
let topic = ts[1].to_string();
|
||||
if let Err(e) = msg_tx.send((cid, topic, f.publish.payload.to_vec())) {
|
||||
log::error!("failed to pub to msg_tx! {:?}", e);
|
||||
}
|
||||
}
|
||||
@@ -182,11 +176,11 @@ fn subs(cid: &str, mut ltx: LinkTx) {
|
||||
ltx.subscribe(format!("{}/{}", cid, topics::CONTROL_RETURN))
|
||||
.unwrap();
|
||||
ltx.subscribe(format!("{}/{}", cid, topics::ERROR)).unwrap();
|
||||
ltx.subscribe(format!("{}/{}", cid, topics::LSS_PUB))
|
||||
ltx.subscribe(format!("{}/{}", cid, topics::LSS_RES))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn unsubs(cid: &str, mut ltx: LinkTx) {
|
||||
fn unsubs(_cid: &str, mut _ltx: LinkTx) {
|
||||
// ltx.unsubscribe(format!("{}/{}", cid, topics::VLS_RETURN))
|
||||
// .unwrap();
|
||||
// ltx.unsubscribe(format!("{}/{}", cid, topics::CONTROL_RETURN))
|
||||
|
||||
Reference in New Issue
Block a user