Class ApplicationMessage

java.lang.Object
org.drasyl.handler.remote.protocol.ApplicationMessage
All Implemented Interfaces:
io.netty.util.ReferenceCounted, AutoCloseable, FullReadMessage<ApplicationMessage>, RemoteMessage

public abstract class ApplicationMessage extends Object implements io.netty.util.ReferenceCounted, AutoCloseable
Describes a message sent by an application running on drasyl. The message's body is structured as follows:
  • Payload: The payload sent by the application (any number of bytes).

This is an immutable object.

  • Constructor Details

    • ApplicationMessage

      public ApplicationMessage()
  • Method Details

    • of

      public static ApplicationMessage of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf payload)
      Creates new application message.

      ReferenceCounted.release() ownership of getPayload() is transferred to this PartialReadMessage.

      Parameters:
      hopCount - the hop count
      isArmed - if the message is armed or not
      networkId - the network id
      nonce - the nonce
      recipient - the public key of the recipient
      sender - the public key of the sender
      proofOfWork - the proof of work of sender
      payload - the payload
      Throws:
      NullPointerException - if nonce, sender, proofOfWork, recipient, hopCount, or payload is null
    • of

      public static ApplicationMessage of(int networkId, IdentityPublicKey recipient, IdentityPublicKey sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf payload)
      Creates new application message with random Nonce, and minimal HopCount value.

      ReferenceCounted.release() ownership of getPayload() is transferred to this PartialReadMessage.

      Parameters:
      networkId - the network id
      recipient - the public key of the recipient
      sender - the public key of the sender
      proofOfWork - the proof of work of sender
      payload - the payload
      Throws:
      NullPointerException - if sender, proofOfWork, recipient, or payload is null
    • getPayload

      public abstract io.netty.buffer.ByteBuf getPayload()
      Returns the payload.
      Returns:
      the payload
    • incrementHopCount

      public ApplicationMessage incrementHopCount()
      Returns this message with incremented hop count.

      ReferenceCounted.release() ownership of getPayload() is transferred to this PartialReadMessage.

      Specified by:
      incrementHopCount in interface FullReadMessage<ApplicationMessage>
      Specified by:
      incrementHopCount in interface RemoteMessage
      Returns:
    • writePrivateHeaderTo

      protected void writePrivateHeaderTo(io.netty.buffer.ByteBuf out)
    • writeBodyTo

      protected void writeBodyTo(io.netty.buffer.ByteBuf out)
    • refCnt

      public int refCnt()
      Specified by:
      refCnt in interface io.netty.util.ReferenceCounted
    • retain

      public io.netty.util.ReferenceCounted retain()
      Specified by:
      retain in interface io.netty.util.ReferenceCounted
    • retain

      public io.netty.util.ReferenceCounted retain(int increment)
      Specified by:
      retain in interface io.netty.util.ReferenceCounted
    • touch

      public io.netty.util.ReferenceCounted touch()
      Specified by:
      touch in interface io.netty.util.ReferenceCounted
    • touch

      public io.netty.util.ReferenceCounted touch(Object hint)
      Specified by:
      touch in interface io.netty.util.ReferenceCounted
    • release

      public boolean release()
      Specified by:
      release in interface io.netty.util.ReferenceCounted
    • release

      public boolean release(int decrement)
      Specified by:
      release in interface io.netty.util.ReferenceCounted
    • close

      public void close() throws Exception
      Calls release().
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • arm

      public ArmedProtocolMessage arm(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException
      Description copied from interface: FullReadMessage
      Returns an armed version (ArmedProtocolMessage) of this message for sending it through untrustworthy channels.
      Specified by:
      arm in interface FullReadMessage<T extends FullReadMessage<?>>
      cryptoInstance - the crypto instance that should be used
      sessionPair - will be used for encryption
      Returns:
      the armed version of this message
      Throws:
      InvalidMessageFormatException - if arming was not possible
    • writeTo

      public void writeTo(io.netty.buffer.ByteBuf out)
      Description copied from interface: RemoteMessage
      Writes this message to the buffer out.
      Specified by:
      writeTo in interface RemoteMessage
      Parameters:
      out - writes this envelope to this buffer
    • writePublicHeaderTo

      protected void writePublicHeaderTo(io.netty.buffer.ByteBuf out)