@ndn/nfdmgmt
This package is part of NDNts, Named Data Networking libraries for the modern web.
This package implements basic support for NFD Management protocol.
In particular, it enables prefix registration on NFD.
import { enableNfdPrefixReg } from "@ndn/nfdmgmt";
import { Endpoint } from "@ndn/endpoint";
import { Forwarder, type FwFace } from "@ndn/fw";
import { generateSigningKey } from "@ndn/keychain";
import { UnixTransport } from "@ndn/node-transport";
import { Data, Interest, Name } from "@ndn/packet";
import { fromUtf8, toUtf8 } from "@ndn/util";
import { strict as assert } from "node:assert";
import { setTimeout as delay } from "node:timers/promises";
NFD Prefix Registration
enableNfdPrefixReg
function enables NFD prefix registration.
The snippet here shows API usage.
If you are using @ndn/cli-common
package, this is called automatically if the uplink connects to NFD.
const fwC = Forwarder.create();
const fwP = Forwarder.create();
const unixSocket = process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock";
let uplinkC: FwFace;
try {
uplinkC = await UnixTransport.createFace({ fw: fwC }, unixSocket);
} catch {
console.warn("NFD not running");
process.exit(0);
}
const uplinkP = await UnixTransport.createFace({ fw: fwP, addRoutes: [] }, unixSocket);
const [privateKey] = await generateSigningKey("/K");
enableNfdPrefixReg(uplinkP, { signer: privateKey });
const producer = new Endpoint({ fw: fwP }).produce("/P",
async () => {
console.log("producing");
return new Data("/P", Data.FreshnessPeriod(1000), toUtf8("NDNts + NFD"));
});
await delay(500);
const data = await new Endpoint({ fw: fwC }).consume(new Interest("/P", Interest.MustBeFresh));
const payloadText = fromUtf8(data.content);
console.log("received", `${data.name} ${payloadText}`);
assert.equal(payloadText, "NDNts + NFD");
uplinkC.close();
uplinkP.close();
producer.close();
Signed Interest 0.2
Previously, NFD Management protocol uses the deprecated Signed Interest 0.2 format.
signInterest02
function provides basic support for this older format.
NFD is now accepting the Signed Interest format in NDN packet spec and this package has switched to it.
However, signInterest02
function is temporarily kept for interoperability with other programs that follows the structure of NFD Management protocol but still requires the old format.