summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-02-15 20:23:23 -0500
committerNick Mathewson <nickm@torproject.org>2018-02-15 20:23:23 -0500
commit3ca04aada2916ce6963358007476eccd851e67cc (patch)
tree9d4a2f68ea04c2a07f64b1d8c583a8e16db59c50
parent3d7bf98d13ffc090e5ba1b918f53668018690dce (diff)
parentad06e0b406f5b3dfaa28da0f03ede4b0f850d00f (diff)
downloadtor-3ca04aada2916ce6963358007476eccd851e67cc.tar.gz
tor-3ca04aada2916ce6963358007476eccd851e67cc.zip
Merge remote-tracking branch 'valentecaio/t-25081'
-rw-r--r--changes/ticket250815
-rw-r--r--src/or/dirserv.c2
-rw-r--r--src/or/hibernate.c2
-rw-r--r--src/or/main.c19
-rw-r--r--src/or/main.h2
-rw-r--r--src/or/router.c2
6 files changed, 22 insertions, 10 deletions
diff --git a/changes/ticket25081 b/changes/ticket25081
new file mode 100644
index 0000000000..b6e6c2a5a6
--- /dev/null
+++ b/changes/ticket25081
@@ -0,0 +1,5 @@
+ o Code simplification and refactoring:
+ - Remove extern declaration of stats_n_seconds_working variable from main,
+ protecting its accesses with get_uptime() and reset_uptime() functions.
+ Closes ticket 25081, patch by “valentecaio”.
+
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 0f47a83986..7ccce50bc5 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1423,7 +1423,7 @@ dirserv_thinks_router_is_hs_dir(const routerinfo_t *router,
* tests aren't instant. If we haven't been running long enough,
* trust the relay. */
- if (stats_n_seconds_working >
+ if (get_uptime() >
get_options()->MinUptimeHidServDirectoryV2 * 1.1)
uptime = MIN(rep_hist_get_uptime(router->cache_info.identity_digest, now),
real_uptime(router, now));
diff --git a/src/or/hibernate.c b/src/or/hibernate.c
index 4dc35f68d0..7261cf8002 100644
--- a/src/or/hibernate.c
+++ b/src/or/hibernate.c
@@ -866,7 +866,7 @@ hibernate_end(hibernate_state_t new_state)
hibernate_state = new_state;
hibernate_end_time = 0; /* no longer hibernating */
- stats_n_seconds_working = 0; /* reset published uptime */
+ reset_uptime(); /* reset published uptime */
}
/** A wrapper around hibernate_begin, for when we get SIGINT. */
diff --git a/src/or/main.c b/src/or/main.c
index ba90e6a8bb..5583f370fa 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1095,7 +1095,7 @@ directory_all_unreachable(time_t now)
{
(void)now;
- stats_n_seconds_working=0; /* reset it */
+ reset_uptime(); /* reset it */
if (!directory_all_unreachable_cb_event) {
directory_all_unreachable_cb_event =
@@ -2064,7 +2064,7 @@ check_for_reachability_bw_callback(time_t now, const or_options_t *options)
if (server_mode(options) &&
(have_completed_a_circuit() || !any_predicted_circuits(now)) &&
!net_is_disabled()) {
- if (stats_n_seconds_working < TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT) {
+ if (get_uptime() < TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT) {
consider_testing_reachability(1, dirport_reachability_count==0);
if (++dirport_reachability_count > 5)
dirport_reachability_count = 0;
@@ -2321,8 +2321,8 @@ second_elapsed_callback(periodic_timer_t *timer, void *arg)
!net_is_disabled() &&
seconds_elapsed > 0 &&
have_completed_a_circuit() &&
- stats_n_seconds_working / TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT !=
- (stats_n_seconds_working+seconds_elapsed) /
+ get_uptime() / TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT !=
+ (get_uptime()+seconds_elapsed) /
TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT) {
/* every 20 minutes, check and complain if necessary */
const routerinfo_t *me = router_get_my_routerinfo();
@@ -2466,9 +2466,9 @@ ip_address_changed(int at_interface)
}
} else {
if (server) {
- if (stats_n_seconds_working > UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST)
+ if (get_uptime() > UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST)
reset_bandwidth_test();
- stats_n_seconds_working = 0;
+ reset_uptime();
router_reset_reachability();
}
}
@@ -3006,6 +3006,13 @@ get_uptime,(void))
return stats_n_seconds_working;
}
+/** Reset Tor's uptime. */
+MOCK_IMPL(void,
+reset_uptime,(void))
+{
+ stats_n_seconds_working = 0;
+}
+
/**
* Write current memory usage information to the log.
*/
diff --git a/src/or/main.h b/src/or/main.h
index c49d216f4e..f01506fcea 100644
--- a/src/or/main.h
+++ b/src/or/main.h
@@ -63,6 +63,7 @@ void reschedule_descriptor_update_check(void);
void reschedule_directory_downloads(void);
MOCK_DECL(long,get_uptime,(void));
+MOCK_DECL(void,reset_uptime,(void));
unsigned get_signewnym_epoch(void);
@@ -87,7 +88,6 @@ uint64_t get_main_loop_error_count(void);
uint64_t get_main_loop_idle_count(void);
extern time_t time_of_process_start;
-extern long stats_n_seconds_working;
extern int quiet_level;
extern int global_read_bucket;
extern int global_write_bucket;
diff --git a/src/or/router.c b/src/or/router.c
index 9c053cad46..ddfc187e9f 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -2922,7 +2922,7 @@ router_dump_router_to_string(routerinfo_t *router,
proto_line,
published,
fingerprint,
- stats_n_seconds_working,
+ get_uptime(),
(int) router->bandwidthrate,
(int) router->bandwidthburst,
(int) router->bandwidthcapacity,