- All Implemented Interfaces:
Service
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classBatched job that processes all search timeouts periodically.private classDon't actually publish unless the RI didn't change during the delay.private classRemove a failing peer after a lookup timeout.private classVerify a failing peer after a successful lookup.private static classRecord the store failure in the peer profile.private static classNote in the profile that the store succeeded.private static classLightweight entry for batched timeout processing.Field Summary
Modifier and TypeFieldDescriptionprivate final ConcurrentHashMap<Hash, FloodSearchJob> Active flood queries keyed by search hash.private final ContactDrivenRefreshJobJob to refresh RouterInfo on contact.private final JobFloodfill monitor job for capability management.private booleanWhether this router is currently floodfill-enabled.private FloodThrottlerThrottles excessive flood operations.private final IntroducerLookupJobJob to prefetch introducer RIs of unreachable peers.private static longRate-limit Client subDb exploratory drop WARN (10s).private LookupBanHammerBan hammer for abusive lookup peers.private LookupThrottlerThrottles excessive lookup operations.private final ProbeStalePeerJobJob to probe stale floodfill peers.private final ConcurrentHashMap<Long, List<FloodfillNetworkDatabaseFacade.TimeoutEntry>> Batched search timeout entries keyed by bucket.Periodic processor for elapsed search timeouts.Hashes whose verification is in progress.static final charUnlimited bandwidth capability flag.static final charBandwidth 12 Kbps capability flag.static final charBandwidth 128 Kbps capability flag.static final charBandwidth 256 Kbps capability flag.static final charBandwidth 32 Kbps capability flag.static final charBandwidth 512 Kbps capability flag.static final charBandwidth 64 Kbps capability flag.static final charModerate congestion capability flag.static final charSevere congestion capability flag.static final charFloodfill capability flag.static final charNo tunnels capability flag.static final charUnreachable capability flag.private static final longInterval between the client subDB warnings.private static final intPriority for flood outbound messages.private static final intTimeout for individual flood messages.private static final intInitial number of concurrent floodfill peers for store operations.private static final intMaximum database size before skipping exploratory searches.private static final intMax job queue lag before skipping exploratory searches.(package private) static final longMax age (ms) for a RouterInfo stored in our NetDB before we consider refreshing it.static final intThis is the flood redundancy.protected static final intMinimum number of active peers before dropping router info lookups.private static final intNumber of additional peers to flood near routing key rollover.private static final longAdvance time before midnight to flood to next routing key for LeaseSet.(package private) static final longAdvance time before midnight to flood to next routing key for RouterInfo.static final StringConfig property recording floodfill status at previous restart.static final StringConfig property for floodfill participation.private static final intDelay before publishing RouterInfo at startup.(package private) static final longThis maybe could be shorter than RepublishLeaseSetJob.REPUBLISH_LEASESET_TIMEOUT, because we are sending direct, but unresponsive floodfills may take a while due to timeouts.Fields inherited from class KademliaNetworkDatabaseFacade
_context, _log, _networkID, _peerSelector, CURRENT_VERSION, DEFAULT_DB_DIR, DONT_FAIL_PERIOD, IP_GROUP_BUCKET_LIMIT, IP_GROUP_GLOBAL_LIMIT, MAX_EXPLORE_QUEUE, MAX_INTRO_SLOTS, MIN_REMAINING_ROUTERS, MIN_RESEED, MIN_ROUTER_VERSION, MIN_VERSION, PROP_BLOCK_MY_COUNTRY, PROP_BUCKET_SIZE, PROP_DB_DIR, PROP_IP_COUNTRY, PROP_MIN_ROUTER_VERSION, PROP_ROUTER_INFO_EXPIRATION_ADJUSTED, PROP_VALIDATE_ROUTERS_AFTER, UNVERIFIED_MAX, UNVERIFIED_MAX_AGEModifier and TypeFieldDescriptionprotected final RouterContext_context.protected final LogClass logger.protected final intNetwork identifier.protected final PeerSelector_peerSelector.static StringCurrent minor version identifier for net DB format.static final StringDefault database directory name.static longFor 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 final intMax bucket entries sharing one IP group — eclipse/Sybil resistance, mirrors kubo's table.go limits.(package private) static final intMax entries across all buckets sharing one IP group.(package private) static final intMaximum number of peers to place in the queue to explore.(package private) static final intIntroducer slots per transport address.protected 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 StringLowest peer version that may be selected for a KBucket probe.static final StringLowest peer version whose LeaseSets we will store and serve.static final StringConfig property for blocking own-country peers.(package private) static final StringProperty: Kademlia bucket size (K), read once at startup.static final StringConfig property for database directory.static final StringConfig property for IP country override.(package private) static final StringProperty: minimum router version for exploration.(package private) static final StringProperty: adjusted RouterInfo expiration time in ms.(package private) static final StringProperty: delay before validating routers in ms.(package private) static final intMax peers held awaiting direct-contact verification.(package private) static final longDrop a pending peer from the verification queue after this long; it is still in the netdb, it just stops being a bucket candidate until it proves itself.Constructor Summary
ConstructorsConstructorDescriptionMain DB.FloodfillNetworkDatabaseFacade(RouterContext context, Hash dbid) Sub DBs.Method Summary
Modifier and TypeMethodDescription(package private) voidMust be called by the search job queued by search() on success or failure.voidcontactHeardFrom(Hash peer) Notify that we heard from or about a peer (e.g.protected voidRegister message handlers for DatabaseLookup and DatabaseStore.private voidfailSearchCallbacks(Job onFindJob, Job onFailedLookupJob) Queue failure callbacks so a search that cannot start never leaves the caller waiting for a timeout that will never be scheduled.voidflood(DatabaseEntry ds) Send to a subset of all floodfill peers.booleanIf we are floodfill AND the key is not throttled, flood it, otherwise don't.booleanWhether this router is currently acting as a floodfill.List of the hashes of currently known floodfill peers.Return all RouterInfo entries from the local data store.private FloodfillNetworkDatabaseFacadeMain (router) NetDb facade, or null if not yet available.Look up the tunnel pool nickname for a destination.static booleanisFloodfill(RouterInfo peer) Checks if a RouterInfo has floodfill capability.(package private) booleanChecks if verification is in progress for the specified hash.protected voidlookupBeforeDropping(Hash peer, RouterInfo info) Search for a newer router info, drop it from the db if the search fails, unless just started up or have bigger problems.(package private) voidprobeStalePeer(Hash peer, RouterInfo ri) Fire a DirectLookupJob for a stale peer, deduplicated via _activeFloodQueries.voidProcess all elapsed search timeouts.voidpublish(RouterInfo localRouterInfo) Send our RI to the closest floodfill.voidregisterSearchTimeout(Hash peer, IterativeSearchJob search, long timeoutMs) Register a search timeout to be processed in batches.(package private) SearchJobLookup using exploratory tunnels.(package private) SearchJobsearch(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease, Hash fromLocalDest) Lookup using the client's tunnels.selectFloodfillParticipants(Set<Hash> toIgnore, int concurrent) Selects a set of floodfill participant peers to which data should be sent: random selection among the filtered floodfill participants, preferring peers not queried in the last 60s to spread load, with a fallback top-up so store operations never starve.selectStoreParticipants(List<Hash> shuffled, int concurrent, Set<Hash> recentlyQueried) Select up toconcurrentstore participants, preferring peers not queried in the last 60s to spread load, with a fallback top-up so store operations never starve.(package private) voidsendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore) Send out a store.voidsetFloodfillEnabled(boolean yes) Public, called from console.(package private) voidsetFloodfillEnabledFromMonitor(boolean yes) Package private, called from FloodfillMonitorJob.(package private) booleanshouldBanLookup(Hash from, TunnelId id) Check if lookup from a peer should be banned.(package private) static booleanshouldFloodOnStore(boolean floodfillEnabled, DatabaseEntry ds) Whether sendStore should wide-flood the entry viaflood(DatabaseEntry)when this router participates in floodfill.private booleanshouldFloodTo(Hash key, int type, SigType lsSigType, Hash peer, RouterInfo target) Determines if we should flood the database store to a peer.(package private) booleanshouldThrottleFlood(Hash key) Increments and tests.(package private) booleanshouldThrottleLookup(Hash from, TunnelId id) Increments and tests.voidshutdown()If we are floodfill, turn it off and tell everybody.voidStart the batched timeout processor.voidstartup()Start monitor jobs, throttle, and optional router refresh.(package private) static intstoreJobCount(boolean floodfillEnabled, DatabaseEntry ds, int selectedCount) How many FloodfillStoreJob instances sendStore should schedule alongside (or instead of) a wide flood.(package private) voidMarks verification as finished for the specified hash.(package private) voidMarks verification as started for the specified hash.Methods inherited from class KademliaNetworkDatabaseFacade
accessLeaseSet, addContact, blindCache, bucketSize, buildBucketTable, clearNegativeCache, createPeerSelector, decrementActiveFloodfillQuery, dropAfterLookupFailed, entryLinks, fail, failPermanently, findNearestRouters, getAllRouters, getBlindData, getBlindData, getClientLeases, getDataStore, getDbDir, getDebugStats, getExploreKeys, getFloodfillLeases, getKBuckets, getKBucketSetSize, getKnownLeaseSets, getKnownRouters, getLastExploreNewDate, getLastRouterInfoPublishTime, getLeases, getPeerSelector, getPeerTimeout, getPublishedLeases, getRouters, getStoredRouterInfoCount, getUnpublishedLeases, getUnverifiedPeerCount, getUnverifiedPeersSnapshot, hasActiveRepublishJob, hasDirectContact, hasDirectContact, incrementActiveFloodfillQuery, invalidRouterInfoBanReason, invalidRouterInfoBanReason, ipDiversityAllows, ipGroup, ipGroups, isClientDb, isFloodfillOverloaded, isInitialized, isNegativeCached, isNegativeCachedForever, isNewer, isRecentlyQueried, lookupDestination, lookupDestinationLocally, lookupFailed, lookupLeaseSet, lookupLeaseSet, lookupLeaseSetLocally, lookupLeaseSetRemotely, lookupLeaseSetRemotely, lookupLocally, lookupLocallyWithoutValidation, lookupRIUnvalidated, lookupRouterInfo, lookupRouterInfoLocally, lookupRouterInfoRemote, lookupTimeout, markQueried, peekNegativeCached, promoteUnverifiedPeers, publish, purgeMatchingRouters, queueForExploration, registerPublishingJob, removeBlindData, removeFromExploreKeys, removeLeaseSetFromTracking, removePublishingJob, removeRouterInfo, renderStatusHTML, rescan, reseedChecker, routerInfoPublishSuccessful, routingKeyChanged, searchComplete, setBlindData, setLastExploreNewDate, shouldAcceptLeaseSet, shouldFailLocalWithoutRemoteSearch, shouldFallbackLocalLookupToMain, stopPublishing, store, store, store, store, stripStoreWrapper, tooManyIntroducers, toString, unpublish, validate, validateModifier and TypeMethodDescriptionvoidaccessLeaseSet(Hash key) Record access to a LeaseSet for refresh tracking.(package private) booleanaddContact(Hash key) Policy entry point for peers learned from search replies, where no RouterInfo is in hand yet: direct-contact gate only.protected BlindCacheReturns the blind data cache used by this database.(package private) static intbucketSize(RouterContext context) Bucket size (K) from the property, clamped to what KBucketSet accepts.(package private) static StringbuildBucketTable(List<String[]> rows, int capacity, java.util.function.Function<String, String> entryRenderer, java.util.function.Function<String, String> tr) Build the bucket table from the rows ofKBucketSet.getDebugBucketRows(): bucket index, XOR-distance bit range, entry count as a details/summary disclosure whose expanded content is the entry hashes rendered by the given function, and fill as a percentage of capacity.voidclearNegativeCache(Hash key) Clear any transient (non-permanent) negative-cache entry for the given key so the nextKademliaNetworkDatabaseFacade.lookupLeaseSet(Hash, Job, Job, long)performs a real search instead of aborting instantly.protected PeerSelectorCreates a peer selector for the network database.(package private) voiddecrementActiveFloodfillQuery(Hash floodfill) Decrement the active outbound query count for a floodfill peer.(package private) booleandropAfterLookupFailed(Hash peer) Final remove for a router info.(package private) static StringentryLinks(String keys, java.util.function.Function<String, String> entryRenderer) Entry hashes rendered through the given function, sorted for stable display.voidFinal remove for a leaseset.(package private) voidfailPermanently(Destination dest) Negative cache until restart.findNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore) The routers closest to that key in response to a remote lookup.Hashes for all known routers.All cached BlindData.BlindData for the given key.LeaseSets published by this router's clients.(package private) DataStoreThe data store.(package private) StringgetDbDir()For the main DB only.long[]Debug overview stats: total keys, bucket count, per-bucket capacity and fullest bucket size, as {keys, buckets, capacity, fullest}.Keys to explore.LeaseSets stored in the floodfill database.(package private) KBucketSet<Hash> KBucketSet for the main DB.protected intSize of the KBucketSet.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) longTime of the last explore run.longTime of the last successful RI publication.All known LeaseSets for display.Returns the main database's peer selector.intgetPeerTimeout(Hash peer) How long to wait for one peer's reply, scaled from its profile.LeaseSets published to the network.RouterInfos stored in the database.intNumber of RouterInfo files stored on disk, if usingPersistentDataStore.LeaseSets not published to the network.(package private) intThe pending-verification queue size, for tests and the debug console.Snapshot of the pending-verification queue, for the probe cycle to target.(package private) booleanhasActiveRepublishJob(Hash hash) Check if an active republish job exists for the given destination.(package private) booleanhasDirectContact(Hash peer) Have we ever heard from this peer directly, as opposed to merely being told about it? An established session or a profile with a received message or successful send counts.(package private) static booleanhasDirectContact(PeerProfile prof) Direct-contact test on profile evidence only: heard-from or successful-send, never heard-about (that only means someone mentioned them).(package private) intincrementActiveFloodfillQuery(Hash floodfill) Increment the active outbound query count for a floodfill peer.(package private) StringThe ban reason if this RouterInfo fails one of the RouterInfo validation rules - a version above every released version, an impossible publication date, or both the reachable and the unreachable flag at once - or null if it passes.(package private) static StringinvalidRouterInfoBanReason(RouterInfo ri, boolean banVersion, boolean banPubDate, boolean banCaps) The validation rule a RouterInfo breaks, given which of the three rules are switched on.(package private) booleanipDiversityAllows(Hash key, RouterInfo routerInfo) Would adding this peer to its bucket exceed the per-bucket or global IP-group caps? Peers with no literal-IP address are unconstrained.(package private) static LongipGroup(byte[] ip) IP group key: /16 for IPv4, /48 for IPv6, packed into a long with a family marker bit so the two families never collide.ipGroups(RouterInfo ri) The distinct IP groups of a router's literal-IP addresses.booleanCheck if the database is a client DB.(package private) booleanisFloodfillOverloaded(Hash floodfill) Check if a floodfill peer already has too many active outbound queries from this router.booleanChecks whether the network database has been fully initialized.(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.(package private) booleanisRecentlyQueried(Hash peer) Check if a floodfill peer was queried recently (within cooldown period).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.Destination stored locally, or null.(package private) voidlookupFailed(Hash key) Increment in the negative lookup cache.voidlookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs) Look up a LeaseSet, locally first.voidlookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest) Lookup using the client's tunnels UseKademliaNetworkDatabaseFacade.lookupDestination(Hash, Job, long, Hash)if you don't need the LS or don't need it validated.LeaseSet stored locally.voidlookupLeaseSetRemotely(Hash key, Hash fromLocalDest) Unconditionally lookup using the client's tunnels, with no jobs.voidlookupLeaseSetRemotely(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, Hash fromLocalDest) Unconditionally lookup using the client's tunnels.lookupLocally(Hash key) Validated entry stored locally.Not for use without validation.(package private) RouterInfolookupRIUnvalidated(Hash key) Look up a peer's RouterInfo without running the fullKademliaNetworkDatabaseFacade.validate(RouterInfo)ban cascade.voidlookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs) Look up a RouterInfo, resolving over the network when not cached locally.This will return immediately with the result or null.voidlookupRouterInfoRemote(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs) Look up a RouterInfo by hash, performing a network search if not locally cached.(package private) voidlookupTimeout(Hash key) Pure-timeout search failure (no peer replied).(package private) voidmarkQueried(Hash peer) Mark a floodfill peer as recently queried.booleanpeekNegativeCached(Hash key) Negative-cache check without recording an abort stat.(package private) intMove pending peers that have earned direct-contact evidence into the routing buckets, and drop those that waited too long.voidPublishes a local LeaseSet to the network: stores it in this facade and, for a client facade, also in the floodfill facade, then schedules republishing.voidTrigger a retroactive purge sweep of the NetDb.voidqueueForExploration(Collection<Hash> keys) Queue keys for exploration.(package private) booleanRegister a new job for tracking.booleanFor console ConfigKeyringHelper.voidremoveFromExploreKeys(Collection<Hash> toRemove) Remove keys from the exploration set.voidRemove a LeaseSet from refresh tracking.(package private) voidremovePublishingJob(Hash hash, RepublishLeaseSetJob job) Remove a specific job from the tracking set.voidremoveRouterInfo(Hash key) Remove a RouterInfo from the local netdb.voidrenderStatusHTML(Writer out) Render the KBucket summary and a per-bucket table.voidrescan()Rescan the netdb directory for new RouterInfo files.Reseed checker, or null for a client DB.(package private) voidRecord the current time as the last successful RI publication.voidNotify the netDB that the routing key changed at midnight UTC.(package private) voidsearchComplete(Hash key) The search for the given key is no longer active.voidBlindData to put in the cache.(package private) voidsetLastExploreNewDate(long when) Time of the last explore run.(package private) static booleanshouldAcceptLeaseSet(LeaseSet stored, LeaseSet incoming, long now) Determine whether an incoming LeaseSet may replace the currently stored copy.(package private) static booleanshouldFailLocalWithoutRemoteSearch(boolean isClientDb, boolean isLocalDest) Whether a client sub-NetDb local miss for a destination this router hosts must fail immediately instead of starting a network search.(package private) static booleanshouldFallbackLocalLookupToMain(boolean isClientDb, boolean isLocalDest, boolean foundLocally) Whether a client sub-NetDb local miss should be re-checked in the main NetDb.(package private) voidstopPublishing(Hash target) Stops publishing the given LeaseSet.Store the LeaseSet without persisting it to disk.Store the leaseSet.store(Hash key, RouterInfo routerInfo) Store the routerInfo.(package private) RouterInfostore(Hash key, RouterInfo routerInfo, boolean persist) Store the routerInfo.(package private) static StringstripStoreWrapper(String message) Strip the "Invalid NetDbStore attempt" wrapper from a store rejection message, keeping the capability flags and the Router [id] the console renders as a link.(package private) static booleanWhether any single transport address advertises more introducers than the SSU2 spec allows.toString()Name this netdb for use in log messages.voidUnpublish a LeaseSet from the network database.Validates whether the given LeaseSet is acceptable as valid and current based on current known parameters.(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 NetworkDatabaseFacade
storeModifier and TypeMethodDescriptionstore(Hash key, DatabaseEntry entry) Store a DatabaseEntry in the network database.
Field Details
CAPABILITY_FLOODFILL
public static final char CAPABILITY_FLOODFILLFloodfill capability flag.- See Also:
CAPABILITY_UNREACHABLE
public static final char CAPABILITY_UNREACHABLEUnreachable capability flag.- See Also:
CAPABILITY_BW12
public static final char CAPABILITY_BW12Bandwidth 12 Kbps capability flag.- See Also:
CAPABILITY_BW32
public static final char CAPABILITY_BW32Bandwidth 32 Kbps capability flag.- See Also:
CAPABILITY_BW64
public static final char CAPABILITY_BW64Bandwidth 64 Kbps capability flag.- See Also:
CAPABILITY_BW128
public static final char CAPABILITY_BW128Bandwidth 128 Kbps capability flag.- See Also:
CAPABILITY_BW256
public static final char CAPABILITY_BW256Bandwidth 256 Kbps capability flag.- See Also:
CAPABILITY_BW512
public static final char CAPABILITY_BW512Bandwidth 512 Kbps capability flag.- See Also:
CAPABILITY_BW_UNLIMITED
public static final char CAPABILITY_BW_UNLIMITEDUnlimited bandwidth capability flag.- See Also:
CAPABILITY_CONGESTION_MODERATE
public static final char CAPABILITY_CONGESTION_MODERATEModerate congestion capability flag.- See Also:
CAPABILITY_CONGESTION_SEVERE
public static final char CAPABILITY_CONGESTION_SEVERESevere congestion capability flag.- See Also:
CAPABILITY_NO_TUNNELS
public static final char CAPABILITY_NO_TUNNELSNo tunnels capability flag.- See Also:
_activeFloodQueries
Active flood queries keyed by search hash._floodfillEnabled
private volatile boolean _floodfillEnabledWhether this router is currently floodfill-enabled._verifiesInProgress
_floodThrottler
Throttles excessive flood operations._lookupThrottler
Throttles excessive lookup operations._lookupBanner
Ban hammer for abusive lookup peers._ffMonitor
Floodfill monitor job for capability management._probeStalePeerJob
Job to probe stale floodfill peers._contactRefreshJob
Job to refresh RouterInfo on contact._introducerLookupJob
Job to prefetch introducer RIs of unreachable peers._searchTimeouts
private final ConcurrentHashMap<Long, List<FloodfillNetworkDatabaseFacade.TimeoutEntry>> _searchTimeoutsBatched search timeout entries keyed by bucket._timeoutProcessor
Periodic processor for elapsed search timeouts.MAX_TO_FLOOD
public static final int MAX_TO_FLOODThis is the flood redundancy. Entries are sent to this many other floodfills. Was 7 through release 0.9; 5 for 0.9.1. 4 as of 0.9.2; 3 as of 0.9.9 Raised to 10: wider RI/LS propagation improves lookup success and reduces dead-zone risk from date-based routing key rotation. Bandwidth cost is negligible (~2KB per store × 10 FFs).- See Also:
FLOOD_PRIORITY
private static final int FLOOD_PRIORITYPriority for flood outbound messages.- See Also:
MAX_RI_AGE_BEFORE_REFRESH_MS
static final long MAX_RI_AGE_BEFORE_REFRESH_MSMax age (ms) for a RouterInfo stored in our NetDB before we consider refreshing it. RIs published within this window are treated as fresh.- See Also:
FLOOD_TIMEOUT
private static final int FLOOD_TIMEOUTTimeout for individual flood messages.- See Also:
NEXT_RKEY_RI_ADVANCE_TIME
static final long NEXT_RKEY_RI_ADVANCE_TIMEAdvance time before midnight to flood to next routing key for RouterInfo.- See Also:
NEXT_RKEY_LS_ADVANCE_TIME
private static final long NEXT_RKEY_LS_ADVANCE_TIMEAdvance time before midnight to flood to next routing key for LeaseSet.- See Also:
NEXT_FLOOD_QTY
private static final int NEXT_FLOOD_QTYNumber of additional peers to flood near routing key rollover.- See Also:
MAX_LAG_BEFORE_SKIP_SEARCH
private static final int MAX_LAG_BEFORE_SKIP_SEARCHMax job queue lag before skipping exploratory searches.PUBLISH_JOB_DELAY
private static final int PUBLISH_JOB_DELAYDelay before publishing RouterInfo at startup.- See Also:
_lastClientSubDbWarn
private static volatile long _lastClientSubDbWarnRate-limit Client subDb exploratory drop WARN (10s). @since 0.9.71+.CLIENT_SUBDB_WARN_INTERVAL
private static final long CLIENT_SUBDB_WARN_INTERVALInterval between the client subDB warnings.- See Also:
PROP_FLOODFILL_PARTICIPANT
Config property for floodfill participation.- See Also:
PROP_FLOODFILL_AT_RESTART
Config property recording floodfill status at previous restart.- See Also:
PUBLISH_TIMEOUT
static final long PUBLISH_TIMEOUTThis maybe could be shorter than RepublishLeaseSetJob.REPUBLISH_LEASESET_TIMEOUT, because we are sending direct, but unresponsive floodfills may take a while due to timeouts.- See Also:
INITIAL_CONCURRENT
private static final int INITIAL_CONCURRENTInitial number of concurrent floodfill peers for store operations.- See Also:
MIN_ACTIVE_PEERS
protected static final int MIN_ACTIVE_PEERSMinimum number of active peers before dropping router info lookups. NTCP connections drop quickly but SSU takes a while, so this is kept a little higher than 1 or 2.MAX_DB_BEFORE_SKIPPING_SEARCH
private static final int MAX_DB_BEFORE_SKIPPING_SEARCHMaximum database size before skipping exploratory searches.
Constructor Details
FloodfillNetworkDatabaseFacade
Main DB.- Parameters:
context- the router context
FloodfillNetworkDatabaseFacade
Sub DBs.- Parameters:
context- the router contextdbid- null for main DB
Method Details
startup
public void startup()Start monitor jobs, throttle, and optional router refresh.- Specified by:
startupin interfaceService- Overrides:
startupin classKademliaNetworkDatabaseFacade
createHandlers
protected void createHandlers()Register message handlers for DatabaseLookup and DatabaseStore.- Overrides:
createHandlersin classKademliaNetworkDatabaseFacade
registerSearchTimeout
Register a search timeout to be processed in batches. Instead of creating individual IterativeTimeoutJob for each peer, we register here and a single BatchedSearchTimeoutJob processes all at once.- Parameters:
peer- the target key whose search timeout is being registeredsearch- the search termtimeoutMs- the absolute time when the timeout expires
processElapsedTimeouts
public void processElapsedTimeouts()Process all elapsed search timeouts. Called by BatchedSearchTimeoutJob.startTimeoutProcessor
public void startTimeoutProcessor()Start the batched timeout processor. Called fromstartup().shutdown
public void shutdown()If we are floodfill, turn it off and tell everybody.- Specified by:
shutdownin interfaceService- Overrides:
shutdownin classKademliaNetworkDatabaseFacade
publish
Send our RI to the closest floodfill.- Overrides:
publishin classKademliaNetworkDatabaseFacade- Parameters:
localRouterInfo- the RouterInfo to publish- Throws:
IllegalArgumentException- if the local router info is invalid
shouldFloodOnStore
Whether sendStore should wide-flood the entry viaflood(DatabaseEntry)when this router participates in floodfill.Floodfill participants wide-flood both RouterInfos (existing) and LeaseSets so published LSs reach the routing-key-closest peers that lookups query, not only the few peers chosen for the reply-based store job. Narrow store-only delivery leaves keys missing on other floodfills (verify FailNoKey).
- Parameters:
floodfillEnabled- whether this router is a floodfill participantds- the entry being stored, may be null- Returns:
- true if flood() should be invoked for this entry
storeJobCount
How many FloodfillStoreJob instances sendStore should schedule alongside (or instead of) a wide flood.Floodfill + RouterInfo: 0 — wide flood only (existing; no reply-based job). Floodfill + LeaseSet: 1 — wide flood covers propagation; this job supplies reply-based success/failure callbacks and verify accounting. Otherwise:
selectedCountstaggered multi-peer jobs (non-floodfill path).- Parameters:
floodfillEnabled- whether this router is a floodfill participantds- the entry being stored, may be nullselectedCount- peers chosen by selectFloodfillParticipants- Returns:
- number of FloodfillStoreJob instances to schedule; never negative
sendStore
void sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore) Send out a store.- Specified by:
sendStorein classKademliaNetworkDatabaseFacade- Parameters:
key- the DatabaseEntry hashds- the database entryonSuccess- may be null; called on reply-based store success (not used for wide-flood-only RI path)onFailure- may be null; called when no floodfill peers are available or reply-based store failssendTimeout- timeout in ms for the reply-based FloodfillStoreJob pathtoIgnore- may be null, if non-null, all attempted and skipped targets will be added as of 0.9.53; passed through to FloodfillStoreJob (unused for wide-flood-only RI path)
selectFloodfillParticipants
Selects a set of floodfill participant peers to which data should be sent: random selection among the filtered floodfill participants, preferring peers not queried in the last 60s to spread load, with a fallback top-up so store operations never starve.- Parameters:
toIgnore- the set of peer hashes to exclude from selection, may be nullconcurrent- the maximum number of peers to select- Returns:
- a set of floodfill participant Hashes; never null but possibly empty if no suitable peers found
selectStoreParticipants
static Set<Hash> selectStoreParticipants(List<Hash> shuffled, int concurrent, Set<Hash> recentlyQueried) Select up toconcurrentstore participants, preferring peers not queried in the last 60s to spread load, with a fallback top-up so store operations never starve.- Parameters:
shuffled- the shuffled candidate peers (may be empty)concurrent- the maximum number of peers to selectrecentlyQueried- hashes of peers queried within the cooldown period- Returns:
- the selected peers; never null, possibly empty
shouldThrottleFlood
Increments and tests.- Parameters:
key- the key being flooded, tested against the per-key flood allowance- Returns:
- true if the flood should be throttled for this key
shouldBanLookup
shouldThrottleLookup
floodConditional
If we are floodfill AND the key is not throttled, flood it, otherwise don't.- Parameters:
ds- the entry to flood, which must be a LeaseSet for the store to accept it- Returns:
- if we did
flood
Send to a subset of all floodfill peers. We do this to implement Kademlia within the floodfills, i.e. we flood to those closest to the key.- Parameters:
ds- the entry to store and flood to the closest floodfill participants
shouldFloodTo
Determines if we should flood the database store to a peer.- Parameters:
key- the database entry hashtype- database store typelsSigType- may be nullpeer- the target peer hashtarget- the peer's RouterInfo, may be null- Returns:
- true if the store should be flooded to this peer
setFloodfillEnabled
public void setFloodfillEnabled(boolean yes) Public, called from console. This wakes up the floodfill monitor, which will rebuild the RI and log in the event log, and call setFloodfillEnabledFromMonitor which really sets it.- Parameters:
yes- true to become floodfill, false to stop
setFloodfillEnabledFromMonitor
void setFloodfillEnabledFromMonitor(boolean yes) Package private, called from FloodfillMonitorJob. This does not wake up the floodfill monitor.- Parameters:
yes- true to become floodfill, false to stop; true also creates the throttler and HFDSMJ stats
floodfillEnabled
public boolean floodfillEnabled()Whether this router is currently acting as a floodfill.- Overrides:
floodfillEnabledin classNetworkDatabaseFacade- Returns:
- true if enabled, as set from the config or the floodfill monitor
isFloodfill
Checks if a RouterInfo has floodfill capability.- Parameters:
peer- may be null, returns false if null- Returns:
- true if the RouterInfo advertises the 'f' floodfill capability
getKnownRouterData
Return all RouterInfo entries from the local data store.- Returns:
- list of known RouterInfo objects, never null
search
Lookup using exploratory tunnels.Caller should check negative cache and/or banlist before calling.
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).
- Specified by:
searchin classKademliaNetworkDatabaseFacade- Parameters:
key- the hash to search foronFindJob- job on findonFailedLookupJob- job on failuretimeoutMs- timeout in msisLease- whether searching for lease- Returns:
- always null; the caller is notified through onFindJob or onFailedLookupJob
search
SearchJob search(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs, boolean isLease, Hash fromLocalDest) Lookup using the client's tunnels.Caller should check negative cache and/or banlist before calling. Every path either schedules a search or queues onFailedLookupJob — never returns without notifying the caller.
- Specified by:
searchin classKademliaNetworkDatabaseFacade- Parameters:
key- the hash to search foronFindJob- job on findonFailedLookupJob- job on failuretimeoutMs- timeout in msisLease- whether searching for leasefromLocalDest- use these tunnels for the lookup, or null for exploratory- Returns:
- null always
getMainFacade
Main (router) NetDb facade, or null if not yet available. Client sub-DBs delegate exploratory searches here so callbacks always fire.- Returns:
- the main FloodfillNetworkDatabaseFacade, or null
failSearchCallbacks
Queue failure callbacks so a search that cannot start never leaves the caller waiting for a timeout that will never be scheduled. Success and failure jobs may both be non-null (lookupDestination); on failure both roles collapse to the finished/failed job.- Parameters:
onFindJob- may be nullonFailedLookupJob- may be null
complete
Must be called by the search job queued by search() on success or failure.- Parameters:
key- the key whose pending search is being retired
contactHeardFrom
Notify that we heard from or about a peer (e.g. received a DatabaseStoreMessage from them). The ContactDrivenRefreshJob will consider refreshing their RouterInfo if it is stale.- Parameters:
peer- the peer hash we heard from or about
probeStalePeer
Fire a DirectLookupJob for a stale peer, deduplicated via _activeFloodQueries. Caller should already have verified the peer is stale and not recently probed.- Parameters:
peer- the stale peer's router hash, which keys the deduplication mapri- the peer's RouterInfo, used by the job to verify the entry
getFloodfillPeers
isVerifyInProgress
Checks if verification is in progress for the specified hash.- Parameters:
h- the key whose verifying floodfill is being tested- Returns:
- true if a FloodfillVerifyStoreJob for this key is still running
verifyStarted
Marks verification as started for the specified hash.- Parameters:
h- the key being verified by a FloodfillVerifyStoreJob
verifyFinished
Marks verification as finished for the specified hash.- Parameters:
h- the key whose verifying floodfill has just completed
lookupBeforeDropping
Search for a newer router info, drop it from the db if the search fails, unless just started up or have bigger problems.- Overrides:
lookupBeforeDroppingin classKademliaNetworkDatabaseFacade- Parameters:
peer- the router hash to drop after the lookup failureinfo- the router info
getTunnelName
Look up the tunnel pool nickname for a destination.- Parameters:
d- the destination whose inbound, else outbound, pool nickname is wanted- Returns:
- the configured nickname, or the empty string if neither pool has one