diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md
index 33f9816ec0c..b75746c62b9 100644
--- a/protocols/mdns/CHANGELOG.md
+++ b/protocols/mdns/CHANGELOG.md
@@ -4,6 +4,10 @@
- Update to `libp2p-swarm` `v0.41.0`.
+- Use `trust-dns-proto` to parse DNS messages. See [PR 3102].
+
+[PR 3102]: https://github.com/libp2p/rust-libp2p/pull/3102
+
# 0.41.0
- Remove default features. If you previously depended on `async-io` you need to enable this explicitly now. See [PR 2918].
diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml
index 5729043514e..78b3a26d67f 100644
--- a/protocols/mdns/Cargo.toml
+++ b/protocols/mdns/Cargo.toml
@@ -11,8 +11,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
+async-io = { version = "1.3.1", optional = true }
data-encoding = "2.3.2"
-dns-parser = "0.8.0"
futures = "0.3.13"
if-watch = "2.0.0"
libp2p-core = { version = "0.38.0", path = "../../core" }
@@ -21,10 +21,9 @@ log = "0.4.14"
rand = "0.8.3"
smallvec = "1.6.1"
socket2 = { version = "0.4.0", features = ["all"] }
-void = "1.0.2"
-
-async-io = { version = "1.3.1", optional = true }
tokio = { version = "1.19", default-features = false, features = ["net", "time"], optional = true}
+trust-dns-proto = { version = "0.22.0", default-features = false, features = ["mdns"] }
+void = "1.0.2"
[features]
tokio = ["dep:tokio"]
diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs
index 4590e1e266e..1f0825727a2 100644
--- a/protocols/mdns/src/behaviour/iface/dns.rs
+++ b/protocols/mdns/src/behaviour/iface/dns.rs
@@ -395,14 +395,14 @@ impl error::Error for MdnsResponseError {}
#[cfg(test)]
mod tests {
use super::*;
- use dns_parser::Packet;
use libp2p_core::identity;
use std::time::Duration;
+ use trust_dns_proto::op::Message;
#[test]
fn build_query_correct() {
let query = build_query();
- assert!(Packet::parse(&query).is_ok());
+ assert!(Message::from_vec(&query).is_ok());
}
#[test]
@@ -417,14 +417,14 @@ mod tests {
Duration::from_secs(60),
);
for packet in packets {
- assert!(Packet::parse(&packet).is_ok());
+ assert!(Message::from_vec(&packet).is_ok());
}
}
#[test]
fn build_service_discovery_response_correct() {
let query = build_service_discovery_response(0x1234, Duration::from_secs(120));
- assert!(Packet::parse(&query).is_ok());
+ assert!(Message::from_vec(&query).is_ok());
}
#[test]
diff --git a/protocols/mdns/src/behaviour/iface/query.rs b/protocols/mdns/src/behaviour/iface/query.rs
index 70e38016849..50b86bd888f 100644
--- a/protocols/mdns/src/behaviour/iface/query.rs
+++ b/protocols/mdns/src/behaviour/iface/query.rs
@@ -19,8 +19,7 @@
// DEALINGS IN THE SOFTWARE.
use super::dns;
-use crate::{META_QUERY_SERVICE, SERVICE_NAME};
-use dns_parser::{Packet, RData};
+use crate::{META_QUERY_SERVICE_FQDN, SERVICE_NAME_FQDN};
use libp2p_core::{
address_translation,
multiaddr::{Multiaddr, Protocol},
@@ -28,6 +27,10 @@ use libp2p_core::{
};
use std::time::Instant;
use std::{convert::TryFrom, fmt, net::SocketAddr, str, time::Duration};
+use trust_dns_proto::{
+ op::Message,
+ rr::{Name, RData},
+};
/// A valid mDNS packet received by the service.
#[derive(Debug)]
@@ -44,33 +47,33 @@ impl MdnsPacket {
pub fn new_from_bytes(
buf: &[u8],
from: SocketAddr,
- ) -> Result