From e6f8ea8e348d076044987764b1cdf895242b7e75 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Fri, 7 Jul 2023 13:15:32 -0700 Subject: [PATCH] both init_1 and init_2 topics --- Cargo.lock | 10 +++++----- broker/Cargo.lock | 8 ++++---- broker/Cargo.toml | 4 ++-- broker/src/lss.rs | 8 ++++---- broker/src/mqtt.rs | 6 ++++-- sphinx-key/Cargo.toml | 6 +++--- sphinx-key/src/conn/mqtt.rs | 3 ++- sphinx-key/src/core/events.rs | 10 ++++++++-- sphinx-key/src/core/lss.rs | 7 ++++--- 9 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ea2dde..ae53aa4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1195,7 +1195,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "lss-connector" version = "0.1.0" -source = "git+https://github.com/stakwork/sphinx-rs.git?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "log", @@ -1775,7 +1775,7 @@ dependencies = [ [[package]] name = "sphinx-auther" version = "0.1.12" -source = "git+https://github.com/stakwork/sphinx-rs.git?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "base64", @@ -1787,7 +1787,7 @@ dependencies = [ [[package]] name = "sphinx-crypter" version = "0.1.0" -source = "git+https://github.com/stakwork/sphinx-rs.git?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "chacha20poly1305", @@ -1798,7 +1798,7 @@ dependencies = [ [[package]] name = "sphinx-glyph" version = "0.1.2" -source = "git+https://github.com/stakwork/sphinx-rs.git?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "hex", @@ -1850,7 +1850,7 @@ dependencies = [ [[package]] name = "sphinx-signer" version = "0.1.0" -source = "git+https://github.com/stakwork/sphinx-rs.git?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "bip39", diff --git a/broker/Cargo.lock b/broker/Cargo.lock index e5912d5..d6fdfea 100644 --- a/broker/Cargo.lock +++ b/broker/Cargo.lock @@ -1702,7 +1702,7 @@ dependencies = [ [[package]] name = "lss-connector" version = "0.1.0" -source = "git+https://github.com/stakwork/sphinx-rs?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "lightning-storage-server", @@ -3311,7 +3311,7 @@ dependencies = [ [[package]] name = "sphinx-auther" version = "0.1.12" -source = "git+https://github.com/stakwork/sphinx-rs?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "base64 0.13.1", @@ -3323,7 +3323,7 @@ dependencies = [ [[package]] name = "sphinx-glyph" version = "0.1.2" -source = "git+https://github.com/stakwork/sphinx-rs?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "hex", @@ -3369,7 +3369,7 @@ dependencies = [ [[package]] name = "sphinx-signer" version = "0.1.0" -source = "git+https://github.com/stakwork/sphinx-rs?rev=78d8c989bed15f63e5cc7df42e19ee7117c33807#78d8c989bed15f63e5cc7df42e19ee7117c33807" +source = "git+https://github.com/stakwork/sphinx-rs?rev=38d7fa25e860b61a813ca8c3fad17f699daf2f08#38d7fa25e860b61a813ca8c3fad17f699daf2f08" dependencies = [ "anyhow", "bip39", diff --git a/broker/Cargo.toml b/broker/Cargo.toml index d6e5347..571ac32 100644 --- a/broker/Cargo.toml +++ b/broker/Cargo.toml @@ -35,8 +35,8 @@ vls-protocol = { git = "https://gitlab.com/lightning-signer/validating-li vls-protocol-client = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "e199c70cbacd3404e7cecf95bb75ca02afd4cffd" } vls-proxy = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "e199c70cbacd3404e7cecf95bb75ca02afd4cffd" } -lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "78d8c989bed15f63e5cc7df42e19ee7117c33807" } -sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "78d8c989bed15f63e5cc7df42e19ee7117c33807" } +lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "38d7fa25e860b61a813ca8c3fad17f699daf2f08" } +sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "38d7fa25e860b61a813ca8c3fad17f699daf2f08" } # lss-connector = { path = "../../sphinx-rs/lss-connector" } # sphinx-signer = { path = "../../sphinx-rs/signer" } diff --git a/broker/src/lss.rs b/broker/src/lss.rs index c66a51b..a86c0c0 100644 --- a/broker/src/lss.rs +++ b/broker/src/lss.rs @@ -35,7 +35,7 @@ async fn send_init( msg_bytes: Vec, mqtt_tx: &mpsc::Sender, ) -> Result { - let reply = ChannelRequest::send(topics::INIT_MSG, msg_bytes, &mqtt_tx).await?; + let reply = ChannelRequest::send(topics::INIT_1_MSG, msg_bytes, &mqtt_tx).await?; let ir = Response::from_slice(&reply)?.as_init()?; Ok(ir) } @@ -44,7 +44,7 @@ async fn send_created( msg_bytes: Vec, mqtt_tx: &mpsc::Sender, ) -> Result { - let reply2 = ChannelRequest::send(topics::INIT_MSG, msg_bytes, &mqtt_tx).await?; + let reply2 = ChannelRequest::send(topics::INIT_2_MSG, msg_bytes, &mqtt_tx).await?; let cr = Response::from_slice(&reply2)?.as_created()?; Ok(cr) } @@ -111,7 +111,7 @@ async fn dance_step_1( mqtt_tx: &mpsc::Sender, ) -> Result { let init_bytes = lss_conn.make_init_msg().await?; - let reply = ChannelRequest::send_for(cid, topics::INIT_MSG, init_bytes, mqtt_tx).await?; + let reply = ChannelRequest::send_for(cid, topics::INIT_1_MSG, init_bytes, mqtt_tx).await?; let ir = Response::from_slice(&reply)?.as_init()?; Ok(ir) } @@ -123,7 +123,7 @@ async fn dance_step_2( ir: &InitResponse, ) -> Result<()> { let state_bytes = lss_conn.get_created_state_msg(ir).await?; - let reply2 = ChannelRequest::send_for(cid, topics::INIT_MSG, state_bytes, mqtt_tx).await?; + let reply2 = ChannelRequest::send_for(cid, topics::INIT_2_MSG, state_bytes, mqtt_tx).await?; let cr = Response::from_slice(&reply2)?.as_created()?; lss_conn.handle(Response::Created(cr)).await?; Ok(()) diff --git a/broker/src/mqtt.rs b/broker/src/mqtt.rs index 637b068..301a0d4 100644 --- a/broker/src/mqtt.rs +++ b/broker/src/mqtt.rs @@ -111,7 +111,7 @@ pub fn start_broker( } else { // VLS, CONTROL, LSS let pld = f.publish.payload.to_vec(); - if topic_end == topics::INIT_RES { + if topic_end == topics::INIT_1_RES || topic_end == topics::INIT_2_RES { if let Err(e) = init_tx.send((cid, topic_end, pld)) { log::error!("failed to pub to init_tx! {:?}", e); } @@ -225,7 +225,9 @@ fn subs(cid: &str, mut ltx: LinkTx) { ltx.subscribe(format!("{}/{}", cid, topics::ERROR)).unwrap(); ltx.subscribe(format!("{}/{}", cid, topics::LSS_RES)) .unwrap(); - ltx.subscribe(format!("{}/{}", cid, topics::INIT_RES)) + ltx.subscribe(format!("{}/{}", cid, topics::INIT_1_RES)) + .unwrap(); + ltx.subscribe(format!("{}/{}", cid, topics::INIT_2_RES)) .unwrap(); } diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index e78f399..d76d71b 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -19,10 +19,10 @@ serde_json = { version = "1.0.81", default-features = false } serde_urlencoded = "0.7.1" url = "2" -lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "78d8c989bed15f63e5cc7df42e19ee7117c33807" } +lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "38d7fa25e860b61a813ca8c3fad17f699daf2f08" } # lss-connector = { path = "../../sphinx-rs/lss-connector", default-features = false } -sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "78d8c989bed15f63e5cc7df42e19ee7117c33807" } -sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "78d8c989bed15f63e5cc7df42e19ee7117c33807" } +sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "38d7fa25e860b61a813ca8c3fad17f699daf2f08" } +sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "38d7fa25e860b61a813ca8c3fad17f699daf2f08" } # sphinx-signer = { path = "../../sphinx-rs/signer", optional = true } anyhow.workspace = true diff --git a/sphinx-key/src/conn/mqtt.rs b/sphinx-key/src/conn/mqtt.rs index a1dd5bb..11f71a8 100644 --- a/sphinx-key/src/conn/mqtt.rs +++ b/sphinx-key/src/conn/mqtt.rs @@ -113,7 +113,8 @@ pub fn make_client( tx.send(CoreEvent::VlsMessage(data)) .expect("couldnt send Event::VlsMessage"); } else if topic.ends_with(topics::LSS_MSG) - || topic.ends_with(topics::INIT_MSG) + || topic.ends_with(topics::INIT_1_MSG) + || topic.ends_with(topics::INIT_2_MSG) { log::debug!("received data len {}", data.len()); tx.send(CoreEvent::LssMessage(data)) diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 29f375f..8273aad 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -38,7 +38,8 @@ pub enum Event { pub const ROOT_STORE: &str = "/sdcard/store"; pub const SUB_TOPICS: &[&str] = &[ - topics::INIT_MSG, + topics::INIT_1_MSG, + topics::INIT_2_MSG, topics::LSS_MSG, topics::VLS, topics::CONTROL, @@ -231,7 +232,12 @@ fn restart_esp_if_memory_low() { let size = esp_idf_sys::heap_caps_get_free_size(4); let block = esp_idf_sys::heap_caps_get_largest_free_block(4); let threshold = 35000; - log::info!("Available DRAM: {}, Max block: {}, Restart Threshold: {}", size, block, threshold); + log::info!( + "Available DRAM: {}, Max block: {}, Restart Threshold: {}", + size, + block, + threshold + ); if block < threshold { log::info!("Restarting esp!"); esp_idf_sys::esp_restart(); diff --git a/sphinx-key/src/core/lss.rs b/sphinx-key/src/core/lss.rs index 0e2d1f4..fd82129 100644 --- a/sphinx-key/src/core/lss.rs +++ b/sphinx-key/src/core/lss.rs @@ -27,8 +27,8 @@ pub fn init_lss( }; let (lss_signer, res1) = LssSigner::new(&handler_builder, &server_pubkey); - let lss_res_topic = format!("{}/{}", client_id, topics::INIT_RES); - mqtt.publish(&lss_res_topic, QOS, false, &res1) + let lss_res_1_topic = format!("{}/{}", client_id, topics::INIT_1_RES); + mqtt.publish(&lss_res_1_topic, QOS, false, &res1) .expect("could not publish LSS response"); let created = loop { @@ -40,7 +40,8 @@ pub fn init_lss( }; let (root_handler, res2) = lss_signer.build_with_lss(created, handler_builder)?; - mqtt.publish(&lss_res_topic, QOS, false, &res2) + let lss_res_2_topic = format!("{}/{}", client_id, topics::INIT_2_RES); + mqtt.publish(&lss_res_2_topic, QOS, false, &res2) .expect("could not publish LSS response 2"); Ok((root_handler, lss_signer))