From b716484748f3706938d62f9c9f0e5594de116369 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Mon, 18 Mar 2024 20:32:10 +0100 Subject: [PATCH] fixup! feat: add initial NDN binding implementation --- example/ndn/client_example.dart | 40 ++++++++++++++++++- lib/src/binding_ndn/ndn_consumer_factory.dart | 8 +++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/example/ndn/client_example.dart b/example/ndn/client_example.dart index bee5fd74..e22464a8 100644 --- a/example/ndn/client_example.dart +++ b/example/ndn/client_example.dart @@ -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 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(); } diff --git a/lib/src/binding_ndn/ndn_consumer_factory.dart b/lib/src/binding_ndn/ndn_consumer_factory.dart index 751943ec..cf2eeee5 100644 --- a/lib/src/binding_ndn/ndn_consumer_factory.dart +++ b/lib/src/binding_ndn/ndn_consumer_factory.dart @@ -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;