Comparing version 0.0.20230121 to 0.0.20240113
@@ -17,3 +17,3 @@ import { Endpoint } from "@ndn/endpoint"; | ||
export async function retrieveMetadata(prefix, arg2 = {}, opts = {}) { | ||
let ctor; | ||
let ctor = Metadata; | ||
if (typeof arg2 === "function") { | ||
@@ -23,3 +23,2 @@ ctor = arg2; | ||
else { | ||
ctor = Metadata; | ||
opts = arg2; | ||
@@ -35,3 +34,3 @@ } | ||
}); | ||
return new Decoder(data.content).decode(ctor); | ||
return Decoder.decode(data.content, ctor); | ||
} |
@@ -17,3 +17,3 @@ import { Endpoint } from "@ndn/endpoint"; | ||
export async function retrieveMetadata(prefix, arg2 = {}, opts = {}) { | ||
let ctor; | ||
let ctor = Metadata; | ||
if (typeof arg2 === "function") { | ||
@@ -23,3 +23,2 @@ ctor = arg2; | ||
else { | ||
ctor = Metadata; | ||
opts = arg2; | ||
@@ -35,3 +34,3 @@ } | ||
}); | ||
return new Decoder(data.content).decode(ctor); | ||
return Decoder.decode(data.content, ctor); | ||
} |
@@ -1,3 +0,3 @@ | ||
import { type RetxPolicy, Endpoint } from "@ndn/endpoint"; | ||
import { type NameLike, type Verifier, Interest } from "@ndn/packet"; | ||
import { Endpoint, type RetxPolicy } from "@ndn/endpoint"; | ||
import { Interest, type NameLike, type Verifier } from "@ndn/packet"; | ||
import { Metadata } from "./metadata.js"; | ||
@@ -4,0 +4,0 @@ /** |
@@ -9,3 +9,3 @@ import { Keyword } from "@ndn/naming-convention2"; | ||
.add(TT.Name, (t, { value }) => t.name = new Name(value), { required: true }) | ||
.setIsCritical(() => false); | ||
.setIsCritical(EvDecoder.neverCritical); | ||
} | ||
@@ -24,5 +24,3 @@ const EVD = makeEvd("Metadata"); | ||
static decodeFrom(decoder) { | ||
const metadata = new Metadata(); | ||
EVD.decodeValue(metadata, decoder); | ||
return metadata; | ||
return EVD.decodeValue(new Metadata(), decoder); | ||
} | ||
@@ -40,5 +38,3 @@ encodeTo(encoder) { | ||
value(decoder) { | ||
const metadata = new ctor(); | ||
evd.decodeValue(metadata, decoder); | ||
return metadata; | ||
return evd.decodeValue(new ctor(), decoder); | ||
}, | ||
@@ -45,0 +41,0 @@ }); |
@@ -9,3 +9,3 @@ import { Keyword } from "@ndn/naming-convention2"; | ||
.add(TT.Name, (t, { value }) => t.name = new Name(value), { required: true }) | ||
.setIsCritical(() => false); | ||
.setIsCritical(EvDecoder.neverCritical); | ||
} | ||
@@ -24,5 +24,3 @@ const EVD = makeEvd("Metadata"); | ||
static decodeFrom(decoder) { | ||
const metadata = new Metadata(); | ||
EVD.decodeValue(metadata, decoder); | ||
return metadata; | ||
return EVD.decodeValue(new Metadata(), decoder); | ||
} | ||
@@ -40,5 +38,3 @@ encodeTo(encoder) { | ||
value(decoder) { | ||
const metadata = new ctor(); | ||
evd.decodeValue(metadata, decoder); | ||
return metadata; | ||
return evd.decodeValue(new ctor(), decoder); | ||
}, | ||
@@ -45,0 +41,0 @@ }); |
import { Endpoint } from "@ndn/endpoint"; | ||
import { Segment, Version } from "@ndn/naming-convention2"; | ||
import { Data, digestSigning, Name } from "@ndn/packet"; | ||
import { Data, Name, noopSigning } from "@ndn/packet"; | ||
import { Encoder } from "@ndn/tlv"; | ||
import { MetadataKeyword } from "./metadata_browser.js"; | ||
function makeName(payload, prefix) { | ||
const name = prefix ? Name.from(prefix) : payload.name.getPrefix(-1); | ||
return name.append(MetadataKeyword, Version.create(Date.now()), Segment.create(0)); | ||
function makeName({ name }, prefix) { | ||
prefix = prefix ? Name.from(prefix) : name.getPrefix(-1); | ||
return prefix.append(MetadataKeyword, Version.create(Date.now()), Segment.create(0)); | ||
} | ||
/** Make RDR metadata packet. */ | ||
export async function makeMetadataPacket(m, { prefix, freshnessPeriod = 1, signer = digestSigning, } = {}) { | ||
export async function makeMetadataPacket(m, { prefix, freshnessPeriod = 1, signer = noopSigning, } = {}) { | ||
const data = new Data(); | ||
@@ -21,11 +21,11 @@ data.name = makeName(m, prefix); | ||
export function isDiscoveryInterest({ name, canBePrefix, mustBeFresh }) { | ||
return !!(name.get(-1)?.equals(MetadataKeyword)) && canBePrefix && mustBeFresh; | ||
return !!name.get(-1)?.equals(MetadataKeyword) && canBePrefix && mustBeFresh; | ||
} | ||
/** Serve RDR metadata packet in a producer. */ | ||
export function serveMetadata(m, opts = {}) { | ||
const { prefix, endpoint = new Endpoint() } = opts; | ||
const { prefix: prefixInput, endpoint = new Endpoint(), announcement, } = opts; | ||
const makeMetadata = typeof m === "function" ? m : () => m; | ||
const name = makeName(makeMetadata(), prefix).getPrefix(-2); | ||
return endpoint.produce(name, async (interest) => { | ||
if (isDiscoveryInterest(interest) && interest.name.length === name.length) { | ||
const prefix = makeName(makeMetadata(), prefixInput).getPrefix(-2); | ||
return endpoint.produce(prefix, async (interest) => { | ||
if (isDiscoveryInterest(interest) && interest.name.length === prefix.length) { | ||
return makeMetadataPacket(makeMetadata(), opts); | ||
@@ -35,5 +35,5 @@ } | ||
}, { | ||
describe: `RDR-s(${name})`, | ||
announcement: opts.announcement, | ||
describe: `RDR-s(${prefix})`, | ||
announcement, | ||
}); | ||
} |
import { Endpoint } from "@ndn/endpoint"; | ||
import { Segment, Version } from "@ndn/naming-convention2"; | ||
import { Data, digestSigning, Name } from "@ndn/packet"; | ||
import { Data, Name, noopSigning } from "@ndn/packet"; | ||
import { Encoder } from "@ndn/tlv"; | ||
import { MetadataKeyword } from "./metadata_node.js"; | ||
function makeName(payload, prefix) { | ||
const name = prefix ? Name.from(prefix) : payload.name.getPrefix(-1); | ||
return name.append(MetadataKeyword, Version.create(Date.now()), Segment.create(0)); | ||
function makeName({ name }, prefix) { | ||
prefix = prefix ? Name.from(prefix) : name.getPrefix(-1); | ||
return prefix.append(MetadataKeyword, Version.create(Date.now()), Segment.create(0)); | ||
} | ||
/** Make RDR metadata packet. */ | ||
export async function makeMetadataPacket(m, { prefix, freshnessPeriod = 1, signer = digestSigning, } = {}) { | ||
export async function makeMetadataPacket(m, { prefix, freshnessPeriod = 1, signer = noopSigning, } = {}) { | ||
const data = new Data(); | ||
@@ -21,11 +21,11 @@ data.name = makeName(m, prefix); | ||
export function isDiscoveryInterest({ name, canBePrefix, mustBeFresh }) { | ||
return !!(name.get(-1)?.equals(MetadataKeyword)) && canBePrefix && mustBeFresh; | ||
return !!name.get(-1)?.equals(MetadataKeyword) && canBePrefix && mustBeFresh; | ||
} | ||
/** Serve RDR metadata packet in a producer. */ | ||
export function serveMetadata(m, opts = {}) { | ||
const { prefix, endpoint = new Endpoint() } = opts; | ||
const { prefix: prefixInput, endpoint = new Endpoint(), announcement, } = opts; | ||
const makeMetadata = typeof m === "function" ? m : () => m; | ||
const name = makeName(makeMetadata(), prefix).getPrefix(-2); | ||
return endpoint.produce(name, async (interest) => { | ||
if (isDiscoveryInterest(interest) && interest.name.length === name.length) { | ||
const prefix = makeName(makeMetadata(), prefixInput).getPrefix(-2); | ||
return endpoint.produce(prefix, async (interest) => { | ||
if (isDiscoveryInterest(interest) && interest.name.length === prefix.length) { | ||
return makeMetadataPacket(makeMetadata(), opts); | ||
@@ -35,5 +35,5 @@ } | ||
}, { | ||
describe: `RDR-s(${name})`, | ||
announcement: opts.announcement, | ||
describe: `RDR-s(${prefix})`, | ||
announcement, | ||
}); | ||
} |
@@ -1,3 +0,3 @@ | ||
import { type Producer, Endpoint } from "@ndn/endpoint"; | ||
import { type Interest, type NameLike, type Signer, Data } from "@ndn/packet"; | ||
import { Endpoint, type Producer } from "@ndn/endpoint"; | ||
import { Data, type Interest, type NameLike, type Signer } from "@ndn/packet"; | ||
import { type Metadata } from "./metadata.js"; | ||
@@ -21,3 +21,6 @@ /** Make RDR metadata packet. */ | ||
freshnessPeriod?: number; | ||
/** Signing key. */ | ||
/** | ||
* Signing key. | ||
* @default noopSigning | ||
*/ | ||
signer?: Signer; | ||
@@ -24,0 +27,0 @@ } |
{ | ||
"name": "@ndn/rdr", | ||
"version": "0.0.20230121", | ||
"version": "0.0.20240113", | ||
"description": "NDNts: RDR Protocol", | ||
@@ -25,9 +25,9 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/endpoint": "0.0.20230121", | ||
"@ndn/naming-convention2": "0.0.20230121", | ||
"@ndn/packet": "0.0.20230121", | ||
"@ndn/tlv": "0.0.20230121", | ||
"tslib": "^2.4.1" | ||
"@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" | ||
}, | ||
"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
13919
326
+ Added@ndn/endpoint@0.0.20240113(transitive)
+ Added@ndn/fw@0.0.20240113(transitive)
+ Added@ndn/naming-convention2@0.0.20240113(transitive)
+ Added@ndn/packet@0.0.20240113(transitive)
+ Added@ndn/tlv@0.0.20240113(transitive)
+ Added@ndn/util@0.0.20240113(transitive)
+ Addedstreaming-iterables@8.0.1(transitive)
+ Addedtype-fest@4.30.0(transitive)
+ Addedtypescript-event-target@1.1.1(transitive)
- Removed@ndn/endpoint@0.0.20230121(transitive)
- Removed@ndn/fw@0.0.20230121(transitive)
- Removed@ndn/naming-convention2@0.0.20230121(transitive)
- Removed@ndn/packet@0.0.20230121(transitive)
- Removed@ndn/tlv@0.0.20230121(transitive)
- Removed@ndn/util@0.0.20230121(transitive)
- Removedapplymixins@1.1.0(transitive)
- Removedrxjs@7.8.1(transitive)
- Removedstreaming-iterables@7.1.0(transitive)
- Removedtyped-emitter@2.1.0(transitive)
Updated@ndn/endpoint@0.0.20240113
Updated@ndn/packet@0.0.20240113
Updated@ndn/tlv@0.0.20240113
Updatedtslib@^2.6.2