cargo clippy

This commit is contained in:
irriden
2023-11-15 17:48:30 +00:00
parent 5bef7ab78e
commit 90d43c4e70
33 changed files with 207 additions and 253 deletions

10
broker/Cargo.lock generated
View File

@@ -1691,7 +1691,7 @@ dependencies = [
[[package]] [[package]]
name = "lss-connector" name = "lss-connector"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"lightning-storage-server", "lightning-storage-server",
@@ -2693,7 +2693,7 @@ dependencies = [
[[package]] [[package]]
name = "rmp-utils" name = "rmp-utils"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log", "log",
@@ -3268,7 +3268,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-auther" name = "sphinx-auther"
version = "0.1.12" version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.21.2", "base64 0.21.2",
@@ -3280,7 +3280,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-glyph" name = "sphinx-glyph"
version = "0.1.2" version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"hex", "hex",
@@ -3326,7 +3326,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-signer" name = "sphinx-signer"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bip39", "bip39",

View File

@@ -39,8 +39,8 @@ vls-proxy = { git = "https://gitlab.com/lightning-signer/validating-li
# vls-protocol-client = { path = "../../vls/vls-protocol-client" } # vls-protocol-client = { path = "../../vls/vls-protocol-client" }
# vls-proxy = { path = "../../vls/vls-proxy" } # vls-proxy = { path = "../../vls/vls-proxy" }
lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "1b6b89123171e621617125e8ab59faa246aa2ee3" } lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "55c4b00dc079d21353904fec45b10c7f09ec8f85" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "1b6b89123171e621617125e8ab59faa246aa2ee3" } sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "55c4b00dc079d21353904fec45b10c7f09ec8f85" }
# lss-connector = { path = "../../sphinx-rs/lss-connector" } # lss-connector = { path = "../../sphinx-rs/lss-connector" }
# sphinx-signer = { path = "../../sphinx-rs/signer" } # sphinx-signer = { path = "../../sphinx-rs/signer" }

View File

@@ -45,7 +45,7 @@ pub fn current_client_and_synced() -> (Option<String>, bool) {
let c = cs.current.clone(); let c = cs.current.clone();
let mut b = false; let mut b = false;
if let Some(ref client) = c { if let Some(ref client) = c {
b = cs.clients.get(client).unwrap_or(&false).clone(); b = *cs.clients.get(client).unwrap_or(&false);
} }
(c, b) (c, b)
} }

View File

