Add a new type entry_connection_t for entry connections

No fields have moved there yet; for now, it's just a placeholder type.
This commit is contained in:
Nick Mathewson 2011-07-20 12:38:13 -04:00
parent a2bd0397ff
commit 33e6a3d750
5 changed files with 58 additions and 9 deletions

View File

@ -243,16 +243,26 @@ or_connection_new(int socket_family)
return or_conn;
}
/** Allocate and return a new entry_connection_t, initialized as by
* connection_init(). */
entry_connection_t *
entry_connection_new(int type, int socket_family)
{
entry_connection_t *entry_conn = tor_malloc_zero(sizeof(entry_connection_t));
tor_assert(type == CONN_TYPE_AP);
connection_init(time(NULL), ENTRY_TO_CONN(entry_conn), type, socket_family);
entry_conn->_edge.socks_request = socks_request_new();
return entry_conn;
}
/** Allocate and return a new edge_connection_t, initialized as by
* connection_init(). */
edge_connection_t *
edge_connection_new(int type, int socket_family)
{
edge_connection_t *edge_conn = tor_malloc_zero(sizeof(edge_connection_t));
tor_assert(type == CONN_TYPE_EXIT || type == CONN_TYPE_AP);
tor_assert(type == CONN_TYPE_EXIT);
connection_init(time(NULL), TO_CONN(edge_conn), type, socket_family);
if (type == CONN_TYPE_AP)
edge_conn->socks_request = socks_request_new();
return edge_conn;
}
@ -291,9 +301,11 @@ connection_new(int type, int socket_family)
return TO_CONN(or_connection_new(socket_family));
case CONN_TYPE_EXIT:
case CONN_TYPE_AP:
return TO_CONN(edge_connection_new(type, socket_family));
case CONN_TYPE_AP:
return ENTRY_TO_CONN(entry_connection_new(type, socket_family));
case CONN_TYPE_DIR:
return TO_CONN(dir_connection_new(socket_family));
@ -334,6 +346,8 @@ connection_init(time_t now, connection_t *conn, int type, int socket_family)
conn->magic = OR_CONNECTION_MAGIC;
break;
case CONN_TYPE_EXIT:
conn->magic = ENTRY_CONNECTION_MAGIC;
break;
case CONN_TYPE_AP:
conn->magic = EDGE_CONNECTION_MAGIC;
break;
@ -402,6 +416,10 @@ _connection_free(connection_t *conn)
memlen = sizeof(or_connection_t);
break;
case CONN_TYPE_AP:
tor_assert(conn->magic == ENTRY_CONNECTION_MAGIC);
mem = TO_ENTRY_CONN(conn);
memlen = sizeof(entry_connection_t);
break;
case CONN_TYPE_EXIT:
tor_assert(conn->magic == EDGE_CONNECTION_MAGIC);
mem = TO_EDGE_CONN(conn);
@ -3930,6 +3948,8 @@ assert_connection_ok(connection_t *conn, time_t now)
tor_assert(conn->magic == OR_CONNECTION_MAGIC);
break;
case CONN_TYPE_AP:
tor_assert(conn->magic == ENTRY_CONNECTION_MAGIC);
break;
case CONN_TYPE_EXIT:
tor_assert(conn->magic == EDGE_CONNECTION_MAGIC);
break;

View File

@ -21,6 +21,7 @@ const char *conn_state_to_string(int type, int state);
dir_connection_t *dir_connection_new(int socket_family);
or_connection_t *or_connection_new(int socket_family);
edge_connection_t *edge_connection_new(int type, int socket_family);
entry_connection_t *entry_connection_new(int type, int socket_family);
control_connection_t *control_connection_new(int socket_family);
listener_connection_t *listener_connection_new(int type, int socket_family);
connection_t *connection_new(int type, int socket_family);

View File

