Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@ndn/endpoint
Advanced tools
This package is part of NDNts, Named Data Networking libraries for the modern web.
This package implements the endpoint concept, consisting of consume
and produce
functions.
These are the basic abstractions through which an application can communicate with the NDN network.
The endpoint concept is similar to a "client face" in other NDN libraries, with the enhancement that it handles these details automatically:
@ndn/l3face
package).@ndn/nfdmgmt
package).import { consume, produce } from "@ndn/endpoint";
// other imports for examples
import { generateSigningKey } from "@ndn/keychain";
import { Data, digestSigning } from "@ndn/packet";
import { fromUtf8, toUtf8 } from "@ndn/util";
// Generate a key pair for the demo.
const [signer, verifier] = await generateSigningKey("/identity");
The produce()
standalone function creates a producer.
It accepts three parameters:
using producer = produce("/P", async (interest) => {
console.log(`Producer is handling Interest ${interest.name}`);
return new Data(interest.name, toUtf8("served by NDNts"));
}, {
concurrency: 16, // allow concurrent calls to the handler function
dataSigner: signer, // enable automatic signing
});
The return value of produce()
function is an object that implements Producer interface.
This interface contains accessors and methods for observing and controlling the producer.
The object implements Disposable interface.
With using
keyword (TypeScript only), the producer is closed when the variable goes out of scope.
Alternatively, you can invoke producer[Symbol.dispose]()
explicitly.
The consume()
standalone function creates a consumer to receive a single Data packet.
It accepts two parameters:
const consumer1 = consume("/P/1", {
retx: 2, // enable retransmission
verifier, // enable automatic verification
});
try {
const data1 = await consumer1;
console.log(`Consumer receives Data ${data1.name} with content "${
fromUtf8(data1.content)}" after ${consumer1.nRetx} retransmissions`);
} catch (err: unknown) {
console.log("Consumer error", err);
}
The return value of consume()
function is an object that implements ConsumerContext interface.
This interface contains accessors and methods for observing and controlling the consumer.
Most importantly, the return value is a Promise that resolves to the retrieved Data or rejects upon error (including timeout).
Thus, you can simply await consume(..)
to obtain the Data.
try {
const data2 = await consume("/P/2", { retx: 2, verifier });
console.log(`Consumer receives Data ${data2.name}`);
} catch (err: unknown) {
console.log("Consumer error", err);
}
FAQs
NDNts: Client Endpoint
The npm package @ndn/endpoint receives a total of 3 weekly downloads. As such, @ndn/endpoint popularity was classified as not popular.
We found that @ndn/endpoint demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.