commit cd633862821edf38f25e597abd244dcb1868081e
parent 4219991e1c635105fe7520085c2d5140f0ac6c30
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 2 Jan 2026 19:43:38 +0000
pass records into DnsDatabase instead of making htem up
Diffstat:
1 file changed, 32 insertions(+), 32 deletions(-)
diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs
@@ -451,36 +451,6 @@ struct DnsDatabase {
}
impl DnsDatabase {
- fn create(my_ip_address : [u8; 4], serial: Option<u8>) -> Self {
- let (hostname, ptr_name) =
- match serial {
- None => (
- String::from("eculogical.local"),
- String::from("Bike._keihin._udp.local")
- ),
- Some(number) => (
- format!("eculogical{number}.local"),
- format!("Bike ({number})._keihin._udp.local")
- )
- };
-
-
- let static_records = [
- DnsResource::new(&hostname, RData::A(my_ip_address)),
- DnsResource::new(
- &ptr_name,
- RData::Srv {
- target: String::from(hostname), port: 5000,
- weight: 0, priority: 0
- }
- ),
- DnsResource::new(&ptr_name, RData::Txt(["txtvers=1".into()].into())),
- DnsResource::new("_keihin._udp.local", RData::Ptr(ptr_name)),
- DnsResource::new(DISCOVERY_NAME, RData::Ptr("_keihin._udp.local".into()))
- ];
- Self { records: Vec::from(static_records) }
- }
-
fn find<'a>(&self, name: impl Into<String>, ty: ResourceType) -> Vec<&DnsResource> {
let name = name.into();
let results : Vec<&DnsResource> =
@@ -527,6 +497,35 @@ impl DnsDatabase {
}
}
+fn dns_records(my_ip_address: [u8;4], serial: Option<usize>) -> Vec<DnsResource> {
+ let (hostname, ptr_name) =
+ match serial {
+ None => (
+ String::from("eculogical.local"),
+ String::from("Bike._keihin._udp.local")
+ ),
+ Some(number) => (
+ format!("eculogical{number}.local"),
+ format!("Bike ({number})._keihin._udp.local")
+ )
+ };
+
+
+ let records = [
+ DnsResource::new(&hostname, RData::A(my_ip_address)),
+ DnsResource::new(
+ &ptr_name,
+ RData::Srv {
+ target: String::from(hostname), port: 5000,
+ weight: 0, priority: 0
+ }
+ ),
+ DnsResource::new(&ptr_name, RData::Txt(["txtvers=1".into()].into())),
+ DnsResource::new("_keihin._udp.local", RData::Ptr(ptr_name)),
+ DnsResource::new(DISCOVERY_NAME, RData::Ptr("_keihin._udp.local".into()))
+ ];
+ Vec::from(records)
+}
pub async fn start_wifi(spawner: &Spawner,
wifi_peripheral: esp_hal::peripherals::WIFI<'static>) -> ! {
@@ -589,7 +588,7 @@ pub async fn start_wifi(spawner: &Spawner,
let mut serial = None;
let mut mdns_responder = MdnsResponder::new(
stack, sock,
- DnsDatabase::create(my_address, serial)
+ DnsDatabase { records: dns_records(my_address, serial) }
);
loop {
@@ -597,7 +596,8 @@ 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::create(my_address, serial);
+ mdns_responder.database =
+ DnsDatabase { records: dns_records(my_address, serial) };
mdns_responder.state = MdnsResponderState::Probing(
Instant::now() + Duration::from_millis(5000),
0