java.lang.Object
net.i2p.router.NetworkDatabaseFacade
net.i2p.router.dummy.DummyNetworkDatabaseFacade
All Implemented Interfaces:
Service

public class DummyNetworkDatabaseFacadeextends NetworkDatabaseFacade
In-memory network database implementation for testing and development scenarios. Provides basic router info storage and lookup functionality without persistence or network communication.
  • Field Details

    • _routers

      private final Map<Hash, RouterInfo> _routers
      Routers this dummy database knows.
    • _context

      private final RouterContext _context
      The router context the facade belongs to.
  • Constructor Details

    • DummyNetworkDatabaseFacade

      public DummyNetworkDatabaseFacade(RouterContext ctx)
      Create an empty in-memory database; nothing is read from disk.
      Parameters:
      ctx - the router context, kept for callers that need the log or config
  • Method Details

    • restart

      public void restart()
      Restart the network database, retaining the in-memory store.
    • shutdown

      public void shutdown()
      Shut down and release resources.
    • startup

      public void startup()
      Start the network database and register the local router info.
    • lookupLocally

      public DatabaseEntry lookupLocally(Hash key)
      Description copied from class: NetworkDatabaseFacade
      Lookup a database entry locally.
      Specified by:
      lookupLocally in class NetworkDatabaseFacade
      Parameters:
      key - the hash of the RouterInfo or LeaseSet to look up
      Returns:
      RouterInfo, LeaseSet, or null
    • lookupLocallyWithoutValidation

      public DatabaseEntry lookupLocallyWithoutValidation(Hash key)
      Description copied from class: NetworkDatabaseFacade
      Not for use without validation.
      Specified by:
      lookupLocallyWithoutValidation in class NetworkDatabaseFacade
      Parameters:
      key - the hash of the RouterInfo or LeaseSet to look up
      Returns:
      RouterInfo, LeaseSet, or null, NOT validated
    • lookupLeaseSet

      public void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
      Look up a lease set in the network database.
      Specified by:
      lookupLeaseSet in class NetworkDatabaseFacade
      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 void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest)
      Description copied from class: NetworkDatabaseFacade
      Lookup using the client's tunnels.
      Specified by:
      lookupLeaseSet in class NetworkDatabaseFacade
      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 LeaseSet lookupLeaseSetLocally(Hash key)
      Description copied from class: NetworkDatabaseFacade
      Look up a LeaseSet in the local network database.
      Specified by:
      lookupLeaseSetLocally in class NetworkDatabaseFacade
      Parameters:
      key - the destination hash whose LeaseSet is sought
      Returns:
      the LeaseSet, or null if not found
    • lookupLeaseSetRemotely

      public void lookupLeaseSetRemotely(Hash key, Hash fromLocalDest)
      Description copied from class: NetworkDatabaseFacade
      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.
      Specified by:
      lookupLeaseSetRemotely in class NetworkDatabaseFacade
      Parameters:
      key - the destination hash whose LeaseSet is sought
      fromLocalDest - use these tunnels for the lookup, or null for exploratory
    • lookupLeaseSetRemotely

      public void lookupLeaseSetRemotely(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest)
      Description copied from class: NetworkDatabaseFacade
      Unconditionally lookup using the client's tunnels.
      Specified by:
      lookupLeaseSetRemotely in class NetworkDatabaseFacade
      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 void lookupDestination(Hash key, Job onFinishedJob, long timeoutMs, Hash fromLocalDest)
      Look up a destination using the client's tunnels.
      Specified by:
      lookupDestination in class NetworkDatabaseFacade
      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 Destination lookupDestinationLocally(Hash key)
      Look up a destination in the in-memory store.
      Specified by:
      lookupDestinationLocally in class NetworkDatabaseFacade
      Parameters:
      key - the destination hash to look up
      Returns:
      the Destination, or null if it is not known or is cached as bad
    • lookupRouterInfo

      public void lookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
      Look up a router info in the network database.
      Specified by:
      lookupRouterInfo in class NetworkDatabaseFacade
      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 RouterInfo lookupRouterInfoLocally(Hash key)
      Look up a router info in the in-memory store.
      Specified by:
      lookupRouterInfoLocally in class NetworkDatabaseFacade
      Parameters:
      key - the router hash whose RouterInfo is sought
      Returns:
      the RouterInfo, or null if not found
    • publish

      public void publish(LeaseSet localLeaseSet)
      Publish a key to the network.
      Specified by:
      publish in class NetworkDatabaseFacade
      Parameters:
      localLeaseSet - the LeaseSet to publish
    • publish

      public void publish(RouterInfo localRouterInfo)
      Publish a key to the network.
      Specified by:
      publish in class NetworkDatabaseFacade
      Parameters:
      localRouterInfo - the RouterInfo to publish
    • store

      public LeaseSet store(Hash key, LeaseSet leaseSet)
      Store a key locally.
      Specified by:
      store in class NetworkDatabaseFacade
      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
    • store

      public RouterInfo store(Hash key, RouterInfo routerInfo)
      Store a key locally.
      Specified by:
      store in class NetworkDatabaseFacade
      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
    • unpublish

      public void unpublish(LeaseSet localLeaseSet)
      Remove a key from publication.
      Specified by:
      unpublish in class NetworkDatabaseFacade
      Parameters:
      localLeaseSet - the LeaseSet to unpublish
    • accessLeaseSet

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

      public void removeLeaseSetFromTracking(Hash key)
      Remove a lease set from tracking.
      Specified by:
      removeLeaseSetFromTracking in class NetworkDatabaseFacade
      Parameters:
      key - the destination hash of the LeaseSet to stop tracking
    • fail

      public void fail(Hash dbEntry)
      Record a lookup failure.
      Specified by:
      fail in class NetworkDatabaseFacade
      Parameters:
      dbEntry - the key of the entry to fail
    • getAllRouters

      public Set<Hash> getAllRouters()
      Description copied from class: NetworkDatabaseFacade
      All known router hashes.
      Specified by:
      getAllRouters in class NetworkDatabaseFacade
      Returns:
      set of router hashes
    • findNearestRouters

      public Set<Hash> findNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore)
      Description copied from class: NetworkDatabaseFacade
      Return the RouterInfo structures for the routers closest to the given key. At most maxNumRouters will be returned.
      Specified by:
      findNearestRouters in class NetworkDatabaseFacade
      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