All Known Implementing Classes:
DatabaseLookupMessage, DatabaseSearchReplyMessage, DatabaseStoreMessage, DataMessage, DeliveryStatusMessage, FastI2NPMessageImpl, GarlicMessage, I2NPMessageImpl, OutboundTunnelBuildReplyMessage, ShortTunnelBuildMessage, ShortTunnelBuildReplyMessage, TunnelBuildMessage, TunnelBuildMessageBase, TunnelBuildReplyMessage, TunnelDataMessage, TunnelGatewayMessage, UnknownI2NPMessage, VariableTunnelBuildMessage, VariableTunnelBuildReplyMessage

public interface I2NPMessage
Base interface for all I2NP messages

Note: No longer extends DataStructure as of 0.9.48.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    4 bytes unsigned.
    static final int
    Nominal limit, actual max is much less.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    long
    Date after which the message should be dropped (and the associated uniqueId forgotten).
    int
    How large the message is, including any checksums, i.e.
    int
    How large the raw message is with the short 5 byte header.
    int
    Return the unique identifier for this type of I2NP message, as defined in the I2NP spec.
    long
    Unique message id, optionally XORed with the given value.
    long
    getUniqueId(long msgIDBloomXor)
    Replay resistant message ID optionally, the caller may pass a msgIDBloomXor value, and the return value will be Xor'ed with that value.
    int
    readBytes(byte[] data, int type, int offset)
    Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification.
    int
    readBytes(byte[] data, int type, int offset, int maxLen)
    Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification.
    void
    readMessage(byte[] data, int offset, int dataSize, int type)
    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.
    void
    readMessage(byte[] data, int offset, int dataSize, int type, I2NPMessageHandler handler)
    Read the message fields from the byte array, dispatching them to the given handler.
    void
    Expiration for this message, assigned when written.
    void
    setUniqueId(long id)
    Unique id for this message, assigned when written.
    byte[]
    Serialize the message, header included, into a new array.
    int
    toByteArray(byte[] buffer)
    Write the message to the buffer, returning the new offset (NOT the length).
    int
    toByteArray(byte[] buffer, int off)
    Write the message to the buffer, returning the new offset (NOT the length).
    int
    toRawByteArray(byte[] buffer)
    Write the message to the buffer, returning the new offset (NOT the length).
    int
    toRawByteArrayNTCP2(byte[] buffer, int off)
    Write the message to the buffer, returning the new offset (NOT the length).
  • Field Details

    • MAX_ID_VALUE

      static final long MAX_ID_VALUE
      4 bytes unsigned.
      See Also:
    • MAX_SIZE

      static final int MAX_SIZE
      Nominal limit, actual max is much less. See website docs for further restrictions due to various overhead and limitations in encryption, fragmentation, and the transports.
      See Also:
  • Method Details

    • readBytes

      int readBytes(byte[] data, int type, int offset) throws I2NPMessageException
      Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification.
      Parameters:
      data - the full serialized message, header included
      type - I2NP message type. If less than zero, read the type from data
      offset - where to start starting at type if type is < 0 (16 byte header) starting at ID if type is >= 0 (15 byte header)
      Returns:
      size of the message read (including headers)
      Throws:
      I2NPMessageException - if there is no valid message
    • readBytes

      int readBytes(byte[] data, int type, int offset, int maxLen) throws I2NPMessageException
      Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification.
      Parameters:
      data - the data, may or may not include the type
      type - I2NP message type. If less than zero, read the type from data
      offset - where to start starting at type if type is < 0 (16 byte header) starting at ID if type is >= 0 (15 byte header)
      maxLen - read no more than this many bytes from data starting at offset, even if it is longer This includes the type byte only if type < 0
      Returns:
      size of the message read (including headers)
      Throws:
      I2NPMessageException - if there is no valid message
    • readMessage

      void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException
      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.
    • readMessage

      void readMessage(byte[] data, int offset, int dataSize, int type, I2NPMessageHandler handler) throws I2NPMessageException
      Read the message fields from the byte array, dispatching them to the given handler. The base implementation ignores the handler and behaves as readMessage(byte[], int, int, int); subclasses that deliver the message asynchronously override this.
      Parameters:
      data - the buffer holding the message, header included
      offset - where to start in the data array
      dataSize - how long into the data to read
      type - I2NP message type
      handler - the target for the message the buffer contains
      Throws:
      I2NPMessageException - if the stream doesn't contain a valid message that this class can read.
    • getType

      int getType()
      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
    • getUniqueId

      long getUniqueId(long msgIDBloomXor)
      Replay resistant message ID optionally, the caller may pass a msgIDBloomXor value, and the return value will be Xor'ed with that value. Passing a msgIDBloomXor value of 0 will result in the original ID being returned, instead of passing 0 use the no-arg version.
      Parameters:
      msgIDBloomXor - value to XOR the id with, or 0 for the id unchanged
      Returns:
      the unique id
    • getUniqueId

      long getUniqueId()
      Unique message id, optionally XORed with the given value.
      Returns:
      the unique id
    • setUniqueId

      void setUniqueId(long id)
      Unique id for this message, assigned when written.
      Parameters:
      id - the unique id to attach to this message
    • getMessageExpiration

      long getMessageExpiration()
      Date after which the message should be dropped (and the associated uniqueId forgotten).
      Returns:
      the message expiration
    • setMessageExpiration

      void setMessageExpiration(long exp)
      Expiration for this message, assigned when written.
      Parameters:
      exp - the expiration as milliseconds since the epoch, which is also when the peer should stop forwarding the message
    • getMessageSize

      int getMessageSize()
      How large the message is, including any checksums, i.e. full 16 byte header.
      Returns:
      the size in bytes of the message with the full NTCP 1 header
    • getRawMessageSize

      int getRawMessageSize()
      How large the raw message is with the short 5 byte header.
      Returns:
      the size in bytes of the message with the short SSU header
    • toByteArray

      byte[] toByteArray()
      Serialize the message, header included, into a new array.
      Returns:
      a new array holding the whole message, full 16 byte header included
    • toByteArray

      int toByteArray(byte[] buffer)
      Write the message to the buffer, returning the new offset (NOT the length). the data is formatted so as to be self contained, with the type, size, expiration, unique id, as well as a checksum bundled along. Full 16 byte header for NTCP 1.
      Parameters:
      buffer - the destination array, which must have room for getMessageSize() bytes
      Returns:
      the new offset (NOT the length)
    • toByteArray

      int toByteArray(byte[] buffer, int off)
      Write the message to the buffer, returning the new offset (NOT the length). the data is formatted so as to be self contained, with the type, size, expiration, unique id, as well as a checksum bundled along. Full 16 byte header for NTCP 1.
      Parameters:
      buffer - the destination array, which must have room for getMessageSize() bytes from off on
      off - the offset to start writing at
      Returns:
      the new offset (NOT the length)
    • toRawByteArray

      int toRawByteArray(byte[] buffer)
      Write the message to the buffer, returning the new offset (NOT the length). the data is is not self contained - it does not include the size, unique id, or any checksum, but does include the type and expiration. Short 5 byte header for SSU.
      Parameters:
      buffer - the destination array, written from index 0, which must have room for getRawMessageSize() bytes
      Returns:
      the length written
    • toRawByteArrayNTCP2

      int toRawByteArrayNTCP2(byte[] buffer, int off)
      Write the message to the buffer, returning the new offset (NOT the length). the data is is not self contained - it does not include the size, unique id, or any checksum, but does include the type and expiration. Short 9 byte header for NTCP 2.
      Parameters:
      buffer - the destination array, which must have room for getRawMessageSize() bytes from off on
      off - the offset to start writing at
      Returns:
      the new offset (NOT the length)