From f6c9c5d64f7b27e7c21afefc76368fbccf80245f Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Fri, 21 Oct 2022 12:23:18 -0700 Subject: [PATCH] broker logs errors to file --- broker/README.md | 26 ++++++++++++++++++++++++++ broker/src/main.rs | 24 +++++++++++++++++++++--- broker/src/mqtt.rs | 8 +++----- broker/src/routes.rs | 15 +++++++++++---- broker/src/run_test.rs | 2 +- broker/src/util.rs | 1 + 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/broker/README.md b/broker/README.md index b17c597..32ab145 100644 --- a/broker/README.md +++ b/broker/README.md @@ -15,3 +15,29 @@ To run the broker test against the esp32-c3: cid=$(docker create sphinx-key-broker) docker cp $cid:/usr/src/sphinx-key-broker - > local-key-broker docker rm -v $cid + +### c-lightning + +##### get the version + +`git describe --tags --long --always --match='v*.*'` + +and only take the last 8 chars of the last string + +or + +`docker run -it --entrypoint "/bin/bash" sphinx-cln` + +`lightningd --version` + +##### build c-lightning + +docker build . -t sphinx-cln + +docker tag sphinx-cln sphinxlightning/sphinx-cln-vls:0.1.4 + +docker push sphinxlightning/sphinx-cln-vls:0.1.4 + +##### testing + +cargo run --bin sphinx-key-tester -- --log \ No newline at end of file diff --git a/broker/src/main.rs b/broker/src/main.rs index a1a2526..13a7875 100644 --- a/broker/src/main.rs +++ b/broker/src/main.rs @@ -13,7 +13,7 @@ use crate::util::read_broker_config; use clap::{App, AppSettings, Arg}; use rocket::tokio::{ self, - sync::{mpsc, oneshot, broadcast}, + sync::{broadcast, mpsc, oneshot}, }; use std::env; use std::sync::Arc; @@ -55,6 +55,7 @@ pub struct ChannelReply { const CLIENT_ID: &str = "sphinx-1"; const BROKER_CONFIG_PATH: &str = "../broker.conf"; +const DEFAULT_ERROR_LOG_PATH: &str = "/root/.lightning/broker_errors.log"; #[rocket::launch] async fn rocket() -> _ { @@ -96,15 +97,32 @@ async fn run_main(parent_fd: i32) -> rocket::Rocket { let (tx, rx) = mpsc::channel(1000); let (status_tx, mut status_rx) = mpsc::channel(1000); - let (error_tx, _) = broadcast::channel(1000); + let (error_tx, mut error_rx) = broadcast::channel(1000); log::info!("=> start broker on network: {}", settings.network); - start_broker(rx, status_tx, error_tx.clone(),CLIENT_ID, settings).await; + start_broker(rx, status_tx, error_tx.clone(), CLIENT_ID, settings).await; log::info!("=> wait for connected status"); // wait for connection = true let status = status_rx.recv().await.expect("couldnt receive"); log::info!("=> connection status: {}", status); // assert_eq!(status, true, "expected connected = true"); + // collect errors + tokio::spawn(async move { + use std::io::Write; + let err_log_path = env::var("BROKER_ERROR_LOG_PATH").unwrap_or(DEFAULT_ERROR_LOG_PATH.to_string()); + if let Ok(mut file) = std::fs::OpenOptions::new() + .create(true) // create if doesn't exist + .append(true) + .open(err_log_path) + { + while let Ok(err_msg) = error_rx.recv().await { + if let Err(e) = file.write_all(&err_msg) { + log::warn!("failed to write error to log {:?}", e); + } + } + } + }); + if let Ok(btc_url) = env::var("BITCOIND_RPC_URL") { let signer_port = MqttSignerPort::new(tx.clone()); let frontend = Frontend::new( diff --git a/broker/src/mqtt.rs b/broker/src/mqtt.rs index 7a482d7..f1346f3 100644 --- a/broker/src/mqtt.rs +++ b/broker/src/mqtt.rs @@ -7,7 +7,7 @@ use librumqttd::{ Config, }; use rocket::tokio::time::timeout; -use rocket::tokio::{self, sync::mpsc, sync::broadcast}; +use rocket::tokio::{self, sync::broadcast, sync::mpsc}; use sphinx_key_parser::topics; use std::sync::Arc; use std::sync::{LazyLock, Mutex}; @@ -140,7 +140,7 @@ fn metrics_to_status(metrics: ConnectionMetrics, client_connected: bool) -> Opti fn config(settings: Settings) -> Config { use librumqttd::rumqttlog::Config as RouterConfig; - use librumqttd::{ConnectionSettings, SphinxLoginCredentials, ConsoleSettings, ServerSettings}; + use librumqttd::{ConnectionSettings, ConsoleSettings, ServerSettings, SphinxLoginCredentials}; use std::collections::HashMap; use std::net::{Ipv4Addr, SocketAddrV4}; use std::path::PathBuf; @@ -167,9 +167,7 @@ fn config(settings: Settings) -> Config { max_inflight_count: 200, max_inflight_size: 1024, login_credentials: None, - sphinx_auth: Some(SphinxLoginCredentials { - within: None, - }), + sphinx_auth: Some(SphinxLoginCredentials { within: None }), }, }, ); diff --git a/broker/src/routes.rs b/broker/src/routes.rs index 42eabc0..6f6c963 100644 --- a/broker/src/routes.rs +++ b/broker/src/routes.rs @@ -2,11 +2,14 @@ use crate::util::Settings; use crate::ChannelRequest; use rocket::fairing::{Fairing, Info, Kind}; use rocket::http::Header; -use rocket::tokio::sync::{mpsc::Sender, broadcast::{self, error::RecvError}}; -use rocket::response::stream::{EventStream, Event}; +use rocket::response::stream::{Event, EventStream}; use rocket::tokio::select; +use rocket::tokio::sync::{ + broadcast::{self, error::RecvError}, + mpsc::Sender, +}; use rocket::*; -use sphinx_key_parser::{topics, error::Error as ParserError}; +use sphinx_key_parser::{error::Error as ParserError, topics}; use std::net::IpAddr::V4; use std::net::Ipv4Addr; @@ -46,7 +49,11 @@ async fn errors(error_tx: &State>>, mut end: Shutdown) } } -pub fn launch_rocket(tx: Sender, error_tx: broadcast::Sender>, settings: Settings) -> Rocket { +pub fn launch_rocket( + tx: Sender, + error_tx: broadcast::Sender>, + settings: Settings, +) -> Rocket { let config = Config { address: V4(Ipv4Addr::UNSPECIFIED), port: settings.http_port, diff --git a/broker/src/run_test.rs b/broker/src/run_test.rs index 8ad12c8..ce3f508 100644 --- a/broker/src/run_test.rs +++ b/broker/src/run_test.rs @@ -2,7 +2,7 @@ use crate::mqtt::start_broker; use crate::routes::launch_rocket; use crate::util::Settings; use crate::ChannelRequest; -use rocket::tokio::{self, sync::mpsc, sync::broadcast}; +use rocket::tokio::{self, sync::broadcast, sync::mpsc}; use sphinx_key_parser as parser; use sphinx_key_parser::topics; use vls_protocol::serde_bolt::WireString; diff --git a/broker/src/util.rs b/broker/src/util.rs index f507d76..670d3e7 100644 --- a/broker/src/util.rs +++ b/broker/src/util.rs @@ -83,6 +83,7 @@ pub fn setup_logging(who: &str, level_arg: &str) { .level(log::LevelFilter::from_str(&level).expect("level")) .level_for("h2", log::LevelFilter::Info) .level_for("sled", log::LevelFilter::Info) + .level_for("librumqttd::async_locallink", log::LevelFilter::Error) .level_for( "librumqttd::rumqttlog::router::router", log::LevelFilter::Warn,