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_SIZEProperty: Kademlia bucket size (B parameter). |
static String | PROP_DB_DIRConfig property for database directory. |
(package private) static String | PROP_EXPLORE_QUEUEProperty: maximum explore queue size. |
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_VERSIONProperty: minimum router version for exploration. |
(package private) static String | PROP_ROUTER_INFO_EXPIRATION_ADJUSTEDProperty: adjusted RouterInfo expiration time in ms. |
(package private) static String | PROP_VALIDATE_ROUTERS_AFTERProperty: delay before validating routers in ms. |
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. |
protected void | createHandlers()Unused, see override |
protected PeerSelector | createPeerSelector()Creates a peer selector for the network database. |
(package private) void | decrementActiveFloodfillQuery(Hash floodfill)Decrement the active outbound query count for a floodfill peer. |
(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)The routers closest to that key in response to a remote lookup. |
Set<Hash> | getAllRouters()Hashes for all known routers. |
List<BlindData> | getBlindData()All cached BlindData. |
BlindData | getBlindData(SigningPublicKey spk)BlindData for the given key. |
Set<LeaseSet> | getClientLeases()LeaseSets published by this router's clients. |
(package private) DataStore | getDataStore()The data store. |
(package private) String | getDbDir()For the main DB only. |
Set<Hash> | getExploreKeys()Keys to explore. |
Set<LeaseSet> | getFloodfillLeases()LeaseSets stored in the floodfill database. |
(package private) KBucketSet<Hash> | getKBuckets()KBucketSet for the main DB. |
protected int | getKBucketSetSize()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()Time of the last explore run. |
long | getLastRouterInfoPublishTime()Time of the last successful RI publication. |
Set<LeaseSet> | getLeases()All known LeaseSets for display. |
PeerSelector | getPeerSelector()Returns the main database's peer selector. |
int | getPeerTimeout(Hash peer)The timeout for a peer, based on the profile data, or the default timeout. |
Set<LeaseSet> | getPublishedLeases()LeaseSets published to the network. |
Set<RouterInfo> | getRouters()RouterInfos stored in the database. |
int | getStoredRouterInfoCount()Number of RouterInfo files stored on disk, if using PersistentDataStore. |
Set<LeaseSet> | getUnpublishedLeases()LeaseSets not published to the network. |
(package private) boolean | hasActiveRepublishJob(Hash hash)Check if an active republish job exists for the given destination. |
(package private) int | incrementActiveFloodfillQuery(Hash floodfill)Increment the active outbound query count for a floodfill peer. |
boolean | isClientDb()Check if the database is a client DB. |
(package private) boolean | isFloodfillOverloaded(Hash floodfill)Check if a floodfill peer already has too many active outbound queries
from this router. |
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. |
(package private) boolean | isRecentlyQueried(Hash peer)Check if a floodfill peer was queried recently (within cooldown period). |
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)Destination stored locally, or null. |
(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)LeaseSet stored locally. |
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)Validated entry stored locally. |
DatabaseEntry | lookupLocallyWithoutValidation(Hash key)Not for use without validation. |
void | lookupRouterInfo(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs)Look up a RouterInfo in the network database. |
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. |
(package private) void | markQueried(Hash peer)Mark a floodfill peer as recently queried. |
(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 to the network: stores it in this facade and,
for a client facade, also in the floodfill facade, then schedules
republishing. |
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 | 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()Reseed checker, or null for a client DB. |
(package private) void | routerInfoPublishSuccessful()Record the current time as the last successful RI publication. |
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)BlindData to put in the cache. |
(package private) void | setLastExploreNewDate(long when)Time of the last explore run. |
void | shutdown()Shut down the NetDB and all its jobs. |
void | startup()Instruct the service that it should start normal operation. |
(package private) void | stopPublishing(Hash target)Stops publishing the given LeaseSet. |
LeaseSet | store(Hash key,
LeaseSet leaseSet)Store a LeaseSet in the network database. |
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()"MainNetDb" for the main netdb, or "ClientNetDb [base32]" for a client netdb. |
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()
protected void createHandlers()
protected PeerSelector createPeerSelector()
IllegalStateException - if called on a client databasevoid decrementActiveFloodfillQuery(Hash floodfill)
floodfill - the floodfill peerboolean 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()
getBlindData 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<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()
getLastRouterInfoPublishTime in class NetworkDatabaseFacadepublic Set<LeaseSet> getLeases()
NetworkDatabaseFacadegetLeases in class NetworkDatabaseFacadepublic PeerSelector getPeerSelector()
public int getPeerTimeout(Hash peer)
peer - the peerpublic Set<LeaseSet> getPublishedLeases()
getPublishedLeases in class NetworkDatabaseFacadepublic Set<RouterInfo> getRouters()
getRouters in class NetworkDatabaseFacadepublic int getStoredRouterInfoCount()
public Set<LeaseSet> getUnpublishedLeases()
getUnpublishedLeases in class NetworkDatabaseFacadeboolean hasActiveRepublishJob(Hash hash)
hash - the destination hashint incrementActiveFloodfillQuery(Hash floodfill)
floodfill - the floodfill peerpublic boolean isClientDb()
boolean isFloodfillOverloaded(Hash floodfill)
floodfill - the floodfill peerpublic 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-nullboolean isRecentlyQueried(Hash peer)
peer - the floodfill peerprotected 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)
lookupLeaseSetLocally in class NetworkDatabaseFacadekey - the keypublic 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)
lookupLocally 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 NetworkDatabaseFacadekey - the keyonFindJob - job to run on successonFailedLookupJob - job to run on failuretimeoutMs - timeout in millisecondspublic RouterInfo lookupRouterInfoLocally(Hash key)
lookupRouterInfoLocally in class NetworkDatabaseFacadekey - the keypublic 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)void markQueried(Hash peer)
peer - the floodfill peervoid 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 the 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 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()
public void startup()
Servicevoid stopPublishing(Hash target)
target - hash to stop publishingpublic LeaseSet store(Hash key, LeaseSet leaseSet) throws IllegalArgumentException
NetworkDatabaseFacadestore in class NetworkDatabaseFacadekey - the keyleaseSet - the LeaseSet to storeIllegalArgumentException - 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 NetworkDatabaseFacadekey - the keyrouterInfo - the RouterInfo to storeIllegalArgumentException - 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