@ -2553,13 +2553,15 @@ connection_ap_make_link(connection_t *partner,
int session_group, int isolation_flags,
int use_begindir, int want_onehop)
{
entry_connection_t *entry_conn;
edge_connection_t *conn;
log_info(LD_APP,"Making internal %s tunnel to %s:%d ...",
want_onehop ? "direct" : "anonymized",
safe_str_client(address), port);
conn = edge_connection_new(CONN_TYPE_AP, AF_INET);
entry_conn = entry_connection_new(CONN_TYPE_AP, AF_INET);
conn = ENTRY_TO_EDGE_CONN(entry_conn);
conn->_base.linked = 1; /* so that we can add it safely below. */
/* populate conn->socks_request */

View File

@ -32,6 +32,7 @@ static void
evdns_server_callback(struct evdns_server_request *req, void *data_)
{
const listener_connection_t *listener = data_;
entry_connection_t *entry_conn;
edge_connection_t *conn;
int i = 0;
struct evdns_server_question *q = NULL;
@ -115,7 +116,8 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
}
/* Make a new dummy AP connection, and attach the request to it. */
conn = edge_connection_new(CONN_TYPE_AP, AF_INET);
entry_conn = entry_connection_new(CONN_TYPE_AP, AF_INET);
conn = ENTRY_TO_EDGE_CONN(entry_conn);
conn->_base.state = AP_CONN_STATE_RESOLVE_WAIT;
conn->is_dns_request = 1;
@ -168,11 +170,13 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
int
dnsserv_launch_request(const char *name, int reverse)
{
entry_connection_t *entry_conn;
edge_connection_t *conn;
char *q_name;
/* Make a new dummy AP connection, and attach the request to it. */
conn = edge_connection_new(CONN_TYPE_AP, AF_INET);
entry_conn = entry_connection_new(CONN_TYPE_AP, AF_INET);
conn = ENTRY_TO_EDGE_CONN(entry_conn);
conn->_base.state = AP_CONN_STATE_RESOLVE_WAIT;
if (reverse)

View File

@ -941,6 +941,7 @@ typedef struct socks_request_t socks_request_t;
#define BASE_CONNECTION_MAGIC 0x7C3C304Eu
#define OR_CONNECTION_MAGIC 0x7D31FF03u
#define EDGE_CONNECTION_MAGIC 0xF0374013u
#define ENTRY_CONNECTION_MAGIC 0xbb4a5703
#define DIR_CONNECTION_MAGIC 0x9988ffeeu
#define CONTROL_CONNECTION_MAGIC 0x8abc765du
#define LISTENER_CONNECTION_MAGIC 0x1a1ac741u
@ -1173,7 +1174,7 @@ typedef struct or_connection_t {
* identity digest as this one. */
} or_connection_t;
/** Subtype of connection_t for an "edge connection" -- that is, a socks (ap)
/** Subtype of connection_t for an "edge connection" -- that is, an entry (ap)
* connection, or an exit. */
typedef struct edge_connection_t {
connection_t _base;
@ -1289,6 +1290,13 @@ typedef struct edge_connection_t {
} edge_connection_t;
/** Subtype of edge_connection_t for an "entry connection" -- that is, a SOCKS
* connection, a DNS request, a TransPort connection or a NATD connection */
typedef struct entry_connection_t {
edge_connection_t _edge;
} entry_connection_t;
/** Subtype of connection_t for an "directory connection" -- that is, an HTTP
* connection to retrieve or serve directory material. */
typedef struct dir_connection_t {
@ -1360,6 +1368,11 @@ typedef struct control_connection_t {
/** Helper macro: Given a pointer to to._base, of type from*, return &to. */
#define DOWNCAST(to, ptr) ((to*)SUBTYPE_P(ptr, to, _base))
/** Cast a entry_connection_t subtype pointer to a edge_connection_t **/
#define ENTRY_TO_EDGE_CONN(c) (&(((c))->_edge))
/** Cast a entry_connection_t subtype pointer to a connection_t **/
#define ENTRY_TO_CONN(c) (TO_CONN(ENTRY_TO_EDGE_CONN(c)))
/** Convert a connection_t* to an or_connection_t*; assert if the cast is
* invalid. */
static or_connection_t *TO_OR_CONN(connection_t *);
@ -1369,6 +1382,9 @@ static dir_connection_t *TO_DIR_CONN(connection_t *);
/** Convert a connection_t* to an edge_connection_t*; assert if the cast is
* invalid. */
static edge_connection_t *TO_EDGE_CONN(connection_t *);
/** Convert a connection_t* to an entry_connection_t*; assert if the cast is
* invalid. */
static entry_connection_t *TO_ENTRY_CONN(connection_t *);
/** Convert a connection_t* to an control_connection_t*; assert if the cast is
* invalid. */
static control_connection_t *TO_CONTROL_CONN(connection_t *);
@ -1388,9 +1404,15 @@ static INLINE dir_connection_t *TO_DIR_CONN(connection_t *c)
}
static INLINE edge_connection_t *TO_EDGE_CONN(connection_t *c)
{
tor_assert(c->magic == EDGE_CONNECTION_MAGIC);
tor_assert(c->magic == EDGE_CONNECTION_MAGIC ||
c->magic == ENTRY_CONNECTION_MAGIC);
return DOWNCAST(edge_connection_t, c);
}
static INLINE entry_connection_t *TO_ENTRY_CONN(connection_t *c)
{
tor_assert(c->magic == ENTRY_CONNECTION_MAGIC);
return (entry_connection_t*) SUBTYPE_P(c, entry_connection_t, _edge._base);
}
static INLINE control_connection_t *TO_CONTROL_CONN(connection_t *c)
{
tor_assert(c->magic == CONTROL_CONNECTION_MAGIC);