Skip to content

Commit

Permalink
feat: add support for CoRE RD discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Aug 22, 2022
1 parent a540629 commit 48829ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/core/protocol_interfaces/protocol_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ abstract class ProtocolClient {
/// Discovers links using the CoRE Link Format (see [RFC 6690]) from a [uri],
/// encoded as a [Stream] of [Content].
///
/// This method will also be used for discovery from CoRE Resource
/// Directories ([RFC 9176]).
///
/// If the [uri]'s path is empty, then `/.well-known/core` will be set as a
/// default value.
///
Expand All @@ -37,6 +40,7 @@ abstract class ProtocolClient {
/// activated in the config.
///
/// [RFC 6690]: https://datatracker.ietf.org/doc/html/rfc6690
/// [RFC 9176]: https://datatracker.ietf.org/doc/html/rfc9176
Stream<Content> discoverWithCoreLinkFormat(Uri uri);

/// Requests the client to perform a `readproperty` operation on a [form].
Expand Down
10 changes: 10 additions & 0 deletions lib/src/core/thing_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class ThingDiscovery extends Stream<ThingDescription>
case scripting_api.DiscoveryMethod.coreLinkFormat:
yield* _discoverWithCoreLinkFormat(thingFilter.url);
break;
case scripting_api.DiscoveryMethod.coreResourceDirectory:
yield* _discoverfromCoreResourceDirectory(thingFilter.url);
break;
default:
throw UnimplementedError();
}
Expand Down Expand Up @@ -133,6 +136,13 @@ class ThingDiscovery extends Stream<ThingDescription>
.flatten();
}

Stream<ThingDescription> _discoverfromCoreResourceDirectory(Uri uri) async* {
// TODO: Remove additional quotes once fixed in CoAP library
yield* _performCoreLinkFormatDiscovery('"core.rd-lookup-res"', uri)
.map(_discoverWithCoreLinkFormat)
.flatten();
}

Stream<Uri> _performCoreLinkFormatDiscovery(
String resourceType,
Uri uri,
Expand Down
8 changes: 8 additions & 0 deletions lib/src/scripting_api/discovery/discovery_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ enum DiscoveryMethod {
///
/// [RFC 6690]: https://datatracker.ietf.org/doc/html/rfc6690
coreLinkFormat,

/// Discovery from a CoRE Resource Directory ([RFC 9176]).
///
/// Note: This discovery method is not officially supported by the Scripting
/// API specification (yet).
///
/// [RFC 9176]: https://datatracker.ietf.org/doc/html/rfc9176
coreResourceDirectory,
}

0 comments on commit 48829ed

Please sign in to comment.