Class 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 Detail

      • ApplicationMessage

        public ApplicationMessage()
    • Method Detail

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