Make getinfo ns/purpose/bridge actually work

Also, dump our bridge router status entries to disk every 30 minutes.


svn:r12871
This commit is contained in:
Roger Dingledine 2007-12-19 04:58:58 +00:00
parent a697573ce9
commit f405f9b614
8 changed files with 46 additions and 18 deletions

View File

@ -36,13 +36,17 @@ Changes in version 0.2.0.13-alpha - 2007-12-??
AlternateBridgeAuthority, and AlternateHSAuthority) that let the
user selectively replace the default directory authorities, rather
than the all-or-nothing replacement that DirServer offers.
- Tor can now be configured to read a GeoIP file from disk in one of two
formats. This can be used by controllers to map IPs to countries.
Eventually, it may support exit-by-country.
- When possible, bridges remember which countries users are coming
from, and report aggregate information in their extra-info
documents, so that the bridge authorities can learn where Tor is
blocked.
- Tor can now be configured to read a GeoIP file from disk in one
of two formats. This can be used by controllers to map IP addresses
to countries. Eventually, it may support exit-by-country.
- When possible, bridge relays remember which countries users
are coming from, and report aggregate information in their
extra-info documents, so that the bridge authorities can learn
where Tor is blocked.
- Bridge directory authorities now do reachability testing on the
bridges they know. They provide router status summaries to the
controller on "getinfo ns/purpose/bridge", and also dump summaries
to a file periodically.
o Minor bugfixes:
- The fix in 0.2.0.12-alpha cleared the "hsdir" flag in v3 network

View File

@ -721,7 +721,7 @@ anything itself; to save bandwidth, leave this option turned off.
.LP
.TP
\fBFallbackNetworkstatusFile\fP \fIFILENAME\fP
If Tor doesn't have a cached networkstatus file, it starts out uses
If Tor doesn't have a cached networkstatus file, it starts out using
this one instead. Even if this file is out of date, Tor can still use
it to learn about directory mirrors, so it doesn't need to put load on
the authorities. (Default: None).

View File

@ -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. */

View File

@ -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,

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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);