Skip to content

Commit

Permalink
endpoint: delete deprecated Endpoint class
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jun 8, 2024
1 parent 13b42d3 commit b9f171c
Show file tree
Hide file tree
Showing 31 changed files with 54 additions and 442 deletions.
5 changes: 4 additions & 1 deletion pkg/cat/src/put-segmented.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export const PutSegmentedCommand: CommandModule<CommonArgs, Args> = {
});
exitClosers.push(server);
if (ver !== "none" && rdr) {
const metadataServer = serveMetadata(new Metadata(server.prefix), { signer, announcement: false });
const metadataServer = serveMetadata(new Metadata(server.prefix), {
signer,
pOpts: { announcement: false },
});
exitClosers.push(metadataServer);
}
await exitClosers.wait();
Expand Down
10 changes: 0 additions & 10 deletions pkg/endpoint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,3 @@ try {
console.log("Consumer error", err);
}
```

## `Endpoint` class deprecated

The `Endpoint` class allows inheriting consumer/producer options from constructor parameters to each consumer/producer created by `endpoint.consume()` and `endpoint.produce()` methods.
This design can cause surprising behavior when the same `Endpoint` instance is reused in different parts of the application.
Therefore, `Endpoint` class is deprecated in favor of `consume()` and `produce()` standalone functions.

APIs accepting `Endpoint` as an option are now accepting `ConsumerOptions` or `ProducerOptions` instead.

The `Endpoint` class and API acceptance of `Endpoint` instance will be deleted on or after 2024-06-05.
73 changes: 0 additions & 73 deletions pkg/endpoint/src/endpoint.ts

This file was deleted.

1 change: 0 additions & 1 deletion pkg/endpoint/src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { type ConsumerContext, ConsumerOptions, consume } from "./consumer";
export { type DataBuffer, DataStoreBuffer } from "./data-buffer";
export * from "./endpoint";
export { type ProducerHandler, ProducerOptions, type Producer, produce } from "./producer";
export type { RetxOptions, RetxGenerator, RetxPolicy } from "./retx";
9 changes: 5 additions & 4 deletions pkg/endpoint/src/producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ export interface ProducerOptions {
* @remarks
* Providing an outgoing Data buffer allows the {@link ProducerHandler} to prepare multiple Data
* packets in response to one Interest, in which one Data satisfies the current Interest and
* additional Data satisfy upcoming Interest. This is useful for a producer that generates a
* additional Data satisfy upcoming Interests. This is useful for a producer that generates a
* multi-segment response triggered by a single Interest, such as a
* {@link https://redmine.named-data.net/projects/nfd/wiki/StatusDataset | StatusDataset}
* producer in NFD Management protocol.
*
* The producer can prepare the Data packets and insert them to the DataBuffer, and then return
* `undefined`, so that the Interest is used to query the DataBuffer and the first matching Data
* is sent. The producer can also return a specify Data packet to satisfy the current Interest.
* The producer handler can prepare the Data packets and insert them to the DataBuffer. Either it
* can return `undefined`, so that the DataBuffer is queried with the current Interest and the
* first matching Data is sent. Or it can return a specific Data packet for satisfying the
* current Interest.
*/
dataBuffer?: DataBuffer;

Expand Down
10 changes: 1 addition & 9 deletions pkg/nac/src/access-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { consume, type ConsumerOptions, type Endpoint } from "@ndn/endpoint";
import { consume, type ConsumerOptions } from "@ndn/endpoint";
import { Certificate, CertNaming, createEncrypter, type CryptoAlgorithm, type NamedDecrypter, type NamedEncrypter, RSAOAEP } from "@ndn/keychain";
import { type Component, Interest, Name, type Signer, type Verifier } from "@ndn/packet";
import type { DataStore as S } from "@ndn/repo-api";
Expand All @@ -10,7 +10,6 @@ import { KeyDecryptionKey, KeyEncryptionKey } from "./packet/mod";
/** NAC access manager. */
export class AccessManager {
public static create({
endpoint, // eslint-disable-line etc/no-deprecated
cOpts,
dataStore,
prefix,
Expand All @@ -20,7 +19,6 @@ export class AccessManager {
{
describe: `NAC-AccessManager(${prefix})`,
retx: 2,
...endpoint?.cOpts,
...cOpts,
},
dataStore,
Expand Down Expand Up @@ -142,12 +140,6 @@ export namespace AccessManager {

/** {@link AccessManager.create} options. */
export interface Options {
/**
* Endpoint for communication.
* @deprecated Specify `.cOpts`.
*/
endpoint?: Endpoint;

/**
* Consumer options.
*
Expand Down
10 changes: 1 addition & 9 deletions pkg/nac/src/consumer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { consume, type ConsumerOptions, type Endpoint } from "@ndn/endpoint";
import { consume, type ConsumerOptions } from "@ndn/endpoint";
import { AESCBC, createDecrypter, type NamedDecrypter, RSAOAEP } from "@ndn/keychain";
import { type Data, type Decrypter, Interest, type Verifier } from "@ndn/packet";
import { Decoder } from "@ndn/tlv";
Expand All @@ -8,7 +8,6 @@ import { ContentKey, EncryptedContent, KeyDecryptionKey } from "./packet/mod";
/** NAC consumer. */
export class Consumer implements Decrypter {
public static create({
endpoint, // eslint-disable-line etc/no-deprecated
cOpts,
verifier,
memberDecrypter,
Expand All @@ -17,7 +16,6 @@ export class Consumer implements Decrypter {
{
describe: `NAC-Consumer(${memberDecrypter.name})`,
retx: 2,
...endpoint?.cOpts,
...cOpts,
verifier,
},
Expand Down Expand Up @@ -50,12 +48,6 @@ export class Consumer implements Decrypter {
export namespace Consumer {
/** {@link Consumer.create} options. */
export interface Options {
/**
* Endpoint for communication.
* @deprecated Specify `.cOpts`.
*/
endpoint?: Endpoint;

/**
* Consumer options.
*
Expand Down
10 changes: 1 addition & 9 deletions pkg/ndncert/src/client/probe.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { consume, type ConsumerOptions, type Endpoint } from "@ndn/endpoint";
import { consume, type ConsumerOptions } from "@ndn/endpoint";
import { CertNaming } from "@ndn/keychain";
import type { Name } from "@ndn/packet";

import { type CaProfile, ErrorMsg, type ParameterKV, ProbeRequest, ProbeResponse } from "../packet/mod";

/** {@link requestProbe} options. */
export interface ClientProbeOptions {
/**
* Endpoint for communication.
* @deprecated Specify `.cOpts`.
*/
endpoint?: Endpoint;

/**
* Consumer options.
*
Expand All @@ -31,15 +25,13 @@ export interface ClientProbeOptions {

/** Run PROBE command to determine available names. */
export async function requestProbe({
endpoint, // eslint-disable-line etc/no-deprecated
cOpts,
profile,
parameters,
}: ClientProbeOptions): Promise<ProbeResponse.Fields> {
cOpts = {
describe: `NDNCERT-client(${profile.prefix}, PROBE)`,
retx: 4,
...endpoint?.cOpts,
...cOpts,
verifier: profile.publicKey,
};
Expand Down
10 changes: 1 addition & 9 deletions pkg/ndncert/src/client/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { consume, type ConsumerOptions, type Endpoint } from "@ndn/endpoint";
import { consume, type ConsumerOptions } from "@ndn/endpoint";
import { Certificate, type NamedSigner, type NamedVerifier } from "@ndn/keychain";
import { Interest, type ValidityPeriod } from "@ndn/packet";

Expand All @@ -8,12 +8,6 @@ import type { ClientChallenge } from "./challenge";

/** {@link requestCertificate} options. */
export interface ClientOptions {
/**
* Endpoint for communication.
* @deprecated Specify `.cOpts`.
*/
endpoint?: Endpoint;

/**
* Consumer options.
*
Expand Down Expand Up @@ -46,7 +40,6 @@ export interface ClientOptions {

/** Request a certificate for the given key. */
export async function requestCertificate({
endpoint, // eslint-disable-line etc/no-deprecated
cOpts,
profile,
privateKey,
Expand All @@ -57,7 +50,6 @@ export async function requestCertificate({
cOpts = {
describe: `NDNCERT-client(${profile.prefix}, REQUEST, ${privateKey.name})`,
retx: 4,
...endpoint?.cOpts,
...cOpts,
verifier: profile.publicKey,
};
Expand Down
10 changes: 1 addition & 9 deletions pkg/ndncert/src/client/retrieve-profile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { consume, type ConsumerOptions, type Endpoint } from "@ndn/endpoint";
import { consume, type ConsumerOptions } from "@ndn/endpoint";
import { CertNaming } from "@ndn/keychain";
import { Segment } from "@ndn/naming-convention2";
import type { Name } from "@ndn/packet";
Expand All @@ -8,12 +8,6 @@ import { C, CaProfile, ProbeResponse } from "../packet/mod";

/** {@link retrieveCaProfile} options. */
export interface RetrieveCaProfileOptions {
/**
* Endpoint for communication.
* @deprecated Specify `.cOpts`.
*/
endpoint?: Endpoint;

/**
* Consumer options.
*
Expand All @@ -36,15 +30,13 @@ export interface RetrieveCaProfileOptions {

/** Retrieve and validate CA profile. */
export async function retrieveCaProfile({
endpoint, // eslint-disable-line etc/no-deprecated
cOpts,
caPrefix,
caCertFullName,
}: RetrieveCaProfileOptions): Promise<CaProfile> {
cOpts = {
describe: `NDNCERT-client(${caPrefix}, INFO)`,
retx: 4,
...endpoint?.cOpts,
...cOpts,
};
ProbeResponse.checkCaCertFullName(caCertFullName);
Expand Down
10 changes: 1 addition & 9 deletions pkg/ndncert/src/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Endpoint, produce, type Producer, type ProducerHandler, type ProducerOptions } from "@ndn/endpoint";
import { produce, type Producer, type ProducerHandler, type ProducerOptions } from "@ndn/endpoint";
import { Certificate, CertNaming, type NamedVerifier } from "@ndn/keychain";
import { Component, type ComponentLike, type Data, type FwHint, type Signer, type ValidityPeriod } from "@ndn/packet";
import { Metadata, serveMetadata } from "@ndn/rdr";
Expand All @@ -9,12 +9,6 @@ import { C, type CaProfile, ChallengeRequest, ChallengeResponse, ErrorCode, Erro
import type { ServerChallenge, ServerChallengeContext } from "./challenge";

export interface ServerOptions {
/**
* Endpoint for communication.
* @deprecated Specify `.pOpts`.
*/
endpoint?: Endpoint;

/**
* Producer options.
*
Expand Down Expand Up @@ -56,7 +50,6 @@ interface RepoDataStore {
/** NDNCERT server. */
export class Server {
public static create({
endpoint, // eslint-disable-line etc/no-deprecated
pOpts,
repo,
repoFwHint,
Expand All @@ -68,7 +61,6 @@ export class Server {
}: ServerOptions): Server {
return new Server(
{
...endpoint?.pOpts,
...pOpts,
announcement: profile.prefix.append(C.CA),
},
Expand Down
16 changes: 2 additions & 14 deletions pkg/nfdmgmt/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ConsumerOptions, Endpoint } from "@ndn/endpoint";
import { type Component, Name, type Verifier } from "@ndn/packet";
import type { ConsumerOptions } from "@ndn/endpoint";
import { type Component, Name } from "@ndn/packet";

export const localhostPrefix = new Name("/localhost/nfd");
export const localhopPrefix = new Name("/localhop/nfd");
Expand All @@ -14,12 +14,6 @@ export function getPrefix(isLocal = false) {
}

export interface CommonOptions {
/**
* Endpoint for communication.
* @deprecated Specify `.cOpts`.
*/
endpoint?: Endpoint;

/**
* Consumer options.
*
Expand All @@ -29,12 +23,6 @@ export interface CommonOptions {
*/
cOpts?: ConsumerOptions;

/**
* Data verifier.
* @deprecated Specify in `.cOpts.verifier`.
*/
verifier?: Verifier;

/**
* NFD management prefix.
* @defaultValue `getPrefix()`
Expand Down
4 changes: 0 additions & 4 deletions pkg/nfdmgmt/src/control-command-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export interface ControlCommandOptions extends CommonOptions {
*/
export async function invokeGeneric(command: string, params: Encodable, opts: ControlCommandOptions = {}): Promise<ControlResponse> {
const {
endpoint, // eslint-disable-line etc/no-deprecated
cOpts,
verifier, // eslint-disable-line etc/no-deprecated
prefix = localhostPrefix,
signer = digestSigning,
signedInterestPolicy = defaultSIP,
Expand All @@ -46,9 +44,7 @@ export async function invokeGeneric(command: string, params: Encodable, opts: Co

const data = await consume(interest, {
describe: "nfdmgmt",
...endpoint?.cOpts,
...cOpts,
verifier,
});
return Decoder.decode(data.content, ControlResponse);
}
Loading

0 comments on commit b9f171c

Please sign in to comment.