public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade
Provides core network database functionality using Kademlia DHT for peer discovery, routing table management, and data storage/lookup operations. Never instantiated directly; see FloodfillNetworkDatabaseFacade.
| Modifier and Type | Field and Description |
|---|---|
protected RouterContext | _context_context. |
protected Log | _logClass logger. |
protected int | _networkIDNetwork identifier. |
protected PeerSelector | _peerSelector_peerSelector. |
static String | CURRENT_VERSIONCurrent minor version identifier for net DB format. |
static String | DEFAULT_DB_DIRDefault database directory name. |
static long | DONT_FAIL_PERIODFor 15 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 int | MAX_EXPLORE_QUEUEMaximum number of peers to place in the queue to explore |
protected static 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. |
(package private) static int | MIN_RESEEDReseed if below this. |
static String | MIN_ROUTER_VERSION |
static String | MIN_VERSION |
static String | PROP_BLOCK_MY_COUNTRYConfig property for blocking own-country peers. |
(package private) static String | PROP_BUCKET_SIZEP r o p b u c k e t s i z e |
static String | PROP_DB_DIRConfig property for database directory. |
(package private) static String | PROP_EXPLORE_QUEUEP r o p e x p l o r e q u e u e |
static String | PROP_IP_COUNTRYConfig property for IP country override. |
(package private) static String | PROP_KAD_BP r o p k a d b |
(package private) static String | PROP_MIN_ROUTER_VERSIONP r o p m i n r o u t e r v e r s i o n |
(package private) static String | PROP_ROUTER_INFO_EXPIRATION_ADJUSTEDP r o p r o u t e r i n f o e x p i r a t i o n a d j u s t e d |
(package private) static String | PROP_VALIDATE_ROUTERS_AFTERP r o p v a l i d a t e r o u t e r s a f t e r |
protected static 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. |
| Constructor and Description |
|---|
KademliaNetworkDatabaseFacade(RouterContext context,
Hash dbid)Initializes the Kademlia-based network database facade. |
| Modifier and Type | Method and Description |
|---|---|
void | accessLeaseSet(Hash key)Record access to a LeaseSet for refresh tracking. |
protected BlindCache | blindCache()Returns the blind data cache used by this database. |
void | cleanupLURouters()Clean up existing LU routers loaded before the ban was added. |
protected void | createHandlers()Unused, see override |
protected PeerSelector | createPeerSelector()Creates a peer selector for the network database. |
(package private) boolean | dropAfterLookupFailed(Hash peer)Final remove for a router info. |
void | fail(Hash dbEntry)Final remove for a leaseset. |
(package private) void | failPermanently(Destination dest)Negative cache until restart |
Set<Hash> | findNearestRouters(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 want |
Set<Hash> | getAllRouters()Get the hashes for all known routers |
List<BlindData> | getBlindData()For console ConfigKeyringHelper |
BlindData | getBlindData(SigningPublicKey spk) |
Set<LeaseSet> | getClientLeases()Public for NetDbRenderer in routerconsole |
(package private) DataStore | getDataStore() |
(package private) String | getDbDir()For the main DB only. |
Set<Hash> | getExploreKeys()Gets the set of keys to explore. |
Set<LeaseSet> | getFloodfillLeases() |
(package private) KBucketSet<Hash> | getKBuckets()Get the KBucketSet for the main DB. |
protected int | getKBucketSetSize()Get the size of the KBucketSet. |
int | getKnownLeaseSets()This is only used by StatisticsManager to publish the count if we are floodfill. |
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. |
(package private) long | getLastExploreNewDate() |
long | getLastRouterInfoPublishTime()The last time we successfully published our RI. |
Set<LeaseSet> | getLeases()Public for NetDbRenderer in routerconsole |
PeerSelector | getPeerSelector()Returns the main database's peer selector. |
int | getPeerTimeout(Hash peer)Get the timeout for a peer, based on the profile data, or the default timeout. |
Set<LeaseSet> | getPublishedLeases()Public for NetDbRenderer in routerconsole |
String | getRouterIPPort(RouterInfo router)Extract IP address and port from RouterInfo for logging to sessionbans.txt. |
Set<RouterInfo> | getRouters()public for NetDbRenderer in routerconsole |
int | getStoredRouterInfoCount()Get the number of RouterInfo files stored on disk, if using PersistentDataStore. |
Set<LeaseSet> | getUnpublishedLeases()Public for NetDbRenderer in routerconsole |
(package private) boolean | hasActiveRepublishJob(Hash hash)Check if an active republish job exists for the given destination. |
boolean | isClientDb()Check if the database is a client DB. |
boolean | isInitialized()Checks whether the network database has been fully initialized. |
(package private) boolean | isNegativeCached(Hash key)Is the key in the negative lookup cache? |
boolean | isNegativeCachedForever(Hash key)Is it permanently negative cached? |
static boolean | isNewer(LeaseSet a,
LeaseSet b)Utility to determine if a is newer than b. |
protected void | lookupBeforeDropping(Hash peer,
RouterInfo info)Don't use directly - see F.N.D.F. |
void | lookupDestination(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. |
Destination | lookupDestinationLocally(Hash key)Lookup locally in netDB and in badDest cache
Succeeds even if LS validation fails due to unsupported sig type, expired, etc. |
(package private) void | lookupFailed(Hash key)Increment in the negative lookup cache |
void | lookupLeaseSet(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs)Lookup a LeaseSet in the network database. |
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. |
LeaseSet | lookupLeaseSetLocally(Hash key)key). |
void | lookupLeaseSetRemotely(Hash key,
Hash fromLocalDest)Unconditionally lookup using the client's tunnels. |
void | lookupLeaseSetRemotely(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs,
Hash fromLocalDest)Unconditionally lookup using the client's tunnels. |
DatabaseEntry | lookupLocally(Hash key)Lookup a database entry locally. |
DatabaseEntry | lookupLocallyWithoutValidation(Hash key)Not for use without validation |
void | lookupRouterInfo(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs)timeoutMs). |
RouterInfo | lookupRouterInfoLocally(Hash key)This will return immediately with the result or null. |
void | lookupRouterInfoRemote(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs)Look up a RouterInfo by hash, performing a network search if not locally cached. |
void | markHostCheckerLeaseSet(Hash hash)Mark a destination hash as being looked up on behalf of HostChecker. |
(package private) void | negativeCacheNow(Hash key)Immediately negative-cache a key (set to its max fail count) so the next
lookup short-circuits via isNegativeCached(net.i2p.data.Hash) instead of running a
full search. |
void | publish(LeaseSet localLeaseSet)Publishes a local LeaseSet by storing it and scheduling republishing if applicable. |
void | publish(RouterInfo localRouterInfo)Stores to local db only. |
void | purgeMatchingRouters()Trigger a retroactive purge sweep of the NetDb. |
void | queueForExploration(Collection<Hash> keys)Queue keys for exploration. |
(package private) boolean | registerPublishingJob(RepublishLeaseSetJob job)Register a new job for tracking. |
boolean | removeBlindData(SigningPublicKey spk)For console ConfigKeyringHelper |
void | removeFromCache(Hash hash)Remove a remote LeaseSet from local cache (e.g. |
void | removeFromExploreKeys(Collection<Hash> toRemove)Remove keys from the exploration set. |
void | removeLeaseSetFromTracking(Hash key)Remove a LeaseSet from refresh tracking. |
(package private) void | removePublishingJob(Hash hash,
RepublishLeaseSetJob job)Remove a specific job from the tracking set. |
void | removeRouterInfo(Hash key)Remove a RouterInfo from the local netdb. |
void | renderStatusHTML(Writer out)Debug only - all user info moved to NetDbRenderer in router console |
void | rescan()Rescan the netdb directory for new RouterInfo files. |
ReseedChecker | reseedChecker() |
(package private) void | routerInfoPublishSuccessful()Set the last time we successfully published our RI. |
void | routingKeyChanged()Notify the netDB that the routing key changed at midnight UTC |
(package private) SearchJob | search(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs,
boolean isLease)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. |
(package private) SearchJob | search(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs,
boolean isLease,
Hash fromLocalDest)Unused - see FNDF |
(package private) void | searchComplete(Hash key)The search for the given key is no longer active. |
(package private) abstract void | sendStore(Hash key,
DatabaseEntry ds,
Job onSuccess,
Job onFailure,
long sendTimeout,
Set<Hash> toIgnore)See implementation in FNDF |
void | setBlindData(BlindData bd) |
(package private) void | setLastExploreNewDate(long when) |
void | shutdown()Instruct the service that the router is shutting down and that it should do
whatever is necessary to go down gracefully. |
void | startup()Instruct the service that it should start normal operation. |
(package private) void | stopPublishing(Hash target) |
LeaseSet | store(Hash key,
LeaseSet leaseSet) |
LeaseSet | store(Hash key,
LeaseSet leaseSet,
boolean force)Store the leaseSet. |
RouterInfo | store(Hash key,
RouterInfo routerInfo)Store the routerInfo. |
(package private) RouterInfo | store(Hash key,
RouterInfo routerInfo,
boolean persist)Store the routerInfo. |
String | toString() |
void | unpublish(LeaseSet localLeaseSet)Unpublish a LeaseSet from the network database. |
String | validate(Hash key,
LeaseSet leaseSet)Validates whether the given LeaseSet is acceptable as valid and current based on current known parameters. |
(package private) String | validate(RouterInfo routerInfo)Determine whether this routerInfo will be accepted as valid and current
given what we know now. |
floodfillEnabled, storeprotected final RouterContext _context
protected final Log _log
protected final int _networkID
protected final PeerSelector _peerSelector
public static String CURRENT_VERSION
public static final String DEFAULT_DB_DIR
public static long DONT_FAIL_PERIOD
static final int MAX_EXPLORE_QUEUE
protected static final int MIN_REMAINING_ROUTERS
static final int MIN_RESEED
public static final String MIN_ROUTER_VERSION
public static final String MIN_VERSION
public static final String PROP_BLOCK_MY_COUNTRY
static final String PROP_BUCKET_SIZE
public static final String PROP_DB_DIR
static final String PROP_EXPLORE_QUEUE
public static final String PROP_IP_COUNTRY
static final String PROP_KAD_B
static final String PROP_MIN_ROUTER_VERSION
static final String PROP_ROUTER_INFO_EXPIRATION_ADJUSTED
static final String PROP_VALIDATE_ROUTERS_AFTER
protected static final long PUBLISH_JOB_DELAY
public KademliaNetworkDatabaseFacade(RouterContext context, Hash dbid)
context - the router contextdbid - the unique identifier for this network databasepublic void accessLeaseSet(Hash key)
accessLeaseSet in class NetworkDatabaseFacadeprotected BlindCache blindCache()
public void cleanupLURouters()
protected void createHandlers()
protected PeerSelector createPeerSelector()
IllegalStateException - if called on a client databaseboolean dropAfterLookupFailed(Hash peer)
peer - the peer hashpublic void fail(Hash dbEntry)
fail in class NetworkDatabaseFacadedbEntry - the key of the entry to failvoid failPermanently(Destination dest)
dest - the destinationpublic Set<Hash> findNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore)
findNearestRouters in class NetworkDatabaseFacadekey - the real key, NOT the routing keypeersToIgnore - can be nullmaxNumRouters - The maximum number of routers to returnpublic Set<Hash> getAllRouters()
getAllRouters in class NetworkDatabaseFacadepublic List<BlindData> getBlindData()
NetworkDatabaseFacadegetBlindData in class NetworkDatabaseFacadepublic BlindData getBlindData(SigningPublicKey spk)
getBlindData in class NetworkDatabaseFacadespk - unblinded keypublic Set<LeaseSet> getClientLeases()
getClientLeases in class NetworkDatabaseFacadeDataStore getDataStore()
String getDbDir()
public Set<Hash> getExploreKeys()
public Set<LeaseSet> getFloodfillLeases()
getFloodfillLeases in class NetworkDatabaseFacadeKBucketSet<Hash> getKBuckets()
protected int getKBucketSetSize()
public int getKnownLeaseSets()
getKnownLeaseSets in class NetworkDatabaseFacadepublic int getKnownRouters()
getKnownRouters in class NetworkDatabaseFacadelong getLastExploreNewDate()
public long getLastRouterInfoPublishTime()
NetworkDatabaseFacadegetLastRouterInfoPublishTime in class NetworkDatabaseFacadepublic Set<LeaseSet> getLeases()
getLeases in class NetworkDatabaseFacadepublic PeerSelector getPeerSelector()
public int getPeerTimeout(Hash peer)
peer - the peerpublic Set<LeaseSet> getPublishedLeases()
getPublishedLeases in class NetworkDatabaseFacadepublic String getRouterIPPort(RouterInfo router)
router - the RouterInfo to extract frompublic Set<RouterInfo> getRouters()
NetworkDatabaseFacadegetRouters in class NetworkDatabaseFacadepublic int getStoredRouterInfoCount()
public Set<LeaseSet> getUnpublishedLeases()
getUnpublishedLeases in class NetworkDatabaseFacadeboolean hasActiveRepublishJob(Hash hash)
hash - the destination hashpublic boolean isClientDb()
public boolean isInitialized()
isInitialized in class NetworkDatabaseFacadeboolean isNegativeCached(Hash key)
key - for Destinations or RouterIdentitiespublic boolean isNegativeCachedForever(Hash key)
isNegativeCachedForever in class NetworkDatabaseFacadekey - only for Destinations; for RouterIdentities, see Banlistpublic static boolean isNewer(LeaseSet a, LeaseSet b)
a - non-nullb - non-nullprotected void lookupBeforeDropping(Hash peer, RouterInfo info)
peer - the peerinfo - the router infopublic void lookupDestination(Hash key, Job onFinishedJob, long timeoutMs, Hash fromLocalDest)
lookupDestination in class NetworkDatabaseFacadeonFinishedJob - non-nullfromLocalDest - use these tunnels for the lookup, or null for exploratorypublic Destination lookupDestinationLocally(Hash key)
lookupDestinationLocally in class NetworkDatabaseFacadevoid lookupFailed(Hash key)
key - for Destinations or RouterIdentitiespublic void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
NetworkDatabaseFacadelookupLeaseSet in class NetworkDatabaseFacadekey - the keyonFindJob - job to run on successonFailedLookupJob - job to run on failuretimeoutMs - timeout in millisecondspublic void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest)
lookupLeaseSet in class NetworkDatabaseFacadefromLocalDest - use these tunnels for the lookup, or null for exploratorypublic LeaseSet lookupLeaseSetLocally(Hash key)
NetworkDatabaseFacadelookupLeaseSetLocally in class NetworkDatabaseFacadepublic void lookupLeaseSetRemotely(Hash key, Hash fromLocalDest)
lookupLeaseSetRemotely in class NetworkDatabaseFacadefromLocalDest - use these tunnels for the lookup, or null for exploratorypublic void lookupLeaseSetRemotely(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest)
lookupLeaseSetRemotely in class NetworkDatabaseFacadefromLocalDest - use these tunnels for the lookup, or null for exploratoryonFindJob - may be nullonFailedLookupJob - may be nullpublic DatabaseEntry lookupLocally(Hash key)
NetworkDatabaseFacadelookupLocally in class NetworkDatabaseFacadekey - the keypublic DatabaseEntry lookupLocallyWithoutValidation(Hash key)
lookupLocallyWithoutValidation in class NetworkDatabaseFacadekey - the keypublic void lookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
NetworkDatabaseFacadelookupRouterInfo in class NetworkDatabaseFacadepublic RouterInfo lookupRouterInfoLocally(Hash key)
lookupRouterInfoLocally in class NetworkDatabaseFacadepublic void lookupRouterInfoRemote(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
The onFindJob fires when the RI is available locally (either it was already present or the search completed). The onFailedLookupJob fires on search timeout or failure.
Caller must clean up via removeRouterInfo() after extracting the needed data.
key - the Router hash to look uponFindJob - run when RI is local (may be null)onFailedLookupJob - run on lookup failure (may be null)timeoutMs - max wait in ms (bounded internally by the adaptive lookup cap)public void markHostCheckerLeaseSet(Hash hash)
hash - the destination hash being pinged by HostCheckervoid negativeCacheNow(Hash key)
isNegativeCached(net.i2p.data.Hash) instead of running a
full search. Used for transit next-hop RouterInfo misses: a peer that is
gone or unreachable should fail fast for subsequent transit messages
rather than each one waiting out the full lookup timeout.key - RouterInfo or Destination hashpublic void publish(LeaseSet localLeaseSet) throws IllegalArgumentException
publish in class NetworkDatabaseFacadelocalLeaseSet - the LeaseSet to publishIllegalArgumentException - if LeaseSet is invalid or expiredpublic void publish(RouterInfo localRouterInfo) throws IllegalArgumentException
publish in class NetworkDatabaseFacadelocalRouterInfo - the RouterInfo to publishIllegalArgumentException - if the local router info is invalid
or if this is a client DBpublic void purgeMatchingRouters()
purgeMatchingRouters in class NetworkDatabaseFacadepublic void queueForExploration(Collection<Hash> keys)
keys - keys to queueboolean registerPublishingJob(RepublishLeaseSetJob job)
job - the job to registerpublic boolean removeBlindData(SigningPublicKey spk)
removeBlindData in class NetworkDatabaseFacadespk - the unblinded public keypublic void removeFromCache(Hash hash)
hash - the LeaseSet hash to removepublic void removeFromExploreKeys(Collection<Hash> toRemove)
toRemove - keys to removepublic void removeLeaseSetFromTracking(Hash key)
removeLeaseSetFromTracking in class NetworkDatabaseFacadevoid removePublishingJob(Hash hash, RepublishLeaseSetJob job)
hash - the destination hashjob - the job to removepublic void removeRouterInfo(Hash key)
key - the Router hash to removepublic void renderStatusHTML(Writer out) throws IOException
NetworkDatabaseFacaderenderStatusHTML in interface ServicerenderStatusHTML in class NetworkDatabaseFacadeout - the writer to write toIOException - if an error occurs writingpublic void rescan()
rescan in class NetworkDatabaseFacadepublic ReseedChecker reseedChecker()
reseedChecker in class NetworkDatabaseFacadevoid routerInfoPublishSuccessful()
public void routingKeyChanged()
routingKeyChanged in class NetworkDatabaseFacadeSearchJob search(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease)
key - the hash to search foronFindJob - job on findonFailedLookupJob - job on failuretimeoutMs - timeout in msisLease - whether searching for leaseUnsupportedOperationException - alwaysSearchJob search(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease, Hash fromLocalDest)
key - the hash to search foronFindJob - job on findonFailedLookupJob - job on failuretimeoutMs - timeout in msisLease - whether searching for leasefromLocalDest - the local destinationUnsupportedOperationException - alwaysvoid searchComplete(Hash key)
key - the key whose search is completeabstract void sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore)
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 RIds - the database entrysendTimeout - timeout in ms for send operations 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 RIpublic void setBlindData(BlindData bd)
setBlindData in class NetworkDatabaseFacadebd - new BlindData to put in the cachevoid setLastExploreNewDate(long when)
when - the new datepublic void shutdown()
Servicepublic void startup()
Servicevoid stopPublishing(Hash target)
target - hash to stop publishingpublic LeaseSet store(Hash key, LeaseSet leaseSet) throws IllegalArgumentException
store in class NetworkDatabaseFacadeIllegalArgumentException - if the data is not validpublic LeaseSet store(Hash key, LeaseSet leaseSet, boolean force) throws IllegalArgumentException
key - the hash keyleaseSet - the leaseSet to storeforce - always store even if not newerIllegalArgumentException - if the leaseSet is not validUnsupportedCryptoException - if that's why it failed.public RouterInfo store(Hash key, RouterInfo routerInfo) throws IllegalArgumentException
store in class NetworkDatabaseFacadeIllegalArgumentException - if the routerInfo is not validUnsupportedCryptoException - if that's why it failed.RouterInfo store(Hash key, RouterInfo routerInfo, boolean persist) throws IllegalArgumentException
key - the hash keyrouterInfo - the router info to storepersist - whether to persist to diskIllegalArgumentException - if the routerInfo is not validUnsupportedCryptoException - if that's why it failed.public String toString()
public void unpublish(LeaseSet localLeaseSet)
NetworkDatabaseFacadeunpublish in class NetworkDatabaseFacadelocalLeaseSet - the LeaseSet to unpublishpublic String validate(Hash key, LeaseSet leaseSet) throws UnsupportedCryptoException
This method performs several checks including:
Note: Unlike RouterInfos, this validation is only done once at storage time.
Afterward, LeaseSet.isCurrent() should be used to check currency.
key - the expected key (destination hash) for this LeaseSetleaseSet - the LeaseSet instance to validatenull if the LeaseSet is validUnsupportedCryptoException - if the LeaseSet uses an unsupported cryptographic type/signatureString validate(RouterInfo routerInfo) throws IllegalArgumentException
routerInfo - the router info to validateIllegalArgumentException