java.lang.Object
net.i2p.data.i2np.I2NPMessageImpl
net.i2p.data.i2np.TunnelBuildMessageBase
All Implemented Interfaces:
I2NPMessage
Direct Known Subclasses:
TunnelBuildMessage, TunnelBuildReplyMessage

public abstract class TunnelBuildMessageBaseextends I2NPMessageImpl
Base for TBM, TBRM, VTBM, VTBRM Retrofitted over them. There's really no difference between the build and build reply.

TBM and VBTM (but not TBRM and VTBRM?) messages are modified in-place by doing a single setRecord(), and retransmitted. Therefore they are NOT good candidates to use FastI2NPMessageImpl; the checksum would have to be invalidated with every setRecord(). Which we could do in TBM and VTBM but not TBRM and VTBRM, but keep it simple for now.

  • Field Details

    • _records

      protected EncryptedBuildRecord[] _records
      The encrypted records, one per hop, or null until readMessage().
    • RECORD_COUNT

      protected int RECORD_COUNT
      Number of records in _records, zero if not yet set.
    • MAX_RECORD_COUNT

      public static final int MAX_RECORD_COUNT
      Maximum number of records in any tunnel build message (8 hops).
      See Also:
    • RECORD_SIZE

      public static final int RECORD_SIZE
      Size in bytes of one encrypted record: 16 byte IV + 512 byte payload.
      See Also:
  • Constructor Details

    • TunnelBuildMessageBase

      public TunnelBuildMessageBase(I2PAppContext context)
      Create with the default number of records.
      Parameters:
      context - the application context the message is read and written under
    • TunnelBuildMessageBase

      protected TunnelBuildMessageBase(I2PAppContext context, int records)
      Leaves the count to be set by readMessage().
      Parameters:
      context - the application context the message is read and written under
      records - the number of records to preallocate, up to MAX_RECORD_COUNT; zero
  • Method Details

    • setRecord

      public void setRecord(int index, EncryptedBuildRecord record)
      Store a build record.
      Parameters:
      index - the zero-based position of the record in the record array
      record - may be null
    • getRecord

      public EncryptedBuildRecord getRecord(int index)
      Build record at the given index, may be null.
      Parameters:
      index - the zero-based position of the record in the record array
      Returns:
      may be null
    • getRecordCount

      public int getRecordCount()
      How many encrypted build records this message carries, which sets both the length of every hop record array and the tunnel's depth.
      Returns:
      the number of records, from 0 to MAX_RECORD_COUNT
    • calculateWrittenLength

      protected int calculateWrittenLength()
      Written length of the message body: one record size per record.
      Specified by:
      calculateWrittenLength in class I2NPMessageImpl
      Returns:
      the number of bytes the body will occupy once serialized
    • readMessage

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

      protected int writeMessageBody(byte[] out, int curIndex) throws I2NPMessageException
      Write the records 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