Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/service_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/service_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, // <service>.<domain>

/// See RFC6763 section 7.1 about "Subtypes":
Expand Down Expand Up @@ -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 (`\`).
Expand Down