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.
This commit is contained in:
Nick Mathewson 2020-07-16 10:07:21 -04:00
parent b0d7b10088
commit 47a48e2f5a
10 changed files with 92 additions and 0 deletions

View File

@ -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)
{

View File

@ -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;

View File

@ -180,6 +180,18 @@ TO_EDGE_CONN(connection_t *c)
return DOWNCAST(edge_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 *`.
*
@ -193,6 +205,18 @@ TO_ENTRY_CONN(connection_t *c)
return (entry_connection_t*) SUBTYPE_P(c, entry_connection_t, edge_.base_);
}
/**
* 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 *`.
*
@ -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.

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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>

View File

@ -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. */

View File

@ -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.
*

View File

@ -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(). */