Remove get_local_ip - server determines IP from WebSocket connection
This commit is contained in:
parent
8824eb1ddb
commit
f8c8c8bb8e
1 changed files with 1 additions and 20 deletions
|
|
@ -382,7 +382,7 @@ impl AgentClient {
|
||||||
version: crate::version::current_version().to_string(),
|
version: crate::version::current_version().to_string(),
|
||||||
hostname: String::new(),
|
hostname: String::new(),
|
||||||
uptime_seconds: get_uptime_seconds(),
|
uptime_seconds: get_uptime_seconds(),
|
||||||
ip_address: get_local_ip().unwrap_or_default(),
|
ip_address: String::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let binary = heartbeat.encode_to_vec();
|
let binary = heartbeat.encode_to_vec();
|
||||||
|
|
@ -1311,15 +1311,6 @@ fn get_uptime_seconds() -> u64 {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get local IP address by connecting a UDP socket to a public address.
|
|
||||||
/// No data is sent; the OS resolves which local interface would be used.
|
|
||||||
fn get_local_ip() -> Option<String> {
|
|
||||||
let socket = std::net::UdpSocket::bind("0.0.0.0:0").ok()?;
|
|
||||||
socket.connect("8.8.8.8:53").ok()?;
|
|
||||||
let addr = socket.local_addr().ok()?;
|
|
||||||
Some(addr.ip().to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -1418,16 +1409,6 @@ mod tests {
|
||||||
assert_eq!(decoded, data);
|
assert_eq!(decoded, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_get_local_ip() {
|
|
||||||
let ip = get_local_ip();
|
|
||||||
// Should resolve to a valid local IP via UDP socket trick
|
|
||||||
assert!(ip.is_some(), "Expected a local IP address");
|
|
||||||
let ip_str = ip.unwrap();
|
|
||||||
assert!(!ip_str.is_empty());
|
|
||||||
assert_ne!(ip_str, "0.0.0.0");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_phoenix_message_serialization() {
|
fn test_phoenix_message_serialization() {
|
||||||
let msg = PhoenixMessage {
|
let msg = PhoenixMessage {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue