[glib-networking/mcatanzaro/handshake-thread-name] Some functions are missing handshake_thread prefix
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/mcatanzaro/handshake-thread-name] Some functions are missing handshake_thread prefix
- Date: Fri, 5 Jul 2019 16:22:11 +0000 (UTC)
commit c30c8f8e5dad453b556476903b69330e5d5cd349
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Thu Jul 4 15:31:10 2019 -0500
Some functions are missing handshake_thread prefix
This handshake_thread naming convention is intended to mitigate the
danger of forgetting which thread a function is designed to be called
from. It only works if all functions called on the handshake thread are
annotated appropriately.
The FIXME in the buffer_application_data() function perfectly
illustrates why this is required: it's too easy to miss spots that
require mutexes without it. Although, it's also hard to reason about
when mutexes are required, and in this case I believe I was wrong.
After app_data_buf is written here on the handshake thread, the op_mutex
will be unlocked before it's read from. Fragile, yes, but I have some
plans to improve this in the futrue.
tls/base/gtlsconnection-base.c | 12 ++++----
tls/base/gtlsconnection-base.h | 15 +++++-----
tls/gnutls/gtlsconnection-gnutls.c | 58 ++++++++++++++++++------------------
tls/openssl/gtlsconnection-openssl.c | 54 ++++++++++++++++-----------------
4 files changed, 69 insertions(+), 70 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 5230152..0018fef 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -1333,7 +1333,7 @@ handshake_thread (GTask *task,
GTlsConnectionBaseStatus status;
if (priv->rehandshake_mode != G_TLS_REHANDSHAKE_UNSAFELY &&
- tls_class->safe_renegotiation_status (tls) != G_TLS_SAFE_RENEGOTIATION_SUPPORTED_BY_PEER)
+ tls_class->handshake_thread_safe_renegotiation_status (tls) !=
G_TLS_SAFE_RENEGOTIATION_SUPPORTED_BY_PEER)
{
g_task_return_new_error (task, G_TLS_ERROR, G_TLS_ERROR_MISC,
_("Peer does not support safe renegotiation"));
@@ -1348,7 +1348,7 @@ handshake_thread (GTask *task,
timeout = 1;
}
- status = tls_class->request_rehandshake (tls, timeout, cancellable, &error);
+ status = tls_class->handshake_thread_request_rehandshake (tls, timeout, cancellable, &error);
if (status != G_TLS_CONNECTION_BASE_OK)
{
g_task_return_error (task, error);
@@ -2459,14 +2459,12 @@ g_tls_connection_base_request_certificate (GTlsConnectionBase *tls,
}
void
-g_tls_connection_base_buffer_application_data (GTlsConnectionBase *tls,
- guint8 *data,
- gsize length)
+g_tls_connection_base_handshake_thread_buffer_application_data (GTlsConnectionBase *tls,
+ guint8 *data,
+ gsize length)
{
GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
- /* FIXME: Called from handshake thread, needs a mutex! */
-
if (!priv->app_data_buf)
priv->app_data_buf = g_byte_array_new ();
diff --git a/tls/base/gtlsconnection-base.h b/tls/base/gtlsconnection-base.h
index 98632ad..b7e094b 100644
--- a/tls/base/gtlsconnection-base.h
+++ b/tls/base/gtlsconnection-base.h
@@ -58,13 +58,15 @@ struct _GTlsConnectionBaseClass
{
GTlsConnectionClass parent_class;
- GTlsConnectionBaseStatus (*request_rehandshake) (GTlsConnectionBase *tls,
+ void (*prepare_handshake) (GTlsConnectionBase *tls,
+ gchar **advertised_protocols);
+ GTlsSafeRenegotiationStatus (*handshake_thread_safe_renegotiation_status)
+ (GTlsConnectionBase *tls);
+ GTlsConnectionBaseStatus (*handshake_thread_request_rehandshake)
+ (GTlsConnectionBase *tls,
gint64 timeout,
GCancellable *cancellable,
GError **error);
-
- void (*prepare_handshake) (GTlsConnectionBase *tls,
- gchar **advertised_protocols);
GTlsConnectionBaseStatus (*handshake_thread_handshake) (GTlsConnectionBase *tls,
gint64 timeout,
GCancellable *cancellable,
@@ -122,8 +124,6 @@ struct _GTlsConnectionBaseClass
gint64 timeout,
GCancellable *cancellable,
GError **error);
-
- GTlsSafeRenegotiationStatus (*safe_renegotiation_status) (GTlsConnectionBase *tls);
};
gboolean g_tls_connection_base_handshake_thread_verify_certificate
@@ -193,7 +193,8 @@ gboolean g_tls_connection_base_ever_handshaked (GTlsCon
gboolean g_tls_connection_base_request_certificate (GTlsConnectionBase *tls,
GError **error);
-void g_tls_connection_base_buffer_application_data (GTlsConnectionBase *tls,
+void g_tls_connection_base_handshake_thread_buffer_application_data
+ (GTlsConnectionBase *tls,
guint8 *data,
gsize length);
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index 0990006..4e883a7 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -757,11 +757,21 @@ g_tls_connection_gnutls_pull_timeout_func (gnutls_transport_ptr_t transport_data
return 0;
}
+static GTlsSafeRenegotiationStatus
+g_tls_connection_gnutls_handshake_thread_safe_renegotiation_status (GTlsConnectionBase *tls)
+{
+ GTlsConnectionGnutls *gnutls = G_TLS_CONNECTION_GNUTLS (tls);
+ GTlsConnectionGnutlsPrivate *priv = g_tls_connection_gnutls_get_instance_private (gnutls);
+
+ return gnutls_safe_renegotiation_status (priv->session) ? G_TLS_SAFE_RENEGOTIATION_SUPPORTED_BY_PEER
+ : G_TLS_SAFE_RENEGOTIATION_UNSUPPORTED;
+}
+
static GTlsConnectionBaseStatus
-g_tls_connection_gnutls_request_rehandshake (GTlsConnectionBase *tls,
- gint64 timeout,
- GCancellable *cancellable,
- GError **error)
+g_tls_connection_gnutls_handshake_thread_request_rehandshake (GTlsConnectionBase *tls,
+ gint64 timeout,
+ GCancellable *cancellable,
+ GError **error)
{
GTlsConnectionGnutls *gnutls = G_TLS_CONNECTION_GNUTLS (tls);
GTlsConnectionGnutlsPrivate *priv = g_tls_connection_gnutls_get_instance_private (gnutls);
@@ -875,7 +885,7 @@ g_tls_connection_gnutls_handshake_thread_handshake (GTlsConnectionBase *tls,
ret = gnutls_record_recv (priv->session, buf, sizeof (buf));
if (ret > -1)
{
- g_tls_connection_base_buffer_application_data (tls, buf, ret);
+ g_tls_connection_base_handshake_thread_buffer_application_data (tls, buf, ret);
ret = GNUTLS_E_AGAIN;
}
}
@@ -1096,36 +1106,26 @@ g_tls_connection_gnutls_close (GTlsConnectionBase *tls,
return status;
}
-static GTlsSafeRenegotiationStatus
-g_tls_connection_gnutls_safe_renegotiation_status (GTlsConnectionBase *tls)
-{
- GTlsConnectionGnutls *gnutls = G_TLS_CONNECTION_GNUTLS (tls);
- GTlsConnectionGnutlsPrivate *priv = g_tls_connection_gnutls_get_instance_private (gnutls);
-
- return gnutls_safe_renegotiation_status (priv->session) ? G_TLS_SAFE_RENEGOTIATION_SUPPORTED_BY_PEER
- : G_TLS_SAFE_RENEGOTIATION_UNSUPPORTED;
-}
-
static void
g_tls_connection_gnutls_class_init (GTlsConnectionGnutlsClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GTlsConnectionBaseClass *base_class = G_TLS_CONNECTION_BASE_CLASS (klass);
- gobject_class->finalize = g_tls_connection_gnutls_finalize;
-
- base_class->request_rehandshake = g_tls_connection_gnutls_request_rehandshake;
- base_class->prepare_handshake = g_tls_connection_gnutls_prepare_handshake;
- base_class->handshake_thread_handshake = g_tls_connection_gnutls_handshake_thread_handshake;
- base_class->retrieve_peer_certificate = g_tls_connection_gnutls_retrieve_peer_certificate;
- base_class->complete_handshake = g_tls_connection_gnutls_complete_handshake;
- base_class->is_session_resumed = g_tls_connection_gnutls_is_session_resumed;
- base_class->read_fn = g_tls_connection_gnutls_read;
- base_class->read_message_fn = g_tls_connection_gnutls_read_message;
- base_class->write_fn = g_tls_connection_gnutls_write;
- base_class->write_message_fn = g_tls_connection_gnutls_write_message;
- base_class->close_fn = g_tls_connection_gnutls_close;
- base_class->safe_renegotiation_status = g_tls_connection_gnutls_safe_renegotiation_status;
+ gobject_class->finalize = g_tls_connection_gnutls_finalize;
+
+ base_class->prepare_handshake = g_tls_connection_gnutls_prepare_handshake;
+ base_class->handshake_thread_safe_renegotiation_status =
g_tls_connection_gnutls_handshake_thread_safe_renegotiation_status;
+ base_class->handshake_thread_request_rehandshake =
g_tls_connection_gnutls_handshake_thread_request_rehandshake;
+ base_class->handshake_thread_handshake =
g_tls_connection_gnutls_handshake_thread_handshake;
+ base_class->retrieve_peer_certificate = g_tls_connection_gnutls_retrieve_peer_certificate;
+ base_class->complete_handshake = g_tls_connection_gnutls_complete_handshake;
+ base_class->is_session_resumed = g_tls_connection_gnutls_is_session_resumed;
+ base_class->read_fn = g_tls_connection_gnutls_read;
+ base_class->read_message_fn = g_tls_connection_gnutls_read_message;
+ base_class->write_fn = g_tls_connection_gnutls_write;
+ base_class->write_message_fn = g_tls_connection_gnutls_write_message;
+ base_class->close_fn = g_tls_connection_gnutls_close;
}
static void
diff --git a/tls/openssl/gtlsconnection-openssl.c b/tls/openssl/gtlsconnection-openssl.c
index 3745766..f07be5a 100644
--- a/tls/openssl/gtlsconnection-openssl.c
+++ b/tls/openssl/gtlsconnection-openssl.c
@@ -66,6 +66,18 @@ g_tls_connection_openssl_finalize (GObject *object)
G_OBJECT_CLASS (g_tls_connection_openssl_parent_class)->finalize (object);
}
+static GTlsSafeRenegotiationStatus
+g_tls_connection_openssl_handshake_thread_safe_renegotiation_status (GTlsConnectionBase *tls)
+{
+ GTlsConnectionOpenssl *openssl = G_TLS_CONNECTION_OPENSSL (tls);
+ SSL *ssl;
+
+ ssl = g_tls_connection_openssl_get_ssl (openssl);
+
+ return SSL_get_secure_renegotiation_support (ssl) ? G_TLS_SAFE_RENEGOTIATION_SUPPORTED_BY_PEER
+ : G_TLS_SAFE_RENEGOTIATION_UNSUPPORTED;
+}
+
static GTlsConnectionBaseStatus
end_openssl_io (GTlsConnectionOpenssl *openssl,
GIOCondition direction,
@@ -213,10 +225,10 @@ end_openssl_io (GTlsConnectionOpenssl *openssl,
} while (status == G_TLS_CONNECTION_BASE_TRY_AGAIN);
static GTlsConnectionBaseStatus
-g_tls_connection_openssl_request_rehandshake (GTlsConnectionBase *tls,
- gint64 timeout,
- GCancellable *cancellable,
- GError **error)
+g_tls_connection_openssl_handshake_thread_request_rehandshake (GTlsConnectionBase *tls,
+ gint64 timeout,
+ GCancellable *cancellable,
+ GError **error)
{
GTlsConnectionOpenssl *openssl;
GTlsConnectionBaseStatus status;
@@ -497,35 +509,23 @@ g_tls_connection_openssl_close (GTlsConnectionBase *tls,
return status;
}
-static GTlsSafeRenegotiationStatus
-g_tls_connection_openssl_safe_renegotiation_status (GTlsConnectionBase *tls)
-{
- GTlsConnectionOpenssl *openssl = G_TLS_CONNECTION_OPENSSL (tls);
- SSL *ssl;
-
- ssl = g_tls_connection_openssl_get_ssl (openssl);
-
- return SSL_get_secure_renegotiation_support (ssl) ? G_TLS_SAFE_RENEGOTIATION_SUPPORTED_BY_PEER
- : G_TLS_SAFE_RENEGOTIATION_UNSUPPORTED;
-}
-
static void
g_tls_connection_openssl_class_init (GTlsConnectionOpensslClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GTlsConnectionBaseClass *base_class = G_TLS_CONNECTION_BASE_CLASS (klass);
- object_class->finalize = g_tls_connection_openssl_finalize;
-
- base_class->request_rehandshake = g_tls_connection_openssl_request_rehandshake;
- base_class->handshake_thread_handshake = g_tls_connection_openssl_handshake_thread_handshake;
- base_class->retrieve_peer_certificate = g_tls_connection_openssl_retrieve_peer_certificate;
- base_class->push_io = g_tls_connection_openssl_push_io;
- base_class->pop_io = g_tls_connection_openssl_pop_io;
- base_class->read_fn = g_tls_connection_openssl_read;
- base_class->write_fn = g_tls_connection_openssl_write;
- base_class->close_fn = g_tls_connection_openssl_close;
- base_class->safe_renegotiation_status = g_tls_connection_openssl_safe_renegotiation_status;
+ object_class->finalize = g_tls_connection_openssl_finalize;
+
+ base_class->handshake_thread_safe_renegotiation_status =
g_tls_connection_openssl_handshake_thread_safe_renegotiation_status;
+ base_class->handshake_thread_request_rehandshake =
g_tls_connection_openssl_handshake_thread_request_rehandshake;
+ base_class->handshake_thread_handshake =
g_tls_connection_openssl_handshake_thread_handshake;
+ base_class->retrieve_peer_certificate =
g_tls_connection_openssl_retrieve_peer_certificate;
+ base_class->push_io = g_tls_connection_openssl_push_io;
+ base_class->pop_io = g_tls_connection_openssl_pop_io;
+ base_class->read_fn = g_tls_connection_openssl_read;
+ base_class->write_fn = g_tls_connection_openssl_write;
+ base_class->close_fn = g_tls_connection_openssl_close;
}
static int data_index = -1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]