eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d3a46d5969190f3eda77c060da2f69ee74a245c6
parent 31306f258dac980408f2ff80dbcfec153843b76e
Author: Daniel Barlow <dan@telent.net>
Date:   Fri,  2 Jan 2026 20:39:47 +0000

make DnsDatabase private

Diffstat:
Mecu-esp32/src/mdns.rs | 16++++++++++------
Mecu-esp32/src/wifi.rs | 7+++----
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/ecu-esp32/src/mdns.rs b/ecu-esp32/src/mdns.rs @@ -37,14 +37,14 @@ pub enum MdnsResponderState { pub struct MdnsResponder<'a> { sock : UdpSocket<'a>, - pub database : DnsDatabase, + database : DnsDatabase, pub state : MdnsResponderState } impl<'a> MdnsResponder<'a> { pub fn new(stack : Stack<'a>, - mut sock: UdpSocket<'a>, - database: DnsDatabase) -> MdnsResponder<'a> { + mut sock: UdpSocket<'a>, + records: Vec<DnsResource>) -> MdnsResponder<'a> { sock.set_hop_limit(Some(255)); log::info!("sock.bind(5353) res: {:?}", sock.bind(MDNS_PORT)); @@ -55,11 +55,15 @@ impl<'a> MdnsResponder<'a> { Self { sock: sock, - database, + database: DnsDatabase { records }, state: MdnsResponderState::Probing(Instant::now(), 0) } } + pub fn set_records(&mut self, records: Vec<DnsResource>) { + self.database = DnsDatabase { records }; + } + async fn advance_state(&mut self) { match self.state { MdnsResponderState::Probing(next_when, number_sent) => { @@ -408,8 +412,8 @@ impl DnsResource { } } -pub struct DnsDatabase { - pub records: Vec<DnsResource> +struct DnsDatabase { + records: Vec<DnsResource> } impl DnsDatabase { diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs @@ -34,7 +34,7 @@ use esp_radio::{ }, }; -use crate::mdns::{MdnsResponder, DnsDatabase, MdnsResponderState, DnsResource, RData, DISCOVERY_NAME}; +use crate::mdns::{MdnsResponder, MdnsResponderState, DnsResource, RData, DISCOVERY_NAME}; // When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html macro_rules! mk_static { @@ -141,7 +141,7 @@ pub async fn start_wifi(spawner: &Spawner, let mut serial = None; let mut mdns_responder = MdnsResponder::new( stack, mdns_sock, - DnsDatabase { records: dns_records(my_address, serial) } + dns_records(my_address, serial) ); loop { @@ -149,8 +149,7 @@ pub async fn start_wifi(spawner: &Spawner, match mdns_responder.state { MdnsResponderState::ProbeFailed => { serial = match serial { None => Some(2), Some(n) => Some(n+1) }; - mdns_responder.database = - DnsDatabase { records: dns_records(my_address, serial) }; + mdns_responder.set_records(dns_records(my_address, serial)); mdns_responder.state = MdnsResponderState::Probing( Instant::now() + Duration::from_millis(5000), 0