public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade
Modifier and Type | Field and Description |
---|---|
protected RouterContext |
_context |
protected Log |
_log |
protected int |
_networkID |
protected PeerSelector |
_peerSelector |
static String |
DEFAULT_DB_DIR |
protected static long |
DONT_FAIL_PERIOD
for 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 int |
MAX_EXPLORE_QUEUE |
(package private) static long |
MAX_LEASE_FUTURE
Don't let leaseSets go 20 minutes into the future
|
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 |
PROP_DB_DIR |
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) |
Modifier and Type | Method and Description |
---|---|
protected void |
createHandlers()
unused, see override
|
protected PeerSelector |
createPeerSelector() |
(package private) void |
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
|
(package private) DataStore |
getDataStore() |
(package private) String |
getDbDir() |
Set<Hash> |
getExploreKeys() |
(package private) KBucketSet<Hash> |
getKBuckets() |
protected int |
getKBucketSetSize()
This is fast and doesn't use synchronization,
but it includes both routerinfos and leasesets.
|
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() |
int |
getPeerTimeout(Hash peer)
todo: does this need more tuning?
|
Set<RouterInfo> |
getRouters()
public for NetDbRenderer in routerconsole
|
boolean |
isInitialized() |
(package private) boolean |
isNegativeCached(Hash key)
Is the key in the negative lookup cache?
|
boolean |
isNegativeCachedForever(Hash key)
Is it permanently negative cached?
|
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.
|
DatabaseEntry |
lookupLocally(Hash key) |
(package private) DatabaseEntry |
lookupLocallyWithoutValidation(Hash key)
Not for use without validation
|
void |
lookupRouterInfo(Hash key,
Job onFindJob,
Job onFailedLookupJob,
long timeoutMs) |
RouterInfo |
lookupRouterInfoLocally(Hash key) |
void |
publish(LeaseSet localLeaseSet) |
void |
publish(RouterInfo localRouterInfo)
Stores to local db only.
|
void |
queueForExploration(Collection<Hash> keys) |
void |
removeFromExploreKeys(Collection<Hash> toRemove) |
void |
renderStatusHTML(Writer out)
Debug info, HTML formatted
|
void |
rescan() |
ReseedChecker |
reseedChecker() |
void |
restart()
Perform a soft restart.
|
(package private) void |
routerInfoPublishSuccessful()
Set the last time we successfully published our RI.
|
(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
|
void |
sendStore(Hash key,
DatabaseEntry ds,
Job onSuccess,
Job onFailure,
long sendTimeout,
Set<Hash> toIgnore)
unused (overridden in FNDF)
|
(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)
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.
|
void |
unpublish(LeaseSet localLeaseSet) |
(package private) String |
validate(RouterInfo routerInfo)
Determine whether this routerInfo will be accepted as valid and current
given what we know now.
|
floodfillEnabled, store
protected final Log _log
protected final PeerSelector _peerSelector
protected final RouterContext _context
protected final int _networkID
protected static final long DONT_FAIL_PERIOD
public static final String PROP_DB_DIR
public static final String DEFAULT_DB_DIR
static final int MIN_RESEED
protected static final int MIN_REMAINING_ROUTERS
protected static final long PUBLISH_JOB_DELAY
static final int MAX_EXPLORE_QUEUE
static final long MAX_LEASE_FUTURE
public KademliaNetworkDatabaseFacade(RouterContext context)
void searchComplete(Hash key)
public boolean isInitialized()
isInitialized
in class NetworkDatabaseFacade
protected PeerSelector createPeerSelector()
public PeerSelector getPeerSelector()
public ReseedChecker reseedChecker()
reseedChecker
in class NetworkDatabaseFacade
KBucketSet<Hash> getKBuckets()
DataStore getDataStore()
long getLastExploreNewDate()
void setLastExploreNewDate(long when)
public void removeFromExploreKeys(Collection<Hash> toRemove)
public void queueForExploration(Collection<Hash> keys)
public void shutdown()
Service
public void restart()
Service
public void rescan()
rescan
in class NetworkDatabaseFacade
String getDbDir()
public void startup()
Service
protected void createHandlers()
public Set<Hash> findNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore)
findNearestRouters
in class NetworkDatabaseFacade
key
- the real key, NOT the routing keypeersToIgnore
- can be nullmaxNumRouters
- The maximum number of routers to returnpublic Set<Hash> getAllRouters()
getAllRouters
in class NetworkDatabaseFacade
public int getKnownRouters()
getKnownRouters
in class NetworkDatabaseFacade
public int getKnownLeaseSets()
getKnownLeaseSets
in class NetworkDatabaseFacade
protected int getKBucketSetSize()
public DatabaseEntry lookupLocally(Hash key)
lookupLocally
in class NetworkDatabaseFacade
DatabaseEntry lookupLocallyWithoutValidation(Hash key)
public void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
lookupLeaseSet
in class NetworkDatabaseFacade
public void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest)
lookupLeaseSet
in class NetworkDatabaseFacade
fromLocalDest
- use these tunnels for the lookup, or null for exploratorypublic void lookupLeaseSetRemotely(Hash key, Hash fromLocalDest)
lookupLeaseSetRemotely
in class NetworkDatabaseFacade
fromLocalDest
- use these tunnels for the lookup, or null for exploratorypublic LeaseSet lookupLeaseSetLocally(Hash key)
lookupLeaseSetLocally
in class NetworkDatabaseFacade
public void lookupDestination(Hash key, Job onFinishedJob, long timeoutMs, Hash fromLocalDest)
lookupDestination
in class NetworkDatabaseFacade
onFinishedJob
- non-nullfromLocalDest
- use these tunnels for the lookup, or null for exploratorypublic Destination lookupDestinationLocally(Hash key)
lookupDestinationLocally
in class NetworkDatabaseFacade
public void lookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs)
lookupRouterInfo
in class NetworkDatabaseFacade
public RouterInfo lookupRouterInfoLocally(Hash key)
lookupRouterInfoLocally
in class NetworkDatabaseFacade
public void publish(LeaseSet localLeaseSet) throws IllegalArgumentException
publish
in class NetworkDatabaseFacade
IllegalArgumentException
- if the leaseSet is not validvoid stopPublishing(Hash target)
public void publish(RouterInfo localRouterInfo) throws IllegalArgumentException
publish
in class NetworkDatabaseFacade
IllegalArgumentException
- if the local router info is invalidvoid routerInfoPublishSuccessful()
public long getLastRouterInfoPublishTime()
getLastRouterInfoPublishTime
in class NetworkDatabaseFacade
public LeaseSet store(Hash key, LeaseSet leaseSet) throws IllegalArgumentException
store
in class NetworkDatabaseFacade
IllegalArgumentException
- if the leaseSet is not validUnsupportedCryptoException
- if that's why it failed.String validate(RouterInfo routerInfo) throws IllegalArgumentException
IllegalArgumentException
public RouterInfo store(Hash key, RouterInfo routerInfo) throws IllegalArgumentException
store
in class NetworkDatabaseFacade
IllegalArgumentException
- 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 fail(Hash dbEntry)
fail
in class NetworkDatabaseFacade
protected void lookupBeforeDropping(Hash peer, RouterInfo info)
void dropAfterLookupFailed(Hash peer)
public void unpublish(LeaseSet localLeaseSet)
unpublish
in class NetworkDatabaseFacade
SearchJob 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
- alwayspublic Set<LeaseSet> getLeases()
getLeases
in class NetworkDatabaseFacade
public Set<RouterInfo> getRouters()
getRouters
in class NetworkDatabaseFacade
public int getPeerTimeout(Hash peer)
public void sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore)
void lookupFailed(Hash key)
key
- for Destinations or RouterIdentitiesboolean isNegativeCached(Hash key)
key
- for Destinations or RouterIdentitiesvoid failPermanently(Destination dest)
public boolean isNegativeCachedForever(Hash key)
isNegativeCachedForever
in class NetworkDatabaseFacade
key
- only for Destinations; for RouterIdentities, see Banlistpublic void renderStatusHTML(Writer out) throws IOException
renderStatusHTML
in interface Service
renderStatusHTML
in class NetworkDatabaseFacade
IOException