Comparing version 0.0.20191223-beta.1 to 0.0.20200606
export declare const TT: { | ||
LpPacket: number; | ||
Fragment: number; | ||
PitToken: number; | ||
}; |
export const TT = { | ||
LpPacket: 0x64, | ||
Fragment: 0x50, | ||
PitToken: 0x62, | ||
}; |
export * from "./an"; | ||
export * from "./packet"; | ||
export * from "./pit-token"; | ||
export * from "./service"; |
export * from "./an.js"; | ||
export * from "./packet.js"; | ||
export * from "./pit-token.js"; | ||
export * from "./service.js"; |
@@ -1,5 +0,10 @@ | ||
import { Decoder } from "@ndn/tlv"; | ||
import { NackHeader } from "@ndn/packet"; | ||
import { Decoder, Encoder } from "@ndn/tlv"; | ||
import { PitToken } from "./mod"; | ||
export declare class LpPacket { | ||
static decodeFrom(decoder: Decoder): LpPacket; | ||
pitToken?: PitToken; | ||
nack?: NackHeader; | ||
fragment?: Uint8Array; | ||
encodeTo(encoder: Encoder): void; | ||
} |
@@ -1,2 +0,3 @@ | ||
import { EvDecoder } from "@ndn/tlv"; | ||
import { NackHeader, TT as l3TT } from "@ndn/packet"; | ||
import { Encoder, EvDecoder } from "@ndn/tlv"; | ||
import { TT } from "./mod.js"; | ||
@@ -8,2 +9,4 @@ function isCritical(tt) { | ||
.setIsCritical(isCritical) | ||
.add(TT.PitToken, (t, { value }) => t.pitToken = value) | ||
.add(l3TT.Nack, (t, { decoder }) => t.nack = decoder.decode(NackHeader)) | ||
.add(TT.Fragment, (t, { value }) => t.fragment = value); | ||
@@ -14,2 +17,5 @@ export class LpPacket { | ||
} | ||
encodeTo(encoder) { | ||
encoder.prependTlv(TT.LpPacket, [TT.PitToken, Encoder.OmitEmpty, this.pitToken], this.nack, [TT.Fragment, Encoder.OmitEmpty, this.fragment]); | ||
} | ||
} |
@@ -0,6 +1,32 @@ | ||
import { Data, Interest, Nack } from "@ndn/packet"; | ||
import { Decoder } from "@ndn/tlv"; | ||
export declare class LpService { | ||
rx: (iterable: AsyncIterable<Decoder.Tlv>) => AsyncIterable<Decoder.Tlv>; | ||
constructor({ keepAlive, }?: LpService.Options); | ||
private keepAlive; | ||
rx: (iterable: AsyncIterable<Decoder.Tlv>) => AsyncIterable<Data | Interest | Nack | LpService.RxError>; | ||
private rx_; | ||
private decode; | ||
private decodeL3; | ||
tx: (iterable: AsyncIterable<LpService.L3Pkt>) => AsyncIterable<Uint8Array | LpService.TxError>; | ||
private tx_; | ||
private encode; | ||
} | ||
export declare namespace LpService { | ||
interface Options { | ||
/** | ||
* How often to send IDLE packets if nothing else was sent, in millis. | ||
* Set false or zero to disable keep-alive. | ||
* @default 60000 | ||
*/ | ||
keepAlive?: false | number; | ||
} | ||
type L3Pkt = Interest | Data | Nack; | ||
class RxError extends Error { | ||
readonly packet: Uint8Array; | ||
constructor(inner: Error, packet: Uint8Array); | ||
} | ||
class TxError extends Error { | ||
readonly packet: L3Pkt; | ||
constructor(inner: Error, packet: L3Pkt); | ||
} | ||
} |
@@ -1,8 +0,38 @@ | ||
import { Decoder } from "@ndn/tlv"; | ||
/// #if false | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
/// #endif | ||
import { Data, Interest, Nack, TT as l3TT } from "@ndn/packet"; | ||
import { Decoder, Encoder, printTT, toHex } from "@ndn/tlv"; | ||
/// #if false | ||
const itKeepAlive = __importDefault(require("it-keepalive")).default; | ||
/* | ||
/// #else | ||
import itKeepAlive from "it-keepalive"; | ||
/// #endif | ||
/// #if false | ||
*/ | ||
/// #endif | ||
import { LpPacket, TT } from "./mod.js"; | ||
import { PitToken } from "./pit-token.js"; | ||
const IDLE = Encoder.encode(new LpPacket()); | ||
export class LpService { | ||
constructor() { | ||
constructor({ keepAlive = 60000, } = {}) { | ||
this.rx = (iterable) => { | ||
return this.rx_(iterable); | ||
}; | ||
this.tx = (iterable) => { | ||
let iterable1 = iterable; | ||
if (this.keepAlive > 0) { | ||
iterable1 = itKeepAlive(() => false, { timeout: this.keepAlive })(iterable); | ||
} | ||
return this.tx_(iterable1); | ||
}; | ||
if (keepAlive === false || keepAlive <= 0) { | ||
this.keepAlive = -1; | ||
} | ||
else { | ||
this.keepAlive = keepAlive; | ||
} | ||
} | ||
@@ -15,17 +45,92 @@ async *rx_(iterable) { | ||
*decode(tlv) { | ||
const { type, decoder } = tlv; | ||
if (type !== TT.LpPacket) { | ||
return yield tlv; | ||
try { | ||
const { type, decoder } = tlv; | ||
if (type !== TT.LpPacket) { | ||
return yield this.decodeL3(tlv); | ||
} | ||
const lpp = decoder.decode(LpPacket); | ||
if (!lpp.fragment) { | ||
return; | ||
} | ||
let l3pkt = this.decodeL3(new Decoder(lpp.fragment).read()); | ||
if (lpp.nack) { | ||
if (l3pkt instanceof Interest) { | ||
l3pkt = new Nack(l3pkt, lpp.nack); | ||
} | ||
else { | ||
throw new Error("Nack can only appear on Interest"); | ||
} | ||
} | ||
PitToken.set(l3pkt, lpp.pitToken); | ||
yield l3pkt; | ||
} | ||
let lpp; | ||
catch (err) { | ||
yield new LpService.RxError(err, tlv.tlv); | ||
} | ||
} | ||
decodeL3({ type, decoder }) { | ||
switch (type) { | ||
case l3TT.Interest: | ||
return decoder.decode(Interest); | ||
case l3TT.Data: | ||
return decoder.decode(Data); | ||
default: | ||
throw new Error(`unrecognized TLV-TYPE ${printTT(type)} as L3Pkt`); | ||
} | ||
} | ||
async *tx_(iterable) { | ||
for await (const pkt of iterable) { | ||
if (pkt === false) { | ||
yield IDLE; | ||
} | ||
else { | ||
yield* this.encode(pkt); | ||
} | ||
} | ||
} | ||
async *encode(pkt) { | ||
try { | ||
lpp = decoder.decode(LpPacket); | ||
switch (true) { | ||
case pkt instanceof Interest: | ||
case pkt instanceof Data: { | ||
const l3pkt = pkt; | ||
const pitToken = PitToken.get(l3pkt); | ||
if (!pitToken) { | ||
return yield Encoder.encode(l3pkt); | ||
} | ||
const lpp = new LpPacket(); | ||
lpp.pitToken = pitToken; | ||
lpp.fragment = Encoder.encode(l3pkt); | ||
return yield Encoder.encode(lpp); | ||
} | ||
case pkt instanceof Nack: { | ||
const nack = pkt; | ||
const lpp = new LpPacket(); | ||
lpp.pitToken = PitToken.get(nack); | ||
lpp.nack = nack.header; | ||
lpp.fragment = Encoder.encode(nack.interest); | ||
return yield Encoder.encode(lpp); | ||
} | ||
} | ||
} | ||
catch { | ||
return; | ||
catch (err) { | ||
return yield new LpService.TxError(err, pkt); | ||
} | ||
if (lpp.fragment) { | ||
yield new Decoder(lpp.fragment).read(); | ||
} | ||
} | ||
(function (LpService) { | ||
class RxError extends Error { | ||
constructor(inner, packet) { | ||
super(`${inner.message} ${toHex(packet)}`); | ||
this.packet = packet; | ||
} | ||
} | ||
} | ||
LpService.RxError = RxError; | ||
class TxError extends Error { | ||
constructor(inner, packet) { | ||
super(`${inner.message} ${packet instanceof Nack ? packet.interest.name : packet.name}`); | ||
this.packet = packet; | ||
} | ||
} | ||
LpService.TxError = TxError; | ||
})(LpService || (LpService = {})); |
{ | ||
"name": "@ndn/lp", | ||
"version": "0.0.20191223-beta.1", | ||
"version": "0.0.20200606", | ||
"description": "NDNts: NDNLP", | ||
@@ -24,5 +24,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/tlv": "0.0.20191223-beta.1", | ||
"@ndn/packet": "0.0.20200606", | ||
"@ndn/tlv": "0.0.20200606", | ||
"it-keepalive": "^1.2.0", | ||
"tslib": "*" | ||
} | ||
} |
@@ -6,2 +6,5 @@ # @ndn/lp | ||
This package implements [NDNLPv2](https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2) link protocol. | ||
Currently, a minimal implementation strips unrecognized headers, and extracts non-fragmented payload out of LpPacket for processing in L3 decoder. | ||
Currently, this is a minimal implementation that understands: | ||
* Interest/Data/Nack packets without fragmentation. | ||
* PIT token. |
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
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
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
9813
12
276
10
4
1
1
+ Added@ndn/packet@0.0.20200606
+ Addedit-keepalive@^1.2.0
+ Added@ndn/packet@0.0.20200606(transitive)
+ Added@ndn/tlv@0.0.20200606(transitive)
+ Addedbuffer-compare@1.1.1(transitive)
+ Addedget-iterator@1.0.2(transitive)
+ Addedit-keepalive@1.2.0(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
- Removed@ndn/tlv@0.0.20191223-beta.1(transitive)
Updated@ndn/tlv@0.0.20200606