Lines Matching defs:cache

2  *  SSL session cache implementation
24 void mbedtls_ssl_cache_init(mbedtls_ssl_cache_context *cache)
26 memset(cache, 0, sizeof(mbedtls_ssl_cache_context));
28 cache->timeout = MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT;
29 cache->max_entries = MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES;
32 mbedtls_mutex_init(&cache->mutex);
37 static int ssl_cache_find_entry(mbedtls_ssl_cache_context *cache,
48 for (cur = cache->chain; cur != NULL; cur = cur->next) {
50 if (cache->timeout != 0 &&
51 (int) (t - cur->timestamp) > cache->timeout) {
80 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
84 if ((ret = mbedtls_mutex_lock(&cache->mutex)) != 0) {
89 ret = ssl_cache_find_entry(cache, session_id, session_id_len, &entry);
105 if (mbedtls_mutex_unlock(&cache->mutex) != 0) {
113 /* zeroize a cache entry */
130 static int ssl_cache_pick_writing_slot(mbedtls_ssl_cache_context *cache,
147 * If not, `count` will hold the size of the session cache
152 for (cur = cache->chain; cur != NULL; cur = cur->next) {
161 /* Check 2: Is there an outdated entry in the cache?
169 for (cur = cache->chain; cur != NULL; cur = cur->next) {
170 if (cache->timeout != 0 &&
171 (int) (t - cur->timestamp) > cache->timeout) {
182 /* Check 3: Is there free space in the cache? */
184 if (count < cache->max_entries) {
193 cache->chain = cur;
201 /* Last resort: The cache is full and doesn't contain any outdated
203 * (if present) or cache-order. */
207 /* This should only happen on an ill-configured cache
213 if (cache->chain == NULL) {
218 old = cache->chain;
219 cache->chain = old->next;
252 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
259 if ((ret = mbedtls_mutex_lock(&cache->mutex)) != 0) {
264 ret = ssl_cache_pick_writing_slot(cache,
308 if (mbedtls_mutex_unlock(&cache->mutex) != 0) {
326 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
331 if ((ret = mbedtls_mutex_lock(&cache->mutex)) != 0) {
336 ret = ssl_cache_find_entry(cache, session_id, session_id_len, &entry);
344 if (entry == cache->chain) {
345 cache->chain = entry->next;
348 for (prev = cache->chain; prev->next != NULL; prev = prev->next) {
362 if (mbedtls_mutex_unlock(&cache->mutex) != 0) {
371 void mbedtls_ssl_cache_set_timeout(mbedtls_ssl_cache_context *cache, int timeout)
377 cache->timeout = timeout;
381 void mbedtls_ssl_cache_set_max_entries(mbedtls_ssl_cache_context *cache, int max)
387 cache->max_entries = max;
390 void mbedtls_ssl_cache_free(mbedtls_ssl_cache_context *cache)
394 cur = cache->chain;
405 mbedtls_mutex_free(&cache->mutex);
407 cache->chain = NULL;