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
  • Constructor Details

    • ApplicationMessage

      public ApplicationMessage()
  • Method Details

    • 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
    • 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
    • arm

      public ArmedProtocolMessage arm(io.netty.buffer.ByteBuf byteBuf, 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<?>>
      Parameters:
      byteBuf - the ByteBuf to write through
      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)