public class Message
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
private static Record[] |
emptyRecordArray |
private TSIGRecord |
generatedTsig |
private Header |
header |
static int |
MAXLENGTH
The maximum length of a message in wire format.
|
private TSIGRecord |
querytsig |
private Resolver |
resolver |
private java.util.List<Record>[] |
sections |
(package private) int |
sig0start |
private int |
size |
(package private) static int |
TSIG_FAILED
The message was signed and verification failed, or was not signed when it should have been.
|
(package private) static int |
TSIG_INTERMEDIATE
The message was an unsigned message in multiple-message response
|
(package private) static int |
TSIG_SIGNED
The message was signed and no verification was attempted.
|
(package private) static int |
TSIG_UNSIGNED
The message was not signed
|
(package private) static int |
TSIG_VERIFIED
The message was signed and verification succeeded
|
private int |
tsigerror |
private TSIG |
tsigkey |
(package private) int |
tsigstart |
(package private) int |
tsigState |
Modifier | Constructor and Description |
---|---|
|
Message()
Creates a new Message with a random Message ID
|
|
Message(byte[] b)
Creates a new Message from its DNS wire format representation
|
|
Message(java.nio.ByteBuffer byteBuffer)
Creates a new Message from its DNS wire format representation
|
(package private) |
Message(DNSInput in) |
private |
Message(Header header) |
|
Message(int id)
Creates a new Message with the specified Message ID
|
Modifier and Type | Method and Description |
---|---|
private void |
addAdditionalRRset(RRset rrset,
java.util.List<RRset> additionalSectionSets,
java.util.List<RRset> cleanedAdditionalSection) |
void |
addRecord(Record r,
int section)
Adds a record to a section of the Message, and adjusts the header.
|
Message |
clone()
Creates a copy of this Message.
|
private boolean |
doesTypeHaveAdditionalRecords(int type) |
boolean |
findRecord(Record r)
Determines if the given record is already present in any section.
|
boolean |
findRecord(Record r,
int section)
Determines if the given record is already present in the given section.
|
boolean |
findRRset(Name name,
int type)
Determines if an RRset with the given name and type is already present in any section.
|
boolean |
findRRset(Name name,
int type,
int section)
Determines if an RRset with the given name and type is already present in the given section.
|
(package private) TSIGRecord |
getGeneratedTSIG()
Gets the generated
TSIGRecord . |
Header |
getHeader()
Retrieves the Header.
|
OPTRecord |
getOPT()
Returns the OPT record from the ADDITIONAL section, if one is present.
|
Record |
getQuestion()
Returns the first record in the QUESTION section.
|
int |
getRcode()
Returns the message's rcode (error code).
|
java.util.Optional<Resolver> |
getResolver()
Gets the resolver that originally received this Message from a server.
|
java.util.List<Record> |
getSection(int section)
Returns all records in the given section, or an empty list if the section is empty.
|
Record[] |
getSectionArray(int section)
Deprecated.
use
getSection(int) |
java.util.List<RRset> |
getSectionRRsets(int section)
Returns an array containing all records in the given section grouped into RRsets.
|
TSIGRecord |
getTSIG()
Returns the TSIG record from the ADDITIONAL section, if one is present.
|
boolean |
isSigned()
Was this message signed by a TSIG?
|
(package private) boolean |
isTypeAllowedInSection(int type,
int section)
|
boolean |
isVerified()
If this message was signed by a TSIG, was the TSIG verified?
|
private void |
logOrThrow(boolean throwOnIrrelevantRecord,
java.lang.String format,
RRset rrset,
Name sname,
Message query) |
static Message |
newQuery(Record r)
Creates a new Message with a random Message ID suitable for sending as a query.
|
static Message |
newUpdate(Name zone)
Creates a new Message to contain a dynamic update.
|
Message |
normalize(Message query)
Creates a normalized copy of this message by following xNAME chains, synthesizing CNAMEs from
DNAMEs if necessary, and removing illegal RRsets from
Section.AUTHORITY and Section.ADDITIONAL . |
Message |
normalize(Message query,
boolean throwOnIrrelevantRecord)
Creates a normalized copy of this message by following xNAME chains, synthesizing CNAMEs from
DNAMEs if necessary, and removing illegal RRsets from
Section.AUTHORITY and Section.ADDITIONAL . |
int |
numBytes()
Returns the size of the message.
|
void |
removeAllRecords(int section)
Removes all records from a section of the Message, and adjusts the header.
|
boolean |
removeRecord(Record r,
int section)
Removes a record from a section of the Message, and adjusts the header.
|
private java.util.List<Record> |
rrsetListToRecords(java.util.List<RRset> rrsets) |
java.lang.String |
sectionToString(int section)
Converts the given section of the Message to a String.
|
private void |
sectionToString(java.lang.StringBuilder sb,
int i) |
private int |
sectionToWire(DNSOutput out,
int section,
Compression c,
int maxLength) |
void |
setHeader(Header h)
Replaces the Header with a new one.
|
void |
setResolver(Resolver resolver)
Sets the resolver that originally received this Message from a server.
|
void |
setTSIG(TSIG key)
Sets the TSIG key to sign a message.
|
void |
setTSIG(TSIG key,
int error,
TSIGRecord querytsig)
Sets the TSIG key and other necessary information to sign a message.
|
java.lang.String |
toString()
Converts the Message to a String.
|
byte[] |
toWire()
Returns an array containing the wire format representation of the
Message , but does not
do any additional processing (e.g. |
(package private) void |
toWire(DNSOutput out) |
private void |
toWire(DNSOutput out,
int maxLength) |
byte[] |
toWire(int maxLength)
Returns an array containing the wire format representation of the Message with the specified
maximum length.
|
public static final int MAXLENGTH
private Header header
private java.util.List<Record>[] sections
private int size
private TSIG tsigkey
private TSIGRecord generatedTsig
private TSIGRecord querytsig
private int tsigerror
private Resolver resolver
int tsigstart
int tsigState
int sig0start
static final int TSIG_UNSIGNED
static final int TSIG_VERIFIED
static final int TSIG_INTERMEDIATE
static final int TSIG_SIGNED
static final int TSIG_FAILED
private static final Record[] emptyRecordArray
private Message(Header header)
public Message(int id)
public Message()
Message(DNSInput in) throws java.io.IOException
java.io.IOException
public Message(byte[] b) throws java.io.IOException
b
- A byte array containing the DNS Message.java.io.IOException
public Message(java.nio.ByteBuffer byteBuffer) throws java.io.IOException
byteBuffer
- A ByteBuffer containing the DNS Message.java.io.IOException
public static Message newQuery(Record r)
r
- A record containing the questionpublic static Message newUpdate(Name zone)
zone
- The zone to be updatedpublic void addRecord(Record r, int section)
public boolean removeRecord(Record r, int section)
public void removeAllRecords(int section)
public boolean findRecord(Record r, int section)
public boolean findRecord(Record r)
public boolean findRRset(Name name, int type, int section)
public boolean findRRset(Name name, int type)
public Record getQuestion()
public TSIGRecord getTSIG()
TSIGRecord
,
TSIG
,
Section
TSIGRecord getGeneratedTSIG()
TSIGRecord
. Only valid if the messages has been converted to wire
format with toWire(int)
before.null
.public boolean isSigned()
TSIG
public boolean isVerified()
TSIG
public OPTRecord getOPT()
public int getRcode()
@Deprecated public Record[] getSectionArray(int section)
getSection(int)
public java.util.List<Record> getSection(int section)
public java.util.List<RRset> getSectionRRsets(int section)
void toWire(DNSOutput out)
private int sectionToWire(DNSOutput out, int section, Compression c, int maxLength)
private void toWire(DNSOutput out, int maxLength)
public byte[] toWire()
Message
, but does not
do any additional processing (e.g. OPT/TSIG records, truncation).
Do NOT use this to actually transmit a message, use toWire(int)
instead.
public byte[] toWire(int maxLength)
setTSIG(TSIG,
int, TSIGRecord)
. This method may return an empty byte array if the message could not be
rendered at all; this could happen if maxLength is smaller than a DNS header, for example.
Do NOT use this method in conjunction with TSIG.apply(Message, TSIGRecord)
, it
produces inconsistent results! Use setTSIG(TSIG, int, TSIGRecord)
instead.
public void setTSIG(TSIG key)
key
- The TSIG key.public void setTSIG(TSIG key, int error, TSIGRecord querytsig)
key
- The TSIG key.error
- The value of the TSIG error field.querytsig
- If this is a response, the TSIG from the request.public int numBytes()
public java.lang.String sectionToString(int section)
Section
private void sectionToString(java.lang.StringBuilder sb, int i)
public java.lang.String toString()
toString
in class java.lang.Object
public Message clone()
clone
in class java.lang.Object
Resolver
,
TSIGRecord
,
OPTRecord
public void setResolver(Resolver resolver)
public java.util.Optional<Resolver> getResolver()
boolean isTypeAllowedInSection(int type, int section)
true
if the type is allowed, false
otherwise.public Message normalize(Message query)
Section.AUTHORITY
and Section.ADDITIONAL
.
Normalization is only applied to Rcode.NOERROR
and Rcode.NXDOMAIN
responses.
This method is equivalent to calling normalize(Message, boolean)
with false
.
query
- The query that produced this message.null
if the message could not be normalized or is otherwise invalid.public Message normalize(Message query, boolean throwOnIrrelevantRecord) throws WireParseException
Section.AUTHORITY
and Section.ADDITIONAL
.
Normalization is only applied to Rcode.NOERROR
and Rcode.NXDOMAIN
responses.
query
- The query that produced this message.throwOnIrrelevantRecord
- If true
, throw an exception instead of silently ignoring
irrelevant records.null
if the message could not be normalized or is otherwise invalid.WireParseException
- when throwOnIrrelevantRecord
is true
and an invalid
or irrelevant record was found.private void logOrThrow(boolean throwOnIrrelevantRecord, java.lang.String format, RRset rrset, Name sname, Message query) throws WireParseException
WireParseException
private void addAdditionalRRset(RRset rrset, java.util.List<RRset> additionalSectionSets, java.util.List<RRset> cleanedAdditionalSection)
private boolean doesTypeHaveAdditionalRecords(int type)