All Implemented Interfaces:
Serializable, DataStructure

public class GarlicCloveextends DataStructureImpl
Contains one deliverable message encrypted to a router along with instructions and a certificate 'paying for' the delivery.

Note that certificates are always the null certificate at this time, others are unimplemented.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Pinned for serialized-form compatibility.
      See Also:
    • _context

      private final transient I2PAppContext _context
      Application context for logging and configuration.
    • _instructions

      private DeliveryInstructions _instructions
      How and where to deliver this clove.
    • _msg

      private I2NPMessage _msg
      The message payload wrapped in this clove.
    • _cloveId

      private long _cloveId
      Unique identifier for this clove.
    • _expiration

      private long _expiration
      Time after which this clove expires.
    • _certificate

      private Certificate _certificate
      Certificate authorizing delivery (always null certificate currently).
  • Constructor Details

    • GarlicClove

      public GarlicClove(I2PAppContext context)
      Creates an empty clove with no id until one is read or set.
      Parameters:
      context - the app context used to read messages and to log
  • Method Details

    • getInstructions

      public DeliveryInstructions getInstructions()
      How and where to deliver this clove.
      Returns:
      the delivery instructions, or null until set
    • setInstructions

      public void setInstructions(DeliveryInstructions instr)
      Delivery instructions for this clove.
      Parameters:
      instr - the routing instructions this clove is to be delivered under
    • getData

      public I2NPMessage getData()
      The message payload wrapped in this clove.
      Returns:
      the wrapped I2NP message, or null until set
    • setData

      public void setData(I2NPMessage msg)
      Message payload wrapped in this clove.
      Parameters:
      msg - the I2NP message this clove carries
    • getCloveId

      public long getCloveId()
      Unique identifier for this clove.
      Returns:
      the clove id
    • setCloveId

      public void setCloveId(long id)
      Unique identifier for this clove.
      Parameters:
      id - the unique identifier to record for this clove
    • getExpiration

      public long getExpiration()
      Time after which this clove expires.
      Returns:
      the expiry time in ms since the epoch, 0 when unset
    • setExpiration

      public void setExpiration(long exp)
      Time after which this clove expires.
      Parameters:
      exp - the time in milliseconds since the epoch after which this clove expires
    • getCertificate

      public Certificate getCertificate()
      Certificate authorizing delivery of this clove.
      Returns:
      the authorizing certificate, or null when none was set
    • setCertificate

      public void setCertificate(Certificate cert)
      Certificate authorizing delivery of this clove.
      Parameters:
      cert - the certificate authorizing delivery of this clove
    • readBytes

      public int readBytes(byte[] source, int offset) throws DataFormatException
      Read the clove from a byte array.
      Parameters:
      source - the array holding the serialized clove
      offset - the offset into source at which the clove starts
      Returns:
      the bytes consumed, from offset through the end of the certificate
      Throws:
      DataFormatException - if the delivery instructions, message or certificate cannot be parsed
    • readBytesRatchet

      public void readBytesRatchet(byte[] source, int offset, int len) throws DataFormatException
      Short format for ECIES-Ratchet, saves 22 bytes. NTCP2-style header, no ID, no separate expiration, no cert.
      Parameters:
      source - the array holding the serialized ratchet-format clove
      offset - the offset into source at which the clove starts
      len - the number of bytes of source that make up the clove
      Throws:
      DataFormatException - if the delivery instructions or message cannot be parsed
    • toByteArray

      public byte[] toByteArray()
      Serialized clove.
      Specified by:
      toByteArray in interface DataStructure
      Overrides:
      toByteArray in class DataStructureImpl
      Returns:
      the clove in standard (non-ratchet) format, sized by estimateSize()
    • writeBytesRatchet

      public int writeBytesRatchet(byte[] tgt, int offset)
      Short format for ECIES-Ratchet, saves 22 bytes. NTCP2-style header, no ID, no separate expiration, no cert.
      Parameters:
      tgt - the array the clove is written into
      offset - the offset into tgt at which to start writing
      Returns:
      the offset just past the ratchet-format clove
    • getSizeRatchet

      public int getSizeRatchet()
      Size of the ratchet-format clove.
      Returns:
      the ratchet-clove size
    • estimateSize

      public int estimateSize()
      Estimated serialized length of this clove.
      Returns:
      the number of bytes toByteArray will produce for this clove
    • equals

      public boolean equals(Object obj)
      Compare all clove fields for equality.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Hash code covering all clove fields.
      Overrides:
      hashCode in class Object
      Returns:
      whether h code is present
    • toString

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