/*
  * dir-spec 5.1: Downloading network-status documents
  *
  *   To avoid swarming the caches whenever a consensus expires, the clients
  *   download new consensuses at a randomly chosen time after the caches are
  *   expected to have a fresh consensus, but before their consensus will
  *   expire. (This time is chosen uniformly at random from the interval
  *   between the time 3/4 into the first interval after the consensus is no
  *   longer fresh, and 7/8 of the time remaining after that before the
  *   consensus is invalid.)
  *
  *   [For example, if a cache has a consensus that became valid at 1:00, and
  *   is fresh until 2:00, and expires at 4:00, that cache will fetch a new
  *   consensus at a random time between 2:45 and 3:50, since 3/4 of the
  *   one-hour interval is 45 minutes, and 7/8 of the remaining 75 minutes is
  *   65 minutes.]
  */
 private Date chooseDownloadTimeForConsensus(ConsensusDocument consensus) {
   final long va = getMilliseconds(consensus.getValidAfterTime());
   final long fu = getMilliseconds(consensus.getFreshUntilTime());
   final long vu = getMilliseconds(consensus.getValidUntilTime());
   final long i1 = fu - va;
   final long start = fu + ((i1 * 3) / 4);
   final long i2 = ((vu - start) * 7) / 8;
   final long r = random.nextLong(i2);
   final long download = start + r;
   return new Date(download);
 }
 private boolean needConsensusDownload() {
   if (directory.hasPendingConsensus()) {
     return false;
   }
   if (currentConsensus == null || !currentConsensus.isLive()) {
     if (currentConsensus == null) {
       logger.info("Downloading consensus because we have no consensus document");
     } else {
       logger.info("Downloading consensus because the document we have is not live");
     }
     return true;
   }
   return consensusDownloadTime.before(new Date());
 }