All Implemented Interfaces:
I2NPMessage

public class DatabaseStoreMessageextends FastI2NPMessageImpl
Defines the message a router sends to another router to test the network database reachability, as well as the reply message sent back.

Could this even change the message length or corrupt things?

  • Field Details

    • MESSAGE_TYPE

      public static final int MESSAGE_TYPE
      I2NP message type ID for a database store request.
      See Also:
    • _key

      private Hash _key
      The key being stored.
    • _dbEntry

      private DatabaseEntry _dbEntry
      The entry being stored.
    • _byteCache

      private byte[] _byteCache
      Cached serialization of the message.
    • _replyToken

      private long _replyToken
      Token identifying the reply to send back.
    • _replyTunnel

      private TunnelId _replyTunnel
      Tunnel the reply should go back through.
    • _replyGateway

      private Hash _replyGateway
      Gateway the reply should go back to.
    • _receivedAsReply

      private boolean _receivedAsReply
      True if this message arrived as someone's reply.
  • Constructor Details

    • DatabaseStoreMessage

      public DatabaseStoreMessage(I2PAppContext context)
      Creates a new DatabaseStoreMessage.
      Parameters:
      context - the I2P app context
  • Method Details

    • getKey

      public Hash getKey()
      Defines the key in the network database being stored.
      Returns:
      the key, or null if not set
    • getEntry

      public DatabaseEntry getEntry()
      Defines the entry in the network database being stored.
      Returns:
      the database entry
    • setEntry

      public void setEntry(DatabaseEntry entry)
      This also sets the key.
      Parameters:
      entry - the entry to store
      Throws:
      IllegalStateException - if data previously set, to protect saved checksum
    • getReplyToken

      public long getReplyToken()
      If a reply is desired, this token specifies the message ID that should be used for a DeliveryStatusMessage to be sent to the reply tunnel on the reply gateway.
      Returns:
      positive reply token ID, or 0 if no reply is necessary.
    • setReplyToken

      public void setReplyToken(long token) throws IllegalArgumentException
      Update the reply token.
      Parameters:
      token - message ID to correlate a DeliveryStatusMessage with, 0 if no reply is needed
      Throws:
      IllegalArgumentException - if the token is out of range (min=0, max=I2NPMessage.MAX_ID_VALUE)
    • getReplyTunnel

      public TunnelId getReplyTunnel()
      The tunnel to send the reply through, or null if no reply is requested.
      Returns:
      the reply tunnel, or null
    • setReplyTunnel

      public void setReplyTunnel(TunnelId id)
      Assigns the tunnel to send the reply through.
      Parameters:
      id - the reply tunnel
    • getReplyGateway

      public Hash getReplyGateway()
      The gateway to send the reply to, or null if no reply is requested.
      Returns:
      the reply gateway, or null
    • setReplyGateway

      public void setReplyGateway(Hash peer)
      Assigns the gateway to send the reply to.
      Parameters:
      peer - the reply gateway
    • getReceivedAsReply

      public boolean getReceivedAsReply()
      If true, we received this by searching for it. Note that searches may query multiple peers in parallel; only the first reply may have this set, and a reply received after the reply job times out will not have this set. Default false.
      Returns:
      the received as reply
    • setReceivedAsReply

      public void setReceivedAsReply()
      Records that this message was received by searching for it.
    • readMessage

      public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException
      Reads the message fields from the 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.
    • calculateWrittenLength

      protected int calculateWrittenLength()
      Calculate the message body's length (not including the header and footer).
      Specified by:
      calculateWrittenLength in class I2NPMessageImpl
      Returns:
      the length of the message body
      Throws:
      IllegalStateException - if the entry is not set
    • 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
    • getType

      public int getType()
      The message type.
      Returns:
      the I2NP message type ID, MESSAGE_TYPE
    • hashCode

      public int hashCode()
      Hash code calculated from the message fields.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • equals

      public boolean equals(Object object)
      Compares this message to another for equality of all fields.
      Overrides:
      equals in class Object
    • toString

      public String toString()
      String form of the message, suitable for debugging.
      Overrides:
      toString in class Object