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 Oct 27, 2023
1 parent 49c0b2d commit dd3a878
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/src/core/thing_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,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,

Check warning on line 291 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L289-L291

Added lines #L289 - L291 were not covered by tests
RRecordType.SRV,
provider: DnsApiProvider.CLOUDFLARE,
);

for (final srvRecord in srvRecords ?? <RRecord>[]) {
final serviceName = srvRecord.name;
final srvRecordEntries = srvRecord.data.split(' ');

Check warning on line 298 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L296-L298

Added lines #L296 - L298 were not covered by tests

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

Check warning on line 300 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L300

Added line #L300 was not covered by tests

if (!validSrvRecord) {
continue;
Expand All @@ -307,15 +311,20 @@ class ThingDiscovery extends Stream<ThingDescription>
continue;
}

final txtRecords =
await DnsUtils.lookupRecord(srvRecord.name, RRecordType.TXT) ?? [];
final txtRecords = await DnsUtils.lookupRecord(

Check warning on line 314 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L314

Added line #L314 was not covered by tests
serviceName,
RRecordType.TXT,
provider: DnsApiProvider.CLOUDFLARE,
) ??
[];

Check warning on line 319 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L319

Added line #L319 was not covered by tests

final txtRecord = txtRecords.firstOrNull;

Check warning on line 321 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L321

Added line #L321 was not covered by tests

if (txtRecord == null) {
continue;
}

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

Check warning on line 328 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L328

Added line #L328 was not covered by tests

final uri = Uri(

Check warning on line 330 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L330

Added line #L330 was not covered by tests
Expand All @@ -325,15 +334,14 @@ class ThingDiscovery extends Stream<ThingDescription>
scheme: parsedTxtRecord['scheme'] ?? defaultScheme,

Check warning on line 334 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L333-L334

Added lines #L333 - L334 were not covered by tests
);

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

Check warning on line 337 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L337

Added line #L337 was not covered by tests

if (duplicate) {
continue;
}

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

Check warning on line 343 in lib/src/core/thing_discovery.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/thing_discovery.dart#L343

Added line #L343 was not covered by tests

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

0 comments on commit dd3a878

Please sign in to comment.