mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-23 16:44:21 +01:00
fix integration test make_event_loop
This commit is contained in:
@@ -12,13 +12,17 @@ Find the path to your `riscv32-esp-elf-gcc` binary within the `.embuild` dir:
|
||||
|
||||
`cargo build --features pingpong`
|
||||
|
||||
### flash test
|
||||
|
||||
`espflash target/riscv32imc-esp-espidf/debug/sphinx-key`
|
||||
|
||||
### build release
|
||||
|
||||
`cargo build --release`
|
||||
|
||||
### flash
|
||||
### flash release
|
||||
|
||||
`espflash target/riscv32imc-esp-espidf/debug/sphinx-key`
|
||||
`espflash target/riscv32imc-esp-espidf/release/sphinx-key`
|
||||
|
||||
### monitor
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ use embedded_svc::mqtt::client::utils::ConnState;
|
||||
use embedded_svc::mqtt::client::{MessageImpl, Publish};
|
||||
use esp_idf_svc::mqtt::client::*;
|
||||
use esp_idf_sys::EspError;
|
||||
use log::*;
|
||||
|
||||
pub enum Event {
|
||||
Connected,
|
||||
@@ -18,27 +17,29 @@ pub enum Event {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "pingpong"))]
|
||||
pub fn make_event_loop(mut mqtt: EspMqttClient<ConnState<MessageImpl, EspError>>, rx: mpsc::Receiver<Event>) -> Result<()> {
|
||||
pub fn make_event_loop(mut mqtt: EspMqttClient<ConnState<MessageImpl, EspError>>, rx: mpsc::Receiver<Event>, do_log: bool) -> Result<()> {
|
||||
|
||||
// initialize the RootHandler
|
||||
let root_handler = while let Ok(event) = rx.recv() {
|
||||
if let Event::Message(msg_bytes) = event {
|
||||
let InitResponse { root_handler, init_reply } = sphinx_key_signer::init(event.clone()).expect("failed to init signer");
|
||||
mqtt.publish(RETURN_TOPIC, QOS, false, init_reply).expect("could not publish init response");
|
||||
break root_handler
|
||||
let root_handler = loop {
|
||||
if let Ok(event) = rx.recv() {
|
||||
if let Event::Message(msg_bytes) = event {
|
||||
let InitResponse { root_handler, init_reply } = sphinx_key_signer::init(msg_bytes).expect("failed to init signer");
|
||||
mqtt.publish(RETURN_TOPIC, QOS, false, init_reply).expect("could not publish init response");
|
||||
break root_handler
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// signing loop
|
||||
let dummy_peer = PubKey([0; 33]);
|
||||
while let Ok(msg_bytes) = rx.recv() {
|
||||
while let Ok(event) = rx.recv() {
|
||||
match event {
|
||||
Event::Connected => {
|
||||
log::info!("SUBSCRIBE TO {}", TOPIC);
|
||||
mqtt.subscribe(TOPIC, QOS).expect("could not MQTT subscribe");
|
||||
},
|
||||
Event::Message(ref msg_bytes) => {
|
||||
let _ret = match sphinx_key_signer::handle(&root_handler, msg_bytes.clone(), dummy_peer.clone()) {
|
||||
let _ret = match sphinx_key_signer::handle(&root_handler, msg_bytes.clone(), dummy_peer.clone(), do_log) {
|
||||
Ok(b) => mqtt.publish(RETURN_TOPIC, QOS, false, b).expect("could not publish init response"),
|
||||
Err(e) => panic!("HANDLE FAILED {:?}", e),
|
||||
};
|
||||
@@ -53,7 +54,7 @@ pub fn make_event_loop(mut mqtt: EspMqttClient<ConnState<MessageImpl, EspError>>
|
||||
}
|
||||
|
||||
#[cfg(feature = "pingpong")]
|
||||
pub fn make_event_loop(mut mqtt: EspMqttClient<ConnState<MessageImpl, EspError>>, rx: mpsc::Receiver<Event>) -> Result<()> {
|
||||
pub fn make_event_loop(mut mqtt: EspMqttClient<ConnState<MessageImpl, EspError>>, rx: mpsc::Receiver<Event>, do_log: bool) -> Result<()> {
|
||||
|
||||
info!("About to subscribe to the mpsc channel");
|
||||
while let Ok(event) = rx.recv() {
|
||||
@@ -64,7 +65,9 @@ pub fn make_event_loop(mut mqtt: EspMqttClient<ConnState<MessageImpl, EspError>>
|
||||
},
|
||||
Event::Message(msg_bytes) => {
|
||||
let b = sphinx_key_signer::parse_ping_and_form_response(msg_bytes);
|
||||
log::info!("GOT A PING MESSAGE! returning pong now...");
|
||||
if do_log {
|
||||
log::info!("GOT A PING MESSAGE! returning pong now...");
|
||||
}
|
||||
mqtt.publish(RETURN_TOPIC, QOS, false, b).expect("could not publish init response");
|
||||
},
|
||||
Event::Disconnected => {
|
||||
|
||||
@@ -49,7 +49,8 @@ fn main() -> Result<()> {
|
||||
|
||||
// this blocks forever... the "main thread"
|
||||
log::info!(">>>>>>>>>>> blocking forever...");
|
||||
make_event_loop(mqtt_client, rx)?;
|
||||
let do_log = true;
|
||||
make_event_loop(mqtt_client, rx, do_log)?;
|
||||
|
||||
let mut blue = Led::new(0x000001, 100);
|
||||
println!("{:?}", wifi.get_status());
|
||||
|
||||
Reference in New Issue
Block a user