@ndn/l3face
Advanced tools
Comparing version 0.0.20220501 to 0.0.20230121
import { __importDefault, __importStar } from "tslib"; | ||
import { EventEmitter } from "events"; | ||
import { Forwarder, FwPacket } from "@ndn/fw"; | ||
@@ -8,4 +9,2 @@ import { LpService } from "@ndn/lp"; | ||
import { pushable } from "it-pushable"; | ||
import { EventEmitter } from "events"; | ||
import { pEvent } from "p-event"; | ||
import _cjsDefaultImport0 from "retry"; const retry = __importDefault(_cjsDefaultImport0).default; | ||
@@ -16,52 +15,7 @@ import { consume, filter, map, pipeline } from "streaming-iterables"; | ||
export class L3Face extends EventEmitter { | ||
constructor(transport, attributes = {}, lpOptions = {}) { | ||
super(); | ||
this.transport = transport; | ||
this.wireTokenPrefix = Math.trunc(Math.random() * 0x10000); | ||
this.state_ = L3Face.State.UP; | ||
this.rxSources = pushable(); | ||
this.tx = async (iterable) => { | ||
const txSourceIterator = this.txTransform(iterable)[Symbol.asyncIterator](); | ||
txSourceIterator.return = undefined; | ||
while (this.state !== L3Face.State.CLOSED) { | ||
if (this.state === L3Face.State.DOWN) { | ||
this.reopenTransport(); | ||
} | ||
const abort = new AbortController(); | ||
const onStateChange = pEvent(this, "state"); | ||
void onStateChange.then(() => abort.abort()); | ||
try { | ||
const txSource = abortableSource(txSourceIterator, abort.signal); | ||
if (this.state === L3Face.State.UP) { | ||
this.rxSources.push(abortableSource(this.transport.rx, abort.signal)); | ||
await this.transport.tx(txSource); | ||
} | ||
else { | ||
await consume(txSource); | ||
} | ||
this.state = L3Face.State.CLOSED; | ||
} | ||
catch (err) { | ||
if (!(err instanceof IteratorAbortError)) { | ||
this.lastError = err; | ||
this.state = L3Face.State.DOWN; | ||
} | ||
} | ||
finally { | ||
abort.abort(); | ||
onStateChange.cancel(); | ||
} | ||
} | ||
this.reopenRetry?.stop(); | ||
this.rxSources.end(); | ||
}; | ||
this.attributes = { | ||
describe: `L3Face(${transport})`, | ||
advertiseFrom: false, | ||
...transport.attributes, | ||
...attributes, | ||
}; | ||
this.lp = new LpService(lpOptions, transport); | ||
this.rx = this.makeRx(); | ||
} | ||
transport; | ||
attributes; | ||
lp; | ||
rx; | ||
wireTokenPrefix = Math.trunc(Math.random() * 0x10000); | ||
get state() { return this.state_; } | ||
@@ -91,2 +45,18 @@ set state(newState) { | ||
} | ||
state_ = L3Face.State.UP; | ||
lastError; | ||
rxSources = pushable({ objectMode: true }); | ||
reopenRetry; | ||
constructor(transport, attributes = {}, lpOptions = {}) { | ||
super(); | ||
this.transport = transport; | ||
this.attributes = { | ||
describe: `L3Face(${transport})`, | ||
advertiseFrom: false, | ||
...transport.attributes, | ||
...attributes, | ||
}; | ||
this.lp = new LpService(lpOptions, transport); | ||
this.rx = this.makeRx(); | ||
} | ||
async *makeRx() { | ||
@@ -149,2 +119,41 @@ for await (const source of this.rxSources) { | ||
} | ||
tx = async (iterable) => { | ||
const txSourceIterator = this.txTransform(iterable)[Symbol.asyncIterator](); | ||
const txSourceIterable = { | ||
[Symbol.asyncIterator]: () => ({ | ||
next: () => txSourceIterator.next(), | ||
}), | ||
}; | ||
while (this.state !== L3Face.State.CLOSED) { | ||
if (this.state === L3Face.State.DOWN) { | ||
this.reopenTransport(); | ||
} | ||
const abort = new AbortController(); | ||
const handleStateChange = () => abort.abort(); | ||
this.once("state", handleStateChange); | ||
try { | ||
const txSource = abortableSource(txSourceIterable, abort.signal); | ||
if (this.state === L3Face.State.UP) { | ||
this.rxSources.push(abortableSource(this.transport.rx, abort.signal)); | ||
await this.transport.tx(txSource); | ||
} | ||
else { | ||
await consume(txSource); | ||
} | ||
this.state = L3Face.State.CLOSED; | ||
} | ||
catch (err) { | ||
if (!(err instanceof IteratorAbortError)) { | ||
this.lastError = err; | ||
this.state = L3Face.State.DOWN; | ||
} | ||
} | ||
finally { | ||
abort.abort(); | ||
this.off("state", handleStateChange); | ||
} | ||
} | ||
this.reopenRetry?.stop(); | ||
this.rxSources.end(); | ||
}; | ||
reopenTransport() { | ||
@@ -151,0 +160,0 @@ this.reopenRetry?.stop(); |
import { __importDefault, __importStar } from "tslib"; | ||
import { EventEmitter } from "node:events"; | ||
import { Forwarder, FwPacket } from "@ndn/fw"; | ||
@@ -8,4 +9,2 @@ import { LpService } from "@ndn/lp"; | ||
import { pushable } from "it-pushable"; | ||
import { EventEmitter } from "node:events"; | ||
import { pEvent } from "p-event"; | ||
import _cjsDefaultImport0 from "retry"; const retry = __importDefault(_cjsDefaultImport0).default; | ||
@@ -16,52 +15,7 @@ import { consume, filter, map, pipeline } from "streaming-iterables"; | ||
export class L3Face extends EventEmitter { | ||
constructor(transport, attributes = {}, lpOptions = {}) { | ||
super(); | ||
this.transport = transport; | ||
this.wireTokenPrefix = Math.trunc(Math.random() * 0x10000); | ||
this.state_ = L3Face.State.UP; | ||
this.rxSources = pushable(); | ||
this.tx = async (iterable) => { | ||
const txSourceIterator = this.txTransform(iterable)[Symbol.asyncIterator](); | ||
txSourceIterator.return = undefined; | ||
while (this.state !== L3Face.State.CLOSED) { | ||
if (this.state === L3Face.State.DOWN) { | ||
this.reopenTransport(); | ||
} | ||
const abort = new AbortController(); | ||
const onStateChange = pEvent(this, "state"); | ||
void onStateChange.then(() => abort.abort()); | ||
try { | ||
const txSource = abortableSource(txSourceIterator, abort.signal); | ||
if (this.state === L3Face.State.UP) { | ||
this.rxSources.push(abortableSource(this.transport.rx, abort.signal)); | ||
await this.transport.tx(txSource); | ||
} | ||
else { | ||
await consume(txSource); | ||
} | ||
this.state = L3Face.State.CLOSED; | ||
} | ||
catch (err) { | ||
if (!(err instanceof IteratorAbortError)) { | ||
this.lastError = err; | ||
this.state = L3Face.State.DOWN; | ||
} | ||
} | ||
finally { | ||
abort.abort(); | ||
onStateChange.cancel(); | ||
} | ||
} | ||
this.reopenRetry?.stop(); | ||
this.rxSources.end(); | ||
}; | ||
this.attributes = { | ||
describe: `L3Face(${transport})`, | ||
advertiseFrom: false, | ||
...transport.attributes, | ||
...attributes, | ||
}; | ||
this.lp = new LpService(lpOptions, transport); | ||
this.rx = this.makeRx(); | ||
} | ||
transport; | ||
attributes; | ||
lp; | ||
rx; | ||
wireTokenPrefix = Math.trunc(Math.random() * 0x10000); | ||
get state() { return this.state_; } | ||
@@ -91,2 +45,18 @@ set state(newState) { | ||
} | ||
state_ = L3Face.State.UP; | ||
lastError; | ||
rxSources = pushable({ objectMode: true }); | ||
reopenRetry; | ||
constructor(transport, attributes = {}, lpOptions = {}) { | ||
super(); | ||
this.transport = transport; | ||
this.attributes = { | ||
describe: `L3Face(${transport})`, | ||
advertiseFrom: false, | ||
...transport.attributes, | ||
...attributes, | ||
}; | ||
this.lp = new LpService(lpOptions, transport); | ||
this.rx = this.makeRx(); | ||
} | ||
async *makeRx() { | ||
@@ -149,2 +119,41 @@ for await (const source of this.rxSources) { | ||
} | ||
tx = async (iterable) => { | ||
const txSourceIterator = this.txTransform(iterable)[Symbol.asyncIterator](); | ||
const txSourceIterable = { | ||
[Symbol.asyncIterator]: () => ({ | ||
next: () => txSourceIterator.next(), | ||
}), | ||
}; | ||
while (this.state !== L3Face.State.CLOSED) { | ||
if (this.state === L3Face.State.DOWN) { | ||
this.reopenTransport(); | ||
} | ||
const abort = new AbortController(); | ||
const handleStateChange = () => abort.abort(); | ||
this.once("state", handleStateChange); | ||
try { | ||
const txSource = abortableSource(txSourceIterable, abort.signal); | ||
if (this.state === L3Face.State.UP) { | ||
this.rxSources.push(abortableSource(this.transport.rx, abort.signal)); | ||
await this.transport.tx(txSource); | ||
} | ||
else { | ||
await consume(txSource); | ||
} | ||
this.state = L3Face.State.CLOSED; | ||
} | ||
catch (err) { | ||
if (!(err instanceof IteratorAbortError)) { | ||
this.lastError = err; | ||
this.state = L3Face.State.DOWN; | ||
} | ||
} | ||
finally { | ||
abort.abort(); | ||
this.off("state", handleStateChange); | ||
} | ||
} | ||
this.reopenRetry?.stop(); | ||
this.rxSources.end(); | ||
}; | ||
reopenTransport() { | ||
@@ -151,0 +160,0 @@ this.reopenRetry?.stop(); |
@@ -5,4 +5,4 @@ import { type FwFace, Forwarder, FwPacket } from "@ndn/fw"; | ||
import type TypedEmitter from "typed-emitter"; | ||
import { Transport } from "./transport"; | ||
declare type Events = { | ||
import { Transport } from "./transport.js"; | ||
type Events = { | ||
/** Emitted upon face state change. */ | ||
@@ -9,0 +9,0 @@ state: (state: L3Face.State) => void; |
@@ -1,5 +0,5 @@ | ||
export * from "./l3face"; | ||
export * from "./rxtx-iterable"; | ||
export * from "./rxtx-stream"; | ||
export * from "./stream-transport"; | ||
export * from "./transport"; | ||
export * from "./l3face.js"; | ||
export * from "./rxtx-iterable.js"; | ||
export * from "./rxtx-stream.js"; | ||
export * from "./stream-transport.js"; | ||
export * from "./transport.js"; |
@@ -1,2 +0,2 @@ | ||
import type { Transport } from "./transport"; | ||
import type { Transport } from "./transport.js"; | ||
export declare function rxFromPacketIterable(iterable: AsyncIterable<Uint8Array>): Transport.Rx; |
@@ -44,3 +44,2 @@ import { Decoder } from "@ndn/tlv"; | ||
const destroyable = conn; | ||
/* istanbul ignore else */ | ||
if (typeof destroyable.destroy === "function") { | ||
@@ -47,0 +46,0 @@ destroyable.destroy(); |
@@ -44,3 +44,2 @@ import { Decoder } from "@ndn/tlv"; | ||
const destroyable = conn; | ||
/* istanbul ignore else */ | ||
if (typeof destroyable.destroy === "function") { | ||
@@ -47,0 +46,0 @@ destroyable.destroy(); |
/// <reference types="node" /> | ||
import type { Transport } from "./transport"; | ||
import type { Transport } from "./transport.js"; | ||
export declare function rxFromStream(conn: NodeJS.ReadableStream): Transport.Rx; | ||
export declare function txToStream(conn: NodeJS.WritableStream): Transport.Tx; |
@@ -5,2 +5,4 @@ import { rxFromStream, txToStream } from "./rxtx-stream_browser.js"; | ||
export class StreamTransport extends Transport { | ||
rx; | ||
tx; | ||
constructor(conn, attrs = {}) { | ||
@@ -7,0 +9,0 @@ super(attrs); |
@@ -5,2 +5,4 @@ import { rxFromStream, txToStream } from "./rxtx-stream_node.js"; | ||
export class StreamTransport extends Transport { | ||
rx; | ||
tx; | ||
constructor(conn, attrs = {}) { | ||
@@ -7,0 +9,0 @@ super(attrs); |
/// <reference types="node" /> | ||
import { Transport } from "./transport"; | ||
import { Transport } from "./transport.js"; | ||
/** Stream-oriented transport. */ | ||
@@ -4,0 +4,0 @@ export declare class StreamTransport extends Transport { |
@@ -8,2 +8,3 @@ const DEFAULT_MTU = 1200; | ||
export class Transport { | ||
attributes; | ||
constructor(attributes) { | ||
@@ -25,3 +26,3 @@ this.attributes = attributes; | ||
toString() { | ||
/* istanbul ignore next */ | ||
/* c8 ignore next */ | ||
return this.attributes.describe ?? this.constructor.name; | ||
@@ -28,0 +29,0 @@ } |
@@ -8,2 +8,3 @@ const DEFAULT_MTU = 1200; | ||
export class Transport { | ||
attributes; | ||
constructor(attributes) { | ||
@@ -25,3 +26,3 @@ this.attributes = attributes; | ||
toString() { | ||
/* istanbul ignore next */ | ||
/* c8 ignore next */ | ||
return this.attributes.describe ?? this.constructor.name; | ||
@@ -28,0 +29,0 @@ } |
{ | ||
"name": "@ndn/l3face", | ||
"version": "0.0.20220501", | ||
"version": "0.0.20230121", | ||
"description": "NDNts: Network Layer Face", | ||
@@ -25,17 +25,16 @@ "keywords": [ | ||
"dependencies": { | ||
"@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", | ||
"@ndn/fw": "0.0.20230121", | ||
"@ndn/lp": "0.0.20230121", | ||
"@ndn/packet": "0.0.20230121", | ||
"@ndn/tlv": "0.0.20230121", | ||
"@ndn/util": "0.0.20230121", | ||
"abortable-iterator": "^4.0.2", | ||
"it-pushable": "^2.0.1", | ||
"it-pushable": "^3.1.2", | ||
"p-event": "^5.0.1", | ||
"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/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" | ||
"types": "lib/mod.d.ts" | ||
} |
Sorry, the diff of this file is not supported yet
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
827
30863
+ Added@ndn/fw@0.0.20230121(transitive)
+ Added@ndn/lp@0.0.20230121(transitive)
+ Added@ndn/packet@0.0.20230121(transitive)
+ Added@ndn/tlv@0.0.20230121(transitive)
+ Added@ndn/util@0.0.20230121(transitive)
+ Addedhirestime@7.0.4(transitive)
+ Addedit-pushable@3.2.3(transitive)
+ Addedp-defer@4.0.1(transitive)
- Removed@ndn/fw@0.0.20220501(transitive)
- Removed@ndn/lp@0.0.20220501(transitive)
- Removed@ndn/packet@0.0.20220501(transitive)
- Removed@ndn/tlv@0.0.20220501(transitive)
- Removed@ndn/util@0.0.20220501(transitive)
- Removedhirestime@6.1.0(transitive)
- Removedit-pushable@2.0.2(transitive)
Updated@ndn/fw@0.0.20230121
Updated@ndn/lp@0.0.20230121
Updated@ndn/packet@0.0.20230121
Updated@ndn/tlv@0.0.20230121
Updated@ndn/util@0.0.20230121
Updatedit-pushable@^3.1.2
Updatedstreaming-iterables@^7.1.0
Updatedtslib@^2.4.1