Skip to content

Commit

Permalink
fixup! feat: add initial NDN binding implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Apr 28, 2024
1 parent 6dec8d6 commit b716484
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
40 changes: 39 additions & 1 deletion example/ndn/client_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,45 @@

import "package:dart_wot/binding_ndn.dart";
import "package:dart_wot/core.dart";
import "package:dart_wot/src/binding_ndn/ndn_config.dart";

Future<void> main() async {
final servient = Servient(clientFactories: [NdnClientFactory(ndnConfig)]);
final faceUri = Uri.parse("tcp4://localhost:6363");
final ndnConfig = NdnConfig(
faceUri: faceUri,
);

final servient = Servient(
clientFactories: [NdnClientFactory(ndnConfig: ndnConfig)],
);

final wot = await servient.start();

final thingDescription = {
"@context": "https://www.w3.org/2022/wot/td/v1.1",
"title": "NDN Thing",
"id": "urn:test",
"securityDefinitions": {
"nosec_sc": {"scheme": "nosec"},
},
"security": "nosec_sc",
"properties": {
"ping": {
"forms": [
{
"contentType": "text/plain",
"href": "ndn:///ndn/ping/9001",
},
],
},
},
}.toThingDescription();

final consumedThing = await wot.consume(thingDescription);

final result = await consumedThing.readProperty("ping");

print(await result.value());

await servient.shutdown();
}
8 changes: 7 additions & 1 deletion lib/src/binding_ndn/ndn_consumer_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import "package:meta/meta.dart";

import "../../core.dart";
import "ndn_config.dart";
import "ndn_consumer.dart";

/// A [ProtocolClientFactory] that produces
@immutable
class NdnClientFactory implements ProtocolClientFactory {
NdnClientFactory(this.ndnConfig);
/// Creates a new [ProtocolClientFactory] from an [ndnConfig].
const NdnClientFactory({
this.ndnConfig = const NdnConfig(),
});

/// The [NdnConfig] acting as the blueprint for creating
final NdnConfig ndnConfig;
Expand Down

0 comments on commit b716484

Please sign in to comment.