feat(inventory agent): Local presence advertisement and discovery now works! Must be within the same LAN to share the multicast address though

This commit is contained in:
2025-08-29 11:22:44 -04:00
parent b857412151
commit 05e7b8075c
10 changed files with 154 additions and 30 deletions

View File

@@ -10,11 +10,10 @@ use crate::SERVICE_TYPE;
const SERVICE_PORT: u16 = 43210; // A port for the service. It needs one, even if unused.
pub async fn advertise() {
info!("Starting Harmony Agent...");
// Get a unique ID for this machine.
let motherboard_id = "some motherboard id";
let motherboard_id = "some motherboard id";
let instance_name = format!("harmony-agent-{}", motherboard_id);
info!("This agent's instance name: {}", instance_name);
info!("Advertising with ID: {}", motherboard_id);
@@ -29,11 +28,13 @@ pub async fn advertise() {
// Create the service information.
// The instance name should be unique on the network.
let local_ip = local_ip_address::local_ip().unwrap();
let service_info = ServiceInfo::new(
SERVICE_TYPE,
&instance_name,
"harmony-host.local.", // A hostname for the service
(), // No specific IP addresses, let the daemon figure it out
local_ip,
// "0.0.0.0",
SERVICE_PORT,
Some(properties),
)
@@ -43,9 +44,16 @@ pub async fn advertise() {
mdns.register(service_info)
.expect("Failed to register service");
info!("Service '{}' registered and now being advertised.", instance_name);
info!(
"Service '{}' registered and now being advertised.",
instance_name
);
info!("Agent is running. Press Ctrl+C to exit.");
for iface in get_if_addrs::get_if_addrs().unwrap() {
println!("{:#?}", iface);
}
// Keep the agent running indefinitely.
tokio::signal::ctrl_c().await.unwrap();
info!("Shutting down agent.");