[glib-networking/mcatanzaro/session-resumption: 1/2] gnutls: use monotonic time for the session cache
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/mcatanzaro/session-resumption: 1/2] gnutls: use monotonic time for the session cache
- Date: Mon, 18 Nov 2019 20:57:19 +0000 (UTC)
commit 5da2ce7baa780411760b766610f82fcda1c56558
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Mon Nov 18 11:24:50 2019 -0600
gnutls: use monotonic time for the session cache
There's no reason for this to be based on real time. E.g. doesn't make
sense for cached time to change if system clock changes.
tls/gnutls/gtlsbackend-gnutls.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/tls/gnutls/gtlsbackend-gnutls.c b/tls/gnutls/gtlsbackend-gnutls.c
index d0e5eaa..f8890e5 100644
--- a/tls/gnutls/gtlsbackend-gnutls.c
+++ b/tls/gnutls/gtlsbackend-gnutls.c
@@ -175,12 +175,12 @@ G_LOCK_DEFINE_STATIC (session_cache_lock);
GHashTable *client_session_cache, *server_session_cache;
#define SESSION_CACHE_MAX_SIZE 50
-#define SESSION_CACHE_MAX_AGE (60 * 60) /* one hour */
+#define SESSION_CACHE_MAX_AGE (60ll * 60ll * G_USEC_PER_SEC) /* one hour */
typedef struct {
GBytes *session_id;
GBytes *session_data;
- time_t last_used;
+ gint64 last_used;
} GTlsBackendGnutlsCacheData;
static void
@@ -189,7 +189,7 @@ session_cache_cleanup (GHashTable *cache)
GHashTableIter iter;
gpointer key, value;
GTlsBackendGnutlsCacheData *cache_data;
- time_t expired = time (NULL) - SESSION_CACHE_MAX_AGE;
+ gint64 expired = g_get_monotonic_time () - SESSION_CACHE_MAX_AGE;
g_hash_table_iter_init (&iter, cache);
while (g_hash_table_iter_next (&iter, &key, &value))
@@ -256,7 +256,7 @@ g_tls_backend_gnutls_store_session (unsigned int type,
g_hash_table_insert (cache, cache_data->session_id, cache_data);
}
- cache_data->last_used = time (NULL);
+ cache_data->last_used = g_get_monotonic_time ();
G_UNLOCK (session_cache_lock);
}
@@ -292,7 +292,7 @@ g_tls_backend_gnutls_lookup_session (unsigned int type,
cache_data = g_hash_table_lookup (cache, session_id);
if (cache_data)
{
- cache_data->last_used = time (NULL);
+ cache_data->last_used = g_get_monotonic_time ();
session_data = g_bytes_ref (cache_data->session_data);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]