diff --git a/ChangeLog b/ChangeLog
index 64421b9d9b..eebda9fbe2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -60,6 +60,7 @@ Changes in version 0.2.0.8-alpha - 2007-??-??
caches will no longer need to hold authority opinions; thus, the
rationale for keeping the types separate is now gone.
- Make the code used to reschedule and reattempt downloads more uniform.
+ - Turn all 'Are we a directory?' logic into a call to dirserver_mode().
Changes in version 0.2.0.7-alpha - 2007-09-21
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 647bdac976..da78784d80 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -2283,8 +2283,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
}
} else if (rh.command == RELAY_COMMAND_BEGIN_DIR) {
or_options_t *options = get_options();
- port = options->DirPort; /* not actually used to open a connection */
- if (!port || circ->purpose != CIRCUIT_PURPOSE_OR) {
+ if (!dirserver_mode(options) || circ->purpose != CIRCUIT_PURPOSE_OR) {
end_payload[0] = END_STREAM_REASON_NOTDIRECTORY;
relay_send_command_from_edge(rh.stream_id, circ, RELAY_COMMAND_END,
end_payload, 1, NULL);
diff --git a/src/or/control.c b/src/or/control.c
index 65bcaa01bc..5b39d586b1 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1381,7 +1381,7 @@ getinfo_helper_dir(control_connection_t *control_conn,
tor_free(url);
smartlist_free(descs);
} else if (!strcmpstart(question, "dir/status/")) {
- if (get_options()->DirPort) {
+ if (dirserver_mode(get_options())) {
size_t len=0;
char *cp;
smartlist_t *status_list = smartlist_create();
diff --git a/src/or/directory.c b/src/or/directory.c
index e41b790e60..75a7e5ad80 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -272,7 +272,7 @@ directory_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose,
{
routerstatus_t *rs = NULL;
or_options_t *options = get_options();
- int prefer_authority = server_mode(options) && options->DirPort != 0;
+ int prefer_authority = dirserver_mode(options);
int get_via_tor = purpose_needs_anonymity(dir_purpose, router_purpose);
authority_type_t type;
@@ -2753,7 +2753,7 @@ dir_routerdesc_download_failed(smartlist_t *failed, int status_code,
{
char digest[DIGEST_LEN];
time_t now = time(NULL);
- int server = server_mode(get_options()) && get_options()->DirPort;
+ int server = dirserver_mode(get_options());
if (!was_descriptor_digests)
return; /* FFFF should implement this someday */
SMARTLIST_FOREACH(failed, const char *, cp,
diff --git a/src/or/main.c b/src/or/main.c
index 9f325fbaf1..36a3a5e1d4 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -937,7 +937,7 @@ run_scheduled_events(time_t now)
* (if we've passed our internal checks). */
if (time_to_fetch_directory < now) {
/* Only caches actually need to fetch directories now. */
- if (options->DirPort && !authdir_mode_v1(options)) {
+ if (dirserver_mode(options) && !authdir_mode_v1(options)) {
/* XXX020 actually, we should only do this if we want to advertise
* our dirport. not simply if we configured one. -RD */
if (any_trusted_dir_is_v1_authority() &&
@@ -951,7 +951,7 @@ run_scheduled_events(time_t now)
}
/* Caches need to fetch running_routers; directory clients don't. */
- if (options->DirPort && time_to_fetch_running_routers < now) {
+ if (dirserver_mode(options) && time_to_fetch_running_routers < now) {
if (!authdir_mode_v1(options) && !should_delay_dir_fetches(options)) {
directory_get_from_dirserver(DIR_PURPOSE_FETCH_RUNNING_LIST,
ROUTER_PURPOSE_GENERAL, NULL, 1);
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 8026b5ff17..12dd05cb31 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -234,7 +234,7 @@ add_networkstatus_to_cache(const char *s,
tor_free(fn);
}
- if (get_options()->DirPort)
+ if (dirserver_mode(get_options()))
dirserv_set_cached_networkstatus_v2(s,
ns->identity_digest,
ns->published_on);
@@ -290,7 +290,7 @@ router_set_networkstatus(const char *s, time_t arrived_at,
!(trusted_dir->type & V2_AUTHORITY)) {
log_info(LD_DIR, "Network status was signed, but not by an authoritative "
"directory we recognize.");
- if (!get_options()->DirPort) {
+ if (!dirserver_mode(get_options())) {
networkstatus_free(ns);
return 0;
}
@@ -345,7 +345,7 @@ router_set_networkstatus(const char *s, time_t arrived_at,
}
if (!trusted_dir) {
- if (!skewed && get_options()->DirPort) {
+ if (!skewed && dirserver_mode(get_options())) {
/* We got a non-trusted networkstatus, and we're a directory cache.
* This means that we asked an authority, and it told us about another
* authority we didn't recognize. */
@@ -459,7 +459,7 @@ networkstatus_list_clean(time_t now)
unlink(fname);
}
tor_free(fname);
- if (get_options()->DirPort) {
+ if (dirserver_mode(get_options())) {
dirserv_set_cached_networkstatus_v2(NULL, ns->identity_digest, 0);
}
networkstatus_free(ns);
@@ -857,7 +857,7 @@ update_consensus_networkstatus_fetch_time(time_t now)
const networkstatus_vote_t *c = current_consensus;
time_t start;
long interval;
- if (options->DirPort) {
+ if (dirserver_mode(options)) {
start = c->valid_after + 120; /*XXXX020 make this a macro. */
/* XXXX020 too much magic. */
interval = (c->fresh_until - c->valid_after) / 2;
@@ -895,7 +895,7 @@ update_networkstatus_downloads(time_t now)
or_options_t *options = get_options();
if (should_delay_dir_fetches(options))
return;
- if (options->DirPort)
+ if (dirserver_mode(options))
update_networkstatus_cache_downloads(now);
else
update_networkstatus_client_downloads(now);
@@ -1019,7 +1019,7 @@ networkstatus_set_current_consensus(const char *consensus, int from_cache,
write_str_to_file(filename, consensus, 0);
}
- if (get_options()->DirPort)
+ if (dirserver_mode(get_options()))
dirserv_set_cached_networkstatus_v3(consensus, c->valid_after);
return 0;
@@ -1317,7 +1317,7 @@ routerstatus_list_update_from_networkstatus(time_t now)
other_digest != conflict) {
if (!warned) {
char *d;
- int should_warn = options->DirPort && authdir_mode(options);
+ int should_warn = authdir_mode(options);
char fp1[HEX_DIGEST_LEN+1];
char fp2[HEX_DIGEST_LEN+1];
base16_encode(fp1, sizeof(fp1), other_digest, DIGEST_LEN);
diff --git a/src/or/or.h b/src/or/or.h
index a2016a1203..25d3ace56f 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3413,6 +3413,7 @@ int authdir_mode_tests_reachability(or_options_t *options);
int authdir_mode_bridge(or_options_t *options);
int authdir_mode_any_nonbridge(or_options_t *options);
int clique_mode(or_options_t *options);
+int dirserver_mode(or_options_t *options);
int server_mode(or_options_t *options);
int advertised_server_mode(void);
int proxy_mode(or_options_t *options);
diff --git a/src/or/router.c b/src/or/router.c
index 073d2e17da..78a158a587 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -854,6 +854,14 @@ server_mode(or_options_t *options)
return (options->ORPort != 0 || options->ORListenAddress);
}
+/** Return true iff we are trying to be a directory server */
+int
+dirserver_mode(or_options_t *options)
+{
+ if (options->ClientOnly) return 0;
+ return options->DirPort != 0;
+}
+
/** Remember if we've advertised ourselves to the dirservers. */
static int server_is_advertised=0;
@@ -879,7 +887,10 @@ set_server_advertised(int s)
int
proxy_mode(or_options_t *options)
{
- return (options->SocksPort != 0 || options->SocksListenAddress);
+ return (options->SocksPort != 0 || options->SocksListenAddress ||
+ options->TransPort != 0 || options->TransListenAddress ||
+ options->NatdPort != 0 || options->NatdListenAddress ||
+ options->DNSPort != 0 || options->DNSListenAddress);
}
/** Decide if we're a publishable server. We are a publishable server if:
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index cf654aeaf8..ea78a2a101 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -2196,6 +2196,8 @@ extrainfo_insert(routerlist_t *rl, extrainfo_t *ei)
return r;
}
+#define should_cache_old_descriptors() dirserver_mode(get_options())
+
/** If we're a directory cache and routerlist rl doesn't have
* a copy of router ri yet, add it to the list of old (not
* recommended but still served) descriptors. Else free it. */
@@ -2209,7 +2211,7 @@ routerlist_insert_old(routerlist_t *rl, routerinfo_t *ri)
}
tor_assert(ri->routerlist_index == -1);
- if (get_options()->DirPort &&
+ if (should_cache_old_descriptors() &&
ri->purpose == ROUTER_PURPOSE_GENERAL &&
!sdmap_get(rl->desc_digest_map,
ri->cache_info.signed_descriptor_digest)) {
@@ -2254,7 +2256,7 @@ routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old)
router_dir_info_changed();
tor_assert(ri_tmp == ri);
- if (make_old && get_options()->DirPort &&
+ if (make_old && should_cache_old_descriptors() &&
ri->purpose == ROUTER_PURPOSE_GENERAL) {
signed_descriptor_t *sd;
sd = signed_descriptor_from_routerinfo(ri);
@@ -2379,7 +2381,7 @@ routerlist_replace(routerlist_t *rl, routerinfo_t *ri_old,
&ri_new->cache_info);
}
- if (get_options()->DirPort &&
+ if (should_cache_old_descriptors() &&
ri_old->purpose == ROUTER_PURPOSE_GENERAL) {
signed_descriptor_t *sd = signed_descriptor_from_routerinfo(ri_old);
smartlist_add(rl->old_routers, sd);
@@ -2566,7 +2568,7 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
*msg = "Router descriptor is not referenced by any network-status.";
/* Only journal this desc if we'll be serving it. */
- if (!from_cache && get_options()->DirPort)
+ if (!from_cache && should_cache_old_descriptors())
signed_desc_append_to_journal(&router->cache_info,
router_get_store(routerlist, router),
router->purpose);
@@ -2596,7 +2598,7 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
log_debug(LD_DIR, "Skipping not-new descriptor for router '%s'",
router->nickname);
/* Only journal this desc if we'll be serving it. */
- if (!from_cache && get_options()->DirPort)
+ if (!from_cache && should_cache_old_descriptors())
signed_desc_append_to_journal(&router->cache_info,
router_get_store(routerlist, router),
router->purpose);
@@ -3568,7 +3570,7 @@ update_router_descriptor_client_downloads(time_t now)
or_options_t *options = get_options();
const smartlist_t *networkstatus_list = networkstatus_get_v2_list();
- if (options->DirPort) {
+ if (dirserver_mode(options)) {
log_warn(LD_BUG,
"Called router_descriptor_client_downloads() on a dir mirror?");
}
@@ -3599,7 +3601,7 @@ launch_router_descriptor_downloads(smartlist_t *downloadable, time_t now)
or_options_t *options = get_options();
n_downloadable = smartlist_len(downloadable);
- if (!options->DirPort) {
+ if (!dirserver_mode(options)) {
if (n_downloadable >= MAX_DL_TO_DELAY) {
log_debug(LD_DIR,
"There are enough downloadable routerdescs to launch requests.");
@@ -3663,7 +3665,7 @@ update_router_descriptor_cache_downloads(time_t now)
or_options_t *options = get_options();
const smartlist_t *networkstatus_list = networkstatus_get_v2_list();
- if (!options->DirPort) {
+ if (! dirserver_mode(options)) {
log_warn(LD_BUG, "Called update_router_descriptor_cache_downloads() "
"on a non-dir-mirror?");
}
@@ -3800,9 +3802,10 @@ update_consensus_router_descriptor_downloads(time_t now)
digestmap_t *map = NULL;
smartlist_t *downloadable = smartlist_create();
int authdir = authdir_mode(options);
+ int dirserver = dirserver_mode(options);
networkstatus_vote_t *consensus = networkstatus_get_latest_consensus();
- if (!options->DirPort) {
+ if (!dirserver) {
if (rep_hist_circbuilding_dormant(now))
return;
}
@@ -3819,7 +3822,7 @@ update_consensus_router_descriptor_downloads(time_t now)
continue; /* We have it already. */
if (authdir && dirserv_would_reject_router(rs))
continue; /* We would throw it out immediately. */
- if (!options->DirPort && !client_would_use_router(rs, now, options))
+ if (!dirserver && !client_would_use_router(rs, now, options))
continue; /* We would never use it ourself. */
if (digestmap_get(map, rs->descriptor_digest))
continue; /* We have an in-progress download. */
@@ -3839,7 +3842,7 @@ update_router_descriptor_downloads(time_t now)
or_options_t *options = get_options();
if (should_delay_dir_fetches(options))
return;
- if (options->DirPort) {
+ if (dirserver_mode(options)) {
update_router_descriptor_cache_downloads(now);
update_consensus_router_descriptor_downloads(now); /*XXXX020 clients too*/
} else {
@@ -3888,12 +3891,12 @@ update_extrainfo_downloads(time_t now)
smartlist_add(wanted, ri->cache_info.extra_info_digest);
}
});
- if (options->DirPort) {
+ if (dirserver_mode(options)) {
SMARTLIST_FOREACH(rl->old_routers, signed_descriptor_t *, sd, {
if (should_download_extrainfo(sd, rl, pending, now)) {
smartlist_add(wanted, sd->extra_info_digest);
}
- });
+ });
}
digestmap_free(pending, NULL);
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index ed8fbe384a..a5264c1bd0 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -670,7 +670,7 @@ router_parse_directory(const char *str)
/* Now that we know the signature is okay, and we have a
* publication time, cache the directory. */
- if (get_options()->DirPort && !authdir_mode_v1(get_options()))
+ if (dirserver_mode(get_options()) && !authdir_mode_v1(get_options()))
dirserv_set_cached_directory(str, published_on, 0);
r = 0;