/
packet.ts
44 lines (38 loc) · 1.18 KB
/
packet.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { Data, Interest, Nack } from "@ndn/packet";
type L3Pkt = Interest | Data | Nack;
/** A logical packet in the logical forwarder. */
export interface FwPacket<T extends L3Pkt = L3Pkt> {
l3: T;
token?: unknown;
congestionMark?: number;
reject?: RejectInterest.Reason;
cancel?: boolean;
}
export namespace FwPacket {
export function create<T extends L3Pkt>(l3: T, token?: unknown, congestionMark?: number): FwPacket<T> {
return { l3, token, congestionMark };
}
/** Determine whether this is a plain packet that can be sent on the wire. */
export function isEncodable({ reject, cancel }: FwPacket): boolean {
return !reject && !cancel;
}
}
/** Indicate an Interest has been rejected. */
export class RejectInterest implements FwPacket<Interest> {
constructor(
public reject: RejectInterest.Reason,
public l3: Interest,
public token?: unknown,
) {}
}
export namespace RejectInterest {
export type Reason = "cancel" | "expire";
}
/** Request to cancel a pending Interest. */
export class CancelInterest implements FwPacket<Interest> {
constructor(
public l3: Interest,
public token?: unknown,
) {}
public readonly cancel = true;
}