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 5, 2024
1 parent f4a8726 commit ec8c40e
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 @@ -275,13 +275,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 @@ -295,15 +299,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 @@ -313,15 +322,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 ec8c40e

Please sign in to comment.