config: add node api address function
This commit is contained in:
parent
c166f21d1e
commit
8f4589615e
2 changed files with 15 additions and 14 deletions
|
@ -46,7 +46,7 @@ pub struct NodeSetup {
|
||||||
|
|
||||||
impl Default for NodeSetup {
|
impl Default for NodeSetup {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let (api_ip, api_port) = NodeConfig::get_api_address();
|
let (api_ip, api_port) = NodeConfig::get_api_ip_port();
|
||||||
let is_api_port_available = NodeConfig::is_api_port_available(&api_ip, &api_port);
|
let is_api_port_available = NodeConfig::is_api_port_available(&api_ip, &api_port);
|
||||||
Self {
|
Self {
|
||||||
available_ips: NodeConfig::get_ip_addrs(),
|
available_ips: NodeConfig::get_ip_addrs(),
|
||||||
|
@ -141,7 +141,7 @@ impl NodeSetup {
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
|
|
||||||
// Show API IP addresses to select.
|
// Show API IP addresses to select.
|
||||||
let (api_ip, api_port) = NodeConfig::get_api_address();
|
let (api_ip, api_port) = NodeConfig::get_api_ip_port();
|
||||||
NetworkSettings::ip_addrs_ui(ui, &api_ip, &self.available_ips, |selected_ip| {
|
NetworkSettings::ip_addrs_ui(ui, &api_ip, &self.available_ips, |selected_ip| {
|
||||||
let api_available = NodeConfig::is_api_port_available(selected_ip, &api_port);
|
let api_available = NodeConfig::is_api_port_available(selected_ip, &api_port);
|
||||||
self.is_api_port_available = api_available;
|
self.is_api_port_available = api_available;
|
||||||
|
@ -214,7 +214,7 @@ impl NodeSetup {
|
||||||
);
|
);
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
|
|
||||||
let (_, port) = NodeConfig::get_api_address();
|
let (_, port) = NodeConfig::get_api_ip_port();
|
||||||
View::button(ui, format!("{} {}", PLUG, port.clone()), Colors::BUTTON, || {
|
View::button(ui, format!("{} {}", PLUG, port.clone()), Colors::BUTTON, || {
|
||||||
// Setup values for modal.
|
// Setup values for modal.
|
||||||
self.api_port_edit = port;
|
self.api_port_edit = port;
|
||||||
|
@ -279,7 +279,7 @@ impl NodeSetup {
|
||||||
// Save button callback.
|
// Save button callback.
|
||||||
let on_save = || {
|
let on_save = || {
|
||||||
// Check if port is available.
|
// Check if port is available.
|
||||||
let (api_ip, _) = NodeConfig::get_api_address();
|
let (api_ip, _) = NodeConfig::get_api_ip_port();
|
||||||
let available = NodeConfig::is_api_port_available(&api_ip, &self.api_port_edit);
|
let available = NodeConfig::is_api_port_available(&api_ip, &self.api_port_edit);
|
||||||
self.api_port_available_edit = available;
|
self.api_port_available_edit = available;
|
||||||
|
|
||||||
|
|
|
@ -346,7 +346,7 @@ impl NodeConfig {
|
||||||
fn is_not_running_stratum_port_available(ip: &String, port: &String) -> bool {
|
fn is_not_running_stratum_port_available(ip: &String, port: &String) -> bool {
|
||||||
if Self::is_host_port_available(&ip, &port) {
|
if Self::is_host_port_available(&ip, &port) {
|
||||||
if &Self::get_p2p_port() != port {
|
if &Self::get_p2p_port() != port {
|
||||||
let (api_ip, api_port) = Self::get_api_address();
|
let (api_ip, api_port) = Self::get_api_ip_port();
|
||||||
return if &api_ip == ip {
|
return if &api_ip == ip {
|
||||||
&api_port != port
|
&api_port != port
|
||||||
} else {
|
} else {
|
||||||
|
@ -438,15 +438,16 @@ impl NodeConfig {
|
||||||
w_node_config.save();
|
w_node_config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get API server IP address and port.
|
/// Get API server address.
|
||||||
pub fn get_api_address() -> (String, String) {
|
pub fn get_api_address() -> String {
|
||||||
let r_config = Settings::node_config_to_read();
|
let r_config = Settings::node_config_to_read();
|
||||||
let saved_api_addr = r_config
|
r_config.node.server.api_http_addr.clone()
|
||||||
.node
|
}
|
||||||
.server
|
|
||||||
.api_http_addr
|
/// Get API server IP and port.
|
||||||
.as_str();
|
pub fn get_api_ip_port() -> (String, String) {
|
||||||
let (addr, port) = saved_api_addr.split_once(":").unwrap();
|
let saved_addr = Self::get_api_address().as_str();
|
||||||
|
let (addr, port) = saved_addr.split_once(":").unwrap();
|
||||||
(addr.into(), port.into())
|
(addr.into(), port.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,7 +629,7 @@ impl NodeConfig {
|
||||||
if port.parse::<u16>().is_err() {
|
if port.parse::<u16>().is_err() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let (_, api_port) = Self::get_api_address();
|
let (_, api_port) = Self::get_api_ip_port();
|
||||||
if Node::is_running() {
|
if Node::is_running() {
|
||||||
// Check if P2P server with same port is running.
|
// Check if P2P server with same port is running.
|
||||||
let same_running = if let Some(running_port) = Node::get_p2p_port() {
|
let same_running = if let Some(running_port) = Node::get_p2p_port() {
|
||||||
|
|
Loading…
Reference in a new issue