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

@ndn/lp

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

Comparing version 0.0.20220501 to 0.0.20230121

10

lib/fragmenter_browser.js
import { Encoder } from "@ndn/tlv";
import { LpPacket } from "./packet_browser.js";
class SeqNumGen {
constructor() {
this.current = (BigInt(Math.trunc(Math.random() * 0x100000000)) << 32n) |
BigInt(Math.trunc(Math.random() * 0x100000000));
}
current = (BigInt(Math.trunc(Math.random() * 0x100000000)) << 32n) |
BigInt(Math.trunc(Math.random() * 0x100000000));
next() {

@@ -22,5 +20,3 @@ this.current = BigInt.asUintN(64, this.current + 1n);

export class Fragmenter {
constructor() {
this.seqNumGen = new SeqNumGen();
}
seqNumGen = new SeqNumGen();
/**

@@ -27,0 +23,0 @@ * Fragment a packet.

import { Encoder } from "@ndn/tlv";
import { LpPacket } from "./packet_node.js";
class SeqNumGen {
constructor() {
this.current = (BigInt(Math.trunc(Math.random() * 0x100000000)) << 32n) |
BigInt(Math.trunc(Math.random() * 0x100000000));
}
current = (BigInt(Math.trunc(Math.random() * 0x100000000)) << 32n) |
BigInt(Math.trunc(Math.random() * 0x100000000));
next() {

@@ -22,5 +20,3 @@ this.current = BigInt.asUintN(64, this.current + 1n);

export class Fragmenter {
constructor() {
this.seqNumGen = new SeqNumGen();
}
seqNumGen = new SeqNumGen();
/**

@@ -27,0 +23,0 @@ * Fragment a packet.

@@ -1,2 +0,2 @@

import { LpPacket } from "./packet";
import { LpPacket } from "./packet.js";
/** NDNLPv2 fragmenter. */

@@ -3,0 +3,0 @@ export declare class Fragmenter {

@@ -1,5 +0,5 @@

export * from "./an";
export * from "./fragmenter";
export * from "./packet";
export * from "./reassembler";
export * from "./service";
export * from "./an.js";
export * from "./fragmenter.js";
export * from "./packet.js";
export * from "./reassembler.js";
export * from "./service.js";

@@ -18,11 +18,13 @@ import { NackHeader } from "@ndn/packet";

export class LpPacket {
constructor() {
this.fragIndex = 0;
this.fragCount = 1;
}
static decodeFrom(decoder) {
return EVD.decode(new LpPacket(), decoder);
}
fragSeqNum;
fragIndex = 0;
fragCount = 1;
pitToken;
nack;
payload;
encodeTo(encoder) {
encoder.prependTlv(TT.LpPacket, this.fragSeqNum === undefined ? undefined : [TT.LpSeqNum, NNI(this.fragSeqNum, { len: 8 })], this.fragIndex > 0 ? [TT.FragIndex, NNI(this.fragIndex)] : undefined, this.fragCount > 1 ? [TT.FragCount, NNI(this.fragCount)] : undefined, ...this.encodeL3Headers(), [TT.LpPayload, Encoder.OmitEmpty, this.payload]);
encoder.prependTlv(TT.LpPacket, this.fragSeqNum !== undefined && [TT.LpSeqNum, NNI(this.fragSeqNum, { len: 8 })], this.fragIndex > 0 && [TT.FragIndex, NNI(this.fragIndex)], this.fragCount > 1 && [TT.FragCount, NNI(this.fragCount)], ...this.encodeL3Headers(), [TT.LpPayload, Encoder.OmitEmpty, this.payload]);
}

@@ -29,0 +31,0 @@ encodeL3Headers() {

@@ -18,11 +18,13 @@ import { NackHeader } from "@ndn/packet";

export class LpPacket {
constructor() {
this.fragIndex = 0;
this.fragCount = 1;
}
static decodeFrom(decoder) {
return EVD.decode(new LpPacket(), decoder);
}
fragSeqNum;
fragIndex = 0;
fragCount = 1;
pitToken;
nack;
payload;
encodeTo(encoder) {
encoder.prependTlv(TT.LpPacket, this.fragSeqNum === undefined ? undefined : [TT.LpSeqNum, NNI(this.fragSeqNum, { len: 8 })], this.fragIndex > 0 ? [TT.FragIndex, NNI(this.fragIndex)] : undefined, this.fragCount > 1 ? [TT.FragCount, NNI(this.fragCount)] : undefined, ...this.encodeL3Headers(), [TT.LpPayload, Encoder.OmitEmpty, this.payload]);
encoder.prependTlv(TT.LpPacket, this.fragSeqNum !== undefined && [TT.LpSeqNum, NNI(this.fragSeqNum, { len: 8 })], this.fragIndex > 0 && [TT.FragIndex, NNI(this.fragIndex)], this.fragCount > 1 && [TT.FragCount, NNI(this.fragCount)], ...this.encodeL3Headers(), [TT.LpPayload, Encoder.OmitEmpty, this.payload]);
}

@@ -29,0 +31,0 @@ encodeL3Headers() {

@@ -0,9 +1,11 @@

import { concatBuffers } from "@ndn/util";
import { LpPacket } from "./packet_browser.js";
class PartialPacket {
seqNumBase;
constructor(seqNumBase) {
this.seqNumBase = seqNumBase;
this.buffer = [];
this.accepted = 0;
this.payloadLength = 0;
}
buffer = [];
accepted = 0;
payloadLength = 0;
accept(fragment) {

@@ -35,11 +37,10 @@ if (this.accepted === 0) { // first

full.copyL3HeadersFrom(this.buffer[0]);
full.payload = new Uint8Array(this.payloadLength);
let offset = 0;
const parts = [];
for (const fragment of this.buffer) {
if (!fragment.payload) {
continue;
const part = fragment?.payload;
if (part) {
parts.push(part);
}
full.payload.set(fragment.payload, offset);
offset += fragment.payload.length;
}
full.payload = concatBuffers(parts, this.payloadLength);
return full;

@@ -50,6 +51,7 @@ }

export class Reassembler {
capacity;
constructor(capacity) {
this.capacity = capacity;
this.partials = new Map();
}
partials = new Map();
/**

@@ -56,0 +58,0 @@ * Process a fragment.

@@ -0,9 +1,11 @@

import { concatBuffers } from "@ndn/util";
import { LpPacket } from "./packet_node.js";
class PartialPacket {
seqNumBase;
constructor(seqNumBase) {
this.seqNumBase = seqNumBase;
this.buffer = [];
this.accepted = 0;
this.payloadLength = 0;
}
buffer = [];
accepted = 0;
payloadLength = 0;
accept(fragment) {

@@ -35,11 +37,10 @@ if (this.accepted === 0) { // first

full.copyL3HeadersFrom(this.buffer[0]);
full.payload = new Uint8Array(this.payloadLength);
let offset = 0;
const parts = [];
for (const fragment of this.buffer) {
if (!fragment.payload) {
continue;
const part = fragment?.payload;
if (part) {
parts.push(part);
}
full.payload.set(fragment.payload, offset);
offset += fragment.payload.length;
}
full.payload = concatBuffers(parts, this.payloadLength);
return full;

@@ -50,6 +51,7 @@ }

export class Reassembler {
capacity;
constructor(capacity) {
this.capacity = capacity;
this.partials = new Map();
}
partials = new Map();
/**

@@ -56,0 +58,0 @@ * Process a fragment.

@@ -1,2 +0,2 @@

import { LpPacket } from "./packet";
import { LpPacket } from "./packet.js";
/** NDNLPv2 reassembler. */

@@ -3,0 +3,0 @@ export declare class Reassembler {

@@ -13,9 +13,5 @@ import { __importDefault, __importStar } from "tslib";

export class LpService {
transport;
constructor({ keepAlive = 60000, mtu = Infinity, reassemblerCapacity = 16, }, transport) {
this.transport = transport;
this.fragmenter = new Fragmenter();
this.rx = (iterable) => flatMapOnce((tlv) => this.decode(tlv), iterable);
this.tx = (iterable) => flatMapOnce((pkt) => this.encode(pkt), this.keepAlive ?
itKeepAlive(() => false, { timeout: this.keepAlive })(iterable) :
iterable);
if (Number.isFinite(keepAlive) && keepAlive > 0) {

@@ -27,2 +23,7 @@ this.keepAlive = Math.ceil(keepAlive);

}
keepAlive;
mtu;
fragmenter = new Fragmenter();
reassembler;
rx = (iterable) => flatMapOnce((tlv) => this.decode(tlv), iterable);
*decode(dtlv) {

@@ -66,2 +67,5 @@ const { type, decoder, tlv } = dtlv;

}
tx = (iterable) => flatMapOnce((pkt) => this.encode(pkt), this.keepAlive ?
itKeepAlive(() => false, { timeout: this.keepAlive })(iterable) :
iterable);
*encode(pkt) {

@@ -103,2 +107,3 @@ if (pkt === false) {

class RxError extends Error {
packet;
constructor(inner, packet) {

@@ -111,2 +116,3 @@ super(`${inner.message} ${toHex(packet)}`);

class TxError extends Error {
packet;
constructor(inner, packet) {

@@ -113,0 +119,0 @@ super(`${inner.message} ${packet instanceof Nack ? packet.interest.name : packet.name}`);

@@ -13,9 +13,5 @@ import { __importDefault, __importStar } from "tslib";

export class LpService {
transport;
constructor({ keepAlive = 60000, mtu = Infinity, reassemblerCapacity = 16, }, transport) {
this.transport = transport;
this.fragmenter = new Fragmenter();
this.rx = (iterable) => flatMapOnce((tlv) => this.decode(tlv), iterable);
this.tx = (iterable) => flatMapOnce((pkt) => this.encode(pkt), this.keepAlive ?
itKeepAlive(() => false, { timeout: this.keepAlive })(iterable) :
iterable);
if (Number.isFinite(keepAlive) && keepAlive > 0) {

@@ -27,2 +23,7 @@ this.keepAlive = Math.ceil(keepAlive);

}
keepAlive;
mtu;
fragmenter = new Fragmenter();
reassembler;
rx = (iterable) => flatMapOnce((tlv) => this.decode(tlv), iterable);
*decode(dtlv) {

@@ -66,2 +67,5 @@ const { type, decoder, tlv } = dtlv;

}
tx = (iterable) => flatMapOnce((pkt) => this.encode(pkt), this.keepAlive ?
itKeepAlive(() => false, { timeout: this.keepAlive })(iterable) :
iterable);
*encode(pkt) {

@@ -103,2 +107,3 @@ if (pkt === false) {

class RxError extends Error {
packet;
constructor(inner, packet) {

@@ -111,2 +116,3 @@ super(`${inner.message} ${toHex(packet)}`);

class TxError extends Error {
packet;
constructor(inner, packet) {

@@ -113,0 +119,0 @@ super(`${inner.message} ${packet instanceof Nack ? packet.interest.name : packet.name}`);

{
"name": "@ndn/lp",
"version": "0.0.20220501",
"version": "0.0.20230121",
"description": "NDNts: NDNLP",

@@ -25,10 +25,9 @@ "keywords": [

"dependencies": {
"@ndn/packet": "0.0.20220501",
"@ndn/tlv": "0.0.20220501",
"@ndn/util": "0.0.20220501",
"@ndn/packet": "0.0.20230121",
"@ndn/tlv": "0.0.20230121",
"@ndn/util": "0.0.20230121",
"it-keepalive": "^1.2.0",
"tslib": "^2.4.0"
"tslib": "^2.4.1"
},
"types": "lib/mod.d.ts",
"readme": "# @ndn/lp\n\nThis package is part of [NDNts](https://yoursunny.com/p/NDNts/), Named Data Networking libraries for the modern web.\n\nThis package implements [NDNLPv2](https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2) link protocol.\nCurrently, this is a minimal implementation that understands:\n\n* Fragmentation and reassembly.\n* Nack.\n* PIT token.\n"
"types": "lib/mod.d.ts"
}

Sorry, the diff of this file is not supported yet

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