java.lang.Object
net.i2p.data.i2cp.I2CPMessageImpl
net.i2p.data.i2cp.MessagePayloadMessage
All Implemented Interfaces:
I2CPMessage

public class MessagePayloadMessageextends I2CPMessageImpl
Defines the payload message a router sends to the client.
  • Field Details

    • MESSAGE_TYPE

      public static final int MESSAGE_TYPE
      I2CP message type code for a payload message.
      See Also:
    • _sessionId

      private int _sessionId
      The session the payload is for.
    • _messageId

      private long _messageId
      The message the payload belongs to.
    • _payload

      private Payload _payload
      The message contents.
  • Constructor Details

    • MessagePayloadMessage

      public MessagePayloadMessage()
      For reading. Deprecated for writing, use 3-arg constructor.
    • MessagePayloadMessage

      public MessagePayloadMessage(long sessID, long msgID, Payload payload)
      For writing.
      Parameters:
      sessID - the session the message belongs to, stored truncated to 32 bits
      msgID - the message ID used to correlate the payload with its reply
      payload - the payload to deliver to the session
  • Method Details

    • getSessionId

      public long getSessionId()
      Get the session this message was sent on.
      Returns:
      the session ID
    • sessionId

      public SessionId sessionId()
      Return the SessionId for this message.
      Specified by:
      sessionId in interface I2CPMessage
      Overrides:
      sessionId in class I2CPMessageImpl
      Returns:
      null always. Extending classes with a SessionId must override.
    • getMessageId

      public long getMessageId()
      Get the message ID, unique within the session.
      Returns:
      the message ID
    • getPayload

      public Payload getPayload()
      Get the payload carried by this message.
      Returns:
      the payload to deliver to the session, or null if not yet set
    • doReadMessage

      protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException
      Read in the payload part of the message (after the initial 4 byte size and 1 byte type).
      Specified by:
      doReadMessage in class I2CPMessageImpl
      Parameters:
      in - 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 byte[] doWriteMessage() throws I2CPMessageException, IOException
      Write the message body to the output stream.
      Specified by:
      doWriteMessage in class I2CPMessageImpl
      Returns:
      byte array
      Throws:
      UnsupportedOperationException - always, as this message is read-only once constructed
      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
      Overrides:
      writeMessage in class I2CPMessageImpl
      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.
    • getType

      public int getType()
      Return the unique identifier for this type of message, as specified in the network specification document under #ClientAccessLayerMessages.
      Returns:
      unique identifier for this type of message
    • toString

      public String toString()
      Overrides:
      toString in class Object