From 210edf6ae62be0f10f8ffcb74b12aa7796906708 Mon Sep 17 00:00:00 2001
From: Gabriel Viganotti
Date: Thu, 16 Jan 2025 23:08:07 -0300
Subject: [PATCH] feaat: show node network IPs when home-network is disabled
---
migrations/20250116191347_node_ips.sql | 1 +
src/db_client.rs | 8 ++++++
src/docker_client.rs | 35 ++++++++++++++++++--------
src/node_instance.rs | 1 +
src/nodes_list_view.rs | 26 +++++++++++++++++--
src/server_api.rs | 30 ++++++++++++++++------
style/tailwind.css | 13 ++++++++++
7 files changed, 94 insertions(+), 20 deletions(-)
create mode 100644 migrations/20250116191347_node_ips.sql
diff --git a/migrations/20250116191347_node_ips.sql b/migrations/20250116191347_node_ips.sql
new file mode 100644
index 0000000..81c7040
--- /dev/null
+++ b/migrations/20250116191347_node_ips.sql
@@ -0,0 +1 @@
+ALTER TABLE nodes ADD ips TEXT
diff --git a/src/db_client.rs b/src/db_client.rs
index 3fc73f8..40b98aa 100644
--- a/src/db_client.rs
+++ b/src/db_client.rs
@@ -64,6 +64,7 @@ struct CachedNodeMetadata {
records: String,
connected_peers: String,
kbuckets_peers: String,
+ ips: String,
}
impl CachedNodeMetadata {
@@ -101,6 +102,9 @@ impl CachedNodeMetadata {
if let Ok(v) = self.kbuckets_peers.parse::() {
info.kbuckets_peers = Some(v);
}
+ if !self.ips.is_empty() {
+ info.ips = Some(self.ips.clone());
+ }
}
}
@@ -279,6 +283,10 @@ impl DbClient {
updates.push("kbuckets_peers=?");
params.push(kbuckets_peers.to_string());
}
+ if let Some(ips) = &info.ips {
+ updates.push("ips=?");
+ params.push(ips.clone());
+ }
if updates.is_empty() {
return; // no updates to make
diff --git a/src/docker_client.rs b/src/docker_client.rs
index 240dcac..e813b1d 100644
--- a/src/docker_client.rs
+++ b/src/docker_client.rs
@@ -261,7 +261,8 @@ impl DockerClient {
pub async fn start_container(
&self,
id: &ContainerId,
- ) -> Result<(Option, Option), DockerClientError> {
+ get_ips: bool,
+ ) -> Result<(Option, Option, Option), DockerClientError> {
let url = format!("{DOCKER_CONTAINERS_API}/{id}/start");
logging::log!("[START] Sending Docker request to START a container: {url} ...");
self.send_request(ReqMethod::post_empty_body(), &url, &[])
@@ -281,7 +282,7 @@ impl DockerClient {
.await?;
// let's try to retrieve new version
- self.get_node_version_and_peer_id(id).await
+ self.get_node_version_and_peer_id(id, get_ips).await
}
// Request the Docker server to STOP a container matching the given id
@@ -416,7 +417,8 @@ impl DockerClient {
pub async fn upgrade_node_in_container(
&self,
id: &ContainerId,
- ) -> Result
- "Home-network: "
- {move || info.read().home_network}
+ "Home-network: "
+ "On"
+ }
+ }
+ >
+
+
+ "Home-network: "
+ "Off"
+
+
+ "IPs: "
+
+
+
+ {move || info.get().ips.unwrap_or_default()}
+
+
+
+
"Created: "
diff --git a/src/server_api.rs b/src/server_api.rs
index b93c7cf..5d9ac96 100644
--- a/src/server_api.rs
+++ b/src/server_api.rs
@@ -186,7 +186,10 @@ async fn helper_start_node_instance(
.update_node_status(&container_id, NodeStatus::Restarting)
.await;
- let (version, peer_id) = context.docker_client.start_container(&container_id).await?;
+ let (version, peer_id, ips) = context
+ .docker_client
+ .start_container(&container_id, true)
+ .await?;
context
.db_client
.update_node_metadata_fields(
@@ -194,6 +197,7 @@ async fn helper_start_node_instance(
&[
("bin_version", &version.unwrap_or_default()),
("peer_id", &peer_id.unwrap_or_default()),
+ ("ips", &ips.unwrap_or_default()),
],
)
.await;
@@ -233,7 +237,11 @@ async fn helper_stop_node_instance(
.db_client
.update_node_metadata_fields(
&container_id,
- &[("connected_peers", "0"), ("kbuckets_peers", "0")],
+ &[
+ ("connected_peers", "0"),
+ ("kbuckets_peers", "0"),
+ ("ips", ""),
+ ],
)
.await;
context
@@ -271,7 +279,7 @@ pub(crate) async fn helper_upgrade_node_instance(
node_status_locked: &ImmutableNodeStatus,
db_client: &DbClient,
docker_client: &DockerClient,
-) -> Result