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.20220501 to 0.0.20230121

6

lib/control-command.d.ts
import { Endpoint } from "@ndn/endpoint";
import { type Signer, Name, SignedInterestPolicy } from "@ndn/packet";
import { ControlParameters } from "./control-parameters";
import { ControlResponse } from "./control-response";
import { ControlParameters } from "./control-parameters.js";
import { ControlResponse } from "./control-response.js";
/**

@@ -10,3 +10,3 @@ * Pick fields from ControlParameters.Fields.

*/
declare type CP<R extends keyof ControlParameters.Fields, O extends keyof ControlParameters.Fields> = Required<Pick<ControlParameters.Fields, R>> & Pick<ControlParameters.Fields, O>;
type CP<R extends keyof ControlParameters.Fields, O extends keyof ControlParameters.Fields> = Required<Pick<ControlParameters.Fields, R>> & Pick<ControlParameters.Fields, O>;
/** Declare required and optional fields of each command. */

@@ -13,0 +13,0 @@ interface Commands {

@@ -47,8 +47,5 @@ import { Name, TT } from "@ndn/packet";

const v = this[key];
if (v === undefined) {
return undefined;
}
return [tt, encodeValue(v)];
return v !== undefined && [tt, encodeValue(v)];
}));
}
}

@@ -47,8 +47,5 @@ import { Name, TT } from "@ndn/packet";

const v = this[key];
if (v === undefined) {
return undefined;
}
return [tt, encodeValue(v)];
return v !== undefined && [tt, encodeValue(v)];
}));
}
}
import { Name } from "@ndn/packet";
import { type Decoder, Encoder } from "@ndn/tlv";
import { type Decoder, type Encoder } from "@ndn/tlv";
/** NFD Management ControlParameters struct. */

