eculocate

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

commit f5a1064264171d17698935a914f5fb01a6ca60e1
parent 7696ac0277cdd685429501da59c1675444a93ee0
Author: Daniel Barlow <dan@telent.net>
Date:   Wed, 31 Dec 2025 23:48:28 +0000

add optional suffix to dns record names

this is in preparation for handling probe failures (name collisions)

Diffstat:
Mecu-esp32/src/wifi.rs | 42++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs @@ -5,6 +5,7 @@ // use alloc::vec; use alloc::vec::Vec; use alloc::string::String; +use alloc::format; use alloc::collections::BTreeSet; use crate::alloc::string::ToString; @@ -94,7 +95,7 @@ impl<'a> MdnsResponder<'a> { Self { sock, - database: DnsDatabase::create(my_address), + database: DnsDatabase::create(my_address, None), } } @@ -374,31 +375,32 @@ struct DnsDatabase { } impl DnsDatabase { - fn create(my_ip_address : [u8; 4]) -> Self { + 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( - "eculogical.local", - RData::A(my_ip_address) - ), - DnsResource::new( - "Bike._keihin._udp.local", + &ptr_name, RData::Srv { - target: String::from("eculogical.local"), port: 5000, + target: String::from(hostname), port: 5000, weight: 0, priority: 0 } ), - DnsResource::new( - "Bike._keihin._udp.local", - RData::Txt(["txtvers=1".into()].into()) - ), - DnsResource::new( - "_keihin._udp.local", - RData::Ptr("Bike._keihin._udp.local".into()) - ), - DnsResource::new( - DISCOVERY_NAME, - RData::Ptr("_keihin._udp.local".into()) - ) + 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) } }