java.lang.Object
net.i2p.data.i2np.I2NPMessageHandler

public class I2NPMessageHandlerextends Object
Handle messages from router to router. This class is NOT threadsafe.
  • Field Details

    • _log

      private final Log _log
      Logger for this class.
    • _context

      private final I2PAppContext _context
      The context the messages are read for.
    • _lastRead

      private I2NPMessage _lastRead
      The message read last, reused between reads.
  • Constructor Details

    • I2NPMessageHandler

      public I2NPMessageHandler(I2PAppContext context)
      Message handler for reading and writing I2NP messages.
      Parameters:
      context - router context supplying the app context and this handler's Log
  • Method Details

    • lastRead

      public I2NPMessage lastRead()
      Clear the last message read from a byte array with an offset.
      Returns:
      the last I2NP message read, or null if none is pending; the call clears it
    • readMessage

      public I2NPMessage readMessage(byte[] data) throws I2NPMessageException
      Read an I2NPMessage from the byte array and return the fully populated object.
      Parameters:
      data - the buffer holding the serialized message
      Returns:
      the fully populated message
      Throws:
      I2NPMessageException - if there is a problem handling the particular message - if it is an unknown type or has improper formatting, etc.
    • readMessage

      public int readMessage(byte[] data, int offset) throws I2NPMessageException
      Result is retrieved with lastRead().
      Parameters:
      data - the buffer holding the serialized message
      offset - the index in data at which the message starts
      Returns:
      the number of bytes read from data
      Throws:
      I2NPMessageException - on an unknown type or body
    • readMessage

      public int readMessage(byte[] data, int offset, int maxLen) throws I2NPMessageException
      Limit the max to read from the data buffer, so that we can use a large buffer but prevent the reader from reading off the end.

      Result is retrieved with lastRead().

      Parameters:
      data - the buffer holding the serialized message
      offset - the index in data at which the message starts
      maxLen - read no more than this many bytes from data starting at offset, even if it is longer must be at least 16
      Returns:
      the number of bytes read from data
      Throws:
      I2NPMessageException - on an unknown type or body