Skip to content

Commit

Permalink
Merge pull request #4 from yoursunny/ndnts-endpoint
Browse files Browse the repository at this point in the history
Stop using NDNts Endpoint class
  • Loading branch information
pulsejet authored Jun 10, 2024
2 parents f5bfb6f + e21d89c commit 3a6df32
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
7 changes: 2 additions & 5 deletions snippets/communication/consumer.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
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
// a part of the global NDN testbed.
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);
Expand Down
7 changes: 2 additions & 5 deletions snippets/communication/producer.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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!");
Expand Down
4 changes: 2 additions & 2 deletions snippets/security/trust-domain.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
9 changes: 3 additions & 6 deletions snippets/testbed/app-consumer.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3a6df32

Please sign in to comment.