New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ndn/nfdmgmt

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndn/nfdmgmt - npm Package Compare versions

Comparing version 0.0.20210930 to 0.0.20220501

LICENSE

17

lib/control-command_browser.js
import { Endpoint } from "@ndn/endpoint";
import { Component, Interest, Name, TT } from "@ndn/packet";
import { Component, digestSigning, Interest, Name, SignedInterestPolicy, TT } from "@ndn/packet";
import { Decoder, Encoder } from "@ndn/tlv";
import { ControlParameters } from "./control-parameters_browser.js";
import { ControlResponse } from "./control-response_browser.js";
import { signInterest02 } from "./sign-interest-02_browser.js";
const defaultSIP = new SignedInterestPolicy(SignedInterestPolicy.Nonce(), SignedInterestPolicy.Time());
/** NFD Management - Control Command client. */

@@ -17,11 +17,10 @@ export var ControlCommand;

/** Invoke a command and wait for response. */
async function call(command, params, opts = {}) {
const { endpoint = new Endpoint({ describe: `ControlCommand(${command})` }), commandPrefix: prefix = ControlCommand.localhostPrefix, } = opts;
const name = new Name([
async function call(command, params, { endpoint = new Endpoint(), commandPrefix: prefix = ControlCommand.localhostPrefix, signer = digestSigning, signedInterestPolicy = defaultSIP, } = {}) {
const interest = new Interest(new Name([
...prefix.comps,
...command.split("/"),
new Component(TT.GenericNameComponent, Encoder.encode(new ControlParameters(params), 512)),
]);
const interest = await signInterest02(new Interest(name), opts);
const data = await endpoint.consume(interest);
new Component(TT.GenericNameComponent, Encoder.encode(new ControlParameters(params))),
]));
await signedInterestPolicy.makeSigner(signer).sign(interest);
const data = await endpoint.consume(interest, { describe: `ControlCommand(${command})` });
return new Decoder(data.content).decode(ControlResponse);

@@ -28,0 +27,0 @@ }

import { Endpoint } from "@ndn/endpoint";
import { Component, Interest, Name, TT } from "@ndn/packet";
import { Component, digestSigning, Interest, Name, SignedInterestPolicy, TT } from "@ndn/packet";
import { Decoder, Encoder } from "@ndn/tlv";
import { ControlParameters } from "./control-parameters_node.js";
import { ControlResponse } from "./control-response_node.js";
import { signInterest02 } from "./sign-interest-02_node.js";
const defaultSIP = new SignedInterestPolicy(SignedInterestPolicy.Nonce(), SignedInterestPolicy.Time());
/** NFD Management - Control Command client. */

@@ -17,11 +17,10 @@ export var ControlCommand;

/** Invoke a command and wait for response. */
async function call(command, params, opts = {}) {
const { endpoint = new Endpoint({ describe: `ControlCommand(${command})` }), commandPrefix: prefix = ControlCommand.localhostPrefix, } = opts;
const name = new Name([
async function call(command, params, { endpoint = new Endpoint(), commandPrefix: prefix = ControlCommand.localhostPrefix, signer = digestSigning, signedInterestPolicy = defaultSIP, } = {}) {
const interest = new Interest(new Name([
...prefix.comps,
...command.split("/"),
new Component(TT.GenericNameComponent, Encoder.encode(new ControlParameters(params), 512)),
]);
const interest = await signInterest02(new Interest(name), opts);
const data = await endpoint.consume(interest);
new Component(TT.GenericNameComponent, Encoder.encode(new ControlParameters(params))),
]));
await signedInterestPolicy.makeSigner(signer).sign(interest);
const data = await endpoint.consume(interest, { describe: `ControlCommand(${command})` });
return new Decoder(data.content).decode(ControlResponse);

@@ -28,0 +27,0 @@ }

import { Endpoint } from "@ndn/endpoint";
import { Name } from "@ndn/packet";
import { type Signer, Name, SignedInterestPolicy } from "@ndn/packet";
import { ControlParameters } from "./control-parameters";
import { ControlResponse } from "./control-response";
import { signInterest02 } from "./sign-interest-02";
/**

@@ -24,5 +23,7 @@ * Pick fields from ControlParameters.Fields.

export declare namespace ControlCommand {
interface Options extends signInterest02.Options {
interface Options {
endpoint?: Endpoint;
commandPrefix?: Name;
signer?: Signer;
signedInterestPolicy?: SignedInterestPolicy;
}

@@ -33,4 +34,4 @@ const localhostPrefix: Name;

/** Invoke a command and wait for response. */
function call<C extends keyof Commands>(command: C, params: Commands[C], opts?: Options): Promise<ControlResponse>;
function call<C extends keyof Commands>(command: C, params: Commands[C], { endpoint, commandPrefix: prefix, signer, signedInterestPolicy, }?: Options): Promise<ControlResponse>;
}
export {};
import { Name, TT } from "@ndn/packet";
import { NNI, toUtf8 } from "@ndn/tlv";
import { EvDecoder, NNI } from "@ndn/tlv";
import { toUtf8 } from "@ndn/util";
const TtControlParameters = 0x68;
function decodeNNI({ nni }) {
return nni;
}
function decodeString({ text }) {
return text;
}
const fieldDefs = [
[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],
[TT.Name, "name", (name) => name.value, ({ decoder }) => decoder.decode(Name)],
[0x69, "faceId", NNI, decodeNNI],
[0x72, "uri", toUtf8, decodeString],
[0x81, "localUri", toUtf8, decodeString],
[0x6F, "origin", NNI, decodeNNI],
[0x6A, "cost", NNI, decodeNNI],
[0x83, "capacity", NNI, decodeNNI],
[0x84, "count", NNI, decodeNNI],
[0x87, "baseCongestionMarkingInterval", NNI, decodeNNI],
[0x88, "defaultCongestionPeriod", NNI, decodeNNI],
[0x89, "mtu", NNI, decodeNNI],
[0x6C, "flags", NNI, decodeNNI],
[0x70, "mask", NNI, decodeNNI],
[0x6B, "strategy", (name) => name, ({ vd }) => vd.decode(Name)],
[0x6D, "expirationPeriod", NNI, decodeNNI],
[0x85, "facePersistency", NNI, decodeNNI],
];
/** NFD Management ControlParameters struct (encoding only). */
const EVD = new EvDecoder("ControlParameters", TtControlParameters)
.setIsCritical(() => false);
for (const [tt, key, , decode] of fieldDefs) {
EVD.add(tt, (t, tlv) => {
t[key] = decode(tlv);
});
}
/** NFD Management ControlParameters struct. */
export class ControlParameters {
static decodeFrom(decoder) {
return EVD.decode(new ControlParameters(), decoder);
}
constructor(value = {}) {

@@ -27,18 +45,10 @@ Object.assign(this, value);

encodeTo(encoder) {
encoder.prependTlv(0x68, ...fieldDefs.map(([tt, key, type]) => {
const value = this[key];
switch (true) {
case value === undefined:
return undefined;
case type === NNI:
return [tt, NNI(value)];
case type === String:
return [tt, toUtf8(value)];
case type === Name:
return [tt, value];
default:
return value;
encoder.prependTlv(TtControlParameters, ...fieldDefs.map(([tt, key, encodeValue]) => {
const v = this[key];
if (v === undefined) {
return undefined;
}
return [tt, encodeValue(v)];
}));
}
}
import { Name, TT } from "@ndn/packet";
import { NNI, toUtf8 } from "@ndn/tlv";
import { EvDecoder, NNI } from "@ndn/tlv";
import { toUtf8 } from "@ndn/util";
const TtControlParameters = 0x68;
function decodeNNI({ nni }) {
return nni;
}
function decodeString({ text }) {
return text;
}
const fieldDefs = [
[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],
[TT.Name, "name", (name) => name.value, ({ decoder }) => decoder.decode(Name)],
[0x69, "faceId", NNI, decodeNNI],
[0x72, "uri", toUtf8, decodeString],
[0x81, "localUri", toUtf8, decodeString],
[0x6F, "origin", NNI, decodeNNI],
[0x6A, "cost", NNI, decodeNNI],
[0x83, "capacity", NNI, decodeNNI],
[0x84, "count", NNI, decodeNNI],
[0x87, "baseCongestionMarkingInterval", NNI, decodeNNI],
[0x88, "defaultCongestionPeriod", NNI, decodeNNI],
[0x89, "mtu", NNI, decodeNNI],
[0x6C, "flags", NNI, decodeNNI],
[0x70, "mask", NNI, decodeNNI],
[0x6B, "strategy", (name) => name, ({ vd }) => vd.decode(Name)],
[0x6D, "expirationPeriod", NNI, decodeNNI],
[0x85, "facePersistency", NNI, decodeNNI],
];
/** NFD Management ControlParameters struct (encoding only). */
const EVD = new EvDecoder("ControlParameters", TtControlParameters)
.setIsCritical(() => false);
for (const [tt, key, , decode] of fieldDefs) {
EVD.add(tt, (t, tlv) => {
t[key] = decode(tlv);
});
}
/** NFD Management ControlParameters struct. */
export class ControlParameters {
static decodeFrom(decoder) {
return EVD.decode(new ControlParameters(), decoder);
}
constructor(value = {}) {

@@ -27,18 +45,10 @@ Object.assign(this, value);

encodeTo(encoder) {
encoder.prependTlv(0x68, ...fieldDefs.map(([tt, key, type]) => {
const value = this[key];
switch (true) {
case value === undefined:
return undefined;
case type === NNI:
return [tt, NNI(value)];
case type === String:
return [tt, toUtf8(value)];
case type === Name:
return [tt, value];
default:
return value;
encoder.prependTlv(TtControlParameters, ...fieldDefs.map(([tt, key, encodeValue]) => {
const v = this[key];
if (v === undefined) {
return undefined;
}
return [tt, encodeValue(v)];
}));
}
}
import { Name } from "@ndn/packet";
import { Encoder } from "@ndn/tlv";
/** NFD Management ControlParameters struct (encoding only). */
import { type Decoder, Encoder } from "@ndn/tlv";
/** NFD Management ControlParameters struct. */
export declare class ControlParameters {
static decodeFrom(decoder: Decoder): ControlParameters;
constructor(value?: ControlParameters.Fields);

@@ -6,0 +7,0 @@ encodeTo(encoder: Encoder): void;

@@ -1,11 +0,21 @@

import { EvDecoder } from "@ndn/tlv";
const EVD = new EvDecoder("ControlResponse", 0x65)
.add(0x66, (t, { nni }) => t.statusCode = nni)
.add(0x67, (t, { text }) => t.statusText = text)
import { EvDecoder, NNI } from "@ndn/tlv";
import { toUtf8 } from "@ndn/util";
const TT = {
ControlResponse: 0x65,
StatusCode: 0x66,
StatusText: 0x67,
};
const EVD = new EvDecoder("ControlResponse", TT.ControlResponse)
.add(TT.StatusCode, (t, { nni }) => t.statusCode = nni)
.add(TT.StatusText, (t, { text, after }) => {
t.statusText = text;
t.body = after;
})
.setIsCritical(() => false);
/** NFD Management ControlResponse struct (decoding only). */
/** NFD Management ControlResponse struct. */
export class ControlResponse {
constructor() {
this.statusCode = 0;
this.statusText = "";
constructor(statusCode = 0, statusText = "", body) {
this.statusCode = statusCode;
this.statusText = statusText;
this.body = body;
}

@@ -15,2 +25,5 @@ static decodeFrom(decoder) {

}
encodeTo(encoder) {
encoder.prependTlv(TT.ControlResponse, [TT.StatusCode, NNI(this.statusCode)], [TT.StatusText, toUtf8(this.statusText)], this.body);
}
}

@@ -1,11 +0,21 @@

import { EvDecoder } from "@ndn/tlv";
const EVD = new EvDecoder("ControlResponse", 0x65)
.add(0x66, (t, { nni }) => t.statusCode = nni)
.add(0x67, (t, { text }) => t.statusText = text)
import { EvDecoder, NNI } from "@ndn/tlv";
import { toUtf8 } from "@ndn/util";
const TT = {
ControlResponse: 0x65,
StatusCode: 0x66,
StatusText: 0x67,
};
const EVD = new EvDecoder("ControlResponse", TT.ControlResponse)
.add(TT.StatusCode, (t, { nni }) => t.statusCode = nni)
.add(TT.StatusText, (t, { text, after }) => {
t.statusText = text;
t.body = after;
})
.setIsCritical(() => false);
/** NFD Management ControlResponse struct (decoding only). */
/** NFD Management ControlResponse struct. */
export class ControlResponse {
constructor() {
this.statusCode = 0;
this.statusText = "";
constructor(statusCode = 0, statusText = "", body) {
this.statusCode = statusCode;
this.statusText = statusText;
this.body = body;
}

@@ -15,2 +25,5 @@ static decodeFrom(decoder) {

}
encodeTo(encoder) {
encoder.prependTlv(TT.ControlResponse, [TT.StatusCode, NNI(this.statusCode)], [TT.StatusText, toUtf8(this.statusText)], this.body);
}
}

@@ -1,7 +0,10 @@

import { Decoder } from "@ndn/tlv";
/** NFD Management ControlResponse struct (decoding only). */
import { type Decoder, type Encodable, type Encoder } from "@ndn/tlv";
/** NFD Management ControlResponse struct. */
export declare class ControlResponse {
static decodeFrom(decoder: Decoder): ControlResponse;
statusCode: number;
statusText: string;
body?: Encodable;
static decodeFrom(decoder: Decoder): ControlResponse;
constructor(statusCode?: number, statusText?: string, body?: Encodable);
encodeTo(encoder: Encoder): void;
}

@@ -0,6 +1,8 @@

import { __importDefault, __importStar } from "tslib";
import { Endpoint } from "@ndn/endpoint";
import { ReadvertiseDestination, TapFace } from "@ndn/fw";
import { Certificate } from "@ndn/keychain";
import { Interest, Name } from "@ndn/packet";
import { toHex } from "@ndn/tlv";
import { Interest, NameMap } from "@ndn/packet";
import { Closers } from "@ndn/util";
import _cjsDefaultImport0 from "obliterator/map.js"; const map = __importDefault(_cjsDefaultImport0).default;
import { ControlCommand } from "./control-command_browser.js";

@@ -11,7 +13,7 @@ class NfdPrefixReg extends ReadvertiseDestination {

this.face = face;
this.preloadCerts = new Map();
this.preloadCerts = new NameMap();
this.handleFaceUp = () => {
for (const [nameHex, { status, state }] of this.table) {
for (const [name, { status, state }] of this.table) {
if (status === ReadvertiseDestination.Status.ADVERTISED) {
this.scheduleRefresh(nameHex, state, 100);
this.scheduleRefresh(name, state, 100);
}

@@ -43,3 +45,3 @@ }

const tapFace = TapFace.create(this.face);
tapFace.addRoute(new Name("/"));
tapFace.addRoute("/");
const endpoint = new Endpoint({

@@ -51,24 +53,17 @@ announcement: false,

const preloadProducers = await this.preload(endpoint);
const closers = new Closers();
closers.push(...map(preloadProducers, ([, p]) => p), tapFace);
return [
{ ...this.commandOptions, endpoint },
() => {
for (const p of preloadProducers.values()) {
p.close();
}
tapFace.close();
},
closers.close,
];
}
async preload(endpoint) {
const producers = new Map();
const producers = new NameMap();
let name = this.preloadCertName;
while (name) {
const key = toHex(name.value);
if (producers.has(key)) {
break;
}
while (name && !producers.has(name)) {
try {
const cert = await this.retrievePreload(endpoint, key, name);
this.preloadCerts.set(key, cert);
producers.set(key, endpoint.produce(name, () => Promise.resolve(cert.data)));
const cert = await this.retrievePreload(endpoint, name);
this.preloadCerts.set(name, cert);
producers.set(name, endpoint.produce(name, async () => cert.data));
name = cert.issuer;

@@ -82,4 +77,4 @@ }

}
async retrievePreload(endpoint, key, name) {
const cert = this.preloadCerts.get(key);
async retrievePreload(endpoint, name) {
const cert = this.preloadCerts.get(name);
if (cert) {

@@ -98,3 +93,3 @@ return cert;

}
async doAdvertise(name, state, nameHex) {
async doAdvertise(name, state) {
const [opts, untap] = await this.tap();

@@ -116,12 +111,12 @@ try {

if (this.refreshInterval !== false) {
this.scheduleRefresh(nameHex, state, this.refreshInterval);
this.scheduleRefresh(name, state, this.refreshInterval);
}
}
scheduleRefresh(nameHex, state, after) {
scheduleRefresh(name, state, after) {
clearTimeout(state.refreshTimer);
state.refreshTimer = setTimeout(() => {
const record = this.table.get(nameHex);
const record = this.table.get(name);
if (record?.status === ReadvertiseDestination.Status.ADVERTISED) {
record.status = ReadvertiseDestination.Status.ADVERTISING;
this.restart(nameHex, record);
this.restart(name, record);
}

@@ -128,0 +123,0 @@ }, after);

@@ -0,6 +1,8 @@

import { __importDefault, __importStar } from "tslib";
import { Endpoint } from "@ndn/endpoint";
import { ReadvertiseDestination, TapFace } from "@ndn/fw";
import { Certificate } from "@ndn/keychain";
import { Interest, Name } from "@ndn/packet";
import { toHex } from "@ndn/tlv";
import { Interest, NameMap } from "@ndn/packet";
import { Closers } from "@ndn/util";
import _cjsDefaultImport0 from "obliterator/map.js"; const map = __importDefault(_cjsDefaultImport0).default;
import { ControlCommand } from "./control-command_node.js";

@@ -11,7 +13,7 @@ class NfdPrefixReg extends ReadvertiseDestination {

this.face = face;
this.preloadCerts = new Map();
this.preloadCerts = new NameMap();
this.handleFaceUp = () => {
for (const [nameHex, { status, state }] of this.table) {
for (const [name, { status, state }] of this.table) {
if (status === ReadvertiseDestination.Status.ADVERTISED) {
this.scheduleRefresh(nameHex, state, 100);
this.scheduleRefresh(name, state, 100);
}

@@ -43,3 +45,3 @@ }

const tapFace = TapFace.create(this.face);
tapFace.addRoute(new Name("/"));
tapFace.addRoute("/");
const endpoint = new Endpoint({

@@ -51,24 +53,17 @@ announcement: false,

const preloadProducers = await this.preload(endpoint);
const closers = new Closers();
closers.push(...map(preloadProducers, ([, p]) => p), tapFace);
return [
{ ...this.commandOptions, endpoint },
() => {
for (const p of preloadProducers.values()) {
p.close();
}
tapFace.close();
},
closers.close,
];
}
async preload(endpoint) {
const producers = new Map();
const producers = new NameMap();
let name = this.preloadCertName;
while (name) {
const key = toHex(name.value);
if (producers.has(key)) {
break;
}
while (name && !producers.has(name)) {
try {
const cert = await this.retrievePreload(endpoint, key, name);
this.preloadCerts.set(key, cert);
producers.set(key, endpoint.produce(name, () => Promise.resolve(cert.data)));
const cert = await this.retrievePreload(endpoint, name);
this.preloadCerts.set(name, cert);
producers.set(name, endpoint.produce(name, async () => cert.data));
name = cert.issuer;

@@ -82,4 +77,4 @@ }

}
async retrievePreload(endpoint, key, name) {
const cert = this.preloadCerts.get(key);
async retrievePreload(endpoint, name) {
const cert = this.preloadCerts.get(name);
if (cert) {

@@ -98,3 +93,3 @@ return cert;

}
async doAdvertise(name, state, nameHex) {
async doAdvertise(name, state) {
const [opts, untap] = await this.tap();

@@ -116,12 +111,12 @@ try {

if (this.refreshInterval !== false) {
this.scheduleRefresh(nameHex, state, this.refreshInterval);
this.scheduleRefresh(name, state, this.refreshInterval);
}
}
scheduleRefresh(nameHex, state, after) {
scheduleRefresh(name, state, after) {
clearTimeout(state.refreshTimer);
state.refreshTimer = setTimeout(() => {
const record = this.table.get(nameHex);
const record = this.table.get(name);
if (record?.status === ReadvertiseDestination.Status.ADVERTISED) {
record.status = ReadvertiseDestination.Status.ADVERTISING;
this.restart(nameHex, record);
this.restart(name, record);
}

@@ -128,0 +123,0 @@ }, after);

import { FwFace, ReadvertiseDestination } from "@ndn/fw";
import { KeyChain } from "@ndn/keychain";
import { Name } from "@ndn/packet";
import { type KeyChain } from "@ndn/keychain";
import { type Name } from "@ndn/packet";
import { ControlCommand } from "./control-command";

@@ -5,0 +5,0 @@ import type { ControlParameters } from "./control-parameters";

@@ -10,3 +10,3 @@ import { digestSigning, LLSign, Name, TT } from "@ndn/packet";

async [LLSign.OP](sign) {
const nonce = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
const nonce = Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER);
const signedPortion = Encoder.encode([

@@ -26,6 +26,6 @@ ...this.name.comps,

/**
* Sign an Interest in 2014 Signed Interest format.
* Sign an Interest in Signed Interest 0.2 format.
* @param interest input Interest without signed Interest specific components.
* @param signer private key to sign the Interest.
* @see https://named-data.net/doc/ndn-cxx/0.6.6/specs/signed-interest.html
* @see https://named-data.net/doc/ndn-cxx/0.8.0/specs/signed-interest.html
*/

@@ -32,0 +32,0 @@ export async function signInterest02(interest, { signer = digestSigning, timestamp = Date.now() } = {}) {

@@ -10,3 +10,3 @@ import { digestSigning, LLSign, Name, TT } from "@ndn/packet";

async [LLSign.OP](sign) {
const nonce = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
const nonce = Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER);
const signedPortion = Encoder.encode([

@@ -26,6 +26,6 @@ ...this.name.comps,

/**
* Sign an Interest in 2014 Signed Interest format.
* Sign an Interest in Signed Interest 0.2 format.
* @param interest input Interest without signed Interest specific components.
* @param signer private key to sign the Interest.
* @see https://named-data.net/doc/ndn-cxx/0.6.6/specs/signed-interest.html
* @see https://named-data.net/doc/ndn-cxx/0.8.0/specs/signed-interest.html
*/

@@ -32,0 +32,0 @@ export async function signInterest02(interest, { signer = digestSigning, timestamp = Date.now() } = {}) {

@@ -1,7 +0,7 @@

import { Interest, Signer } from "@ndn/packet";
import { type Signer, Interest } from "@ndn/packet";
/**
* Sign an Interest in 2014 Signed Interest format.
* Sign an Interest in Signed Interest 0.2 format.
* @param interest input Interest without signed Interest specific components.
* @param signer private key to sign the Interest.
* @see https://named-data.net/doc/ndn-cxx/0.6.6/specs/signed-interest.html
* @see https://named-data.net/doc/ndn-cxx/0.8.0/specs/signed-interest.html
*/

@@ -8,0 +8,0 @@ export declare function signInterest02(interest: Interest, { signer, timestamp }?: signInterest02.Options): Promise<Interest>;

{
"name": "@ndn/nfdmgmt",
"version": "0.0.20210930",
"version": "0.0.20220501",
"description": "NDNts: NFD Management",

@@ -25,10 +25,13 @@ "keywords": [

"dependencies": {
"@ndn/endpoint": "0.0.20210930",
"@ndn/fw": "0.0.20210930",
"@ndn/keychain": "0.0.20210930",
"@ndn/packet": "0.0.20210930",
"@ndn/tlv": "0.0.20210930",
"tslib": "^2.3.1"
"@ndn/endpoint": "0.0.20220501",
"@ndn/fw": "0.0.20220501",
"@ndn/keychain": "0.0.20220501",
"@ndn/packet": "0.0.20220501",
"@ndn/tlv": "0.0.20220501",
"@ndn/util": "0.0.20220501",
"obliterator": "^2.0.3",
"tslib": "^2.4.0"
},
"types": "lib/mod.d.ts"
"types": "lib/mod.d.ts",
"readme": "# @ndn/nfdmgmt\n\nThis package is part of [NDNts](https://yoursunny.com/p/NDNts/), Named Data Networking libraries for the modern web.\n\nThis package implements basic support for [NFD Management protocol](https://redmine.named-data.net/projects/nfd/wiki/Management).\nIn particular, it enables prefix registration on NFD.\n\n```ts\nimport { enableNfdPrefixReg } from \"@ndn/nfdmgmt\";\n\n// other imports for examples\nimport { Endpoint } from \"@ndn/endpoint\";\nimport { Forwarder, type FwFace } from \"@ndn/fw\";\nimport { generateSigningKey } from \"@ndn/keychain\";\nimport { UnixTransport } from \"@ndn/node-transport\";\nimport { Data, Interest, Name } from \"@ndn/packet\";\nimport { fromUtf8, toUtf8 } from \"@ndn/util\";\nimport { strict as assert } from \"node:assert\";\nimport { setTimeout as delay } from \"node:timers/promises\";\n```\n\n## NFD Prefix Registration\n\n`enableNfdPrefixReg` function enables NFD prefix registration.\nThe snippet here shows API usage.\nIf you are using `@ndn/cli-common` package, this is called automatically if the uplink connects to NFD.\n\n```ts\n// Create two forwarders, one as consumer and one as producer.\nconst fwC = Forwarder.create();\nconst fwP = Forwarder.create();\n\n// Connect to NFD using Unix socket transport.\nconst unixSocket = process.env.DEMO_NFD_UNIX ?? \"/run/nfd.sock\";\nlet uplinkC: FwFace;\ntry {\n uplinkC = await UnixTransport.createFace({ fw: fwC }, unixSocket);\n} catch {\n // Skip the example if NFD is not running.\n console.warn(\"NFD not running\");\n process.exit(0);\n}\nconst uplinkP = await UnixTransport.createFace({ fw: fwP, addRoutes: [] }, unixSocket);\n\n// Generate a signing key and enable NFD prefix registration.\nconst [privateKey] = await generateSigningKey(\"/K\");\nenableNfdPrefixReg(uplinkP, { signer: privateKey });\n\n// Start a producer.\nconst producer = new Endpoint({ fw: fwP }).produce(\"/P\",\n async () => {\n console.log(\"producing\");\n return new Data(\"/P\", Data.FreshnessPeriod(1000), toUtf8(\"NDNts + NFD\"));\n });\nawait delay(500);\n\n// Start a consumer, fetch Data from the producer via NFD.\nconst data = await new Endpoint({ fw: fwC }).consume(new Interest(\"/P\", Interest.MustBeFresh));\nconst payloadText = fromUtf8(data.content);\nconsole.log(\"received\", `${data.name} ${payloadText}`);\nassert.equal(payloadText, \"NDNts + NFD\");\n\n// Close faces.\nuplinkC.close();\nuplinkP.close();\nproducer.close();\n```\n\n## Signed Interest 0.2\n\nPreviously, NFD Management protocol uses the deprecated [Signed Interest 0.2 format](https://named-data.net/doc/ndn-cxx/0.8.0/specs/signed-interest.html).\n`signInterest02` function provides basic support for this older format.\n\nNFD is now accepting the [Signed Interest format in NDN packet spec](https://named-data.net/doc/NDN-packet-spec/0.3/signed-interest.html) and this package has switched to it.\nHowever, `signInterest02` function is temporarily kept for interoperability with other programs that follows the structure of NFD Management protocol but still requires the old format.\n"
}

@@ -9,35 +9,22 @@ # @ndn/nfdmgmt

```ts
import { enableNfdPrefixReg, signInterest02 } from "@ndn/nfdmgmt";
import { enableNfdPrefixReg } from "@ndn/nfdmgmt";
// other imports for examples
import { Endpoint } from "@ndn/endpoint";
import { Forwarder, FwFace } from "@ndn/fw";
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/tlv";
import { fromUtf8, toUtf8 } from "@ndn/util";
import { strict as assert } from "node:assert";
(async () => {
import { setTimeout as delay } from "node:timers/promises";
```
## 2014 Signed Interest
## NFD Prefix Registration
While `@ndn/keychain` package only supports 2019 Signed Interest format, NFD Management protocol is using [2014 Signed Interest format](https://named-data.net/doc/ndn-cxx/0.6.6/specs/signed-interest.html).
`signInterest02` function provides basic support for that format.
`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.
```ts
// 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
```ts
// Create two forwarders, one as consumer and one as producer.

@@ -48,14 +35,15 @@ const fwC = Forwarder.create();

// Connect to NFD using Unix socket transport.
const unixSocket = process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock";
let uplinkC: FwFace;
try {
uplinkC = await UnixTransport.createFace({ fw: fwC }, "/run/nfd.sock");
uplinkC = await UnixTransport.createFace({ fw: fwC }, unixSocket);
} catch {
// Skip the example if NFD is not running.
console.warn("NFD not running");
return;
process.exit(0);
}
uplinkC.addRoute(new Name("/"));
const uplinkP = await UnixTransport.createFace({ fw: fwP }, "/run/nfd.sock");
const uplinkP = await UnixTransport.createFace({ fw: fwP, addRoutes: [] }, unixSocket);
// Enable NFD prefix registration.
// Generate a signing key and enable NFD prefix registration.
const [privateKey] = await generateSigningKey("/K");
enableNfdPrefixReg(uplinkP, { signer: privateKey });

@@ -69,8 +57,6 @@

});
await new Promise((r) => setTimeout(r, 500));
await delay(500);
// Start a consumer, fetching Data from the producer via NFD.
const data = await new Endpoint({ fw: fwC }).consume(
new Interest("/P", Interest.MustBeFresh),
);
// Start a consumer, fetch Data from the producer via NFD.
const data = await new Endpoint({ fw: fwC }).consume(new Interest("/P", Interest.MustBeFresh));
const payloadText = fromUtf8(data.content);

@@ -86,4 +72,8 @@ console.log("received", `${data.name} ${payloadText}`);

```ts
})();
```
## Signed Interest 0.2
Previously, NFD Management protocol uses the deprecated [Signed Interest 0.2 format](https://named-data.net/doc/ndn-cxx/0.8.0/specs/signed-interest.html).
`signInterest02` function provides basic support for this older format.
NFD is now accepting the [Signed Interest format in NDN packet spec](https://named-data.net/doc/NDN-packet-spec/0.3/signed-interest.html) 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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc