java.lang.Object
net.i2p.router.networkdb.kademlia.TransientDataStore
All Implemented Interfaces:
DataStore
Direct Known Subclasses:
PersistentDataStore

class TransientDataStoreextends Object implements DataStore
In-memory network database storage implementation.

Provides volatile storage for database entries with no persistence to disk. Optimized for fast access and low memory footprint with concurrent operations using ConcurrentHashMap for thread-safe access patterns.

Primarily used for client network databases and temporary storage during router operations where persistence is not required.

Note: This should not be used for the main router database where persistence is necessary. Use PersistentDataStore instead.

  • Field Details

    • _log

      protected final Log _log
      Logger for this data store.
    • _data

      private final ConcurrentHashMap<Hash, DatabaseEntry> _data
      Entries held only for this router's uptime.
    • _context

      protected final RouterContext _context
      Router context this store was constructed with.
    • _banLogger

      private final BanLogger _banLogger
      Peers that have sent bad data.
  • Constructor Details

    • TransientDataStore

      public TransientDataStore(RouterContext ctx)
      Build an empty volatile store, pre-sizing the entry map and the ban logger.
      Parameters:
      ctx - router context supplying the log manager and initializing the ban logger
  • Method Details

    • isInitialized

      public boolean isInitialized()
      Whether the data store is initialized.
      Specified by:
      isInitialized in interface DataStore
      Returns:
      always true, an in-memory store has nothing to initialize
    • stop

      public void stop()
      Clear the in-memory store.
      Specified by:
      stop in interface DataStore
    • rescan

      public void rescan()
      No-op - the in-memory store has no external state to rescan.
      Specified by:
      rescan in interface DataStore
    • size

      public int size()
      Entries currently stored.
      Specified by:
      size in interface DataStore
      Returns:
      total size (RI and LS)
    • getKeys

      public Set<Hash> getKeys()
      Keys of all stored entries.
      Specified by:
      getKeys in interface DataStore
      Returns:
      Unmodifiable view, not a copy
    • getEntries

      public Collection<DatabaseEntry> getEntries()
      All stored entries.
      Specified by:
      getEntries in interface DataStore
      Returns:
      Unmodifiable view, not a copy
    • getMapEntries

      public Set<Map.Entry<Hash, DatabaseEntry>> getMapEntries()
      All stored entries as key-value pairs.
      Specified by:
      getMapEntries in interface DataStore
      Returns:
      Unmodifiable view, not a copy
    • get

      public DatabaseEntry get(Hash key, boolean persist)
      For PersistentDataStore only - don't use here.
      Specified by:
      get in interface DataStore
      Parameters:
      key - the hash key to look up
      persist - if true, keep the entry in persistent storage
      Returns:
      the database entry, or null if not found
      Throws:
      UnsupportedOperationException - always, this store has no persistence layer
    • get

      public DatabaseEntry get(Hash key)
      The entry for the key, or null if not found.
      Specified by:
      get in interface DataStore
      Parameters:
      key - the hash to look up
      Returns:
      the entry or null
    • isKnown

      public boolean isKnown(Hash key)
      Whether the data store contains the key.
      Specified by:
      isKnown in interface DataStore
      Parameters:
      key - the hash key to look up
      Returns:
      true if an entry is held for key
    • countLeaseSets

      public int countLeaseSets()
      Number of lease sets in the store.
      Specified by:
      countLeaseSets in interface DataStore
      Returns:
      the number of LeaseSets stored
    • put

      public boolean put(Hash key, DatabaseEntry data, boolean persist)
      For PersistentDataStore only - don't use here.
      Specified by:
      put in interface DataStore
      Parameters:
      key - the hash key to store under
      data - the database entry to store
      persist - if true, keep the entry in persistent storage
      Returns:
      true if the store was successful
      Throws:
      UnsupportedOperationException - always, this store has no persistence layer
    • put

      public boolean put(Hash key, DatabaseEntry data)
      Store an entry, replacing any previous one for the key.
      Specified by:
      put in interface DataStore
      Parameters:
      key - the hash key to store under
      data - must be validated before here
      Returns:
      true only if the entry was stored; false for null data, a banned RouterInfo, or an entry older than the one held
    • forcePut

      public boolean forcePut(Hash key, DatabaseEntry data)
      Unconditionally store, bypass all newer/older checks.
      Specified by:
      forcePut in interface DataStore
      Parameters:
      key - non-null
      data - non-null
      Returns:
      always true, the entry replaces any existing one
    • toString

      public String toString()
      Debug string listing all stored entries.
      Overrides:
      toString in class Object
    • remove

      public DatabaseEntry remove(Hash key, boolean persist)
      For PersistentDataStore only - don't use here.
      Specified by:
      remove in interface DataStore
      Parameters:
      key - the hash key to remove
      persist - if true, also remove from persistent storage
      Returns:
      the removed database entry, or null if not found
      Throws:
      UnsupportedOperationException - always, this store has no persistence layer
    • remove

      public DatabaseEntry remove(Hash key)
      Remove and return the entry for the key.
      Specified by:
      remove in interface DataStore
      Parameters:
      key - the hash to remove
      Returns:
      the removed entry, or null if not found
    • containsCapability

      private boolean containsCapability(RouterInfo ri, char capability)
      True if the router offers the capability.
      Parameters:
      ri - the router to check
      capability - the capability letter to look for
      Returns:
      true if it offers it