Create a new packet wrapper.
The raw DNS packet
A flag to indicate whether the packet has been sent and is therefore frozen
The raw DNS packet
Create a copy of the packet wrapper.
A copy of the packet wrapper
Freeze the packet wrapper immutably, making it read-only. This is used to prevent modifications to the packet after it has been sent. Note that this method does not modify the current packet wrapper, but instead returns a new frozen packet wrapper.
The frozen packet wrapper
The packet wrapper class is intended to solve a couple of problems with the provided
Packet type from
dns-packet`.The first is that there's currently no way to provide a read-only view of the packet, which is essential for ensuring that the packet is not modified after it has been sent.
The second is that many of the properties of the packet are optional, which leads to some awkward type assertions when using the raw packet. For example, any time you want to access the
answers
property, you have to assert that it's notundefined
ornull
, despite the fact that we can set it to an empty array if it's not provided. Likewise,questions
in practice should never be undefined, though it could of course be an empty array.This class is not generic because it heavily relies on the structure of the
Packet
type fromdns-packet
. If thePacket
type changes, this class will need to be updated.