Class ArmedProtocolMessage

java.lang.Object
org.drasyl.handler.remote.protocol.ArmedProtocolMessage
All Implemented Interfaces:
io.netty.util.ReferenceCounted, AutoCloseable, PartialReadMessage, RemoteMessage

public abstract class ArmedProtocolMessage extends Object implements PartialReadMessage
Describes a protocol message whose contents has been armed by using authenticated encryption with associated data.

Only the message recipient can decrypt and authenticate the message by calling disarm(ByteBufAllocator, Crypto, SessionPair).

This is an immutable object.

  • Field Details

  • Constructor Details

    • ArmedProtocolMessage

      public ArmedProtocolMessage()
  • Method Details

    • close

      public void close()
      Description copied from interface: PartialReadMessage
      Calls ReferenceCounted.release().
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface PartialReadMessage
    • 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
    • incrementHopCount

      public ArmedProtocolMessage incrementHopCount()
      Returns a copy of this message with incremented RemoteMessage.getHopCount().

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

      Specified by:
      incrementHopCount in interface RemoteMessage
      Returns:
      message with incremented hop count
    • disarm

      public FullReadMessage<?> disarm(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException
      Returns a disarmed version (FullReadMessage) of this message.

      Disarming will authenticate the nonce, network id, sender, sender's proof of work, recipient, agreement id, and decrypt all remaining bytes.

      Parameters:
      alloc -
      cryptoInstance - the crypto instance that should be used
      sessionPair - the SessionPair to decrypt this message
      Returns:
      the disarmed version of this message
      Throws:
      InvalidMessageFormatException - if disarming was not possible
    • disarmAndRelease

      public FullReadMessage<?> disarmAndRelease(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException
      Returns a disarmed version (FullReadMessage) of this message and then releases this message.

      Disarming will authenticate the nonce, network id, sender, sender's proof of work, recipient, agreement id, and decrypt all remaining bytes.

      Parameters:
      alloc -
      cryptoInstance - the crypto instance that should be used
      sessionPair - the SessionPair to decrypt this message
      Returns:
      the disarmed version of this message
      Throws:
      InvalidMessageFormatException - if disarming 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
    • of

      public static ArmedProtocolMessage of(Nonce nonce, HopCount hopCount, int networkId, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf bytes)
      Creates an armed message.

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

      Modifying the content of bytes or the returned message's buffer affects each other's content while they maintain separate indexes and marks.

      Parameters:
      nonce - the nonce
      hopCount - the hop count
      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
      bytes - the message's remaining armed bytes
      Throws:
      NullPointerException - if nonce, sender, proofOfWork, recipient, hopCount, agreementId, or bytes is null