java.lang.Object
net.i2p.router.networkdb.kademlia.BlindCache
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentHashMap<SigningPublicKey, BlindData> The blind data, by our unblinded signing key.private booleanTrue when the cache awaits a save.private final RouterContextThe router doing the lookups.private final ConcurrentHashMap<Hash, BlindData> The blind data, by destination hash.private final ConcurrentHashMap<SigningPublicKey, BlindData> The blind data, by the blinded peer signing key.private static final intMost entries kept in the cache.private static final StringFile the cache is persisted to.Constructor Summary
ConstructorsConstructorDescriptionBlindCache(RouterContext ctx) Caller MUST callstartup()to load persistent cache from disk.Method Summary
Modifier and TypeMethodDescriptionvoidaddToCache(BlindData bd) Persists immediately if secret or privkey is non-null.private voidEnforce maximum cache size.private BlindDatafromPersistentString(String line) Format: sigtype,bsigtype,authtype,timestamp,b64 pubkey,[b64 secret],[b64 auth privkey],[b64 dest]getBlindedHash(Destination dest) The hash to lookup for a dest.The hash to lookup for a SPK known to be blinded.getData()For console ConfigKeyringHelper.getData(Destination dest) The cached data or null.getData(SigningPublicKey spk) The cached data or null.getHash(Destination dest) The hash to lookup for a dest.The hash to lookup for a dest hash.The cached data or null.private voidload()Load from file.booleanFor console ConfigKeyringHelper.voidrollover()Refresh all the data at midnight.voidsetBlinded(Destination dest) Add the destination to the cache entry.voidsetBlinded(Destination dest, SigType blindedType, String secret) Mark a destination as known to be blinded.voidshutdown()May be restarted by calling startup() again.voidstartup()Load persistent cache from disk.private voidstore()Writes the cache to the file.private voidAdd blinded lookup data to the cache.private static StringFormat: sigtype,bsigtype,authtype,timestamp,b64 pubkey,[b64 secret],[b64 auth privkey],[b64 dest]
Field Details
_context
The router doing the lookups._cache
The blind data, by our unblinded signing key._reverseCache
The blind data, by the blinded peer signing key._hashCache
The blind data, by destination hash._changed
private boolean _changedTrue when the cache awaits a save.PERSIST_FILE
File the cache is persisted to.- See Also:
MAX_CACHE_SIZE
private static final int MAX_CACHE_SIZEMost entries kept in the cache.- See Also:
Constructor Details
BlindCache
Caller MUST callstartup()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
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
getBlindedHash
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
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
Mark a destination as known to be blinded.- Parameters:
dest- known to be blindedblindedType- null for defaultsecret- may be null- Throws:
IllegalArgumentException- on various errors
setBlinded
Add the destination to the cache entry. Must previously be in cache.- Parameters:
dest- known to be blinded- Throws:
IllegalArgumentException- on various errors
addToCache
Persists immediately if secret or privkey is non-null.- Parameters:
bd- the blind data to add
storeInCache
Add blinded lookup data to the cache.- Parameters:
bd- the blind data to place in the in-memory caches
getData
The cached data or null.- Parameters:
dest- the destination to look up- Returns:
- the cached BlindData or null
getData
The cached data or null.- Parameters:
spk- the unblinded public key- Returns:
- the cached BlindData or null
getReverseData
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
removeBlindData
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
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 bytoPersistentString(BlindData)- Returns:
- the parsed blind data, never null
- Throws:
DataFormatException- if the line is malformed, or a signature type is unknown or unavailable
toPersistentString
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)