net.i2p.router.networkdb.kademlia

## Class IterativeSearchJob

- java.lang.Object
- - net.i2p.router.JobImpl
  - - net.i2p.router.networkdb.kademlia.FloodSearchJob
    - - net.i2p.router.networkdb.kademlia.IterativeSearchJob

- All Implemented Interfaces:
    Job

      public class IterativeSearchJob
      extends FloodSearchJob

  Traditional Kademlia iterative search with enhanced robustness.

  Continues searching when initial lookup fails by iteratively querying closer-to-the-key peers returned in DatabaseSearchReplyMessages. Unlike traditional Kademlia, doesn't stop when no closer keys are available - keeps searching until timeout or maximum search limit is reached.

  Key differences from FloodOnlySearchJob: - Chases peers in DSRM immediately rather than waiting - Searches one peer at a time with individual per-search timeouts - Uses total timeout rather than per-search timeouts - Longer overall timeout for better success rates - Reduces search traffic by half compared to parallel approaches

  Advantages over flood-only approaches: - More robust in large networks with incomplete floodfill knowledge - Better success rates through sequential searching - Reduced network traffic through single-peer queries

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `DEFAULT_ENCRYPT_RI` only on fast boxes, for now
    `static String` | `PROP_ENCRYPT_RI`

    - ### Fields inherited from class net.i2p.router.networkdb.kademlia.FloodSearchJob

      `_created, _dead, _expiration, _facade, _isLease, _key, _log, _lookupsRemaining, _onFailed, _onFind, _success, _timeoutMs, CONCURRENT_SEARCHES`

    - ### Fields inherited from class net.i2p.router.JobImpl

      `_id`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IterativeSearchJob(RouterContext ctx, FloodfillNetworkDatabaseFacade facade, Hash key, Job onFind, Job onFailed, int timeoutMs, boolean isLease)` Lookup using exploratory tunnels
    `IterativeSearchJob(RouterContext ctx, FloodfillNetworkDatabaseFacade facade, Hash key, Job onFind, Job onFailed, int timeoutMs, boolean isLease, Hash fromLocalDest)` Lookup using the client's tunnels.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) void` | `cancelJob()` Cancels the job without performing full failure handling.
    `void` | `dropped()` Dropped by the job queue
    `(package private) void` | `failed()` Total failure
    `(package private) void` | `failed(Hash peer, boolean timedOut)` Note that the peer did not respond with a DSM (either a DSRM, timeout, or failure).
    `Hash` | `getFromHash()` Hash of the dest this query is from
    `String` | `getName()` Deprecated, unused, see FOSJ override
    `(package private) void` | `newPeerToTry(Hash peer)` A new (floodfill) peer was discovered that may have the answer.
    `void` | `runJob()` Deprecated, unused, see FOSJ override
    `(package private) void` | `success()` Deprecated, unused, see FOSJ override
    `(package private) long` | `timeSent(Hash peer)` When did we send the query to the peer?
    `boolean` | `wasQueried(Hash peer)` Did we send a request to this peer?

    - ### Methods inherited from class net.i2p.router.networkdb.kademlia.FloodSearchJob

      `addDeferred, decrementRemaining, getCreated, getExpiration, getKey, getLookupsRemaining`

    - ### Methods inherited from class net.i2p.router.JobImpl

      `getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeue, toString`

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

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

- - ### Field Detail

    - #### DEFAULT_ENCRYPT_RI

          public static final boolean DEFAULT_ENCRYPT_RI

      only on fast boxes, for now

    - #### PROP_ENCRYPT_RI

          public static final String PROP_ENCRYPT_RI

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### IterativeSearchJob

          public IterativeSearchJob(RouterContext ctx,
                                    FloodfillNetworkDatabaseFacade facade,
                                    Hash key,
                                    Job onFind,
                                    Job onFailed,
                                    int timeoutMs,
                                    boolean isLease)

      Lookup using exploratory tunnels

    - #### IterativeSearchJob

          public IterativeSearchJob(RouterContext ctx,
                                    FloodfillNetworkDatabaseFacade facade,
                                    Hash key,
                                    Job onFind,
                                    Job onFailed,
                                    int timeoutMs,
                                    boolean isLease,
                                    Hash fromLocalDest)

      Lookup using the client's tunnels. Do not use for RI lookups down client tunnels, as the response will be dropped in InboundMessageDistributor.
      Parameters:
        `fromLocalDest` - use these tunnels for the lookup, or null for exploratory

  - ### Method Detail

    - #### cancelJob

          void cancelJob()

      Cancels the job without performing full failure handling.

    - #### dropped

          public void dropped()

      Dropped by the job queue
      Specified by:
        `dropped` in interface `Job`
      Overrides:
        `dropped` in class `JobImpl`

    - #### failed

          void failed()

      Total failure
      Overrides:
        `failed` in class `FloodSearchJob`

    - #### failed

          void failed(Hash peer,
                      boolean timedOut)

      Note that the peer did not respond with a DSM (either a DSRM, timeout, or failure). This is not necessarily a total failure of the search.
      Parameters:
        `timedOut` - if true, will blame the peer's profile

    - #### getFromHash

          public Hash getFromHash()

      Hash of the dest this query is from
      Returns:
        null for router

    - #### getName

          public String getName()

      Description copied from class: `FloodSearchJob`
      Deprecated, unused, see FOSJ override
      Specified by:
        `getName` in interface `Job`
      Overrides:
        `getName` in class `FloodSearchJob`
      Returns:
        the descriptive name of the task

    - #### newPeerToTry

          void newPeerToTry(Hash peer)

      A new (floodfill) peer was discovered that may have the answer.
      Parameters:
        `peer` - may not actually be new

    - #### runJob

          public void runJob()

      Description copied from class: `FloodSearchJob`
      Deprecated, unused, see FOSJ override
      Specified by:
        `runJob` in interface `Job`
      Overrides:
        `runJob` in class `FloodSearchJob`

    - #### success

          void success()

      Description copied from class: `FloodSearchJob`
      Deprecated, unused, see FOSJ override
      Overrides:
        `success` in class `FloodSearchJob`

    - #### timeSent

          long timeSent(Hash peer)

      When did we send the query to the peer?
      Returns:
        context time, or -1 if never sent

    - #### wasQueried

          public boolean wasQueried(Hash peer)

      Did we send a request to this peer?