java.lang.Object
net.i2p.data.i2cp.I2CPMessageImpl
All Implemented Interfaces:
I2CPMessage
Direct Known Subclasses:
BandwidthLimitsMessage, BlindingInfoMessage, CreateLeaseSetMessage, CreateSessionMessage, DestLookupMessage, DestReplyMessage, DestroySessionMessage, DisconnectMessage, GetBandwidthLimitsMessage, GetDateMessage, HostLookupMessage, HostReplyMessage, MessagePayloadMessage, MessageStatusMessage, PoisonI2CPMessage, ReceiveMessageBeginMessage, ReceiveMessageEndMessage, ReconfigureSessionMessage, ReportAbuseMessage, RequestLeaseSetMessage, RequestVariableLeaseSetMessage, SendMessageMessage, SessionStatusMessage, SetDateMessage

public abstract class I2CPMessageImplextends Object implements I2CPMessage
Defines the base message implementation.

As of 0.9.48, does NOT extend DataStructureImpl.

  • Constructor Summary

    Constructors
    Constructor
    Description
    I2CPMessageImpl.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    doReadMessage(InputStream buf, int size)
    Read in the payload part of the message (after the initial 4 byte size and 1 byte type).
    protected abstract byte[]
    Write out the payload part of the message (not including the 4 byte size and 1 byte type).
    void
    Read the message from the stream, wrapping I2CPMessageException in DataFormatException.
    void
    Validate the type and size of the message, and then read the message into the data structures.
    void
    readMessage(InputStream in, int length, int type)
    Read the body into the data structures.
    Return the SessionId for this type of message.
    void
    Write the message to the stream, wrapping I2CPMessageException in DataFormatException.
    void
    Write out the full message to the stream, including the 4 byte size and 1 byte type header.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface I2CPMessage

    getType
    Modifier and Type
    Method
    Description
    int
    Return the unique identifier for this type of message, as specified in the network specification document under #ClientAccessLayerMessages.
  • Constructor Details

    • I2CPMessageImpl

      public I2CPMessageImpl()
      I2CPMessageImpl.
  • Method Details

    • readMessage

      public void readMessage(InputStream in) throws I2CPMessageException, IOException
      Validate the type and size of the message, and then read the message into the data structures.
      Specified by:
      readMessage in interface I2CPMessage
      Parameters:
      in - stream to read from
      Throws:
      IOException - if there's an error reading from the stream
      I2CPMessageException - if the stream doesn't contain a valid message that this class can read.
    • readMessage

      public void readMessage(InputStream in, int length, int type) throws I2CPMessageException, IOException
      Read the body into the data structures.
      Specified by:
      readMessage in interface I2CPMessage
      Parameters:
      in - stream to read from
      length - number of bytes in the message payload
      type - type of message (should equal I2CPMessage.getType())
      Throws:
      IOException - if there's an error reading from the stream
      I2CPMessageException - if the stream doesn't contain a valid message that this class can read.
    • doReadMessage

      protected abstract void doReadMessage(InputStream buf, int size) throws I2CPMessageException, IOException
      Read in the payload part of the message (after the initial 4 byte size and 1 byte type).
      Parameters:
      buf - positioned just past the 4 byte size and 1 byte type header
      size - how many payload bytes remain to be read
      Throws:
      I2CPMessageException - if the message format is invalid
      IOException - if there's an error reading from the stream
    • doWriteMessage

      protected abstract byte[] doWriteMessage() throws I2CPMessageException, IOException
      Write out the payload part of the message (not including the 4 byte size and 1 byte type).
      Returns:
      byte array
      Throws:
      I2CPMessageException - if the message cannot be written
      IOException - if there's an error writing to the stream
    • writeMessage

      public void writeMessage(OutputStream out) throws I2CPMessageException, IOException
      Write out the full message to the stream, including the 4 byte size and 1 byte type header.
      Specified by:
      writeMessage in interface I2CPMessage
      Parameters:
      out - receives the length, type and payload, in that order
      Throws:
      IOException - if there's an error writing to the stream
      I2CPMessageException - if the current object doesn't have sufficient data to write a properly formatted message.
    • readBytes

      public void readBytes(InputStream in) throws DataFormatException, IOException
      Read the message from the stream, wrapping I2CPMessageException in DataFormatException.
      Parameters:
      in - the input stream to read from
      Throws:
      DataFormatException - if the message format is invalid
      IOException - if there's an error reading from the stream
    • writeBytes

      public void writeBytes(OutputStream out) throws DataFormatException, IOException
      Write the message to the stream, wrapping I2CPMessageException in DataFormatException.
      Parameters:
      out - the output stream to write to
      Throws:
      DataFormatException - if the message cannot be written
      IOException - if there's an error writing to the stream
    • sessionId

      public SessionId sessionId()
      Return the SessionId for this type of message. Most but not all message types include a SessionId. The ones that do already define getSessionId(), but some return a SessionId and some return a long, so we define a new method here.
      Specified by:
      sessionId in interface I2CPMessage
      Returns:
      null always. Extending classes with a SessionId must override.