diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-07-16 10:07:21 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-07-16 10:08:15 -0400 |
commit | 47a48e2f5a384450679a544e7a1f26f378a26a78 (patch) | |
tree | a9848573bd201bca1017fd711f6388328dbe6f32 /src/core/or | |
parent | b0d7b100886ef14a785f6ca1de968df9a884d0a7 (diff) | |
download | tor-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/core/or')
-rw-r--r-- | src/core/or/connection_edge.c | 36 | ||||
-rw-r--r-- | src/core/or/connection_edge.h | 4 | ||||
-rw-r--r-- | src/core/or/connection_or.c | 11 | ||||
-rw-r--r-- | src/core/or/connection_or.h | 1 |
4 files changed, 52 insertions, 0 deletions
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" |