From e21d89cdc55368376b3fef8cf7efce39084a6ca3 Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Sat, 8 Jun 2024 21:37:24 +0000 Subject: [PATCH] Stop using NDNts Endpoint class Endpoint class has been deleted in favor of standalone functions in @ndn/endpoint package. Also, import ValidityPeriod from @ndn/packet. --- snippets/communication/consumer.ts | 7 ++----- snippets/communication/producer.ts | 7 ++----- snippets/security/trust-domain.ts | 4 ++-- snippets/testbed/app-consumer.ts | 9 +++------ 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/snippets/communication/consumer.ts b/snippets/communication/consumer.ts index e7cf620..5e92be2 100644 --- a/snippets/communication/consumer.ts +++ b/snippets/communication/consumer.ts @@ -1,6 +1,6 @@ import { Interest } from '@ndn/packet'; import { WsTransport } from '@ndn/ws-transport'; -import { Endpoint } from '@ndn/endpoint'; +import { consume } from '@ndn/endpoint'; // Code running in the browser cannot connect to a local Unix socket. // In this example, we connect to a remote NFD instance, running as @@ -8,15 +8,12 @@ import { Endpoint } from '@ndn/endpoint'; const uplink = await WsTransport.createFace({}, "wss://suns.cs.ucla.edu/ws/"); console.log(`Connected to NFD at ${uplink.remoteAddress}`); -// Construct an Endpoint on the default forwarder instance. -const endpoint = new Endpoint(); - // Create an Interest packet const interest = new Interest(`/ndn/edu/arizona/ping/NDNts/${Date.now()}`); // Send the Interest packet and wait for the Data packet try { - const data = await endpoint.consume(interest); + const data = await consume(interest); console.log(`Received data with name [${data.name}]`); } catch (err: any) { console.warn(err); diff --git a/snippets/communication/producer.ts b/snippets/communication/producer.ts index c073453..6fccce7 100644 --- a/snippets/communication/producer.ts +++ b/snippets/communication/producer.ts @@ -1,6 +1,6 @@ import { Data, digestSigning } from '@ndn/packet'; import { WsTransport } from '@ndn/ws-transport'; -import { Endpoint } from '@ndn/endpoint'; +import { produce } from '@ndn/endpoint'; import { toUtf8 } from '@ndn/util'; // Code running in the browser cannot connect to a local Unix socket. @@ -9,11 +9,8 @@ import { toUtf8 } from '@ndn/util'; const uplink = await WsTransport.createFace({}, "wss://suns.cs.ucla.edu/ws/"); console.log(`Connected to NFD at ${uplink.remoteAddress}`); -// Construct an Endpoint on the default forwarder instance. -const endpoint = new Endpoint(); - // Start one producer -const myProducer = endpoint.produce('/edu/ucla/cs/118/notes', async (interest) => { +const myProducer = produce('/edu/ucla/cs/118/notes', async (interest) => { console.log(`Received Interest packet for ${interest.name.toString()}`); // Create the content bytes for the Data packet const content = toUtf8("Hello, NDN!"); diff --git a/snippets/security/trust-domain.ts b/snippets/security/trust-domain.ts index f655fff..56f906f 100644 --- a/snippets/security/trust-domain.ts +++ b/snippets/security/trust-domain.ts @@ -1,7 +1,7 @@ -import { Component, Data, Name } from '@ndn/packet'; +import { Component, Data, Name, ValidityPeriod } from '@ndn/packet'; import { Encoder } from '@ndn/tlv'; import { toHex, toUtf8 } from '@ndn/util'; -import { Certificate, Ed25519, generateSigningKey, ValidityPeriod } from '@ndn/keychain'; +import { Certificate, Ed25519, generateSigningKey } from '@ndn/keychain'; // Generate trust anchor of admin const adminIdentityName = new Name('/lab/admin'); diff --git a/snippets/testbed/app-consumer.ts b/snippets/testbed/app-consumer.ts index 9cdb180..a65ac73 100644 --- a/snippets/testbed/app-consumer.ts +++ b/snippets/testbed/app-consumer.ts @@ -1,16 +1,13 @@ import { connectToNetwork } from "@ndn/autoconfig"; -import { Endpoint } from "@ndn/endpoint"; +import { consume } from "@ndn/endpoint"; import { Interest } from "@ndn/packet"; -// Connect the default forwarder instance to the closest NDN testbed node using the FCH secvice +// Connect the default forwarder instance to the closest NDN testbed node using the FCH service await connectToNetwork({ fallback: ["titan.cs.memphis.edu"], // optional fallback list connectTimeout: 3000, // optional connection timeout }); -// Create an endpoint using the default forwarder instance -const endpoint = new Endpoint(); - // Send an Interest to a ping server on the testbed const interest = new Interest(`/ndn/edu/memphis/ping/1234`); -const data = await endpoint.consume(interest); // wait for echo +const data = await consume(interest); // wait for echo