@@ -4,0 +4,0 @@ export declare class ControlParameters {

@@ -17,2 +17,8 @@ import { EvDecoder, NNI } from "@ndn/tlv";

export class ControlResponse {
statusCode;
statusText;
body;
static decodeFrom(decoder) {
return EVD.decode(new ControlResponse(), decoder);
}
constructor(statusCode = 0, statusText = "", body) {

@@ -23,5 +29,2 @@ this.statusCode = statusCode;

}
static decodeFrom(decoder) {
return EVD.decode(new ControlResponse(), decoder);
}
encodeTo(encoder) {

@@ -28,0 +31,0 @@ encoder.prependTlv(TT.ControlResponse, [TT.StatusCode, NNI(this.statusCode)], [TT.StatusText, toUtf8(this.statusText)], this.body);

@@ -17,2 +17,8 @@ import { EvDecoder, NNI } from "@ndn/tlv";

export class ControlResponse {
statusCode;
statusText;
body;
static decodeFrom(decoder) {
return EVD.decode(new ControlResponse(), decoder);
}
constructor(statusCode = 0, statusText = "", body) {

@@ -23,5 +29,2 @@ this.statusCode = statusCode;

}
static decodeFrom(decoder) {
return EVD.decode(new ControlResponse(), decoder);
}
encodeTo(encoder) {

@@ -28,0 +31,0 @@ encoder.prependTlv(TT.ControlResponse, [TT.StatusCode, NNI(this.statusCode)], [TT.StatusText, toUtf8(this.statusText)], this.body);

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

export * from "./control-command";
export * from "./control-parameters";
export * from "./control-response";
export * from "./prefix-reg";
export * from "./sign-interest-02";
export * from "./control-command.js";
export * from "./control-parameters.js";
export * from "./control-response.js";
export * from "./prefix-reg.js";
export * from "./sign-interest-02.js";

@@ -10,13 +10,13 @@ import { __importDefault, __importStar } from "tslib";

class NfdPrefixReg extends ReadvertiseDestination {
face;
commandOptions;
routeOptions;
refreshInterval;
preloadCertName;
preloadFromKeyChain;
preloadInterestLifetime;
preloadCerts = new NameMap();
constructor(face, opts) {
super(opts.retry);
this.face = face;
this.preloadCerts = new NameMap();
this.handleFaceUp = () => {
for (const [name, { status, state }] of this.table) {
if (status === ReadvertiseDestination.Status.ADVERTISED) {
this.scheduleRefresh(name, state, 100);
}
}
};
this.commandOptions = {

@@ -90,2 +90,9 @@ commandPrefix: ControlCommand.getPrefix(face.attributes.local),

}
handleFaceUp = () => {
for (const [name, { status, state }] of this.table) {
if (status === ReadvertiseDestination.Status.ADVERTISED) {
this.scheduleRefresh(name, state, 100);
}
}
};
async doAdvertise(name, state) {

@@ -92,0 +99,0 @@ const [opts, untap] = await this.tap();

@@ -10,13 +10,13 @@ import { __importDefault, __importStar } from "tslib";

class NfdPrefixReg extends ReadvertiseDestination {
face;
commandOptions;
routeOptions;
refreshInterval;
preloadCertName;
preloadFromKeyChain;
preloadInterestLifetime;
preloadCerts = new NameMap();
constructor(face, opts) {
super(opts.retry);
this.face = face;
this.preloadCerts = new NameMap();
this.handleFaceUp = () => {
for (const [name, { status, state }] of this.table) {
if (status === ReadvertiseDestination.Status.ADVERTISED) {
this.scheduleRefresh(name, state, 100);
}
}
};
this.commandOptions = {

@@ -90,2 +90,9 @@ commandPrefix: ControlCommand.getPrefix(face.attributes.local),

}
handleFaceUp = () => {
for (const [name, { status, state }] of this.table) {
if (status === ReadvertiseDestination.Status.ADVERTISED) {
this.scheduleRefresh(name, state, 100);
}
}
};
async doAdvertise(name, state) {

@@ -92,0 +99,0 @@ const [opts, untap] = await this.tap();

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

import { FwFace, ReadvertiseDestination } from "@ndn/fw";
import { type FwFace, ReadvertiseDestination } from "@ndn/fw";
import { type KeyChain } from "@ndn/keychain";
import { type Name } from "@ndn/packet";
import { ControlCommand } from "./control-command";
import type { ControlParameters } from "./control-parameters";
declare type CommandOptions = Omit<ControlCommand.Options, "endpoint">;
declare type RouteOptions = Pick<ControlParameters.Fields, "origin" | "cost" | "flags">;
declare type Options = CommandOptions & RouteOptions & {
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">;
type Options = CommandOptions & RouteOptions & {
retry?: ReadvertiseDestination.RetryOptions;

@@ -10,0 +10,0 @@ /** How often to refresh prefix registration, false to disable. */

import { digestSigning, LLSign, Name, TT } from "@ndn/packet";
import { Encoder, NNI } from "@ndn/tlv";
class SignedInterest02 {
name;
timestamp;
sigInfo;
sigValue = new Uint8Array();
constructor(name, timestamp) {
this.name = name;
this.timestamp = timestamp;
this.sigValue = new Uint8Array();
}

@@ -9,0 +12,0 @@ async [LLSign.OP](sign) {

import { digestSigning, LLSign, Name, TT } from "@ndn/packet";
import { Encoder, NNI } from "@ndn/tlv";
class SignedInterest02 {
name;
timestamp;
sigInfo;
sigValue = new Uint8Array();
constructor(name, timestamp) {
this.name = name;
this.timestamp = timestamp;
this.sigValue = new Uint8Array();
}

@@ -9,0 +12,0 @@ async [LLSign.OP](sign) {

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

import { type Signer, Interest } from "@ndn/packet";
import { type Interest, type Signer } from "@ndn/packet";
/**

@@ -3,0 +3,0 @@ * Sign an Interest in Signed Interest 0.2 format.

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

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

"dependencies": {
"@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"
"@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",
"obliterator": "^2.0.4",
"tslib": "^2.4.1"
},
"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"
"types": "lib/mod.d.ts"
}

@@ -17,5 +17,4 @@ # @ndn/nfdmgmt

import { Data, Interest, Name } from "@ndn/packet";
import { fromUtf8, toUtf8 } from "@ndn/util";
import { delay, fromUtf8, toUtf8 } from "@ndn/util";
import { strict as assert } from "node:assert";
import { setTimeout as delay } from "node:timers/promises";
```

@@ -22,0 +21,0 @@

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

import { enableNfdPrefixReg, signInterest02 } from "@ndn/nfdmgmt";
import { enableNfdPrefixReg } from "@ndn/nfdmgmt";

@@ -9,15 +9,5 @@ // other imports for examples

import { Data, Interest, Name } from "@ndn/packet";
import { fromUtf8, toUtf8 } from "@ndn/tlv";
import { delay, fromUtf8, toUtf8 } from "@ndn/util";
import { strict as assert } from "node:assert";
import { setTimeout as delay } from "node:timers/promises";
// 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}`);
// Create two forwarders, one as consumer and one as producer.

@@ -39,3 +29,4 @@ const fwC = Forwarder.create();

// Enable NFD prefix registration.
// Generate a signing key and enable NFD prefix registration.
const [privateKey] = await generateSigningKey("/K");
enableNfdPrefixReg(uplinkP, { signer: privateKey });

@@ -42,0 +33,0 @@

Sorry, the diff of this file is not supported yet

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