Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ndn/nfdmgmt

Package Overview
Dependencies
Maintainers
1
Versions
9
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.20200909 to 0.0.20210203

4

lib/control-command_browser.js

@@ -18,7 +18,7 @@ import { Endpoint } from "@ndn/endpoint";

async function call(command, params, opts = {}) {
const { endpoint = new Endpoint(), commandPrefix: prefix = ControlCommand.localhostPrefix, } = opts;
const { endpoint = new Endpoint({ describe: `ControlCommand(${command})` }), commandPrefix: prefix = ControlCommand.localhostPrefix, } = opts;
const name = new Name([
...prefix.comps,
...command.split("/"),
new Component(TT.GenericNameComponent, Encoder.encode(new ControlParameters(params))),
new Component(TT.GenericNameComponent, Encoder.encode(new ControlParameters(params), 512)),
]);

@@ -25,0 +25,0 @@ const interest = await signInterest02(new Interest(name), opts);

@@ -18,7 +18,7 @@ import { Endpoint } from "@ndn/endpoint";

async function call(command, params, opts = {}) {
const { endpoint = new Endpoint(), commandPrefix: prefix = ControlCommand.localhostPrefix, } = opts;
const { endpoint = new Endpoint({ describe: `ControlCommand(${command})` }), commandPrefix: prefix = ControlCommand.localhostPrefix, } = opts;
const name = new Name([
...prefix.comps,
...command.split("/"),
new Component(TT.GenericNameComponent, Encoder.encode(new ControlParameters(params))),
new Component(TT.GenericNameComponent, Encoder.encode(new ControlParameters(params), 512)),
]);

@@ -25,0 +25,0 @@ const interest = await signInterest02(new Interest(name), opts);

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 { ControlCommand } from "./control-command_browser.js";
const PRELOAD_INTEREST_LIFETIME = Interest.Lifetime(500);
class NfdPrefixReg extends ReadvertiseDestination {

@@ -9,11 +13,10 @@ constructor(face, opts) {

this.face = face;
this.preloadCerts = new Map();
this.commandOptions = {
commandPrefix: ControlCommand.getPrefix(face.attributes.local),
...opts,
};
if (!this.commandOptions.commandPrefix) {
this.commandOptions.commandPrefix = ControlCommand.getPrefix(face.attributes.local);
}
this.routeOptions = {
origin: 65,
cost: 0x7473,
cost: 87,
flags: 0x02,

@@ -23,12 +26,45 @@ ...opts,

this.refreshInterval = (_a = opts.refreshInterval) !== null && _a !== void 0 ? _a : 300000;
this.preloadCertName = opts.preloadCertName;
face.once("close", () => this.disable());
}
tap() {
async tap() {
const tapFace = TapFace.create(this.face);
tapFace.addRoute(this.commandOptions.commandPrefix);
const endpoint = new Endpoint({ fw: tapFace.fw });
return [{ ...this.commandOptions, endpoint }, () => tapFace.close()];
tapFace.addRoute(new Name("/"));
const endpoint = new Endpoint({
announcement: false,
describe: "NfdPrefixReg",
fw: tapFace.fw,
});
const preloadProducers = await this.preload(endpoint);
return [
{ ...this.commandOptions, endpoint },
() => {
preloadProducers.forEach((p) => p.close());
tapFace.close();
},
];
}
async preload(endpoint) {
var _a;
const producers = new Map();
let name = this.preloadCertName;
while (name) {
const key = toHex(name.value);
if (producers.has(key)) {
break;
}
try {
const cert = (_a = this.preloadCerts.get(key)) !== null && _a !== void 0 ? _a : Certificate.fromData(await endpoint.consume(new Interest(name, Interest.CanBePrefix, PRELOAD_INTEREST_LIFETIME)));
this.preloadCerts.set(key, cert);
producers.set(key, endpoint.produce(name, () => Promise.resolve(cert.data)));
name = cert.issuer;
}
catch {
name = undefined;
}
}
return producers;
}
async doAdvertise(name, state, nameHex) {
const [opts, untap] = this.tap();
const [opts, untap] = await this.tap();
try {

@@ -62,3 +98,3 @@ const cr = await ControlCommand.call("rib/register", {

}
const [opts, untap] = this.tap();
const [opts, untap] = await this.tap();
try {

@@ -65,0 +101,0 @@ const cr = await ControlCommand.call("rib/unregister", {

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 { ControlCommand } from "./control-command_node.js";
const PRELOAD_INTEREST_LIFETIME = Interest.Lifetime(500);
class NfdPrefixReg extends ReadvertiseDestination {

@@ -9,11 +13,10 @@ constructor(face, opts) {

this.face = face;
this.preloadCerts = new Map();
this.commandOptions = {
commandPrefix: ControlCommand.getPrefix(face.attributes.local),
...opts,
};
if (!this.commandOptions.commandPrefix) {
this.commandOptions.commandPrefix = ControlCommand.getPrefix(face.attributes.local);
}
this.routeOptions = {
origin: 65,
cost: 0x7473,
cost: 87,
flags: 0x02,

@@ -23,12 +26,45 @@ ...opts,

this.refreshInterval = (_a = opts.refreshInterval) !== null && _a !== void 0 ? _a : 300000;
this.preloadCertName = opts.preloadCertName;
face.once("close", () => this.disable());
}
tap() {
async tap() {
const tapFace = TapFace.create(this.face);
tapFace.addRoute(this.commandOptions.commandPrefix);
const endpoint = new Endpoint({ fw: tapFace.fw });
return [{ ...this.commandOptions, endpoint }, () => tapFace.close()];
tapFace.addRoute(new Name("/"));
const endpoint = new Endpoint({
announcement: false,
describe: "NfdPrefixReg",
fw: tapFace.fw,
});
const preloadProducers = await this.preload(endpoint);
return [
{ ...this.commandOptions, endpoint },
() => {
preloadProducers.forEach((p) => p.close());
tapFace.close();
},
];
}
async preload(endpoint) {
var _a;
const producers = new Map();
let name = this.preloadCertName;
while (name) {
const key = toHex(name.value);
if (producers.has(key)) {
break;
}
try {
const cert = (_a = this.preloadCerts.get(key)) !== null && _a !== void 0 ? _a : Certificate.fromData(await endpoint.consume(new Interest(name, Interest.CanBePrefix, PRELOAD_INTEREST_LIFETIME)));
this.preloadCerts.set(key, cert);
producers.set(key, endpoint.produce(name, () => Promise.resolve(cert.data)));
name = cert.issuer;
}
catch {
name = undefined;
}
}
return producers;
}
async doAdvertise(name, state, nameHex) {
const [opts, untap] = this.tap();
const [opts, untap] = await this.tap();
try {

@@ -62,3 +98,3 @@ const cr = await ControlCommand.call("rib/register", {

}
const [opts, untap] = this.tap();
const [opts, untap] = await this.tap();
try {

@@ -65,0 +101,0 @@ const cr = await ControlCommand.call("rib/unregister", {

import { FwFace, ReadvertiseDestination } from "@ndn/fw";
import { Name } from "@ndn/packet";
import { ControlCommand } from "./control-command";
import { ControlParameters } from "./control-parameters";
import type { ControlParameters } from "./control-parameters";
declare type CommandOptions = Omit<ControlCommand.Options, "endpoint">;

@@ -10,2 +11,4 @@ declare type RouteOptions = Pick<ControlParameters.Fields, "origin" | "cost" | "flags">;

refreshInterval?: number | false;
/** Set to signer name to retrieve and serve certificate chain. */
preloadCertName?: Name;
};

@@ -12,0 +15,0 @@ /**

{
"name": "@ndn/nfdmgmt",
"version": "0.0.20200909",
"version": "0.0.20210203",
"description": "NDNts: NFD Management",

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

"dependencies": {
"@ndn/endpoint": "0.0.20200909",
"@ndn/fw": "0.0.20200909",
"@ndn/packet": "0.0.20200909",
"@ndn/tlv": "0.0.20200909",
"tslib": "^2.0.1"
"@ndn/endpoint": "0.0.20210203",
"@ndn/fw": "0.0.20210203",
"@ndn/keychain": "0.0.20210203",
"@ndn/packet": "0.0.20210203",
"@ndn/tlv": "0.0.20210203",
"tslib": "^2.1.0"
},
"types": "lib/mod.d.ts"
}
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