From 16ba6711cf077d44bfaf23a565040ec309a3f205 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sat, 28 Oct 2023 01:59:46 +0200 Subject: [PATCH] fixup! feat: implement unicast DNS-SD --- .../core/implementation/thing_discovery.dart | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/src/core/implementation/thing_discovery.dart b/lib/src/core/implementation/thing_discovery.dart index ebe1e206..1d5be51d 100644 --- a/lib/src/core/implementation/thing_discovery.dart +++ b/lib/src/core/implementation/thing_discovery.dart @@ -278,13 +278,17 @@ class ThingDiscovery extends Stream const defaultType = "Thing"; for (final ptrRecord in ptrRecords ?? []) { - final srvRecords = - await DnsUtils.lookupRecord(ptrRecord.name, RRecordType.SRV); + final srvRecords = await DnsUtils.lookupRecord( + ptrRecord.name, + RRecordType.SRV, + provider: DnsApiProvider.CLOUDFLARE, + ); for (final srvRecord in srvRecords ?? []) { + final serviceName = srvRecord.name; final srvRecordEntries = srvRecord.data.split(" "); - final validSrvRecord = srvRecordEntries.length == 7; + final validSrvRecord = srvRecordEntries.length == 4; if (!validSrvRecord) { continue; @@ -298,8 +302,12 @@ class ThingDiscovery extends Stream continue; } - final txtRecords = - await DnsUtils.lookupRecord(srvRecord.name, RRecordType.TXT) ?? []; + final txtRecords = await DnsUtils.lookupRecord( + serviceName, + RRecordType.TXT, + provider: DnsApiProvider.CLOUDFLARE, + ) ?? + []; final txtRecord = txtRecords.firstOrNull; @@ -307,6 +315,7 @@ class ThingDiscovery extends Stream continue; } + // FIXME: Add parsing of multiple TXT records final parsedTxtRecord = _parseTxtRecords(txtRecord.data); final uri = Uri( @@ -316,7 +325,7 @@ class ThingDiscovery extends Stream scheme: parsedTxtRecord["scheme"] ?? defaultScheme, ); - final duplicate = discoveredUris.add(uri); + final duplicate = !discoveredUris.add(uri); if (duplicate) { continue; @@ -324,7 +333,6 @@ class ThingDiscovery extends Stream final type = parsedTxtRecord["type"] ?? defaultType; - print(parsedTxtRecord); switch (type) { case "Thing": yield* _discoverDirectly(uri);