Comparing version 0.0.20210203 to 0.0.20210930
import { Endpoint } from "@ndn/endpoint"; | ||
import { Interest, Name } from "@ndn/packet"; | ||
import { decodeMetadataContent, MetadataKeyword } from "./metadata_browser.js"; | ||
import { Decoder } from "@ndn/tlv"; | ||
import { Metadata, MetadataKeyword } from "./metadata_browser.js"; | ||
/** | ||
@@ -9,5 +10,4 @@ * Make RDR discovery Interest. | ||
export function makeDiscoveryInterest(prefix) { | ||
var _a; | ||
let name = new Name(prefix); | ||
if (!((_a = name.get(-1)) === null || _a === void 0 ? void 0 : _a.equals(MetadataKeyword))) { | ||
if (!name.get(-1)?.equals(MetadataKeyword)) { | ||
name = name.append(MetadataKeyword); | ||
@@ -17,15 +17,20 @@ } | ||
} | ||
/** Retrieve RDR metadata packet. */ | ||
export async function retrieveMetadata(prefix, { endpoint = new Endpoint(), retx, signal, verifier, } = {}) { | ||
export async function retrieveMetadata(prefix, arg2 = {}, opts = {}) { | ||
let ctor; | ||
if (typeof arg2 === "function") { | ||
ctor = arg2; | ||
} | ||
else { | ||
ctor = Metadata; | ||
opts = arg2; | ||
} | ||
const { endpoint = new Endpoint(), retx, signal, verifier, } = opts; | ||
const interest = makeDiscoveryInterest(prefix); | ||
const consumer = endpoint.consume(interest, { | ||
const data = await endpoint.consume(interest, { | ||
describe: `RDR-c(${prefix})`, | ||
retx, | ||
signal, | ||
verifier, | ||
}); | ||
const data = await consumer; | ||
if (verifier) { | ||
await verifier.verify(data); | ||
} | ||
return decodeMetadataContent(data.content); | ||
return new Decoder(data.content).decode(ctor); | ||
} |
import { Endpoint } from "@ndn/endpoint"; | ||
import { Interest, Name } from "@ndn/packet"; | ||
import { decodeMetadataContent, MetadataKeyword } from "./metadata_node.js"; | ||
import { Decoder } from "@ndn/tlv"; | ||
import { Metadata, MetadataKeyword } from "./metadata_node.js"; | ||
/** | ||
@@ -9,5 +10,4 @@ * Make RDR discovery Interest. | ||
export function makeDiscoveryInterest(prefix) { | ||
var _a; | ||
let name = new Name(prefix); | ||
if (!((_a = name.get(-1)) === null || _a === void 0 ? void 0 : _a.equals(MetadataKeyword))) { | ||
if (!name.get(-1)?.equals(MetadataKeyword)) { | ||
name = name.append(MetadataKeyword); | ||
@@ -17,15 +17,20 @@ } | ||
} | ||
/** Retrieve RDR metadata packet. */ | ||
export async function retrieveMetadata(prefix, { endpoint = new Endpoint(), retx, signal, verifier, } = {}) { | ||
export async function retrieveMetadata(prefix, arg2 = {}, opts = {}) { | ||
let ctor; | ||
if (typeof arg2 === "function") { | ||
ctor = arg2; | ||
} | ||
else { | ||
ctor = Metadata; | ||
opts = arg2; | ||
} | ||
const { endpoint = new Endpoint(), retx, signal, verifier, } = opts; | ||
const interest = makeDiscoveryInterest(prefix); | ||
const consumer = endpoint.consume(interest, { | ||
const data = await endpoint.consume(interest, { | ||
describe: `RDR-c(${prefix})`, | ||
retx, | ||
signal, | ||
verifier, | ||
}); | ||
const data = await consumer; | ||
if (verifier) { | ||
await verifier.verify(data); | ||
} | ||
return decodeMetadataContent(data.content); | ||
return new Decoder(data.content).decode(ctor); | ||
} |
@@ -0,4 +1,7 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="web" /> | ||
import { Endpoint, RetxPolicy } from "@ndn/endpoint"; | ||
import { Interest, NameLike, Verifier } from "@ndn/packet"; | ||
import type { AbortSignal } from "abort-controller"; | ||
import { Metadata } from "./metadata"; | ||
/** | ||
@@ -10,10 +13,16 @@ * Make RDR discovery Interest. | ||
/** Retrieve RDR metadata packet. */ | ||
export declare function retrieveMetadata(prefix: NameLike, { endpoint, retx, signal, verifier, }?: retrieveMetadata.Options): Promise<import("./metadata").Metadata>; | ||
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 | globalThis.AbortSignal; | ||
/** Data verifier. Default is no verify. */ | ||
verifier?: Verifier; | ||
} | ||
} |
import { Keyword } from "@ndn/naming-convention2"; | ||
import { Name, TT } from "@ndn/packet"; | ||
import { Decoder, Encoder } from "@ndn/tlv"; | ||
import { EvDecoder, Extensible } from "@ndn/tlv"; | ||
/** 32=metadata component. */ | ||
export const MetadataKeyword = Keyword.create("metadata"); | ||
/** Encode RDR metadata packet content. */ | ||
export function encodeMetadataContent({ name }) { | ||
const encoder = new Encoder(); | ||
encoder.prependValue(name); | ||
return encoder.output; | ||
function makeEvd(title) { | ||
return new EvDecoder(title) | ||
.add(TT.Name, (t, { value }) => t.name = new Name(value), { required: true }) | ||
.setIsCritical(() => false); | ||
} | ||
/** Decode RDR metadata packet content. */ | ||
export function decodeMetadataContent(wire) { | ||
const d = new Decoder(wire); | ||
while (!d.eof) { | ||
const { type, decoder: d1 } = d.read(); | ||
if (type === TT.Name) { | ||
const name = d1.decode(Name); | ||
return { name }; | ||
} | ||
const EVD = makeEvd("Metadata"); | ||
/** RDR metadata packet content. */ | ||
export class Metadata { | ||
/** | ||
* Constructor. | ||
* @param name versioned name. | ||
*/ | ||
constructor(name = new Name()) { | ||
this.name = name; | ||
} | ||
throw new Error("invalid RDR metadata Content"); | ||
static decodeFrom(decoder) { | ||
const metadata = new Metadata(); | ||
EVD.decodeValue(metadata, decoder); | ||
return metadata; | ||
} | ||
encodeTo(encoder) { | ||
encoder.prependValue(this.name); | ||
} | ||
} | ||
(function (Metadata) { | ||
/** Class decorator on an extensible Metadata subclass. */ | ||
function extend(ctor) { | ||
const registry = new ctor()[Extensible.TAG]; | ||
const evd = makeEvd(ctor.name).setUnknown(registry.decodeUnknown); | ||
Object.defineProperty(ctor, "decodeFrom", { value(decoder) { | ||
const metadata = new ctor(); | ||
evd.decodeValue(metadata, decoder); | ||
return metadata; | ||
} }); | ||
Object.defineProperty(ctor.prototype, "encodeTo", { value(encoder) { | ||
encoder.prependValue(this.name, ...registry.encode(this)); | ||
} }); | ||
} | ||
Metadata.extend = extend; | ||
})(Metadata || (Metadata = {})); |
import { Keyword } from "@ndn/naming-convention2"; | ||
import { Name, TT } from "@ndn/packet"; | ||
import { Decoder, Encoder } from "@ndn/tlv"; | ||
import { EvDecoder, Extensible } from "@ndn/tlv"; | ||
/** 32=metadata component. */ | ||
export const MetadataKeyword = Keyword.create("metadata"); | ||
/** Encode RDR metadata packet content. */ | ||
export function encodeMetadataContent({ name }) { | ||
const encoder = new Encoder(); | ||
encoder.prependValue(name); | ||
return encoder.output; | ||
function makeEvd(title) { | ||
return new EvDecoder(title) | ||
.add(TT.Name, (t, { value }) => t.name = new Name(value), { required: true }) | ||
.setIsCritical(() => false); | ||
} | ||
/** Decode RDR metadata packet content. */ | ||
export function decodeMetadataContent(wire) { | ||
const d = new Decoder(wire); | ||
while (!d.eof) { | ||
const { type, decoder: d1 } = d.read(); | ||
if (type === TT.Name) { | ||
const name = d1.decode(Name); | ||
return { name }; | ||
} | ||
const EVD = makeEvd("Metadata"); | ||
/** RDR metadata packet content. */ | ||
export class Metadata { | ||
/** | ||
* Constructor. | ||
* @param name versioned name. | ||
*/ | ||
constructor(name = new Name()) { | ||
this.name = name; | ||
} | ||
throw new Error("invalid RDR metadata Content"); | ||
static decodeFrom(decoder) { | ||
const metadata = new Metadata(); | ||
EVD.decodeValue(metadata, decoder); | ||
return metadata; | ||
} | ||
encodeTo(encoder) { | ||
encoder.prependValue(this.name); | ||
} | ||
} | ||
(function (Metadata) { | ||
/** Class decorator on an extensible Metadata subclass. */ | ||
function extend(ctor) { | ||
const registry = new ctor()[Extensible.TAG]; | ||
const evd = makeEvd(ctor.name).setUnknown(registry.decodeUnknown); | ||
Object.defineProperty(ctor, "decodeFrom", { value(decoder) { | ||
const metadata = new ctor(); | ||
evd.decodeValue(metadata, decoder); | ||
return metadata; | ||
} }); | ||
Object.defineProperty(ctor.prototype, "encodeTo", { value(encoder) { | ||
encoder.prependValue(this.name, ...registry.encode(this)); | ||
} }); | ||
} | ||
Metadata.extend = extend; | ||
})(Metadata || (Metadata = {})); |
import { Component, Name } from "@ndn/packet"; | ||
import { Decodable, Decoder, EncodableObj, Encoder, Extensible } from "@ndn/tlv"; | ||
/** 32=metadata component. */ | ||
export declare const MetadataKeyword: Component; | ||
/** RDR metadata packet content. */ | ||
export interface Metadata { | ||
/** Versioned name. */ | ||
export declare class Metadata implements EncodableObj { | ||
name: Name; | ||
/** | ||
* Constructor. | ||
* @param name versioned name. | ||
*/ | ||
constructor(name?: Name); | ||
static decodeFrom(decoder: Decoder): Metadata; | ||
encodeTo(encoder: Encoder): void; | ||
} | ||
/** Encode RDR metadata packet content. */ | ||
export declare function encodeMetadataContent({ name }: Metadata): Uint8Array; | ||
/** Decode RDR metadata packet content. */ | ||
export declare function decodeMetadataContent(wire: Uint8Array): Metadata; | ||
export declare namespace Metadata { | ||
interface Constructor<M extends Metadata = Metadata> extends Decodable<M> { | ||
new (name?: Name): M; | ||
} | ||
/** Class decorator on an extensible Metadata subclass. */ | ||
function extend<M extends Metadata & Extensible>(ctor: new () => M): void; | ||
} |
export * from "./metadata"; | ||
export * from "./consumer"; | ||
export * from "./producer"; |
import { Endpoint } from "@ndn/endpoint"; | ||
import { Segment, Version } from "@ndn/naming-convention2"; | ||
import { Data, digestSigning, Name } from "@ndn/packet"; | ||
import { encodeMetadataContent, MetadataKeyword } from "./metadata_browser.js"; | ||
import { Encoder } from "@ndn/tlv"; | ||
import { MetadataKeyword } from "./metadata_browser.js"; | ||
function makeName(payload, prefix) { | ||
@@ -10,8 +11,6 @@ const name = prefix ? new Name(prefix) : payload.name.getPrefix(-1); | ||
/** Make RDR metadata packet. */ | ||
export async function makeMetadataPacket(m, { freshnessPeriod = 1, prefix, signer = digestSigning, } = {}) { | ||
let name = prefix ? new Name(prefix) : m.name.getPrefix(-1); | ||
name = name.append(MetadataKeyword, Version.create(Date.now()), Segment.create(0)); | ||
export async function makeMetadataPacket(m, { prefix, freshnessPeriod = 1, signer = digestSigning, } = {}) { | ||
const data = new Data(); | ||
data.name = makeName(m, prefix); | ||
data.content = encodeMetadataContent(m); | ||
data.content = Encoder.encode(m); | ||
data.freshnessPeriod = freshnessPeriod; | ||
@@ -23,4 +22,3 @@ await signer.sign(data); | ||
export function isDiscoveryInterest({ name, canBePrefix, mustBeFresh }) { | ||
var _a, _b; | ||
return ((_b = (_a = name.get(-1)) === null || _a === void 0 ? void 0 : _a.equals(MetadataKeyword)) !== null && _b !== void 0 ? _b : false) && canBePrefix && mustBeFresh; | ||
return !!(name.get(-1)?.equals(MetadataKeyword)) && canBePrefix && mustBeFresh; | ||
} | ||
@@ -27,0 +25,0 @@ /** Serve RDR metadata packet in a producer. */ |
import { Endpoint } from "@ndn/endpoint"; | ||
import { Segment, Version } from "@ndn/naming-convention2"; | ||
import { Data, digestSigning, Name } from "@ndn/packet"; | ||
import { encodeMetadataContent, MetadataKeyword } from "./metadata_node.js"; | ||
import { Encoder } from "@ndn/tlv"; | ||
import { MetadataKeyword } from "./metadata_node.js"; | ||
function makeName(payload, prefix) { | ||
@@ -10,8 +11,6 @@ const name = prefix ? new Name(prefix) : payload.name.getPrefix(-1); | ||
/** Make RDR metadata packet. */ | ||
export async function makeMetadataPacket(m, { freshnessPeriod = 1, prefix, signer = digestSigning, } = {}) { | ||
let name = prefix ? new Name(prefix) : m.name.getPrefix(-1); | ||
name = name.append(MetadataKeyword, Version.create(Date.now()), Segment.create(0)); | ||
export async function makeMetadataPacket(m, { prefix, freshnessPeriod = 1, signer = digestSigning, } = {}) { | ||
const data = new Data(); | ||
data.name = makeName(m, prefix); | ||
data.content = encodeMetadataContent(m); | ||
data.content = Encoder.encode(m); | ||
data.freshnessPeriod = freshnessPeriod; | ||
@@ -23,4 +22,3 @@ await signer.sign(data); | ||
export function isDiscoveryInterest({ name, canBePrefix, mustBeFresh }) { | ||
var _a, _b; | ||
return ((_b = (_a = name.get(-1)) === null || _a === void 0 ? void 0 : _a.equals(MetadataKeyword)) !== null && _b !== void 0 ? _b : false) && canBePrefix && mustBeFresh; | ||
return !!(name.get(-1)?.equals(MetadataKeyword)) && canBePrefix && mustBeFresh; | ||
} | ||
@@ -27,0 +25,0 @@ /** Serve RDR metadata packet in a producer. */ |
import { Endpoint, Producer } from "@ndn/endpoint"; | ||
import { Data, Interest, NameLike, Signer } from "@ndn/packet"; | ||
import { Metadata } from "./metadata"; | ||
interface Options { | ||
/** | ||
* RDR metadata packet prefix. | ||
* | ||
* This should not contain 32=metadata. | ||
* | ||
* @default metadata.name.getPrefix(-1) | ||
*/ | ||
prefix?: NameLike; | ||
/** | ||
* FreshnessPeriod. | ||
* @default 1 | ||
*/ | ||
freshnessPeriod?: number; | ||
/** Signing key. */ | ||
signer?: Signer; | ||
/** Endpoint to run producer. */ | ||
endpoint?: Endpoint; | ||
/** Prefix to announce from producer. */ | ||
announcement?: Endpoint.RouteAnnouncement; | ||
/** Make RDR metadata packet. */ | ||
export declare function makeMetadataPacket(m: Metadata, { prefix, freshnessPeriod, signer, }?: makeMetadataPacket.Options): Promise<Data>; | ||
export declare namespace makeMetadataPacket { | ||
interface Options { | ||
/** | ||
* RDR metadata packet prefix. | ||
* | ||
* This should not contain 32=metadata. | ||
* | ||
* @default metadata.name.getPrefix(-1) | ||
*/ | ||
prefix?: NameLike; | ||
/** | ||
* FreshnessPeriod. | ||
* @default 1 | ||
*/ | ||
freshnessPeriod?: number; | ||
/** Signing key. */ | ||
signer?: Signer; | ||
} | ||
} | ||
/** Make RDR metadata packet. */ | ||
export declare function makeMetadataPacket(m: Metadata, { freshnessPeriod, prefix, signer, }?: Options): Promise<Data>; | ||
/** Determine if an Interest is an RDR discovery Interest. */ | ||
export declare function isDiscoveryInterest({ name, canBePrefix, mustBeFresh }: Interest): boolean; | ||
/** Serve RDR metadata packet in a producer. */ | ||
export declare function serveMetadata(m: Metadata | (() => Metadata), opts?: Options): Producer; | ||
export {}; | ||
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; | ||
} | ||
} |
{ | ||
"name": "@ndn/rdr", | ||
"version": "0.0.20210203", | ||
"version": "0.0.20210930", | ||
"description": "NDNts: RDR Protocol", | ||
@@ -25,10 +25,10 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/endpoint": "0.0.20210203", | ||
"@ndn/naming-convention2": "0.0.20210203", | ||
"@ndn/packet": "0.0.20210203", | ||
"@ndn/tlv": "0.0.20210203", | ||
"@ndn/endpoint": "0.0.20210930", | ||
"@ndn/naming-convention2": "0.0.20210930", | ||
"@ndn/packet": "0.0.20210930", | ||
"@ndn/tlv": "0.0.20210930", | ||
"abort-controller": "^3.0.0", | ||
"tslib": "^2.1.0" | ||
"tslib": "^2.3.1" | ||
}, | ||
"types": "lib/mod.d.ts" | ||
} |
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
13346
326
+ Added@ndn/endpoint@0.0.20210930(transitive)
+ Added@ndn/fw@0.0.20210930(transitive)
+ Added@ndn/naming-convention2@0.0.20210930(transitive)
+ Added@ndn/packet@0.0.20210930(transitive)
+ Added@ndn/tlv@0.0.20210930(transitive)
+ Addedit-pushable@1.4.2(transitive)
+ Addedretry@0.13.1(transitive)
+ Addedstreaming-iterables@6.2.0(transitive)
- Removed@ndn/endpoint@0.0.20210203(transitive)
- Removed@ndn/fw@0.0.20210203(transitive)
- Removed@ndn/naming-convention2@0.0.20210203(transitive)
- Removed@ndn/packet@0.0.20210203(transitive)
- Removed@ndn/tlv@0.0.20210203(transitive)
- Removedit-pushable@1.4.0(transitive)
- Removedretry@0.12.0(transitive)
- Removedstreaming-iterables@5.0.4(transitive)
Updated@ndn/endpoint@0.0.20210930
Updated@ndn/packet@0.0.20210930
Updated@ndn/tlv@0.0.20210930
Updatedtslib@^2.3.1