diff --git a/src/lib.rs b/src/lib.rs index f9e575c..1f2717c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,7 +74,21 @@ //! // Create a daemon //! let mdns = ServiceDaemon::new().expect("Failed to create daemon"); //! +//! // Recommended: Setup a monitor connection to receive events, especially errors from the daemon thread. +//! let receiver = mdns.monitor().expect("Failed to monitor daemon"); +//! std::thread::spawn(move || { +//! while let Ok(event) = receiver.recv() { +//! match event { +//! mdns_sd::DaemonEvent::Error(error) => { +//! eprintln!("Daemon error: {error}"); +//! } +//! _ => {} +//! } +//! } +//! }); +//! //! // Create a service info. +//! // ❗ Make sure that the service name: "mdns-sd-my-test" is not longer than the max length limit. (15 characters by default) //! let service_type = "_mdns-sd-my-test._udp.local."; //! let instance_name = "my_instance"; //! let ip = "192.168.1.12"; diff --git a/src/service_daemon.rs b/src/service_daemon.rs index 0e10c1a..ff7362d 100644 --- a/src/service_daemon.rs +++ b/src/service_daemon.rs @@ -29,7 +29,7 @@ // in Service Discovery, the basic data structure is "Service Info". One Service Info // corresponds to a set of DNS Resource Records. #[cfg(feature = "logging")] -use crate::log::{debug, trace}; +use crate::log::{debug, error, trace}; use crate::{ dns_cache::{current_time_millis, DnsCache}, dns_parser::{ @@ -1863,7 +1863,7 @@ impl Zeroconf { fn register_service(&mut self, mut info: ServiceInfo) { // Check the service name length. if let Err(e) = check_service_name_length(info.get_type(), self.service_name_len_max) { - debug!("check_service_name_length: {}", &e); + error!("check_service_name_length: {}", &e); self.notify_monitors(DaemonEvent::Error(e)); return; } diff --git a/src/service_info.rs b/src/service_info.rs index 00f86db..638d21f 100644 --- a/src/service_info.rs +++ b/src/service_info.rs @@ -87,6 +87,8 @@ fn escape_instance_name(name: &str) -> String { /// as well as A (IPv4 Address) and AAAA (IPv6 Address) records. #[derive(Debug, Clone)] pub struct ServiceInfo { + // With default settings service name length must be <= 15 bytes + // so "_abcdefghijklmno._udp.local." would be valid but "_abcdefghijklmnop._udp.local." is not ty_domain: String, // . /// See RFC6763 section 7.1 about "Subtypes": @@ -128,6 +130,10 @@ impl ServiceInfo { /// /// `ty_domain` is the service type and the domain label, for example /// "_my-service._udp.local.". + /// With default settings service name length must be <= 15 bytes + /// so "_abcdefghijklmno._udp.local." would be valid but "_abcdefghijklmnop._udp.local." is not + /// ❗ **This will fail with an error log which may not be noticed unless you properly setup logging**. + /// It is recommended to setup a monitor connection via `ServiceDaemon::monitor()` /// /// `my_name` is the instance name, without the service type suffix. /// It allows dots (`.`) and backslashes (`\`).