ChatGPT Codex 5.2 xhigh refactored > 45min

This commit is contained in:
2026-01-13 18:59:12 +01:00
parent f76d59265c
commit b60dcef471
15 changed files with 1672 additions and 367 deletions
+32 -6
View File
@@ -1,6 +1,6 @@
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
use std::net::SocketAddr;
use std::{collections::HashMap, net::SocketAddr};
use eyre::bail;
pub use mdns_sd::DaemonEvent;
@@ -15,7 +15,12 @@ pub struct MdnsAdvertiser {
}
impl MdnsAdvertiser {
pub fn new(service_type: &str, instance_name: &str, address: SocketAddr) -> eyre::Result<Self> {
pub fn new(
service_type: &str,
instance_name: &str,
address: SocketAddr,
properties: Option<HashMap<String, String>>,
) -> eyre::Result<Self> {
let host_name = format!("{}.local.", address.ip());
let daemon = ServiceDaemon::new()?;
let service_info = ServiceInfo::new(
@@ -24,7 +29,7 @@ impl MdnsAdvertiser {
&host_name,
address.ip(),
address.port(),
None,
properties,
)?;
let monitor = daemon.monitor()?;
@@ -53,6 +58,14 @@ pub struct MdnsBrowser {
service_type: String,
}
#[derive(Debug, Clone)]
pub struct MdnsService {
pub addr: SocketAddr,
pub fullname: String,
pub hostname: String,
pub properties: HashMap<String, String>,
}
impl MdnsBrowser {
pub fn new(service_type: &str) -> eyre::Result<Self> {
let daemon = ServiceDaemon::new()?;
@@ -64,10 +77,10 @@ impl MdnsBrowser {
})
}
pub fn next_address(
pub fn next_service(
&self,
ignore_addr: Option<SocketAddr>,
) -> eyre::Result<Option<SocketAddr>> {
) -> eyre::Result<Option<MdnsService>> {
loop {
match self.receiver.recv() {
Ok(ServiceEvent::ServiceResolved(info)) => {
@@ -93,7 +106,13 @@ impl MdnsBrowser {
}
log::info!("Found server at {addr}");
return Ok(Some(addr));
let properties = info.get_properties().clone().into_property_map_str();
return Ok(Some(MdnsService {
addr,
fullname: info.get_fullname().to_string(),
hostname: info.get_hostname().to_string(),
properties,
}));
}
if ignored_match {
@@ -116,6 +135,13 @@ impl MdnsBrowser {
}
}
}
pub fn next_address(
&self,
ignore_addr: Option<SocketAddr>,
) -> eyre::Result<Option<SocketAddr>> {
Ok(self.next_service(ignore_addr)?.map(|service| service.addr))
}
}
impl Drop for MdnsBrowser {