java.lang.Object
net.i2p.router.NetworkDatabaseFacade
All Implemented Interfaces:
Service
Direct Known Subclasses:
DummyNetworkDatabaseFacade, KademliaNetworkDatabaseFacade

public abstract class NetworkDatabaseFacadeextends Object implements Service
Abstract interface for I2P network database operations. Provides router info and lease set lookup, storage, and search functionality for peer discovery and routing.
  • Constructor Details

    • NetworkDatabaseFacade

      protected NetworkDatabaseFacade()
      The abstract facade holds no state of its own; subclasses initialize themselves through their own constructors.
  • Method Details

    • findNearestRouters

      public abstract Set<Hash> findNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore)
      Return the RouterInfo structures for the routers closest to the given key. At most maxNumRouters will be returned.
      Parameters:
      key - the hash to measure Kademlia distance from, normally our own router hash
      maxNumRouters - The maximum number of routers to return
      peersToIgnore - Hash of routers not to include
      Returns:
      set of router hashes closest to the key
    • lookupLocally

      public abstract DatabaseEntry lookupLocally(Hash key)
      Lookup a database entry locally.
      Parameters:
      key - the hash of the RouterInfo or LeaseSet to look up
      Returns:
      RouterInfo, LeaseSet, or null
    • lookupLocallyWithoutValidation

      public abstract DatabaseEntry lookupLocallyWithoutValidation(Hash key)
      Not for use without validation.
      Parameters:
      key - the hash of the RouterInfo or LeaseSet to look up
      Returns:
      RouterInfo, LeaseSet, or null, NOT validated
    • lookupLeaseSet

      public abstract void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
      Lookup a LeaseSet in the network database.
      Parameters:
      key - the destination hash whose LeaseSet is sought
      onFindJob - job to run on success
      onFailedLookupJob - job to run on failure
      timeoutMs - timeout in milliseconds
    • lookupLeaseSet

      public abstract void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest)
      Lookup using the client's tunnels.
      Parameters:
      key - the destination hash whose LeaseSet is sought
      onFindJob - job to run on success
      onFailedLookupJob - job to run on failure
      timeoutMs - timeout in milliseconds
      fromLocalDest - use these tunnels for the lookup, or null for exploratory
    • lookupLeaseSetLocally

      public abstract LeaseSet lookupLeaseSetLocally(Hash key)
      Look up a LeaseSet in the local network database.
      Parameters:
      key - the destination hash whose LeaseSet is sought
      Returns:
      the LeaseSet, or null if not found
    • lookupRouterInfo

      public abstract void lookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
      Look up a RouterInfo in the network database.
      Parameters:
      key - the router hash whose RouterInfo is sought
      onFindJob - job to run on success
      onFailedLookupJob - job to run on failure
      timeoutMs - timeout in milliseconds
    • lookupRouterInfoLocally

      public abstract RouterInfo lookupRouterInfoLocally(Hash key)
      Look up a RouterInfo in the local network database.
      Parameters:
      key - the router hash whose RouterInfo is sought
      Returns:
      the RouterInfo, or null if not found
    • lookupLeaseSetRemotely

      public abstract void lookupLeaseSetRemotely(Hash key, Hash fromLocalDest)
      Unconditionally lookup using the client's tunnels. No success or failed jobs, no local lookup, no checks. Use this to refresh a leaseset before expiration.
      Parameters:
      key - the destination hash whose LeaseSet is sought
      fromLocalDest - use these tunnels for the lookup, or null for exploratory
    • lookupLeaseSetRemotely

      public abstract void lookupLeaseSetRemotely(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest)
      Unconditionally lookup using the client's tunnels.
      Parameters:
      key - the destination hash whose LeaseSet is sought
      onFindJob - may be null
      onFailedLookupJob - may be null
      timeoutMs - timeout in milliseconds
      fromLocalDest - use these tunnels for the lookup, or null for exploratory
    • lookupDestination

      public abstract void lookupDestination(Hash key, Job onFinishedJob, long timeoutMs, Hash fromLocalDest)
      Lookup using the client's tunnels Succeeds even if LS validation fails due to unsupported sig type.
      Parameters:
      key - the destination hash whose LeaseSet is sought
      onFinishedJob - job to run on success
      timeoutMs - timeout in milliseconds
      fromLocalDest - use these tunnels for the lookup, or null for exploratory
    • lookupDestinationLocally

      public abstract Destination lookupDestinationLocally(Hash key)
      Lookup locally in netDB and in badDest cache Succeeds even if LS validation failed due to unsupported sig type.
      Parameters:
      key - the destination hash to look up
      Returns:
      the Destination, or null if it is not known or is cached as bad
    • store

      public abstract LeaseSet store(Hash key, LeaseSet leaseSet) throws IllegalArgumentException
      Store a LeaseSet in the network database.
      Parameters:
      key - the destination hash to file the LeaseSet under
      leaseSet - the LeaseSet to store
      Returns:
      the leaseSet if another leaseSet already existed at that key
      Throws:
      IllegalArgumentException - if the data is not valid
    • accessLeaseSet

      public abstract void accessLeaseSet(Hash key)
      Record access to a LeaseSet for refresh tracking. Only tracks if we have tunnels built AND there's a hostname.
      Parameters:
      key - the destination hash of the LeaseSet that was used
    • removeLeaseSetFromTracking

      public abstract void removeLeaseSetFromTracking(Hash key)
      Remove a LeaseSet from refresh tracking. Call this after HostChecker completes to avoid unnecessary refreshes.
      Parameters:
      key - the destination hash of the LeaseSet to stop tracking
    • store

      public abstract RouterInfo store(Hash key, RouterInfo routerInfo) throws IllegalArgumentException
      Store a RouterInfo in the network database.
      Parameters:
      key - the router hash to file the RouterInfo under
      routerInfo - the RouterInfo to store
      Returns:
      the routerInfo if another router already existed at that key
      Throws:
      IllegalArgumentException - if the data is not valid
    • store

      public DatabaseEntry store(Hash key, DatabaseEntry entry) throws IllegalArgumentException
      Store a DatabaseEntry in the network database.
      Parameters:
      key - the hash to file the entry under
      entry - the entry to store
      Returns:
      the old entry if it already existed at that key
      Throws:
      IllegalArgumentException - if the data is not valid
    • publish

      public abstract void publish(RouterInfo localRouterInfo) throws IllegalArgumentException
      Publish a RouterInfo to the network database.
      Parameters:
      localRouterInfo - the RouterInfo to publish
      Throws:
      IllegalArgumentException - if the local router is not valid
    • publish

      public abstract void publish(LeaseSet localLeaseSet)
      Publish a LeaseSet to the network database.
      Parameters:
      localLeaseSet - the LeaseSet to publish
    • unpublish

      public abstract void unpublish(LeaseSet localLeaseSet)
      Unpublish a LeaseSet from the network database.
      Parameters:
      localLeaseSet - the LeaseSet to unpublish
    • fail

      public abstract void fail(Hash dbEntry)
      Mark a database entry as failed.
      Parameters:
      dbEntry - the key of the entry to fail
    • getLastRouterInfoPublishTime

      public long getLastRouterInfoPublishTime()
      The last time we successfully published our RI.
      Returns:
      the timestamp, or 0
    • getAllRouters

      public abstract Set<Hash> getAllRouters()
      All known router hashes.
      Returns:
      set of router hashes
    • getKnownRouters

      public int getKnownRouters()
      Number of known routers.
      Returns:
      the count, 0 in this do-nothing base implementation
    • getKnownLeaseSets

      public int getKnownLeaseSets()
      Number of known LeaseSets.
      Returns:
      the count, 0 in this do-nothing base implementation
    • isInitialized

      public boolean isInitialized()
      Is the network database initialized?
      Returns:
      true if initialized
    • rescan

      public void rescan()
      Rescan the network database.
    • renderStatusHTML

      public void renderStatusHTML(Writer out) throws IOException
      Debug only - all user info moved to NetDbRenderer in router console.
      Specified by:
      renderStatusHTML in interface Service
      Parameters:
      out - the writer to write to
      Throws:
      IOException - if an error occurs writing
    • getDebugStats

      public long[] getDebugStats()
      Debug overview stats: total keys, bucket count, per-bucket capacity and fullest bucket size, as {keys, buckets, capacity, fullest}. Null where the facade has no kademlia buckets.
      Returns:
      the stats, or null
    • getLeases

      public Set<LeaseSet> getLeases()
      All known LeaseSets for display.
      Returns:
      set of LeaseSets, or empty
    • getRouters

      public Set<RouterInfo> getRouters()
      Public for NetDbRenderer in routerconsole.
      Returns:
      the set of known RouterInfos, empty in the base facade
    • getClientLeases

      public Set<LeaseSet> getClientLeases()
      The known client LeaseSets. Public for NetDbRenderer in routerconsole.
      Returns:
      the client leases
    • getPublishedLeases

      public Set<LeaseSet> getPublishedLeases()
      The known published LeaseSets. Public for NetDbRenderer in routerconsole.
      Returns:
      the published leases
    • getUnpublishedLeases

      public Set<LeaseSet> getUnpublishedLeases()
      The known unpublished LeaseSets. Public for NetDbRenderer in routerconsole.
      Returns:
      the unpublished leases
    • getFloodfillLeases

      public Set<LeaseSet> getFloodfillLeases()
      The known floodfill LeaseSets. Public for NetDbRenderer in routerconsole.
      Returns:
      the floodfill leases
    • reseedChecker

      public ReseedChecker reseedChecker()
      The reseed checker; the base facade has none, FNDF overrides this.
      Returns:
      the reseed checker, or null in the base facade
    • floodfillEnabled

      public boolean floodfillEnabled()
      For convenience, so users don't have to cast to FNDF, and unit tests using Dummy NDF will work.
      Returns:
      false; FNDF overrides to return actual setting
    • isNegativeCachedForever

      public boolean isNegativeCachedForever(Hash key)
      Is it permanently negative cached?
      Parameters:
      key - only for Destinations; for RouterIdentities, see Banlist
      Returns:
      whether negative cached forever
    • getBlindData

      public BlindData getBlindData(SigningPublicKey spk)
      Look up the cached BlindData for the given key.
      Parameters:
      spk - unblinded key
      Returns:
      BlindData or null
    • setBlindData

      public void setBlindData(BlindData bd)
      Cache the given BlindData for later lookup.
      Parameters:
      bd - new BlindData to put in the cache
    • getBlindData

      public List<BlindData> getBlindData()
      The blind data for the given unblinded key, for console ConfigKeyringHelper.
      Returns:
      the blind data
    • removeBlindData

      public boolean removeBlindData(SigningPublicKey spk)
      For console ConfigKeyringHelper.
      Parameters:
      spk - the signing key whose blind data is to be dropped
      Returns:
      true if removed
    • routingKeyChanged

      public void routingKeyChanged()
      Notify the netDB that the routing key changed at midnight UTC.
    • purgeMatchingRouters

      public void purgeMatchingRouters()
      Trigger a retroactive purge sweep of the NetDb. Bans and removes all routers matching enabled LU/XG/custom-cap bans.