Options
All
  • Public
  • Public/Protected
  • All
Menu

@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, signInterest02 } from "@ndn/nfdmgmt";

// other imports for examples
import { Endpoint } from "@ndn/endpoint";
import { Forwarder, 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/tlv";
import { strict as assert } from "assert";
(async () => {

2014 Signed Interest

While @ndn/keychain package only supports 2019 Signed Interest format, NFD Management protocol is using 2014 Signed Interest format. signInterest02 function provides basic support for that format.

// Generate a signing key.
const [privateKey] = await generateSigningKey("/K");

// Prepare the Interest.
const interest = new Interest("/I");
await signInterest02(interest, { signer: privateKey });
assert.equal(interest.name.length, 5);
console.log(`${interest.name}`);

NFD Prefix Registration

// Create two forwarders, one as consumer and one as producer.
const fwC = Forwarder.create();
const fwP = Forwarder.create();

// Connect to NFD using Unix socket transport.
let uplinkC: FwFace;
try {
  uplinkC = await UnixTransport.createFace({ fw: fwC }, "/run/nfd.sock");
} catch {
  // Skip the example if NFD is not running.
  console.warn("NFD not running");
  return;
}
uplinkC.addRoute(new Name("/"));
const uplinkP = await UnixTransport.createFace({ fw: fwP }, "/run/nfd.sock");

// Enable NFD prefix registration.
enableNfdPrefixReg(uplinkP, { signer: privateKey });

// Start a producer.
const producer = new Endpoint({ fw: fwP }).produce("/P",
  async () => {
    console.log("producing");
    return new Data("/P", Data.FreshnessPeriod(1000), toUtf8("NDNts + NFD"));
  });
await new Promise((r) => setTimeout(r, 500));

// Start a consumer, fetching Data from the producer via NFD.
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");

// Close faces.
uplinkC.close();
uplinkP.close();
producer.close();
})();

Index

References

ControlCommand

Re-exports ControlCommand

ControlParameters

Re-exports ControlParameters

ControlResponse

Re-exports ControlResponse

enableNfdPrefixReg

Re-exports enableNfdPrefixReg

signInterest02

Re-exports signInterest02

Type aliases

CP

CP<R, O>: Required<Pick<Fields, R>> & Pick<Fields, O>

Pick fields from ControlParameters.Fields. R are required. O are optional.

Type parameters

CommandOptions

CommandOptions: Omit<Options, "endpoint">

Fields_

Fields_: Fields

Options

Options: CommandOptions & RouteOptions & { refreshInterval?: number | false; retry?: RetryOptions }

RouteOptions

RouteOptions: Pick<Fields, "origin" | "cost" | "flags">

Variables

Const EVD

EVD: EvDecoder<ControlResponse> = new EvDecoder<ControlResponse>("ControlResponse", 0x65).add(0x66, (t, { nni }) => t.statusCode = nni).add(0x67, (t, { text }) => t.statusText = text).setIsCritical(() => false)

Const fieldDefs

fieldDefs: [number, "name" | "mtu" | "faceId" | "uri" | "localUri" | "origin" | "cost" | "capacity" | "count" | "baseCongestionMarkingInterval" | "defaultCongestionPeriod" | "flags" | "mask" | "strategy" | "expirationPeriod" | "facePersistency", any][] = [[TT.Name, "name", undefined],[0x69, "faceId", NNI],[0x72, "uri", String],[0x81, "localUri", String],[0x6F, "origin", NNI],[0x6A, "cost", NNI],[0x83, "capacity", NNI],[0x84, "count", NNI],[0x87, "baseCongestionMarkingInterval", NNI],[0x88, "defaultCongestionPeriod", NNI],[0x89, "mtu", NNI],[0x6C, "flags", NNI],[0x70, "mask", NNI],[0x6B, "strategy", Name],[0x6D, "expirationPeriod", NNI],[0x85, "facePersistency", NNI],] as Array<[number, keyof Fields, any]>

Functions

enableNfdPrefixReg

  • enableNfdPrefixReg(face: FwFace, opts?: Options): void

Legend

  • Namespace
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Type alias
  • Type alias with type parameter
  • Interface
  • Interface with type parameter
  • Class
  • Class with type parameter
  • Enumeration

Generated using TypeDoc