Class KademliaNetworkDatabaseFacade

    • Field Detail

      • _log

        protected final Log _log
      • _networkID

        protected final int _networkID
      • DONT_FAIL_PERIOD

        protected static final 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
        See Also:
        Constant Field Values
      • MIN_RESEED

        static final int MIN_RESEED
        Reseed if below this.
        Since:
        0.9.4
        See Also:
        Constant Field Values
      • MIN_REMAINING_ROUTERS

        protected static final 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. As of 0.9.4, we make this LOWER than the min for reseeding, so a reseed will be forced if necessary.
        See Also:
        Constant Field Values
      • PUBLISH_JOB_DELAY

        protected static final 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. Unused.
        See Also:
        Constant Field Values
    • Constructor Detail

      • KademliaNetworkDatabaseFacade

        public KademliaNetworkDatabaseFacade​(RouterContext context)
    • Method Detail

      • searchComplete

        void searchComplete​(Hash key)
        The search for the given key is no longer active
      • createPeerSelector

        protected abstract PeerSelector createPeerSelector()
      • getLastExploreNewDate

        long getLastExploreNewDate()
      • setLastExploreNewDate

        void setLastExploreNewDate​(long when)
      • getExploreKeys

        public Set<Hash> getExploreKeys()
        Returns:
        unmodifiable set
      • removeFromExploreKeys

        public void removeFromExploreKeys​(Collection<Hash> toRemove)
      • queueForExploration

        public void queueForExploration​(Collection<Hash> keys)
      • shutdown

        public void shutdown()
        Description copied from interface: Service
        Instruct the service that the router is shutting down and that it should do whatever is necessary to go down gracefully. It should not depend on other components at this point. This call DOES block.
      • restart

        public void restart()
        Description copied from interface: Service
        Perform a soft restart.
      • startup

        public void startup()
        Description copied from interface: Service
        Instruct the service that it should start normal operation. This call DOES block until the service is ready.
      • createHandlers

        protected void createHandlers()
        unused, see override
      • findNearestRouters

        public 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
        Specified by:
        findNearestRouters in class NetworkDatabaseFacade
        Parameters:
        key - the real key, NOT the routing key
        peersToIgnore - can be null
        maxNumRouters - The maximum number of routers to return
      • getKnownRouters

        public 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. But now that is probably not what you want. Just return the count in the data store.
        Overrides:
        getKnownRouters in class NetworkDatabaseFacade
      • getKnownLeaseSets

        public int getKnownLeaseSets()
        This is only used by StatisticsManager to publish the count if we are floodfill. So to hide a clue that a popular eepsite is hosted on a floodfill router, only count leasesets that are "received as published", as of 0.7.14
        Overrides:
        getKnownLeaseSets in class NetworkDatabaseFacade
      • getKBucketSetSize

        protected int getKBucketSetSize()
        This is fast and doesn't use synchronization, but it includes both routerinfos and leasesets. Use it to avoid deadlocks. No - not true - the KBS contains RIs only.
      • routingKeyChanged

        public void routingKeyChanged()
        Notify the netDB that the routing key changed at midnight UTC
        Overrides:
        routingKeyChanged in class NetworkDatabaseFacade
        Since:
        0.9.50
      • lookupLeaseSet

        public void lookupLeaseSet​(Hash key,
                                   Job onFindJob,
                                   Job onFailedLookupJob,
                                   long timeoutMs)
        Lookup using exploratory tunnels. Use lookupDestination() if you don't need the LS or don't need it validated.
        Specified by:
        lookupLeaseSet in class NetworkDatabaseFacade
      • lookupLeaseSet

        public 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.
        Specified by:
        lookupLeaseSet in class NetworkDatabaseFacade
        Parameters:
        fromLocalDest - use these tunnels for the lookup, or null for exploratory
        Since:
        0.9.10
      • lookupLeaseSetRemotely

        public void lookupLeaseSetRemotely​(Hash key,
                                           Hash fromLocalDest)
        Unconditionally lookup using the client's tunnels. No success or failed jobs, no local lookup, no checks. Use this to refresh a leaseset before expiration.
        Specified by:
        lookupLeaseSetRemotely in class NetworkDatabaseFacade
        Parameters:
        fromLocalDest - use these tunnels for the lookup, or null for exploratory
        Since:
        0.9.25
      • lookupLeaseSetRemotely

        public void lookupLeaseSetRemotely​(Hash key,
                                           Job onFindJob,
                                           Job onFailedLookupJob,
                                           long timeoutMs,
                                           Hash fromLocalDest)
        Unconditionally lookup using the client's tunnels.
        Specified by:
        lookupLeaseSetRemotely in class NetworkDatabaseFacade
        Parameters:
        fromLocalDest - use these tunnels for the lookup, or null for exploratory
        onFindJob - may be null
        onFailedLookupJob - may be null
        Since:
        0.9.47
      • lookupDestination

        public 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. Note that there are not separate success and fail jobs. Caller must call lookupDestinationLocally() in the job to determine success.
        Specified by:
        lookupDestination in class NetworkDatabaseFacade
        Parameters:
        onFinishedJob - non-null
        fromLocalDest - use these tunnels for the lookup, or null for exploratory
        Since:
        0.9.16
      • lookupRouterInfoLocally

        public RouterInfo lookupRouterInfoLocally​(Hash key)
        This will return immediately with the result or null. However, this may still fire off a lookup if the RI is present but expired (and will return null). This may result in deadlocks. For true local only, use lookupLocallyWithoutValidation()
        Specified by:
        lookupRouterInfoLocally in class NetworkDatabaseFacade
      • stopPublishing

        void stopPublishing​(Hash target)
      • routerInfoPublishSuccessful

        void routerInfoPublishSuccessful()
        Set the last time we successfully published our RI.
        Since:
        0.9.9
      • validate

        String validate​(RouterInfo routerInfo)
                 throws IllegalArgumentException
        Determine whether this routerInfo will be accepted as valid and current given what we know now. Call this before each use, to check expiration
        Returns:
        reason why the entry is not valid, or null if it is valid
        Throws:
        IllegalArgumentException
        Since:
        0.9.7
      • fail

        public void fail​(Hash dbEntry)
        Final remove for a leaseset. For a router info, will look up in the network before dropping.
        Specified by:
        fail in class NetworkDatabaseFacade
      • lookupBeforeDropping

        protected void lookupBeforeDropping​(Hash peer,
                                            RouterInfo info)
        don't use directly - see F.N.D.F. override
      • dropAfterLookupFailed

        void dropAfterLookupFailed​(Hash peer)
        Final remove for a router info. Do NOT use for leasesets.
      • search

        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.
        Throws:
        UnsupportedOperationException - always
      • getPeerTimeout

        public int getPeerTimeout​(Hash peer)
        todo: does this need more tuning?
      • sendStore

        public abstract void sendStore​(Hash key,
                                       DatabaseEntry ds,
                                       Job onSuccess,
                                       Job onFailure,
                                       long sendTimeout,
                                       Set<Hash> toIgnore)
        unused (overridden in FNDF)
      • lookupFailed

        void lookupFailed​(Hash key)
        Increment in the negative lookup cache
        Parameters:
        key - for Destinations or RouterIdentities
        Since:
        0.9.4 moved from FNDF to KNDF in 0.9.16
      • isNegativeCached

        boolean isNegativeCached​(Hash key)
        Is the key in the negative lookup cache?
        Parameters:
        key - for Destinations or RouterIdentities
        Since:
        0.9.4 moved from FNDF to KNDF in 0.9.16
      • failPermanently

        void failPermanently​(Destination dest)
        Negative cache until restart
        Since:
        0.9.16
      • isNegativeCachedForever

        public boolean isNegativeCachedForever​(Hash key)
        Is it permanently negative cached?
        Overrides:
        isNegativeCachedForever in class NetworkDatabaseFacade
        Parameters:
        key - only for Destinations; for RouterIdentities, see Banlist
        Since:
        0.9.16