net.i2p.data.i2np

## Class DatabaseLookupMessage

- java.lang.Object
- - net.i2p.data.i2np.I2NPMessageImpl
  - - net.i2p.data.i2np.FastI2NPMessageImpl
    - - net.i2p.data.i2np.DatabaseLookupMessage

- All Implemented Interfaces:
    I2NPMessage

      public class DatabaseLookupMessage
      extends FastI2NPMessageImpl

  Defines the message a router sends to another router to search for a key in the network database.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DatabaseLookupMessage.Type` Database lookup type enumeration.

    - ### Nested classes/interfaces inherited from class net.i2p.data.i2np.I2NPMessageImpl

      `I2NPMessageImpl.Builder`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `MESSAGE_TYPE`
    `static boolean` | `USE_ECIES_FF`

    - ### Fields inherited from class net.i2p.data.i2np.FastI2NPMessageImpl

      `_checksum, _hasChecksum`

    - ### Fields inherited from class net.i2p.data.i2np.I2NPMessageImpl

      `_context, _expiration, CHECKSUM_LENGTH, DEFAULT_EXPIRATION_MS, HEADER_LENGTH`

    - ### Fields inherited from interface net.i2p.data.i2np.I2NPMessage

      `MAX_ID_VALUE, MAX_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DatabaseLookupMessage(I2PAppContext context)`
    `DatabaseLookupMessage(I2PAppContext context, boolean locallyCreated)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDontIncludePeer(Hash peer)` Add to the set.
    `void` | `addDontIncludePeers(Collection<Hash> peers)` Add to the set.
    `protected int` | `calculateWrittenLength()` calculate the message body's length (not including the header and footer
    `boolean` | `equals(Object object)`
    `Set<Hash>` | `getDontIncludePeers()` Set of peers that a lookup reply should NOT include.
    `Hash` | `getFrom()` Contains the router who requested this lookup
    `PublicKey` | `getRatchetPublicKey()` The included session key or null if unset.
    `RatchetSessionTag` | `getRatchetReplyTag()` The included session tag or null if unset
    `SessionKey` | `getReplyKey()` The included session key or null if unset.
    `SessionTag` | `getReplyTag()` The included session tag or null if unset
    `TunnelId` | `getReplyTunnel()` Contains the tunnel ID a reply should be sent to
    `Hash` | `getSearchKey()` Defines the key being searched for
    `DatabaseLookupMessage.Type` | `getSearchType()` Defines the type of data being searched for.
    `int` | `getType()` Return the unique identifier for this type of I2NP message, as defined in the I2NP spec
    `int` | `hashCode()`
    `void` | `readMessage(byte[] data, int offset, int dataSize, int type)` Read the body into the data structures, after the initial type byte and the uniqueId / expiration, using the current class's format as defined by the I2NP specification
    `void` | `setDontIncludePeers(Collection<Hash> peers)` Replace the dontInclude set with this set.
    `void` | `setFrom(Hash from)`
    `void` | `setReplySession(PublicKey pubKey)` Ratchet.
    `void` | `setReplySession(SessionKey encryptKey, RatchetSessionTag encryptTag)` Ratchet
    `void` | `setReplySession(SessionKey encryptKey, SessionTag encryptTag)` Only worthwhile if sending reply via tunnel
    `void` | `setReplyTunnel(TunnelId replyTunnel)`
    `void` | `setSearchKey(Hash key)`
    `void` | `setSearchType(DatabaseLookupMessage.Type type)` Defines the type of data being searched for.
    `static boolean` | `supportsEncryptedReplies(RouterInfo to)` Does this router support encrypted replies?
    `static boolean` | `supportsRatchetReplies(RouterInfo to)` Does this router support ratchet replies?
    `String` | `toString()`
    `protected int` | `writeMessageBody(byte[] out, int curIndex)` write the message body to the output array, starting at the given index.

    - ### Methods inherited from class net.i2p.data.i2np.FastI2NPMessageImpl

      `readBytes, toByteArray, toByteArrayWithSavedChecksum`

    - ### Methods inherited from class net.i2p.data.i2np.I2NPMessageImpl

      `createMessage, fromRawByteArray, fromRawByteArrayNTCP2, getMessageExpiration, getMessageSize, getRawMessageSize, getUniqueId, getUniqueId, readBytes, readMessage, setMessageExpiration, setUniqueId, toByteArray, toByteArray, toRawByteArray, toRawByteArrayNTCP2`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### MESSAGE_TYPE

          public static final int MESSAGE_TYPE

      See Also:
        Constant Field Values

    - #### USE_ECIES_FF

          public static final boolean USE_ECIES_FF

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DatabaseLookupMessage

          public DatabaseLookupMessage(I2PAppContext context)

    - #### DatabaseLookupMessage

          public DatabaseLookupMessage(I2PAppContext context,
                                       boolean locallyCreated)

      Parameters:
        `locallyCreated` - ignored

  - ### Method Detail

    - #### addDontIncludePeer

          public void addDontIncludePeer(Hash peer)

      Add to the set. Invalidates the checksum.
      Parameters:
        `peer` - non-null

    - #### addDontIncludePeers

          public void addDontIncludePeers(Collection<Hash> peers)

      Add to the set. Invalidates the checksum.
      Parameters:
        `peers` - non-null

    - #### calculateWrittenLength

          protected int calculateWrittenLength()

      Description copied from class: `I2NPMessageImpl`
      calculate the message body's length (not including the header and footer
      Specified by:
        `calculateWrittenLength` in class `I2NPMessageImpl`

    - #### equals

          public boolean equals(Object object)

      Overrides:
        `equals` in class `Object`

    - #### getDontIncludePeers

          public Set<Hash> getDontIncludePeers()

      Set of peers that a lookup reply should NOT include. WARNING - returns a copy.
      Returns:
        Set of Hash objects, each of which is the H(routerIdentity) to skip, or null

    - #### getFrom

          public Hash getFrom()

      Contains the router who requested this lookup

    - #### getRatchetPublicKey

          public PublicKey getRatchetPublicKey()

      The included session key or null if unset. Preliminary, not fully supported, see proposal 154.

    - #### getRatchetReplyTag

          public RatchetSessionTag getRatchetReplyTag()

      The included session tag or null if unset

    - #### getReplyKey

          public SessionKey getReplyKey()

      The included session key or null if unset. If non-null, either getReplyTag() or getRatchetReplyTag() is non-null.

    - #### getReplyTag

          public SessionTag getReplyTag()

      The included session tag or null if unset

    - #### getReplyTunnel

          public TunnelId getReplyTunnel()

      Contains the tunnel ID a reply should be sent to

    - #### getSearchKey

          public Hash getSearchKey()

      Defines the key being searched for

    - #### getSearchType

          public DatabaseLookupMessage.Type getSearchType()

      Defines the type of data being searched for. Default ANY.
      Returns:
        non-null

    - #### getType

          public int getType()

      Description copied from interface: `I2NPMessage`
      Return the unique identifier for this type of I2NP message, as defined in the I2NP spec

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### readMessage

          public void readMessage(byte[] data,
                                  int offset,
                                  int dataSize,
                                  int type)
                           throws I2NPMessageException

      Description copied from interface: `I2NPMessage`
      Read the body into the data structures, after the initial type byte and the uniqueId / expiration, using the current class's format as defined by the I2NP specification
      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.

    - #### setDontIncludePeers

          public void setDontIncludePeers(Collection<Hash> peers)

      Replace the dontInclude set with this set. WARNING - makes a copy. Invalidates the checksum.
      Parameters:
        `peers` - may be null

    - #### setFrom

          public void setFrom(Hash from)

      Throws:
        `IllegalStateException` - if from previously set, to protect saved checksum

    - #### setReplySession

          public void setReplySession(PublicKey pubKey)

      Ratchet. Preliminary, not fully supported, see proposal 154.
      Parameters:
        `pubKey` - non-null
      Throws:
        `IllegalStateException` - if key or tag previously set, to protect saved checksum

    - #### setReplySession

          public void setReplySession(SessionKey encryptKey,
                                      RatchetSessionTag encryptTag)

      Ratchet
      Parameters:
        `encryptKey` - non-null
        `encryptTag` - non-null
      Throws:
        `IllegalStateException` - if key or tag previously set, to protect saved checksum

    - #### setReplySession

          public void setReplySession(SessionKey encryptKey,
                                      SessionTag encryptTag)

      Only worthwhile if sending reply via tunnel
      Parameters:
        `encryptKey` - non-null
        `encryptTag` - non-null
      Throws:
        `IllegalStateException` - if key or tag previously set, to protect saved checksum

    - #### setReplyTunnel

          public void setReplyTunnel(TunnelId replyTunnel)

      Throws:
        `IllegalStateException` - if tunnel previously set, to protect saved checksum

    - #### setSearchKey

          public void setSearchKey(Hash key)

      Throws:
        `IllegalStateException` - if key previously set, to protect saved checksum

    - #### setSearchType

          public void setSearchType(DatabaseLookupMessage.Type type)

      Defines the type of data being searched for. Default ANY. Must be ANY for queried routers 0.9.5 or lower, but there are few if any floodfills that old left, so not even worth checking.
      Parameters:
        `type` - non-null

    - #### supportsEncryptedReplies

          public static boolean supportsEncryptedReplies(RouterInfo to)

      Does this router support encrypted replies?
      Parameters:
        `to` - null OK

    - #### supportsRatchetReplies

          public static boolean supportsRatchetReplies(RouterInfo to)

      Does this router support ratchet replies?
      Parameters:
        `to` - null OK

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### writeMessageBody

          protected int writeMessageBody(byte[] out,
                                         int curIndex)
                                  throws I2NPMessageException

      Description copied from class: `I2NPMessageImpl`
      write the message body to the output array, starting at the given index.
      Specified by:
        `writeMessageBody` in class `I2NPMessageImpl`
      Returns:
        the index into the array after the last byte written (NOT the length)
      Throws:
        `I2NPMessageException`