Skip to content

Commit 0b59b71

Browse files
committed
Alter the Mdns trait and impls not to take Matter on construction, as this creates issues in rs-matter-embassy
1 parent ac4b7ba commit 0b59b71

File tree

5 files changed

+30
-71
lines changed

5 files changed

+30
-71
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn main() -> Result<(), Error> {
138138
// Will try to find a default network interface
139139
UnixNetifs,
140140
// Will use the mDNS implementation based on the `zeroconf` crate
141-
ZeroconfMdns::new(stack.matter()),
141+
ZeroconfMdns,
142142
// Will persist in `<tmp-dir>/rs-matter`
143143
&store,
144144
// Our `AsyncHandler` + `AsyncMetadata` impl

examples/light.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn main() -> Result<(), Error> {
8686
// A dummy wireless controller that does nothing
8787
NoopWirelessNetCtl::new(NetworkType::Wifi),
8888
// Will use the mDNS implementation based on the `zeroconf` crate
89-
ZeroconfMdns::new(stack.matter()),
89+
ZeroconfMdns,
9090
BuiltinGattPeripheral::new(None),
9191
),
9292
// Will persist in `<tmp-dir>/rs-matter`

examples/light_eth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn main() -> Result<(), Error> {
8686
// Will try to find a default network interface
8787
UnixNetifs,
8888
// Will use the mDNS implementation based on the `zeroconf` crate
89-
ZeroconfMdns::new(stack.matter()),
89+
ZeroconfMdns,
9090
// Will persist in `<tmp-dir>/rs-matter`
9191
&store,
9292
// Our `AsyncHandler` + `AsyncMetadata` impl

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ where
401401
let (recv, send) = socket.split();
402402

403403
let mut mdns_task = pin!(mdns.run(
404+
self.matter(),
404405
&udp_bind,
405406
&cur_netif.mac,
406407
cur_netif.ipv4,

src/mdns.rs

Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub trait Mdns {
1515
/// NOTE: This trait might change once `rs-matter` starts supporting mDNS resolvers
1616
async fn run<U>(
1717
&mut self,
18+
matter: &Matter<'_>,
1819
udp: U,
1920
mac: &[u8],
2021
ipv4: Ipv4Addr,
@@ -31,6 +32,7 @@ where
3132
{
3233
async fn run<U>(
3334
&mut self,
35+
matter: &Matter<'_>,
3436
udp: U,
3537
mac: &[u8],
3638
ipv4: Ipv4Addr,
@@ -40,24 +42,14 @@ where
4042
where
4143
U: UdpBind,
4244
{
43-
(*self).run(udp, mac, ipv4, ipv6, interface).await
45+
(*self).run(matter, udp, mac, ipv4, ipv6, interface).await
4446
}
4547
}
4648

4749
/// A built-in mDNS responder for Matter, utilizing the `rs-matter` built-in mDNS implementation.
48-
pub struct BuiltinMdns<'a> {
49-
matter: &'a Matter<'a>,
50-
}
51-
52-
impl<'a> BuiltinMdns<'a> {
53-
/// Create a new instance of the built-in mDNS responder.
54-
///
55-
/// # Arguments
56-
/// * `matter` - A reference to the Matter instance that this responder will use.
57-
pub const fn new(matter: &'a Matter<'a>) -> Self {
58-
Self { matter }
59-
}
50+
pub struct BuiltinMdns;
6051

52+
impl BuiltinMdns {
6153
/// A utility to prep and run the built-in `rs-matter` mDNS responder for Matter via the `edge-nal` UDP traits.
6254
///
6355
/// Arguments:
@@ -69,6 +61,7 @@ impl<'a> BuiltinMdns<'a> {
6961
/// - `interface`: The interface index for the host, used for IPv6 multicast.
7062
pub async fn run<U>(
7163
&mut self,
64+
matter: &Matter<'_>,
7265
udp: U,
7366
mac: &[u8],
7467
ipv4: Ipv4Addr,
@@ -137,7 +130,7 @@ impl<'a> BuiltinMdns<'a> {
137130
panic!("Invalid MAC address length: should be 6 or 8 bytes");
138131
}
139132

140-
BuiltinMdnsResponder::new(self.matter)
133+
BuiltinMdnsResponder::new(matter)
141134
.run(
142135
udp::Udp(send),
143136
udp::Udp(recv),
@@ -156,9 +149,10 @@ impl<'a> BuiltinMdns<'a> {
156149
}
157150
}
158151

159-
impl Mdns for BuiltinMdns<'_> {
152+
impl Mdns for BuiltinMdns {
160153
async fn run<U>(
161154
&mut self,
155+
matter: &Matter<'_>,
162156
udp: U,
163157
mac: &[u8],
164158
ipv4: Ipv4Addr,
@@ -168,35 +162,29 @@ impl Mdns for BuiltinMdns<'_> {
168162
where
169163
U: UdpBind,
170164
{
171-
self.run(udp, mac, ipv4, ipv6, interface).await
165+
self.run(matter, udp, mac, ipv4, ipv6, interface).await
172166
}
173167
}
174168

175169
/// An mDNS responder for Matter using the Avahi zbus mDNS implementation.
176170
#[cfg(feature = "zbus")]
177171
pub struct AvahiMdns<'a> {
178-
matter: &'a Matter<'a>,
179172
connection: &'a rs_matter::utils::zbus::Connection,
180173
}
181174

182175
#[cfg(feature = "zbus")]
183176
impl<'a> AvahiMdns<'a> {
184177
/// Create a new instance of the Avahi mDNS responder.
185-
///
186-
/// # Arguments
187-
/// * `matter` - A reference to the Matter instance that this responder will use.
188-
pub const fn new(
189-
matter: &'a Matter<'a>,
190-
connection: &'a rs_matter::utils::zbus::Connection,
191-
) -> Self {
192-
Self { matter, connection }
178+
pub const fn new(connection: &'a rs_matter::utils::zbus::Connection) -> Self {
179+
Self { connection }
193180
}
194181
}
195182

196183
#[cfg(feature = "zbus")]
197184
impl Mdns for AvahiMdns<'_> {
198185
async fn run<U>(
199186
&mut self,
187+
matter: &Matter<'_>,
200188
_udp: U,
201189
_mac: &[u8],
202190
_ipv4: Ipv4Addr,
@@ -206,7 +194,7 @@ impl Mdns for AvahiMdns<'_> {
206194
where
207195
U: UdpBind,
208196
{
209-
rs_matter::transport::network::mdns::avahi::AvahiMdnsResponder::new(self.matter)
197+
rs_matter::transport::network::mdns::avahi::AvahiMdnsResponder::new(matter)
210198
.run(self.connection)
211199
.await
212200
}
@@ -215,28 +203,22 @@ impl Mdns for AvahiMdns<'_> {
215203
/// An mDNS responder for Matter using the systemd-resolved zbus mDNS implementation.
216204
#[cfg(feature = "zbus")]
217205
pub struct ResolveMdns<'a> {
218-
matter: &'a Matter<'a>,
219206
connection: &'a rs_matter::utils::zbus::Connection,
220207
}
221208

222209
#[cfg(feature = "zbus")]
223210
impl<'a> ResolveMdns<'a> {
224211
/// Create a new instance of the systemd-resolved mDNS responder.
225-
///
226-
/// # Arguments
227-
/// * `matter` - A reference to the Matter instance that this responder will use.
228-
pub const fn new(
229-
matter: &'a Matter<'a>,
230-
connection: &'a rs_matter::utils::zbus::Connection,
231-
) -> Self {
232-
Self { matter, connection }
212+
pub const fn new(connection: &'a rs_matter::utils::zbus::Connection) -> Self {
213+
Self { connection }
233214
}
234215
}
235216

236217
#[cfg(feature = "zbus")]
237218
impl Mdns for ResolveMdns<'_> {
238219
async fn run<U>(
239220
&mut self,
221+
matter: &Matter<'_>,
240222
_udp: U,
241223
_mac: &[u8],
242224
_ipv4: Ipv4Addr,
@@ -246,33 +228,21 @@ impl Mdns for ResolveMdns<'_> {
246228
where
247229
U: UdpBind,
248230
{
249-
rs_matter::transport::network::mdns::resolve::ResolveMdnsResponder::new(self.matter)
231+
rs_matter::transport::network::mdns::resolve::ResolveMdnsResponder::new(matter)
250232
.run(self.connection)
251233
.await
252234
}
253235
}
254236

255237
/// An mDNS responder for Matter using the `zeroconf` crate.
256238
#[cfg(feature = "zeroconf")]
257-
pub struct ZeroconfMdns<'a> {
258-
matter: &'a Matter<'a>,
259-
}
260-
261-
#[cfg(feature = "zeroconf")]
262-
impl<'a> ZeroconfMdns<'a> {
263-
/// Create a new instance of the `zeroconf` `mDNS responder.
264-
///
265-
/// # Arguments
266-
/// * `matter` - A reference to the Matter instance that this responder will use.
267-
pub const fn new(matter: &'a Matter<'a>) -> Self {
268-
Self { matter }
269-
}
270-
}
239+
pub struct ZeroconfMdns;
271240

272241
#[cfg(feature = "zeroconf")]
273-
impl Mdns for ZeroconfMdns<'_> {
242+
impl Mdns for ZeroconfMdns {
274243
async fn run<U>(
275244
&mut self,
245+
matter: &Matter<'_>,
276246
_udp: U,
277247
_mac: &[u8],
278248
_ipv4: Ipv4Addr,
@@ -282,33 +252,21 @@ impl Mdns for ZeroconfMdns<'_> {
282252
where
283253
U: UdpBind,
284254
{
285-
rs_matter::transport::network::mdns::zeroconf::ZeroconfMdnsResponder::new(self.matter)
255+
rs_matter::transport::network::mdns::zeroconf::ZeroconfMdnsResponder::new(matter)
286256
.run()
287257
.await
288258
}
289259
}
290260

291261
/// An mDNS responder for Matter using the `astro-dnssd` crate.
292262
#[cfg(feature = "astro-dnssd")]
293-
pub struct AstroMdns<'a> {
294-
matter: &'a Matter<'a>,
295-
}
296-
297-
#[cfg(feature = "astro-dnssd")]
298-
impl<'a> AstroMdns<'a> {
299-
/// Create a new instance of the `astro-dnssd` `mDNS responder.
300-
///
301-
/// # Arguments
302-
/// * `matter` - A reference to the Matter instance that this responder will use.
303-
pub const fn new(matter: &'a Matter<'a>) -> Self {
304-
Self { matter }
305-
}
306-
}
263+
pub struct AstroMdns;
307264

308265
#[cfg(feature = "astro-dnssd")]
309-
impl Mdns for AstroMdns<'_> {
266+
impl Mdns for AstroMdns {
310267
async fn run<U>(
311268
&mut self,
269+
matter: &Matter<'_>,
312270
_udp: U,
313271
_mac: &[u8],
314272
_ipv4: Ipv4Addr,
@@ -318,7 +276,7 @@ impl Mdns for AstroMdns<'_> {
318276
where
319277
U: UdpBind,
320278
{
321-
rs_matter::transport::network::mdns::astro::AstroMdnsResponder::new(self.matter)
279+
rs_matter::transport::network::mdns::astro::AstroMdnsResponder::new(matter)
322280
.run()
323281
.await
324282
}

0 commit comments

Comments
 (0)