@ndn/nfdmgmt
Advanced tools
Comparing version 0.0.20210203 to 0.0.20210930
@@ -13,3 +13,3 @@ import { Endpoint } from "@ndn/endpoint"; | ||
function getPrefix(isLocal) { | ||
return (isLocal !== null && isLocal !== void 0 ? isLocal : false) ? ControlCommand.localhostPrefix : ControlCommand.localhopPrefix; | ||
return (isLocal ?? false) ? ControlCommand.localhostPrefix : ControlCommand.localhopPrefix; | ||
} | ||
@@ -16,0 +16,0 @@ ControlCommand.getPrefix = getPrefix; |
@@ -13,3 +13,3 @@ import { Endpoint } from "@ndn/endpoint"; | ||
function getPrefix(isLocal) { | ||
return (isLocal !== null && isLocal !== void 0 ? isLocal : false) ? ControlCommand.localhostPrefix : ControlCommand.localhopPrefix; | ||
return (isLocal ?? false) ? ControlCommand.localhostPrefix : ControlCommand.localhopPrefix; | ||
} | ||
@@ -16,0 +16,0 @@ ControlCommand.getPrefix = getPrefix; |
@@ -0,0 +0,0 @@ import { Endpoint } from "@ndn/endpoint"; |
@@ -30,3 +30,3 @@ import { Name, TT } from "@ndn/packet"; | ||
switch (true) { | ||
case typeof value === "undefined": | ||
case value === undefined: | ||
return undefined; | ||
@@ -33,0 +33,0 @@ case type === NNI: |
@@ -30,3 +30,3 @@ import { Name, TT } from "@ndn/packet"; | ||
switch (true) { | ||
case typeof value === "undefined": | ||
case value === undefined: | ||
return undefined; | ||
@@ -33,0 +33,0 @@ case type === NNI: |
import { Name } from "@ndn/packet"; | ||
import { Encoder } from "@ndn/tlv"; | ||
interface Fields { | ||
name?: Name; | ||
faceId?: number; | ||
uri?: string; | ||
localUri?: string; | ||
origin?: number; | ||
cost?: number; | ||
capacity?: number; | ||
count?: number; | ||
baseCongestionMarkingInterval?: number; | ||
defaultCongestionPeriod?: number; | ||
mtu?: number; | ||
flags?: number; | ||
mask?: number; | ||
strategy?: Name; | ||
expirationPeriod?: number; | ||
facePersistency?: number; | ||
} | ||
/** NFD Management ControlParameters struct (encoding only). */ | ||
export declare class ControlParameters { | ||
constructor(value?: Fields); | ||
constructor(value?: ControlParameters.Fields); | ||
encodeTo(encoder: Encoder): void; | ||
@@ -28,6 +10,21 @@ } | ||
} | ||
declare type Fields_ = Fields; | ||
export declare namespace ControlParameters { | ||
type Fields = Fields_; | ||
interface Fields { | ||
name?: Name; | ||
faceId?: number; | ||
uri?: string; | ||
localUri?: string; | ||
origin?: number; | ||
cost?: number; | ||
capacity?: number; | ||
count?: number; | ||
baseCongestionMarkingInterval?: number; | ||
defaultCongestionPeriod?: number; | ||
mtu?: number; | ||
flags?: number; | ||
mask?: number; | ||
strategy?: Name; | ||
expirationPeriod?: number; | ||
facePersistency?: number; | ||
} | ||
} | ||
export {}; |
@@ -0,0 +0,0 @@ import { Decoder } from "@ndn/tlv"; |
@@ -0,0 +0,0 @@ export * from "./control-command"; |
@@ -7,9 +7,14 @@ import { Endpoint } from "@ndn/endpoint"; | ||
import { ControlCommand } from "./control-command_browser.js"; | ||
const PRELOAD_INTEREST_LIFETIME = Interest.Lifetime(500); | ||
class NfdPrefixReg extends ReadvertiseDestination { | ||
constructor(face, opts) { | ||
var _a; | ||
super(opts.retry); | ||
this.face = face; | ||
this.preloadCerts = new Map(); | ||
this.handleFaceUp = () => { | ||
for (const [nameHex, { status, state }] of this.table) { | ||
if (status === ReadvertiseDestination.Status.ADVERTISED) { | ||
this.scheduleRefresh(nameHex, state, 100); | ||
} | ||
} | ||
}; | ||
this.commandOptions = { | ||
@@ -21,10 +26,17 @@ commandPrefix: ControlCommand.getPrefix(face.attributes.local), | ||
origin: 65, | ||
cost: 87, | ||
cost: 0, | ||
flags: 0x02, | ||
...opts, | ||
}; | ||
this.refreshInterval = (_a = opts.refreshInterval) !== null && _a !== void 0 ? _a : 300000; | ||
this.refreshInterval = opts.refreshInterval ?? 300000; | ||
this.preloadCertName = opts.preloadCertName; | ||
this.preloadFromKeyChain = opts.preloadFromKeyChain; | ||
this.preloadInterestLifetime = Interest.Lifetime(opts.preloadInterestLifetime ?? 500); | ||
face.on("up", this.handleFaceUp); | ||
face.once("close", () => this.disable()); | ||
} | ||
disable() { | ||
this.face.off("up", this.handleFaceUp); | ||
super.disable(); | ||
} | ||
async tap() { | ||
@@ -42,3 +54,5 @@ const tapFace = TapFace.create(this.face); | ||
() => { | ||
preloadProducers.forEach((p) => p.close()); | ||
for (const p of preloadProducers.values()) { | ||
p.close(); | ||
} | ||
tapFace.close(); | ||
@@ -49,3 +63,2 @@ }, | ||
async preload(endpoint) { | ||
var _a; | ||
const producers = new Map(); | ||
@@ -59,3 +72,3 @@ let name = this.preloadCertName; | ||
try { | ||
const cert = (_a = this.preloadCerts.get(key)) !== null && _a !== void 0 ? _a : Certificate.fromData(await endpoint.consume(new Interest(name, Interest.CanBePrefix, PRELOAD_INTEREST_LIFETIME))); | ||
const cert = await this.retrievePreload(endpoint, key, name); | ||
this.preloadCerts.set(key, cert); | ||
@@ -71,2 +84,17 @@ producers.set(key, endpoint.produce(name, () => Promise.resolve(cert.data))); | ||
} | ||
async retrievePreload(endpoint, key, name) { | ||
const cert = this.preloadCerts.get(key); | ||
if (cert) { | ||
return cert; | ||
} | ||
if (this.preloadFromKeyChain) { | ||
try { | ||
return await this.preloadFromKeyChain.getCert(name); | ||
} | ||
catch { } | ||
} | ||
const interest = new Interest(name, Interest.CanBePrefix, this.preloadInterestLifetime); | ||
const data = await endpoint.consume(interest); | ||
return Certificate.fromData(data); | ||
} | ||
async doAdvertise(name, state, nameHex) { | ||
@@ -88,10 +116,16 @@ const [opts, untap] = await this.tap(); | ||
} | ||
if (typeof this.refreshInterval === "number") { | ||
clearTimeout(state.refreshTimer); | ||
state.refreshTimer = setTimeout(() => { | ||
this.table.get(nameHex).status = ReadvertiseDestination.Status.ADVERTISING; | ||
this.queue.push(nameHex); | ||
}, this.refreshInterval); | ||
if (this.refreshInterval !== false) { | ||
this.scheduleRefresh(nameHex, state, this.refreshInterval); | ||
} | ||
} | ||
scheduleRefresh(nameHex, state, after) { | ||
clearTimeout(state.refreshTimer); | ||
state.refreshTimer = setTimeout(() => { | ||
const record = this.table.get(nameHex); | ||
if (record?.status === ReadvertiseDestination.Status.ADVERTISED) { | ||
record.status = ReadvertiseDestination.Status.ADVERTISING; | ||
this.restart(nameHex, record); | ||
} | ||
}, after); | ||
} | ||
async doWithdraw(name, state) { | ||
@@ -98,0 +132,0 @@ clearTimeout(state.refreshTimer); |
@@ -7,9 +7,14 @@ import { Endpoint } from "@ndn/endpoint"; | ||
import { ControlCommand } from "./control-command_node.js"; | ||
const PRELOAD_INTEREST_LIFETIME = Interest.Lifetime(500); | ||
class NfdPrefixReg extends ReadvertiseDestination { | ||
constructor(face, opts) { | ||
var _a; | ||
super(opts.retry); | ||
this.face = face; | ||
this.preloadCerts = new Map(); | ||
this.handleFaceUp = () => { | ||
for (const [nameHex, { status, state }] of this.table) { | ||
if (status === ReadvertiseDestination.Status.ADVERTISED) { | ||
this.scheduleRefresh(nameHex, state, 100); | ||
} | ||
} | ||
}; | ||
this.commandOptions = { | ||
@@ -21,10 +26,17 @@ commandPrefix: ControlCommand.getPrefix(face.attributes.local), | ||
origin: 65, | ||
cost: 87, | ||
cost: 0, | ||
flags: 0x02, | ||
...opts, | ||
}; | ||
this.refreshInterval = (_a = opts.refreshInterval) !== null && _a !== void 0 ? _a : 300000; | ||
this.refreshInterval = opts.refreshInterval ?? 300000; | ||
this.preloadCertName = opts.preloadCertName; | ||
this.preloadFromKeyChain = opts.preloadFromKeyChain; | ||
this.preloadInterestLifetime = Interest.Lifetime(opts.preloadInterestLifetime ?? 500); | ||
face.on("up", this.handleFaceUp); | ||
face.once("close", () => this.disable()); | ||
} | ||
disable() { | ||
this.face.off("up", this.handleFaceUp); | ||
super.disable(); | ||
} | ||
async tap() { | ||
@@ -42,3 +54,5 @@ const tapFace = TapFace.create(this.face); | ||
() => { | ||
preloadProducers.forEach((p) => p.close()); | ||
for (const p of preloadProducers.values()) { | ||
p.close(); | ||
} | ||
tapFace.close(); | ||
@@ -49,3 +63,2 @@ }, | ||
async preload(endpoint) { | ||
var _a; | ||
const producers = new Map(); | ||
@@ -59,3 +72,3 @@ let name = this.preloadCertName; | ||
try { | ||
const cert = (_a = this.preloadCerts.get(key)) !== null && _a !== void 0 ? _a : Certificate.fromData(await endpoint.consume(new Interest(name, Interest.CanBePrefix, PRELOAD_INTEREST_LIFETIME))); | ||
const cert = await this.retrievePreload(endpoint, key, name); | ||
this.preloadCerts.set(key, cert); | ||
@@ -71,2 +84,17 @@ producers.set(key, endpoint.produce(name, () => Promise.resolve(cert.data))); | ||
} | ||
async retrievePreload(endpoint, key, name) { | ||
const cert = this.preloadCerts.get(key); | ||
if (cert) { | ||
return cert; | ||
} | ||
if (this.preloadFromKeyChain) { | ||
try { | ||
return await this.preloadFromKeyChain.getCert(name); | ||
} | ||
catch { } | ||
} | ||
const interest = new Interest(name, Interest.CanBePrefix, this.preloadInterestLifetime); | ||
const data = await endpoint.consume(interest); | ||
return Certificate.fromData(data); | ||
} | ||
async doAdvertise(name, state, nameHex) { | ||
@@ -88,10 +116,16 @@ const [opts, untap] = await this.tap(); | ||
} | ||
if (typeof this.refreshInterval === "number") { | ||
clearTimeout(state.refreshTimer); | ||
state.refreshTimer = setTimeout(() => { | ||
this.table.get(nameHex).status = ReadvertiseDestination.Status.ADVERTISING; | ||
this.queue.push(nameHex); | ||
}, this.refreshInterval); | ||
if (this.refreshInterval !== false) { | ||
this.scheduleRefresh(nameHex, state, this.refreshInterval); | ||
} | ||
} | ||
scheduleRefresh(nameHex, state, after) { | ||
clearTimeout(state.refreshTimer); | ||
state.refreshTimer = setTimeout(() => { | ||
const record = this.table.get(nameHex); | ||
if (record?.status === ReadvertiseDestination.Status.ADVERTISED) { | ||
record.status = ReadvertiseDestination.Status.ADVERTISING; | ||
this.restart(nameHex, record); | ||
} | ||
}, after); | ||
} | ||
async doWithdraw(name, state) { | ||
@@ -98,0 +132,0 @@ clearTimeout(state.refreshTimer); |
import { FwFace, ReadvertiseDestination } from "@ndn/fw"; | ||
import { KeyChain } from "@ndn/keychain"; | ||
import { Name } from "@ndn/packet"; | ||
@@ -13,2 +14,6 @@ import { ControlCommand } from "./control-command"; | ||
preloadCertName?: Name; | ||
/** Local KeyChain to collect preloaded certificates. */ | ||
preloadFromKeyChain?: KeyChain; | ||
/** InterestLifetime for retrieving preloaded certificates. */ | ||
preloadInterestLifetime?: number; | ||
}; | ||
@@ -15,0 +20,0 @@ /** |
@@ -0,0 +0,0 @@ import { Interest, Signer } from "@ndn/packet"; |
{ | ||
"name": "@ndn/nfdmgmt", | ||
"version": "0.0.20210203", | ||
"version": "0.0.20210930", | ||
"description": "NDNts: NFD Management", | ||
@@ -25,10 +25,10 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/endpoint": "0.0.20210203", | ||
"@ndn/fw": "0.0.20210203", | ||
"@ndn/keychain": "0.0.20210203", | ||
"@ndn/packet": "0.0.20210203", | ||
"@ndn/tlv": "0.0.20210203", | ||
"tslib": "^2.1.0" | ||
"@ndn/endpoint": "0.0.20210930", | ||
"@ndn/fw": "0.0.20210930", | ||
"@ndn/keychain": "0.0.20210930", | ||
"@ndn/packet": "0.0.20210930", | ||
"@ndn/tlv": "0.0.20210930", | ||
"tslib": "^2.3.1" | ||
}, | ||
"types": "lib/mod.d.ts" | ||
} |
@@ -18,3 +18,4 @@ # @ndn/nfdmgmt | ||
import { fromUtf8, toUtf8 } from "@ndn/tlv"; | ||
import { strict as assert } from "assert"; | ||
import { strict as assert } from "node:assert"; | ||
(async () => { | ||
@@ -21,0 +22,0 @@ ``` |
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
28401
672
86
+ Added@ndn/endpoint@0.0.20210930(transitive)
+ Added@ndn/fw@0.0.20210930(transitive)
+ Added@ndn/keychain@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)
+ Addedidb-keyval@6.2.1(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/keychain@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)
- Removed@types/minimalistic-assert@1.0.3(transitive)
- Removedidb-keyval@5.1.5(transitive)
- Removedit-pushable@1.4.0(transitive)
- Removedretry@0.12.0(transitive)
- Removedsafari-14-idb-fix@1.0.6(transitive)
- Removedstreaming-iterables@5.0.4(transitive)
Updated@ndn/endpoint@0.0.20210930
Updated@ndn/fw@0.0.20210930
Updated@ndn/keychain@0.0.20210930
Updated@ndn/packet@0.0.20210930
Updated@ndn/tlv@0.0.20210930
Updatedtslib@^2.3.1