mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-20 23:25:48 +01:00
broker: add http_port file setting, and BROKER_HTTP_PORT env var
This commit is contained in:
@@ -7,6 +7,7 @@ use toml::Value;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Settings {
|
||||
pub http_port: u16,
|
||||
pub mqtt_port: u16,
|
||||
pub network: Network,
|
||||
}
|
||||
@@ -14,6 +15,7 @@ pub struct Settings {
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Settings {
|
||||
http_port: 8000,
|
||||
mqtt_port: 1883,
|
||||
network: Network::Regtest,
|
||||
}
|
||||
@@ -31,6 +33,9 @@ pub fn read_broker_config(config_path: &str) -> Settings {
|
||||
if let Some(mqtt_port) = read_mqtt_port_setting(&table) {
|
||||
settings.mqtt_port = mqtt_port;
|
||||
}
|
||||
if let Some(http_port) = read_http_port_setting(&table) {
|
||||
settings.http_port = http_port;
|
||||
}
|
||||
} else {
|
||||
log::info!("File broker.conf not found, using default settings");
|
||||
}
|
||||
@@ -46,6 +51,13 @@ pub fn read_broker_config(config_path: &str) -> Settings {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Ok(env_port) = env::var("BROKER_HTTP_PORT") {
|
||||
if let Ok(http_port) = env_port.parse::<u16>() {
|
||||
if http_port > 1023 {
|
||||
settings.http_port = http_port;
|
||||
}
|
||||
}
|
||||
}
|
||||
settings
|
||||
}
|
||||
|
||||
@@ -119,3 +131,23 @@ fn read_mqtt_port_setting(table: &Value) -> Option<u16> {
|
||||
Some(temp.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
fn read_http_port_setting(table: &Value) -> Option<u16> {
|
||||
if let None = table.get("http_port") {
|
||||
log::info!("Broker http port not specified, setting to default 8000");
|
||||
None
|
||||
} else {
|
||||
let temp = table["http_port"]
|
||||
.as_integer()
|
||||
.expect("The http port number is not an integer greater than 1023");
|
||||
if temp <= 1023 {
|
||||
panic!("The http port number is not an integer greater than 1023")
|
||||
}
|
||||
let max: i64 = u16::MAX.into();
|
||||
if temp > max {
|
||||
panic!("The http port number is way too big!")
|
||||
}
|
||||
log::info!("Read broker http port setting: {}", temp);
|
||||
Some(temp.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user