Skip to content

Commit

Permalink
packet: deprecate new Component(undefined, ..)
Browse files Browse the repository at this point in the history
`undefined` means GenericNameComponent but is unreadable.
  • Loading branch information
yoursunny committed Mar 10, 2024
1 parent dd79029 commit d7a6efe
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pkg/fileserver/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ConsumerOptions } from "@ndn/endpoint";
import { Component, type Name } from "@ndn/packet";
import { Component, type Name, TT } from "@ndn/packet";
import { retrieveMetadata } from "@ndn/rdr";
import { fetch } from "@ndn/segmented-object";
import { assert } from "@ndn/util";
Expand Down Expand Up @@ -40,7 +40,7 @@ export class Client {
if (child) {
yield child.name;
}
})(), (comp) => new Component(undefined, comp)));
})(), (comp) => new Component(TT.GenericNameComponent, comp)));
return retrieveMetadata(name, FileMetadata, this.opts);
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/naming-convention1/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Markered implements NumberConvention {
}

public create(v: number | bigint): Component {
return new Component(undefined, Encoder.encode([this.marker, NNI(v)], 9));
return new Component(TT.GenericNameComponent, Encoder.encode([this.marker, NNI(v)], 9));
}

public parse(comp: Component): number {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ndncert/src/packet/challenge-request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NamedSigner, NamedVerifier } from "@ndn/keychain";
import { Component, Interest, type LLDecrypt, type LLEncrypt, type SignedInterestPolicy } from "@ndn/packet";
import { Component, Interest, type LLDecrypt, type LLEncrypt, type SignedInterestPolicy, TT as l3TT } from "@ndn/packet";
import { Decoder, Encoder, EvDecoder } from "@ndn/tlv";
import { toUtf8 } from "@ndn/util";
import type { Promisable } from "type-fest";
Expand Down Expand Up @@ -125,7 +125,7 @@ export namespace ChallengeRequest {
]);

const interest = new Interest();
interest.name = profile.prefix.append(C.CA, C.CHALLENGE, new Component(undefined, requestId));
interest.name = profile.prefix.append(C.CA, C.CHALLENGE, new Component(l3TT.GenericNameComponent, requestId));
interest.mustBeFresh = true;
interest.appParameters = encrypted_payload.encode(
await sessionEncrypter.llEncrypt({ plaintext: payload, additionalData: requestId }));
Expand Down
4 changes: 3 additions & 1 deletion pkg/nfdmgmt/src/status-dataset-nfd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ buildFaceQueryFilter.subclass = FaceQueryFilter;
export function FaceQuery(filter: FaceQuery.Filter): StatusDataset<FaceStatus> {
return {
datasetName: "faces/query",
datasetParams: [new Component(undefined, Encoder.encode(Object.assign(new FaceQueryFilter(), filter)))],
datasetParams: [
new Component(l3TT.GenericNameComponent, Encoder.encode(Object.assign(new FaceQueryFilter(), filter))),
],
decodeFrom: FaceStatus.decodeFrom,
};
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/packet/src/name/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export class Component {
return new Component(type, FROM, encoder, length); // eslint-disable-line etc/no-internal
}

/**
* Construct GenericNameComponent from TLV-VALUE.
* @deprecated Pass `TT.GenericNameComponent` as type.
*/
constructor(type: undefined, value: Uint8Array | string);

/**
* Construct from TLV-TYPE and TLV-VALUE.
* @param type - TLV-TYPE. Default is GenericNameComponent.
Expand Down
1 change: 1 addition & 0 deletions pkg/packet/tests/component.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test("decode", () => {
expect(comp.toString()).toEqual("240=A%01%A0");
expect(AltUri.ofComponent(comp)).toEqual("240=A%01%A0");

// eslint-disable-next-line etc/no-deprecated
comp = new Component(undefined, Uint8Array.of(0x2E, 0x2E, 0x2E, 0x42));
expect(comp.type).toBe(0x08);
expect(comp.value).toEqualUint8Array([0x2E, 0x2E, 0x2E, 0x42]);
Expand Down
4 changes: 2 additions & 2 deletions pkg/psync/src/detail/iblt-codec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from "@ndn/packet";
import { Component, TT } from "@ndn/packet";

import { IBLT } from "../iblt";

Expand All @@ -12,7 +12,7 @@ export class IbltCodec {
declare protected readonly ibltParams: IBLT.PreparedParameters;

public iblt2comp(iblt: IBLT): Component {
return new Component(undefined, this.ibltCompression.compress(iblt.serialize()));
return new Component(TT.GenericNameComponent, this.ibltCompression.compress(iblt.serialize()));
}

public comp2iblt(comp: Component): IBLT {
Expand Down
2 changes: 1 addition & 1 deletion pkg/psync/src/psync/param-compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function makePSyncCompatParam({
return [
GenericNumber.create(bf.projectedElementCount),
GenericNumber.create(Math.trunc(bf.falsePositiveProbability * 1000)),
new Component(undefined, bf.encode()),
new Component(TT.GenericNameComponent, bf.encode()),
];
},
decodeBloom(Bloom, comps) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/pyrepo/src/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export interface Verb {
}

export const InsertVerb = {
action: new Component(undefined, "insert"),
check: new Component(undefined, "insert check"),
action: new Component(l3TT.GenericNameComponent, "insert"),
check: new Component(l3TT.GenericNameComponent, "insert check"),
};

export const DeleteVerb = {
action: new Component(undefined, "delete"),
check: new Component(undefined, "delete check"),
action: new Component(l3TT.GenericNameComponent, "delete"),
check: new Component(l3TT.GenericNameComponent, "delete check"),
};

const enum TT {
Expand Down
2 changes: 1 addition & 1 deletion pkg/pyrepo/src/prps/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class NotifyAppParam extends buildNotifyAppParam.baseClass<NotifyAppParam
public makeMsgInterest(topic: Name): Interest {
const interest = new Interest();
interest.name = this.publisher.append(
MsgSuffix, ...topic.comps, new Component(undefined, this.nonce));
MsgSuffix, ...topic.comps, new Component(l3TT.GenericNameComponent, this.nonce));
interest.fwHint = this.publisherFwHint && new FwHint(this.publisherFwHint);
return interest;
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/pyrepo/src/prps/publisher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { consume, ConsumerOptions, type Endpoint, produce, type Producer, type ProducerHandler, ProducerOptions } from "@ndn/endpoint";
import { Forwarder } from "@ndn/fw";
import { SequenceNum } from "@ndn/naming-convention2";
import { Component, Data, digestSigning, Interest, Name, NameMap, SignedInterestPolicy, type Signer } from "@ndn/packet";
import { Component, Data, digestSigning, Interest, Name, NameMap, SignedInterestPolicy, type Signer, TT } from "@ndn/packet";
import { type Encodable, Encoder } from "@ndn/tlv";
import { crypto } from "@ndn/util";
import { type SetRequired } from "type-fest";
Expand Down Expand Up @@ -71,7 +71,10 @@ export class PrpsPublisher implements Disposable {
let key: Name;
do {
crypto.getRandomValues(notifyNonce);
key = this.pubPrefix.append(MsgSuffix, ...topic.comps, new Component(undefined, notifyNonce));
key = this.pubPrefix.append(
MsgSuffix, ...topic.comps,
new Component(TT.GenericNameComponent, notifyNonce),
);
} while (this.pendings.has(key));

this.pendings.set(key, { topic, item });
Expand Down

0 comments on commit d7a6efe

Please sign in to comment.