mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Concentrate all TOR_USEC_PER_SEC definitions in a single header file.
Co-authored-by: Mike Perry <mikeperry-git@torproject.org>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "core/or/channel.h"
|
||||
|
||||
#include "lib/time/compat_time.h"
|
||||
#include "lib/defs/time.h"
|
||||
#include "lib/crypt_ops/crypto_rand.h"
|
||||
|
||||
#include "core/or/crypt_path_st.h"
|
||||
@@ -31,10 +32,6 @@
|
||||
|
||||
#include "app/config/config.h"
|
||||
|
||||
/* XXX: This is a dup of the constant in ./src/lib/time/tvdiff.c.
|
||||
* Should/Do we have a header for time constants like this? */
|
||||
#define TOR_USEC_PER_SEC (1000000)
|
||||
|
||||
static inline circpad_purpose_mask_t circpad_circ_purpose_to_mask(uint8_t
|
||||
circ_purpose);
|
||||
static inline circpad_circuit_state_t circpad_circuit_state(
|
||||
|
||||
@@ -37,6 +37,7 @@ hibernating, phase 2:
|
||||
#include "core/or/connection_or.h"
|
||||
#include "feature/control/control.h"
|
||||
#include "lib/crypt_ops/crypto_rand.h"
|
||||
#include "lib/defs/time.h"
|
||||
#include "feature/hibernate/hibernate.h"
|
||||
#include "core/mainloop/mainloop.h"
|
||||
#include "feature/relay/router.h"
|
||||
@@ -832,8 +833,6 @@ hibernate_soft_limit_reached(void)
|
||||
return get_accounting_bytes() >= soft_limit;
|
||||
}
|
||||
|
||||
#define TOR_USEC_PER_SEC (1000000)
|
||||
|
||||
/** Called when we get a SIGINT, or when bandwidth soft limit is
|
||||
* reached. Puts us into "loose hibernation": we don't accept new
|
||||
* connections, but we continue handling old ones. */
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
noinst_HEADERS += \
|
||||
src/lib/defs/dh_sizes.h \
|
||||
src/lib/defs/digest_sizes.h \
|
||||
src/lib/defs/time.h \
|
||||
src/lib/defs/x25519_sizes.h
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/* Copyright (c) 2001, Matej Pfajfar.
|
||||
* Copyright (c) 2001-2004, Roger Dingledine.
|
||||
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
||||
* Copyright (c) 2007-2018, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
#ifndef TOR_TIME_DEFS_H
|
||||
#define TOR_TIME_DEFS_H
|
||||
|
||||
/**
|
||||
* \file time.h
|
||||
*
|
||||
* \brief Definitions for timing-related constants.
|
||||
**/
|
||||
|
||||
/** How many microseconds per second */
|
||||
#define TOR_USEC_PER_SEC (1000000)
|
||||
/** How many nanoseconds per microsecond */
|
||||
#define TOR_NSEC_PER_USEC (1000)
|
||||
/* How many nanoseconds per millisecond */
|
||||
#define TOR_NSEC_PER_MSEC (1000*1000)
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@ lib/log/*.h
|
||||
lib/subsys/*.h
|
||||
lib/time/*.h
|
||||
lib/wallclock/*.h
|
||||
lib/defs/time.h
|
||||
|
||||
# For load_windows_system_lib.
|
||||
lib/fs/winlib.h
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "lib/time/tvdiff.h"
|
||||
|
||||
#include "lib/cc/compat_compiler.h"
|
||||
#include "lib/defs/time.h"
|
||||
#include "lib/log/log.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -20,8 +21,6 @@
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#define TOR_USEC_PER_SEC 1000000
|
||||
|
||||
/** Return the difference between start->tv_sec and end->tv_sec.
|
||||
* Returns INT64_MAX on overflow and underflow.
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <event.h>
|
||||
#include "lib/evloop/compat_libevent.h"
|
||||
#include "lib/time/compat_time.h"
|
||||
#include "lib/defs/time.h"
|
||||
#include "core/or/relay.h"
|
||||
#include "core/or/circuitlist.h"
|
||||
#include "core/or/circuitbuild.h"
|
||||
@@ -32,10 +33,6 @@
|
||||
|
||||
extern smartlist_t *connection_array;
|
||||
|
||||
#define USEC_PER_SEC (1000000)
|
||||
#define NSEC_PER_USEC (1000)
|
||||
#define NSEC_PER_MSEC (1000*1000)
|
||||
|
||||
circid_t get_unique_circ_id_by_chan(channel_t *chan);
|
||||
void helper_create_basic_machine(void);
|
||||
static void helper_create_conditional_machines(void);
|
||||
@@ -69,7 +66,7 @@ static circpad_machine_t circ_client_machine;
|
||||
static void
|
||||
timers_advance_and_run(int64_t msec_update)
|
||||
{
|
||||
curr_mocked_time += msec_update*NSEC_PER_MSEC;
|
||||
curr_mocked_time += msec_update*TOR_NSEC_PER_MSEC;
|
||||
monotime_coarse_set_mock_time_nsec(curr_mocked_time);
|
||||
monotime_set_mock_time_nsec(curr_mocked_time);
|
||||
timers_run_pending();
|
||||
@@ -304,9 +301,9 @@ test_circuitpadding_rtt(void *arg)
|
||||
|
||||
monotime_init();
|
||||
monotime_enable_test_mocking();
|
||||
monotime_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*NSEC_PER_USEC;
|
||||
monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*TOR_NSEC_PER_USEC;
|
||||
|
||||
timers_initialize();
|
||||
circpad_machines_init();
|
||||
@@ -994,9 +991,9 @@ test_circuitpadding_tokens(void *arg)
|
||||
|
||||
monotime_init();
|
||||
monotime_enable_test_mocking();
|
||||
monotime_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*NSEC_PER_USEC;
|
||||
monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*TOR_NSEC_PER_USEC;
|
||||
|
||||
timers_initialize();
|
||||
|
||||
@@ -1441,9 +1438,9 @@ test_circuitpadding_negotiation(void *arg)
|
||||
|
||||
monotime_init();
|
||||
monotime_enable_test_mocking();
|
||||
monotime_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*NSEC_PER_USEC;
|
||||
monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*TOR_NSEC_PER_USEC;
|
||||
|
||||
timers_initialize();
|
||||
circpad_machines_init();
|
||||
@@ -1562,7 +1559,7 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay,
|
||||
circpad_cell_event_nonpadding_received((circuit_t*)mid_relay);
|
||||
|
||||
// Advance time a tiny bit so we can calculate an RTT
|
||||
curr_mocked_time += 10 * NSEC_PER_MSEC;
|
||||
curr_mocked_time += 10 * TOR_NSEC_PER_MSEC;
|
||||
monotime_coarse_set_mock_time_nsec(curr_mocked_time);
|
||||
monotime_set_mock_time_nsec(curr_mocked_time);
|
||||
|
||||
@@ -1715,9 +1712,9 @@ test_circuitpadding_conditions(void *arg)
|
||||
|
||||
monotime_init();
|
||||
monotime_enable_test_mocking();
|
||||
monotime_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*NSEC_PER_USEC;
|
||||
monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*TOR_NSEC_PER_USEC;
|
||||
|
||||
timers_initialize();
|
||||
helper_create_conditional_machines();
|
||||
@@ -1835,9 +1832,9 @@ test_circuitpadding_circuitsetup_machine(void *arg)
|
||||
|
||||
monotime_init();
|
||||
monotime_enable_test_mocking();
|
||||
monotime_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*NSEC_PER_USEC;
|
||||
monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
|
||||
curr_mocked_time = 1*TOR_NSEC_PER_USEC;
|
||||
|
||||
timers_initialize();
|
||||
circpad_machines_init();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "feature/client/transports.h"
|
||||
#include "lib/crypt_ops/crypto_format.h"
|
||||
#include "lib/crypt_ops/crypto_rand.h"
|
||||
#include "lib/defs/time.h"
|
||||
#include "test/test.h"
|
||||
#include "lib/memarea/memarea.h"
|
||||
#include "lib/process/waitpid.h"
|
||||
@@ -404,7 +405,6 @@ test_util_time(void *arg)
|
||||
|
||||
/* Assume tv_usec is an unsigned integer until proven otherwise */
|
||||
#define TV_USEC_MAX UINT_MAX
|
||||
#define TOR_USEC_PER_SEC 1000000
|
||||
|
||||
/* Overflows in the result type */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user