summaryrefslogtreecommitdiff
path: root/src/feature/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/feature/control')
-rw-r--r--src/feature/control/control.c20
-rw-r--r--src/feature/control/control.h1
-rw-r--r--src/feature/control/control_bootstrap.c4
-rw-r--r--src/feature/control/control_getinfo.c7
4 files changed, 25 insertions, 7 deletions
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index ee1026359d..ef707319a6 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -61,8 +61,12 @@
#include <sys/stat.h>
#endif
-/** Convert a connection_t* to an control_connection_t*; assert if the cast is
- * invalid. */
+/**
+ * Cast a `connection_t *` to a `control_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not a
+ * `control_connection_t`.
+ **/
control_connection_t *
TO_CONTROL_CONN(connection_t *c)
{
@@ -70,6 +74,18 @@ TO_CONTROL_CONN(connection_t *c)
return DOWNCAST(control_connection_t, c);
}
+/**
+ * Cast a `const connection_t *` to a `const control_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not a
+ * `control_connection_t`.
+ **/
+const control_connection_t *
+CONST_TO_CONTROL_CONN(const connection_t *c)
+{
+ return TO_CONTROL_CONN((connection_t*)c);
+}
+
/** Create and add a new controller connection on <b>sock</b>. If
* <b>CC_LOCAL_FD_IS_OWNER</b> is set in <b>flags</b>, this Tor process should
* exit when the connection closes. If <b>CC_LOCAL_FD_IS_AUTHENTICATED</b>
diff --git a/src/feature/control/control.h b/src/feature/control/control.h
index 7e72b2736b..f884286ec7 100644
--- a/src/feature/control/control.h
+++ b/src/feature/control/control.h
@@ -13,6 +13,7 @@
#define TOR_CONTROL_H
control_connection_t *TO_CONTROL_CONN(connection_t *);
+const control_connection_t *CONST_TO_CONTROL_CONN(const connection_t *);
#define CONTROL_CONN_STATE_MIN_ 1
/** State for a control connection: Authenticated and accepting v1 commands. */
diff --git a/src/feature/control/control_bootstrap.c b/src/feature/control/control_bootstrap.c
index fee7612ba2..d4f2adde81 100644
--- a/src/feature/control/control_bootstrap.c
+++ b/src/feature/control/control_bootstrap.c
@@ -274,7 +274,7 @@ control_event_bootstrap_problem(const char *warn, const char *reason,
const char *recommendation = "ignore";
int severity;
char *or_id = NULL, *hostaddr = NULL;
- or_connection_t *or_conn = NULL;
+ const or_connection_t *or_conn = NULL;
/* bootstrap_percent must not be in "undefined" state here. */
tor_assert(status >= 0);
@@ -301,7 +301,7 @@ control_event_bootstrap_problem(const char *warn, const char *reason,
if (conn && conn->type == CONN_TYPE_OR) {
/* XXX TO_OR_CONN can't deal with const */
- or_conn = TO_OR_CONN((connection_t *)conn);
+ or_conn = CONST_TO_OR_CONN(conn);
or_id = tor_strdup(hex_str(or_conn->identity_digest, DIGEST_LEN));
} else {
or_id = tor_strdup("?");
diff --git a/src/feature/control/control_getinfo.c b/src/feature/control/control_getinfo.c
index daf71f04c9..3e4feadded 100644
--- a/src/feature/control/control_getinfo.c
+++ b/src/feature/control/control_getinfo.c
@@ -132,12 +132,13 @@ getinfo_helper_misc(control_connection_t *conn, const char *question,
} else if (!strcmp(question, "features/names")) {
*answer = tor_strdup("VERBOSE_NAMES EXTENDED_EVENTS");
} else if (!strcmp(question, "address")) {
- uint32_t addr;
- if (router_pick_published_address(get_options(), &addr, 0) < 0) {
+ tor_addr_t addr;
+ if (!relay_find_addr_to_publish(get_options(), AF_INET,
+ RELAY_FIND_ADDR_CACHE_ONLY, &addr)) {
*errmsg = "Address unknown";
return -1;
}
- *answer = tor_dup_ip(addr);
+ *answer = tor_addr_to_str_dup(&addr);
tor_assert_nonfatal(*answer);
} else if (!strcmp(question, "traffic/read")) {
tor_asprintf(answer, "%"PRIu64, (get_bytes_read()));