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

@ndn/fw

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/fw - npm Package Compare versions

Comparing version 0.0.20220501 to 0.0.20230121

63

lib/face_browser.js

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

import { EventEmitter } from "events";
import { Data, Interest, Nack, Name, NameMultiSet } from "@ndn/packet";
import { safeIter } from "@ndn/util";
import { pushable } from "it-pushable";
import { EventEmitter } from "events";
import { filter, pipeline, tap } from "streaming-iterables";

@@ -27,2 +27,9 @@ function duplexFromRxTx(rxtx) {

export class FaceImpl extends EventEmitter {
fw;
rxtx;
attributes;
routes = new NameMultiSet();
announcements = new NameMultiSet();
running = true;
txQueue = pushable({ objectMode: true });
constructor(fw, rxtx, attributes) {

@@ -32,31 +39,2 @@ super();

this.rxtx = rxtx;
this.routes = new NameMultiSet();
this.announcements = new NameMultiSet();
this.running = true;
this.txQueue = pushable();
this.handleLowerUp = () => {
this.emit("up");
};
this.handleLowerDown = () => {
this.emit("down");
};
this.rxLoop = async (input) => {
for await (const pkt of filter(() => this.running, input)) {
switch (true) {
case pkt.l3 instanceof Interest: {
this.fw[pkt.cancel ? "cancelInterest" : "processInterest"](this, pkt);
break;
}
case pkt.l3 instanceof Data: {
this.fw.processData(this, pkt);
break;
}
case pkt.l3 instanceof Nack: {
this.fw.processNack(this, pkt);
break;
}
}
}
this.close();
};
this.attributes = {

@@ -147,2 +125,27 @@ local: false,

}
handleLowerUp = () => {
this.emit("up");
};
handleLowerDown = () => {
this.emit("down");
};
rxLoop = async (input) => {
for await (const pkt of filter(() => this.running, input)) {
switch (true) {
case pkt.l3 instanceof Interest: {
this.fw[pkt.cancel ? "cancelInterest" : "processInterest"](this, pkt);
break;
}
case pkt.l3 instanceof Data: {
this.fw.processData(this, pkt);
break;
}
case pkt.l3 instanceof Nack: {
this.fw.processNack(this, pkt);
break;
}
}
}
this.close();
};
txLoop() {

@@ -149,0 +152,0 @@ return safeIter(this.txQueue);

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

import { EventEmitter } from "node:events";
import { Data, Interest, Nack, Name, NameMultiSet } from "@ndn/packet";
import { safeIter } from "@ndn/util";
import { pushable } from "it-pushable";
import { EventEmitter } from "node:events";
import { filter, pipeline, tap } from "streaming-iterables";

@@ -27,2 +27,9 @@ function duplexFromRxTx(rxtx) {

export class FaceImpl extends EventEmitter {
fw;
rxtx;
attributes;
routes = new NameMultiSet();
announcements = new NameMultiSet();
running = true;
txQueue = pushable({ objectMode: true });
constructor(fw, rxtx, attributes) {

@@ -32,31 +39,2 @@ super();

this.rxtx = rxtx;
this.routes = new NameMultiSet();
this.announcements = new NameMultiSet();
this.running = true;
this.txQueue = pushable();
this.handleLowerUp = () => {
this.emit("up");
};
this.handleLowerDown = () => {
this.emit("down");
};
this.rxLoop = async (input) => {
for await (const pkt of filter(() => this.running, input)) {
switch (true) {
case pkt.l3 instanceof Interest: {
this.fw[pkt.cancel ? "cancelInterest" : "processInterest"](this, pkt);
break;
}
case pkt.l3 instanceof Data: {
this.fw.processData(this, pkt);
break;
}
case pkt.l3 instanceof Nack: {
this.fw.processNack(this, pkt);
break;
}
}
}
this.close();
};
this.attributes = {

@@ -147,2 +125,27 @@ local: false,

}
handleLowerUp = () => {
this.emit("up");
};
handleLowerDown = () => {
this.emit("down");
};
rxLoop = async (input) => {
for await (const pkt of filter(() => this.running, input)) {
switch (true) {
case pkt.l3 instanceof Interest: {
this.fw[pkt.cancel ? "cancelInterest" : "processInterest"](this, pkt);
break;
}
case pkt.l3 instanceof Data: {
this.fw.processData(this, pkt);
break;
}
case pkt.l3 instanceof Nack: {
this.fw.processNack(this, pkt);
break;
}
}
}
this.close();
};
txLoop() {

@@ -149,0 +152,0 @@ return safeIter(this.txQueue);

import { type NameLike } from "@ndn/packet";
import type TypedEmitter from "typed-emitter";
import type { Forwarder, ForwarderImpl } from "./forwarder";
import type { FwPacket } from "./packet";
declare type Events = {
import type { Forwarder, ForwarderImpl } from "./forwarder.js";
import type { FwPacket } from "./packet.js";
type Events = {
/** Emitted upon face is up as reported by lower layer. */

@@ -7,0 +7,0 @@ up: () => void;

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

class FibEntry {
constructor() {
this.nexthops = new Map(); // face=>capture
}
nexthops = new Map(); // face=>capture
}
export class Fib {
constructor() {
this.table = new DefaultMap(() => new FibEntry());
}
table = new DefaultMap(() => new FibEntry());
insert(face, nameHex, capture) {

@@ -16,0 +12,0 @@ const entry = this.table.get(nameHex);

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

class FibEntry {
constructor() {
this.nexthops = new Map(); // face=>capture
}
nexthops = new Map(); // face=>capture
}
export class Fib {
constructor() {
this.table = new DefaultMap(() => new FibEntry());
}
table = new DefaultMap(() => new FibEntry());
insert(face, nameHex, capture) {

@@ -16,0 +12,0 @@ const entry = this.table.get(nameHex);

import { type Name } from "@ndn/packet";
import type { FaceImpl } from "./face";
import type { FaceImpl } from "./face.js";
export declare class Fib {

@@ -4,0 +4,0 @@ private readonly table;

@@ -41,9 +41,11 @@ import { EventEmitter } from "events";

export class ForwarderImpl extends EventEmitter {
opts;
nodeNames = [];
faces = new Set();
fib = new Fib();
pit;
readvertise = new Readvertise(this);
constructor(opts) {
super();
this.opts = opts;
this.nodeNames = [];
this.faces = new Set();
this.fib = new Fib();
this.readvertise = new Readvertise(this);
this.pit = new Pit(opts.dataNoTokenMatch);

@@ -50,0 +52,0 @@ }

@@ -41,9 +41,11 @@ import { EventEmitter } from "node:events";

export class ForwarderImpl extends EventEmitter {
opts;
nodeNames = [];
faces = new Set();
fib = new Fib();
pit;
readvertise = new Readvertise(this);
constructor(opts) {
super();
this.opts = opts;
this.nodeNames = [];
this.faces = new Set();
this.fib = new Fib();
this.readvertise = new Readvertise(this);
this.pit = new Pit(opts.dataNoTokenMatch);

@@ -50,0 +52,0 @@ }

import type { Data, Interest, Nack, Name } from "@ndn/packet";
import type TypedEmitter from "typed-emitter";
import { type FwFace, FaceImpl } from "./face";
import { Fib } from "./fib";
import type { FwPacket } from "./packet";
import { Pit } from "./pit";
import { Readvertise } from "./readvertise";
declare type Events = {
import { type FwFace, FaceImpl } from "./face.js";
import { Fib } from "./fib.js";
import type { FwPacket } from "./packet.js";
import { Pit } from "./pit.js";
import { Readvertise } from "./readvertise.js";
type Events = {
/** Emitted before adding face. */

@@ -10,0 +10,0 @@ faceadd: (face: FwFace) => void;

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

export * from "./packet";
export { FwFace } from "./face";
export { Forwarder } from "./forwarder";
export { ReadvertiseDestination } from "./readvertise";
export { TapFace } from "./tap-face";
export { Tracer as FwTracer } from "./tracer";
export * from "./packet.js";
export type { FwFace } from "./face.js";
export { Forwarder } from "./forwarder.js";
export { ReadvertiseDestination } from "./readvertise.js";
export { TapFace } from "./tap-face.js";
export { Tracer as FwTracer } from "./tracer.js";

@@ -15,2 +15,5 @@ export var FwPacket;

export class RejectInterest {
reject;
l3;
token;
constructor(reject, l3, token) {

@@ -24,7 +27,9 @@ this.reject = reject;

export class CancelInterest {
l3;
token;
constructor(l3, token) {
this.l3 = l3;
this.token = token;
this.cancel = true;
}
cancel = true;
}

@@ -15,2 +15,5 @@ export var FwPacket;

export class RejectInterest {
reject;
l3;
token;
constructor(reject, l3, token) {

@@ -24,7 +27,9 @@ this.reject = reject;

export class CancelInterest {
l3;
token;
constructor(l3, token) {
this.l3 = l3;
this.token = token;
this.cancel = true;
}
cancel = true;
}
import type { Data, Interest, Nack } from "@ndn/packet";
declare type L3Pkt = Interest | Data | Nack;
type L3Pkt = Interest | Data | Nack;
/** A logical packet in the forwarder. */

@@ -4,0 +4,0 @@ export interface FwPacket<T extends L3Pkt = L3Pkt> {

import { __importDefault, __importStar } from "tslib";
import { Interest } from "@ndn/packet";
import _cjsDefaultImport0 from "hirestime"; const hirestime = __importDefault(_cjsDefaultImport0).default;
import _cjsDefaultImport1 from "mnemonist/default-map.js"; const DefaultMap = __importDefault(_cjsDefaultImport1).default;
import hirestime from "hirestime";
import _cjsDefaultImport0 from "mnemonist/default-map.js"; const DefaultMap = __importDefault(_cjsDefaultImport0).default;
import { filter, flatMap, pipeline, reduce, tap } from "streaming-iterables";

@@ -10,15 +10,17 @@ import { FwPacket, RejectInterest } from "./packet_browser.js";

export class PitEntry {
pit;
key;
/** Representative Interest. */
interest;
/** Outgoing numeric PIT token. */
token;
/** Downstream records. */
dnRecords = new DefaultMap(() => ({ nRx: 0, expire: 0, nonce: 0, token: undefined }));
/** Last expiration time among downstream. */
lastExpire = 0;
/** Entry expiration timer; should match this.lastExpire. */
expireTimer;
constructor(pit, key, interest) {
this.pit = pit;
this.key = key;
/** Downstream records. */
this.dnRecords = new DefaultMap(() => ({ nRx: 0, expire: 0, nonce: 0, token: undefined }));
/** Last expiration time among downstream. */
this.lastExpire = 0;
this.expire = () => {
this.pit.eraseEntry(this);
for (const [face, { token }] of this.dnRecords) {
face.send(new RejectInterest("expire", this.interest, token));
}
};
this.interest = new Interest(interest);

@@ -89,11 +91,18 @@ }

}
expire = () => {
this.pit.eraseEntry(this);
for (const [face, { token }] of this.dnRecords) {
face.send(new RejectInterest("expire", this.interest, token));
}
};
}
/** Pending Interest table. */
export class Pit {
dataNoTokenMatch;
constructor(dataNoTokenMatch) {
this.dataNoTokenMatch = dataNoTokenMatch;
this.byName = new Map();
this.byToken = new Map();
this.lastToken = 0;
}
byName = new Map();
byToken = new Map();
lastToken = 0;
generateToken() {

@@ -100,0 +109,0 @@ do {

import { __importDefault, __importStar } from "tslib";
import { Interest } from "@ndn/packet";
import _cjsDefaultImport0 from "hirestime"; const hirestime = __importDefault(_cjsDefaultImport0).default;
import _cjsDefaultImport1 from "mnemonist/default-map.js"; const DefaultMap = __importDefault(_cjsDefaultImport1).default;
import hirestime from "hirestime";
import _cjsDefaultImport0 from "mnemonist/default-map.js"; const DefaultMap = __importDefault(_cjsDefaultImport0).default;
import { filter, flatMap, pipeline, reduce, tap } from "streaming-iterables";

@@ -10,15 +10,17 @@ import { FwPacket, RejectInterest } from "./packet_node.js";

export class PitEntry {
pit;
key;
/** Representative Interest. */
interest;
/** Outgoing numeric PIT token. */
token;
/** Downstream records. */
dnRecords = new DefaultMap(() => ({ nRx: 0, expire: 0, nonce: 0, token: undefined }));
/** Last expiration time among downstream. */
lastExpire = 0;
/** Entry expiration timer; should match this.lastExpire. */
expireTimer;
constructor(pit, key, interest) {
this.pit = pit;
this.key = key;
/** Downstream records. */
this.dnRecords = new DefaultMap(() => ({ nRx: 0, expire: 0, nonce: 0, token: undefined }));
/** Last expiration time among downstream. */
this.lastExpire = 0;
this.expire = () => {
this.pit.eraseEntry(this);
for (const [face, { token }] of this.dnRecords) {
face.send(new RejectInterest("expire", this.interest, token));
}
};
this.interest = new Interest(interest);

@@ -89,11 +91,18 @@ }

}
expire = () => {
this.pit.eraseEntry(this);
for (const [face, { token }] of this.dnRecords) {
face.send(new RejectInterest("expire", this.interest, token));
}
};
}
/** Pending Interest table. */
export class Pit {
dataNoTokenMatch;
constructor(dataNoTokenMatch) {
this.dataNoTokenMatch = dataNoTokenMatch;
this.byName = new Map();
this.byToken = new Map();
this.lastToken = 0;
}
byName = new Map();
byToken = new Map();
lastToken = 0;
generateToken() {

@@ -100,0 +109,0 @@ do {

/// <reference types="node" />
import { Data, Interest } from "@ndn/packet";
import { type Data, Interest } from "@ndn/packet";
import DefaultMap from "mnemonist/default-map.js";
import type { FaceImpl } from "./face";
import { FwPacket } from "./packet";
import type { FaceImpl } from "./face.js";
import { FwPacket } from "./packet.js";
/** Downstream of pending Interest. */

@@ -7,0 +7,0 @@ interface PitDn {

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

export class Readvertise {
fw;
constructor(fw) {
this.fw = fw;
this.announcements = new NameMultiMap();
this.destinations = new Set();
}
announcements = new NameMultiMap();
destinations = new Set();
addAnnouncement(face, name) {

@@ -54,2 +55,7 @@ if (this.announcements.add(name, face) > 1) {

export class ReadvertiseDestination {
retryOptions;
readvertise;
table = new NameMap();
queue = pushable({ objectMode: true });
closed = false;
constructor(retryOptions = {

@@ -62,5 +68,2 @@ forever: true,

this.retryOptions = retryOptions;
this.table = new NameMap();
this.queue = pushable();
this.closed = false;
}

@@ -67,0 +70,0 @@ /** Enable and attach to a forwarder. */

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

export class Readvertise {
fw;
constructor(fw) {
this.fw = fw;
this.announcements = new NameMultiMap();
this.destinations = new Set();
}
announcements = new NameMultiMap();
destinations = new Set();
addAnnouncement(face, name) {

@@ -54,2 +55,7 @@ if (this.announcements.add(name, face) > 1) {

export class ReadvertiseDestination {
retryOptions;
readvertise;
table = new NameMap();
queue = pushable({ objectMode: true });
closed = false;
constructor(retryOptions = {

@@ -62,5 +68,2 @@ forever: true,

this.retryOptions = retryOptions;
this.table = new NameMap();
this.queue = pushable();
this.closed = false;
}

@@ -67,0 +70,0 @@ /** Enable and attach to a forwarder. */

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

import { Name, NameMap, NameMultiMap } from "@ndn/packet";
import { type Name, NameMap, NameMultiMap } from "@ndn/packet";
import * as retry from "retry";
import type { FaceImpl } from "./face";
import type { Forwarder, ForwarderImpl } from "./forwarder";
import type { FaceImpl } from "./face.js";
import type { Forwarder, ForwarderImpl } from "./forwarder.js";
/**

@@ -6,0 +6,0 @@ * Manage advertised prefix of the forwarder.

import { __importDefault, __importStar } from "tslib";
import { assert } from "@ndn/util";
import { assert, MultiMap } from "@ndn/util";
import { pushable } from "it-pushable";
import _cjsDefaultImport0 from "mnemonist/default-weak-map.js"; const DefaultWeakMap = __importDefault(_cjsDefaultImport0).default;
import _cjsDefaultImport1 from "mnemonist/multi-map.js"; const MultiMap = __importDefault(_cjsDefaultImport1).default;
import { Forwarder } from "./forwarder_browser.js";
class TapRxController {
fw;
static instances = new DefaultWeakMap((fw) => new TapRxController(fw));
static lookup(fw) {
return TapRxController.instances.get(fw);
}
taps = new MultiMap();
constructor(fw) {
this.fw = fw;
this.taps = new MultiMap(Set);
this.facerm = (src) => {
const dst = this.taps.get(src);
if (dst) {
for (const { rx } of dst) {
rx.end();
}
}
this.detachIfIdle();
};
this.pktrx = (src, pkt) => {
const dst = this.taps.get(src);
if (dst) {
for (const { rx } of dst) {
rx.push(pkt);
}
}
};
this.fw.on("pktrx", this.pktrx);
this.fw.on("facerm", this.facerm);
}
static lookup(fw) {
return TapRxController.instances.get(fw);
}
add(src, dst) {
assert.equal(src.fw, this.fw);
this.taps.set(src, dst);
this.taps.add(src, dst);
}

@@ -42,2 +26,9 @@ remove(src, dst) {

}
facerm = (src) => {
const dst = this.taps.list(src);
for (const { rx } of dst) {
rx.end();
}
this.detachIfIdle();
};
detachIfIdle() {

@@ -50,4 +41,9 @@ if (this.taps.size === 0) {

}
pktrx = (src, pkt) => {
const dst = this.taps.list(src);
for (const { rx } of dst) {
rx.push(pkt);
}
};
}
TapRxController.instances = new DefaultWeakMap((fw) => new TapRxController(fw));
/**

@@ -62,14 +58,3 @@ * Create a secondary face by tapping on a primary face.

export class TapFace {
constructor(face) {
this.face = face;
this.rx = pushable();
this.tx = async (iterable) => {
for await (const pkt of iterable) {
this.face.send(pkt);
}
this.ctrl.remove(this.face, this);
};
this.ctrl = TapRxController.lookup(face.fw);
this.ctrl.add(this.face, this);
}
face;
get attributes() {

@@ -81,2 +66,15 @@ return {

}
rx = pushable({ objectMode: true });
ctrl;
constructor(face) {
this.face = face;
this.ctrl = TapRxController.lookup(face.fw);
this.ctrl.add(this.face, this);
}
tx = async (iterable) => {
for await (const pkt of iterable) {
this.face.send(pkt);
}
this.ctrl.remove(this.face, this);
};
}

@@ -83,0 +81,0 @@ (function (TapFace) {

import { __importDefault, __importStar } from "tslib";
import { assert } from "@ndn/util";
import { assert, MultiMap } from "@ndn/util";
import { pushable } from "it-pushable";
import _cjsDefaultImport0 from "mnemonist/default-weak-map.js"; const DefaultWeakMap = __importDefault(_cjsDefaultImport0).default;
import _cjsDefaultImport1 from "mnemonist/multi-map.js"; const MultiMap = __importDefault(_cjsDefaultImport1).default;
import { Forwarder } from "./forwarder_node.js";
class TapRxController {
fw;
static instances = new DefaultWeakMap((fw) => new TapRxController(fw));
static lookup(fw) {
return TapRxController.instances.get(fw);
}
taps = new MultiMap();
constructor(fw) {
this.fw = fw;
this.taps = new MultiMap(Set);
this.facerm = (src) => {
const dst = this.taps.get(src);
if (dst) {
for (const { rx } of dst) {
rx.end();
}
}
this.detachIfIdle();
};
this.pktrx = (src, pkt) => {
const dst = this.taps.get(src);
if (dst) {
for (const { rx } of dst) {
rx.push(pkt);
}
}
};
this.fw.on("pktrx", this.pktrx);
this.fw.on("facerm", this.facerm);
}
static lookup(fw) {
return TapRxController.instances.get(fw);
}
add(src, dst) {
assert.equal(src.fw, this.fw);
this.taps.set(src, dst);
this.taps.add(src, dst);
}

@@ -42,2 +26,9 @@ remove(src, dst) {

}
facerm = (src) => {
const dst = this.taps.list(src);
for (const { rx } of dst) {
rx.end();
}
this.detachIfIdle();
};
detachIfIdle() {

@@ -50,4 +41,9 @@ if (this.taps.size === 0) {

}
pktrx = (src, pkt) => {
const dst = this.taps.list(src);
for (const { rx } of dst) {
rx.push(pkt);
}
};
}
TapRxController.instances = new DefaultWeakMap((fw) => new TapRxController(fw));
/**

@@ -62,14 +58,3 @@ * Create a secondary face by tapping on a primary face.

export class TapFace {
constructor(face) {
this.face = face;
this.rx = pushable();
this.tx = async (iterable) => {
for await (const pkt of iterable) {
this.face.send(pkt);
}
this.ctrl.remove(this.face, this);
};
this.ctrl = TapRxController.lookup(face.fw);
this.ctrl.add(this.face, this);
}
face;
get attributes() {

@@ -81,2 +66,15 @@ return {

}
rx = pushable({ objectMode: true });
ctrl;
constructor(face) {
this.face = face;
this.ctrl = TapRxController.lookup(face.fw);
this.ctrl.add(this.face, this);
}
tx = async (iterable) => {
for await (const pkt of iterable) {
this.face.send(pkt);
}
this.ctrl.remove(this.face, this);
};
}

@@ -83,0 +81,0 @@ (function (TapFace) {

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

import { type FwFace } from "./face";
import type { FwPacket } from "./packet";
import type { FwFace } from "./face.js";
import type { FwPacket } from "./packet.js";
/**

@@ -4,0 +4,0 @@ * Create a secondary face by tapping on a primary face.

@@ -6,30 +6,10 @@ import { Data, Interest, Nack } from "@ndn/packet";

export class Tracer {
static enable(opts = {}) {
return new Tracer(opts);
}
output;
fw;
constructor({ output = console, fw = Forwarder.getDefault(), face = true, prefix = true, ann = true, pkt = true, }) {
this.faceadd = (face) => {
this.output.log(`+Face ${face}`);
};
this.facerm = (face) => {
this.output.log(`-Face ${face}`);
};
this.prefixadd = (face, prefix) => {
this.output.log(`${face} +Prefix ${prefix}`);
};
this.prefixrm = (face, prefix) => {
this.output.log(`${face} -Prefix ${prefix}`);
};
this.annadd = (name) => {
this.output.log(`+Announcement ${name}`);
};
this.annrm = (name) => {
this.output.log(`-Announcement ${name}`);
};
this.pktrx = (face, pkt) => {
this.pkt(face, pkt, ">");
};
this.pkttx = (face, pkt) => {
this.pkt(face, pkt, "<");
};
this.output = output;
this.fw = fw;
/* istanbul ignore else */
if (face) {

@@ -39,3 +19,2 @@ this.fw.on("faceadd", this.faceadd);

}
/* istanbul ignore else */
if (prefix) {

@@ -45,3 +24,2 @@ this.fw.on("prefixadd", this.prefixadd);

}
/* istanbul ignore else */
if (ann) {

@@ -51,3 +29,2 @@ this.fw.on("annadd", this.annadd);

}
/* istanbul ignore else */
if (pkt) {

@@ -58,5 +35,2 @@ this.fw.on("pktrx", this.pktrx);

}
static enable(opts = {}) {
return new Tracer(opts);
}
disable() {

@@ -72,2 +46,26 @@ this.fw.off("faceadd", this.faceadd);

}
faceadd = (face) => {
this.output.log(`+Face ${face}`);
};
facerm = (face) => {
this.output.log(`-Face ${face}`);
};
prefixadd = (face, prefix) => {
this.output.log(`${face} +Prefix ${prefix}`);
};
prefixrm = (face, prefix) => {
this.output.log(`${face} -Prefix ${prefix}`);
};
annadd = (name) => {
this.output.log(`+Announcement ${name}`);
};
annrm = (name) => {
this.output.log(`-Announcement ${name}`);
};
pktrx = (face, pkt) => {
this.pkt(face, pkt, ">");
};
pkttx = (face, pkt) => {
this.pkt(face, pkt, "<");
};
pkt(face, pkt, dir) {

@@ -74,0 +72,0 @@ switch (true) {

@@ -6,30 +6,10 @@ import { Data, Interest, Nack } from "@ndn/packet";

export class Tracer {
static enable(opts = {}) {
return new Tracer(opts);
}
output;
fw;
constructor({ output = console, fw = Forwarder.getDefault(), face = true, prefix = true, ann = true, pkt = true, }) {
this.faceadd = (face) => {
this.output.log(`+Face ${face}`);
};
this.facerm = (face) => {
this.output.log(`-Face ${face}`);
};
this.prefixadd = (face, prefix) => {
this.output.log(`${face} +Prefix ${prefix}`);
};
this.prefixrm = (face, prefix) => {
this.output.log(`${face} -Prefix ${prefix}`);
};
this.annadd = (name) => {
this.output.log(`+Announcement ${name}`);
};
this.annrm = (name) => {
this.output.log(`-Announcement ${name}`);
};
this.pktrx = (face, pkt) => {
this.pkt(face, pkt, ">");
};
this.pkttx = (face, pkt) => {
this.pkt(face, pkt, "<");
};
this.output = output;
this.fw = fw;
/* istanbul ignore else */
if (face) {

@@ -39,3 +19,2 @@ this.fw.on("faceadd", this.faceadd);

}
/* istanbul ignore else */
if (prefix) {

@@ -45,3 +24,2 @@ this.fw.on("prefixadd", this.prefixadd);

}
/* istanbul ignore else */
if (ann) {

@@ -51,3 +29,2 @@ this.fw.on("annadd", this.annadd);

}
/* istanbul ignore else */
if (pkt) {

@@ -58,5 +35,2 @@ this.fw.on("pktrx", this.pktrx);

}
static enable(opts = {}) {
return new Tracer(opts);
}
disable() {

@@ -72,2 +46,26 @@ this.fw.off("faceadd", this.faceadd);

}
faceadd = (face) => {
this.output.log(`+Face ${face}`);
};
facerm = (face) => {
this.output.log(`-Face ${face}`);
};
prefixadd = (face, prefix) => {
this.output.log(`${face} +Prefix ${prefix}`);
};
prefixrm = (face, prefix) => {
this.output.log(`${face} -Prefix ${prefix}`);
};
annadd = (name) => {
this.output.log(`+Announcement ${name}`);
};
annrm = (name) => {
this.output.log(`-Announcement ${name}`);
};
pktrx = (face, pkt) => {
this.pkt(face, pkt, ">");
};
pkttx = (face, pkt) => {
this.pkt(face, pkt, "<");
};
pkt(face, pkt, dir) {

@@ -74,0 +72,0 @@ switch (true) {

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

import { Forwarder } from "./forwarder";
import { Forwarder } from "./forwarder.js";
/** Print trace logs from Forwarder events. */

@@ -3,0 +3,0 @@ export declare class Tracer {

{
"name": "@ndn/fw",
"version": "0.0.20220501",
"version": "0.0.20230121",
"description": "NDNts: Forwarding Plane",

@@ -25,15 +25,14 @@ "keywords": [

"dependencies": {
"@ndn/packet": "0.0.20220501",
"@ndn/util": "0.0.20220501",
"@ndn/packet": "0.0.20230121",
"@ndn/util": "0.0.20230121",
"@types/retry": "^0.12.2",
"hirestime": "^6.1.0",
"it-pushable": "^2.0.1",
"mnemonist": "^0.39.1",
"hirestime": "^7.0.3",
"it-pushable": "^3.1.2",
"mnemonist": "^0.39.5",
"retry": "^0.13.1",
"streaming-iterables": "^7.0.2",
"tslib": "^2.4.0",
"streaming-iterables": "^7.1.0",
"tslib": "^2.4.1",
"typed-emitter": "^2.1.0"
},
"types": "lib/mod.d.ts",
"readme": "# @ndn/fw\n\nThis package is part of [NDNts](https://yoursunny.com/p/NDNts/), Named Data Networking libraries for the modern web.\n\nThis package implements the forwarding plane, the central piece of NDN stack.\nIt exports a **Forwarder** type that represents the forwarding plane, and a **FwFace** type that represents a *face* attached to the forwarding plane.\n\n## Concepts\n\nYou may be wondering: why there's a forwarding plane in my application?\nThe main purpose is to demultiplex incoming packets.\nSuppose a producer application can serve multiple kinds of data, the forwarding plane can dispatch incoming Interests of each kind of data to the correct Interest handler function in the application, so that the application does not perform this dispatching itself.\n\nThis leads to our definition of the *face*: **a face is a duplex stream of packets**.\nIt could be a connection to another network node or standalone forwarder, as implemented in `@ndn/l3face` package.\nIt could also be a part of application logic, as implemented in `@ndn/endpoint` package.\nCreating a `FwFace` for application logic is relatively cheap: if you need to receive different kinds of packets in separate callback functions, you should create one face per callback function, instead of sharing the same face and attempting to dispatch packets yourself.\n\nA *packet* transmitted or received on an `FwFace` is typically an Interest or a Data.\nFrom application logic, it is possible to associate arbitrary metadata, called a *token*, on an outgoing Interest, and receive them back on the corresponding Data.\nYou can also send a `CancelInterest` command to cancel a pending Interest, and receive a `RejectInterest` notice when the Interest is canceled or has expired.\nObviously, these tokens and commands are not encodable, so they are only available for communication between application logic and the forwarding plane, but cannot appear beyond the NDNts application.\n\n## Forwarding Behavior\n\nIt's sad but NDN does not have a formal forwarding behavior specification.\nThis package implements a simplified version of NDN forwarding behavior specified in [NDN-LAN dissertation](https://hdl.handle.net/10150/625652) chapter 3.\nThe main differences from a full forwarder include:\n\n* Forwarding strategy is dumb.\n* No Interest aggregation.\n* No Content Store (CS).\n * If your application needs data packet caching, use `@ndn/repo` package.\n* No Nack generation or processing.\n* Limited forwarding hint processing:\n * Only the first delegation name is considered. Others are ignored.\n * If the first delegation name is a prefix of one of the configured node names, FIB lookup uses the Interest name; otherwise, FIB lookup uses the first delegation name.\n * Forwarding hint is not stripped even if it matches a configured node name.\n\nThese are subject to change.\n"
"types": "lib/mod.d.ts"
}

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