java.lang.Object
net.i2p.router.networkdb.kademlia.BlindCache

class BlindCacheextends Object
Cache for blinding data as specified in I2P proposal 123.

Manages blinded and unblinded key mappings with persistent storage and automatic rollover at midnight UTC. Provides lookup operations for both blinded destinations and their corresponding unblinded hashes.

  • Field Details

  • Constructor Details

    • BlindCache

      public BlindCache(RouterContext ctx)
      Caller MUST call startup() to load persistent cache from disk.
      Parameters:
      ctx - the router context
  • Method Details

    • shutdown

      public void shutdown()
      May be restarted by calling startup() again.
    • enforceMaxSize

      private void enforceMaxSize()
      Enforce maximum cache size.
    • startup

      public void startup()
      Load persistent cache from disk.
    • getHash

      public Hash getHash(Destination dest)
      The hash to lookup for a dest. If known to be blinded, returns the current blinded hash. If not known to be blinded, returns the standard dest hash.
      Parameters:
      dest - may or may not be blinded
      Returns:
      the unblinded or blinded hash
    • getHash

      public Hash getHash(Hash h)
      The hash to lookup for a dest hash. If known to be blinded, returns the current blinded hash. If not known to be blinded, returns h.
      Parameters:
      h - may or may not be blinded
      Returns:
      the blinded hash or h
    • getBlindedHash

      public Hash getBlindedHash(Destination dest)
      The hash to lookup for a dest. If known to be blinded, returns the current blinded hash. If not known to be blinded, returns null.
      Parameters:
      dest - may or may not be blinded
      Returns:
      the blinded hash or null if not blinded
    • getBlindedHash

      public Hash getBlindedHash(SigningPublicKey spk)
      The hash to lookup for a SPK known to be blinded. Default blinded type assumed. Secret assumed null.
      Parameters:
      spk - known to be blinded
      Returns:
      the blinded hash
      Throws:
      IllegalArgumentException - on various errors
    • setBlinded

      public void setBlinded(Destination dest, SigType blindedType, String secret)
      Mark a destination as known to be blinded.
      Parameters:
      dest - known to be blinded
      blindedType - null for default
      secret - may be null
      Throws:
      IllegalArgumentException - on various errors
    • setBlinded

      public void setBlinded(Destination dest)
      Add the destination to the cache entry. Must previously be in cache.
      Parameters:
      dest - known to be blinded
      Throws:
      IllegalArgumentException - on various errors
    • addToCache

      public void addToCache(BlindData bd)
      Persists immediately if secret or privkey is non-null.
      Parameters:
      bd - the blind data to add
    • storeInCache

      private void storeInCache(BlindData bd)
      Add blinded lookup data to the cache.
      Parameters:
      bd - the blind data to place in the in-memory caches
    • getData

      public BlindData getData(Destination dest)
      The cached data or null.
      Parameters:
      dest - the destination to look up
      Returns:
      the cached BlindData or null
    • getData

      public BlindData getData(SigningPublicKey spk)
      The cached data or null.
      Parameters:
      spk - the unblinded public key
      Returns:
      the cached BlindData or null
    • getReverseData

      public BlindData getReverseData(SigningPublicKey spk)
      The cached data or null.
      Parameters:
      spk - the blinded public key
      Returns:
      the cached BlindData or null
    • rollover

      public void rollover()
      Refresh all the data at midnight.
    • getData

      public List<BlindData> getData()
      For console ConfigKeyringHelper.
      Returns:
      list is copied
    • removeBlindData

      public boolean removeBlindData(SigningPublicKey spk)
      For console ConfigKeyringHelper. Persists immediately if removed.
      Parameters:
      spk - the unblinded public key
      Returns:
      true if removed
    • load

      private void load()
      Load from file. Format: sigtype,bsigtype,authtype,timestamp,b64 pubkey,[b64 secret],[b64 auth privkey],[b64 dest]

      If timestamp is positive, it's a creation date; if negative, it's a negative expiration date.

    • store

      private void store()
      Writes the cache to the file.
    • fromPersistentString

      private BlindData fromPersistentString(String line) throws DataFormatException
      Format: sigtype,bsigtype,authtype,timestamp,b64 pubkey,[b64 secret],[b64 auth privkey],[b64 dest]

      If timestamp is positive, it's a creation date; if negative, it's a negative expiration date.

      Parameters:
      line - the comma-separated record as written by toPersistentString(BlindData)
      Returns:
      the parsed blind data, never null
      Throws:
      DataFormatException - if the line is malformed, or a signature type is unknown or unavailable
    • toPersistentString

      private static String toPersistentString(BlindData bd)
      Format: sigtype,bsigtype,authtype,timestamp,b64 pubkey,[b64 secret],[b64 auth privkey],[b64 dest]

      If timestamp is positive, it's a creation date; if negative, it's a negative expiration date.

      Parameters:
      bd - the blind data to encode
      Returns:
      the comma-separated record, parseable by fromPersistentString(String)