@@ -15,9 +15,7 @@ pub fn log_errors(mut error_rx: tokio::sync::broadcast::Receiver<Vec<u8>>) {
.open(err_log_path) .open(err_log_path)
{ {
while let Ok(err_msg) = error_rx.recv().await { while let Ok(err_msg) = error_rx.recv().await {
let mut log = format!("[{}]: ", chrono::Utc::now().to_string()) let mut log = format!("[{}]: ", chrono::Utc::now()).as_bytes().to_vec();
.as_bytes()
.to_vec();
log.extend_from_slice(&err_msg); log.extend_from_slice(&err_msg);
log.extend_from_slice(b"\n"); log.extend_from_slice(b"\n");
if let Err(e) = file.write_all(&log) { if let Err(e) = file.write_all(&log) {

View File

@@ -43,7 +43,7 @@ pub fn handle_message(
let res_bytes = loop { let res_bytes = loop {
let (cid, is_synced) = current_client_and_synced(); let (cid, is_synced) = current_client_and_synced();
if let None = cid { if cid.is_none() {
log::info!("no client yet... retry"); log::info!("no client yet... retry");
thread::sleep(Duration::from_millis(96)); thread::sleep(Duration::from_millis(96));
continue; continue;

View File

@@ -77,7 +77,7 @@ async fn connect_dance(
let lss_conn = new_broker.as_ref().xor(lss_conn).ok_or(anyhow!( let lss_conn = new_broker.as_ref().xor(lss_conn).ok_or(anyhow!(
"should never happen, either we use the newly initialized, or the one passed in" "should never happen, either we use the newly initialized, or the one passed in"
))?; ))?;
let _ = dance_step_2(cid, lss_conn, mqtt_tx, &ir).await?; dance_step_2(cid, lss_conn, mqtt_tx, &ir).await?;
// only some when lss_conn is none // only some when lss_conn is none
Ok(new_broker) Ok(new_broker)
} }

View File

@@ -51,13 +51,11 @@ async fn rocket() -> _ {
env::var("GREENLIGHT_VERSION").expect("set GREENLIGHT_VERSION to match c-lightning"); env::var("GREENLIGHT_VERSION").expect("set GREENLIGHT_VERSION to match c-lightning");
println!("{}", version); println!("{}", version);
panic!("end") panic!("end")
} else { } else if matches.is_present("test") {
if matches.is_present("test") {
run_test::run_test() run_test::run_test()
} else { } else {
run_main(parent_fd) run_main(parent_fd)
} }
}
} }
fn make_clap_app() -> App<'static> { fn make_clap_app() -> App<'static> {
@@ -111,7 +109,7 @@ fn run_main(parent_fd: i32) -> rocket::Rocket<rocket::Build> {
let cln_client = UnixClient::new(UnixConnection::new(parent_fd)); let cln_client = UnixClient::new(UnixConnection::new(parent_fd));
// TODO pass status_rx into SignerLoop? // TODO pass status_rx into SignerLoop?
let mut signer_loop = SignerLoop::new(cln_client, mqtt_tx.clone(), lss_tx.clone()); let mut signer_loop = SignerLoop::new(cln_client, mqtt_tx.clone(), lss_tx);
// spawn CLN listener // spawn CLN listener
std::thread::spawn(move || { std::thread::spawn(move || {
signer_loop.start(Some(settings.network)); signer_loop.start(Some(settings.network));
@@ -145,14 +143,7 @@ pub fn broker_setup(
// broker // broker
log::info!("=> start broker on network: {}", settings.network); log::info!("=> start broker on network: {}", settings.network);
start_broker( start_broker(settings, mqtt_rx, init_rx, status_tx, error_tx, auth_tx)
settings,
mqtt_rx,
init_rx,
status_tx,
error_tx.clone(),
auth_tx,
)
.expect("BROKER FAILED TO START"); .expect("BROKER FAILED TO START");
// client connections state // client connections state

View File

@@ -27,7 +27,7 @@ pub fn start_broker(
let _ = link_tx.subscribe(format!("+/{}", topics::HELLO)); let _ = link_tx.subscribe(format!("+/{}", topics::HELLO));
let _ = link_tx.subscribe(format!("+/{}", topics::BYE)); let _ = link_tx.subscribe(format!("+/{}", topics::BYE));
let auth_sender_ = auth_sender.clone(); let auth_sender_ = auth_sender;
std::thread::spawn(move || { std::thread::spawn(move || {
broker broker
.start(Some(auth_sender_)) .start(Some(auth_sender_))
@@ -83,13 +83,13 @@ pub fn start_broker(
// receive replies back from glyph // receive replies back from glyph
let _sub_task = std::thread::spawn(move || { let _sub_task = std::thread::spawn(move || {
while let Ok(message) = link_rx.recv() { while let Ok(message) = link_rx.recv() {
if let None = message { if message.is_none() {
continue; continue;
} }
match message.unwrap() { match message.unwrap() {
Notification::Forward(f) => { Notification::Forward(f) => {
let topic_res = std::str::from_utf8(&f.publish.topic); let topic_res = std::str::from_utf8(&f.publish.topic);
if let Err(_) = topic_res { if topic_res.is_err() {
continue; continue;
} }
@@ -99,7 +99,7 @@ pub fn start_broker(
continue; continue;
} }
let ts: Vec<&str> = topic.split("/").collect(); let ts: Vec<&str> = topic.split('/').collect();
if ts.len() != 2 { if ts.len() != 2 {
continue; continue;
} }
@@ -117,13 +117,11 @@ pub fn start_broker(
if let Err(e) = init_tx.send((cid, topic_end, pld)) { if let Err(e) = init_tx.send((cid, topic_end, pld)) {
log::error!("failed to pub to init_tx! {:?}", e); log::error!("failed to pub to init_tx! {:?}", e);
} }
} else { } else if let Err(e) = msg_tx.send((cid, topic_end, pld)) {
if let Err(e) = msg_tx.send((cid, topic_end, pld)) {
log::error!("failed to pub to msg_tx! {:?}", e); log::error!("failed to pub to msg_tx! {:?}", e);
} }
} }
} }
}
_ => continue, _ => continue,
} }
} }
@@ -150,11 +148,11 @@ fn pub_and_wait(
loop { loop {
log::debug!("looping in pub_and_wait"); log::debug!("looping in pub_and_wait");
let reply = pub_timeout(&msg.cid, &msg.topic, &msg.message, &msg_rx, link_tx); let reply = pub_timeout(&msg.cid, &msg.topic, &msg.message, msg_rx, link_tx);
if let Some(reply) = reply { if let Some(reply) = reply {
log::debug!("MQTT got this response: {:?}", reply); log::debug!("MQTT got this response: {:?}", reply);
if let Err(_) = msg.reply_tx.send(reply) { if msg.reply_tx.send(reply).is_err() {
log::warn!("could not send on reply_tx"); log::warn!("could not send on reply_tx");
} }
break; break;
@@ -164,7 +162,7 @@ fn pub_and_wait(
if let Some(max) = retries { if let Some(max) = retries {
log::debug!("counter: {}, retries: {}", counter, max); log::debug!("counter: {}, retries: {}", counter, max);
if counter == max { if counter == max {
if let Err(_) = msg.reply_tx.send(ChannelReply::empty()) { if msg.reply_tx.send(ChannelReply::empty()).is_err() {
log::warn!("could not send on reply_tx"); log::warn!("could not send on reply_tx");
} }
break; break;
@@ -190,7 +188,7 @@ fn pub_timeout(
// and receive from the correct client (or timeout to next) // and receive from the correct client (or timeout to next)
let dur = Duration::from_secs(10); let dur = Duration::from_secs(10);
if let Ok((cid, topic_end, reply)) = msg_rx.recv_timeout(dur) { if let Ok((cid, topic_end, reply)) = msg_rx.recv_timeout(dur) {
if &cid == client_id { if cid == client_id {
return Some(ChannelReply::new(topic_end, reply)); return Some(ChannelReply::new(topic_end, reply));
} else { } else {
log::warn!("Mismatched client id!"); log::warn!("Mismatched client id!");
@@ -226,7 +224,7 @@ pub fn check_auth(
Ok(t) => match t.recover() { Ok(t) => match t.recover() {
Ok(pubkey) => { Ok(pubkey) => {
// pubkey must match signature // pubkey must match signature
if &pubkey.to_string() == username { if pubkey.to_string() == username {
if let Some(pk) = already_pubkey { if let Some(pk) = already_pubkey {
// if there is an existing pubkey then new client must match // if there is an existing pubkey then new client must match
(pk == username, None) (pk == username, None)

View File

@@ -33,13 +33,13 @@ pub async fn control(
} }
let (request, reply_rx) = ChannelRequest::new(cid, topics::CONTROL, message); let (request, reply_rx) = ChannelRequest::new(cid, topics::CONTROL, message);
// send to ESP // send to ESP
let _ = sender.send(request).await.map_err(|_| Error::Fail)?; sender.send(request).await.map_err(|_| Error::Fail)?;
// wait for reply // wait for reply
let reply = reply_rx.await.map_err(|_| Error::Fail)?; let reply = reply_rx.await.map_err(|_| Error::Fail)?;
if reply.is_empty() { if reply.is_empty() {
return Err(Error::Fail); return Err(Error::Fail);
} }
Ok(hex::encode(reply.reply).to_string()) Ok(hex::encode(reply.reply))
} }
#[get("/errors")] #[get("/errors")]
@@ -98,13 +98,12 @@ impl<'r, 'o: 'r> Responder<'r, 'o> for Error {
// log `self` to your favored error tracker, e.g. // log `self` to your favored error tracker, e.g.
// sentry::capture_error(&self); // sentry::capture_error(&self);
println!("ERROR {:?}", self); println!("ERROR {:?}", self);
match self {
// in our simplistic example, we're happy to respond with the default 500 responder in all cases // in our simplistic example, we're happy to respond with the default 500 responder in all cases
_ => Status::InternalServerError.respond_to(req), Status::InternalServerError.respond_to(req)
}
} }
} }
#[allow(clippy::upper_case_acronyms)]
pub struct CORS; pub struct CORS;
#[rocket::async_trait] #[rocket::async_trait]

View File

@@ -23,13 +23,7 @@ pub fn run_test() -> rocket::Rocket<rocket::Build> {
crate::error_log::log_errors(error_rx); crate::error_log::log_errors(error_rx);
// block until connection // block until connection
crate::broker_setup( crate::broker_setup(settings, mqtt_rx, init_rx, conn_tx, error_tx.clone());
settings,
mqtt_rx,
init_rx,
conn_tx.clone(),
error_tx.clone(),
);
log::info!("=> off to the races!"); log::info!("=> off to the races!");
let tx_ = mqtt_tx.clone(); let tx_ = mqtt_tx.clone();

View File

@@ -110,7 +110,7 @@ pub fn setup_logging(who: &str, level_arg: &str) {
} }
fn read_network_setting(table: &Value) -> Option<Network> { fn read_network_setting(table: &Value) -> Option<Network> {
if let None = table.get("network") { if table.get("network").is_none() {
log::info!("Network not specified, setting to default regtest"); log::info!("Network not specified, setting to default regtest");
None None
} else { } else {
@@ -129,7 +129,7 @@ fn read_network_setting(table: &Value) -> Option<Network> {
} }
fn read_mqtt_port_setting(table: &Value) -> Option<u16> { fn read_mqtt_port_setting(table: &Value) -> Option<u16> {
if let None = table.get("mqtt_port") { if table.get("mqtt_port").is_none() {
log::info!("Broker mqtt port not specified, setting to default 1883"); log::info!("Broker mqtt port not specified, setting to default 1883");
None None
} else { } else {
@@ -149,7 +149,7 @@ fn read_mqtt_port_setting(table: &Value) -> Option<u16> {
} }
fn read_http_port_setting(table: &Value) -> Option<u16> { fn read_http_port_setting(table: &Value) -> Option<u16> {
if let None = table.get("http_port") { if table.get("http_port").is_none() {
log::info!("Broker http port not specified, setting to default 8000"); log::info!("Broker http port not specified, setting to default 8000");
None None
} else { } else {
@@ -169,7 +169,7 @@ fn read_http_port_setting(table: &Value) -> Option<u16> {
} }
fn read_ws_port_setting(table: &Value) -> Option<u16> { fn read_ws_port_setting(table: &Value) -> Option<u16> {
if let None = table.get("ws_port") { if table.get("ws_port").is_none() {
log::info!("Broker ws port not specified, setting to default 8083"); log::info!("Broker ws port not specified, setting to default 8083");
None None
} else { } else {

View File

@@ -1,28 +1,28 @@
pub(crate) struct RGB { pub(crate) struct Rgb {
pub(crate) r: u8, pub(crate) r: u8,
pub(crate) g: u8, pub(crate) g: u8,
pub(crate) b: u8, pub(crate) b: u8,
} }
pub(crate) const BLUE: RGB = RGB { pub(crate) const BLUE: Rgb = Rgb {
r: 00, r: 00,
g: 00, g: 00,
b: 255, b: 255,
}; };
pub(crate) const GREEN: RGB = RGB { pub(crate) const GREEN: Rgb = Rgb {
r: 00, r: 00,
g: 255, g: 255,
b: 00, b: 00,
}; };
pub(crate) const ORANGE: RGB = RGB { pub(crate) const ORANGE: Rgb = Rgb {
r: 255, r: 255,
g: 55, g: 55,
b: 00, b: 00,
}; };
pub(crate) const WHITE: RGB = RGB { pub(crate) const WHITE: Rgb = Rgb {
r: 255, r: 255,
g: 255, g: 255,
b: 255, b: 255,

View File

@@ -16,30 +16,30 @@ pub(crate) fn setup(peripherals: Peripherals) -> Result<TxRmtDriver<'static>, Fa
let led = peripherals.led; let led = peripherals.led;
let channel = peripherals.channel; let channel = peripherals.channel;
let config = TransmitConfig::new().clock_divider(1); let config = TransmitConfig::new().clock_divider(1);
let tx = TxRmtDriver::new(channel, led, &config).map_err(|e| FactoryError::EspError(e))?; let tx = TxRmtDriver::new(channel, led, &config).map_err(FactoryError::Esp)?;
Ok(tx) Ok(tx)
} }
pub(crate) fn setup_complete(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> { pub(crate) fn setup_complete(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> {
neopixel(BLUE, led_tx).map_err(|e| FactoryError::EspError(e))?; neopixel(BLUE, led_tx).map_err(FactoryError::Esp)?;
FreeRtos::delay_ms(10); FreeRtos::delay_ms(10);
Ok(()) Ok(())
} }
pub(crate) fn update_launch(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> { pub(crate) fn update_launch(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> {
neopixel(ORANGE, led_tx).map_err(|e| FactoryError::EspError(e))?; neopixel(ORANGE, led_tx).map_err(FactoryError::Esp)?;
FreeRtos::delay_ms(10); FreeRtos::delay_ms(10);
Ok(()) Ok(())
} }
pub(crate) fn update_complete(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> { pub(crate) fn update_complete(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> {
neopixel(GREEN, led_tx).map_err(|e| FactoryError::EspError(e))?; neopixel(GREEN, led_tx).map_err(FactoryError::Esp)?;
FreeRtos::delay_ms(10); FreeRtos::delay_ms(10);
Ok(()) Ok(())
} }
pub(crate) fn main_app_launch(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> { pub(crate) fn main_app_launch(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> {
neopixel(WHITE, led_tx).map_err(|e| FactoryError::EspError(e))?; neopixel(WHITE, led_tx).map_err(FactoryError::Esp)?;
FreeRtos::delay_ms(10); FreeRtos::delay_ms(10);
Ok(()) Ok(())
} }
@@ -48,7 +48,7 @@ fn ns(nanos: u64) -> Duration {
Duration::from_nanos(nanos) Duration::from_nanos(nanos)
} }
fn neopixel(rgb: RGB, tx: &mut TxRmtDriver) -> Result<(), EspError> { fn neopixel(rgb: Rgb, tx: &mut TxRmtDriver) -> Result<(), EspError> {
// e.g. rgb: (1,2,4) // e.g. rgb: (1,2,4)
// G R B // G R B
// 7 0 7 0 7 0 // 7 0 7 0 7 0

View File

@@ -15,9 +15,9 @@ use esp_println::println;
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum FactoryError { pub(crate) enum FactoryError {
SdCardError(Error<SdCardError>), SdCard(Error<SdCardError>),
OtaError(EspError), Ota(EspError),
EspError(EspError), Esp(EspError),
} }
#[no_mangle] #[no_mangle]
@@ -52,7 +52,7 @@ fn main() -> Result<(), FactoryError> {
fn assign_peripherals() -> Result<(sdcard::Peripherals, led::Peripherals), FactoryError> { fn assign_peripherals() -> Result<(sdcard::Peripherals, led::Peripherals), FactoryError> {
// this function here must be called only once // this function here must be called only once
let peripherals = Peripherals::take().map_err(|e| FactoryError::EspError(e))?; let peripherals = Peripherals::take().map_err(FactoryError::Esp)?;
let sd_card_peripherals = sdcard::Peripherals { let sd_card_peripherals = sdcard::Peripherals {
spi: peripherals.spi2, spi: peripherals.spi2,
sck: peripherals.pins.gpio6, sck: peripherals.pins.gpio6,

View File

@@ -13,14 +13,14 @@ const BUFFER_LEN: usize = 1024;
pub(crate) fn update_present(volume_mgr: &mut Manager) -> Result<bool, FactoryError> { pub(crate) fn update_present(volume_mgr: &mut Manager) -> Result<bool, FactoryError> {
let volume0 = volume_mgr let volume0 = volume_mgr
.get_volume(VolumeIdx(0)) .get_volume(VolumeIdx(0))
.map_err(|e| FactoryError::SdCardError(e))?; .map_err(FactoryError::SdCard)?;
let root_dir = volume_mgr let root_dir = volume_mgr
.open_root_dir(&volume0) .open_root_dir(&volume0)
.map_err(|e| FactoryError::SdCardError(e))?; .map_err(FactoryError::SdCard)?;
let ret = match volume_mgr.find_directory_entry(&volume0, &root_dir, FILE) { let ret = match volume_mgr.find_directory_entry(&volume0, &root_dir, FILE) {
Ok(_) => Ok(true), Ok(_) => Ok(true),
Err(FileNotFound) => Ok(false), Err(FileNotFound) => Ok(false),
Err(e) => Err(FactoryError::SdCardError(e)), Err(e) => Err(FactoryError::SdCard(e)),
}; };
volume_mgr.close_dir(&volume0, root_dir); volume_mgr.close_dir(&volume0, root_dir);
ret ret
@@ -29,33 +29,30 @@ pub(crate) fn update_present(volume_mgr: &mut Manager) -> Result<bool, FactoryEr
pub(crate) fn write_update(volume_mgr: &mut Manager) -> Result<(), FactoryError> { pub(crate) fn write_update(volume_mgr: &mut Manager) -> Result<(), FactoryError> {
let mut volume0 = volume_mgr let mut volume0 = volume_mgr
.get_volume(VolumeIdx(0)) .get_volume(VolumeIdx(0))
.map_err(|e| FactoryError::SdCardError(e))?; .map_err(FactoryError::SdCard)?;
let root_dir = volume_mgr let root_dir = volume_mgr
.open_root_dir(&volume0) .open_root_dir(&volume0)
.map_err(|e| FactoryError::SdCardError(e))?; .map_err(FactoryError::SdCard)?;
let mut my_file = volume_mgr let mut my_file = volume_mgr
.open_file_in_dir(&mut volume0, &root_dir, FILE, Mode::ReadOnly) .open_file_in_dir(&mut volume0, &root_dir, FILE, Mode::ReadOnly)
.map_err(|e| FactoryError::SdCardError(e))?; .map_err(FactoryError::SdCard)?;
let mut ota = EspOta::new().map_err(|e| FactoryError::OtaError(e))?; let mut ota = EspOta::new().map_err(FactoryError::Ota)?;
let mut ota = ota let mut ota = ota.initiate_update().map_err(FactoryError::Ota)?;
.initiate_update()
.map_err(|e| FactoryError::OtaError(e))?;
let mut buffer = [0u8; BUFFER_LEN]; let mut buffer = [0u8; BUFFER_LEN];
while !my_file.eof() { while !my_file.eof() {
let r = volume_mgr let r = volume_mgr
.read(&volume0, &mut my_file, &mut buffer) .read(&volume0, &mut my_file, &mut buffer)
.map_err(|e| FactoryError::SdCardError(e))?; .map_err(FactoryError::SdCard)?;
ota.write(&buffer[..r]) ota.write(&buffer[..r]).map_err(FactoryError::Ota)?;
.map_err(|e| FactoryError::OtaError(e))?;
} }
ota.complete().map_err(|e| FactoryError::OtaError(e))?; ota.complete().map_err(FactoryError::Ota)?;
volume_mgr volume_mgr
.close_file(&volume0, my_file) .close_file(&volume0, my_file)
.map_err(|e| FactoryError::SdCardError(e))?; .map_err(FactoryError::SdCard)?;
volume_mgr.close_dir(&volume0, root_dir); volume_mgr.close_dir(&volume0, root_dir);
Ok(()) Ok(())
} }
@@ -65,5 +62,5 @@ pub(crate) fn set_boot_main_app() -> Result<(), FactoryError> {
let partition = esp_ota_get_next_update_partition(ptr::null()); let partition = esp_ota_get_next_update_partition(ptr::null());
esp_ota_set_boot_partition(partition) esp_ota_set_boot_partition(partition)
}) })
.map_err(|e| FactoryError::OtaError(e)) .map_err(FactoryError::Ota)
} }

View File

@@ -46,13 +46,13 @@ pub(crate) fn setup(peripherals: Peripherals) -> Result<Manager<'static>, Factor
Some(peripherals.miso), Some(peripherals.miso),
&DriverConfig::default(), &DriverConfig::default(),
) )
.map_err(|e| FactoryError::EspError(e))?; .map_err(FactoryError::Esp)?;
let mut spi_config = SpiConfig::new(); let mut spi_config = SpiConfig::new();
spi_config.duplex = Duplex::Full; spi_config.duplex = Duplex::Full;
spi_config = spi_config.baudrate(24.MHz().into()); spi_config = spi_config.baudrate(24.MHz().into());
let spi = SpiDeviceDriver::new(driver, Option::<Gpio10>::None, &spi_config) let spi = SpiDeviceDriver::new(driver, Option::<Gpio10>::None, &spi_config)
.map_err(|e| FactoryError::EspError(e))?; .map_err(FactoryError::Esp)?;
let sdmmc_cs = PinDriver::output(peripherals.cs).map_err(|e| FactoryError::EspError(e))?; let sdmmc_cs = PinDriver::output(peripherals.cs).map_err(FactoryError::Esp)?;
let sdcard = SdCard::new(spi, sdmmc_cs, Ets {}); let sdcard = SdCard::new(spi, sdmmc_cs, Ets {});
let volume_mgr = VolumeManager::new(sdcard, SdMmcClock {}); let volume_mgr = VolumeManager::new(sdcard, SdMmcClock {});
Ok(volume_mgr) Ok(volume_mgr)

12
sphinx-key/Cargo.lock generated
View File

@@ -1161,7 +1161,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]] [[package]]
name = "lss-connector" name = "lss-connector"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log", "log",
@@ -1530,7 +1530,7 @@ dependencies = [
[[package]] [[package]]
name = "rmp-utils" name = "rmp-utils"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log", "log",
@@ -1728,7 +1728,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-auther" name = "sphinx-auther"
version = "0.1.12" version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
@@ -1740,7 +1740,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-crypter" name = "sphinx-crypter"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chacha20poly1305", "chacha20poly1305",
@@ -1751,7 +1751,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-glyph" name = "sphinx-glyph"
version = "0.1.2" version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"hex", "hex",
@@ -1783,7 +1783,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-signer" name = "sphinx-signer"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1b6b89123171e621617125e8ab59faa246aa2ee3#1b6b89123171e621617125e8ab59faa246aa2ee3" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bip39", "bip39",

View File

@@ -21,9 +21,9 @@ serde_urlencoded = "0.7.1"
url = "2" url = "2"
# sphinx-rs # sphinx-rs
lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "1b6b89123171e621617125e8ab59faa246aa2ee3" } lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "55c4b00dc079d21353904fec45b10c7f09ec8f85" }
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "1b6b89123171e621617125e8ab59faa246aa2ee3" } sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "55c4b00dc079d21353904fec45b10c7f09ec8f85" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "1b6b89123171e621617125e8ab59faa246aa2ee3" } sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "55c4b00dc079d21353904fec45b10c7f09ec8f85" }
# local # local
# lss-connector = { path = "../../sphinx-rs/lss-connector", default-features = false } # lss-connector = { path = "../../sphinx-rs/lss-connector", default-features = false }
# sphinx-crypter = { path = "../../sphinx-rs/crypter" } # sphinx-crypter = { path = "../../sphinx-rs/crypter" }

View File

@@ -10,10 +10,7 @@ use esp_idf_svc::hal::gpio::Gpio9;
use esp_idf_svc::hal::peripheral::Peripheral; use esp_idf_svc::hal::peripheral::Peripheral;
use esp_idf_svc::hal::peripherals::Peripherals; use esp_idf_svc::hal::peripherals::Peripherals;
use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::nvs::EspDefaultNvsPartition;
use esp_idf_svc::nvs::EspNvs;
use esp_idf_svc::nvs::*;
use esp_idf_svc::sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported use esp_idf_svc::sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported
use log;
use status::Status; use status::Status;
use std::sync::mpsc; use std::sync::mpsc;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@@ -42,7 +39,7 @@ fn main() -> anyhow::Result<()> {
// BUTTON thread // BUTTON thread
let default_nvs = EspDefaultNvsPartition::take()?; let default_nvs = EspDefaultNvsPartition::take()?;
let flash_per = FlashPersister::new(default_nvs.clone()); let flash_per = FlashPersister::new(default_nvs);
let flash_arc = Arc::new(Mutex::new(flash_per)); let flash_arc = Arc::new(Mutex::new(flash_per));
while let Err(e) = while let Err(e) =
periph::button::button_loop(unsafe { Gpio9::new() }, led_tx.clone(), flash_arc.clone()) periph::button::button_loop(unsafe { Gpio9::new() }, led_tx.clone(), flash_arc.clone())

View File

@@ -16,6 +16,7 @@ pub struct Params {
pub config: String, pub config: String,
} }
#[allow(clippy::type_complexity)]
pub fn config_server( pub fn config_server(
mutex: Arc<(Mutex<Option<(Config, Option<[u8; 32]>)>>, Condvar)>, mutex: Arc<(Mutex<Option<(Config, Option<[u8; 32]>)>>, Condvar)>,
has_stored_seed: bool, has_stored_seed: bool,
@@ -34,7 +35,7 @@ pub fn config_server(
})? })?
.fn_handler("/config", Method::Post, move |request| { .fn_handler("/config", Method::Post, move |request| {
let params = let params =
serde_urlencoded::from_str::<Params>(request.uri().split_once("?").unwrap().1)?; serde_urlencoded::from_str::<Params>(request.uri().split_once('?').unwrap().1)?;
let dto = serde_json::from_str::<ConfigDTO>(&params.config)?; let dto = serde_json::from_str::<ConfigDTO>(&params.config)?;
let conf_seed_tuple = decrypt_seed(dto, sk1)?; let conf_seed_tuple = decrypt_seed(dto, sk1)?;
if !has_stored_seed && conf_seed_tuple.1.is_none() { if !has_stored_seed && conf_seed_tuple.1.is_none() {

View File

@@ -53,9 +53,8 @@ pub fn make_client(
info!("MQTT Listening for messages"); info!("MQTT Listening for messages");
let mut inflight = Vec::new(); let mut inflight = Vec::new();
let mut inflight_topic = "".to_string(); let mut inflight_topic = "".to_string();
loop { while let Some(msg) = connection.next() {
match connection.next() { match msg {
Some(msg) => match msg {
Err(e) => match e.to_string().as_ref() { Err(e) => match e.to_string().as_ref() {
"ESP_FAIL" => { "ESP_FAIL" => {
error!("ESP_FAIL msg!"); error!("ESP_FAIL msg!");
@@ -79,13 +78,9 @@ pub fn make_client(
Event::Published(_mes_id) => info!("RECEIVED Published MESSAGE"), Event::Published(_mes_id) => info!("RECEIVED Published MESSAGE"),
Event::Received(msg) => { Event::Received(msg) => {
let incoming_message: Option<(String, Vec<u8>)> = match msg.details() { let incoming_message: Option<(String, Vec<u8>)> = match msg.details() {
Details::Complete => { Details::Complete => msg
if let Some(topic) = msg.topic() { .topic()
Some((topic.to_string(), msg.data().to_vec())) .map(|topic| (topic.to_string(), msg.data().to_vec())),
} else {
None
}
}
Details::InitialChunk(chunk_info) => { Details::InitialChunk(chunk_info) => {
if let Some(topic) = msg.topic() { if let Some(topic) = msg.topic() {
inflight = Vec::with_capacity(chunk_info.total_data_size); inflight = Vec::with_capacity(chunk_info.total_data_size);
@@ -131,12 +126,10 @@ pub fn make_client(
} }
Event::Deleted(_mes_id) => info!("RECEIVED Deleted MESSAGE"), Event::Deleted(_mes_id) => info!("RECEIVED Deleted MESSAGE"),
}, },
}, } // match
None => break, } // while let
}
}
//info!("MQTT connection loop exit"); //info!("MQTT connection loop exit");
})?; })?; // spawn
Ok(client) Ok(client)
} }

View File

@@ -15,7 +15,7 @@ pub fn sync_time_timeout() -> Result<()> {
} else if counter == 30 { } else if counter == 30 {
break Err(anyhow!("SNTP setup timed out")); break Err(anyhow!("SNTP setup timed out"));
} }
counter = counter + 1; counter += 1;
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(1));
} }
} }

View File

@@ -115,9 +115,5 @@ pub fn start_config_server_and_wait(
// drop(wifi); // drop(wifi);
// thread::sleep(Duration::from_secs(1)); // thread::sleep(Duration::from_secs(1));
println!("===> config! {:?}", config_seed_tuple.0); println!("===> config! {:?}", config_seed_tuple.0);
Ok(( Ok((wifi, config_seed_tuple.0.clone(), config_seed_tuple.1))
wifi,
config_seed_tuple.0.clone(),
config_seed_tuple.1.clone(),
))
} }

View File

@@ -49,8 +49,8 @@ impl ControlPersist for FlashPersister {
.0 .0
.get_raw(FlashKey::Config.as_str(), &mut buf)? .get_raw(FlashKey::Config.as_str(), &mut buf)?
.ok_or(anyhow!("no existing config"))?; .ok_or(anyhow!("no existing config"))?;
let mut bytes = Bytes::new(&existing); let mut bytes = Bytes::new(existing);
Ok(deserialize_config(&mut bytes)?) deserialize_config(&mut bytes)
} }
fn write_config(&mut self, conf: Config) -> Result<()> { fn write_config(&mut self, conf: Config) -> Result<()> {
let mut bb = ByteBuf::new(); let mut bb = ByteBuf::new();
@@ -97,8 +97,8 @@ impl ControlPersist for FlashPersister {
.0 .0
.get_raw(FlashKey::Policy.as_str(), &mut buf)? .get_raw(FlashKey::Policy.as_str(), &mut buf)?
.ok_or(anyhow!("no existing policy"))?; .ok_or(anyhow!("no existing policy"))?;
let mut bytes = Bytes::new(&existing); let mut bytes = Bytes::new(existing);
Ok(deserialize_policy(&mut bytes, None)?) deserialize_policy(&mut bytes, None)
} }
fn write_policy(&mut self, pol: Policy) -> Result<()> { fn write_policy(&mut self, pol: Policy) -> Result<()> {
let mut bb = ByteBuf::new(); let mut bb = ByteBuf::new();
@@ -118,7 +118,7 @@ impl ControlPersist for FlashPersister {
.ok_or(anyhow!("no existing velocity"))?; .ok_or(anyhow!("no existing velocity"))?;
let mut bytes = Bytes::new(existing); let mut bytes = Bytes::new(existing);
let desvel = deserialize_velocity(&mut bytes, None)?; let desvel = deserialize_velocity(&mut bytes, None)?;
Ok(desvel.context(anyhow::anyhow!("no velocity"))?) desvel.context(anyhow::anyhow!("no velocity"))
} }
fn write_velocity(&mut self, vel: Velocity) -> Result<()> { fn write_velocity(&mut self, vel: Velocity) -> Result<()> {
let mut bb = ByteBuf::new(); let mut bb = ByteBuf::new();

View File

@@ -60,6 +60,7 @@ fn mqtt_pub(
// the main event loop // the main event loop
#[cfg(not(feature = "pingpong"))] #[cfg(not(feature = "pingpong"))]
#[allow(clippy::too_many_arguments)]
pub fn make_event_loop( pub fn make_event_loop(
mut mqtt: EspMqttClient<ConnState<MessageImpl, EspError>>, mut mqtt: EspMqttClient<ConnState<MessageImpl, EspError>>,
rx: mpsc::Receiver<Event>, rx: mpsc::Receiver<Event>,
@@ -79,23 +80,20 @@ pub fn make_event_loop(
while let Ok(event) = rx.recv() { while let Ok(event) = rx.recv() {
log::info!("BROKER IP AND PORT: {}", config.broker); log::info!("BROKER IP AND PORT: {}", config.broker);
// wait for a Connection first. // wait for a Connection first.
match event { if let Event::Connected = event {
Event::Connected => {
mqtt_sub(&mut mqtt, &client_id, topics::SIGNER_SUBS); mqtt_sub(&mut mqtt, &client_id, topics::SIGNER_SUBS);
break; break;
} }
_ => (),
}
} }
let kvv_store = FsKVVStore::new(&ROOT_STORE, signer_id.clone(), None).0; let kvv_store = FsKVVStore::new(ROOT_STORE, *signer_id, None).0;
let fs_persister = CloudKVVStore::new(kvv_store); let fs_persister = CloudKVVStore::new(kvv_store);
let _ = fs_persister.enter(); let _ = fs_persister.enter();
let initial_allowlist = match fs_persister.get_nodes() { let initial_allowlist = match fs_persister.get_nodes() {
Ok(ns) => { Ok(ns) => {
if !ns.is_empty() { if !ns.is_empty() {
match fs_persister.get_node_allowlist(&node_id) { match fs_persister.get_node_allowlist(node_id) {
Ok(al) => al, Ok(al) => al,
Err(_) => { Err(_) => {
log::warn!("no allowlist found in fs persister!"); log::warn!("no allowlist found in fs persister!");
@@ -164,7 +162,7 @@ pub fn make_event_loop(
current_status = update_led(current_status, Status::Signing, &led_tx); current_status = update_led(current_status, Status::Signing, &led_tx);
let state1 = approver.control().get_state(); let state1 = approver.control().get_state();
//log::info!("FULL MSG {:?}", &msg_bytes); //log::info!("FULL MSG {:?}", &msg_bytes);
let _ret = match sphinx_signer::root::handle_with_lss( match sphinx_signer::root::handle_with_lss(
&root_handler, &root_handler,
&lss_signer, &lss_signer,
msg_bytes, msg_bytes,
@@ -317,7 +315,7 @@ fn handle_control_response(
} }
} }
ControlMessage::UpdateAllowlist(al) => { ControlMessage::UpdateAllowlist(al) => {
if let Err(e) = sphinx_signer::policy::set_allowlist(&root_handler, &al) { if let Err(e) = sphinx_signer::policy::set_allowlist(root_handler, &al) {
log::error!("set allowlist failed {:?}", e); log::error!("set allowlist failed {:?}", e);
control_res = control_res =
ControlResponse::Error(format!("set allowlist failed {:?}", e)) ControlResponse::Error(format!("set allowlist failed {:?}", e))
@@ -325,7 +323,7 @@ fn handle_control_response(
} }
// overwrite the real Allowlist response, loaded from Node // overwrite the real Allowlist response, loaded from Node
ControlMessage::QueryAllowlist => { ControlMessage::QueryAllowlist => {
match sphinx_signer::policy::get_allowlist(&root_handler) { match sphinx_signer::policy::get_allowlist(root_handler) {
Ok(al) => control_res = ControlResponse::AllowlistCurrent(al), Ok(al) => control_res = ControlResponse::AllowlistCurrent(al),
Err(e) => { Err(e) => {
log::error!("read allowlist failed {:?}", e); log::error!("read allowlist failed {:?}", e);
@@ -335,7 +333,7 @@ fn handle_control_response(
} }
} }
ControlMessage::Ota(params) => { ControlMessage::Ota(params) => {
if let Err(e) = validate_ota_message(params.clone()) { if let Err(e) = validate_ota_message(params) {
log::error!("OTA update cannot launch {:?}", e.to_string()); log::error!("OTA update cannot launch {:?}", e.to_string());
control_res = control_res =
ControlResponse::Error(format!("OTA update cannot launch {:?}", e)) ControlResponse::Error(format!("OTA update cannot launch {:?}", e))

View File

@@ -77,7 +77,7 @@ fn main() -> Result<()> {
exist exist
); );
led_tx.send(Status::ConnectingToWifi).unwrap(); led_tx.send(Status::ConnectingToWifi).unwrap();
let _wifi = match start_wifi_client(peripherals.modem, default_nvs.clone(), &exist) { let _wifi = match start_wifi_client(peripherals.modem, default_nvs, &exist) {
Ok(wifi) => wifi, Ok(wifi) => wifi,
Err(e) => { Err(e) => {
log::error!("Could not setup wifi: {}", e); log::error!("Could not setup wifi: {}", e);
@@ -106,7 +106,7 @@ fn main() -> Result<()> {
if let Ok(()) = make_and_launch_client( if let Ok(()) = make_and_launch_client(
exist.clone(), exist.clone(),
seed, seed,
id.clone(), id,
&policy, &policy,
&velocity, &velocity,
led_tx.clone(), led_tx.clone(),
@@ -124,11 +124,7 @@ fn main() -> Result<()> {
println!("=============> START SERVER NOW AND WAIT <=============="); println!("=============> START SERVER NOW AND WAIT <==============");
let stored_seed = flash.read_seed().ok(); let stored_seed = flash.read_seed().ok();
drop(flash); drop(flash);
match start_config_server_and_wait( match start_config_server_and_wait(peripherals.modem, default_nvs, stored_seed.is_some()) {
peripherals.modem,
default_nvs.clone(),
stored_seed.is_some(),
) {
Ok((_wifi, config, seed_opt)) => { Ok((_wifi, config, seed_opt)) => {
let mut flash = flash_arc.lock().unwrap(); let mut flash = flash_arc.lock().unwrap();
flash.write_config(config).expect("could not store config"); flash.write_config(config).expect("could not store config");
@@ -177,12 +173,11 @@ fn make_and_launch_client(
let ctrlr = controller_from_seed(&network, &seed[..], flash); let ctrlr = controller_from_seed(&network, &seed[..], flash);
let pubkey = ctrlr.pubkey(); let pubkey = ctrlr.pubkey();
let pubkey_str = hex::encode(&pubkey.serialize()); let pubkey_str = hex::encode(pubkey.serialize());
let token = ctrlr.make_auth_token().expect("couldnt make auth token"); let token = ctrlr.make_auth_token().expect("couldnt make auth token");
log::info!("PUBKEY {} TOKEN {}", &pubkey_str, &token); log::info!("PUBKEY {} TOKEN {}", &pubkey_str, &token);
let mqtt_client = let mqtt_client = conn::mqtt::make_client(&config.broker, &signer_id, &pubkey_str, &token, tx)?;
conn::mqtt::make_client(&config.broker, &signer_id, &pubkey_str, &token, tx.clone())?;
// let mqtt_client = conn::mqtt::start_listening(mqtt, connection, tx)?; // let mqtt_client = conn::mqtt::start_listening(mqtt, connection, tx)?;
// this blocks forever... the "main thread" // this blocks forever... the "main thread"

View File

@@ -48,7 +48,7 @@ pub fn button_loop(
up_times = 0; up_times = 0;
} }
if !pressed { if !pressed {
up_times = up_times + 1; up_times += 1;
// back to start after waiting for a button release // back to start after waiting for a button release
if machine.state == Status::Waiting { if machine.state == Status::Waiting {
@@ -70,11 +70,9 @@ pub fn button_loop(
} }
// if stayed up, advance // if stayed up, advance
if PAUSE * up_times > MILLIS { if PAUSE * up_times > MILLIS && machine.state == Status::Reset1 {
if machine.state == Status::Reset1 {
machine.update_status(Status::Reset2a); machine.update_status(Status::Reset2a);
} }
}
// if stays up for much longer, reset // if stays up for much longer, reset
if PAUSE * up_times > 2 * MILLIS { if PAUSE * up_times > 2 * MILLIS {
@@ -89,7 +87,7 @@ pub fn button_loop(
low_times = 0; low_times = 0;
} }
if pressed { if pressed {
low_times = low_times + 1; low_times += 1;
// if button press while in reset1, wait for a release, and reset // if button press while in reset1, wait for a release, and reset
if machine.state == Status::Reset1 { if machine.state == Status::Reset1 {

View File

@@ -100,9 +100,7 @@ impl Led {
// Set low // Set low
let mut signal = FixedLengthSignal::<24>::new(); let mut signal = FixedLengthSignal::<24>::new();
for i in 0..24 { for i in 0..24 {
let bit = 2_u32.pow(i) & 0x000000 != 0; signal.set(i as usize, &(t0h, t0l)).unwrap();
let (high_pulse, low_pulse) = if bit { (t1h, t1l) } else { (t0h, t0l) };
signal.set(i as usize, &(high_pulse, low_pulse)).unwrap();
} }
tx.start_blocking(&signal).unwrap(); tx.start_blocking(&signal).unwrap();
} }

View File

@@ -14,7 +14,7 @@ use std::io::Write;
use std::ptr; use std::ptr;
use std::string::String; use std::string::String;
const C_MOUNT_POINT: &'static [u8] = b"/sdcard\0"; const C_MOUNT_POINT: &[u8] = b"/sdcard\0";
const SPI_HOST_SLOT: spi_host_device_t = spi_host_device_t_SPI2_HOST; const SPI_HOST_SLOT: spi_host_device_t = spi_host_device_t_SPI2_HOST;
const SPI_GPIO_MOSI: gpio_num_t = 7; const SPI_GPIO_MOSI: gpio_num_t = 7;
@@ -84,7 +84,7 @@ pub fn mount_sd_card() -> anyhow::Result<()> {
if let Err(error) = esp!(unsafe { if let Err(error) = esp!(unsafe {
spi_bus_initialize( spi_bus_initialize(
SPI_HOST_SLOT as u32, SPI_HOST_SLOT,
&bus_cfg, &bus_cfg,
esp_idf_svc::sys::spi_common_dma_t_SPI_DMA_CH_AUTO, esp_idf_svc::sys::spi_common_dma_t_SPI_DMA_CH_AUTO,
) )

41
tester/Cargo.lock generated
View File

@@ -261,7 +261,7 @@ checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42"
[[package]] [[package]]
name = "bolt-derive" name = "bolt-derive"
version = "0.2.0" version = "0.2.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=19447b1e5d2956aa72aeca4229da7a96c5eaf208#19447b1e5d2956aa72aeca4229da7a96c5eaf208"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -668,8 +668,8 @@ dependencies = [
[[package]] [[package]]
name = "fsdb" name = "fsdb"
version = "0.1.17" version = "0.1.18"
source = "git+https://github.com/Evanfeenstra/fsdb.git?rev=634125776c14be45ab0618f2fa2b7f1aff4adb85#634125776c14be45ab0618f2fa2b7f1aff4adb85" source = "git+https://github.com/Evanfeenstra/fsdb.git?rev=7d0db454133bf37b16d9cf5500111491e67c81e5#7d0db454133bf37b16d9cf5500111491e67c81e5"
dependencies = [ dependencies = [
"rmp-serde", "rmp-serde",
"serde", "serde",
@@ -1151,7 +1151,7 @@ dependencies = [
[[package]] [[package]]
name = "lss-connector" name = "lss-connector"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log", "log",
@@ -1702,7 +1702,7 @@ dependencies = [
[[package]] [[package]]
name = "rmp-utils" name = "rmp-utils"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log", "log",
@@ -2014,11 +2014,11 @@ dependencies = [
[[package]] [[package]]
name = "serde_with" name = "serde_with"
version = "2.3.3" version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.21.2",
"chrono", "chrono",
"hex", "hex",
"serde", "serde",
@@ -2029,9 +2029,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_with_macros" name = "serde_with_macros"
version = "2.3.3" version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
@@ -2085,7 +2085,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-auther" name = "sphinx-auther"
version = "0.1.12" version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.21.2", "base64 0.21.2",
@@ -2097,7 +2097,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-crypter" name = "sphinx-crypter"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chacha20poly1305", "chacha20poly1305",
@@ -2108,7 +2108,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-glyph" name = "sphinx-glyph"
version = "0.1.2" version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"hex", "hex",
@@ -2147,7 +2147,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-signer" name = "sphinx-signer"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=55c4b00dc079d21353904fec45b10c7f09ec8f85#55c4b00dc079d21353904fec45b10c7f09ec8f85"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bip39", "bip39",
@@ -2538,9 +2538,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]] [[package]]
name = "txoo" name = "txoo"
version = "0.6.1" version = "0.6.2-beta.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b35482e5bf458fa43996535afbca884b2562ab6419e20686340bb19f5305b30" checksum = "74fb0ae52e565a5e1364ed50933a2a884f2e6330e8ffe9ac32ec6c4084bd3a3a"
dependencies = [ dependencies = [
"bitcoin", "bitcoin",
"log", "log",
@@ -2671,7 +2671,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "vls-core" name = "vls-core"
version = "0.10.0" version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=19447b1e5d2956aa72aeca4229da7a96c5eaf208#19447b1e5d2956aa72aeca4229da7a96c5eaf208"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bitcoin", "bitcoin",
@@ -2695,7 +2695,7 @@ dependencies = [
[[package]] [[package]]
name = "vls-persist" name = "vls-persist"
version = "0.10.0" version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=19447b1e5d2956aa72aeca4229da7a96c5eaf208#19447b1e5d2956aa72aeca4229da7a96c5eaf208"
dependencies = [ dependencies = [
"hex", "hex",
"log", "log",
@@ -2708,7 +2708,7 @@ dependencies = [
[[package]] [[package]]
name = "vls-protocol" name = "vls-protocol"
version = "0.10.0" version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=19447b1e5d2956aa72aeca4229da7a96c5eaf208#19447b1e5d2956aa72aeca4229da7a96c5eaf208"
dependencies = [ dependencies = [
"as-any", "as-any",
"bitcoin-consensus-derive", "bitcoin-consensus-derive",
@@ -2716,12 +2716,13 @@ dependencies = [
"hex", "hex",
"log", "log",
"serde_bolt", "serde_bolt",
"txoo",
] ]
[[package]] [[package]]
name = "vls-protocol-signer" name = "vls-protocol-signer"
version = "0.10.0" version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=19447b1e5d2956aa72aeca4229da7a96c5eaf208#19447b1e5d2956aa72aeca4229da7a96c5eaf208"
dependencies = [ dependencies = [
"bit-vec", "bit-vec",
"log", "log",

View File

@@ -24,8 +24,8 @@ serde_json = "1.0"
tokio = { version = "1.4.0", features = ["rt", "rt-multi-thread", "macros"] } tokio = { version = "1.4.0", features = ["rt", "rt-multi-thread", "macros"] }
urlencoding = "2.1.0" urlencoding = "2.1.0"
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "af50ee91e3600b7b4862e8f00772601c8a342110" } sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "55c4b00dc079d21353904fec45b10c7f09ec8f85" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "af50ee91e3600b7b4862e8f00772601c8a342110" } sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "55c4b00dc079d21353904fec45b10c7f09ec8f85" }
# sphinx-crypter = { path = "../../sphinx-rs/crypter" } # sphinx-crypter = { path = "../../sphinx-rs/crypter" }
# sphinx-signer = { path = "../../sphinx-rs/signer" } # sphinx-signer = { path = "../../sphinx-rs/signer" }

View File

@@ -100,7 +100,7 @@ async fn main() -> anyhow::Result<()> {
serde_json::to_string(&config)? serde_json::to_string(&config)?
}; };
let conf_encoded = urlencoding::encode(&conf_string).to_owned(); let conf_encoded = urlencoding::encode(&conf_string).into_owned();
println!("Posting seed"); println!("Posting seed");
let res2 = client let res2 = client
.post(format!("{}/{}={}", url, "config?config", conf_encoded)) .post(format!("{}/{}={}", url, "config?config", conf_encoded))

View File

@@ -42,7 +42,7 @@ fn ecdh(keys: &State<Keys>) -> String {
#[post("/config?<config>")] #[post("/config?<config>")]
fn config(keys: &State<Keys>, config: &str) -> String { fn config(keys: &State<Keys>, config: &str) -> String {
// println!("============> {:?}", config); // println!("============> {:?}", config);
let dto = serde_json::from_str::<ConfigBody>(&config).expect("failed to parse"); let dto = serde_json::from_str::<ConfigBody>(config).expect("failed to parse");
let conf = decrypt_seed(dto, keys.sk).expect("couldnt decrypt seed"); let conf = decrypt_seed(dto, keys.sk).expect("couldnt decrypt seed");
println!("SEED: ===========> {:?}", hex::encode(conf.seed)); println!("SEED: ===========> {:?}", hex::encode(conf.seed));
"{\"success\":true}".to_string() "{\"success\":true}".to_string()
@@ -62,7 +62,7 @@ pub fn decrypt_seed(dto: ConfigBody, sk1: SecretKey) -> anyhow::Result<Config> {
ssid: dto.ssid, ssid: dto.ssid,
pass: dto.pass, pass: dto.pass,
network: dto.network, network: dto.network,
seed: seed, seed,
}) })
} }