aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-07-16 10:07:21 -0400
committerNick Mathewson <nickm@torproject.org>2020-07-16 10:08:15 -0400
commit47a48e2f5a384450679a544e7a1f26f378a26a78 (patch)
treea9848573bd201bca1017fd711f6388328dbe6f32 /src
parentb0d7b100886ef14a785f6ca1de968df9a884d0a7 (diff)
downloadtor-47a48e2f5a384450679a544e7a1f26f378a26a78.tar.gz
tor-47a48e2f5a384450679a544e7a1f26f378a26a78.zip
Define new CONST_TO_*_CONN() functions for const-to-const casts
These names are analogous to the CONST_TO_*_CIRC() functions we have for circuits. Part of #40046.
Diffstat (limited to 'src')
-rw-r--r--src/core/mainloop/connection.c12
-rw-r--r--src/core/mainloop/connection.h2
-rw-r--r--src/core/or/connection_edge.c36
-rw-r--r--src/core/or/connection_edge.h4
-rw-r--r--src/core/or/connection_or.c11
-rw-r--r--src/core/or/connection_or.h1
-rw-r--r--src/feature/control/control.c12
-rw-r--r--src/feature/control/control.h1
-rw-r--r--src/feature/dircommon/directory.c12
-rw-r--r--src/feature/dircommon/directory.h1
10 files changed, 92 insertions, 0 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 216aeb68d1..20e38ac44b 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -233,6 +233,18 @@ TO_LISTENER_CONN(connection_t *c)
return DOWNCAST(listener_connection_t, c);
}
+/**
+ * Cast a `const connection_t *` to a `const listener_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not a
+ * `listener_connection_t`.
+ **/
+const listener_connection_t *
+CONST_TO_LISTENER_CONN(const connection_t *c)
+{
+ return TO_LISTENER_CONN((connection_t *)c);
+}
+
size_t
connection_get_inbuf_len(connection_t *conn)
{
diff --git a/src/core/mainloop/connection.h b/src/core/mainloop/connection.h
index af45007676..ee3dce49f4 100644
--- a/src/core/mainloop/connection.h
+++ b/src/core/mainloop/connection.h
@@ -31,6 +31,8 @@ struct tor_addr_t;
struct or_options_t;
struct listener_connection_t *TO_LISTENER_CONN(struct connection_t *);
+const struct listener_connection_t *CONST_TO_LISTENER_CONN(
+ const struct connection_t *);
struct buf_t;
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
index 30cfb18f0f..ed27fb1b57 100644
--- a/src/core/or/connection_edge.c
+++ b/src/core/or/connection_edge.c
@@ -181,6 +181,18 @@ TO_EDGE_CONN(connection_t *c)
}
/**
+ * Cast a `const connection_t *` to a `const edge_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not an
+ * `edge_connection_t`.
+ **/
+const edge_connection_t *
+CONST_TO_EDGE_CONN(const connection_t *c)
+{
+ return TO_EDGE_CONN((connection_t *)c);
+}
+
+/**
* Cast a `connection_t *` to an `entry_connection_t *`.
*
* Exit with an assertion failure if the input is not an
@@ -194,6 +206,18 @@ TO_ENTRY_CONN(connection_t *c)
}
/**
+ * Cast a `const connection_t *` to a `const entry_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not an
+ * `entry_connection_t`.
+ **/
+const entry_connection_t *
+CONST_TO_ENTRY_CONN(const connection_t *c)
+{
+ return TO_ENTRY_CONN((connection_t*) c);
+}
+
+/**
* Cast an `edge_connection_t *` to an `entry_connection_t *`.
*
* Exit with an assertion failure if the input is not an
@@ -206,6 +230,18 @@ EDGE_TO_ENTRY_CONN(edge_connection_t *c)
return (entry_connection_t*) SUBTYPE_P(c, entry_connection_t, edge_);
}
+/**
+ * Cast a `const edge_connection_t *` to a `const entry_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not an
+ * `entry_connection_t`.
+ **/
+const entry_connection_t *
+CONST_EDGE_TO_ENTRY_CONN(const edge_connection_t *c)
+{
+ return EDGE_TO_ENTRY_CONN((edge_connection_t*)c);
+}
+
/** An AP stream has failed/finished. If it hasn't already sent back
* a socks reply, send one now (based on endreason). Also set
* has_sent_end to 1, and mark the conn.
diff --git a/src/core/or/connection_edge.h b/src/core/or/connection_edge.h
index 8c06af5664..9b2cbb8532 100644
--- a/src/core/or/connection_edge.h
+++ b/src/core/or/connection_edge.h
@@ -20,6 +20,10 @@ edge_connection_t *TO_EDGE_CONN(connection_t *);
entry_connection_t *TO_ENTRY_CONN(connection_t *);
entry_connection_t *EDGE_TO_ENTRY_CONN(edge_connection_t *);
+const edge_connection_t *CONST_TO_EDGE_CONN(const connection_t *);
+const entry_connection_t *CONST_TO_ENTRY_CONN(const connection_t *);
+const entry_connection_t *CONST_EDGE_TO_ENTRY_CONN(const edge_connection_t *);
+
#define EXIT_CONN_STATE_MIN_ 1
/** State for an exit connection: waiting for response from DNS farm. */
#define EXIT_CONN_STATE_RESOLVING 1
diff --git a/src/core/or/connection_or.c b/src/core/or/connection_or.c
index e6dc62a475..91dcbe695b 100644
--- a/src/core/or/connection_or.c
+++ b/src/core/or/connection_or.c
@@ -111,6 +111,17 @@ TO_OR_CONN(connection_t *c)
return DOWNCAST(or_connection_t, c);
}
+/**
+ * Cast a `const connection_t *` to a `const or_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not an `or_connnection_t`.
+ **/
+const or_connection_t *
+CONST_TO_OR_CONN(const connection_t *c)
+{
+ return TO_OR_CONN((connection_t *)c);
+}
+
/** Clear clear conn->identity_digest and update other data
* structures as appropriate.*/
void
diff --git a/src/core/or/connection_or.h b/src/core/or/connection_or.h
index e9ace56ab4..fe81b5c5e1 100644
--- a/src/core/or/connection_or.h
+++ b/src/core/or/connection_or.h
@@ -16,6 +16,7 @@ struct ed25519_public_key_t;
struct ed25519_keypair_t;
or_connection_t *TO_OR_CONN(connection_t *);
+const or_connection_t *CONST_TO_OR_CONN(const connection_t *);
#include "core/or/orconn_event.h"
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index b5d4c31525..ef707319a6 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -74,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/dircommon/directory.c b/src/feature/dircommon/directory.c
index bb9264eaf9..e92e6480af 100644
--- a/src/feature/dircommon/directory.c
+++ b/src/feature/dircommon/directory.c
@@ -92,6 +92,18 @@ TO_DIR_CONN(connection_t *c)
return DOWNCAST(dir_connection_t, c);
}
+/**
+ * Cast a `const connection_t *` to a `const dir_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not a
+ * `dir_connection_t`.
+ **/
+const dir_connection_t *
+CONST_TO_DIR_CONN(const connection_t *c)
+{
+ return TO_DIR_CONN((connection_t *)c);
+}
+
/** Return false if the directory purpose <b>dir_purpose</b>
* does not require an anonymous (three-hop) connection.
*
diff --git a/src/feature/dircommon/directory.h b/src/feature/dircommon/directory.h
index 0f26cdeff9..0aa2ff53ef 100644
--- a/src/feature/dircommon/directory.h
+++ b/src/feature/dircommon/directory.h
@@ -13,6 +13,7 @@
#define TOR_DIRECTORY_H
dir_connection_t *TO_DIR_CONN(connection_t *c);
+const dir_connection_t *CONST_TO_DIR_CONN(const connection_t *c);
#define DIR_CONN_STATE_MIN_ 1
/** State for connection to directory server: waiting for connect(). */