summaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c148
1 files changed, 99 insertions, 49 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 09cf833e37..af052f756c 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2017, The Tor Project, Inc. */
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -35,59 +35,77 @@
#define CONTROL_PRIVATE
-#include "or.h"
-#include "addressmap.h"
-#include "bridges.h"
-#include "buffers.h"
-#include "channel.h"
-#include "channeltls.h"
-#include "circuitbuild.h"
-#include "circuitlist.h"
-#include "circuitstats.h"
-#include "circuituse.h"
-#include "command.h"
-#include "compat_libevent.h"
-#include "config.h"
-#include "confparse.h"
-#include "connection.h"
-#include "connection_edge.h"
-#include "connection_or.h"
-#include "control.h"
-#include "crypto_rand.h"
-#include "crypto_util.h"
-#include "directory.h"
-#include "dirserv.h"
-#include "dnsserv.h"
-#include "entrynodes.h"
-#include "geoip.h"
-#include "hibernate.h"
-#include "hs_cache.h"
-#include "hs_common.h"
-#include "hs_control.h"
-#include "main.h"
-#include "microdesc.h"
-#include "networkstatus.h"
-#include "nodelist.h"
-#include "policies.h"
-#include "proto_control0.h"
-#include "proto_http.h"
-#include "reasons.h"
-#include "rendclient.h"
-#include "rendcommon.h"
-#include "rendservice.h"
-#include "rephist.h"
-#include "router.h"
-#include "routerlist.h"
-#include "routerparse.h"
-#include "shared_random_client.h"
+#include "or/or.h"
+#include "or/addressmap.h"
+#include "or/bridges.h"
+#include "lib/container/buffers.h"
+#include "or/channel.h"
+#include "or/channeltls.h"
+#include "or/circuitbuild.h"
+#include "or/circuitlist.h"
+#include "or/circuitstats.h"
+#include "or/circuituse.h"
+#include "or/command.h"
+#include "common/compat_libevent.h"
+#include "or/config.h"
+#include "or/confparse.h"
+#include "or/connection.h"
+#include "or/connection_edge.h"
+#include "or/connection_or.h"
+#include "or/control.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
+#include "or/directory.h"
+#include "or/dirserv.h"
+#include "or/dnsserv.h"
+#include "or/entrynodes.h"
+#include "or/geoip.h"
+#include "or/hibernate.h"
+#include "or/hs_cache.h"
+#include "or/hs_common.h"
+#include "or/hs_control.h"
+#include "or/main.h"
+#include "or/microdesc.h"
+#include "or/networkstatus.h"
+#include "or/nodelist.h"
+#include "or/policies.h"
+#include "or/proto_control0.h"
+#include "or/proto_http.h"
+#include "or/reasons.h"
+#include "or/rendclient.h"
+#include "or/rendcommon.h"
+#include "or/rendservice.h"
+#include "or/rephist.h"
+#include "or/router.h"
+#include "or/routerlist.h"
+#include "or/routerparse.h"
+#include "or/shared_random_client.h"
+
+#include "or/cached_dir_st.h"
+#include "or/control_connection_st.h"
+#include "or/cpath_build_state_st.h"
+#include "or/entry_connection_st.h"
+#include "or/extrainfo_st.h"
+#include "or/networkstatus_st.h"
+#include "or/node_st.h"
+#include "or/or_connection_st.h"
+#include "or/or_circuit_st.h"
+#include "or/origin_circuit_st.h"
+#include "or/microdesc_st.h"
+#include "or/rend_authorized_client_st.h"
+#include "or/rend_encoded_v2_service_descriptor_st.h"
+#include "or/rend_service_descriptor_st.h"
+#include "or/routerinfo_st.h"
+#include "or/routerlist_st.h"
+#include "or/socks_request_st.h"
#ifndef _WIN32
#include <pwd.h>
#include <sys/resource.h>
#endif
-#include "crypto_s2k.h"
-#include "procmon.h"
+#include "lib/crypt_ops/crypto_s2k.h"
+#include "common/procmon.h"
/** Yield true iff <b>s</b> is the state of a control_connection_t that has
* finished authentication and is accepting commands. */
@@ -226,6 +244,15 @@ static void flush_queued_events_cb(mainloop_event_t *event, void *arg);
static char * download_status_to_string(const download_status_t *dl);
static void control_get_bytes_rw_last_sec(uint64_t *r, uint64_t *w);
+/** Convert a connection_t* to an control_connection_t*; assert if the cast is
+ * invalid. */
+control_connection_t *
+TO_CONTROL_CONN(connection_t *c)
+{
+ tor_assert(c->magic == CONTROL_CONNECTION_MAGIC);
+ return DOWNCAST(control_connection_t, c);
+}
+
/** Given a control event code for a message event, return the corresponding
* log severity. */
static inline int
@@ -2207,6 +2234,27 @@ getinfo_helper_dir(control_connection_t *control_conn,
return -1;
}
}
+ } else if (!strcmp(question, "md/all")) {
+ const smartlist_t *nodes = nodelist_get_list();
+ tor_assert(nodes);
+
+ if (smartlist_len(nodes) == 0) {
+ *answer = tor_strdup("");
+ return 0;
+ }
+
+ smartlist_t *microdescs = smartlist_new();
+
+ SMARTLIST_FOREACH_BEGIN(nodes, node_t *, n) {
+ if (n->md && n->md->body) {
+ char *copy = tor_strndup(n->md->body, n->md->bodylen);
+ smartlist_add(microdescs, copy);
+ }
+ } SMARTLIST_FOREACH_END(n);
+
+ *answer = smartlist_join_strings(microdescs, "", 0, NULL);
+ SMARTLIST_FOREACH(microdescs, char *, md, tor_free(md));
+ smartlist_free(microdescs);
} else if (!strcmpstart(question, "md/id/")) {
const node_t *node = node_get_by_hex_id(question+strlen("md/id/"), 0);
const microdesc_t *md = NULL;
@@ -3241,6 +3289,7 @@ static const getinfo_item_t getinfo_items[] = {
ITEM("desc/download-enabled", dir,
"Do we try to download router descriptors?"),
ITEM("desc/all-recent-extrainfo-hack", dir, NULL), /* Hack. */
+ ITEM("md/all", dir, "All known microdescriptors."),
PREFIX("md/id/", dir, "Microdescriptors by ID"),
PREFIX("md/name/", dir, "Microdescriptors by name"),
ITEM("md/download-enabled", dir,
@@ -3400,6 +3449,7 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
SMARTLIST_FOREACH_BEGIN(questions, const char *, q) {
const char *errmsg = NULL;
+
if (handle_getinfo_helper(conn, q, &ans, &errmsg) < 0) {
if (!errmsg)
errmsg = "Internal error";
@@ -4629,7 +4679,7 @@ handle_control_add_onion(control_connection_t *conn,
static const char *max_s_prefix = "MaxStreams=";
static const char *auth_prefix = "ClientAuth=";
- const char *arg = smartlist_get(args, i);
+ const char *arg = smartlist_get(args, (int)i);
if (!strcasecmpstart(arg, port_prefix)) {
/* "Port=VIRTPORT[,TARGET]". */
const char *port_str = arg + strlen(port_prefix);