Turn all "Is DirPort nonzero? Because if it is, we must be a directory" logic into calls to dirserver_mode().
svn:r11817
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
}
} 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);
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();
{
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;
{
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,
* (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() &&
}
/* 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);
tor_free(fn);
}
- if (get_options()->DirPort)
+ if (dirserver_mode(get_options()))
dirserv_set_cached_networkstatus_v2(s,
ns->identity_digest,
ns->published_on);
!(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;
}
}
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. */
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);
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;
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);
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;
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);
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);
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;
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:
return r;
}
+#define should_cache_old_descriptors() dirserver_mode(get_options())
+
/** If we're a directory cache and routerlist <b>rl</b> doesn't have
* a copy of router <b>ri</b> yet, add it to the list of old (not
* recommended but still served) descriptors. Else free it. */
}
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)) {
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);
&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);
*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);
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);
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?");
}
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.");
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?");
}
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;
}
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. */
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 {
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);
/* 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;