All Implemented Interfaces:
I2NPMessage

public class TunnelGatewayMessageextends FastI2NPMessageImpl
Defines the message sent between one tunnel's endpoint and another's gateway. format: { tunnelId, sizeof(i2npMessage.toByteArray()), i2npMessage.toByteArray() }.
  • Field Details

    • _tunnelId

      private TunnelId _tunnelId
      The tunnel this message enters.
    • _msg

      private I2NPMessage _msg
      The message carried inside.
    • _msgData

      private byte[] _msgData
      The carried message, as bytes.
    • MESSAGE_TYPE

      public static final int MESSAGE_TYPE
      Message type ID for this I2NP message.
      See Also:
    • EXPIRATION_PERIOD

      private static final int EXPIRATION_PERIOD
      If we can't deliver a tunnel message in 10s, forget it.
      See Also:
  • Constructor Details

    • TunnelGatewayMessage

      public TunnelGatewayMessage(I2PAppContext context)
      Constructor with 10-second message expiration from context clock.
      Parameters:
      context - the router context whose clock timestamps this message's expiration
  • Method Details

    • getTunnelId

      public TunnelId getTunnelId()
      Return the tunnel to deliver this message to.
      Returns:
      the ID of the tunnel to deliver to, null until setTunnelId has been called
    • setTunnelId

      public void setTunnelId(TunnelId id)
      Tunnel ID for this message; may only be set once.
      Parameters:
      id - the ID of the tunnel that must deliver this message to the far endpoint
      Throws:
      IllegalStateException - if id previously set, to protect saved checksum
    • getMessage

      public I2NPMessage getMessage()
      Warning, at the IBGW, where the message was read in, this will be an UnknownI2NPMessage. If you need a real message class, use UnknownI2NPMessage.convert().

      Warning, will be null after message has been written.

      Note that if you change the expiration on the embedded message it will mess up the checksum of this message, so don't do that.

      Returns:
      the message carried onward through the tunnel, held as an UnknownI2NPMessage when this instance was read at the IBGW, or null once this message has been written out
    • setMessage

      public void setMessage(I2NPMessage msg)
      Embedded message; may only be set once.
      Parameters:
      msg - the message to carry onward through the tunnel, which must not be null
      Throws:
      IllegalStateException - if msg previously set, to protect saved checksum
    • calculateWrittenLength

      protected int calculateWrittenLength()
      Calculate the serialized length of this message.
      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
    • readMessage

      public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException
      Read and parse the message from raw data into fields.
      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

      public void readMessage(byte[] data, int offset, int dataSize, int type, I2NPMessageHandler handler) throws I2NPMessageException
      Note that for efficiency at the IBGW, this does not fully deserialize the included I2NP Message. It just puts it in an UnknownI2NPMessage.
      Specified by:
      readMessage in interface I2NPMessage
      Overrides:
      readMessage in class I2NPMessageImpl
      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 - unused, may be null
      Throws:
      I2NPMessageException - if the stream doesn't contain a valid message that this class can read.
    • getType

      public int getType()
      Return the type.
      Returns:
      the message type number, as defined in the I2NP spec
    • hashCode

      public int hashCode()
      Hash based on tunnel ID and embedded message.
      Overrides:
      hashCode in class Object
      Returns:
      whether h code is present
    • equals

      public boolean equals(Object object)
      Two TunnelGatewayMessages are equal if they have the same tunnel ID and message content.
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Label with message ID, tunnel ID, and embedded message for logging.
      Overrides:
      toString in class Object