net.i2p.router.networkdb.kademlia

## Class FloodfillNetworkDatabaseFacade

- java.lang.Object
- - net.i2p.router.NetworkDatabaseFacade
  - - net.i2p.router.networkdb.kademlia.KademliaNetworkDatabaseFacade
    - - net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade

- All Implemented Interfaces:
    Service

      public class FloodfillNetworkDatabaseFacade
      extends KademliaNetworkDatabaseFacade

  The network database

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static char` | `CAPABILITY_BW_UNLIMITED`
    `static char` | `CAPABILITY_BW12`
    `static char` | `CAPABILITY_BW128`
    `static char` | `CAPABILITY_BW256`
    `static char` | `CAPABILITY_BW32`
    `static char` | `CAPABILITY_BW512`
    `static char` | `CAPABILITY_BW64`
    `static char` | `CAPABILITY_CONGESTION_MODERATE`
    `static char` | `CAPABILITY_CONGESTION_SEVERE`
    `static char` | `CAPABILITY_FLOODFILL`
    `static char` | `CAPABILITY_NO_TUNNELS`
    `static char` | `CAPABILITY_UNREACHABLE`
    `static int` | `MAX_TO_FLOOD` This is the flood redundancy.
    `protected static int` | `MIN_ACTIVE_PEERS` NTCP cons drop quickly but SSU takes a while, so it's prudent to keep this a little higher than 1 or 2.
    `(package private) static long` | `NEXT_RKEY_RI_ADVANCE_TIME`
    `static String` | `PROP_FLOODFILL_AT_RESTART`
    `static String` | `PROP_FLOODFILL_PARTICIPANT`
    `(package private) static long` | `PUBLISH_TIMEOUT` This maybe could be shorter than RepublishLeaseSetJob.REPUBLISH_LEASESET_TIMEOUT, because we are sending direct, but unresponsive floodfills may take a while due to timeouts.

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

      `_context, _log, _networkID, _peerSelector, CURRENT_VERSION, DEFAULT_DB_DIR, DONT_FAIL_PERIOD, MAX_EXPLORE_QUEUE, MIN_REMAINING_ROUTERS, MIN_RESEED, MIN_VERSION, minRouterVersion, PROP_BLOCK_MY_COUNTRY, PROP_BLOCK_XG, PROP_BUCKET_SIZE, PROP_DB_DIR, PROP_EXPLORE_QUEUE, PROP_IP_COUNTRY, PROP_KAD_B, PROP_MIN_ROUTER_VERSION, PROP_ROUTER_INFO_EXPIRATION_ADJUSTED, PROP_VALIDATE_ROUTERS_AFTER`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FloodfillNetworkDatabaseFacade(RouterContext context)` Main DB
    `FloodfillNetworkDatabaseFacade(RouterContext context, Hash dbid)` Sub DBs

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) void` | `complete(Hash key)` Must be called by the search job queued by search() on success or failure
    `protected void` | `createHandlers()` unused, see override
    `void` | `flood(DatabaseEntry ds)` Send to a subset of all floodfill peers.
    `boolean` | `floodConditional(DatabaseEntry ds)` If we are floodfill AND the key is not throttled, flood it, otherwise don't.
    `boolean` | `floodfillEnabled()` For convenience, so users don't have to cast to FNDF, and unit tests using Dummy NDF will work.
    `List<Hash>` | `getFloodfillPeers()` list of the Hashes of currently known floodfill peers; Returned list will not include our own hash.
    `List<RouterInfo>` | `getKnownRouterData()`
    `String` | `getTunnelName(Destination d)`
    `static boolean` | `isFloodfill(RouterInfo peer)`
    `(package private) boolean` | `isVerifyInProgress(Hash h)`
    `protected void` | `lookupBeforeDropping(Hash peer, RouterInfo info)` Search for a newer router info, drop it from the db if the search fails, unless just started up or have bigger problems.
    `void` | `publish(RouterInfo localRouterInfo)` Send our RI to the closest floodfill.
    `(package private) SearchJob` | `search(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease)` Lookup using exploratory tunnels.
    `(package private) SearchJob` | `search(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease, Hash fromLocalDest)` Lookup using the client's tunnels.
    `(package private) void` | `sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore)` See implementation in FNDF
    `void` | `setFloodfillEnabled(boolean yes)` Public, called from console.
    `(package private) void` | `setFloodfillEnabledFromMonitor(boolean yes)` Package private, called from FloodfillMonitorJob.
    `(package private) boolean` | `shouldBanLookup(Hash from, TunnelId id)`
    `(package private) boolean` | `shouldThrottleFlood(Hash key)` Increments and tests.
    `(package private) boolean` | `shouldThrottleLookup(Hash from, TunnelId id)` Increments and tests.
    `void` | `shutdown()` If we are floodfill, turn it off and tell everybody.
    `void` | `startup()` Instruct the service that it should start normal operation.
    `(package private) void` | `verifyFinished(Hash h)`
    `(package private) void` | `verifyStarted(Hash h)`

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

      `blindCache, createPeerSelector, dropAfterLookupFailed, fail, failPermanently, findNearestRouters, getAllRouters, getBlindData, getBlindData, getClientLeases, getDataStore, getDbDir, getExploreKeys, getFloodfillLeases, getKBuckets, getKBucketSetSize, getKnownLeaseSets, getKnownRouters, getLastExploreNewDate, getLastRouterInfoPublishTime, getLeases, getPeerSelector, getPeerTimeout, getPublishedLeases, getRouters, getStoredRouterInfoCount, getUnpublishedLeases, hasActiveRepublishJob, isClientDb, isInitialized, isNegativeCached, isNegativeCachedForever, isNewer, lookupDestination, lookupDestinationLocally, lookupFailed, lookupLeaseSet, lookupLeaseSet, lookupLeaseSetLocally, lookupLeaseSetRemotely, lookupLeaseSetRemotely, lookupLocally, lookupLocallyWithoutValidation, lookupRouterInfo, lookupRouterInfoLocally, publish, queueForExploration, registerPublishingJob, removeBlindData, removeFromExploreKeys, removePublishingJob, renderStatusHTML, rescan, reseedChecker, routerInfoPublishSuccessful, routingKeyChanged, searchComplete, setBlindData, setLastExploreNewDate, stopPublishing, store, store, store, store, toString, unpublish, validate, validate`

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

      `store`

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

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

    - ### Methods inherited from interface net.i2p.router.Service

      `restart`

- - ### Field Detail

    - #### CAPABILITY_BW_UNLIMITED

          public static final char CAPABILITY_BW_UNLIMITED

      See Also:
        Constant Field Values

    - #### CAPABILITY_BW12

          public static final char CAPABILITY_BW12

      See Also:
        Constant Field Values

    - #### CAPABILITY_BW128

          public static final char CAPABILITY_BW128

      See Also:
        Constant Field Values

    - #### CAPABILITY_BW256

          public static final char CAPABILITY_BW256

      See Also:
        Constant Field Values

    - #### CAPABILITY_BW32

          public static final char CAPABILITY_BW32

      See Also:
        Constant Field Values

    - #### CAPABILITY_BW512

          public static final char CAPABILITY_BW512

      See Also:
        Constant Field Values

    - #### CAPABILITY_BW64

          public static final char CAPABILITY_BW64

      See Also:
        Constant Field Values

    - #### CAPABILITY_CONGESTION_MODERATE

          public static final char CAPABILITY_CONGESTION_MODERATE

      See Also:
        Constant Field Values

    - #### CAPABILITY_CONGESTION_SEVERE

          public static final char CAPABILITY_CONGESTION_SEVERE

      See Also:
        Constant Field Values

    - #### CAPABILITY_FLOODFILL

          public static final char CAPABILITY_FLOODFILL

      See Also:
        Constant Field Values

    - #### CAPABILITY_NO_TUNNELS

          public static final char CAPABILITY_NO_TUNNELS

      See Also:
        Constant Field Values

    - #### CAPABILITY_UNREACHABLE

          public static final char CAPABILITY_UNREACHABLE

      See Also:
        Constant Field Values

    - #### MAX_TO_FLOOD

          public static final int MAX_TO_FLOOD

      This is the flood redundancy. Entries are sent to this many other floodfills. Was 7 through release 0.9; 5 for 0.9.1. 4 as of 0.9.2; 3 as of 0.9.9
      See Also:
        Constant Field Values

    - #### MIN_ACTIVE_PEERS

          protected static final int MIN_ACTIVE_PEERS

      NTCP cons drop quickly but SSU takes a while, so it's prudent to keep this a little higher than 1 or 2.

    - #### NEXT_RKEY_RI_ADVANCE_TIME

          static final long NEXT_RKEY_RI_ADVANCE_TIME

      See Also:
        Constant Field Values

    - #### PROP_FLOODFILL_AT_RESTART

          public static final String PROP_FLOODFILL_AT_RESTART

      See Also:
        Constant Field Values

    - #### PROP_FLOODFILL_PARTICIPANT

          public static final String PROP_FLOODFILL_PARTICIPANT

      See Also:
        Constant Field Values

    - #### PUBLISH_TIMEOUT

          static final long PUBLISH_TIMEOUT

      This maybe could be shorter than RepublishLeaseSetJob.REPUBLISH_LEASESET_TIMEOUT, because we are sending direct, but unresponsive floodfills may take a while due to timeouts.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FloodfillNetworkDatabaseFacade

          public FloodfillNetworkDatabaseFacade(RouterContext context)

      Main DB

    - #### FloodfillNetworkDatabaseFacade

          public FloodfillNetworkDatabaseFacade(RouterContext context,
                                                Hash dbid)

      Sub DBs
      Parameters:
        `dbid` - null for main DB

  - ### Method Detail

    - #### complete

          void complete(Hash key)

      Must be called by the search job queued by search() on success or failure

    - #### createHandlers

          protected void createHandlers()

      Description copied from class: `KademliaNetworkDatabaseFacade`
      unused, see override
      Overrides:
        `createHandlers` in class `KademliaNetworkDatabaseFacade`

    - #### flood

          public void flood(DatabaseEntry ds)

      Send to a subset of all floodfill peers. We do this to implement Kademlia within the floodfills, i.e. we flood to those closest to the key.

    - #### floodConditional

          public boolean floodConditional(DatabaseEntry ds)

      If we are floodfill AND the key is not throttled, flood it, otherwise don't.
      Returns:
        if we did

    - #### floodfillEnabled

          public boolean floodfillEnabled()

      Description copied from class: `NetworkDatabaseFacade`
      For convenience, so users don't have to cast to FNDF, and unit tests using Dummy NDF will work.
      Overrides:
        `floodfillEnabled` in class `NetworkDatabaseFacade`
      Returns:
        false; FNDF overrides to return actual setting

    - #### getFloodfillPeers

          public List<Hash> getFloodfillPeers()

      list of the Hashes of currently known floodfill peers; Returned list will not include our own hash. List is not sorted and not shuffled.

    - #### getKnownRouterData

          public List<RouterInfo> getKnownRouterData()

    - #### getTunnelName

          public String getTunnelName(Destination d)

    - #### isFloodfill

          public static boolean isFloodfill(RouterInfo peer)

      Parameters:
        `peer` - may be null, returns false if null

    - #### isVerifyInProgress

          boolean isVerifyInProgress(Hash h)

    - #### lookupBeforeDropping

          protected void lookupBeforeDropping(Hash peer,
                                              RouterInfo info)

      Search for a newer router info, drop it from the db if the search fails, unless just started up or have bigger problems.
      Overrides:
        `lookupBeforeDropping` in class `KademliaNetworkDatabaseFacade`

    - #### publish

          public void publish(RouterInfo localRouterInfo)
                       throws IllegalArgumentException

      Send our RI to the closest floodfill.
      Overrides:
        `publish` in class `KademliaNetworkDatabaseFacade`
      Throws:
        `IllegalArgumentException` - if the local router info is invalid

    - #### search

          SearchJob search(Hash key,
                           Job onFindJob,
                           Job onFailedLookupJob,
                           long timeoutMs,
                           boolean isLease)

      Lookup using exploratory tunnels. Caller should check negative cache and/or banlist before calling. Begin a kademlia style search for the key specified, which can take up to timeoutMs and will fire the appropriate jobs on success or timeout (or if the kademlia search completes without any match)
      Overrides:
        `search` in class `KademliaNetworkDatabaseFacade`
      Returns:
        null always

    - #### search

          SearchJob search(Hash key,
                           Job onFindJob,
                           Job onFailedLookupJob,
                           long timeoutMs,
                           boolean isLease,
                           Hash fromLocalDest)

      Lookup using the client's tunnels. Caller should check negative cache and/or banlist before calling.
      Overrides:
        `search` in class `KademliaNetworkDatabaseFacade`
      Parameters:
        `fromLocalDest` - use these tunnels for the lookup, or null for exploratory
      Returns:
        null always

    - #### sendStore

          void sendStore(Hash key,
                         DatabaseEntry ds,
                         Job onSuccess,
                         Job onFailure,
                         long sendTimeout,
                         Set<Hash> toIgnore)

      Description copied from class: `KademliaNetworkDatabaseFacade`
      See implementation in FNDF
      Specified by:
        `sendStore` in class `KademliaNetworkDatabaseFacade`
      Parameters:
        `key` - the DatabaseEntry hash
        `onSuccess` - may be null, always called if we are ff and ds is an RI
        `onFailure` - may be null, ignored if we are ff and ds is an RI
        `sendTimeout` - ignored if we are ff and ds is an RI
        `toIgnore` - may be null, if non-null, all attempted and skipped targets will be added as of 0.9.53, unused if we are ff and ds is an RI

    - #### setFloodfillEnabled

          public void setFloodfillEnabled(boolean yes)

      Public, called from console. This wakes up the floodfill monitor, which will rebuild the RI and log in the event log, and call setFloodfillEnabledFromMonitor which really sets it.

    - #### setFloodfillEnabledFromMonitor

          void setFloodfillEnabledFromMonitor(boolean yes)

      Package private, called from FloodfillMonitorJob. This does not wake up the floodfill monitor.

    - #### shouldBanLookup

          boolean shouldBanLookup(Hash from,
                                  TunnelId id)

    - #### shouldThrottleFlood

          boolean shouldThrottleFlood(Hash key)

      Increments and tests.

    - #### shouldThrottleLookup

          boolean shouldThrottleLookup(Hash from,
                                       TunnelId id)

      Increments and tests.

    - #### shutdown

          public void shutdown()

      If we are floodfill, turn it off and tell everybody.
      Specified by:
        `shutdown` in interface `Service`
      Overrides:
        `shutdown` in class `KademliaNetworkDatabaseFacade`

    - #### startup

          public void startup()

      Description copied from interface: `Service`
      Instruct the service that it should start normal operation. This call DOES block until the service is ready.
      Specified by:
        `startup` in interface `Service`
      Overrides:
        `startup` in class `KademliaNetworkDatabaseFacade`

    - #### verifyFinished

          void verifyFinished(Hash h)

    - #### verifyStarted

          void verifyStarted(Hash h)