Skip to content

Commit b716484

Browse files
committed
fixup! feat: add initial NDN binding implementation
1 parent 6dec8d6 commit b716484

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

example/ndn/client_example.dart

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,45 @@
88

99
import "package:dart_wot/binding_ndn.dart";
1010
import "package:dart_wot/core.dart";
11+
import "package:dart_wot/src/binding_ndn/ndn_config.dart";
1112

1213
Future<void> main() async {
13-
final servient = Servient(clientFactories: [NdnClientFactory(ndnConfig)]);
14+
final faceUri = Uri.parse("tcp4://localhost:6363");
15+
final ndnConfig = NdnConfig(
16+
faceUri: faceUri,
17+
);
18+
19+
final servient = Servient(
20+
clientFactories: [NdnClientFactory(ndnConfig: ndnConfig)],
21+
);
22+
23+
final wot = await servient.start();
24+
25+
final thingDescription = {
26+
"@context": "https://www.w3.org/2022/wot/td/v1.1",
27+
"title": "NDN Thing",
28+
"id": "urn:test",
29+
"securityDefinitions": {
30+
"nosec_sc": {"scheme": "nosec"},
31+
},
32+
"security": "nosec_sc",
33+
"properties": {
34+
"ping": {
35+
"forms": [
36+
{
37+
"contentType": "text/plain",
38+
"href": "ndn:///ndn/ping/9001",
39+
},
40+
],
41+
},
42+
},
43+
}.toThingDescription();
44+
45+
final consumedThing = await wot.consume(thingDescription);
46+
47+
final result = await consumedThing.readProperty("ping");
48+
49+
print(await result.value());
50+
51+
await servient.shutdown();
1452
}

lib/src/binding_ndn/ndn_consumer_factory.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
//
55
// SPDX-License-Identifier: BSD-3-Clause
66

7+
import "package:meta/meta.dart";
8+
79
import "../../core.dart";
810
import "ndn_config.dart";
911
import "ndn_consumer.dart";
1012

1113
/// A [ProtocolClientFactory] that produces
14+
@immutable
1215
class NdnClientFactory implements ProtocolClientFactory {
13-
NdnClientFactory(this.ndnConfig);
16+
/// Creates a new [ProtocolClientFactory] from an [ndnConfig].
17+
const NdnClientFactory({
18+
this.ndnConfig = const NdnConfig(),
19+
});
1420

1521
/// The [NdnConfig] acting as the blueprint for creating
1622
final NdnConfig ndnConfig;

0 commit comments

Comments
 (0)