Skip to content

Commit

Permalink
Rollback dns_parser.rs from mdns-parser subcrate to mdns-sd crate (#297)
Browse files Browse the repository at this point in the history
This is rolling back the changes of PR #284 . The main reasons are:

- Increased complexity of this repo. I felt it's more difficult to maintain mdns-sd now.
- According to crates.io, it seems not many users of the extracted sub crate mdns-parser.

Overall, I felt it was not a good trade-off at this point. If we were to extract the parser in the future, it's probably better / cleaner to move it to its own repo.
  • Loading branch information
keepsimple1 authored Feb 2, 2025
1 parent 4288190 commit a2814fd
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 88 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ if-addrs = { version = "0.13", features = ["link-local"] } # get local IP addres
log = { version = "0.4", optional = true } # logging
mio = { version = "1.0", features = ["os-poll", "net"] } # select/poll sockets
socket2 = { version = "0.5.5", features = ["all"] } # socket APIs
mdns-parser = { path = "mdns-parser" } # DNS message parsing

[dev-dependencies]
env_logger = { version = "= 0.10.2", default-features = false, features= ["humantime"] }
Expand Down
19 changes: 0 additions & 19 deletions mdns-parser/Cargo.toml

This file was deleted.

12 changes: 0 additions & 12 deletions mdns-parser/README.md

This file was deleted.

28 changes: 0 additions & 28 deletions mdns-parser/src/lib.rs

This file was deleted.

6 changes: 4 additions & 2 deletions src/dns_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#[cfg(feature = "logging")]
use crate::log::trace;
use crate::service_info::{split_sub_domain, valid_two_addrs_on_intf};
use crate::{
dns_parser::{DnsAddress, DnsPointer, DnsRecordBox, DnsSrv, RRType},
service_info::{split_sub_domain, valid_two_addrs_on_intf},
};
use if_addrs::Interface;
use mdns_parser::{DnsAddress, DnsPointer, DnsRecordBox, DnsSrv, RRType};
use std::{
collections::{HashMap, HashSet},
net::IpAddr,
Expand Down
14 changes: 1 addition & 13 deletions mdns-parser/src/dns_parser.rs → src/dns_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,18 +883,6 @@ pub struct TxtProperty {
}

impl TxtProperty {
/// Returns the key of a property.
pub fn key(&self) -> &str {
&self.key
}

/// Returns the value of a property, which could be `None`.
///
/// To obtain a `&str` of the value, use `val_str()` instead.
pub fn val(&self) -> Option<&[u8]> {
self.val.as_deref()
}

/// Returns the value of a property as str.
pub fn val_str(&self) -> &str {
self.val
Expand Down Expand Up @@ -1085,7 +1073,7 @@ impl DnsNSec {
}

/// Returns the types marked by `type_bitmap`
pub fn types(&self) -> Vec<u16> {
pub fn _types(&self) -> Vec<u16> {
// From RFC 4034: 4.1.2 The Type Bit Maps Field
// https://datatracker.ietf.org/doc/html/rfc4034#section-4.1.2
//
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ mod log {
}

mod dns_cache;
mod dns_parser;
mod error;
mod service_daemon;
mod service_info;

pub use dns_parser::RRType;
pub use error::{Error, Result};
pub use service_daemon::{
DaemonEvent, DaemonStatus, DnsNameChange, HostnameResolutionEvent, IfKind, Metrics,
Expand All @@ -160,6 +162,3 @@ pub use service_info::{AsIpAddrs, IntoTxtProperties, ServiceInfo, TxtProperties,

/// A handler to receive messages from [ServiceDaemon]. Re-export from `flume` crate.
pub use flume::Receiver;

/// DNS Resource Record types. Re-export from `mdns-parser` crate.
pub use mdns_parser::RRType;
18 changes: 10 additions & 8 deletions src/service_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
use crate::log::{debug, trace};
use crate::{
dns_cache::{current_time_millis, DnsCache},
dns_parser::{
ip_address_rr_type, DnsAddress, DnsEntryExt, DnsIncoming, DnsOutgoing, DnsPointer,
DnsRecordBox, DnsRecordExt, DnsSrv, DnsTxt, RRType, CLASS_CACHE_FLUSH, CLASS_IN, FLAGS_AA,
FLAGS_QR_QUERY, FLAGS_QR_RESPONSE, MAX_MSG_ABSOLUTE,
},
error::{Error, Result},
service_info::{
split_sub_domain, valid_ip_on_intf, DnsRegistry, Probe, ServiceInfo, ServiceStatus,
Expand All @@ -40,11 +45,6 @@ use crate::{
};
use flume::{bounded, Sender, TrySendError};
use if_addrs::{IfAddr, Interface};
use mdns_parser::{
ip_address_rr_type, DnsAddress, DnsEntryExt, DnsIncoming, DnsOutgoing, DnsPointer,
DnsRecordBox, DnsRecordExt, DnsSrv, DnsTxt, RRType, CLASS_CACHE_FLUSH, CLASS_IN, FLAGS_AA,
FLAGS_QR_QUERY, FLAGS_QR_RESPONSE, MAX_MSG_ABSOLUTE,
};
use mio::{net::UdpSocket as MioUdpSocket, Poll};
use socket2::Socket;
use std::{
Expand Down Expand Up @@ -2210,7 +2210,7 @@ impl Zeroconf {
|| service
.get_subtype()
.as_ref()
.map_or(false, |v| v == question.entry_name())
.is_some_and(|v| v == question.entry_name())
{
add_answer_with_additionals(&mut out, &msg, service, intf, dns_registry);
} else if question.entry_name() == META_QUERY {
Expand Down Expand Up @@ -3497,8 +3497,10 @@ mod tests {
HostnameResolutionEvent, ServiceDaemon, ServiceEvent, ServiceInfo, GROUP_ADDR_V4,
MDNS_PORT,
};
use crate::service_daemon::check_hostname;
use mdns_parser::{DnsOutgoing, DnsPointer, RRType, CLASS_IN, FLAGS_AA, FLAGS_QR_RESPONSE};
use crate::{
dns_parser::{DnsOutgoing, DnsPointer, RRType, CLASS_IN, FLAGS_AA, FLAGS_QR_RESPONSE},
service_daemon::check_hostname,
};
use std::{
net::{SocketAddr, SocketAddrV4},
time::Duration,
Expand Down
6 changes: 4 additions & 2 deletions src/service_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#[cfg(feature = "logging")]
use crate::log::debug;
use crate::{Error, Result};
use crate::{
dns_parser::{DnsRecordBox, DnsRecordExt, DnsSrv, RRType},
Error, Result,
};
use if_addrs::{IfAddr, Interface};
use mdns_parser::{DnsRecordBox, DnsRecordExt, DnsSrv, RRType};
use std::{
cmp,
collections::{HashMap, HashSet},
Expand Down

0 comments on commit a2814fd

Please sign in to comment.