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.20230121 to 0.0.20240113

lib/an-nfd_browser.js

38

lib/control-response_browser.js

@@ -1,15 +0,10 @@

import { EvDecoder, NNI } from "@ndn/tlv";
import { Encoder, 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 }) => {
const EVD = new EvDecoder("ControlResponse", 101 /* TT.ControlResponse */)
.add(102 /* TT.StatusCode */, (t, { nni }) => t.statusCode = nni)
.add(103 /* TT.StatusText */, (t, { text, after }) => {
t.statusText = text;
t.body = after;
})
.setIsCritical(() => false);
.setIsCritical(EvDecoder.neverCritical);
/** NFD Management ControlResponse struct. */

@@ -19,14 +14,31 @@ export class ControlResponse {

statusText;
body;
static decodeFrom(decoder) {
return EVD.decode(new ControlResponse(), decoder);
}
/**
* Constructor.
* @param statusCode command status code.
* @param statusText command status text.
* @param body additional elements in the response.
*/
constructor(statusCode = 0, statusText = "", body) {
this.statusCode = statusCode;
this.statusText = statusText;
this.body = body;
this.body_ = body;
}
body_;
/**
* Additional elements in the response.
* For most NFD control commands, this is ControlParameters, and can be decoded like:
* ControlParameters.decodeFromResponseBody(response);
*/
get body() {
return ArrayBuffer.isView(this.body_) ? this.body_ : Encoder.encode(this.body_);
}
set body(value) {
this.body_ = value;
}
encodeTo(encoder) {
encoder.prependTlv(TT.ControlResponse, [TT.StatusCode, NNI(this.statusCode)], [TT.StatusText, toUtf8(this.statusText)], this.body);
encoder.prependTlv(101 /* TT.ControlResponse */, [102 /* TT.StatusCode */, NNI(this.statusCode)], [103 /* TT.StatusText */, toUtf8(this.statusText)], this.body_);
}
}

@@ -1,15 +0,10 @@

import { EvDecoder, NNI } from "@ndn/tlv";
import { Encoder, 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 }) => {
const EVD = new EvDecoder("ControlResponse", 101 /* TT.ControlResponse */)
.add(102 /* TT.StatusCode */, (t, { nni }) => t.statusCode = nni)
.add(103 /* TT.StatusText */, (t, { text, after }) => {
t.statusText = text;
t.body = after;
})
.setIsCritical(() => false);
.setIsCritical(EvDecoder.neverCritical);
/** NFD Management ControlResponse struct. */

@@ -19,14 +14,31 @@ export class ControlResponse {

statusText;
body;
static decodeFrom(decoder) {
return EVD.decode(new ControlResponse(), decoder);
}
/**
* Constructor.
* @param statusCode command status code.
* @param statusText command status text.
* @param body additional elements in the response.
*/
constructor(statusCode = 0, statusText = "", body) {
this.statusCode = statusCode;
this.statusText = statusText;
this.body = body;
this.body_ = body;
}
body_;
/**
* Additional elements in the response.
* For most NFD control commands, this is ControlParameters, and can be decoded like:
* ControlParameters.decodeFromResponseBody(response);
*/
get body() {
return ArrayBuffer.isView(this.body_) ? this.body_ : Encoder.encode(this.body_);
}
set body(value) {
this.body_ = value;
}
encodeTo(encoder) {
encoder.prependTlv(TT.ControlResponse, [TT.StatusCode, NNI(this.statusCode)], [TT.StatusText, toUtf8(this.statusText)], this.body);
encoder.prependTlv(101 /* TT.ControlResponse */, [102 /* TT.StatusCode */, NNI(this.statusCode)], [103 /* TT.StatusText */, toUtf8(this.statusText)], this.body_);
}
}

@@ -1,2 +0,2 @@

import { type Decoder, type Encodable, type Encoder } from "@ndn/tlv";
import { type Decoder, type Encodable, Encoder } from "@ndn/tlv";
/** NFD Management ControlResponse struct. */

@@ -6,6 +6,19 @@ export declare class ControlResponse {

statusText: string;
body?: Encodable;
static decodeFrom(decoder: Decoder): ControlResponse;
/**
* Constructor.
* @param statusCode command status code.
* @param statusText command status text.
* @param body additional elements in the response.
*/
constructor(statusCode?: number, statusText?: string, body?: Encodable);
private body_;
/**
* Additional elements in the response.
* For most NFD control commands, this is ControlParameters, and can be decoded like:
* ControlParameters.decodeFromResponseBody(response);
*/
get body(): Uint8Array;
set body(value: Encodable);
encodeTo(encoder: Encoder): void;
}

@@ -1,5 +0,9 @@

export * from "./control-command_browser.js";
export * from "./control-parameters_browser.js";
export * from "./an-nfd_browser.js";
export * from "./control-command-generic_browser.js";
export * from "./control-command-nfd_browser.js";
export * from "./control-response_browser.js";
export { localhopPrefix, localhostPrefix, getPrefix } from "./common_browser.js";
export * from "./prefix-reg_browser.js";
export * from "./sign-interest-02_browser.js";
export * from "./status-dataset-generic_browser.js";
export * from "./status-dataset-nfd_browser.js";

@@ -1,5 +0,9 @@

export * from "./control-command_node.js";
export * from "./control-parameters_node.js";
export * from "./an-nfd_node.js";
export * from "./control-command-generic_node.js";
export * from "./control-command-nfd_node.js";
export * from "./control-response_node.js";
export { localhopPrefix, localhostPrefix, getPrefix } from "./common_node.js";
export * from "./prefix-reg_node.js";
export * from "./sign-interest-02_node.js";
export * from "./status-dataset-generic_node.js";
export * from "./status-dataset-nfd_node.js";

@@ -1,5 +0,9 @@

export * from "./control-command.js";
export * from "./control-parameters.js";
export * from "./an-nfd.js";
export * from "./control-command-generic.js";
export * from "./control-command-nfd.js";
export * from "./control-response.js";
export { localhopPrefix, localhostPrefix, getPrefix } from "./common.js";
export * from "./prefix-reg.js";
export * from "./sign-interest-02.js";
export * from "./status-dataset-generic.js";
export * from "./status-dataset-nfd.js";

@@ -6,9 +6,12 @@ import { __importDefault, __importStar } from "tslib";

import { Interest, NameMap } from "@ndn/packet";
import { Closers } from "@ndn/util";
import { NNI } from "@ndn/tlv";
import { Closers, randomJitter } from "@ndn/util";
import _cjsDefaultImport0 from "obliterator/map.js"; const map = __importDefault(_cjsDefaultImport0).default;
import { ControlCommand } from "./control-command_browser.js";
import { RouteFlags } from "./an-nfd_browser.js";
import { getPrefix } from "./common_browser.js";
import { invokeGeneric } from "./control-command-generic_browser.js";
class NfdPrefixReg extends ReadvertiseDestination {
face;
commandOptions;
routeOptions;
routeElements;
refreshInterval;

@@ -23,23 +26,28 @@ preloadCertName;

this.commandOptions = {
commandPrefix: ControlCommand.getPrefix(face.attributes.local),
prefix: getPrefix(face.attributes.local),
...opts,
};
this.routeOptions = {
origin: 65,
cost: 0,
flags: 0x02,
...opts,
};
this.refreshInterval = opts.refreshInterval ?? 300000;
const { origin = 65, cost = 0, flagChildInherit = false, flagCapture = true, refreshInterval = 300000, } = opts;
this.routeElements = [
[111 /* TT.Origin */, NNI(origin)],
[106 /* TT.Cost */, NNI(cost)],
[108 /* TT.Flags */, NNI((Number(flagChildInherit) * RouteFlags.ChildInherit) |
(Number(flagCapture) * RouteFlags.Capture))],
undefined,
];
if (refreshInterval !== false) {
this.routeElements[3] = [109 /* TT.ExpirationPeriod */, NNI(Math.max(refreshInterval * 4, 60000))];
this.refreshInterval = randomJitter(0.1, refreshInterval);
}
this.preloadCertName = opts.preloadCertName;
this.preloadFromKeyChain = opts.preloadFromKeyChain;
this.preloadInterestLifetime = Interest.Lifetime(opts.preloadInterestLifetime ?? 500);
face.on("up", this.handleFaceUp);
face.once("close", () => this.disable());
face.addEventListener("up", this.handleFaceUp);
face.addEventListener("close", () => this.disable(), { once: true });
}
disable() {
this.face.off("up", this.handleFaceUp);
this.face.removeEventListener("up", this.handleFaceUp);
super.disable();
}
async tap() {
async tap(f) {
const tapFace = TapFace.create(this.face);

@@ -55,6 +63,8 @@ tapFace.addRoute("/");

closers.push(...map(preloadProducers, ([, p]) => p), tapFace);
return [
{ ...this.commandOptions, endpoint },
closers.close,
];
try {
return await f({ ...this.commandOptions, endpoint });
}
finally {
closers.close();
}
}

@@ -100,20 +110,7 @@ async preload(endpoint) {

async doAdvertise(name, state) {
const [opts, untap] = await this.tap();
try {
const cr = await ControlCommand.call("rib/register", {
name,
origin: this.routeOptions.origin,
cost: this.routeOptions.cost,
flags: this.routeOptions.flags,
}, opts);
if (cr.statusCode !== 200) {
throw new Error(`${cr.statusCode} ${cr.statusText}`);
}
if (this.refreshInterval !== undefined) {
this.scheduleRefresh(name, state, this.refreshInterval());
}
finally {
untap();
}
if (this.refreshInterval !== false) {
this.scheduleRefresh(name, state, this.refreshInterval);
}
const cr = await this.tap((opts) => invokeGeneric("rib/register", [104 /* TT.ControlParameters */, name, ...this.routeElements], opts));
this.checkSuccess(cr);
}

@@ -136,15 +133,9 @@ scheduleRefresh(name, state, after) {

}
const [opts, untap] = await this.tap();
try {
const cr = await ControlCommand.call("rib/unregister", {
name,
origin: this.routeOptions.origin,
}, opts);
if (cr.statusCode !== 200) {
throw new Error(`${cr.statusCode} ${cr.statusText}`);
}
const cr = await this.tap((opts) => invokeGeneric("rib/unregister", [104 /* TT.ControlParameters */, name, this.routeElements[0]], opts));
this.checkSuccess(cr);
}
checkSuccess(cr) {
if (cr.statusCode !== 200) {
throw new Error(`${cr.statusCode} ${cr.statusText}`);
}
finally {
untap();
}
}

@@ -151,0 +142,0 @@ }

@@ -6,9 +6,12 @@ import { __importDefault, __importStar } from "tslib";

import { Interest, NameMap } from "@ndn/packet";
import { Closers } from "@ndn/util";
import { NNI } from "@ndn/tlv";
import { Closers, randomJitter } from "@ndn/util";
import _cjsDefaultImport0 from "obliterator/map.js"; const map = __importDefault(_cjsDefaultImport0).default;
import { ControlCommand } from "./control-command_node.js";
import { RouteFlags } from "./an-nfd_node.js";
import { getPrefix } from "./common_node.js";
import { invokeGeneric } from "./control-command-generic_node.js";
class NfdPrefixReg extends ReadvertiseDestination {
face;
commandOptions;
routeOptions;
routeElements;
refreshInterval;

@@ -23,23 +26,28 @@ preloadCertName;

this.commandOptions = {
commandPrefix: ControlCommand.getPrefix(face.attributes.local),
prefix: getPrefix(face.attributes.local),
...opts,
};
this.routeOptions = {
origin: 65,
cost: 0,
flags: 0x02,
...opts,
};
this.refreshInterval = opts.refreshInterval ?? 300000;
const { origin = 65, cost = 0, flagChildInherit = false, flagCapture = true, refreshInterval = 300000, } = opts;
this.routeElements = [
[111 /* TT.Origin */, NNI(origin)],
[106 /* TT.Cost */, NNI(cost)],
[108 /* TT.Flags */, NNI((Number(flagChildInherit) * RouteFlags.ChildInherit) |
(Number(flagCapture) * RouteFlags.Capture))],
undefined,
];
if (refreshInterval !== false) {
this.routeElements[3] = [109 /* TT.ExpirationPeriod */, NNI(Math.max(refreshInterval * 4, 60000))];
this.refreshInterval = randomJitter(0.1, refreshInterval);
}
this.preloadCertName = opts.preloadCertName;
this.preloadFromKeyChain = opts.preloadFromKeyChain;
this.preloadInterestLifetime = Interest.Lifetime(opts.preloadInterestLifetime ?? 500);
face.on("up", this.handleFaceUp);
face.once("close", () => this.disable());
face.addEventListener("up", this.handleFaceUp);
face.addEventListener("close", () => this.disable(), { once: true });
}
disable() {
this.face.off("up", this.handleFaceUp);
this.face.removeEventListener("up", this.handleFaceUp);
super.disable();
}
async tap() {
async tap(f) {
const tapFace = TapFace.create(this.face);

@@ -55,6 +63,8 @@ tapFace.addRoute("/");

closers.push(...map(preloadProducers, ([, p]) => p), tapFace);
return [
{ ...this.commandOptions, endpoint },
closers.close,
];
try {
return await f({ ...this.commandOptions, endpoint });
}
finally {
closers.close();
}
}

@@ -100,20 +110,7 @@ async preload(endpoint) {

async doAdvertise(name, state) {
const [opts, untap] = await this.tap();
try {
const cr = await ControlCommand.call("rib/register", {
name,
origin: this.routeOptions.origin,
cost: this.routeOptions.cost,
flags: this.routeOptions.flags,
}, opts);
if (cr.statusCode !== 200) {
throw new Error(`${cr.statusCode} ${cr.statusText}`);
}
if (this.refreshInterval !== undefined) {
this.scheduleRefresh(name, state, this.refreshInterval());
}
finally {
untap();
}
if (this.refreshInterval !== false) {
this.scheduleRefresh(name, state, this.refreshInterval);
}
const cr = await this.tap((opts) => invokeGeneric("rib/register", [104 /* TT.ControlParameters */, name, ...this.routeElements], opts));
this.checkSuccess(cr);
}

@@ -136,15 +133,9 @@ scheduleRefresh(name, state, after) {

}
const [opts, untap] = await this.tap();
try {
const cr = await ControlCommand.call("rib/unregister", {
name,
origin: this.routeOptions.origin,
}, opts);
if (cr.statusCode !== 200) {
throw new Error(`${cr.statusCode} ${cr.statusText}`);
}
const cr = await this.tap((opts) => invokeGeneric("rib/unregister", [104 /* TT.ControlParameters */, name, this.routeElements[0]], opts));
this.checkSuccess(cr);
}
checkSuccess(cr) {
if (cr.statusCode !== 200) {
throw new Error(`${cr.statusCode} ${cr.statusText}`);
}
finally {
untap();
}
}

@@ -151,0 +142,0 @@ }

import { type FwFace, ReadvertiseDestination } from "@ndn/fw";
import { type KeyChain } from "@ndn/keychain";
import { type Name } from "@ndn/packet";
import { ControlCommand } from "./control-command.js";
import type { ControlParameters } from "./control-parameters.js";
type CommandOptions = Omit<ControlCommand.Options, "endpoint">;
type RouteOptions = Pick<ControlParameters.Fields, "origin" | "cost" | "flags">;
import type { Except } from "type-fest";
import { RouteFlags } from "./an-nfd.js";
import { type ControlCommandOptions } from "./control-command-generic.js";
import type { ControlParameters } from "./control-command-nfd.js";
type CommandOptions = Except<ControlCommandOptions, "endpoint" | "prefix">;
type RouteOptions = Pick<ControlParameters.Fields, "origin" | "cost" | `flag${keyof typeof RouteFlags}`>;
type Options = CommandOptions & RouteOptions & {

@@ -9,0 +11,0 @@ retry?: ReadvertiseDestination.RetryOptions;

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

* @param signer private key to sign the Interest.
* @see https://named-data.net/doc/ndn-cxx/0.8.0/specs/signed-interest.html
* @see https://docs.named-data.net/ndn-cxx/0.8.0/specs/signed-interest.html
*/

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

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

* @param signer private key to sign the Interest.
* @see https://named-data.net/doc/ndn-cxx/0.8.0/specs/signed-interest.html
* @see https://docs.named-data.net/ndn-cxx/0.8.0/specs/signed-interest.html
*/

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

@@ -6,3 +6,3 @@ import { type Interest, type Signer } from "@ndn/packet";

* @param signer private key to sign the Interest.
* @see https://named-data.net/doc/ndn-cxx/0.8.0/specs/signed-interest.html
* @see https://docs.named-data.net/ndn-cxx/0.8.0/specs/signed-interest.html
*/

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

{
"name": "@ndn/nfdmgmt",
"version": "0.0.20230121",
"version": "0.0.20240113",
"description": "NDNts: NFD Management",

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

"dependencies": {
"@ndn/endpoint": "0.0.20230121",
"@ndn/fw": "0.0.20230121",
"@ndn/keychain": "0.0.20230121",
"@ndn/packet": "0.0.20230121",
"@ndn/tlv": "0.0.20230121",
"@ndn/util": "0.0.20230121",
"@ndn/endpoint": "0.0.20240113",
"@ndn/fw": "0.0.20240113",
"@ndn/keychain": "0.0.20240113",
"@ndn/packet": "0.0.20240113",
"@ndn/segmented-object": "0.0.20240113",
"@ndn/tlv": "0.0.20240113",
"@ndn/util": "0.0.20240113",
"obliterator": "^2.0.4",
"tslib": "^2.4.1"
"tslib": "^2.6.2"
},
"types": "lib/mod.d.ts"
}

@@ -6,4 +6,14 @@ # @ndn/nfdmgmt

This package implements basic support for [NFD Management protocol](https://redmine.named-data.net/projects/nfd/wiki/Management).
In particular, it enables prefix registration on NFD.
It includes both a generic variant and a NFD-specific variant with additional typing.
* [X] ControlCommand
* [X] generic: `invokeGeneric`, `ControlResponse`
* [X] NFD: `invoke`, `ControlParameters`
* [X] StatusDataset
* [X] generic: `list`, `StatusDataset`
* [X] NFD: `FaceDataset`, `FaceQuery`, `CsInfo`, `StrategyChoice`, `RibEntry`
* [ ] NotificationStream
This implementation is validated against NFD using [nfdmgmt-interop](../../integ/nfdmgmt-interop/).
```ts

@@ -19,3 +29,3 @@ import { enableNfdPrefixReg } from "@ndn/nfdmgmt";

import { delay, fromUtf8, toUtf8 } from "@ndn/util";
import { strict as assert } from "node:assert";
import assert from "node:assert/strict";
```

@@ -35,3 +45,3 @@

// Connect to NFD using Unix socket transport.
const unixSocket = process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock";
const unixSocket = process.env.DEMO_NFD_UNIX ?? "/run/nfd/nfd.sock";
let uplinkC: FwFace;

@@ -73,6 +83,6 @@ try {

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).
Previously, NFD Management protocol uses the deprecated [Signed Interest 0.2 format](https://docs.named-data.net/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.
NFD is now accepting the [Signed Interest format in NDN packet spec](https://docs.named-data.net/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.

@@ -10,3 +10,3 @@ import { enableNfdPrefixReg } from "@ndn/nfdmgmt";

import { delay, fromUtf8, toUtf8 } from "@ndn/util";
import { strict as assert } from "node:assert";
import assert from "node:assert/strict";

@@ -18,3 +18,3 @@ // Create two forwarders, one as consumer and one as producer.

// Connect to NFD using Unix socket transport.
const unixSocket = process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock";
const unixSocket = process.env.DEMO_NFD_UNIX ?? "/run/nfd/nfd.sock";
let uplinkC: FwFace;

@@ -21,0 +21,0 @@ try {

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