Class PublicHeader


public abstract class PublicHeader extends Object
This class models the public header of a drasyl protocol message. The header is structured as follows:
  • Flags: Several packet flags (bits 1-3: hop count, bit 4: set if message is armed, bits 5-8: unused).
  • 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.
The public header is only authenticated and protected from the 2th byte. The hop count is not protected. This allows us to update the hop count in-place during relaying.
  • Field Details

  • Constructor Details

    • PublicHeader

      public PublicHeader()
  • Method Details

    • of

      public static PublicHeader of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork)
    • of

      public static PublicHeader of(RemoteMessage msg)
    • of

      public static PublicHeader of(io.netty.buffer.ByteBuf byteBuf) throws InvalidMessageFormatException
    • getHopCount

      public abstract HopCount getHopCount()
    • getArmed

      public abstract boolean getArmed()
    • getNetworkId

      public abstract int getNetworkId()
    • getNonce

      public abstract Nonce getNonce()
    • getRecipient

      @Nullable public abstract DrasylAddress getRecipient()
    • getSender

      public abstract DrasylAddress getSender()
    • getProofOfWork

      public abstract ProofOfWork getProofOfWork()
    • buildAuthTag

      public byte[] buildAuthTag()
      Builds the authentication tag from this public header.
      the authentication tag
    • writeTo

      public void writeTo(io.netty.buffer.ByteBuf byteBuf, boolean withHopCount)
      Writes this header to the buffer byteBuf.
      byteBuf - writes this header to the given buffer
      withHopCount - if the hop count should be included
    • writeTo

      public void writeTo(io.netty.buffer.ByteBuf byteBuf)
      Writes this header to the buffer byteBuf. Similar to #writeTo(ByteBuf, true).
      byteBuf - writes this header to the given buffer