From ce6c79adbfca2a0fe585ca4e31e7bf24c2bd6ed6 Mon Sep 17 00:00:00 2001 From: probonopd Date: Fri, 25 Apr 2025 23:06:51 +0200 Subject: [PATCH] Publish TXT record on FTP service, only show MiniDexed FTP servers in updater --- src/minidexed.cpp | 8 +++++--- updater.py | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 134d241..1e925ed 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -833,7 +833,7 @@ void CMiniDexed::SetMIDIChannel (uint8_t uchChannel, unsigned nTG) assert (nActiveTGs <= 8); static const unsigned Log2[] = {0, 0, 1, 2, 2, 3, 3, 3, 3}; - m_nActiveTGsLog2 = Log2[nActiveTGs]; + m_nActiveTGsLog2 = Log2[nActiveTGs]; */ #endif @@ -2334,7 +2334,8 @@ void CMiniDexed::UpdateNetwork() } static constexpr const char *ServiceTypeFTP = "_ftp._tcp"; - if (!m_pmDNSPublisher->PublishService (m_pConfig->GetNetworkHostname(), ServiceTypeFTP, 21)) + static const char *ftpTxt[] = { "app=MiniDexed", nullptr }; + if (!m_pmDNSPublisher->PublishService (m_pConfig->GetNetworkHostname(), ServiceTypeFTP, 21, ftpTxt)) { LOGPANIC ("Cannot publish mdns service"); } @@ -2384,7 +2385,8 @@ void CMiniDexed::UpdateNetwork() } static constexpr const char *ServiceTypeFTP = "_ftp._tcp"; - if (!m_pmDNSPublisher->PublishService (m_pConfig->GetNetworkHostname(), ServiceTypeFTP, 21)) + static const char *ftpTxt[] = { "app=MiniDexed", nullptr }; + if (!m_pmDNSPublisher->PublishService (m_pConfig->GetNetworkHostname(), ServiceTypeFTP, 21, ftpTxt)) { LOGPANIC ("Cannot publish mdns service"); } diff --git a/updater.py b/updater.py index 3307417..311b886 100644 --- a/updater.py +++ b/updater.py @@ -36,10 +36,18 @@ class MyListener(ServiceListener): info = zc.get_service_info(type_, name) print(f"Service {name} added, service info: {info}") if info and info.addresses: - ip = socket.inet_ntoa(info.addresses[0]) - if ip not in self.ip_list: - self.ip_list.append(ip) - self.name_list.append(info.server.rstrip('.')) + # Only add if TXT record contains 'MiniDexed' + txt_records = info.properties + if txt_records: + for k, v in txt_records.items(): + # v may be bytes, decode if needed + val = v.decode() if isinstance(v, bytes) else v + if (b"MiniDexed" in k or b"MiniDexed" in v) or ("MiniDexed" in str(k) or "MiniDexed" in str(val)): + ip = socket.inet_ntoa(info.addresses[0]) + if ip not in self.ip_list: + self.ip_list.append(ip) + self.name_list.append(info.server.rstrip('.')) + break # Constants