Skip to content

Commit 71810bd

Browse files
committed
Support for one-shot queries
1 parent 8c40cf9 commit 71810bd

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

edge-mdns/src/io.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,26 @@ where
297297
};
298298

299299
if let MdnsResponse::Reply { data, delay } = response {
300-
if delay {
301-
self.delay().await;
302-
}
300+
if remote.port() != PORT {
301+
// Support one-shot legacy queries by replying privately
302+
// to the remote address, if the query was not sent from the mDNS port (as per the spec)
303303

304-
info!("Replying to mDNS query from {remote}");
304+
info!("Replying privately to a one-shot mDNS query from {remote}");
305305

306-
self.broadcast_once(send, data).await?;
306+
if let Err(err) = send.send(remote, data).await {
307+
warn!("Failed to reply privately to {remote}: {err:?}");
308+
}
309+
} else {
310+
// Otherwise, re-broadcast the response
311+
312+
if delay {
313+
self.delay().await;
314+
}
315+
316+
info!("Re-broadcasting due to mDNS query from {remote}");
317+
318+
self.broadcast_once(send, data).await?;
319+
}
307320
}
308321
}
309322
}

0 commit comments

Comments
 (0)