summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2007-08-17 01:29:58 +0000
committerRoger Dingledine <arma@torproject.org>2007-08-17 01:29:58 +0000
commit3f186e6510f0df216ee1f807922745b21c791c68 (patch)
tree942b841b5a5825e618a15706327794c41b1eb383 /src
parent357b4645cf1e01e0b8790b0739d36221eb2bb3d0 (diff)
downloadtor-3f186e6510f0df216ee1f807922745b21c791c68.tar.gz
tor-3f186e6510f0df216ee1f807922745b21c791c68.zip
help nick work on proposal 108
svn:r11148
Diffstat (limited to 'src')
-rw-r--r--src/or/dirserv.c37
-rw-r--r--src/or/main.c8
-rw-r--r--src/or/or.h5
-rw-r--r--src/or/rephist.c30
4 files changed, 57 insertions, 23 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index ed3a15061c..4762b99805 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -53,8 +53,8 @@ dirserv_get_status_impl(const char *fp, const char *nickname,
uint32_t addr, uint16_t or_port,
const char *platform, const char *contact,
const char **msg, int should_log);
-static int dirserv_thinks_router_is_reachable(routerinfo_t *router,
- time_t now);
+static void dirserv_set_router_is_running(routerinfo_t *router,
+ time_t now);
static void clear_cached_dir(cached_dir_t *d);
static int dirserv_add_extrainfo(extrainfo_t *ei, const char **msg);
@@ -839,13 +839,23 @@ list_single_server_status(routerinfo_t *desc, int is_live)
/** Treat a router as alive if
* - It's me, and I'm not hibernating.
* or - We've found it reachable recently. */
-static int
-dirserv_thinks_router_is_reachable(routerinfo_t *router, time_t now)
+static void
+dirserv_set_router_is_running(routerinfo_t *router, time_t now)
{
+ int answer;
+
if (router_is_me(router) && !we_are_hibernating())
- return 1;
- return get_options()->AssumeReachable ||
- now < router->last_reachable + REACHABLE_TIMEOUT;
+ answer = 1;
+ else
+ answer = get_options()->AssumeReachable ||
+ now < router->last_reachable + REACHABLE_TIMEOUT;
+
+ if (router->is_running && !answer) {
+ /* it was running but now it's not. tell rephist. */
+ rep_hist_note_router_unreachable(router->cache_info.identity_digest, now);
+ }
+
+ router->is_running = answer;
}
/** Return 1 if we're confident that there's a problem with
@@ -892,7 +902,7 @@ list_server_status(smartlist_t *routers, char **router_status_out,
{
if (authdir) {
/* Update router status in routerinfo_t. */
- ri->is_running = dirserv_thinks_router_is_reachable(ri, now);
+ dirserv_set_router_is_running(ri, now);
}
if (for_controller == 1 || ri->cache_info.published_on >= cutoff)
smartlist_add(rs_entries, list_single_server_status(ri, ri->is_running));
@@ -1927,7 +1937,7 @@ generate_networkstatus_vote_obj(crypto_pk_env_t *private_key,
/* precompute this part, since we need it to decide what "stable"
* means. */
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
- ri->is_running = dirserv_thinks_router_is_reachable(ri, now);
+ dirserv_set_router_is_running(ri, now);
});
dirserv_compute_performance_thresholds(rl);
@@ -2345,7 +2355,7 @@ generate_networkstatus_opinion(int v2)
/* precompute this part, since we need it to decide what "stable"
* means. */
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
- ri->is_running = dirserv_thinks_router_is_reachable(ri, now);
+ dirserv_set_router_is_running(ri, now);
});
dirserv_compute_performance_thresholds(rl);
@@ -2649,6 +2659,7 @@ dirserv_orconn_tls_done(const char *address,
int as_advertised)
{
routerlist_t *rl = router_get_routerlist();
+ time_t now = time(NULL);
tor_assert(address);
tor_assert(digest_rcvd);
@@ -2659,7 +2670,8 @@ dirserv_orconn_tls_done(const char *address,
/* correct digest. mark this router reachable! */
log_info(LD_DIRSERV, "Found router %s to be reachable. Yay.",
ri->nickname);
- ri->last_reachable = time(NULL);
+ rep_hist_note_router_reachable(digest_rcvd, now);
+ ri->last_reachable = now;
ri->num_unreachable_notifications = 0;
}
});
@@ -2677,9 +2689,8 @@ dirserv_orconn_tls_done(const char *address,
* bit over 20 minutes).
*/
void
-dirserv_test_reachability(int try_all)
+dirserv_test_reachability(time_t now, int try_all)
{
- time_t now = time(NULL);
/* XXX decide what to do here; see or-talk thread "purging old router
* information, revocation." -NM
* We can't afford to mess with this in 0.1.2.x. The reason is that
diff --git a/src/or/main.c b/src/or/main.c
index 3ccad90adc..aae07dfcf5 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -929,7 +929,7 @@ run_scheduled_events(time_t now)
if (now % 10 == 0 && (authdir_mode_tests_reachability(options)) &&
!we_are_hibernating()) {
/* try to determine reachability of the other Tor servers */
- dirserv_test_reachability(0);
+ dirserv_test_reachability(now, 0);
}
/** 1d. DOCDOC */
@@ -1322,6 +1322,7 @@ static int
do_main_loop(void)
{
int loop_result;
+ time_t now;
/* initialize dns resolve map, spawn workers if needed */
if (dns_init() < 0) {
@@ -1361,11 +1362,12 @@ do_main_loop(void)
if (router_reload_consensus_networkstatus()) {
return -1;
}
- directory_info_has_arrived(time(NULL),1);
+ now = time(NULL);
+ directory_info_has_arrived(now, 1);
if (authdir_mode_tests_reachability(get_options())) {
/* the directory is already here, run startup things */
- dirserv_test_reachability(1);
+ dirserv_test_reachability(now, 1);
}
if (server_mode(get_options())) {
diff --git a/src/or/or.h b/src/or/or.h
index 88eb43c44d..b1ab23ca32 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2804,7 +2804,7 @@ void dirserv_orconn_tls_done(const char *address,
uint16_t or_port,
const char *digest_rcvd,
int as_advertised);
-void dirserv_test_reachability(int try_all);
+void dirserv_test_reachability(time_t now, int try_all);
int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
int complain);
int dirserv_would_reject_router(routerstatus_t *rs);
@@ -3117,6 +3117,9 @@ void rep_hist_update_state(or_state_t *state);
int rep_hist_load_state(or_state_t *state, char **err);
void rep_history_clean(time_t before);
+void rep_hist_note_router_reachable(const char *id, time_t when);
+void rep_hist_note_router_unreachable(const char *id, time_t when);
+
time_t rep_hist_downrate_old_runs(time_t now);
double rep_hist_get_stability(const char *id, time_t when);
diff --git a/src/or/rephist.c b/src/or/rephist.c
index ccb8d79531..628bf794bc 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -262,6 +262,24 @@ rep_hist_note_connection_died(const char* id, time_t when)
hist->changed = when;
}
+/** We have just decided that this router is reachable, meaning
+ * we will give it a "Running" flag for the next while. */
+void
+rep_hist_note_router_reachable(const char *id, time_t when)
+{
+ (void)id;
+ (void)when;
+}
+
+/** We have just decided that this router is unreachable, meaning
+ * we are taking away its "Running" flag. */
+void
+rep_hist_note_router_unreachable(const char *id, time_t when)
+{
+ (void)id;
+ (void)when;
+}
+
/**DOCDOC*/
time_t
rep_hist_downrate_old_runs(time_t now)
@@ -1463,7 +1481,7 @@ hs_usage_write_service_related_observations_to_history(
hs_usage_list_clear(h->list);
}
-/** Advances to next observation period */
+/** Advances to next observation period. */
static void
hs_usage_advance_current_observation_period(void)
{
@@ -1533,7 +1551,7 @@ hs_usage_note_publish_novel(const char *service_id, time_t now)
}
/** Adds the observation of being requested for a rendezvous service descriptor
-* in our role as HS authoritative directory. */
+ * in our role as HS authoritative directory. */
void
hs_usage_note_fetch_total(const char *service_id, time_t now)
{
@@ -1541,15 +1559,15 @@ hs_usage_note_fetch_total(const char *service_id, time_t now)
}
/** Adds the observation of being requested for a rendezvous service descriptor
-* in our role as HS authoritative directory and being able to answer that
-* request successfully. */
+ * in our role as HS authoritative directory and being able to answer that
+ * request successfully. */
void
hs_usage_note_fetch_successful(const char *service_id, time_t now)
{
hs_usage_add_service_related_observation(fetch_successful, now, service_id);
}
-/** Writes the given circular array to a string */
+/** Writes the given circular array to a string. */
static size_t
hs_usage_format_history(char *buf, size_t len, uint32_t *data)
{
@@ -1574,7 +1592,7 @@ hs_usage_format_history(char *buf, size_t len, uint32_t *data)
}
/** Writes the complete usage history as hidden service authoritative directory
- * to a string */
+ * to a string. */
static char *
hs_usage_format_statistics(void)
{