mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-19 08:14:28 +01:00
broker logs errors to file
This commit is contained in:
@@ -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
|
||||
@@ -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<rocket::Build> {
|
||||
|
||||
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(
|
||||
|
||||
@@ -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 }),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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<broadcast::Sender<Vec<u8>>>, mut end: Shutdown)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn launch_rocket(tx: Sender<ChannelRequest>, error_tx: broadcast::Sender<Vec<u8>>, settings: Settings) -> Rocket<Build> {
|
||||
pub fn launch_rocket(
|
||||
tx: Sender<ChannelRequest>,
|
||||
error_tx: broadcast::Sender<Vec<u8>>,
|
||||
settings: Settings,
|
||||
) -> Rocket<Build> {
|
||||
let config = Config {
|
||||
address: V4(Ipv4Addr::UNSPECIFIED),
|
||||
port: settings.http_port,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user