All Implemented Interfaces:
I2NPMessage

public class DataMessageextends FastI2NPMessageImpl
Defines a message containing arbitrary bytes of data. This is what goes in a GarlicClove.
  • Field Details

    • MESSAGE_TYPE

      public static final int MESSAGE_TYPE
      The message type identifier.
      See Also:
    • _data

      private byte[] _data
      The opaque payload.
  • Constructor Details

    • DataMessage

      public DataMessage(I2PAppContext context)
      Create a new DataMessage.
      Parameters:
      context - the router context
  • Method Details

    • getData

      public byte[] getData()
      Payload data.
      Returns:
      the payload bytes, or null if no payload was set
    • setData

      public void setData(byte[] data)
      The data payload, settable only once so the saved checksum stays valid.
      Parameters:
      data - the payload this message will carry to the far endpoint
      Throws:
      IllegalStateException - if data previously set, to protect saved checksum
    • getSize

      public int getSize()
      Payload size in bytes.
      Returns:
      the data size
    • readMessage

      public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException
      Description copied from interface: I2NPMessage
      Read the body into the data structures, after the initial type byte and the uniqueId / expiration, using the current class's format as defined by the I2NP specification.

      Implementations must not read more than dataSize, or throw I2NPMessageException or IndexOutOfBoundsException if they do.

      Parameters:
      data - data to read from
      offset - where to start in the data array
      dataSize - how long into the data to read
      type - I2NP message type
      Throws:
      I2NPMessageException - if the stream doesn't contain a valid message that this class can read.
    • calculateWrittenLength

      protected int calculateWrittenLength()
      Calculate the message body's length, not including the header and footer.
      Specified by:
      calculateWrittenLength in class I2NPMessageImpl
      Returns:
      the number of bytes the body will occupy once serialized
    • writeMessageBody

      protected int writeMessageBody(byte[] out, int curIndex)
      Write the message body to the output array, starting at the given index.
      Specified by:
      writeMessageBody in class I2NPMessageImpl
      Parameters:
      out - the buffer to serialize the body into
      curIndex - the offset into out at which to begin writing; leave room for the signature where the header format calls for one
      Returns:
      the index into the array after the last byte written (NOT the length)
    • getType

      public int getType()
      Description copied from interface: I2NPMessage
      Return the unique identifier for this type of I2NP message, as defined in the I2NP spec.
      Returns:
      the message type number, as defined in the I2NP spec
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object