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

@ndn/l3face

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

Comparing version 0.0.20191223-beta.1 to 0.0.20200606

53

lib/l3face.d.ts

@@ -1,23 +0,21 @@

/// <reference types="node" />
import { LpService } from "@ndn/lp";
import { Data, Interest } from "@ndn/packet";
import { EventEmitter } from "events";
import StrictEventEmitter from "strict-event-emitter-types";
import { Forwarder, FwFace } from "@ndn/fw";
import { LpService, NumericPitToken } from "@ndn/lp";
import TypedEmitter from "typed-emitter";
import { Transport } from "./mod";
declare type Packet = Interest | Data;
declare type Packet = LpService.L3Pkt;
interface Events {
/** Emitted upon face state change. */
state: L3Face.State;
state: (state: L3Face.State) => void;
/** Emitted upon state becomes UP. */
up: void;
up: () => void;
/** Emitted upon state becomes DOWN. */
down: Error;
down: (err: Error) => void;
/** Emitted upon state becomes CLOSED. */
close: void;
close: () => void;
/** Emitted upon RX decoding error. */
rxerror: L3Face.RxError;
rxerror: (err: L3Face.RxError) => void;
/** Emitted upon TX preparation error. */
txerror: L3Face.TxError;
txerror: (err: L3Face.TxError) => void;
}
declare const L3Face_base: new () => StrictEventEmitter<EventEmitter, Events, Events, "addEventListener" | "removeEventListener", "on" | "addListener" | "removeListener" | "once" | "emit">;
declare const L3Face_base: new () => TypedEmitter<Events>;
/** Network layer face for sending and receiving L3 packets. */

@@ -27,2 +25,3 @@ export declare class L3Face extends L3Face_base {

readonly lp: LpService;
readonly numericPitToken: NumericPitToken;
readonly rx: AsyncIterable<Packet>;

@@ -32,7 +31,5 @@ get state(): L3Face.State;

private state_;
constructor(transport: Transport, attributes?: L3Face.Attributes);
makeRx(): AsyncGenerator<Packet, void, undefined>;
private decode;
constructor(transport: Transport, attributes?: L3Face.Attributes, lpOptions?: LpService.Options);
private makeRx;
tx: (iterable: AsyncIterable<Packet>) => Promise<void>;
private encode;
private txImpl;

@@ -51,11 +48,19 @@ private reopenTransport;

}
class RxError extends Error {
packet: Uint8Array;
constructor(inner: Error, packet: Uint8Array);
type RxError = LpService.RxError;
type TxError = LpService.TxError;
interface CreateFaceOptions {
fw?: Forwarder;
l3?: Attributes;
lp?: LpService.Options;
}
class TxError extends Error {
packet: Packet;
constructor(inner: Error, packet: Packet);
}
/**
* A function to create a transport then add to forwarder.
* First parameter is CreateFaceOptions.
* Subsequent parameters are passed to Transport.connect() function.
* Returns FwFace.
*/
type CreateFaceFunc<R extends Transport | Transport[], C extends (...args: any) => Promise<R>> = <U extends any[] = C extends (...args: infer P) => any ? P : never>(opts: CreateFaceOptions, ...args: U) => Promise<R extends Transport ? FwFace : FwFace[]>;
function makeCreateFace<C extends (...args: any) => Promise<Transport>>(createTransport: C): CreateFaceFunc<Transport, C>;
function makeCreateFace<C extends (...args: any) => Promise<Transport[]>>(createTransports: C): CreateFaceFunc<Transport[], C>;
}
export {};

@@ -1,29 +0,26 @@

