Skip to content

Commit

Permalink
Merge pull request #48 from stakwork/update-deps
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
Evanfeenstra authored Jul 22, 2022
2 parents d866ece + b6fdb3f commit 11b9a26
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 58 deletions.
2 changes: 1 addition & 1 deletion persister/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ lightning-signer-core = { git = "https://gitlab.com/Evanfeenstra/validating-ligh
lightning-signer-server = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "patch-sign-chan", default-features = false, features = ["persist", "secp-lowmemory"] }
serde = { version = "1.0.105" }
hex = "0.4.3"
fsdb = "0.1.10"
fsdb = "0.1.11"
log = "0.4"
1 change: 1 addition & 0 deletions persister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl Persist for FsPersister {
Ok(ns) => ns,
Err(_) => return res,
};
log::info!("NODE LIST LEN {}", list.len());
for pk in list {
if let Ok(pubkey) = self.pubkeys.get(&pk) {
if let Ok(node) = self.nodes.get(&pk) {
Expand Down
3 changes: 2 additions & 1 deletion signer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use lightning_signer::persist::{DummyPersister, Persist};
use lightning_signer::persist::Persist;
// use lightning_signer::persist::DummyPersister;
use std::sync::Arc;
use vls_protocol::model::PubKey;
use vls_protocol::msgs::{self, read_serial_request_header, write_serial_response_header, Message};
Expand Down
2 changes: 1 addition & 1 deletion sphinx-key/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF vers
[env]
# Note: these variables are not used when using pio builder
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF stable (v4.4)
ESP_IDF_VERSION = { value = "tag:v4.4.1" }
ESP_IDF_VERSION = { value = "release/v4.4" }
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF master (mainline)
#ESP_IDF_VERSION = { value = "master" }
8 changes: 5 additions & 3 deletions sphinx-key/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ default = ["std"]
std = ["sphinx-key-signer"]
pio = ["esp-idf-sys/pio"]
pingpong = []
no_persist = []

[dependencies]
bitflags = "1.3.2"
esp-idf-sys = { version = "0.31.6", features = ["binstart"] }
sphinx-key-signer = { path = "../signer", optional = true }
sphinx-key-crypter = { path = "../crypter" }
embedded-svc = { version = "0.21.2" }
esp-idf-svc = "0.41"
esp-idf-hal = "0.37"
embedded-svc = "0.22.0"
esp-idf-svc = "0.42.1"
esp-idf-hal = "0.38.0"
embedded-hal = "=1.0.0-alpha.8"
anyhow = {version = "1", features = ["backtrace"]}
log = "0.4"
Expand All @@ -34,6 +35,7 @@ serde_urlencoded = "0.7.1"
serde = { version = "1.0.137", default-features = false }
serde_json = { version = "1.0.81", default-features = false }
hex = "0.4.3"
rmp-serde = "1.1.0"

[patch.crates-io]
# updates the "rand" create to use esp RNG
Expand Down
7 changes: 4 additions & 3 deletions sphinx-key/src/clear.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported

use embedded_svc::storage::StorageBase;
use esp_idf_svc::nvs::*;
use esp_idf_svc::nvs_storage::EspNvsStorage;
use embedded_svc::storage::Storage;

use std::sync::Arc;

fn main() -> anyhow::Result<()> {
let default_nvs = Arc::new(EspDefaultNvs::new()?);
let mut store = EspNvsStorage::new_default(default_nvs.clone(), "sphinx", true).expect("no storage");
let mut store =
EspNvsStorage::new_default(default_nvs.clone(), "sphinx", true).expect("no storage");
store.remove("config").expect("couldnt remove config 1");
println!("NVS cleared!");
Ok(())
}
}
80 changes: 41 additions & 39 deletions sphinx-key/src/conn/wifi.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
use crate::core::config::Config;

use esp_idf_svc::wifi::*;
use esp_idf_svc::sysloop::*;
use esp_idf_svc::netif::*;
use esp_idf_svc::nvs::EspDefaultNvs;
use esp_idf_svc::ping;
use esp_idf_svc::sysloop::*;
use esp_idf_svc::wifi::*;

use embedded_svc::wifi::*;
use embedded_svc::httpd::Result;
use embedded_svc::ping::Ping;
use embedded_svc::ipv4;
use embedded_svc::ping::Ping;
use embedded_svc::wifi::Wifi;
use embedded_svc::wifi::*;

use log::*;
use std::time::Duration;
use std::sync::Arc;
use std::thread;
use std::time::Duration;

pub fn start_client(
default_nvs: Arc<EspDefaultNvs>,
config: &Config,
) -> Result<Box<EspWifi>> {
pub fn start_client(default_nvs: Arc<EspDefaultNvs>, config: &Config) -> Result<Box<EspWifi>> {
let netif_stack = Arc::new(EspNetifStack::new()?);
let sys_loop_stack = Arc::new(EspSysLoopStack::new()?);

Expand All @@ -30,24 +28,29 @@ pub fn start_client(

let ours = ap_infos.into_iter().find(|a| a.ssid == ssid);
let channel = if let Some(ours) = ours {
info!("Found configured access point {} on channel {}", ssid, ours.channel);
info!(
"Found configured access point {} on channel {}",
ssid, ours.channel
);
Some(ours.channel)
} else {
info!("Configured access point {} not found during scanning, will go with unknown channel", ssid);
info!(
"Configured access point {} not found during scanning, will go with unknown channel",
ssid
);
None
};

wifi.set_configuration(&Configuration::Client(
ClientConfiguration {
ssid: ssid.into(),
password: pass.into(),
channel,
..Default::default()
}
))?;
wifi.set_configuration(&Configuration::Client(ClientConfiguration {
ssid: ssid.into(),
password: pass.into(),
channel,
..Default::default()
}))?;

info!("...Wifi client configuration set, get status");
match wifi.wait_status_with_timeout(Duration::from_secs(20), |status| !status.is_transitional()) {
match wifi.wait_status_with_timeout(Duration::from_secs(20), |status| !status.is_transitional())
{
Ok(_) => (),
Err(e) => warn!("Unexpected Wifi status: {:?}", e),
};
Expand All @@ -58,44 +61,40 @@ pub fn start_client(
if let Status(
ClientStatus::Started(ClientConnectionStatus::Connected(ClientIpStatus::Done(ip_settings))),
ApStatus::Stopped,
) = status {
) = status
{
info!("Wifi started!");
ping(&ip_settings)?;
} else {
thread::sleep(Duration::from_secs(13));
// bail!("Unexpected Client Wifi status: {:?}", status);
return Err(anyhow::anyhow!("Unexpected Client Wifi status: {:?}", status));
return Err(anyhow::anyhow!(
"Unexpected Client Wifi status: {:?}",
status
));
}

info!("wifi::start_client Ok(())");

Ok(wifi)
}

pub fn start_access_point(
default_nvs: Arc<EspDefaultNvs>,
) -> Result<Box<EspWifi>> {
pub fn start_access_point(default_nvs: Arc<EspDefaultNvs>) -> Result<Box<EspWifi>> {
let netif_stack = Arc::new(EspNetifStack::new()?);
let sys_loop_stack = Arc::new(EspSysLoopStack::new()?);

let mut wifi = Box::new(EspWifi::new(netif_stack, sys_loop_stack, default_nvs)?);
wifi.set_configuration(&Configuration::AccessPoint(
AccessPointConfiguration {
ssid: "sphinxkey".into(),
channel: 6,
..Default::default()
},
))?;
wifi.set_configuration(&Configuration::AccessPoint(AccessPointConfiguration {
ssid: "sphinxkey".into(),
channel: 6,
..Default::default()
}))?;

info!("Wifi configuration set, about to get status");
wifi.wait_status_with_timeout(Duration::from_secs(20), |status| !status.is_transitional())
.map_err(|e| anyhow::anyhow!("Unexpected Wifi status: {:?}", e))?;

let status = wifi.get_status();
if let Status(
ClientStatus::Stopped,
ApStatus::Started(ApIpStatus::Done),
) = status {
if let Status(ClientStatus::Stopped, ApStatus::Started(ApIpStatus::Done)) = status {
info!("Wifi started!");
} else {
return Err(anyhow::anyhow!("Unexpected AP Wifi status: {:?}", status));
Expand All @@ -110,10 +109,13 @@ fn ping(ip_settings: &ipv4::ClientSettings) -> Result<()> {
let ping_summary =
ping::EspPing::default().ping(ip_settings.subnet.gateway, &Default::default())?;
if ping_summary.transmitted != ping_summary.received {
return Err(anyhow::anyhow!("Pinging gateway {} resulted in timeouts", ip_settings.subnet.gateway));
return Err(anyhow::anyhow!(
"Pinging gateway {} resulted in timeouts",
ip_settings.subnet.gateway
));
}

info!("Pinging done");

Ok(())
}
}
11 changes: 5 additions & 6 deletions sphinx-key/src/core/events.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::conn::mqtt::{QOS, RETURN_TOPIC, TOPIC};
use crate::core::init::make_init_msg;

use sphinx_key_signer::lightning_signer::bitcoin::Network;
use sphinx_key_signer::vls_protocol::model::PubKey;
use sphinx_key_signer::{self, InitResponse};
use sphinx_key_signer::lightning_signer::bitcoin::Network;
use std::sync::mpsc;

use embedded_svc::httpd::Result;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn make_event_loop(
network: Network,
do_log: bool,
led_tx: mpsc::Sender<Status>,
seed: [u8; 32]
seed: [u8; 32],
) -> Result<()> {
while let Ok(event) = rx.recv() {
match event {
Expand All @@ -66,7 +66,6 @@ pub fn make_event_loop(
root_handler,
init_reply: _,
} = sphinx_key_signer::init(init_msg, network).expect("failed to init signer");

// signing loop
let dummy_peer = PubKey([0; 33]);
while let Ok(event) = rx.recv() {
Expand All @@ -86,9 +85,9 @@ pub fn make_event_loop(
do_log,
) {
Ok(b) => {
mqtt.publish(RETURN_TOPIC, QOS, false, b)
mqtt.publish(RETURN_TOPIC, QOS, false, &b)
.expect("could not publish init response");
},
}
Err(e) => {
log::error!("HANDLE FAILED {:?}", e);
// panic!("HANDLE FAILED {:?}", e);
Expand All @@ -112,7 +111,7 @@ pub fn make_event_loop(
_network: Network,
do_log: bool,
led_tx: mpsc::Sender<Status>,
_seed: [u8; 32]
_seed: [u8; 32],
) -> Result<()> {
log::info!("About to subscribe to the mpsc channel");
while let Ok(event) = rx.recv() {
Expand Down
12 changes: 8 additions & 4 deletions sphinx-key/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::sync::{mpsc, Arc};
use std::thread;
use std::time::Duration;

use embedded_svc::storage::Storage;
use embedded_svc::storage::RawStorage;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_svc::nvs::*;
use esp_idf_svc::nvs_storage::EspNvsStorage;
Expand Down Expand Up @@ -49,8 +49,11 @@ fn main() -> Result<()> {
let default_nvs = Arc::new(EspDefaultNvs::new()?);
let mut store =
EspNvsStorage::new_default(default_nvs.clone(), "sphinx", true).expect("no storage");
let existing: Option<Config> = store.get("config").expect("failed");
if let Some(exist) = existing {
let mut buf = [0u8; 250];
// let existing: Option<Config> = store.get_raw("config", buf).expect("failed");
let existing = store.get_raw("config", &mut buf).expect("failed");
if let Some((exist_bytes, _)) = existing {
let exist: Config = rmp_serde::from_slice(exist_bytes).expect("failed to parse Config");
println!(
"=============> START CLIENT NOW <============== {:?}",
exist
Expand Down Expand Up @@ -82,8 +85,9 @@ fn main() -> Result<()> {
led_tx.send(Status::WifiAccessPoint).unwrap();
println!("=============> START SERVER NOW AND WAIT <==============");
if let Ok((wifi, config)) = start_config_server_and_wait(default_nvs.clone()) {
let conf = rmp_serde::to_vec(&config).expect("couldnt rmp Config");
store
.put("config", &config)
.put_raw("config", &conf[..])
.expect("could not store config");
println!("CONFIG SAVED");
drop(wifi);
Expand Down

0 comments on commit 11b9a26

Please sign in to comment.