summaryrefslogtreecommitdiff
path: root/src/or/channeltls.c
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2012-10-09 14:16:51 -0700
committerAndrea Shepard <andrea@torproject.org>2012-10-09 23:19:53 -0700
commitbddfb9ffa85a0fe73545fb231a0847c4101758c1 (patch)
tree381d051786cadc514732cf93f73f52dbdb1cc003 /src/or/channeltls.c
parentf00b44ef8c82eb52fad19fd2218f485f1c5aceca (diff)
downloadtor-bddfb9ffa85a0fe73545fb231a0847c4101758c1.tar.gz
tor-bddfb9ffa85a0fe73545fb231a0847c4101758c1.zip
Add magic number for type-checking channel casts
Diffstat (limited to 'src/or/channeltls.c')
-rw-r--r--src/or/channeltls.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index 339663e00a..5d6a7a912f 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -102,8 +102,9 @@ channel_tls_connect(const tor_addr_t *addr, uint16_t port,
const char *id_digest)
{
channel_tls_t *tlschan = tor_malloc_zero(sizeof(*tlschan));
- channel_t *chan = TLS_CHAN_TO_BASE(tlschan);
+ channel_t *chan = &(tlschan->_base);
channel_init(chan);
+ chan->magic = TLS_CHAN_MAGIC;
chan->state = CHANNEL_STATE_OPENING;
chan->close = channel_tls_close_method;
chan->describe_transport = channel_tls_describe_transport_method;
@@ -233,12 +234,13 @@ channel_t *
channel_tls_handle_incoming(or_connection_t *orconn)
{
channel_tls_t *tlschan = tor_malloc_zero(sizeof(*tlschan));
- channel_t *chan = TLS_CHAN_TO_BASE(tlschan);
+ channel_t *chan = &(tlschan->_base);
tor_assert(orconn);
tor_assert(!(orconn->chan));
channel_init(chan);
+ chan->magic = TLS_CHAN_MAGIC;
chan->state = CHANNEL_STATE_OPENING;
chan->close = channel_tls_close_method;
chan->describe_transport = channel_tls_describe_transport_method;
@@ -267,6 +269,37 @@ channel_tls_handle_incoming(or_connection_t *orconn)
return chan;
}
+/*********
+ * Casts *
+ ********/
+
+/**
+ * Cast a channel_tls_t to a channel_t.
+ */
+
+channel_t *
+channel_tls_to_base(channel_tls_t *tlschan)
+{
+ if (!tlschan) return NULL;
+
+ return &(tlschan->_base);
+}
+
+/**
+ * Cast a channel_t to a channel_tls_t, with appropriate type-checking
+ * asserts.
+ */
+
+channel_tls_t *
+channel_tls_from_base(channel_t *chan)
+{
+ if (!chan) return NULL;
+
+ tor_assert(chan->magic == TLS_CHAN_MAGIC);
+
+ return (channel_tls_t *)(chan);
+}
+
/********************************************
* Method implementations for channel_tls_t *
*******************************************/