@ndn/endpoint
Advanced tools
Comparing version 0.0.20200909 to 0.0.20210203
@@ -0,29 +1,6 @@ | ||
import { __importDefault, __importStar } from "tslib"; | ||
import { CancelInterest, FwPacket } from "@ndn/fw"; | ||
import { Data, Interest } from "@ndn/packet"; | ||
import pushable from "it-pushable"; | ||
import PCancelable from "p-cancelable"; | ||
import _cjsDefaultImport0 from "it-pushable"; const pushable = __importDefault(_cjsDefaultImport0).default; | ||
import { makeRetxGenerator } from "./retx_browser.js"; | ||
function makeModifyInterest(input) { | ||
if (typeof input === "function") { | ||
return input; | ||
} | ||
const { canBePrefix, mustBeFresh, fwHint, lifetime, hopLimit, } = input; | ||
return (interest) => { | ||
if (typeof canBePrefix !== "undefined") { | ||
interest.canBePrefix = canBePrefix; | ||
} | ||
if (typeof mustBeFresh !== "undefined") { | ||
interest.mustBeFresh = mustBeFresh; | ||
} | ||
if (typeof fwHint !== "undefined") { | ||
interest.fwHint = fwHint; | ||
} | ||
if (typeof lifetime !== "undefined") { | ||
interest.lifetime = lifetime; | ||
} | ||
if (typeof hopLimit !== "undefined") { | ||
interest.hopLimit = hopLimit; | ||
} | ||
}; | ||
} | ||
/** Consumer functionality of Endpoint. */ | ||
@@ -34,9 +11,8 @@ export class EndpointConsumer { | ||
const interest = interestInput instanceof Interest ? interestInput : new Interest(interestInput); | ||
const { describe = `consume(${interest.name})`, modifyInterest, retx, verifier, } = { ...this.opts, ...opts }; | ||
if (modifyInterest) { | ||
makeModifyInterest(modifyInterest)(interest); | ||
} | ||
const { describe = `consume(${interest.name})`, modifyInterest, retx, signal, verifier, } = { ...this.opts, ...opts }; | ||
Interest.makeModifyFunc(modifyInterest)(interest); | ||
let nRetx = -1; | ||
const retxGen = makeRetxGenerator(retx)(interest.lifetime)[Symbol.iterator](); | ||
const promise = new PCancelable((resolve, reject, onCancel) => { | ||
const promise = new Promise((resolve, reject) => { | ||
var _a; | ||
const rx = pushable(); | ||
@@ -59,5 +35,11 @@ let timer; | ||
}; | ||
const onabort = () => { | ||
cancelRetx(); | ||
rx.push(new CancelInterest(interest)); | ||
}; | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", onabort); | ||
this.fw.addFace({ | ||
rx, | ||
async tx(iterable) { | ||
var _a; | ||
for await (const pkt of iterable) { | ||
@@ -81,2 +63,3 @@ if (pkt.l3 instanceof Data) { | ||
cancelRetx(); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", onabort); | ||
rx.end(); | ||
@@ -89,7 +72,2 @@ }, | ||
sendInterest(); | ||
onCancel(() => { | ||
cancelRetx(); | ||
rx.push(new CancelInterest(interest)); | ||
}); | ||
onCancel.shouldReject = false; | ||
}); | ||
@@ -96,0 +74,0 @@ return Object.defineProperties(promise, { |
@@ -1,32 +0,6 @@ | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
import { __importDefault, __importStar } from "tslib"; | ||
import { CancelInterest, FwPacket } from "@ndn/fw"; | ||
import { Data, Interest } from "@ndn/packet"; | ||
const pushable = __importDefault(require("it-pushable")).default; | ||
const PCancelable = __importDefault(require("p-cancelable")).default; | ||
import _cjsDefaultImport0 from "it-pushable"; const pushable = __importDefault(_cjsDefaultImport0).default; | ||
import { makeRetxGenerator } from "./retx_node.js"; | ||
function makeModifyInterest(input) { | ||
if (typeof input === "function") { | ||
return input; | ||
} | ||
const { canBePrefix, mustBeFresh, fwHint, lifetime, hopLimit, } = input; | ||
return (interest) => { | ||
if (typeof canBePrefix !== "undefined") { | ||
interest.canBePrefix = canBePrefix; | ||
} | ||
if (typeof mustBeFresh !== "undefined") { | ||
interest.mustBeFresh = mustBeFresh; | ||
} | ||
if (typeof fwHint !== "undefined") { | ||
interest.fwHint = fwHint; | ||
} | ||
if (typeof lifetime !== "undefined") { | ||
interest.lifetime = lifetime; | ||
} | ||
if (typeof hopLimit !== "undefined") { | ||
interest.hopLimit = hopLimit; | ||
} | ||
}; | ||
} | ||
/** Consumer functionality of Endpoint. */ | ||
@@ -37,9 +11,8 @@ export class EndpointConsumer { | ||
const interest = interestInput instanceof Interest ? interestInput : new Interest(interestInput); | ||
const { describe = `consume(${interest.name})`, modifyInterest, retx, verifier, } = { ...this.opts, ...opts }; | ||
if (modifyInterest) { | ||
makeModifyInterest(modifyInterest)(interest); | ||
} | ||
const { describe = `consume(${interest.name})`, modifyInterest, retx, signal, verifier, } = { ...this.opts, ...opts }; | ||
Interest.makeModifyFunc(modifyInterest)(interest); | ||
let nRetx = -1; | ||
const retxGen = makeRetxGenerator(retx)(interest.lifetime)[Symbol.iterator](); | ||
const promise = new PCancelable((resolve, reject, onCancel) => { | ||
const promise = new Promise((resolve, reject) => { | ||
var _a; | ||
const rx = pushable(); | ||
@@ -62,5 +35,11 @@ let timer; | ||
}; | ||
const onabort = () => { | ||
cancelRetx(); | ||
rx.push(new CancelInterest(interest)); | ||
}; | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", onabort); | ||
this.fw.addFace({ | ||
rx, | ||
async tx(iterable) { | ||
var _a; | ||
for await (const pkt of iterable) { | ||
@@ -84,2 +63,3 @@ if (pkt.l3 instanceof Data) { | ||
cancelRetx(); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", onabort); | ||
rx.end(); | ||
@@ -92,7 +72,2 @@ }, | ||
sendInterest(); | ||
onCancel(() => { | ||
cancelRetx(); | ||
rx.push(new CancelInterest(interest)); | ||
}); | ||
onCancel.shouldReject = false; | ||
}); | ||
@@ -99,0 +74,0 @@ return Object.defineProperties(promise, { |
import { Forwarder } from "@ndn/fw"; | ||
import { Data, FwHint, Interest, NameLike, Verifier } from "@ndn/packet"; | ||
import PCancelable from "p-cancelable"; | ||
import { Data, Interest, NameLike, Verifier } from "@ndn/packet"; | ||
import type { AbortSignal } from "abort-controller"; | ||
import { RetxPolicy } from "./retx"; | ||
declare type ModifyInterestFunc = (interest: Interest) => void; | ||
interface ModifyInterestFields { | ||
canBePrefix?: boolean; | ||
mustBeFresh?: boolean; | ||
fwHint?: FwHint; | ||
lifetime?: number; | ||
hopLimit?: number; | ||
} | ||
declare type ModifyInterest = ModifyInterestFunc | ModifyInterestFields; | ||
export interface Options { | ||
@@ -21,3 +12,3 @@ /** Description for debugging purpose. */ | ||
*/ | ||
modifyInterest?: ModifyInterest; | ||
modifyInterest?: Interest.Modify; | ||
/** | ||
@@ -28,2 +19,4 @@ * Retransmission policy. | ||
retx?: RetxPolicy; | ||
/** AbortSignal that allows canceling the Interest via AbortController. */ | ||
signal?: AbortSignal | globalThis.AbortSignal; | ||
/** | ||
@@ -41,3 +34,3 @@ * Data verifier. | ||
*/ | ||
export declare type Context = PCancelable<Data> & { | ||
export declare type Context = Promise<Data> & { | ||
readonly interest: Interest; | ||
@@ -53,2 +46,1 @@ readonly nRetx: number; | ||
} | ||
export {}; |
@@ -1,2 +0,3 @@ | ||
import assert from "minimalistic-assert"; | ||
import { __importDefault, __importStar } from "tslib"; | ||
import _cjsDefaultImport0 from "minimalistic-assert"; const assert = __importDefault(_cjsDefaultImport0).default; | ||
import { signUnsignedData } from "./producer_browser.js"; | ||
@@ -3,0 +4,0 @@ // We declare an interface here instead of importing DataStore, in order to reduce bundle size for |
@@ -1,5 +0,3 @@ | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
const assert = __importDefault(require("minimalistic-assert")).default; | ||
import { __importDefault, __importStar } from "tslib"; | ||
import _cjsDefaultImport0 from "minimalistic-assert"; const assert = __importDefault(_cjsDefaultImport0).default; | ||
import { signUnsignedData } from "./producer_node.js"; | ||
@@ -6,0 +4,0 @@ // We declare an interface here instead of importing DataStore, in order to reduce bundle size for |
@@ -0,3 +1,4 @@ | ||
import { __importDefault, __importStar } from "tslib"; | ||
import { Forwarder } from "@ndn/fw"; | ||
import applyMixins from "applymixins"; | ||
import _cjsDefaultImport0 from "applymixins"; const applyMixins = __importDefault(_cjsDefaultImport0).default; | ||
import { EndpointConsumer } from "./consumer_browser.js"; | ||
@@ -4,0 +5,0 @@ import { EndpointProducer } from "./producer_browser.js"; |
@@ -1,6 +0,4 @@ | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
import { __importDefault, __importStar } from "tslib"; | ||
import { Forwarder } from "@ndn/fw"; | ||
const applyMixins = __importDefault(require("applymixins")).default; | ||
import _cjsDefaultImport0 from "applymixins"; const applyMixins = __importDefault(_cjsDefaultImport0).default; | ||
import { EndpointConsumer } from "./consumer_node.js"; | ||
@@ -7,0 +5,0 @@ import { EndpointProducer } from "./producer_node.js"; |
@@ -65,2 +65,3 @@ import { FwPacket } from "@ndn/fw"; | ||
dataBuffer, | ||
processInterest, | ||
close() { face.close(); }, | ||
@@ -67,0 +68,0 @@ }; |
@@ -1,7 +0,4 @@ | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
import { FwPacket } from "@ndn/fw"; | ||
import { Data, Interest, Name, SigType } from "@ndn/packet"; | ||
const { flatTransform } = require("streaming-iterables"); | ||
import { flatTransform } from "streaming-iterables"; | ||
/** Producer functionality of Endpoint. */ | ||
@@ -68,2 +65,3 @@ export class EndpointProducer { | ||
dataBuffer, | ||
processInterest, | ||
close() { face.close(); }, | ||
@@ -70,0 +68,0 @@ }; |
@@ -7,10 +7,10 @@ import { Forwarder, FwFace } from "@ndn/fw"; | ||
* | ||
* The handler can return a Data to respond to the Interest, or return 'false' to cause a timeout. | ||
* The handler can return a Data to respond to the Interest, or return `undefined` to cause a timeout. | ||
* | ||
* If Options.dataBuffer is provided, the handler can access the DataBuffer via producer.dataBuffer . | ||
* The handler can return a Data to respond to the Interest, which is also inserted to the DataBuffer | ||
* unless Options.autoBuffer is set to false. If the handler returns 'false', the Interest is used | ||
* unless Options.autoBuffer is set to false. If the handler returns `undefined`, the Interest is used | ||
* to query the DataBuffer, and any matching Data may be sent. | ||
*/ | ||
export declare type Handler = (interest: Interest, producer: Producer) => Promise<Data | false>; | ||
export declare type Handler = (interest: Interest, producer: Producer) => Promise<Data | undefined>; | ||
export interface Options { | ||
@@ -48,2 +48,11 @@ /** Description for debugging purpose. */ | ||
readonly dataBuffer?: DataBuffer; | ||
/** | ||
* Process an Interest received elsewhere. | ||
* | ||
* Use case of this function: | ||
* 1. Producer A dynamically creates producer B upon receiving an Interest. | ||
* 2. Producer A can invoke this function to let producer B generate a response. | ||
* 3. The response should be sent by producer A. | ||
*/ | ||
processInterest: (interest: Interest) => Promise<Data | undefined>; | ||
/** Close the producer. */ | ||
@@ -50,0 +59,0 @@ close: () => void; |
{ | ||
"name": "@ndn/endpoint", | ||
"version": "0.0.20200909", | ||
"version": "0.0.20210203", | ||
"description": "NDNts: Client Endpoint", | ||
@@ -25,13 +25,13 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/fw": "0.0.20200909", | ||
"@ndn/packet": "0.0.20200909", | ||
"@ndn/tlv": "0.0.20200909", | ||
"@ndn/fw": "0.0.20210203", | ||
"@ndn/packet": "0.0.20210203", | ||
"@ndn/tlv": "0.0.20210203", | ||
"abort-controller": "^3.0.0", | ||
"applymixins": "^1.1.0", | ||
"it-pushable": "^1.4.0", | ||
"it-pushable": "1.4.0", | ||
"minimalistic-assert": "^1.0.1", | ||
"p-cancelable": "^2.0.0", | ||
"streaming-iterables": "^5.0.2", | ||
"tslib": "^2.0.1" | ||
"streaming-iterables": "^5.0.4", | ||
"tslib": "^2.1.0" | ||
}, | ||
"types": "lib/mod.d.ts" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
0
0
28003
670
+ Addedabort-controller@^3.0.0
+ Added@ndn/fw@0.0.20210203(transitive)
+ Added@ndn/packet@0.0.20210203(transitive)
+ Added@ndn/tlv@0.0.20210203(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedit-pushable@1.4.0(transitive)
- Removedp-cancelable@^2.0.0
- Removed@ndn/fw@0.0.20200909(transitive)
- Removed@ndn/packet@0.0.20200909(transitive)
- Removed@ndn/tlv@0.0.20200909(transitive)
- Removedit-pushable@1.4.2(transitive)
- Removedloglevel@1.9.2(transitive)
- Removedp-cancelable@2.1.1(transitive)
Updated@ndn/fw@0.0.20210203
Updated@ndn/packet@0.0.20210203
Updated@ndn/tlv@0.0.20210203
Updatedit-pushable@1.4.0
Updatedstreaming-iterables@^5.0.4
Updatedtslib@^2.1.0