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 |
protected Log |
_log |
protected int |
_networkID |
protected PeerSelector |
_peerSelector |
static String |
CURRENT_VERSION |
static String |
DEFAULT_DB_DIR |
static long |
DONT_FAIL_PERIOD
For 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_QUEUE
Maximum number of peers to place in the queue to explore
|
protected static int |
MIN_REMAINING_ROUTERS
If 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_RESEED
Reseed if below this.
|
static String |
MIN_VERSION |
static String |
minRouterVersion |
static String |
PROP_BLOCK_MY_COUNTRY |
static String |
PROP_BLOCK_XG |
(package private) static String |
PROP_BUCKET_SIZE |
static String |
PROP_DB_DIR |
(package private) static String |
PROP_EXPLORE_QUEUE |
static String |
PROP_IP_COUNTRY |
(package private) static String |
PROP_KAD_B |
(package private) static String |
PROP_MIN_ROUTER_VERSION |
(package private) static String |
PROP_ROUTER_INFO_EXPIRATION_ADJUSTED |
(package private) static String |
PROP_VALIDATE_ROUTERS_AFTER |
protected static long |
PUBLISH_JOB_DELAY
This 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 |
|---|---|
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) 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() |
Set<LeaseSet> |
getFloodfillLeases()
Public for NetDbRenderer in routerconsole
|
(package private) KBucketSet<Hash> |
getKBuckets() |
protected int |
getKBucketSetSize()
The KBucketSet contains RIs only.
|
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) |
Set<LeaseSet> |
getPublishedLeases()
public for NetDbRenderer in routerconsole
|
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 using exploratory tunnels.
|
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)
Use lookupDestination() if you don't need the LS or don't need it validated.
|
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) |
DatabaseEntry |
lookupLocallyWithoutValidation(Hash key)
Not for use without validation
|
void |
lookupRouterInfo(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs) |
RouterInfo |
lookupRouterInfoLocally(Hash key)
This will return immediately with the result or null.
|
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 |
queueForExploration(Collection<Hash> keys) |
(package private) boolean |
registerPublishingJob(RepublishLeaseSetJob job)
Register a new job for tracking.
|
boolean |
removeBlindData(SigningPublicKey spk)
For console ConfigKeyringHelper
|
void |
removeFromExploreKeys(Collection<Hash> toRemove) |
(package private) void |
removePublishingJob(Hash hash,
RepublishLeaseSetJob job)
Remove a specific job from the tracking set.
|
void |
renderStatusHTML(Writer out)
Debug info, HTML formatted
|
void |
rescan() |
ReseedChecker |
reseedChecker()
Returns the reseed checker for this database.
|
(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 |
setTransient()
Mark this client database as transient (short-lived, unpublished LeaseSets).
|
void |
shutdown()
Cannot be restarted.
|
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) |
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_VERSION
public static final String minRouterVersion
public static final String PROP_BLOCK_MY_COUNTRY
public static final String PROP_BLOCK_XG
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 databaseprotected BlindCache blindCache()
protected void createHandlers()
protected PeerSelector createPeerSelector()
IllegalStateException - if called on a client databaseboolean dropAfterLookupFailed(Hash peer)
public void fail(Hash dbEntry)
fail in class NetworkDatabaseFacadevoid failPermanently(Destination dest)
public 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()
getLeases in class NetworkDatabaseFacadepublic PeerSelector getPeerSelector()
public int getPeerTimeout(Hash peer)
public 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)
public 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)
public 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)
lookupLeaseSet in class NetworkDatabaseFacadepublic 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 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)
lookupLocally in class NetworkDatabaseFacadepublic DatabaseEntry lookupLocallyWithoutValidation(Hash key)
lookupLocallyWithoutValidation in class NetworkDatabaseFacadepublic void lookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
lookupRouterInfo in class NetworkDatabaseFacadepublic RouterInfo lookupRouterInfoLocally(Hash key)
lookupRouterInfoLocally in class NetworkDatabaseFacadepublic 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 NetworkDatabaseFacadeIllegalArgumentException - if the local router info is invalid
or if this is a client DBpublic void queueForExploration(Collection<Hash> keys)
boolean registerPublishingJob(RepublishLeaseSetJob job)
public boolean removeBlindData(SigningPublicKey spk)
removeBlindData in class NetworkDatabaseFacadespk - the unblinded public keypublic void removeFromExploreKeys(Collection<Hash> toRemove)
void removePublishingJob(Hash hash, RepublishLeaseSetJob job)
public void renderStatusHTML(Writer out) throws IOException
renderStatusHTML in interface ServicerenderStatusHTML in class NetworkDatabaseFacadeIOExceptionpublic 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)
UnsupportedOperationException - alwaysSearchJob search(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease, Hash fromLocalDest)
UnsupportedOperationException - alwaysvoid searchComplete(Hash key)
abstract 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 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 RIpublic void setBlindData(BlindData bd)
setBlindData in class NetworkDatabaseFacadebd - new BlindData to put in the cachevoid setLastExploreNewDate(long when)
public void setTransient()
public void shutdown()
public void startup()
Servicevoid stopPublishing(Hash target)
public 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
force - 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
IllegalArgumentException - if the routerInfo is not validUnsupportedCryptoException - if that's why it failed.public void unpublish(LeaseSet localLeaseSet)
unpublish in class NetworkDatabaseFacadepublic 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
IllegalArgumentException