aboutsummaryrefslogtreecommitdiff
path: root/src/lockmanager/gnunet-service-lockmanager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lockmanager/gnunet-service-lockmanager.c')
-rw-r--r--src/lockmanager/gnunet-service-lockmanager.c75
1 files changed, 70 insertions, 5 deletions
diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c
index 3642ca030..974c14be1 100644
--- a/src/lockmanager/gnunet-service-lockmanager.c
+++ b/src/lockmanager/gnunet-service-lockmanager.c
@@ -217,7 +217,6 @@ find_lock (const char *domain_name,
217 void *value) 217 void *value)
218 { 218 {
219 matched_lock = value; 219 matched_lock = value;
220
221 if ((lock_num == matched_lock->lock_num) 220 if ((lock_num == matched_lock->lock_num)
222 && (0 == strcmp (domain_name, matched_lock->domain_name))) 221 && (0 == strcmp (domain_name, matched_lock->domain_name)))
223 return GNUNET_NO; 222 return GNUNET_NO;
@@ -266,7 +265,7 @@ add_lock (const char *domain_name,
266 265
267 266
268/** 267/**
269 * Removes a lock from the lock map 268 * Removes a lock from the lock map. The WaitList of the lock should be empty
270 * 269 *
271 * @param lock the lock to remove 270 * @param lock the lock to remove
272 */ 271 */
@@ -274,7 +273,8 @@ static void
274remove_lock (struct Lock *lock) 273remove_lock (struct Lock *lock)
275{ 274{
276 struct GNUNET_HashCode key; 275 struct GNUNET_HashCode key;
277 276
277 GNUNET_assert (NULL == lock->wl_head);
278 get_key (lock->domain_name, 278 get_key (lock->domain_name,
279 lock->lock_num, 279 lock->lock_num,
280 &key); 280 &key);
@@ -468,13 +468,14 @@ cl_add_client (struct GNUNET_SERVER_Client *client)
468 468
469 469
470/** 470/**
471 * Delete the given client from the client list 471 * Delete the given client from the client list. The LockList should be empty
472 * 472 *
473 * @param cl_entry the client list entry to delete 473 * @param cl_entry the client list entry to delete
474 */ 474 */
475static void 475static void
476cl_remove_client (struct ClientList *cl_entry) 476cl_remove_client (struct ClientList *cl_entry)
477{ 477{
478 GNUNET_assert (NULL == cl_entry->ll_head);
478 LOG (GNUNET_ERROR_TYPE_DEBUG, 479 LOG (GNUNET_ERROR_TYPE_DEBUG,
479 "Removing a client from the client list\n"); 480 "Removing a client from the client list\n");
480 GNUNET_SERVER_client_drop (cl_entry->client); 481 GNUNET_SERVER_client_drop (cl_entry->client);
@@ -635,7 +636,6 @@ process_lock_release (struct Lock *lock)
635 LOG (GNUNET_ERROR_TYPE_DEBUG, 636 LOG (GNUNET_ERROR_TYPE_DEBUG,
636 "Giving lock to a client from wait list\n"); 637 "Giving lock to a client from wait list\n");
637 lock->cl_entry = wl_entry->cl_entry; 638 lock->cl_entry = wl_entry->cl_entry;
638 cl_ll_add_lock (wl_entry->cl_entry, lock);
639 lock_wl_remove(lock, wl_entry); 639 lock_wl_remove(lock, wl_entry);
640 send_success_msg (lock->cl_entry->client, 640 send_success_msg (lock->cl_entry->client,
641 lock->domain_name, 641 lock->domain_name,
@@ -751,6 +751,68 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
751 751
752 752
753/** 753/**
754 * Hashmap Iterator to delete lock entries in hash map
755 *
756 * @param cls NULL
757 * @param key current key code
758 * @param value value in the hash map
759 * @return GNUNET_YES if we should continue to
760 * iterate,
761 * GNUNET_NO if not.
762 */
763static int
764lock_delete_iterator (void *cls,
765 const GNUNET_HashCode * key,
766 void *value)
767{
768 struct Lock *lock = value;
769
770 GNUNET_assert (NULL != lock);
771 while (NULL != lock->wl_head)
772 {
773 lock_wl_remove (lock, lock->wl_head);
774 }
775 GNUNET_assert (GNUNET_YES ==
776 GNUNET_CONTAINER_multihashmap_remove(lock_map,
777 key,
778 lock));
779 GNUNET_free (lock->domain_name);
780 GNUNET_free (lock);
781 return GNUNET_YES;
782}
783
784
785/**
786 * Task to clean up and shutdown nicely
787 *
788 * @param
789 * @return
790 */
791static void
792shutdown_task (void *cls,
793 const struct GNUNET_SCHEDULER_TaskContext *tc)
794{
795 LOG (GNUNET_ERROR_TYPE_DEBUG,
796 "Shutting down lock manager\n");
797 /* Clean the global ClientList */
798 while (NULL != cl_head)
799 {
800 while (NULL != cl_head->ll_head) /* Clear the LockList */
801 {
802 cl_ll_remove_lock (cl_head, cl_head->ll_head);
803 }
804 cl_remove_client (cl_head);
805 }
806 /* Clean the global hash table */
807 GNUNET_CONTAINER_multihashmap_iterate (lock_map,
808 &lock_delete_iterator,
809 NULL);
810 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (lock_map));
811 GNUNET_CONTAINER_multihashmap_destroy (lock_map);
812}
813
814
815/**
754 * Lock manager setup 816 * Lock manager setup
755 * 817 *
756 * @param cls closure 818 * @param cls closure
@@ -774,6 +836,9 @@ lockmanager_run (void *cls,
774 &client_disconnect_cb, 836 &client_disconnect_cb,
775 NULL); 837 NULL);
776 lock_map = GNUNET_CONTAINER_multihashmap_create (30); 838 lock_map = GNUNET_CONTAINER_multihashmap_create (30);
839 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
840 &shutdown_task,
841 NULL);
777} 842}
778 843
779 844