aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_cache.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-02-05 11:14:10 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-02-05 11:14:10 +0000
commit8c68fab395e3261e7e23e9f897a2ba8849b16ef1 (patch)
tree9fe034d272b4f5da65e2b0a5fedbce81d6149959 /src/testbed/gnunet-service-testbed_cache.c
parent477681a2f6cfab72414ca0d1d1134e6704b8bf57 (diff)
downloadgnunet-8c68fab395e3261e7e23e9f897a2ba8849b16ef1.tar.gz
gnunet-8c68fab395e3261e7e23e9f897a2ba8849b16ef1.zip
- expire cache entries (expiry set to 'forever' for now)
Diffstat (limited to 'src/testbed/gnunet-service-testbed_cache.c')
-rw-r--r--src/testbed/gnunet-service-testbed_cache.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/testbed/gnunet-service-testbed_cache.c b/src/testbed/gnunet-service-testbed_cache.c
index 46c7d4fce..601d10b0f 100644
--- a/src/testbed/gnunet-service-testbed_cache.c
+++ b/src/testbed/gnunet-service-testbed_cache.c
@@ -36,6 +36,13 @@
36 36
37 37
38/** 38/**
39 * Time to expire a cache entry
40 */
41#define CACHE_EXPIRY \
42 GNUNET_TIME_UNIT_FOREVER_REL //GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
43
44
45/**
39 * Type of cache-get requests 46 * Type of cache-get requests
40 */ 47 */
41enum CacheGetType 48enum CacheGetType
@@ -230,6 +237,12 @@ struct CacheEntry
230 GNUNET_SCHEDULER_TaskIdentifier notify_task; 237 GNUNET_SCHEDULER_TaskIdentifier notify_task;
231 238
232 /** 239 /**
240 * The task to expire this cache entry, free any handlers it has opened and
241 * mark their corresponding operations as done.
242 */
243 GNUNET_SCHEDULER_TaskIdentifier expire_task;
244
245 /**
233 * Number of operations this cache entry is being used 246 * Number of operations this cache entry is being used
234 */ 247 */
235 unsigned int demand; 248 unsigned int demand;
@@ -317,10 +330,16 @@ close_handles (struct CacheEntry *entry)
317 if (GNUNET_YES == entry->in_lru) 330 if (GNUNET_YES == entry->in_lru)
318 { 331 {
319 GNUNET_assert (0 < lru_cache_size); 332 GNUNET_assert (0 < lru_cache_size);
333 if (GNUNET_SCHEDULER_NO_TASK != entry->expire_task)
334 {
335 GNUNET_SCHEDULER_cancel (entry->expire_task);
336 entry->expire_task = GNUNET_SCHEDULER_NO_TASK;
337 }
320 GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry); 338 GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry);
321 lru_cache_size--; 339 lru_cache_size--;
322 entry->in_lru = GNUNET_NO; 340 entry->in_lru = GNUNET_NO;
323 } 341 }
342 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == entry->expire_task);
324 while (NULL != (ctxt = entry->nctxt_qhead)) 343 while (NULL != (ctxt = entry->nctxt_qhead))
325 { 344 {
326 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt); 345 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt);
@@ -348,6 +367,24 @@ close_handles (struct CacheEntry *entry)
348 367
349 368
350/** 369/**
370 * The task to expire this cache entry, free any handlers it has opened and
371 * mark their corresponding operations as done.
372 *
373 * @param cls the CacheEntry
374 * @param tc the scheduler task context
375 */
376static void
377expire_cache_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
378{
379 struct CacheEntry *entry = cls;
380
381 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->expire_task);
382 entry->expire_task = GNUNET_SCHEDULER_NO_TASK;
383 close_handles (entry);
384}
385
386
387/**
351 * Creates a new cache entry and then puts it into the cache's hashtable. 388 * Creates a new cache entry and then puts it into the cache's hashtable.
352 * 389 *
353 * @param key the hash code to use for inserting the newly created entry 390 * @param key the hash code to use for inserting the newly created entry
@@ -697,6 +734,11 @@ cache_get_handle (unsigned int peer_id, struct GSTCacheGetHandle *cgh,
697 { 734 {
698 GNUNET_assert (0 == entry->demand); 735 GNUNET_assert (0 == entry->demand);
699 GNUNET_assert (0 < lru_cache_size); 736 GNUNET_assert (0 < lru_cache_size);
737 if (GNUNET_SCHEDULER_NO_TASK != entry->expire_task)
738 {
739 GNUNET_SCHEDULER_cancel (entry->expire_task);
740 entry->expire_task = GNUNET_SCHEDULER_NO_TASK;
741 }
700 GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry); 742 GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry);
701 lru_cache_size--; 743 lru_cache_size--;
702 entry->in_lru = GNUNET_NO; 744 entry->in_lru = GNUNET_NO;
@@ -785,6 +827,7 @@ cache_clear_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
785 if (0 == entry->demand) 827 if (0 == entry->demand)
786 close_handles (entry); 828 close_handles (entry);
787 GNUNET_free_non_null (entry->hello); 829 GNUNET_free_non_null (entry->hello);
830 GNUNET_break (GNUNET_SCHEDULER_NO_TASK == entry->expire_task);
788 GNUNET_break (NULL == entry->transport_handle_); 831 GNUNET_break (NULL == entry->transport_handle_);
789 GNUNET_break (NULL == entry->transport_op_); 832 GNUNET_break (NULL == entry->transport_op_);
790 GNUNET_break (NULL == entry->core_handle); 833 GNUNET_break (NULL == entry->core_handle);
@@ -860,6 +903,8 @@ GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh)
860 GNUNET_free (cgh); 903 GNUNET_free (cgh);
861 if (0 == entry->demand) 904 if (0 == entry->demand)
862 { 905 {
906 entry->expire_task =
907 GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire_cache_entry, entry);
863 GNUNET_CONTAINER_DLL_insert_tail (lru_cache_head, lru_cache_tail, entry); 908 GNUNET_CONTAINER_DLL_insert_tail (lru_cache_head, lru_cache_tail, entry);
864 lru_cache_size++; 909 lru_cache_size++;
865 entry->in_lru = GNUNET_YES; 910 entry->in_lru = GNUNET_YES;