aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-08-26 19:31:51 +0000
committerNick Mathewson <nickm@torproject.org>2005-08-26 19:31:51 +0000
commit7f78be16595e2a164acbb66e4e0f2e1bfb2603fa (patch)
treedb2c7d69ffba49f7d60fc89366fa4b15b3678fd4
parent43488472ec120dcf5bd1c5e33009a36e08d2b9e3 (diff)
downloadtor-7f78be16595e2a164acbb66e4e0f2e1bfb2603fa.tar
tor-7f78be16595e2a164acbb66e4e0f2e1bfb2603fa.tar.gz
Clean up the "add myself as a trusted dirserver" code.
svn:r4849
-rw-r--r--src/or/router.c2
-rw-r--r--src/or/routerlist.c15
2 files changed, 8 insertions, 9 deletions
diff --git a/src/or/router.c b/src/or/router.c
index 0d4350027..ed00241d2 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -368,7 +368,7 @@ init_keys(void)
/* 6b. [authdirserver only] add own key to approved directories. */
crypto_pk_get_digest(get_identity_key(), digest);
if (!router_digest_is_trusted_dir(digest)) {
- add_trusted_dir_server(options->Address, (uint16_t)options->DirPort, digest);
+ add_trusted_dir_server(NULL, (uint16_t)options->DirPort, digest);
}
/* 7. [authdirserver only] load old directory, if it's there */
tor_snprintf(keydir,sizeof(keydir),"%s/cached-directory", datadir);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 95a2a471f..802784688 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1452,17 +1452,19 @@ router_update_status_from_smartlist(routerinfo_t *router,
}
/** Add to the list of authorized directory servers one at
- * <b>address</b>:<b>port</b>, with identity key <b>digest</b>. */
+ * <b>address</b>:<b>port</b>, with identity key <b>digest</b>. If
+ * <b>address</b> is NULL, add ourself. */
void
add_trusted_dir_server(const char *address, uint16_t port, const char *digest)
{
trusted_dir_server_t *ent;
uint32_t a;
+ char *hostname = NULL;
if (!trusted_dir_servers)
trusted_dir_servers = smartlist_create();
- if (!address) { /* need to guess */
- if (resolve_my_address(get_options(), &a, NULL) < 0) {
+ if (!address) { /* The address is us; we should guess. */
+ if (resolve_my_address(get_options(), &a, &hostname) < 0) {
log_fn(LOG_WARN, "Couldn't find a suitable address. Returning.");
return;
}
@@ -1472,15 +1474,12 @@ add_trusted_dir_server(const char *address, uint16_t port, const char *digest)
address);
return;
}
+ hostname = tor_strdup(address);
a = ntohl(a);
}
ent = tor_malloc(sizeof(trusted_dir_server_t));
- if (address) {
- ent->address = tor_strdup(address);
- } else {
- ent->address = tor_dup_addr(a);
- }
+ ent->address = hostname;
ent->addr = a;
ent->dir_port = port;
ent->is_running = 1;