Commit 474c60b7 authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

Cleanup on time-relaqted constants. New conventions:

  1) Surround all constants by (parens), whether we'll be using them
     in a denominator or not.
  2) Express all time periods as products (24*60*60), not as multiplied-out
     constants (86400).
  3) Comments like "(60*60) /* one hour */" are as pointless as comments
     like "c = a + b; /* set c to the sum of a and b */".  Remove them.
  4) All time periods should be #defined constants, not given inline.
  5) All time periods should have doxygen comments.
  6) All time periods, unless specified, are in seconds.  It's not necessary
     to say so.

To summarize, the old (lack of) style would allow:

  #define FOO_RETRY_INTERVAL 60*60 /* one hour (seconds) */
  next_try = now + 3600;

The new style is:

  /** How often do we reattempt foo? */
  #define FOO_RETRY_INTERVAL (60*60)

  next_try = now + RETRY_INTERVAL;


svn:r6142
parent b67a5ba4
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ circuit_stream_is_being_handled(connection_t *conn, uint16_t port, int min)
  return 0;
}

/** Don't keep more than 10 unused open circuits around. */
/** Don't keep more than this many unused open circuits around. */
#define MAX_UNUSED_OPEN_CIRCUITS 12

/** Figure out how many circuits we have open that are clean. Make
@@ -547,6 +547,9 @@ circuit_about_to_close_connection(connection_t *conn)
  } /* end switch */
}

/** How old do we let an unused circuit get before expiring it? */
#define CIRCUIT_UNUSED_CIRC_TIMEOUT (60*60)

/** Find each circuit that has been dirty for too long, and has
 * no streams on it: mark it for close.
 */
@@ -576,7 +579,6 @@ circuit_expire_old_circuits(void)
    } else if (!circ->timestamp_dirty && CIRCUIT_IS_ORIGIN(circ) &&
               circ->state == CIRCUIT_STATE_OPEN &&
               circ->purpose == CIRCUIT_PURPOSE_C_GENERAL) {
#define CIRCUIT_UNUSED_CIRC_TIMEOUT 3600 /* an hour */
      if (circ->timestamp_created + CIRCUIT_UNUSED_CIRC_TIMEOUT < now) {
        log_debug(LD_CIRC,
                  "Closing circuit that has been unused for %d seconds.",
+18 −8
Original line number Diff line number Diff line
@@ -1952,6 +1952,24 @@ fascist_firewall_allows_address_dir(uint32_t addr, uint16_t port)
                                          reachable_dir_addr_policy);
}

/** Lowest allowable value for DirFetchPeriod; if this is too low, clients can
 * overload the directory system. */
#define MIN_DIR_FETCH_PERIOD (10*60)
/** Lowest allowable value for RendPostPeriod; if this is too low, hidden
 * services can overload the directory system. */
#define MIN_REND_POST_PERIOD (5*60)
/** Lowest allowable value for StatusFetchPeriod; if this is too low, clients
 * can overload the directory system. */
#define MIN_STATUS_FETCH_PERIOD (5*60)

/** Highest allowable value for DirFetchPeriod, StatusFetchPeriod, and
 * RendPostPeriod. */
#define MAX_DIR_PERIOD (MIN_ONION_KEY_LIFETIME/2)
/** Highest allowable value for DirFetchPeriod for directory caches. */
#define MAX_CACHE_DIR_FETCH_PERIOD (60*60)
/** Highest allowable value for StatusFetchPeriod for directory caches. */
#define MAX_CACHE_STATUS_FETCH_PERIOD (15*60)

/** Return 0 if every setting in <b>options</b> is reasonable.  Else
 * warn and return -1.  Should have no side effects, except for
 * normalizing the contents of <b>options</b>.
@@ -2257,14 +2275,6 @@ options_validate(or_options_t *old_options, or_options_t *options,
      (options->PathlenCoinWeight < 0.0 || options->PathlenCoinWeight >= 1.0))
    REJECT("PathlenCoinWeight option must be >=0.0 and <1.0.");

#define MIN_DIR_FETCH_PERIOD 600
#define MIN_REND_POST_PERIOD 300
#define MIN_STATUS_FETCH_PERIOD 60

#define MAX_DIR_PERIOD (MIN_ONION_KEY_LIFETIME/2)
#define MAX_CACHE_DIR_FETCH_PERIOD 3600
#define MAX_CACHE_STATUS_FETCH_PERIOD 900

  if (options->DirFetchPeriod &&
      options->DirFetchPeriod < MIN_DIR_FETCH_PERIOD) {
    log(LOG_WARN, LD_CONFIG,
+7 −5
Original line number Diff line number Diff line
@@ -398,12 +398,14 @@ process_pending_task(connection_t *cpuworker)
    log_warn(LD_OR,"assign_to_cpuworker failed. Ignoring.");
}

#define CPUWORKER_BUSY_TIMEOUT 3600 /* seconds */
/** How long do we let a cpuworker work before deciding that it's wedged? */
#define CPUWORKER_BUSY_TIMEOUT (60*60)

/** We have a bug that I can't find. Sometimes, very rarely, cpuworkers
 * get stuck in the 'busy' state, even though the cpuworker process
 * thinks of itself as idle. I don't know why. But here's a workaround
 * to kill any cpuworker that's been busy for more than 3600 seconds. */
/** We have a bug that I can't find. Sometimes, very rarely, cpuworkers get
 * stuck in the 'busy' state, even though the cpuworker process thinks of
 * itself as idle. I don't know why. But here's a workaround to kill any
 * cpuworker that's been busy for more than CPUWORKER_BUSY_TIMEOUT.
 */
static void
cull_wedged_cpuworkers(void)
{
+3 −1
Original line number Diff line number Diff line
@@ -56,7 +56,9 @@ static void note_request(const char *key, size_t bytes);

static addr_policy_t *dir_policy = NULL;

#define ALLOW_DIRECTORY_TIME_SKEW 30*60 /* 30 minutes */
/** How far in the future do we allow a directory server to tell us it is
 * before deciding that one of us has the wrong time? */
#define ALLOW_DIRECTORY_TIME_SKEW (30*60)

/********* END VARIABLES ************/

+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ const char dirserv_c_id[] =
 **/

/** How far in the future do we allow a router to get? (seconds) */
#define ROUTER_ALLOW_SKEW (60*60*12) /* 12 hours */
#define ROUTER_ALLOW_SKEW (60*60*12)
/** How many seconds do we wait before regenerating the directory? */
#define DIR_REGEN_SLACK_TIME 30
/** If we're a cache, keep this many networkstatuses around from non-trusted
Loading