summaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-12-08 01:50:02 +0000
committerNick Mathewson <nickm@torproject.org>2006-12-08 01:50:02 +0000
commit1567e13dc853bcba4b75789d25a318ada9f81fab (patch)
treeab83bdc661a806a3bcf28a7fa2bbdaac965643d9 /src/or/control.c
parent566543a4f87b41ead10155964884e1b42992e3c1 (diff)
downloadtor-1567e13dc853bcba4b75789d25a318ada9f81fab.tar.gz
tor-1567e13dc853bcba4b75789d25a318ada9f81fab.zip
r11475@Kushana: nickm | 2006-12-07 20:49:21 -0500
Make GETINFO dir/status/... work even when we are not a directory. Needs a little cleanup. Closes bug 263. svn:r9051
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 9470e49e0d..e07b81b1f6 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1449,6 +1449,7 @@ list_getinfo_options(void)
"desc/name/* Server descriptor by nickname.\n"
"desc/all-recent Latest server descriptor for every router.\n"
"dir/server/* Fetch server descriptors -- see dir-spec.txt.\n"
+ "dir/status/* Fetch networkstatus documents -- see dir-spec.txt.\n"
"entry-guards Which nodes will we use as entry guards?\n"
"events/names What events the controller can ask for.\n"
"exit-policy/default Default lines appended to config->ExitPolicy.\n"
@@ -1708,24 +1709,44 @@ handle_getinfo_helper(control_connection_t *control_conn,
tor_free(url);
smartlist_free(descs);
} else if (!strcmpstart(question, "dir/status/")) {
- smartlist_t *status_list;
size_t len;
char *cp;
- if (!get_options()->DirPort) {
- log_warn(LD_CONTROL, "getinfo dir/status/ requires an open dirport.");
- return -1;
+ if (get_options()->DirPort) {
+ smartlist_t *status_list = smartlist_create();
+ dirserv_get_networkstatus_v2(status_list,
+ question+strlen("dir/status/"));
+ SMARTLIST_FOREACH(status_list, cached_dir_t *, d, len += d->dir_len);
+ len = 0;
+ cp = *answer = tor_malloc(len+1);
+ SMARTLIST_FOREACH(status_list, cached_dir_t *, d, {
+ memcpy(cp, d->dir, d->dir_len);
+ cp += d->dir_len;
+ });
+ *cp = '\0';
+ smartlist_free(status_list);
+ } else {
+ smartlist_t *fp_list = smartlist_create();
+ smartlist_t *status_list = smartlist_create();
+ size_t fn_len = strlen(get_options()->DataDirectory)+HEX_DIGEST_LEN+32;
+ char *fn = tor_malloc(fn_len+1);
+ char hex_id[HEX_DIGEST_LEN+1];
+ dirserv_get_networkstatus_v2_fingerprints(
+ fp_list, question+strlen("dir/status/"));
+ SMARTLIST_FOREACH(fp_list, const char *, fp, {
+ char *s;
+ base16_encode(hex_id, sizeof(hex_id), fp, DIGEST_LEN);
+ tor_snprintf(fn, fn_len, "%s/cached-status/%s",
+ get_options()->DataDirectory, hex_id);
+ s = read_file_to_str(fn, 0, NULL);
+ if (s)
+ smartlist_add(status_list, s);
+ });
+ SMARTLIST_FOREACH(fp_list, char *, fp, tor_free(fp));
+ smartlist_free(fp_list);
+ *answer = smartlist_join_strings(status_list, "", 0, NULL);
+ SMARTLIST_FOREACH(status_list, char *, s, tor_free(s));
+ smartlist_free(status_list);
}
- status_list = smartlist_create();
- dirserv_get_networkstatus_v2(status_list,
- question+strlen("dir/status/"));
- len = 0;
- SMARTLIST_FOREACH(status_list, cached_dir_t *, d, len += d->dir_len);
- cp = *answer = tor_malloc(len+1);
- SMARTLIST_FOREACH(status_list, cached_dir_t *, d, {
- memcpy(cp, d->dir, d->dir_len);
- cp += d->dir_len;
- });
- *cp = '\0';
} else if (!strcmpstart(question, "exit-policy/")) {
return policies_getinfo_helper(question, answer);
}