summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2007-12-19 04:58:58 +0000
committerRoger Dingledine <arma@torproject.org>2007-12-19 04:58:58 +0000
commitf405f9b6140d9f001bb96364dc4c240afc222103 (patch)
tree8c16b2430bf2e4b0a19e010d640cb0291db17152 /src
parenta697573ce911f0b16e5cb5e8d73d4863883f82ac (diff)
downloadtor-f405f9b6140d9f001bb96364dc4c240afc222103.tar.gz
tor-f405f9b6140d9f001bb96364dc4c240afc222103.zip
Make getinfo ns/purpose/bridge actually work
Also, dump our bridge router status entries to disk every 30 minutes. svn:r12871
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c1
-rw-r--r--src/or/control.c2
-rw-r--r--src/or/main.c11
-rw-r--r--src/or/networkstatus.c20
-rw-r--r--src/or/or.h2
-rw-r--r--src/or/rephist.c8
6 files changed, 34 insertions, 10 deletions
diff --git a/src/or/config.c b/src/or/config.c
index f83ca0f246..a7650637f1 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -83,6 +83,7 @@ static config_abbrev_t _option_abbrevs[] = {
{ "ResolvConf", "ServerDNSResolvConfFile", 0, 1},
{ "SearchDomains", "ServerDNSSearchDomains", 0, 1},
{ "PreferTunnelledDirConns", "PreferTunneledDirConns", 0, 0},
+ { "BridgeAuthoritativeDirectory", "BridgeAuthoritativeDir", 0, 0},
{ NULL, NULL, 0, 0},
};
/* A list of state-file abbreviations, for compatibility. */
diff --git a/src/or/control.c b/src/or/control.c
index af1bb42f60..23c331b937 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1745,6 +1745,8 @@ static const getinfo_item_t getinfo_items[] = {
"Brief summary of router status by ID (v2 directory format)."),
PREFIX("ns/name/", networkstatus,
"Brief summary of router status by nickname (v2 directory format)."),
+ PREFIX("ns/purpose/", networkstatus,
+ "Brief summary of router status by purpose (v2 directory format)."),
PREFIX("unregistered-servers-", dirserv_unregistered, NULL),
ITEM("network-status", dir,
diff --git a/src/or/main.c b/src/or/main.c
index 620edad426..e00a03ac83 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -119,8 +119,6 @@ int has_completed_circuit=0;
/** How long do we let OR connections handshake before we decide that
* they are obsolete? */
#define TLS_HANDSHAKE_TIMEOUT (60)
-/** How often do we write hidden service usage statistics to disk? */
-#define WRITE_HSUSAGE_INTERVAL (900)
/********* END VARIABLES ************/
@@ -830,7 +828,10 @@ run_scheduled_events(time_t now)
static time_t time_to_try_getting_descriptors = 0;
static time_t time_to_reset_descriptor_failures = 0;
static time_t time_to_add_entropy = 0;
+#define WRITE_HSUSAGE_INTERVAL (30*60)
static time_t time_to_write_hs_statistics = 0;
+#define BRIDGE_STATUSFILE_INTERVAL (30*60)
+ static time_t time_to_write_bridge_status_file = 0;
static time_t time_to_downrate_stability = 0;
#define SAVE_STABILITY_INTERVAL (30*60)
static time_t time_to_save_stability = 0;
@@ -1111,6 +1112,12 @@ run_scheduled_events(time_t now)
hs_usage_write_statistics_to_file(now);
time_to_write_hs_statistics = now+WRITE_HSUSAGE_INTERVAL;
}
+ /** 10b. write bridge networkstatus file to disk */
+ if (options->BridgeAuthoritativeDir &&
+ time_to_write_bridge_status_file < now) {
+ hs_usage_write_statistics_to_file(now);
+ time_to_write_bridge_status_file = now+BRIDGE_STATUSFILE_INTERVAL;
+ }
}
/** Libevent timer: used to invoke second_elapsed_callback() once per
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 884bc0a3a6..e2f3d9281b 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -1685,9 +1685,8 @@ networkstatus_getinfo_helper_single(routerstatus_t *rs)
* shouldn't use this for general-purpose routers, since those
* should be listed from the consensus, not from the routers list). */
char *
-networkstatus_getinfo_by_purpose(const char *purpose_string)
+networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now)
{
- time_t now = time(NULL);
time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
char *answer;
routerlist_t *rl = router_get_routerlist();
@@ -1720,6 +1719,21 @@ networkstatus_getinfo_by_purpose(const char *purpose_string)
return answer;
}
+/** Write out router status entries for all our bridge descriptors. */
+void
+networkstatus_dump_bridge_status_to_file(time_t now)
+{
+ char *status = networkstatus_getinfo_by_purpose("bridge", now);
+ or_options_t *options = get_options();
+ size_t len = strlen(options->DataDirectory) + 32;
+ char *fname = tor_malloc(len);
+ tor_snprintf(fname, len, "%s"PATH_SEPARATOR"networkstatus-bridges",
+ options->DataDirectory);
+ write_str_to_file(fname,status,0);
+ tor_free(fname);
+ tor_free(status);
+}
+
/** If <b>question</b> is a string beginning with "ns/" in a format the
* control interface expects for a GETINFO question, set *<b>answer</b> to a
* newly-allocated string containing networkstatus lines for the appropriate
@@ -1756,7 +1770,7 @@ getinfo_helper_networkstatus(control_connection_t *conn,
} else if (!strcmpstart(question, "ns/name/")) {
status = router_get_consensus_status_by_nickname(question+8, 0);
} else if (!strcmpstart(question, "ns/purpose/")) {
- *answer = networkstatus_getinfo_by_purpose(question+11);
+ *answer = networkstatus_getinfo_by_purpose(question+11, time(NULL));
return *answer ? 0 : -1;
} else {
return -1;
diff --git a/src/or/or.h b/src/or/or.h
index 4625f7852c..7aba08ca75 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3361,7 +3361,7 @@ void signed_descs_update_status_from_consensus_networkstatus(
smartlist_t *descs);
char *networkstatus_getinfo_helper_single(routerstatus_t *rs);
-char *networkstatus_getinfo_by_purpose(const char *purpose_string);
+char *networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now);
int getinfo_helper_networkstatus(control_connection_t *conn,
const char *question, char **answer);
void networkstatus_free_all(void);
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 1561540d02..2c84e40c2f 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -2153,21 +2153,21 @@ hs_usage_format_statistics(void)
return buf;
}
-/** Writes current statistics to file. */
+/** Write current statistics about hidden service usage to file. */
void
hs_usage_write_statistics_to_file(time_t now)
{
char *buf;
size_t len;
char *fname;
- or_options_t *options;
+ or_options_t *options = get_options();
/* check if we are up-to-date */
hs_usage_check_if_current_period_is_up_to_date(now);
buf = hs_usage_format_statistics();
- options = get_options();
len = strlen(options->DataDirectory) + 16;
fname = tor_malloc(len);
- tor_snprintf(fname,len, "%s"PATH_SEPARATOR"hsusage", options->DataDirectory);
+ tor_snprintf(fname, len, "%s"PATH_SEPARATOR"hsusage",
+ options->DataDirectory);
write_str_to_file(fname,buf,0);
tor_free(buf);
tor_free(fname);