Skip to content

Commit

Permalink
fixup! feat: implement unicast DNS-SD
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jan 27, 2024
1 parent 7de5d5c commit 16ba671
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/src/core/implementation/thing_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,17 @@ class ThingDiscovery extends Stream<ThingDescription>
const defaultType = "Thing";

for (final ptrRecord in ptrRecords ?? <RRecord>[]) {
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 ?? <RRecord>[]) {
final serviceName = srvRecord.name;
final srvRecordEntries = srvRecord.data.split(" ");

final validSrvRecord = srvRecordEntries.length == 7;
final validSrvRecord = srvRecordEntries.length == 4;

if (!validSrvRecord) {
continue;
Expand All @@ -298,15 +302,20 @@ class ThingDiscovery extends Stream<ThingDescription>
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;

if (txtRecord == null) {
continue;
}

// FIXME: Add parsing of multiple TXT records
final parsedTxtRecord = _parseTxtRecords(txtRecord.data);

final uri = Uri(
Expand All @@ -316,15 +325,14 @@ class ThingDiscovery extends Stream<ThingDescription>
scheme: parsedTxtRecord["scheme"] ?? defaultScheme,
);

final duplicate = discoveredUris.add(uri);
final duplicate = !discoveredUris.add(uri);

if (duplicate) {
continue;
}

final type = parsedTxtRecord["type"] ?? defaultType;

print(parsedTxtRecord);
switch (type) {
case "Thing":
yield* _discoverDirectly(uri);
Expand Down

0 comments on commit 16ba671

Please sign in to comment.