@ndn/l3face
Advanced tools
Comparing version 0.0.20210930 to 0.0.20220501
@@ -5,9 +5,8 @@ import { __importDefault, __importStar } from "tslib"; | ||
import { Interest } from "@ndn/packet"; | ||
import { Encoder } from "@ndn/tlv"; | ||
import _cjsDefaultImport0 from "abort-controller"; const AbortController = __importDefault(_cjsDefaultImport0).default; | ||
import _cjsDefaultImport1 from "abortable-iterator"; const abortable = __importDefault(_cjsDefaultImport1).default; const { AbortError: IteratorAbortError } = __importStar(_cjsDefaultImport1); | ||
import _cjsDefaultImport2 from "it-pushable"; const pushable = __importDefault(_cjsDefaultImport2).default; | ||
import { asDataView } from "@ndn/util"; | ||
import { abortableSource, AbortError as IteratorAbortError } from "abortable-iterator"; | ||
import { pushable } from "it-pushable"; | ||
import { EventEmitter } from "events"; | ||
import _cjsDefaultImport3 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport3).default; | ||
import _cjsDefaultImport4 from "retry"; const retry = __importDefault(_cjsDefaultImport4).default; | ||
import { pEvent } from "p-event"; | ||
import _cjsDefaultImport0 from "retry"; const retry = __importDefault(_cjsDefaultImport0).default; | ||
import { consume, filter, map, pipeline } from "streaming-iterables"; | ||
@@ -20,3 +19,3 @@ import { Transport } from "./transport_browser.js"; | ||
this.transport = transport; | ||
this.wireTokenPrefix = Math.floor(Math.random() * 0x10000); | ||
this.wireTokenPrefix = Math.trunc(Math.random() * 0x10000); | ||
this.state_ = L3Face.State.UP; | ||
@@ -33,8 +32,7 @@ this.rxSources = pushable(); | ||
const onStateChange = pEvent(this, "state"); | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
void onStateChange.then(() => abort.abort()); | ||
try { | ||
const txSource = abortable(txSourceIterator, abort.signal); | ||
const txSource = abortableSource(txSourceIterator, abort.signal); | ||
if (this.state === L3Face.State.UP) { | ||
this.rxSources.push(abortable(this.transport.rx, abort.signal)); | ||
this.rxSources.push(abortableSource(this.transport.rx, abort.signal)); | ||
await this.transport.tx(txSource); | ||
@@ -67,3 +65,3 @@ } | ||
}; | ||
this.lp = new LpService(lpOptions); | ||
this.lp = new LpService(lpOptions, transport); | ||
this.rx = this.makeRx(); | ||
@@ -123,3 +121,3 @@ } | ||
else if (wireToken?.length === 6) { | ||
const dv = Encoder.asDataView(wireToken); | ||
const dv = asDataView(wireToken); | ||
if (dv.getUint16(0) === this.wireTokenPrefix) { | ||
@@ -137,3 +135,3 @@ internalToken = dv.getUint32(2); | ||
wireToken = new Uint8Array(6); | ||
const dv = Encoder.asDataView(wireToken); | ||
const dv = asDataView(wireToken); | ||
dv.setUint16(0, this.wireTokenPrefix); | ||
@@ -192,6 +190,7 @@ dv.setUint32(2, internalToken); | ||
const created = await createTransport(...args); | ||
const { fw = Forwarder.getDefault(), l3, lp, callback, } = opts; | ||
const { fw = Forwarder.getDefault(), addRoutes, l3, lp, callback, } = opts; | ||
const makeFace = (transport) => { | ||
const l3face = new L3Face(transport, l3, lp); | ||
const l3face = new L3Face(transport, { advertiseFrom: false, ...l3 }, lp); | ||
const fwFace = fw.addFace(l3face); | ||
processAddRoutes(fwFace, addRoutes); | ||
callback?.(transport, l3face, fwFace); | ||
@@ -204,2 +203,8 @@ return fwFace; | ||
L3Face.makeCreateFace = makeCreateFace; | ||
function processAddRoutes(fwFace, addRoutes = ["/"]) { | ||
for (const routeName of addRoutes) { | ||
fwFace.addRoute(routeName); | ||
} | ||
} | ||
L3Face.processAddRoutes = processAddRoutes; | ||
})(L3Face || (L3Face = {})); |
@@ -5,9 +5,8 @@ import { __importDefault, __importStar } from "tslib"; | ||
import { Interest } from "@ndn/packet"; | ||
import { Encoder } from "@ndn/tlv"; | ||
import _cjsDefaultImport0 from "abort-controller"; const AbortController = __importDefault(_cjsDefaultImport0).default; | ||
import _cjsDefaultImport1 from "abortable-iterator"; const abortable = __importDefault(_cjsDefaultImport1).default; const { AbortError: IteratorAbortError } = __importStar(_cjsDefaultImport1); | ||
import _cjsDefaultImport2 from "it-pushable"; const pushable = __importDefault(_cjsDefaultImport2).default; | ||
import { asDataView } from "@ndn/util"; | ||
import { abortableSource, AbortError as IteratorAbortError } from "abortable-iterator"; | ||
import { pushable } from "it-pushable"; | ||
import { EventEmitter } from "node:events"; | ||
import _cjsDefaultImport3 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport3).default; | ||
import _cjsDefaultImport4 from "retry"; const retry = __importDefault(_cjsDefaultImport4).default; | ||
import { pEvent } from "p-event"; | ||
import _cjsDefaultImport0 from "retry"; const retry = __importDefault(_cjsDefaultImport0).default; | ||
import { consume, filter, map, pipeline } from "streaming-iterables"; | ||
@@ -20,3 +19,3 @@ import { Transport } from "./transport_node.js"; | ||
this.transport = transport; | ||
this.wireTokenPrefix = Math.floor(Math.random() * 0x10000); | ||
this.wireTokenPrefix = Math.trunc(Math.random() * 0x10000); | ||
this.state_ = L3Face.State.UP; | ||
@@ -33,8 +32,7 @@ this.rxSources = pushable(); | ||
const onStateChange = pEvent(this, "state"); | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
void onStateChange.then(() => abort.abort()); | ||
try { | ||
const txSource = abortable(txSourceIterator, abort.signal); | ||
const txSource = abortableSource(txSourceIterator, abort.signal); | ||
if (this.state === L3Face.State.UP) { | ||
this.rxSources.push(abortable(this.transport.rx, abort.signal)); | ||
this.rxSources.push(abortableSource(this.transport.rx, abort.signal)); | ||
await this.transport.tx(txSource); | ||
@@ -67,3 +65,3 @@ } | ||
}; | ||
this.lp = new LpService(lpOptions); | ||
this.lp = new LpService(lpOptions, transport); | ||
this.rx = this.makeRx(); | ||
@@ -123,3 +121,3 @@ } | ||
else if (wireToken?.length === 6) { | ||
const dv = Encoder.asDataView(wireToken); | ||
const dv = asDataView(wireToken); | ||
if (dv.getUint16(0) === this.wireTokenPrefix) { | ||
@@ -137,3 +135,3 @@ internalToken = dv.getUint32(2); | ||
wireToken = new Uint8Array(6); | ||
const dv = Encoder.asDataView(wireToken); | ||
const dv = asDataView(wireToken); | ||
dv.setUint16(0, this.wireTokenPrefix); | ||
@@ -192,6 +190,7 @@ dv.setUint32(2, internalToken); | ||
const created = await createTransport(...args); | ||
const { fw = Forwarder.getDefault(), l3, lp, callback, } = opts; | ||
const { fw = Forwarder.getDefault(), addRoutes, l3, lp, callback, } = opts; | ||
const makeFace = (transport) => { | ||
const l3face = new L3Face(transport, l3, lp); | ||
const l3face = new L3Face(transport, { advertiseFrom: false, ...l3 }, lp); | ||
const fwFace = fw.addFace(l3face); | ||
processAddRoutes(fwFace, addRoutes); | ||
callback?.(transport, l3face, fwFace); | ||
@@ -204,2 +203,8 @@ return fwFace; | ||
L3Face.makeCreateFace = makeCreateFace; | ||
function processAddRoutes(fwFace, addRoutes = ["/"]) { | ||
for (const routeName of addRoutes) { | ||
fwFace.addRoute(routeName); | ||
} | ||
} | ||
L3Face.processAddRoutes = processAddRoutes; | ||
})(L3Face || (L3Face = {})); |
@@ -1,6 +0,7 @@ | ||
import { Forwarder, FwFace, FwPacket } from "@ndn/fw"; | ||
import { type FwFace, Forwarder, FwPacket } from "@ndn/fw"; | ||
import { LpService } from "@ndn/lp"; | ||
import { type NameLike } from "@ndn/packet"; | ||
import type TypedEmitter from "typed-emitter"; | ||
import { Transport } from "./transport"; | ||
interface Events { | ||
declare type Events = { | ||
/** Emitted upon face state change. */ | ||
@@ -18,3 +19,3 @@ state: (state: L3Face.State) => void; | ||
txerror: (err: L3Face.TxError) => void; | ||
} | ||
}; | ||
declare const L3Face_base: new () => TypedEmitter<Events>; | ||
@@ -48,2 +49,3 @@ /** Network layer face for sending and receiving L3 packets. */ | ||
interface Attributes extends Transport.Attributes { | ||
/** Whether to readvertise registered routes. */ | ||
advertiseFrom?: boolean; | ||
@@ -60,3 +62,8 @@ } | ||
fw?: Forwarder; | ||
/** L3Face attributes. */ | ||
/** Routes to be added on the created face. Default is ["/"]. */ | ||
addRoutes?: NameLike[]; | ||
/** | ||
* L3Face attributes. | ||
* l3.advertiseFrom defaults to false in createFace function. | ||
*/ | ||
l3?: Attributes; | ||
@@ -79,3 +86,4 @@ /** NDNLP service options. */ | ||
function makeCreateFace<C extends (...args: any[]) => Promise<Transport | Transport[]>>(createTransport: C): CreateFaceFunc<C extends (...args: any[]) => Promise<infer R> ? R : never, Parameters<C>>; | ||
function processAddRoutes(fwFace: FwFace, addRoutes?: readonly NameLike[]): void; | ||
} | ||
export {}; |
import { Decoder } from "@ndn/tlv"; | ||
import { safe } from "./safe_browser.js"; | ||
import { safeIter } from "@ndn/util"; | ||
export async function* rxFromPacketIterable(iterable) { | ||
for await (const pkt of safe(iterable)) { | ||
for await (const pkt of safeIter(iterable)) { | ||
const decoder = new Decoder(pkt); | ||
@@ -6,0 +6,0 @@ let tlv; |
import { Decoder } from "@ndn/tlv"; | ||
import { safe } from "./safe_node.js"; | ||
import { safeIter } from "@ndn/util"; | ||
export async function* rxFromPacketIterable(iterable) { | ||
for await (const pkt of safe(iterable)) { | ||
for await (const pkt of safeIter(iterable)) { | ||
const decoder = new Decoder(pkt); | ||
@@ -6,0 +6,0 @@ let tlv; |
@@ -1,9 +0,8 @@ | ||
import { __importDefault, __importStar } from "tslib"; | ||
import { Decoder } from "@ndn/tlv"; | ||
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default; | ||
import { fromStream, writeToStream } from "streaming-iterables"; | ||
import { safe } from "./safe_browser.js"; | ||
import { safeIter } from "@ndn/util"; | ||
import { pEvent } from "p-event"; | ||
import { writeToStream } from "streaming-iterables"; | ||
export async function* rxFromStream(conn) { | ||
let leftover = Buffer.alloc(0); | ||
for await (const chunk of safe(fromStream(conn))) { | ||
for await (const chunk of safeIter(conn)) { | ||
if (leftover.length > 0) { | ||
@@ -10,0 +9,0 @@ leftover = Buffer.concat([leftover, chunk], leftover.length + chunk.length); |
@@ -1,9 +0,8 @@ | ||
import { __importDefault, __importStar } from "tslib"; | ||
import { Decoder } from "@ndn/tlv"; | ||
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default; | ||
import { fromStream, writeToStream } from "streaming-iterables"; | ||
import { safe } from "./safe_node.js"; | ||
import { safeIter } from "@ndn/util"; | ||
import { pEvent } from "p-event"; | ||
import { writeToStream } from "streaming-iterables"; | ||
export async function* rxFromStream(conn) { | ||
let leftover = Buffer.alloc(0); | ||
for await (const chunk of safe(fromStream(conn))) { | ||
for await (const chunk of safeIter(conn)) { | ||
if (leftover.length > 0) { | ||
@@ -10,0 +9,0 @@ leftover = Buffer.concat([leftover, chunk], leftover.length + chunk.length); |
@@ -10,2 +10,3 @@ import { rxFromStream, txToStream } from "./rxtx-stream_browser.js"; | ||
} | ||
get mtu() { return Infinity; } | ||
} |
@@ -10,2 +10,3 @@ import { rxFromStream, txToStream } from "./rxtx-stream_node.js"; | ||
} | ||
get mtu() { return Infinity; } | ||
} |
@@ -8,2 +8,3 @@ /// <reference types="node" /> | ||
constructor(conn: NodeJS.ReadWriteStream, attrs?: Record<string, any>); | ||
get mtu(): number; | ||
} |
@@ -0,1 +1,2 @@ | ||
const DEFAULT_MTU = 1200; | ||
/** | ||
@@ -11,2 +12,7 @@ * Low-level transport. | ||
/** | ||
* Return the transport MTU, if known. | ||
* The transport should be able to send TLV structure of up to this size. | ||
*/ | ||
get mtu() { return DEFAULT_MTU; } | ||
/** | ||
* Reopen the transport after it has failed. | ||
@@ -13,0 +19,0 @@ * @returns the same transport or a new transport after it has been reconnected. |
@@ -0,1 +1,2 @@ | ||
const DEFAULT_MTU = 1200; | ||
/** | ||
@@ -11,2 +12,7 @@ * Low-level transport. | ||
/** | ||
* Return the transport MTU, if known. | ||
* The transport should be able to send TLV structure of up to this size. | ||
*/ | ||
get mtu() { return DEFAULT_MTU; } | ||
/** | ||
* Reopen the transport after it has failed. | ||
@@ -13,0 +19,0 @@ * @returns the same transport or a new transport after it has been reconnected. |
@@ -13,2 +13,7 @@ import type { Decoder } from "@ndn/tlv"; | ||
/** | ||
* Return the transport MTU, if known. | ||
* The transport should be able to send TLV structure of up to this size. | ||
*/ | ||
get mtu(): number; | ||
/** | ||
* Reopen the transport after it has failed. | ||
@@ -15,0 +20,0 @@ * @returns the same transport or a new transport after it has been reconnected. |
{ | ||
"name": "@ndn/l3face", | ||
"version": "0.0.20210930", | ||
"version": "0.0.20220501", | ||
"description": "NDNts: Network Layer Face", | ||
@@ -25,16 +25,17 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/fw": "0.0.20210930", | ||
"@ndn/lp": "0.0.20210930", | ||
"@ndn/packet": "0.0.20210930", | ||
"@ndn/tlv": "0.0.20210930", | ||
"abort-controller": "^3.0.0", | ||
"abortable-iterator": "^3.0.0", | ||
"it-pushable": "^1.4.2", | ||
"p-event": "^4.2.0", | ||
"@ndn/fw": "0.0.20220501", | ||
"@ndn/lp": "0.0.20220501", | ||
"@ndn/packet": "0.0.20220501", | ||
"@ndn/tlv": "0.0.20220501", | ||
"@ndn/util": "0.0.20220501", | ||
"abortable-iterator": "^4.0.2", | ||
"it-pushable": "^2.0.1", | ||
"p-event": "^5.0.1", | ||
"retry": "^0.13.1", | ||
"streaming-iterables": "^6.0.0", | ||
"tslib": "^2.3.1", | ||
"typed-emitter": "^1.3.1" | ||
"streaming-iterables": "^7.0.2", | ||
"tslib": "^2.4.0", | ||
"typed-emitter": "^2.1.0" | ||
}, | ||
"types": "lib/mod.d.ts" | ||
"types": "lib/mod.d.ts", | ||
"readme": "# @ndn/l3face\n\nThis package is part of [NDNts](https://yoursunny.com/p/NDNts/), Named Data Networking libraries for the modern web.\n\nThis package implements network layer face and transport base types.\nSee `@ndn/node-transport` package for more explanation and examples.\n" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31129
805
21
+ Added@ndn/util@0.0.20220501
+ Added@ndn/fw@0.0.20220501(transitive)
+ Added@ndn/lp@0.0.20220501(transitive)
+ Added@ndn/packet@0.0.20220501(transitive)
+ Added@ndn/tlv@0.0.20220501(transitive)
+ Added@ndn/util@0.0.20220501(transitive)
+ Added@types/minimalistic-assert@1.0.3(transitive)
+ Addedabortable-iterator@4.0.3(transitive)
+ Addedget-iterator@2.0.1(transitive)
+ Addedit-pushable@2.0.2(transitive)
+ Addedit-stream-types@1.0.5(transitive)
+ Addedmnemonist@0.39.8(transitive)
+ Addedp-event@5.0.1(transitive)
+ Addedp-timeout@5.1.0(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedstreaming-iterables@7.1.0(transitive)
+ Addedtyped-emitter@2.1.0(transitive)
- Removedabort-controller@^3.0.0
- Removed@ndn/fw@0.0.20210930(transitive)
- Removed@ndn/lp@0.0.20210930(transitive)
- Removed@ndn/packet@0.0.20210930(transitive)
- Removed@ndn/tlv@0.0.20210930(transitive)
- Removedabort-controller@3.0.0(transitive)
- Removedabortable-iterator@3.0.2(transitive)
- Removedevent-target-shim@5.0.1(transitive)
- Removedfast-fifo@1.3.2(transitive)
- Removedit-pushable@1.4.2(transitive)
- Removedmnemonist@0.38.5(transitive)
- Removedp-defer@3.0.0(transitive)
- Removedp-event@4.2.0(transitive)
- Removedp-fifo@1.0.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedstreaming-iterables@6.2.0(transitive)
- Removedtyped-emitter@1.4.0(transitive)
Updated@ndn/fw@0.0.20220501
Updated@ndn/lp@0.0.20220501
Updated@ndn/packet@0.0.20220501
Updated@ndn/tlv@0.0.20220501
Updatedabortable-iterator@^4.0.2
Updatedit-pushable@^2.0.1
Updatedp-event@^5.0.1
Updatedstreaming-iterables@^7.0.2
Updatedtslib@^2.4.0
Updatedtyped-emitter@^2.1.0