mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-19 16:24:29 +01:00
broker: make Settings struct Copy, pass copies around
This commit is contained in:
@@ -98,7 +98,7 @@ async fn run_main(parent_fd: i32) -> rocket::Rocket<rocket::Build> {
|
|||||||
let (status_tx, mut status_rx) = mpsc::channel(1000);
|
let (status_tx, mut status_rx) = mpsc::channel(1000);
|
||||||
let (error_tx, _) = broadcast::channel(1000);
|
let (error_tx, _) = broadcast::channel(1000);
|
||||||
log::info!("=> start broker on network: {}", settings.network);
|
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");
|
log::info!("=> wait for connected status");
|
||||||
// wait for connection = true
|
// wait for connection = true
|
||||||
let status = status_rx.recv().await.expect("couldnt receive");
|
let status = status_rx.recv().await.expect("couldnt receive");
|
||||||
@@ -124,7 +124,7 @@ async fn run_main(parent_fd: i32) -> rocket::Rocket<rocket::Build> {
|
|||||||
let mut signer_loop = SignerLoop::new(client, tx.clone());
|
let mut signer_loop = SignerLoop::new(client, tx.clone());
|
||||||
// spawn CLN listener on a std thread
|
// spawn CLN listener on a std thread
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
signer_loop.start(Some(&settings));
|
signer_loop.start(Some(settings));
|
||||||
});
|
});
|
||||||
|
|
||||||
routes::launch_rocket(tx, error_tx)
|
routes::launch_rocket(tx, error_tx)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ pub async fn start_broker(
|
|||||||
status_sender: mpsc::Sender<bool>,
|
status_sender: mpsc::Sender<bool>,
|
||||||
error_sender: broadcast::Sender<Vec<u8>>,
|
error_sender: broadcast::Sender<Vec<u8>>,
|
||||||
expected_client_id: &str,
|
expected_client_id: &str,
|
||||||
settings: &Settings,
|
settings: Settings,
|
||||||
) {
|
) {
|
||||||
let config = config(settings);
|
let config = config(settings);
|
||||||
let client_id = expected_client_id.to_string();
|
let client_id = expected_client_id.to_string();
|
||||||
@@ -144,7 +144,7 @@ fn metrics_to_status(metrics: ConnectionMetrics, client_connected: bool) -> Opti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn config(settings: &Settings) -> Config {
|
fn config(settings: Settings) -> Config {
|
||||||
use librumqttd::rumqttlog::Config as RouterConfig;
|
use librumqttd::rumqttlog::Config as RouterConfig;
|
||||||
use librumqttd::{ConnectionSettings, SphinxLoginCredentials, ConsoleSettings, ServerSettings};
|
use librumqttd::{ConnectionSettings, SphinxLoginCredentials, ConsoleSettings, ServerSettings};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub async fn run_test() -> rocket::Rocket<rocket::Build> {
|
|||||||
let (tx, rx) = mpsc::channel(1000);
|
let (tx, rx) = mpsc::channel(1000);
|
||||||
let (status_tx, mut status_rx) = mpsc::channel(1000);
|
let (status_tx, mut status_rx) = mpsc::channel(1000);
|
||||||
let (error_tx, _) = broadcast::channel(1000);
|
let (error_tx, _) = broadcast::channel(1000);
|
||||||
start_broker(rx, status_tx, error_tx.clone(), CLIENT_ID, &settings).await;
|
start_broker(rx, status_tx, error_tx.clone(), CLIENT_ID, settings).await;
|
||||||
let mut connected = false;
|
let mut connected = false;
|
||||||
let tx_ = tx.clone();
|
let tx_ = tx.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ impl<C: 'static + Client> SignerLoop<C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start the read loop
|
/// Start the read loop
|
||||||
pub fn start(&mut self, settings: Option<&Settings>) {
|
pub fn start(&mut self, settings: Option<Settings>) {
|
||||||
info!("loop {}: start", self.log_prefix);
|
info!("loop {}: start", self.log_prefix);
|
||||||
match self.do_loop(settings) {
|
match self.do_loop(settings) {
|
||||||
Ok(()) => info!("loop {}: done", self.log_prefix),
|
Ok(()) => info!("loop {}: done", self.log_prefix),
|
||||||
@@ -70,7 +70,7 @@ impl<C: 'static + Client> SignerLoop<C> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_loop(&mut self, settings: Option<&Settings>) -> Result<()> {
|
fn do_loop(&mut self, settings: Option<Settings>) -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
let raw_msg = self.client.read_raw()?;
|
let raw_msg = self.client.read_raw()?;
|
||||||
debug!("loop {}: got raw", self.log_prefix);
|
debug!("loop {}: got raw", self.log_prefix);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use std::fs;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub network: Network,
|
pub network: Network,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
|
|||||||
Reference in New Issue
Block a user