All Implemented Interfaces:
I2NPMessage

public class GarlicMessageextends FastI2NPMessageImpl
Defines the wrapped garlic message.
  • Field Details

    • MESSAGE_TYPE

      public static final int MESSAGE_TYPE
      I2NP message type code for a garlic message.
      See Also:
  • Constructor Details

    • GarlicMessage

      public GarlicMessage(I2PAppContext context)
      Creates an empty garlic message, to be filled in on read.
      Parameters:
      context - the app context supplying the log, the clock that stamps the expiry and the random source for message ids
  • Method Details

    • getData

      public byte[] getData()
      The raw message data.
      Returns:
      the raw garlic payload bytes, or null if never set
    • setData

      public void setData(byte[] data)
      The raw message data.
      Parameters:
      data - the complete garlic payload; settable only once, so the saved
      Throws:
      IllegalStateException - if data previously set, to protect saved checksum checksum cannot be invalidated
    • readMessage

      public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException
      Read the message from a byte array.
      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) throws I2NPMessageException
      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)
      Throws:
      I2NPMessageException - if the body cannot be serialized into out, because it is too small or a field is unserializable
    • getType

      public int getType()
      The I2NP message type of a garlic message.
      Returns:
      the I2NP message type number, for dispatch
    • hashCode

      public int hashCode()
      Hash code based on the message data.
      Overrides:
      hashCode in class Object
      Returns:
      whether h code is present
    • equals

      public boolean equals(Object object)
      Compare the message data for equality.
      Overrides:
      equals in class Object
    • toString

      public String toString()
      String form for debugging, showing the id and data length.
      Overrides:
      toString in class Object