Lines Matching full:cache
2 * SSL session cache implementation
35 void mbedtls_ssl_cache_init(mbedtls_ssl_cache_context *cache) in mbedtls_ssl_cache_init() argument
37 memset(cache, 0, sizeof(mbedtls_ssl_cache_context)); in mbedtls_ssl_cache_init()
39 cache->timeout = MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT; in mbedtls_ssl_cache_init()
40 cache->max_entries = MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES; in mbedtls_ssl_cache_init()
43 mbedtls_mutex_init(&cache->mutex); in mbedtls_ssl_cache_init()
48 static int ssl_cache_find_entry(mbedtls_ssl_cache_context *cache, in ssl_cache_find_entry() argument
59 for (cur = cache->chain; cur != NULL; cur = cur->next) { in ssl_cache_find_entry()
61 if (cache->timeout != 0 && in ssl_cache_find_entry()
62 (int) (t - cur->timestamp) > cache->timeout) { in ssl_cache_find_entry()
91 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data; in mbedtls_ssl_cache_get() local
95 if ((ret = mbedtls_mutex_lock(&cache->mutex)) != 0) { in mbedtls_ssl_cache_get()
100 ret = ssl_cache_find_entry(cache, session_id, session_id_len, &entry); in mbedtls_ssl_cache_get()
116 if (mbedtls_mutex_unlock(&cache->mutex) != 0) { in mbedtls_ssl_cache_get()
124 /* zeroize a cache entry */
142 static int ssl_cache_pick_writing_slot(mbedtls_ssl_cache_context *cache, in ssl_cache_pick_writing_slot() argument
159 * If not, `count` will hold the size of the session cache in ssl_cache_pick_writing_slot()
164 for (cur = cache->chain; cur != NULL; cur = cur->next) { in ssl_cache_pick_writing_slot()
173 /* Check 2: Is there an outdated entry in the cache? in ssl_cache_pick_writing_slot()
181 for (cur = cache->chain; cur != NULL; cur = cur->next) { in ssl_cache_pick_writing_slot()
182 if (cache->timeout != 0 && in ssl_cache_pick_writing_slot()
183 (int) (t - cur->timestamp) > cache->timeout) { in ssl_cache_pick_writing_slot()
194 /* Check 3: Is there free space in the cache? */ in ssl_cache_pick_writing_slot()
196 if (count < cache->max_entries) { in ssl_cache_pick_writing_slot()
205 cache->chain = cur; in ssl_cache_pick_writing_slot()
213 /* Last resort: The cache is full and doesn't contain any outdated in ssl_cache_pick_writing_slot()
215 * (if present) or cache-order. */ in ssl_cache_pick_writing_slot()
219 /* This should only happen on an ill-configured cache in ssl_cache_pick_writing_slot()
225 if (cache->chain == NULL) { in ssl_cache_pick_writing_slot()
229 old = cache->chain; in ssl_cache_pick_writing_slot()
230 cache->chain = old->next; in ssl_cache_pick_writing_slot()
263 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data; in mbedtls_ssl_cache_set() local
270 if ((ret = mbedtls_mutex_lock(&cache->mutex)) != 0) { in mbedtls_ssl_cache_set()
275 ret = ssl_cache_pick_writing_slot(cache, in mbedtls_ssl_cache_set()
320 if (mbedtls_mutex_unlock(&cache->mutex) != 0) { in mbedtls_ssl_cache_set()
339 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data; in mbedtls_ssl_cache_remove() local
344 if ((ret = mbedtls_mutex_lock(&cache->mutex)) != 0) { in mbedtls_ssl_cache_remove()
349 ret = ssl_cache_find_entry(cache, session_id, session_id_len, &entry); in mbedtls_ssl_cache_remove()
357 if (entry == cache->chain) { in mbedtls_ssl_cache_remove()
358 cache->chain = entry->next; in mbedtls_ssl_cache_remove()
361 for (prev = cache->chain; prev->next != NULL; prev = prev->next) { in mbedtls_ssl_cache_remove()
375 if (mbedtls_mutex_unlock(&cache->mutex) != 0) { in mbedtls_ssl_cache_remove()
384 void mbedtls_ssl_cache_set_timeout(mbedtls_ssl_cache_context *cache, int timeout) in mbedtls_ssl_cache_set_timeout() argument
390 cache->timeout = timeout; in mbedtls_ssl_cache_set_timeout()
394 void mbedtls_ssl_cache_set_max_entries(mbedtls_ssl_cache_context *cache, int max) in mbedtls_ssl_cache_set_max_entries() argument
400 cache->max_entries = max; in mbedtls_ssl_cache_set_max_entries()
403 void mbedtls_ssl_cache_free(mbedtls_ssl_cache_context *cache) in mbedtls_ssl_cache_free() argument
407 cur = cache->chain; in mbedtls_ssl_cache_free()
418 mbedtls_mutex_free(&cache->mutex); in mbedtls_ssl_cache_free()
420 cache->chain = NULL; in mbedtls_ssl_cache_free()