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

@ndn/rdr

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndn/rdr - npm Package Compare versions

Comparing version 0.0.20240113 to 0.0.20240630

18

lib/consumer_browser.js

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

import { Endpoint } from "@ndn/endpoint";
import { consume } from "@ndn/endpoint";
import { Interest, Name } from "@ndn/packet";

@@ -6,4 +6,5 @@ import { Decoder } from "@ndn/tlv";

/**
* Make RDR discovery Interest.
* @param prefix prefix of RDR metadata packet; 32=metadata component is optional.
* Make discovery Interest.
* @param prefix - Metadata packet prefix.
* `32=metadata` component is optional; it will be appended automatically if absent.
*/

@@ -17,3 +18,3 @@ export function makeDiscoveryInterest(prefix) {

}
export async function retrieveMetadata(prefix, arg2 = {}, opts = {}) {
export async function retrieveMetadata(prefix, arg2, cOpts) {
let ctor = Metadata;

@@ -24,13 +25,10 @@ if (typeof arg2 === "function") {

else {
opts = arg2;
cOpts = arg2;
}
const { endpoint = new Endpoint(), retx, signal, verifier, } = opts;
const interest = makeDiscoveryInterest(prefix);
const data = await endpoint.consume(interest, {
const data = await consume(interest, {
describe: `RDR-c(${prefix})`,
retx,
signal,
verifier,
...cOpts,
});
return Decoder.decode(data.content, ctor);
}

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

import { Endpoint } from "@ndn/endpoint";
import { consume } from "@ndn/endpoint";
import { Interest, Name } from "@ndn/packet";

@@ -6,4 +6,5 @@ import { Decoder } from "@ndn/tlv";

/**
* Make RDR discovery Interest.
* @param prefix prefix of RDR metadata packet; 32=metadata component is optional.
* Make discovery Interest.
* @param prefix - Metadata packet prefix.
* `32=metadata` component is optional; it will be appended automatically if absent.
*/

@@ -17,3 +18,3 @@ export function makeDiscoveryInterest(prefix) {

}
export async function retrieveMetadata(prefix, arg2 = {}, opts = {}) {
export async function retrieveMetadata(prefix, arg2, cOpts) {
let ctor = Metadata;

@@ -24,13 +25,10 @@ if (typeof arg2 === "function") {

else {
opts = arg2;
cOpts = arg2;
}
const { endpoint = new Endpoint(), retx, signal, verifier, } = opts;
const interest = makeDiscoveryInterest(prefix);
const data = await endpoint.consume(interest, {
const data = await consume(interest, {
describe: `RDR-c(${prefix})`,
retx,
signal,
verifier,
...cOpts,
});
return Decoder.decode(data.content, ctor);
}

@@ -1,24 +0,29 @@

import { Endpoint, type RetxPolicy } from "@ndn/endpoint";
import { Interest, type NameLike, type Verifier } from "@ndn/packet";
import { type ConsumerOptions } from "@ndn/endpoint";
import { Interest, type NameLike } from "@ndn/packet";
import { Metadata } from "./metadata.js";
/**
* Make RDR discovery Interest.
* @param prefix prefix of RDR metadata packet; 32=metadata component is optional.
* Make discovery Interest.
* @param prefix - Metadata packet prefix.
* `32=metadata` component is optional; it will be appended automatically if absent.
*/
export declare function makeDiscoveryInterest(prefix: NameLike): Interest;
/** Retrieve RDR metadata packet. */
export declare function retrieveMetadata(prefix: NameLike, opts?: retrieveMetadata.Options): Promise<Metadata>;
/** Retrieve RDR metadata packet. */
export declare function retrieveMetadata<C extends typeof Metadata>(prefix: NameLike, ctor: C, opts?: retrieveMetadata.Options): Promise<InstanceType<C>>;
export declare namespace retrieveMetadata {
interface Options {
/** Endpoint for communication. */
endpoint?: Endpoint;
/** Interest retransmission policy. */
retx?: RetxPolicy;
/** Abort signal to cancel retrieval. */
signal?: AbortSignal;
/** Data verifier. Default is no verify. */
verifier?: Verifier;
}
}
/**
* Retrieve metadata packet of base type.
* @param prefix - Metadata packet prefix.
* @param cOpts - Consumer options.
* - Commonly specified: `.retx` and `.verifier`.
* - `.describe` defaults to "RDR-c" + prefix.
* @returns Metadata packet.
*/
export declare function retrieveMetadata(prefix: NameLike, cOpts?: ConsumerOptions): Promise<Metadata>;
/**
* Retrieve metadata packet of subclass type.
* @typeParam C - Metadata subclass type.
* @param prefix - Metadata packet prefix.
* @param ctor - Metadata subclass constructor.
* @param cOpts - Consumer options.
* - Commonly specified: `.retx` and `.verifier`.
* - `.describe` defaults to "RDR-c" + prefix.
* @returns Metadata packet of type C.
*/
export declare function retrieveMetadata<C extends Metadata.Constructor>(prefix: NameLike, ctor: C, cOpts?: ConsumerOptions): Promise<InstanceType<C>>;
import { Keyword } from "@ndn/naming-convention2";
import { Name, TT } from "@ndn/packet";
import { EvDecoder, Extensible } from "@ndn/tlv";
/** 32=metadata component. */
/** `32=metadata` component. */
export const MetadataKeyword = Keyword.create("metadata");

@@ -12,3 +12,3 @@ function makeEvd(title) {

const EVD = makeEvd("Metadata");
/** RDR metadata packet content. */
/** Metadata packet content. */
export class Metadata {

@@ -18,3 +18,3 @@ name;

* Constructor.
* @param name versioned name.
* @param name - Versioned name.
*/

@@ -32,4 +32,5 @@ constructor(name = new Name()) {

(function (Metadata) {
/** Class decorator on an extensible Metadata subclass. */
function extend(ctor) {
/** Class decorator on an extensible {@link Metadata} subclass. */
function extend(ctor, ctx) {
void ctx; // cannot use due to https://github.com/vitest-dev/vitest/issues/3140
const registry = new ctor()[Extensible.TAG];

@@ -36,0 +37,0 @@ const evd = makeEvd(ctor.name).setUnknown(registry.decodeUnknown);

import { Keyword } from "@ndn/naming-convention2";
import { Name, TT } from "@ndn/packet";
import { EvDecoder, Extensible } from "@ndn/tlv";
/** 32=metadata component. */
/** `32=metadata` component. */
export const MetadataKeyword = Keyword.create("metadata");

@@ -12,3 +12,3 @@ function makeEvd(title) {

const EVD = makeEvd("Metadata");
/** RDR metadata packet content. */
/** Metadata packet content. */
export class Metadata {

@@ -18,3 +18,3 @@ name;

* Constructor.
* @param name versioned name.
* @param name - Versioned name.
*/

@@ -32,4 +32,5 @@ constructor(name = new Name()) {

(function (Metadata) {
/** Class decorator on an extensible Metadata subclass. */
function extend(ctor) {
/** Class decorator on an extensible {@link Metadata} subclass. */
function extend(ctor, ctx) {
void ctx; // cannot use due to https://github.com/vitest-dev/vitest/issues/3140
const registry = new ctor()[Extensible.TAG];

@@ -36,0 +37,0 @@ const evd = makeEvd(ctor.name).setUnknown(registry.decodeUnknown);

import { type Component, Name } from "@ndn/packet";
import { type Decodable, type Decoder, type EncodableObj, type Encoder, Extensible } from "@ndn/tlv";
/** 32=metadata component. */
/** `32=metadata` component. */
export declare const MetadataKeyword: Component;
/** RDR metadata packet content. */
/** Metadata packet content. */
export declare class Metadata implements EncodableObj {

@@ -10,3 +10,3 @@ name: Name;

* Constructor.
* @param name versioned name.
* @param name - Versioned name.
*/

@@ -21,4 +21,4 @@ constructor(name?: Name);

}
/** Class decorator on an extensible Metadata subclass. */
function extend<M extends Metadata & Extensible>(ctor: new () => M): void;
/** Class decorator on an extensible {@link Metadata} subclass. */
function extend<M extends Metadata & Extensible>(ctor: new () => M, ctx?: ClassDecoratorContext): void;
}

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

import { Endpoint } from "@ndn/endpoint";
import { produce } from "@ndn/endpoint";
import { Segment, Version } from "@ndn/naming-convention2";

@@ -10,3 +10,3 @@ import { Data, Name, noopSigning } from "@ndn/packet";

}
/** Make RDR metadata packet. */
/** Make metadata packet. */
export async function makeMetadataPacket(m, { prefix, freshnessPeriod = 1, signer = noopSigning, } = {}) {

@@ -20,14 +20,17 @@ const data = new Data();

}
/** Determine if an Interest is an RDR discovery Interest. */
/** Determine if an Interest is a discovery Interest. */
export function isDiscoveryInterest({ name, canBePrefix, mustBeFresh }) {
return !!name.get(-1)?.equals(MetadataKeyword) && canBePrefix && mustBeFresh;
}
/** Serve RDR metadata packet in a producer. */
/** Serve metadata packet in a producer. */
export function serveMetadata(m, opts = {}) {
const { prefix: prefixInput, endpoint = new Endpoint(), announcement, } = opts;
const { prefix: prefixInput, pOpts, } = opts;
const makeMetadata = typeof m === "function" ? m : () => m;
const prefix = makeName(makeMetadata(), prefixInput).getPrefix(-2);
return endpoint.produce(prefix, async (interest) => {
return produce(prefix, async (interest) => {
if (isDiscoveryInterest(interest) && interest.name.length === prefix.length) {
return makeMetadataPacket(makeMetadata(), opts);
return makeMetadataPacket(makeMetadata(), {
signer: pOpts?.dataSigner,
...opts,
});
}

@@ -37,4 +40,4 @@ return undefined;

describe: `RDR-s(${prefix})`,
announcement,
...pOpts,
});
}

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

import { Endpoint } from "@ndn/endpoint";
import { produce } from "@ndn/endpoint";
import { Segment, Version } from "@ndn/naming-convention2";

@@ -10,3 +10,3 @@ import { Data, Name, noopSigning } from "@ndn/packet";

}
/** Make RDR metadata packet. */
/** Make metadata packet. */
export async function makeMetadataPacket(m, { prefix, freshnessPeriod = 1, signer = noopSigning, } = {}) {

@@ -20,14 +20,17 @@ const data = new Data();

}
/** Determine if an Interest is an RDR discovery Interest. */
/** Determine if an Interest is a discovery Interest. */
export function isDiscoveryInterest({ name, canBePrefix, mustBeFresh }) {
return !!name.get(-1)?.equals(MetadataKeyword) && canBePrefix && mustBeFresh;
}
/** Serve RDR metadata packet in a producer. */
/** Serve metadata packet in a producer. */
export function serveMetadata(m, opts = {}) {
const { prefix: prefixInput, endpoint = new Endpoint(), announcement, } = opts;
const { prefix: prefixInput, pOpts, } = opts;
const makeMetadata = typeof m === "function" ? m : () => m;
const prefix = makeName(makeMetadata(), prefixInput).getPrefix(-2);
return endpoint.produce(prefix, async (interest) => {
return produce(prefix, async (interest) => {
if (isDiscoveryInterest(interest) && interest.name.length === prefix.length) {
return makeMetadataPacket(makeMetadata(), opts);
return makeMetadataPacket(makeMetadata(), {
signer: pOpts?.dataSigner,
...opts,
});
}

@@ -37,4 +40,4 @@ return undefined;

describe: `RDR-s(${prefix})`,
announcement,
...pOpts,
});
}

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

import { Endpoint, type Producer } from "@ndn/endpoint";
import { type Producer, type ProducerOptions } from "@ndn/endpoint";
import { Data, type Interest, type NameLike, type Signer } from "@ndn/packet";
import { type Metadata } from "./metadata.js";
/** Make RDR metadata packet. */
/** Make metadata packet. */
export declare function makeMetadataPacket(m: Metadata, { prefix, freshnessPeriod, signer, }?: makeMetadataPacket.Options): Promise<Data>;

@@ -9,7 +9,6 @@ export declare namespace makeMetadataPacket {

/**
* RDR metadata packet prefix.
* Metadata packet prefix.
* @defaultValue `metadata.name.getPrefix(-1)`
*
* This should not contain 32=metadata.
*
* @default metadata.name.getPrefix(-1)
* This should not contain `32=metadata` component.
*/

@@ -19,8 +18,8 @@ prefix?: NameLike;

* FreshnessPeriod.
* @default 1
* @defaultValue 1
*/
freshnessPeriod?: number;
/**
* Signing key.
* @default noopSigning
* Data signer.
* @defaultValue noopSigning
*/

@@ -30,13 +29,18 @@ signer?: Signer;

}
/** Determine if an Interest is an RDR discovery Interest. */
/** Determine if an Interest is a discovery Interest. */
export declare function isDiscoveryInterest({ name, canBePrefix, mustBeFresh }: Interest): boolean;
/** Serve RDR metadata packet in a producer. */
/** Serve metadata packet in a producer. */
export declare function serveMetadata(m: Metadata | (() => Metadata), opts?: serveMetadata.Options): Producer;
export declare namespace serveMetadata {
interface Options extends makeMetadataPacket.Options {
/** Endpoint for communication. */
endpoint?: Endpoint;
/** Prefix to announce from producer. */
announcement?: Endpoint.RouteAnnouncement;
/**
* Producer options.
*
* @remarks
* - `.describe` defaults to "RDR-s" + prefix.
* - `.announcement` defaults to {@link makeMetadataPacket.Options.prefix}.
* - {@link makeMetadataPacket.Options.signer} defaults to `.dataSigner`.
*/
pOpts?: ProducerOptions;
}
}
{
"name": "@ndn/rdr",
"version": "0.0.20240113",
"version": "0.0.20240630",
"description": "NDNts: RDR Protocol",

@@ -22,12 +22,12 @@ "keywords": [

"url": "https://github.com/yoursunny/NDNts.git",
"directory": "packages/rdr"
"directory": "pkg/rdr"
},
"dependencies": {
"@ndn/endpoint": "0.0.20240113",
"@ndn/naming-convention2": "0.0.20240113",
"@ndn/packet": "0.0.20240113",
"@ndn/tlv": "0.0.20240113",
"tslib": "^2.6.2"
"@ndn/endpoint": "0.0.20240630",
"@ndn/naming-convention2": "0.0.20240630",
"@ndn/packet": "0.0.20240630",
"@ndn/tlv": "0.0.20240630",
"tslib": "^2.6.3"
},
"types": "lib/mod.d.ts"
}

@@ -5,2 +5,2 @@ # @ndn/rdr

This package implements [Realtime Data Retrieval (RDR) protocol](https://redmine.named-data.net/projects/ndn-tlv/wiki/RDR).
This package implements metadata publishing and retrieval using [Realtime Data Retrieval (RDR) protocol](https://redmine.named-data.net/projects/ndn-tlv/wiki/RDR).

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