コード例 #1
0
  /**
   * Search for a newer router info, drop it from the db if the search fails, unless just started up
   * or have bigger problems.
   */
  @Override
  protected void lookupBeforeDropping(Hash peer, RouterInfo info) {
    // following are some special situations, we don't want to
    // drop the peer in these cases
    // yikes don't do this - stack overflow //  getFloodfillPeers().size() == 0 ||
    // yikes2 don't do this either - deadlock! // getKnownRouters() < MIN_REMAINING_ROUTERS ||
    if (info.getNetworkId() == Router.NETWORK_ID
        && (getKBucketSetSize() < MIN_REMAINING_ROUTERS
            || _context.router().getUptime() < DONT_FAIL_PERIOD
            || _context.commSystem().countActivePeers() <= MIN_ACTIVE_PEERS)) {
      if (_log.shouldLog(Log.WARN))
        _log.warn(
            "Not failing " + peer.toBase64() + " as we are just starting up or have problems");
      return;
    }

    // should we skip the search?
    if (_floodfillEnabled
        || _context.jobQueue().getMaxLag() > 500
        || getKBucketSetSize() > MAX_DB_BEFORE_SKIPPING_SEARCH) {
      // don't try to overload ourselves (e.g. failing 3000 router refs at
      // once, and then firing off 3000 netDb lookup tasks)
      // Also don't queue a search if we have plenty of routerinfos
      // (KBucketSetSize() includes leasesets but avoids locking)
      super.lookupBeforeDropping(peer, info);
      return;
    }
    // this sends out the search to the floodfill peers even if we already have the
    // entry locally, firing no job if it gets a reply with an updated value (meaning
    // we shouldn't drop them but instead use the new data), or if they all time out,
    // firing the dropLookupFailedJob, which actually removes out local reference
    search(
        peer,
        new DropLookupFoundJob(_context, peer, info),
        new DropLookupFailedJob(_context, peer, info),
        10 * 1000,
        false);
  }