Class PublicHeader
java.lang.Object
org.drasyl.handler.remote.protocol.PublicHeader
This class models the public header of a drasyl protocol message. The header is structured as
follows:
- Armed: The 1 byte armed value. Indicates, if the message is armed or not.
- HopCount: The 1 byte hop count value. Is incremented on each hop. Used to avoid loops.
- NetworkId: The 4 bytes network id value. Is a unique network-wide value. Used to filter messages from other networks.
- Nonce: The 24 bytes nonce value. Is used for encryption and as message id.
- Recipient: The 32 bytes recipient address. This value is optional. If not set it MUST be sent as 0.
- Sender: The 32 bytes sender address.
- ProofOfWork: The 4 bytes proof of work for the sender address.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
Builds the authentication tag from this public header.abstract boolean
getArmed()
abstract HopCount
abstract int
abstract Nonce
getNonce()
abstract ProofOfWork
abstract DrasylAddress
abstract DrasylAddress
static PublicHeader
of
(io.netty.buffer.ByteBuf byteBuf) static PublicHeader
of
(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork) static PublicHeader
of
(RemoteMessage msg) void
writeTo
(io.netty.buffer.ByteBuf byteBuf) Writes this header to the bufferbyteBuf
.void
writeTo
(io.netty.buffer.ByteBuf byteBuf, boolean withHopCount) Writes this header to the bufferbyteBuf
.
-
Field Details
-
LENGTH
public static final int LENGTH- See Also:
-
-
Constructor Details
-
PublicHeader
public PublicHeader()
-
-
Method Details
-
getHopCount
-
getArmed
public abstract boolean getArmed() -
getNetworkId
public abstract int getNetworkId() -
getNonce
-
getRecipient
-
getSender
-
getProofOfWork
-
of
public static PublicHeader of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork) -
of
-
buildAuthTag
public byte[] buildAuthTag()Builds the authentication tag from this public header.- Returns:
- the authentication tag
-
writeTo
public void writeTo(io.netty.buffer.ByteBuf byteBuf, boolean withHopCount) Writes this header to the bufferbyteBuf
.- Parameters:
byteBuf
- writes this header to the given bufferwithHopCount
- if the hop count should be included
-
writeTo
public void writeTo(io.netty.buffer.ByteBuf byteBuf) Writes this header to the bufferbyteBuf
. Similar to#writeTo(ByteBuf, true)
.- Parameters:
byteBuf
- writes this header to the given buffer
-
of
- Throws:
InvalidMessageFormatException
-