Add node ip and node start time to node info

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet
2026-05-19 15:29:17 +02:00
parent 94f22b4905
commit 01fa99bee2
8 changed files with 56 additions and 2 deletions
+4
View File
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Add a node ip and node start time field to the node info struct.
## [0.7.7] - 2026-05-06
### Added
+9
View File
@@ -733,6 +733,10 @@ components:
description: The subnet owned by the node and advertised to peers
type: string
example: 54f:b680:ba6e:7ced::/64
nodeIp:
description: The full overlay IP of the node, derived from its public key
type: string
example: 54f:b680:ba6e:7ced:abcd:1234:5678:9abc
nodePubkey:
description: The public key of the node
type: string
@@ -740,6 +744,11 @@ components:
minLength: 64
maxLength: 64
example: 02468ace13579bdf02468ace13579bdf02468ace13579bdf02468ace13579bdf
nodeStartTime:
description: The time the node started, as seconds since the Unix epoch
type: integer
format: int64
example: 1716100000
PacketStatEntry:
description: Statistics for packets routed for a single IP address
+11
View File
@@ -871,6 +871,11 @@
"type": "string",
"example": "54f:b680:ba6e:7ced::/64"
},
"nodeIp": {
"description": "The full overlay IP of the node, derived from its public key",
"type": "string",
"example": "54f:b680:ba6e:7ced:abcd:1234:5678:9abc"
},
"nodePubkey": {
"description": "The public key of the node",
"type": "string",
@@ -878,6 +883,12 @@
"minLength": 64,
"maxLength": 64,
"example": "02468ace13579bdf02468ace13579bdf02468ace13579bdf02468ace13579bdf"
},
"nodeStartTime": {
"description": "The time the node started, as seconds since the Unix epoch",
"type": "integer",
"format": "int64",
"example": 1716100000
}
}
},
+6
View File
@@ -404,8 +404,12 @@ where
pub struct Info {
/// The overlay subnet in use by the node.
pub node_subnet: String,
/// The full overlay IP of the node.
pub node_ip: String,
/// The public key of the node
pub node_pubkey: PublicKey,
/// Node start time, as seconds since the Unix epoch.
pub node_start_time: u64,
}
/// Get general info about the node.
@@ -416,7 +420,9 @@ where
let info = state.node.lock().await.info();
Json(Info {
node_subnet: info.node_subnet.to_string(),
node_ip: info.node_ip.to_string(),
node_pubkey: info.node_pubkey,
node_start_time: info.node_start_time,
})
}
+2
View File
@@ -169,7 +169,9 @@ where
let node_info = self.state.node.lock().await.info();
Ok(Info {
node_subnet: node_info.node_subnet.to_string(),
node_ip: node_info.node_ip.to_string(),
node_pubkey: node_info.node_pubkey,
node_start_time: node_info.node_start_time,
})
}
+2
View File
@@ -320,7 +320,9 @@ pub unsafe extern "C" fn mycelium_get_node_info(
let info = h.node().lock().await.info();
*out = mycelium_node_info_t {
subnet: cstring(info.node_subnet.to_string()),
ip: cstring(info.node_ip.to_string()),
pubkey: cstring(info.node_pubkey.to_string()),
start_time: info.node_start_time,
};
MYCELIUM_OK
})
+8 -2
View File
@@ -70,7 +70,11 @@ pub struct mycelium_secret_key_t {
#[repr(C)]
pub struct mycelium_node_info_t {
pub subnet: *mut c_char,
/// The full overlay IP of the node, derived from its public key.
pub ip: *mut c_char,
pub pubkey: *mut c_char,
/// Node start time, as seconds since the Unix epoch.
pub start_time: u64,
}
/// Information about a known peer connection.
@@ -238,8 +242,8 @@ pub unsafe extern "C" fn mycelium_string_array_free(arr: *mut mycelium_string_ar
}
/// Free a `mycelium_node_info_t` populated by `mycelium_get_node_info`.
/// Releases the inner `subnet` and `pubkey` strings and resets them to
/// NULL.
/// Releases the inner `subnet`, `ip` and `pubkey` strings and resets them
/// to NULL.
///
/// # Safety
///
@@ -253,8 +257,10 @@ pub unsafe extern "C" fn mycelium_node_info_free(info: *mut mycelium_node_info_t
}
let info = &mut *info;
free_cstring(info.subnet);
free_cstring(info.ip);
free_cstring(info.pubkey);
info.subnet = std::ptr::null_mut();
info.ip = std::ptr::null_mut();
info.pubkey = std::ptr::null_mut();
}
+14
View File
@@ -133,14 +133,20 @@ pub struct Node<M> {
proxy: Proxy<M>,
#[cfg(feature = "message")]
message_stack: message::MessageStack<M>,
/// The moment this node was created, used to report uptime/start time.
started: std::time::SystemTime,
}
/// General info about a node.
pub struct NodeInfo {
/// The overlay subnet in use by the node.
pub node_subnet: Subnet,
/// The full overlay IP of the node (derived from the public key).
pub node_ip: std::net::IpAddr,
/// The public key of the node
pub node_pubkey: crypto::PublicKey,
/// Node start time, as seconds since the Unix epoch.
pub node_start_time: u64,
}
impl<M> Node<M>
@@ -149,6 +155,7 @@ where
{
/// Setup a new `Node` with the provided [`Config`].
pub async fn new(config: Config<M>) -> Result<Self, Box<dyn std::error::Error>> {
let started = std::time::SystemTime::now();
// If a private network is configured, validate network name
if let Some((net_name, _)) = &config.private_network_config {
if net_name.len() < 2 || net_name.len() > 64 {
@@ -334,6 +341,7 @@ where
proxy,
#[cfg(feature = "message")]
message_stack: ms,
started,
})
}
@@ -341,7 +349,13 @@ where
pub fn info(&self) -> NodeInfo {
NodeInfo {
node_subnet: self.router.node_tun_subnet(),
node_ip: self.router.node_public_key().address().into(),
node_pubkey: self.router.node_public_key(),
node_start_time: self
.started
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0),
}
}