import { LpService } from "@ndn/lp";
import { Data, Interest, LLSign, TT } from "@ndn/packet";
import { Encoder, printTT, toHex } from "@ndn/tlv";
/// #if false
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const { __importDefault } = require("tslib");
/// #endif
import { Forwarder, InterestToken } from "@ndn/fw";
import { LpService, NumericPitToken, PitToken } from "@ndn/lp";
import { Interest } from "@ndn/packet";
import { EventEmitter } from "events";
import { filter, map, pipeline } from "streaming-iterables";
/// #if false
const { filter, pipeline, tap } = require("streaming-iterables");
/*
/// #else
import { filter, pipeline, tap } from "streaming-iterables";
/// #endif
/// #if false
*/
/// #endif
const REOPENED = Symbol("L3Face.REOPENED");
/** Network layer face for sending and receiving L3 packets. */
export class L3Face extends EventEmitter {
constructor(transport, attributes = {}) {
constructor(transport, attributes = {}, lpOptions = {}) {
super();
this.lp = new LpService();
this.numericPitToken = new NumericPitToken();
this.state_ = L3Face.State.UP;
this.decode = ({ type, decoder, tlv }) => {
try {
switch (type) {
case TT.Interest:
return decoder.decode(Interest);
case TT.Data:
return decoder.decode(Data);
default:
throw new Error(`TLV-TYPE ${printTT(type)} cannot appear at top level`);
}
}
catch (err) {
this.emit("rxerror", new L3Face.RxError(err, tlv));
}
return undefined;
};
this.tx = async (iterable) => {

@@ -35,12 +32,2 @@ await this.txImpl(iterable);

};
this.encode = async (packet) => {
try {
await packet[LLSign.PROCESS]();
}
catch (err) {
this.emit("txerror", new L3Face.TxError(err, packet));
return undefined;
}
return Encoder.encode(packet);
};
this.transport = transport;

@@ -52,2 +39,3 @@ this.attributes = {

};
this.lp = new LpService(lpOptions);
this.rx = this.makeRx();

@@ -60,3 +48,16 @@ this.rx.return = undefined;

while (this.state_ !== L3Face.State.CLOSED) {
yield* pipeline(() => this.transport.rx, this.lp.rx, map(this.decode), filter((pkt) => !!pkt));
yield* pipeline(() => this.transport.rx, this.lp.rx, filter((pkt) => {
if (pkt instanceof LpService.RxError) {
this.emit("rxerror", pkt);
return false;
}
return true;
}), tap((pkt) => {
if (pkt instanceof Interest) {
InterestToken.set(pkt, PitToken.get(pkt));
}
else {
InterestToken.set(pkt, this.numericPitToken.get(pkt));
}
}));
await Promise.race([

@@ -69,3 +70,11 @@ new Promise((r) => this.once("up", r)),

async txImpl(iterable) {
const iterator = iterable[Symbol.asyncIterator]();
const iterator = pipeline(() => iterable, tap((pkt) => {
const token = InterestToken.get(pkt);
if (typeof token === "number") {
this.numericPitToken.set(pkt, token);
}
else if (token instanceof Uint8Array) {
PitToken.set(pkt, token);
}
}), this.lp.tx)[Symbol.asyncIterator]();
const transportTx = (async function* () {

@@ -77,10 +86,11 @@ while (true) {

}
const wire = await this.encode(value);
if (!wire) {
continue;
if (value instanceof LpService.TxError) {
this.emit("txerror", value);
}
yield wire;
else {
yield value;
}
}
}).bind(this);
while (true) {
for (;;) {
try {

@@ -96,3 +106,3 @@ await this.transport.tx(transportTx());

const reopenPromise = this.reopenTransport();
while (true) {
for (;;) {
const res = await Promise.race([

@@ -118,3 +128,3 @@ reopenPromise,

}
catch (err) {
catch {
// reopen error, try again

@@ -133,3 +143,3 @@ continue;

/* istanbul ignore next */
return _a = this.attributes.describe, (_a !== null && _a !== void 0 ? _a : `L3Face(${this.transport})`);
return (_a = this.attributes.describe) !== null && _a !== void 0 ? _a : `L3Face(${this.transport})`;
}

@@ -144,16 +154,11 @@ }

})(State = L3Face.State || (L3Face.State = {}));
class RxError extends Error {
constructor(inner, packet) {
super(`${inner.message} ${toHex(packet)}`);
this.packet = packet;
}
function makeCreateFace(createTransport) {
return async (opts, ...args) => {
const created = await createTransport(...args);
const { fw = Forwarder.getDefault(), l3, lp, } = opts;
const makeFace = (transport) => fw.addFace(new L3Face(transport, l3, lp));
return Array.isArray(created) ? created.map(makeFace) : makeFace(created);
};
}
L3Face.RxError = RxError;
class TxError extends Error {
constructor(inner, packet) {
super(`${inner.message} ${packet.name}`);
this.packet = packet;
}
}
L3Face.TxError = TxError;
L3Face.makeCreateFace = makeCreateFace;
})(L3Face || (L3Face = {}));

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

@@ -0,0 +0,0 @@ /// <reference types="node" />

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

/// #if false
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const { __importDefault } = require("tslib");
/// #endif
import { Decoder } from "@ndn/tlv";
/// #if false
const { fromStream, writeToStream } = require("streaming-iterables");
/*
/// #else
import { fromStream, writeToStream } from "streaming-iterables";
/// #endif
/// #if false
*/
/// #endif
export async function* rxFromPacketIterable(iterable) {

@@ -10,3 +23,3 @@ for await (const pkt of iterable) {

}
catch (err) {
catch {
continue;

@@ -21,3 +34,3 @@ }

}
catch (err) { }
catch { }
}

@@ -40,3 +53,3 @@ export async function* rxFromStream(conn) {

}
catch (err) {
catch {
break;

@@ -43,0 +56,0 @@ }

@@ -0,0 +0,0 @@ /// <reference types="node" />

@@ -19,2 +19,3 @@ import { Decoder } from "@ndn/tlv";

local?: boolean;
multicast?: boolean;
}

@@ -21,0 +22,0 @@ /** RX iterable for incoming packets. */

@@ -12,3 +12,3 @@ /**

/* istanbul ignore next */
return Promise.reject("reopen not supported");
return Promise.reject(new Error("reopen not supported"));
}

@@ -18,4 +18,4 @@ toString() {

/* istanbul ignore next */
return _a = this.attributes.describe, (_a !== null && _a !== void 0 ? _a : this.constructor.name);
return (_a = this.attributes.describe) !== null && _a !== void 0 ? _a : this.constructor.name;
}
}
{
"name": "@ndn/l3face",
"version": "0.0.20191223-beta.1",
"version": "0.0.20200606",
"description": "NDNts: Network Layer Face",

@@ -24,10 +24,11 @@ "keywords": [

"dependencies": {
"@ndn/lp": "0.0.20191223-beta.1",
"@ndn/packet": "0.0.20191223-beta.1",
"@ndn/tlv": "0.0.20191223-beta.1",
"@ndn/fw": "0.0.20200606",
"@ndn/lp": "0.0.20200606",
"@ndn/packet": "0.0.20200606",
"@ndn/tlv": "0.0.20200606",
"it-pushable": "^1.4.0",
"streaming-iterables": "^4.1.1",
"strict-event-emitter-types": "^2.0.0",
"tslib": "*"
"streaming-iterables": "^4.1.2",
"tslib": "*",
"typed-emitter": "^1.2.0"
}
}
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