Class KademliaNetworkDatabaseFacade
java.lang.Object
net.i2p.router.NetworkDatabaseFacade
net.i2p.router.networkdb.kademlia.KademliaNetworkDatabaseFacade
- All Implemented Interfaces:
Service
- Direct Known Subclasses:
FloodfillNetworkDatabaseFacade
Kademlia based version of the network database.
Never instantiated directly; see FloodfillNetworkDatabaseFacade.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RouterContextprotected final Logprotected final intprotected final PeerSelectorstatic final Stringprotected static final longfor the 10 minutes after startup, don't fail db entries so that if we were offline for a while, we'll have a chance of finding some live peers with the previous references(package private) static final intprotected static final intif we have less than this many routers left, don't drop any more, even if they're failing or doing bad stuff.(package private) static final intReseed if below this.static final Stringprotected static final longthis needs to be long enough to give us time to start up, but less than 20m (when we start accepting tunnels and could be a IBGW) Actually no, we need this soon if we are a new router or other routers have forgotten about us, else we can't build IB exploratory tunnels. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected BlindCacheWe still always use a single blind cache in the main Db(for now), see issue #421 on i2pgit.org/i2p-hackers/i2p.i2p for details.protected voidunused, see overrideprotected PeerSelectorOnly for main DB(package private) voiddropAfterLookupFailed(Hash peer) Final remove for a router info.voidFinal remove for a leaseset.(package private) voidfailPermanently(Destination dest) Negative cache until restartfindNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore) Get the routers closest to that key in response to a remote lookup Only used by ../HDLMJ Set MAY INCLUDE our own router - add to peersToIgnore if you don't wantGet the hashes for all known routersFor console ConfigKeyringHelper(package private) DataStore(package private) StringgetDbDir()For the main DB only.(package private) KBucketSet<Hash> protected intThe KBucketSet contains RIs only.intThis is only used by StatisticsManager to publish the count if we are floodfill.intThis used to return the number of routers that were in both the kbuckets AND the data store, which was fine when the kbuckets held everything.(package private) longlongThe last time we successfully published our RI.public for NetDbRenderer in routerconsoleintgetPeerTimeout(Hash peer) todo: does this need more tuning?Public for NetDbRenderer in routerconsolebooleanCheck if the database is a client DB.boolean(package private) booleanisNegativeCached(Hash key) Is the key in the negative lookup cache?booleanIs it permanently negative cached?static booleanUtility to determine if a is newer than b.protected voidlookupBeforeDropping(Hash peer, RouterInfo info) don't use directly - see F.N.D.F.voidlookupDestination(Hash key, Job onFinishedJob, long timeoutMs, Hash fromLocalDest) Lookup using the client's tunnels Succeeds even if LS validation and store fails due to unsupported sig type, expired, etc.Lookup locally in netDB and in badDest cache Succeeds even if LS validation fails due to unsupported sig type, expired, etc.(package private) voidlookupFailed(Hash key) Increment in the negative lookup cachevoidlookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs) Lookup using exploratory tunnels.voidlookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest) Lookup using the client's tunnels Use lookupDestination() if you don't need the LS or don't need it validated.Use lookupDestination() if you don't need the LS or don't need it validated.voidlookupLeaseSetRemotely(Hash key, Hash fromLocalDest) Unconditionally lookup using the client's tunnels.voidlookupLeaseSetRemotely(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest) Unconditionally lookup using the client's tunnels.lookupLocally(Hash key) Not for use without validationvoidlookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs) This will return immediately with the result or null.voidStores in local netdb, and publishes to floodfill if client manager says tovoidpublish(RouterInfo localRouterInfo) Stores to local db only.voidqueueForExploration(Collection<Hash> keys) booleanFor console ConfigKeyringHelpervoidremoveFromExploreKeys(Collection<Hash> toRemove) voidrenderStatusHTML(Writer out) Debug info, HTML formattedvoidrescan()voidrestart()Deprecated.(package private) voidSet the last time we successfully published our RI.voidNotify the netDB that the routing key changed at midnight UTC(package private) SearchJobBegin a kademlia style search for the key specified, which can take up to timeoutMs and will fire the appropriate jobs on success or timeout (or if the kademlia search completes without any match) Unused - called only by FNDF.searchFull() from FloodSearchJob which is overridden - don't use this.(package private) SearchJobsearch(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease, Hash fromLocalDest) Unused - see FNDF(package private) voidsearchComplete(Hash key) The search for the given key is no longer active(package private) abstract voidsendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore) See implementation in FNDFvoid(package private) voidsetLastExploreNewDate(long when) voidshutdown()Cannot be restarted.voidstartup()Instruct the service that it should start normal operation.(package private) voidstopPublishing(Hash target) Store the leaseSet.Store the leaseSet.store(Hash key, RouterInfo routerInfo) Store the routerInfo.(package private) RouterInfostore(Hash key, RouterInfo routerInfo, boolean persist) Store the routerInfo.toString()voidDetermine whether this leaseSet will be accepted as valid and current given what we know now.(package private) Stringvalidate(RouterInfo routerInfo) Determine whether this routerInfo will be accepted as valid and current given what we know now.Methods inherited from class net.i2p.router.NetworkDatabaseFacade
floodfillEnabled, store
-
Field Details
-
_log
-
_peerSelector
-
_context
-
_networkID
protected final int _networkID -
DONT_FAIL_PERIOD
protected static final long DONT_FAIL_PERIODfor the 10 minutes after startup, don't fail db entries so that if we were offline for a while, we'll have a chance of finding some live peers with the previous references- See Also:
-
PROP_DB_DIR
- See Also:
-
DEFAULT_DB_DIR
- See Also:
-
MIN_RESEED
static final int MIN_RESEEDReseed if below this.- Since:
- 0.9.4
- See Also:
-
MIN_REMAINING_ROUTERS
protected static final int MIN_REMAINING_ROUTERSif we have less than this many routers left, don't drop any more, even if they're failing or doing bad stuff. As of 0.9.4, we make this LOWER than the min for reseeding, so a reseed will be forced if necessary.- See Also:
-
PUBLISH_JOB_DELAY
protected static final long PUBLISH_JOB_DELAYthis needs to be long enough to give us time to start up, but less than 20m (when we start accepting tunnels and could be a IBGW) Actually no, we need this soon if we are a new router or other routers have forgotten about us, else we can't build IB exploratory tunnels. Unused.- See Also:
-
MAX_EXPLORE_QUEUE
static final int MAX_EXPLORE_QUEUE- See Also:
-
-
Constructor Details
-
KademliaNetworkDatabaseFacade
-
-
Method Details
-
searchComplete
The search for the given key is no longer active -
isInitialized
public boolean isInitialized()- Overrides:
isInitializedin classNetworkDatabaseFacade
-
createPeerSelector
Only for main DB -
getPeerSelector
- Returns:
- the main DB's peer selector. Client DBs do not have their own.
-
reseedChecker
- Overrides:
reseedCheckerin classNetworkDatabaseFacade- Since:
- 0.9
-
blindCache
We still always use a single blind cache in the main Db(for now), see issue #421 on i2pgit.org/i2p-hackers/i2p.i2p for details. This checks if we're the main DB already and returns our blind cache if we are. If not, it looks up the main Db and gets it.- Returns:
- non-null
- Since:
- 0.9.61
-
getKBuckets
KBucketSet<Hash> getKBuckets()- Returns:
- the main DB's KBucketSet. Client DBs do not have their own.
-
getDataStore
DataStore getDataStore() -
getLastExploreNewDate
long getLastExploreNewDate() -
setLastExploreNewDate
void setLastExploreNewDate(long when) -
getExploreKeys
- Returns:
- unmodifiable set
-
removeFromExploreKeys
-
queueForExploration
-
shutdown
public void shutdown()Cannot be restarted. -
restart
Deprecated.Unsupported, do not use- Throws:
UnsupportedOperationException- always
-
rescan
public void rescan()- Overrides:
rescanin classNetworkDatabaseFacade
-
getDbDir
String getDbDir()For the main DB only. Sub DBs are not persisted and must not access this directory.- Returns:
- null before startup() is called; non-null thereafter, even for subdbs.
-
isClientDb
public boolean isClientDb()Check if the database is a client DB.- Returns:
- true if the database is a client DB, false otherwise
- Since:
- 0.9.61
-
startup
public void startup()Description copied from interface:ServiceInstruct the service that it should start normal operation. This call DOES block until the service is ready. -
createHandlers
protected void createHandlers()unused, see override -
findNearestRouters
Get the routers closest to that key in response to a remote lookup Only used by ../HDLMJ Set MAY INCLUDE our own router - add to peersToIgnore if you don't want- Specified by:
findNearestRoutersin classNetworkDatabaseFacade- Parameters:
key- the real key, NOT the routing keymaxNumRouters- The maximum number of routers to returnpeersToIgnore- can be null
-
getAllRouters
Get the hashes for all known routers- Specified by:
getAllRoutersin classNetworkDatabaseFacade- Returns:
- empty set if this is a client DB
-
getKnownRouters
public int getKnownRouters()This used to return the number of routers that were in both the kbuckets AND the data store, which was fine when the kbuckets held everything. But now that is probably not what you want. Just return the count in the data store.- Overrides:
getKnownRoutersin classNetworkDatabaseFacade- Returns:
- 0 if this is a client DB
-
getKnownLeaseSets
public int getKnownLeaseSets()This is only used by StatisticsManager to publish the count if we are floodfill. So to hide a clue that a popular eepsite is hosted on a floodfill router, only count leasesets that are "received as published", as of 0.7.14- Overrides:
getKnownLeaseSetsin classNetworkDatabaseFacade
-
getKBucketSetSize
protected int getKBucketSetSize()The KBucketSet contains RIs only. -
getBlindData
- Overrides:
getBlindDatain classNetworkDatabaseFacade- Parameters:
spk- unblinded key- Returns:
- BlindData or null
- Since:
- 0.9.40
-
setBlindData
- Overrides:
setBlindDatain classNetworkDatabaseFacade- Parameters:
bd- new BlindData to put in the cache- Since:
- 0.9.40
-
getBlindData
For console ConfigKeyringHelper- Overrides:
getBlindDatain classNetworkDatabaseFacade- Since:
- 0.9.41
-
removeBlindData
For console ConfigKeyringHelper- Overrides:
removeBlindDatain classNetworkDatabaseFacade- Parameters:
spk- the unblinded public key- Returns:
- true if removed
- Since:
- 0.9.41
-
routingKeyChanged
public void routingKeyChanged()Notify the netDB that the routing key changed at midnight UTC- Overrides:
routingKeyChangedin classNetworkDatabaseFacade- Since:
- 0.9.50
-
lookupLocally
- Specified by:
lookupLocallyin classNetworkDatabaseFacade- Returns:
- RouterInfo, LeaseSet, or null, validated
- Since:
- 0.8.3
-
lookupLocallyWithoutValidation
Not for use without validation- Specified by:
lookupLocallyWithoutValidationin classNetworkDatabaseFacade- Returns:
- RouterInfo, LeaseSet, or null, NOT validated
- Since:
- 0.9.9, public since 0.9.38
-
lookupLeaseSet
Lookup using exploratory tunnels. Use lookupDestination() if you don't need the LS or don't need it validated.- Specified by:
lookupLeaseSetin classNetworkDatabaseFacade
-
lookupLeaseSet
public void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest) Lookup using the client's tunnels Use lookupDestination() if you don't need the LS or don't need it validated.- Specified by:
lookupLeaseSetin classNetworkDatabaseFacade- Parameters:
fromLocalDest- use these tunnels for the lookup, or null for exploratory- Since:
- 0.9.10
-
lookupLeaseSetRemotely
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:
lookupLeaseSetRemotelyin classNetworkDatabaseFacade- Parameters:
fromLocalDest- use these tunnels for the lookup, or null for exploratory- Since:
- 0.9.25
-
lookupLeaseSetRemotely
public void lookupLeaseSetRemotely(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest) Unconditionally lookup using the client's tunnels.- Specified by:
lookupLeaseSetRemotelyin classNetworkDatabaseFacade- Parameters:
onFindJob- may be nullonFailedLookupJob- may be nullfromLocalDest- use these tunnels for the lookup, or null for exploratory- Since:
- 0.9.47
-
lookupLeaseSetLocally
Use lookupDestination() if you don't need the LS or don't need it validated.- Specified by:
lookupLeaseSetLocallyin classNetworkDatabaseFacade
-
lookupDestination
Lookup using the client's tunnels Succeeds even if LS validation and store fails due to unsupported sig type, expired, etc. Note that there are not separate success and fail jobs. Caller must call lookupDestinationLocally() in the job to determine success.- Specified by:
lookupDestinationin classNetworkDatabaseFacade- Parameters:
onFinishedJob- non-nullfromLocalDest- use these tunnels for the lookup, or null for exploratory- Since:
- 0.9.16
-
lookupDestinationLocally
Lookup locally in netDB and in badDest cache Succeeds even if LS validation fails due to unsupported sig type, expired, etc.- Specified by:
lookupDestinationLocallyin classNetworkDatabaseFacade- Since:
- 0.9.16
-
lookupRouterInfo
- Specified by:
lookupRouterInfoin classNetworkDatabaseFacade
-
lookupRouterInfoLocally
This will return immediately with the result or null. However, this may still fire off a lookup if the RI is present but expired (and will return null). This may result in deadlocks. For true local only, use lookupLocallyWithoutValidation()- Specified by:
lookupRouterInfoLocallyin classNetworkDatabaseFacade- Returns:
- null always for client dbs
-
publish
Stores in local netdb, and publishes to floodfill if client manager says to- Specified by:
publishin classNetworkDatabaseFacade- Throws:
IllegalArgumentException- if the leaseSet is not valid
-
stopPublishing
-
publish
Stores to local db only. Overridden in FNDF to actually send to the floodfills.- Specified by:
publishin classNetworkDatabaseFacade- Throws:
IllegalArgumentException- if the local router info is invalid or if this is a client DB
-
routerInfoPublishSuccessful
void routerInfoPublishSuccessful()Set the last time we successfully published our RI.- Since:
- 0.9.9
-
getLastRouterInfoPublishTime
public long getLastRouterInfoPublishTime()The last time we successfully published our RI.- Overrides:
getLastRouterInfoPublishTimein classNetworkDatabaseFacade- Since:
- 0.9.9
-
validate
Determine whether this leaseSet will be accepted as valid and current given what we know now. Unlike for RouterInfos, this is only called once, when stored. After that, LeaseSet.isCurrent() is used.- Returns:
- reason why the entry is not valid, or null if it is valid
- Throws:
UnsupportedCryptoException- if that's why it failed.
-
store
Store the leaseSet. If the store fails due to unsupported crypto, it will negative cache the hash until restart.- Specified by:
storein classNetworkDatabaseFacade- Returns:
- previous entry or null
- Throws:
IllegalArgumentException- if the leaseSet is not validUnsupportedCryptoException- if that's why it failed.
-
store
Store the leaseSet. If the store fails due to unsupported crypto, it will negative cache the hash until restart.- Parameters:
force- always store even if not newer- Returns:
- previous entry or null
- Throws:
IllegalArgumentException- if the leaseSet is not validUnsupportedCryptoException- if that's why it failed.- Since:
- 0.9.64
-
isNewer
Utility to determine if a is newer than b. Uses publish date if a and b are both LS2, else earliest lease date.- Parameters:
a- non-nullb- non-null- Returns:
- if a is newer than b
- Since:
- 0.9.64
-
validate
Determine whether this routerInfo will be accepted as valid and current given what we know now. Call this before each use, to check expiration- Returns:
- reason why the entry is not valid, or null if it is valid
- Throws:
IllegalArgumentException- Since:
- 0.9.7
-
store
Store the routerInfo. If the store fails due to unsupported crypto, it will banlist the router hash until restart and then throw UnsupportedCrytpoException.- Specified by:
storein classNetworkDatabaseFacade- Returns:
- previous entry or null
- Throws:
IllegalArgumentException- if the routerInfo is not validUnsupportedCryptoException- if that's why it failed.
-
store
Store the routerInfo. If the store fails due to unsupported crypto, it will banlist the router hash until restart and then throw UnsupportedCrytpoException.- Returns:
- previous entry or null
- Throws:
IllegalArgumentException- if the routerInfo is not validUnsupportedCryptoException- if that's why it failed.
-
fail
Final remove for a leaseset. For a router info, will look up in the network before dropping.- Specified by:
failin classNetworkDatabaseFacade
-
lookupBeforeDropping
don't use directly - see F.N.D.F. override -
dropAfterLookupFailed
Final remove for a router info. Do NOT use for leasesets. -
unpublish
- Specified by:
unpublishin classNetworkDatabaseFacade
-
search
Begin a kademlia style search for the key specified, which can take up to timeoutMs and will fire the appropriate jobs on success or timeout (or if the kademlia search completes without any match) Unused - called only by FNDF.searchFull() from FloodSearchJob which is overridden - don't use this.- Throws:
UnsupportedOperationException- always
-
search
SearchJob search(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease, Hash fromLocalDest) Unused - see FNDF- Throws:
UnsupportedOperationException- always- Since:
- 0.9.10
-
getLeases
public for NetDbRenderer in routerconsole- Overrides:
getLeasesin classNetworkDatabaseFacade
-
getRouters
Public for NetDbRenderer in routerconsole- Overrides:
getRoutersin classNetworkDatabaseFacade- Returns:
- empty set if this is a client DB
-
getPeerTimeout
todo: does this need more tuning? -
sendStore
abstract void sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore) See implementation in FNDF- Parameters:
key- the DatabaseEntry hashonSuccess- may be null, always called if we are ff and ds is an RIonFailure- may be null, ignored if we are ff and ds is an RIsendTimeout- ignored if we are ff and ds is an RItoIgnore- may be null, if non-null, all attempted and skipped targets will be added as of 0.9.53, unused if we are ff and ds is an RI
-
lookupFailed
Increment in the negative lookup cache- Parameters:
key- for Destinations or RouterIdentities- Since:
- 0.9.4 moved from FNDF to KNDF in 0.9.16
-
isNegativeCached
Is the key in the negative lookup cache?- Parameters:
key- for Destinations or RouterIdentities- Since:
- 0.9.4 moved from FNDF to KNDF in 0.9.16
-
failPermanently
Negative cache until restart- Since:
- 0.9.16
-
isNegativeCachedForever
Is it permanently negative cached?- Overrides:
isNegativeCachedForeverin classNetworkDatabaseFacade- Parameters:
key- only for Destinations; for RouterIdentities, see Banlist- Since:
- 0.9.16
-
renderStatusHTML
Debug info, HTML formatted- Specified by:
renderStatusHTMLin interfaceService- Overrides:
renderStatusHTMLin classNetworkDatabaseFacade- Throws:
IOException- Since:
- 0.9.10
-
toString
-