diff --git a/src/dns_parser/.mod.rs.swp b/src/dns_parser/.mod.rs.swp new file mode 100644 index 0000000..31ad430 Binary files /dev/null and b/src/dns_parser/.mod.rs.swp differ diff --git a/src/dns_parser/.structs.rs.swp b/src/dns_parser/.structs.rs.swp new file mode 100644 index 0000000..7868560 Binary files /dev/null and b/src/dns_parser/.structs.rs.swp differ diff --git a/src/dns_parser/mod.rs b/src/dns_parser/mod.rs index 23234a3..6a6f058 100644 --- a/src/dns_parser/mod.rs +++ b/src/dns_parser/mod.rs @@ -12,4 +12,5 @@ pub use self::header::Header; mod rrdata; pub use self::rrdata::RRData; mod builder; +#[allow(unused_imports)] pub use self::builder::{Answers, Builder, Questions}; diff --git a/src/dns_parser/structs.rs b/src/dns_parser/structs.rs index 50bdd44..f352255 100644 --- a/src/dns_parser/structs.rs +++ b/src/dns_parser/structs.rs @@ -1,6 +1,7 @@ use super::{Class, Header, Name, QueryClass, QueryType, RRData}; /// Parsed DNS packet +#[allow(dead_code)] #[derive(Debug)] pub struct Packet<'a> { pub header: Header, @@ -24,6 +25,7 @@ pub struct Question<'a> { /// We aim to provide whole range of DNS records available. But as time is /// limited we have some types of packets which are parsed and other provided /// as unparsed slice of bytes. +#[allow(dead_code)] #[derive(Debug)] pub struct ResourceRecord<'a> { pub name: Name<'a>, diff --git a/src/lib.rs b/src/lib.rs index 15f13fb..3eedf4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -269,6 +269,43 @@ impl Responder { _shutdown: self.shutdown.clone(), } } + + #[must_use] + pub fn register_with_ttl(&self, svc_type: String, svc_name: String, port: u16, txt: &[&str], ttl: u32) -> Service { + let txt = if txt.is_empty() { + vec![0] + } else { + txt.iter() + .flat_map(|entry| { + let entry = entry.as_bytes(); + if entry.len() > 255 { + panic!("{:?} is too long for a TXT record", entry); + } + std::iter::once(entry.len() as u8).chain(entry.iter().cloned()) + }) + .collect() + }; + + let svc = ServiceData { + typ: Name::from_str(format!("{}.local", svc_type)).unwrap(), + name: Name::from_str(format!("{}.{}.local", svc_name, svc_type)).unwrap(), + port: port, + txt: txt, + }; + + self.commands + .borrow_mut() + .send_unsolicited(svc.clone(), ttl, true); + + let id = self.services.write().unwrap().register(svc); + + Service { + id: id, + commands: self.commands.borrow().clone(), + services: self.services.clone(), + _shutdown: self.shutdown.clone(), + } + } } impl Drop for Service {