All Implemented Interfaces:
I2NPMessage

public class DatabaseSearchReplyMessageextends FastI2NPMessageImpl
Defines the message a router sends to another router in response to a search (DatabaseFindNearest or DatabaseLookup) when it doesn't have the value, specifying what routers it would search.
  • Field Details

    • MESSAGE_TYPE

      public static final int MESSAGE_TYPE
      I2NP message type ID written to the wire header.
      See Also:
    • _key

      private Hash _key
      The hash that was looked up.
    • _peerHashes

      private final List<Hash> _peerHashes
      The peers found, closest first.
    • _from

      private Hash _from
      The router sending the reply.
  • Constructor Details

    • DatabaseSearchReplyMessage

      public DatabaseSearchReplyMessage(I2PAppContext context)
      Builds a reply carrying no peers yet, with the list ready to fill.
      Parameters:
      context - the context to use for the message
  • Method Details

    • getSearchKey

      public Hash getSearchKey()
      Defines the key being searched for.
      Returns:
      the search key
    • setSearchKey

      public void setSearchKey(Hash key)
      Assigns the key being searched for.
      Parameters:
      key - the hash being searched for; it may only be assigned once
      Throws:
      IllegalStateException - if key previously set, to protect saved checksum
    • getNumReplies

      public int getNumReplies()
      The number of peer hashes included in the reply.
      Returns:
      the num replies
    • getReply

      public Hash getReply(int index)
      The peer hash at the given index.
      Parameters:
      index - the position of the wanted peer hash in the reply list
      Returns:
      the router hash found at that index in the reply list
    • addReply

      public void addReply(Hash peer)
      Adds a peer hash to the reply.
      Parameters:
      peer - the hash of the router answering the search, appended to the reply list
    • getFromHash

      public Hash getFromHash()
      The router that sent this reply.
      Returns:
      the from hash
    • setFromHash

      public void setFromHash(Hash from)
      Assigns the router that sent this reply.
      Parameters:
      from - the hash of the router whose database was searched
    • 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 number of bytes the body will occupy once serialized
    • 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, always MESSAGE_TYPE
    • equals

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

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

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