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.20191223-beta.1 to 0.0.20200606

0

lib/control-command.d.ts

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

6

lib/control-command.js

@@ -13,3 +13,3 @@ import { Endpoint } from "@ndn/endpoint";

function getPrefix(isLocal) {
return ((isLocal !== null && isLocal !== void 0 ? isLocal : false)) ? ControlCommand.localhostPrefix : ControlCommand.localhopPrefix;
return (isLocal !== null && isLocal !== void 0 ? isLocal : false) ? ControlCommand.localhostPrefix : ControlCommand.localhopPrefix;
}

@@ -19,4 +19,3 @@ ControlCommand.getPrefix = getPrefix;

async function call(command, params, opts = {}) {
var _a, _b;
const prefix = (_a = opts.commandPrefix, (_a !== null && _a !== void 0 ? _a : ControlCommand.localhostPrefix));
const { endpoint = new Endpoint(), commandPrefix: prefix = ControlCommand.localhostPrefix, } = opts;
const name = new Name([

@@ -28,3 +27,2 @@ ...prefix.comps,

const interest = await signInterest02(new Interest(name), opts);
const endpoint = (_b = opts.endpoint, (_b !== null && _b !== void 0 ? _b : new Endpoint()));
const data = await endpoint.consume(interest);

@@ -31,0 +29,0 @@ return new Decoder(data.content).decode(ControlResponse);

@@ -0,0 +0,0 @@ import { Name } from "@ndn/packet";

import { Name, TT } from "@ndn/packet";
import { NNI } from "@ndn/tlv";
import { NNI, toUtf8 } from "@ndn/tlv";
const fieldDefs = [
[TT.Name, "name", null],
[TT.Name, "name", undefined],
[0x69, "faceId", NNI],

@@ -35,3 +35,3 @@ [0x72, "uri", String],

case type === String:
return [tt, new TextEncoder().encode(value)];
return [tt, toUtf8(value)];
case type === Name:

@@ -38,0 +38,0 @@ return [tt, value];

@@ -0,0 +0,0 @@ import { Decoder } from "@ndn/tlv";

import { EvDecoder } from "@ndn/tlv";
const EVD = new EvDecoder("ControlResponse", 0x65)
.add(0x66, (t, { nni }) => t.statusCode = nni)
.add(0x67, (t, { value }) => t.statusText = new TextDecoder().decode(value))
.add(0x67, (t, { text }) => t.statusText = text)
.setIsCritical(() => false);

@@ -6,0 +6,0 @@ /** NFD Management ControlResponse struct (decoding only). */

@@ -0,0 +0,0 @@ export * from "./control-command";

@@ -1,4 +0,11 @@

import { FwFace } from "@ndn/fw";
import { FwFace, ReadvertiseDestination } from "@ndn/fw";
import { ControlCommand } from "./control-command";
declare type Options = Omit<ControlCommand.Options, "endpoint">;
import { 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 & {
retry?: ReadvertiseDestination.RetryOptions;
/** How often to refresh prefix registration, false to disable. */
refreshInterval?: number | false;
};
/**

@@ -5,0 +12,0 @@ * Enable prefix registration via NFD management protocol.

import { Endpoint } from "@ndn/endpoint";
import { Advertise, TapFace } from "@ndn/fw";
import { ReadvertiseDestination, TapFace } from "@ndn/fw";
import { ControlCommand } from "./control-command.js";
class NfdAdvertise extends Advertise {
class NfdPrefixReg extends ReadvertiseDestination {
constructor(face, opts) {
var _a;
super(face);
this.opts = opts;
this.opts.commandPrefix = (_a = this.opts.commandPrefix, (_a !== null && _a !== void 0 ? _a : ControlCommand.getPrefix(face.attributes.local)));
super(opts.retry);
this.face = face;
this.commandOptions = {
...opts,
};
if (!this.commandOptions.commandPrefix) {
this.commandOptions.commandPrefix = ControlCommand.getPrefix(face.attributes.local);
}
this.routeOptions = {
origin: 65,
cost: 0x7473,
flags: 0x02,
...opts,
};
this.refreshInterval = (_a = opts.refreshInterval) !== null && _a !== void 0 ? _a : 300000;
face.once("close", () => this.disable());
}
tap() {
const tapFace = TapFace.create(this.face);
tapFace.addRoute(this.opts.commandPrefix);
tapFace.addRoute(this.commandOptions.commandPrefix);
const endpoint = new Endpoint({ fw: tapFace.fw });
return [endpoint, () => tapFace.close()];
return [{ ...this.commandOptions, endpoint }, () => tapFace.close()];
}
async doAdvertise(name) {
const [endpoint, untap] = this.tap();
const cr = await ControlCommand.call("rib/register", {
name,
origin: 65,
cost: 0x7473,
flags: 0x02,
}, { ...this.opts, endpoint }).finally(untap);
if (cr.statusCode !== 200) {
throw new Error(`${cr.statusCode} ${cr.statusText}`);
async doAdvertise(name, state, nameHex) {
const [opts, untap] = 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}`);
}
}
finally {
untap();
}
if (typeof this.refreshInterval === "number") {
clearTimeout(state.refreshTimer);
state.refreshTimer = setTimeout(() => {
this.table.get(nameHex).status = ReadvertiseDestination.Status.ADVERTISING;
this.queue.push(nameHex);
}, this.refreshInterval);
}
}
async doWithdraw(name) {
const [endpoint, untap] = this.tap();
const cr = await ControlCommand.call("rib/unregister", {
name,
origin: 65,
}, { ...this.opts, endpoint }).finally(untap);
if (cr.statusCode !== 200) {
throw new Error(`${cr.statusCode} ${cr.statusText}`);
async doWithdraw(name, state) {
clearTimeout(state.refreshTimer);
state.refreshTimer = undefined;
if (this.closed) {
return;
}
const [opts, untap] = 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}`);
}
}
finally {
untap();
}
}

@@ -46,3 +81,3 @@ }

export function enableNfdPrefixReg(face, opts = {}) {
face.advertise = new NfdAdvertise(face, opts);
new NfdPrefixReg(face, opts).enable(face.fw);
}

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

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

@@ -12,5 +11,5 @@ * Sign an Interest in 2014 Signed Interest format.

interface Options {
signer?: PrivateKey;
signer?: Signer;
timestamp?: number;
}
}

@@ -1,4 +0,3 @@

import { theDigestKey } from "@ndn/keychain";
import { LLSign, Name, TT } from "@ndn/packet";
import { Decoder, Encoder, NNI } from "@ndn/tlv";
import { digestSigning, LLSign, Name, TT } from "@ndn/packet";
import { Encoder, NNI } from "@ndn/tlv";
class SignedInterest02 {

@@ -9,3 +8,3 @@ constructor(name, timestamp) {

}
async [(LLSign.PENDING, LLSign.PROCESS)]() {
async [LLSign.OP](sign) {
const nonce = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);

@@ -18,8 +17,7 @@ const signedPortion = Encoder.encode([

]);
await LLSign.processImpl(this, () => signedPortion, (sig) => this.sigValue = sig);
this.name = new Decoder(Encoder.encode([
TT.Name,
this.sigValue = await sign(signedPortion);
this.name = new Name(Encoder.encode([
signedPortion,
[TT.GenericNameComponent, [TT.DSigValue, this.sigValue]],
])).decode(Name);
]));
}

@@ -33,8 +31,7 @@ }

*/
export async function signInterest02(interest, { signer = theDigestKey, timestamp = Date.now() } = {}) {
export async function signInterest02(interest, { signer = digestSigning, timestamp = Date.now() } = {}) {
const si = new SignedInterest02(interest.name, timestamp);
signer.sign(si);
await si[LLSign.PROCESS]();
await signer.sign(si);
interest.name = si.name;
return interest;
}
{
"name": "@ndn/nfdmgmt",
"version": "0.0.20191223-beta.1",
"version": "0.0.20200606",
"description": "NDNts: NFD Management",

@@ -24,9 +24,8 @@ "keywords": [

"dependencies": {
"@ndn/endpoint": "0.0.20191223-beta.1",
"@ndn/fw": "0.0.20191223-beta.1",
"@ndn/keychain": "0.0.20191223-beta.1",
"@ndn/packet": "0.0.20191223-beta.1",
"@ndn/tlv": "0.0.20191223-beta.1",
"@ndn/endpoint": "0.0.20200606",
"@ndn/fw": "0.0.20200606",
"@ndn/packet": "0.0.20200606",
"@ndn/tlv": "0.0.20200606",
"tslib": "*"
}
}

@@ -13,8 +13,7 @@ # @ndn/nfdmgmt

import { Endpoint } from "@ndn/endpoint";
import { Forwarder } from "@ndn/fw";
import { Forwarder, FwFace } from "@ndn/fw";
import { EcPrivateKey } from "@ndn/keychain";
import { L3Face } from "@ndn/l3face";
import { Data, Interest } from "@ndn/packet";
import { Name } from "@ndn/packet";
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";

@@ -48,6 +47,6 @@ (async () => {

// Connect to NFD using Unix socket transport.
let transportC: UnixTransport;
let uplinkC: FwFace;
try {
transportC = await UnixTransport.connect("/var/run/nfd.sock");
} catch (err) {
uplinkC = await UnixTransport.createFace({ fw: fwC }, "/run/nfd.sock");
} catch {
// Skip the example if NFD is not running.

@@ -57,6 +56,4 @@ console.warn("NFD not running");

}
const uplinkC = fwC.addFace(new L3Face(transportC));
uplinkC.addRoute(new Name("/"));
const transportP = await UnixTransport.connect("/var/run/nfd.sock");
const uplinkP = fwP.addFace(new L3Face(transportP));
const uplinkP = await UnixTransport.createFace({ fw: fwP }, "/run/nfd.sock");

@@ -68,6 +65,5 @@ // Enable NFD prefix registration.

const producer = new Endpoint({ fw: fwP }).produce("/P",
async() => {
async () => {
console.log("producing");
return new Data("/P", Data.FreshnessPeriod(1000),
new TextEncoder().encode("NDNts + NFD"));
return new Data("/P", Data.FreshnessPeriod(1000), toUtf8("NDNts + NFD"));
});

@@ -80,3 +76,3 @@ await new Promise((r) => setTimeout(r, 500));

);
const payloadText = new TextDecoder().decode(data.content);
const payloadText = fromUtf8(data.content);
console.log("received", `${data.name} ${payloadText}`);

@@ -83,0 +79,0 @@ assert.equal(payloadText, "NDNts + NFD");

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