From 42c6c351a1e6a8f568e53b34ad95d108c7db34c8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 6 Oct 2013 12:19:35 +0000 Subject: -more dead code elimination / house cleaning --- src/Makefile.am | 1 - src/include/gnunet_chat_service.h | 253 ------ src/lockmanager/Makefile.am | 84 -- src/lockmanager/gnunet-service-lockmanager.c | 847 --------------------- src/lockmanager/lockmanager.conf.in | 12 - src/lockmanager/lockmanager.h | 71 -- src/lockmanager/lockmanager_api.c | 729 ------------------ src/lockmanager/test_lockmanager_api.c | 202 ----- src/lockmanager/test_lockmanager_api.conf | 64 -- .../test_lockmanager_api_acquireretry.c | 224 ------ src/lockmanager/test_lockmanager_api_lockrelease.c | 223 ------ src/lockmanager/test_lockmanager_api_servercrash.c | 246 ------ src/revocation/gnunet-service-revocation.c | 2 +- 13 files changed, 1 insertion(+), 2957 deletions(-) delete mode 100644 src/include/gnunet_chat_service.h delete mode 100644 src/lockmanager/Makefile.am delete mode 100644 src/lockmanager/gnunet-service-lockmanager.c delete mode 100644 src/lockmanager/lockmanager.conf.in delete mode 100644 src/lockmanager/lockmanager.h delete mode 100644 src/lockmanager/lockmanager_api.c delete mode 100644 src/lockmanager/test_lockmanager_api.c delete mode 100644 src/lockmanager/test_lockmanager_api.conf delete mode 100644 src/lockmanager/test_lockmanager_api_acquireretry.c delete mode 100644 src/lockmanager/test_lockmanager_api_lockrelease.c delete mode 100644 src/lockmanager/test_lockmanager_api_servercrash.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index a43f1b865..11c964d53 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -66,7 +66,6 @@ SUBDIRS = \ topology \ regex \ mesh \ - lockmanager \ dns \ identity \ set \ diff --git a/src/include/gnunet_chat_service.h b/src/include/gnunet_chat_service.h deleted file mode 100644 index d539197a0..000000000 --- a/src/include/gnunet_chat_service.h +++ /dev/null @@ -1,253 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2009, 2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file include/gnunet_chat_service.h - * @brief API for chatting via GNUnet - * @author Christian Grothoff - * @author Nathan Evans - * @author Vitaly Minko - */ - -#ifndef GNUNET_CHAT_SERVICE_H -#define GNUNET_CHAT_SERVICE_H - -#include "gnunet_util_lib.h" - -#ifdef __cplusplus -extern "C" -{ -#if 0 /* keep Emacsens' auto-indent happy */ -} -#endif -#endif - - -#define GNUNET_CHAT_VERSION 0x00000003 -#define MAX_MESSAGE_LENGTH (32 * 1024) - -/** - * Options for messaging. Compatible options can be OR'ed together. - */ -enum GNUNET_CHAT_MsgOptions -{ - /** - * No special options. - */ - GNUNET_CHAT_MSG_OPTION_NONE = 0, - - /** - * Encrypt the message so that only the receiver can decrypt it. - */ - GNUNET_CHAT_MSG_PRIVATE = 1, - - /** - * Hide the identity of the sender. - */ - GNUNET_CHAT_MSG_ANONYMOUS = 2, - - /** - * Sign the content, authenticating the sender (using the provided private - * key, which may represent a pseudonym). - */ - GNUNET_CHAT_MSG_AUTHENTICATED = 4, - - /** - * Require signed acknowledgment before completing delivery (and of course, - * only acknowledge if delivery is guaranteed). - */ - GNUNET_CHAT_MSG_ACKNOWLEDGED = 8, - - /** - * Authenticate for the receiver, but ensure that receiver cannot prove - * authenticity to third parties later. (not yet implemented) - */ - GNUNET_CHAT_MSG_OFF_THE_RECORD = 16, - -}; - -/** - * Handle for a (joined) chat room. - */ -struct GNUNET_CHAT_Room; - -/** - * Callback used for notification that we have joined the room. - * - * @param cls closure - * @return GNUNET_OK - */ -typedef int (*GNUNET_CHAT_JoinCallback) (void *cls); - -/** - * Callback used for notification about incoming messages. - * - * @param cls closure - * @param room in which room was the message received? - * @param sender what is the ID of the sender? (maybe NULL) - * @param member_info information about the joining member - * @param message the message text - * @param timestamp when was the message sent? - * @param options options for the message - * @return GNUNET_OK to accept the message now, GNUNET_NO to - * accept (but user is away), GNUNET_SYSERR to signal denied delivery - */ -typedef int (*GNUNET_CHAT_MessageCallback) (void *cls, - struct GNUNET_CHAT_Room * room, - const struct GNUNET_HashCode * sender, - const struct - GNUNET_CONTAINER_MetaData * - member_info, const char *message, - struct GNUNET_TIME_Absolute - timestamp, - enum GNUNET_CHAT_MsgOptions - options); - -/** - * Callback used for notification that another room member has joined or left. - * - * @param cls closure - * @param member_info will be non-null if the member is joining, NULL if he is - * leaving - * @param member_id hash of public key of the user (for unique identification) - * @param options what types of messages is this member willing to receive? - * @return GNUNET_OK - */ -typedef int (*GNUNET_CHAT_MemberListCallback) (void *cls, - const struct - GNUNET_CONTAINER_MetaData * - member_info, - const struct - GNUNET_CRYPTO_RsaPublicKey - * member_id, - enum GNUNET_CHAT_MsgOptions - options); - -/** - * Callback used for message delivery confirmations. - * - * @param cls closure - * @param room in which room was the message received? - * @param orig_seq_number sequence number of the original message - * @param timestamp when was the message received? - * @param receiver who is confirming the receipt? - * @return GNUNET_OK to continue, GNUNET_SYSERR to refuse processing further - * confirmations from anyone for this message - */ -typedef int (*GNUNET_CHAT_MessageConfirmation) (void *cls, - struct GNUNET_CHAT_Room * room, - uint32_t orig_seq_number, - struct GNUNET_TIME_Absolute - timestamp, - const struct GNUNET_HashCode * - receiver); - -/** - * Join a chat room. - * - * @param cfg configuration - * @param nick_name nickname of the user joining (used to - * determine which public key to use); - * the nickname should probably also - * be used in the member_info (as "EXTRACTOR_TITLE") - * @param member_info information about the joining member - * @param room_name name of the room - * @param msg_options message options of the joining user - * @param joinCallback which function to call when we've joined the room - * @param join_cls argument to callback - * @param messageCallback which function to call if a message has - * been received? - * @param message_cls argument to callback - * @param memberCallback which function to call for join/leave notifications - * @param member_cls argument to callback - * @param confirmationCallback which function to call for confirmations - * (maybe NULL) - * @param confirmation_cls argument to callback - * @param me member ID (pseudonym) - * @return NULL on error - */ -struct GNUNET_CHAT_Room * -GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *nick_name, - struct GNUNET_CONTAINER_MetaData *member_info, - const char *room_name, - enum GNUNET_CHAT_MsgOptions msg_options, - GNUNET_CHAT_JoinCallback joinCallback, void *join_cls, - GNUNET_CHAT_MessageCallback messageCallback, - void *message_cls, - GNUNET_CHAT_MemberListCallback memberCallback, - void *member_cls, - GNUNET_CHAT_MessageConfirmation confirmationCallback, - void *confirmation_cls, struct GNUNET_HashCode * me); - -/** - * Send a message. - * - * @param room handle for the chat room - * @param message message to be sent - * @param options options for the message - * @param receiver use NULL to send to everyone in the room - * @param sequence_number where to write the sequence id of the message - */ -void -GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, const char *message, - enum GNUNET_CHAT_MsgOptions options, - const struct GNUNET_CRYPTO_RsaPublicKey - *receiver, uint32_t * sequence_number); - - -/** - * Leave a chat room. - */ -void -GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room); - - -#if 0 -/* these are not yet implemented / supported */ -/** - * Callback function to iterate over rooms. - * - * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration - */ -typedef int (*GNUNET_CHAT_RoomIterator) (const char *room, const char *topic, - void *cls); - -/** - * List all of the (publically visible) chat rooms. - * @return number of rooms on success, GNUNET_SYSERR if iterator aborted - */ -int -GNUNET_CHAT_list_rooms (struct GNUNET_GE_Context *ectx, - struct GNUNET_GC_Configuration *cfg, - GNUNET_CHAT_RoomIterator it, void *cls); -#endif - - -#if 0 /* keep Emacsens' auto-indent happy */ -{ -#endif -#ifdef __cplusplus -} -#endif - -#endif - -/* end of gnunet_chat_service.h */ diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am deleted file mode 100644 index 9b3d94286..000000000 --- a/src/lockmanager/Makefile.am +++ /dev/null @@ -1,84 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/src/include - -if MINGW - WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -endif - -if USE_COVERAGE - AM_CFLAGS = --coverage -O0 - XLIB = -lgcov -endif - -pkgcfgdir= $(pkgdatadir)/config.d/ - -libexecdir= $(pkglibdir)/libexec/ - -pkgcfg_DATA = \ - lockmanager.conf - -libexec_PROGRAMS = \ - gnunet-service-lockmanager - -lib_LTLIBRARIES = \ - libgnunetlockmanager.la - -gnunet_service_lockmanager_SOURCES = \ - gnunet-service-lockmanager.c \ - lockmanager.h -gnunet_service_lockmanager_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la -gnunet_service_lockmanager_DEPENDENCIES = \ - $(top_builddir)/src/util/libgnunetutil.la - -libgnunetlockmanager_la_SOURCES = \ - lockmanager_api.c lockmanager.h -libgnunetlockmanager_la_LIBADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(XLIB) \ - $(LTLIBINTL) -libgnunetlockmanager_la_LDFLAGS = \ - $(GN_LIB_LDFLAGS) $(WINFLAGS) \ - -version-info 0:0:0 - -if HAVE_TESTING -check_PROGRAMS = \ - test_lockmanager_api \ - test_lockmanager_api_lockrelease \ - test_lockmanager_api_servercrash \ - test_lockmanager_api_acquireretry -endif - -EXTRA_DIST = \ - test_lockmanager_api.conf - -if ENABLE_TEST_RUN - TESTS = $(check_PROGRAMS) -endif - -test_lockmanager_api_SOURCES = \ - test_lockmanager_api.c -test_lockmanager_api_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetlockmanager.la - -test_lockmanager_api_lockrelease_SOURCES = \ - test_lockmanager_api_lockrelease.c -test_lockmanager_api_lockrelease_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetlockmanager.la - -test_lockmanager_api_servercrash_SOURCES = \ - test_lockmanager_api_servercrash.c -test_lockmanager_api_servercrash_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetlockmanager.la - -test_lockmanager_api_acquireretry_SOURCES = \ - test_lockmanager_api_acquireretry.c -test_lockmanager_api_acquireretry_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetlockmanager.la diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c deleted file mode 100644 index fde32ed60..000000000 --- a/src/lockmanager/gnunet-service-lockmanager.c +++ /dev/null @@ -1,847 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2008--2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file lockmanager/gnunet-service-lockmanager.c - * @brief implementation of the LOCKMANAGER service - * @author Sree Harsha Totakura - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_protocols.h" - -#include "lockmanager.h" - - -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) - -#define TIME_REL_MINS(min) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, min) - -#define TIMEOUT TIME_REL_MINS(3) - - -/** - * Doubly linked list of clients having connections to us - */ -struct ClientList; - - -/** - * Doubly linked list of clients waiting for a lock - */ -struct WaitList -{ - /** - * The next client structure - */ - struct WaitList *next; - - /** - * The prev client structure - */ - struct WaitList *prev; - - /** - * Pointer to the client - */ - struct ClientList *cl_entry; -}; - - -/** - * Structure representing a Lock - */ -struct Lock -{ - /** - * List head of clients waiting for this lock - */ - struct WaitList *wl_head; - - /** - * List tail of clients waiting for this lock - */ - struct WaitList *wl_tail; - - /** - * The client which is currently holding this lock - */ - struct ClientList *cl_entry; - - /** - * The name of the locking domain this lock belongs to - */ - char *domain_name; - - /** - * The number of this lock - */ - uint32_t lock_num; -}; - - -/** - * A Lock element for a doubly linked list - */ -struct LockList -{ - /** - * The next element pointer - */ - struct LockList *next; - - /** - * Pointer to the previous element - */ - struct LockList *prev; - - /** - * Pointer to the Lock - */ - struct Lock *lock; -}; - - -/** - * Doubly linked list of clients having connections to us - */ -struct ClientList -{ - - /** - * The next client structure - */ - struct ClientList *next; - - /** - * The previous client structure - */ - struct ClientList *prev; - - /** - * Head of the doubly linked list of the currently held locks by this client - */ - struct LockList *ll_head; - - /** - * Tail of the doubly linked list of the currently held locks by this client - */ - struct LockList *ll_tail; - - /** - * Pointer to the client - */ - struct GNUNET_SERVER_Client *client; -}; - - -/** - * Structure for matching a lock - */ -struct LockMatch -{ - /** - * The matched LockingRequest entry; Should be NULL if no entry is found - */ - struct Lock *matched_entry; - - /** - * The locking domain name of the lock - */ - const char *domain_name; - - /** - * The lock number - */ - uint32_t lock_num; -}; - - -/** - * Map of lock-keys to the 'struct LockList' entry for the key. - */ -static struct GNUNET_CONTAINER_MultiHashMap *lock_map; - -/** - * Head of the doubly linked list of clients currently connected - */ -static struct ClientList *cl_head; - -/** - * Tail of the doubly linked list of clients currently connected - */ -static struct ClientList *cl_tail; - - -/** - * Get the key for the given lock in the 'lock_map'. - * - * @param domain_name - * @param lock_number - * @param key set to the key - */ -static void -get_key (const char *domain_name, uint32_t lock_number, - struct GNUNET_HashCode *key) -{ - uint32_t *last_32; - - GNUNET_CRYPTO_hash (domain_name, strlen (domain_name), key); - last_32 = (uint32_t *) key; - *last_32 ^= lock_number; -} - - -/** - * Hashmap iterator for matching a lock - * - * @param cls the LockMatch structure - * @param key current key code - * @param value value in the hash map (struct Lock) - * @return GNUNET_YES if we should continue to - * iterate, - * GNUNET_NO if not. - */ -static int -match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) -{ - struct LockMatch *match = cls; - struct Lock *lock = value; - - if ((match->lock_num == lock->lock_num) && - (0 == strcmp (match->domain_name, lock->domain_name))) - { - match->matched_entry = lock; - return GNUNET_NO; - } - return GNUNET_YES; -} - - -/** - * Function to search for a lock in the global lock hashmap - * - * @param domain_name the name of the locking domain - * @param lock_num the number of the lock - * @return the lock if found; NULL if not - */ -static struct Lock * -find_lock (const char *domain_name, const uint32_t lock_num) -{ - struct LockMatch match; - struct GNUNET_HashCode key; - - match.lock_num = lock_num; - match.domain_name = domain_name; - match.matched_entry = NULL; - get_key (domain_name, lock_num, &key); - GNUNET_CONTAINER_multihashmap_get_multiple (lock_map, &key, &match_iterator, - &match); - return match.matched_entry; -} - - -/** - * Adds a lock to the global lock hashmap - * - * @param domain_name the name of the lock's locking domain - * @param lock_num the lock number - * @return pointer to the lock structure which is added to lock map - */ -static struct Lock * -add_lock (const char *domain_name, uint32_t lock_num) -{ - struct Lock *lock; - struct GNUNET_HashCode key; - size_t domain_name_len; - - lock = GNUNET_malloc (sizeof (struct Lock)); - domain_name_len = strlen (domain_name) + 1; - lock->domain_name = GNUNET_malloc (domain_name_len); - strncpy (lock->domain_name, domain_name, domain_name_len); - lock->lock_num = lock_num; - get_key (domain_name, lock_num, &key); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding a lock with num: %d and domain: %s to the lock map\n", - lock->lock_num, lock->domain_name); - GNUNET_CONTAINER_multihashmap_put (lock_map, &key, lock, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - return lock; -} - - -/** - * Removes a lock from the lock map. The WaitList of the lock should be empty - * - * @param lock the lock to remove - */ -static void -remove_lock (struct Lock *lock) -{ - struct GNUNET_HashCode key; - - GNUNET_assert (NULL == lock->wl_head); - get_key (lock->domain_name, lock->lock_num, &key); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Removing lock with num: %u, domain: %s from lock map\n", lock->lock_num, - lock->domain_name); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (lock_map, &key, lock)); - GNUNET_free (lock->domain_name); - GNUNET_free (lock); -} - - -/** - * Find the LockList entry corresponding to the given Lock in a ClientList - * entry - * - * @param cl_entry the ClientList entry whose lock list has to be searched - * @param lock the lock which has to be matched - * @return the matching LockList entry; NULL if no match is found - */ -static struct LockList * -cl_ll_find_lock (struct ClientList *cl_entry, const struct Lock *lock) -{ - struct LockList *ll_entry; - - for (ll_entry = cl_entry->ll_head; NULL != ll_entry; - ll_entry = ll_entry->next) - { - if (lock == ll_entry->lock) - return ll_entry; - } - return NULL; -} - - -/** - * Function to append a lock to the lock list of a ClientList entry - * - * @param cl_entry the client which currently owns this lock - * @param lock the lock to be added to the cl_entry's lock list - */ -static void -cl_ll_add_lock (struct ClientList *cl_entry, struct Lock *lock) -{ - struct LockList *ll_entry; - - ll_entry = GNUNET_malloc (sizeof (struct LockList)); - ll_entry->lock = lock; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding a lock with num: %u and domain: %s to lock list\n", - lock->lock_num, lock->domain_name); - GNUNET_CONTAINER_DLL_insert_tail (cl_entry->ll_head, cl_entry->ll_tail, - ll_entry); -} - - -/** - * Function to delete a lock from the lock list of the given ClientList entry - * - * @param cl_entry the ClientList entry - * @param ll_entry the LockList entry to be deleted - */ -static void -cl_ll_remove_lock (struct ClientList *cl_entry, struct LockList *ll_entry) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Removing lock with num: %u, domain: %s from lock list of a client\n", - ll_entry->lock->lock_num, ll_entry->lock->domain_name); - GNUNET_assert (NULL != cl_entry->ll_head); - GNUNET_CONTAINER_DLL_remove (cl_entry->ll_head, cl_entry->ll_tail, ll_entry); - GNUNET_free (ll_entry); -} - - -/** - * Find a WaitList entry in the waiting list of a lock - * - * @param lock the lock whose wait list has to be searched - * @param cl_entry the ClientList entry to be searched - * @return the WaitList entry matching the given cl_entry; NULL if not match - * was found - */ -static struct WaitList * -lock_wl_find (const struct Lock *lock, const struct ClientList *cl_entry) -{ - struct WaitList *wl_entry; - - for (wl_entry = lock->wl_head; NULL != wl_entry; wl_entry = wl_entry->next) - { - if (cl_entry == wl_entry->cl_entry) - return wl_entry; - } - return NULL; -} - - -/** - * Add a client to the wait list of given lock - * - * @param lock the lock list entry of a lock - * @param cl_entry the client to queue for the lock's wait list - */ -static void -lock_wl_add_client (struct Lock *lock, struct ClientList *cl_entry) -{ - struct WaitList *wl_entry; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Adding a client to lock's wait list (lock num: %u, domain: %s)\n", - lock->lock_num, lock->domain_name); - wl_entry = GNUNET_malloc (sizeof (struct WaitList)); - wl_entry->cl_entry = cl_entry; - GNUNET_CONTAINER_DLL_insert_tail (lock->wl_head, lock->wl_tail, wl_entry); -} - - -/** - * Remove an entry from the wait list of the given lock - * - * @param lock the lock - * @param wl_entry the wait list entry to be removed - */ -static void -lock_wl_remove (struct Lock *lock, struct WaitList *wl_entry) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Removing client from wait list of lock with num: %u, domain: %s\n", - lock->lock_num, lock->domain_name); - GNUNET_CONTAINER_DLL_remove (lock->wl_head, lock->wl_tail, wl_entry); - GNUNET_free (wl_entry); -} - - -/** - * Search for a client in the client list - * - * @param client the client to be searched for - * @return the ClientList entry; NULL if the client is not found - */ -static struct ClientList * -cl_find_client (const struct GNUNET_SERVER_Client *client) -{ - struct ClientList *current; - - for (current = cl_head; NULL != current; current = current->next) - if (client == current->client) - return current; - return NULL; -} - - -/** - * Append a client to the client list - * - * @param client the client to be appended to the list - * @return the client list entry which is added to the client list - */ -static struct ClientList * -cl_add_client (struct GNUNET_SERVER_Client *client) -{ - struct ClientList *new_client; - - LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding a client to the client list\n"); - new_client = GNUNET_malloc (sizeof (struct ClientList)); - GNUNET_SERVER_client_keep (client); - new_client->client = client; - GNUNET_CONTAINER_DLL_insert_tail (cl_head, cl_tail, new_client); - return new_client; -} - - -/** - * Delete the given client from the client list. The LockList should be empty - * - * @param cl_entry the client list entry to delete - */ -static void -cl_remove_client (struct ClientList *cl_entry) -{ - GNUNET_assert (NULL == cl_entry->ll_head); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing a client from the client list\n"); - GNUNET_SERVER_client_drop (cl_entry->client); - GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl_entry); - GNUNET_free (cl_entry); -} - - -/** - * Transmit notify for sending message to client - * - * @param cls the message to send - * @param size number of bytes available in buf - * @param buf where the callee should write the message - * @return number of bytes written to buf - */ -static size_t -transmit_notify (void *cls, size_t size, void *buf) -{ - struct GNUNET_LOCKMANAGER_Message *msg = cls; - uint16_t msg_size; - - if ((0 == size) || (NULL == buf)) - { - /* FIXME: Timed out -- requeue? */ - return 0; - } - msg_size = ntohs (msg->header.size); - GNUNET_assert (size >= msg_size); - memcpy (buf, msg, msg_size); - GNUNET_free (msg); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Message of size %u sent\n", msg_size); - return msg_size; -} - - -/** - * Send SUCCESS message to the client - * - * @param client the client to which the message has to be sent - * @param domain_name the locking domain of the successfully acquried lock - * @param lock_num the number of the successfully acquired lock - */ -static void -send_success_msg (struct GNUNET_SERVER_Client *client, const char *domain_name, - int lock_num) -{ - struct GNUNET_LOCKMANAGER_Message *reply; - size_t domain_name_len; - uint16_t reply_size; - - domain_name_len = strlen (domain_name) + 1; - reply_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_len; - reply = GNUNET_malloc (reply_size); - reply->header.size = htons (reply_size); - reply->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS); - reply->lock = htonl (lock_num); - strncpy ((char *) &reply[1], domain_name, domain_name_len); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending SUCCESS message for lock with num: %u, domain: %s\n", lock_num, - domain_name); - GNUNET_SERVER_notify_transmit_ready (client, reply_size, TIMEOUT, - &transmit_notify, reply); -} - - -/** - * Handler for GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE - * - * @param cls NULL - * @param client the client sending this message - * @param message GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE message - */ -static void -handle_acquire (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) -{ - const struct GNUNET_LOCKMANAGER_Message *request; - const char *domain_name; - struct Lock *lock; - struct ClientList *cl_entry; - uint32_t lock_num; - uint16_t msize; - - msize = htons (message->size); - if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - request = (struct GNUNET_LOCKMANAGER_Message *) message; - domain_name = (const char *) &request[1]; - msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); - if ('\0' != domain_name[msize - 1]) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Bad domain `%.*s' - byte with index %u is %X, not 0.\n", msize, - domain_name, msize - 1, (unsigned int) domain_name[msize - 1]); - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - lock_num = ntohl (request->lock); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received an ACQUIRE message for lock num: %u domain: %s\n", lock_num, - domain_name); - if (NULL == (cl_entry = cl_find_client (client))) - cl_entry = cl_add_client (client); /* Add client if not in client list */ - if (NULL != (lock = find_lock (domain_name, lock_num))) - { - if (lock->cl_entry == cl_entry) - { /* Client is requesting a lock it already owns */ - GNUNET_break_op (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - lock_wl_add_client (lock, cl_entry); - cl_ll_add_lock (cl_entry, lock); - } - else /* Lock not present */ - { - lock = add_lock (domain_name, lock_num); - lock->cl_entry = cl_entry; - cl_ll_add_lock (cl_entry, lock); - send_success_msg (cl_entry->client, domain_name, lock_num); - } - GNUNET_SERVER_receive_done (client, GNUNET_OK); -} - - -/** - * This function gives the lock to the first client in the wait list of the - * lock. If no clients are currently waiting for this lock, the lock is then - * destroyed. - * - * @param lock the lock which has to be processed for release - */ -static void -process_lock_release (struct Lock *lock) -{ - struct WaitList *wl_entry; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Processing lock release for lock with num: %u, domain: %s\n", - lock->lock_num, lock->domain_name); - wl_entry = lock->wl_head; - if (NULL == wl_entry) - { - remove_lock (lock); /* No clients waiting for this lock - delete */ - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving lock to a client from wait list\n"); - lock->cl_entry = wl_entry->cl_entry; - lock_wl_remove (lock, wl_entry); - send_success_msg (lock->cl_entry->client, lock->domain_name, lock->lock_num); -} - - -/** - * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE - * - * @param cls NULL - * @param client the client sending this message - * @param message the LOCKMANAGER_RELEASE message - */ -static void -handle_release (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) -{ - const struct GNUNET_LOCKMANAGER_Message *request; - struct ClientList *cl_entry; - struct WaitList *wl_entry; - struct LockList *ll_entry; - const char *domain_name; - struct Lock *lock; - uint32_t lock_num; - uint16_t msize; - - msize = ntohs (message->size); - if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - request = (const struct GNUNET_LOCKMANAGER_Message *) message; - domain_name = (const char *) &request[1]; - msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); - if ('\0' != domain_name[msize - 1]) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - - - } - lock_num = ntohl (request->lock); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received RELEASE message for lock with num: %d, domain: %s\n", lock_num, - domain_name); - if (NULL == (cl_entry = cl_find_client (client))) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - lock = find_lock (domain_name, lock_num); - if (NULL == lock) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - if (NULL == (ll_entry = cl_ll_find_lock (cl_entry, lock))) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - cl_ll_remove_lock (cl_entry, ll_entry); - if (cl_entry == lock->cl_entry) - { - process_lock_release (lock); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } - /* remove 'client' from wait list (check that it is not there...) */ - if (NULL != (wl_entry = lock_wl_find (lock, cl_entry))) - { - lock_wl_remove (lock, wl_entry); - } - GNUNET_SERVER_receive_done (client, GNUNET_OK); -} - - -/** - * Callback for client disconnect - * - * @param cls NULL - * @param client the client which has disconnected - */ -static void -client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) -{ - struct ClientList *cl_entry; - struct LockList *ll_entry; - struct Lock *lock; - struct WaitList *wl_entry; - - if (NULL == client) - return; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "A client has been disconnected -- freeing its locks and resources\n"); - cl_entry = cl_find_client (client); - if (NULL == cl_entry) - return; - while (NULL != (ll_entry = cl_entry->ll_head)) - { - lock = ll_entry->lock; - cl_ll_remove_lock (cl_entry, ll_entry); - if (lock->cl_entry == cl_entry) - process_lock_release (lock); - else - { - wl_entry = lock_wl_find (lock, cl_entry); - GNUNET_assert (NULL != wl_entry); - lock_wl_remove (lock, wl_entry); - } - } - cl_remove_client (cl_entry); -} - - -/** - * Hashmap Iterator to delete lock entries in hash map - * - * @param cls NULL - * @param key current key code - * @param value value in the hash map - * @return GNUNET_YES if we should continue to - * iterate, - * GNUNET_NO if not. - */ -static int -lock_delete_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) -{ - struct Lock *lock = value; - - GNUNET_assert (NULL != lock); - while (NULL != lock->wl_head) - { - lock_wl_remove (lock, lock->wl_head); - } - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (lock_map, key, lock)); - GNUNET_free (lock->domain_name); - GNUNET_free (lock); - return GNUNET_YES; -} - - -/** - * Task to clean up and shutdown nicely - * - * @param cls NULL - * @param tc the TaskContext from scheduler - */ -static void -shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down lock manager\n"); - /* Clean the global ClientList */ - while (NULL != cl_head) - { - while (NULL != cl_head->ll_head) /* Clear the LockList */ - { - cl_ll_remove_lock (cl_head, cl_head->ll_head); - } - cl_remove_client (cl_head); - } - /* Clean the global hash table */ - GNUNET_CONTAINER_multihashmap_iterate (lock_map, &lock_delete_iterator, NULL); - GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (lock_map)); - GNUNET_CONTAINER_multihashmap_destroy (lock_map); - lock_map = NULL; -} - - -/** - * Lock manager setup - * - * @param cls closure - * @param server the initialized server - * @param cfg configuration to use - */ -static void -lockmanager_run (void *cls, struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { - {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0}, - {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0}, - {NULL} - }; - GNUNET_SERVER_add_handlers (server, message_handlers); - GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); - lock_map = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, - NULL); -} - - -/** - * The starting point of execution - */ -int -main (int argc, char *const *argv) -{ - return (GNUNET_OK == - GNUNET_SERVICE_run (argc, argv, "lockmanager", - GNUNET_SERVICE_OPTION_NONE, &lockmanager_run, - NULL)) ? 0 : 1; -} - -/* end of gnunet-service-lockmanager.c */ diff --git a/src/lockmanager/lockmanager.conf.in b/src/lockmanager/lockmanager.conf.in deleted file mode 100644 index 42d574324..000000000 --- a/src/lockmanager/lockmanager.conf.in +++ /dev/null @@ -1,12 +0,0 @@ -[lockmanager] -AUTOSTART = YES -@UNIXONLY@ PORT = 2100 -HOSTNAME = localhost -HOME = $SERVICEHOME -BINARY = gnunet-service-lockmanager -ACCEPT_FROM = 127.0.0.1; -ACCEPT_FROM6 = ::1; -UNIXPATH = /tmp/gnunet-service-lockmanager.sock -UNIX_MATCH_UID = YES -UNIX_MATCH_GID = YES - diff --git a/src/lockmanager/lockmanager.h b/src/lockmanager/lockmanager.h deleted file mode 100644 index 030c827c1..000000000 --- a/src/lockmanager/lockmanager.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2008--2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file lockmanager/lockmanager.h - * @brief client-server protocol messages for LOCKMANAGER service - * @author Sree Harsha Totakura - */ - -#ifndef LOCKMANAGER_H -#define LOCKMANAGER_H - -#ifdef __cplusplus -extern "C" -{ -#if 0 /* keep Emacsens' auto-indent happy */ -} -#endif -#endif - -#include "gnunet_common.h" - -/** - * Structure of Lockmanager message - */ -struct GNUNET_LOCKMANAGER_Message -{ - /** - * The generic message header - */ - struct GNUNET_MessageHeader header; - - /** - * The lock - */ - uint32_t lock; - - /** - * The locking domain name(NULL terminated string of characters) should - * follow here. The size of the header should include the size of this string - * with its trailing NULL - */ -}; - -#if 0 /* keep Emacsens' auto-indent happy */ -{ -#endif -#ifdef __cplusplus -} -#endif - -/* ifndef LOCKMANAGER_H */ -#endif -/* end of lockmanager.h */ diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c deleted file mode 100644 index 8f66cf00b..000000000 --- a/src/lockmanager/lockmanager_api.c +++ /dev/null @@ -1,729 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2008--2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file lockmanager/lockmanager_api.c - * @brief API implementation of gnunet_lockmanager_service.h - * @author Sree Harsha Totakura - */ - - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_lockmanager_service.h" -#include "gnunet_protocols.h" - -#include "lockmanager.h" - -#define LOG(kind,...) \ - GNUNET_log_from (kind, "lockmanager-api",__VA_ARGS__) - -#define TIME_REL_MINS(min) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, min) - -#define TIMEOUT TIME_REL_MINS(3) - - -/** - * The message queue - */ -struct MessageQueue -{ - /** - * The next pointer for doubly linked list - */ - struct MessageQueue *next; - - /** - * The prev pointer for doubly linked list - */ - struct MessageQueue *prev; - - /** - * The LOCKMANAGER Message - */ - struct GNUNET_LOCKMANAGER_Message *msg; - - /** - * If this is a AQUIRE_LOCK message, this is the - * affiliated locking request. - */ - struct GNUNET_LOCKMANAGER_LockingRequest *lr; -}; - - -/** - * Handler for the lockmanager service - */ -struct GNUNET_LOCKMANAGER_Handle -{ - /** - * The client connection to the service - */ - struct GNUNET_CLIENT_Connection *conn; - - /** - * The transmit handle for transmissions using conn - */ - struct GNUNET_CLIENT_TransmitHandle *transmit_handle; - - /** - * Hashmap handle - */ - struct GNUNET_CONTAINER_MultiHashMap *hashmap; - - /** - * Double linked list head for message queue - */ - struct MessageQueue *mq_head; - - /** - * Double linked list tail for message queue - */ - struct MessageQueue *mq_tail; - - /** - * Are we currently handling replies? - */ - int in_replies; -}; - - -/** - * Structure for Locking Request - */ -struct GNUNET_LOCKMANAGER_LockingRequest -{ - /** - * The handle associated with this request - */ - struct GNUNET_LOCKMANAGER_Handle *handle; - - /** - * The status callback - */ - GNUNET_LOCKMANAGER_StatusCallback status_cb; - - /** - * Entry in the request message queue for aquiring this - * lock; NULL after request has been sent. - */ - struct MessageQueue *mqe; - - /** - * Closure for the status callback - */ - void *status_cb_cls; - - /** - * The locking domain of this request - */ - char *domain; - - /** - * The lock - */ - uint32_t lock; - - /** - * The status of the lock - */ - enum GNUNET_LOCKMANAGER_Status status; - - /** - * set to GNUNET_YES if acquire message for this lock is till in messga queue - */ - int acquire_sent; -}; - - -/** - * Structure for matching a lock - */ -struct LockingRequestMatch -{ - /** - * The matched LockingRequest entry; Should be NULL if no entry is found - */ - struct GNUNET_LOCKMANAGER_LockingRequest *matched_entry; - - /** - * The locking domain name of the lock - */ - const char *domain; - - /** - * The lock number - */ - uint32_t lock; -}; - - -/** - * Handler for server replies - * - * @param cls the LOCKMANAGER_Handle - * @param msg received message, NULL on timeout or fatal error - */ -static void -handle_replies (void *cls, const struct GNUNET_MessageHeader *msg); - - -/** - * Transmit notify for sending message to server - * - * @param cls the lockmanager handle - * @param size number of bytes available in buf - * @param buf where the callee should write the message - * @return number of bytes written to buf - */ -static size_t -transmit_notify (void *cls, size_t size, void *buf) -{ - struct GNUNET_LOCKMANAGER_Handle *handle = cls; - struct MessageQueue *queue_entity; - uint16_t msg_size; - - handle->transmit_handle = NULL; - queue_entity = handle->mq_head; - GNUNET_assert (NULL != queue_entity); - if ((0 == size) || (NULL == buf)) - { - handle->transmit_handle = - GNUNET_CLIENT_notify_transmit_ready (handle->conn, - ntohs (queue_entity->msg-> - header.size), - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, &transmit_notify, - handle); - return 0; - } - msg_size = ntohs (queue_entity->msg->header.size); - GNUNET_assert (size >= msg_size); - memcpy (buf, queue_entity->msg, msg_size); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Message of size %u sent\n", msg_size); - if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE == - ntohs (queue_entity->msg->header.type)) - { - GNUNET_break (GNUNET_NO == queue_entity->lr->acquire_sent); - queue_entity->lr->acquire_sent = GNUNET_YES; - queue_entity->lr->mqe = NULL; - } - GNUNET_free (queue_entity->msg); - GNUNET_CONTAINER_DLL_remove (handle->mq_head, handle->mq_tail, queue_entity); - GNUNET_free (queue_entity); - queue_entity = handle->mq_head; - if (NULL != queue_entity) - { - handle->transmit_handle = - GNUNET_CLIENT_notify_transmit_ready (handle->conn, - ntohs (queue_entity->msg-> - header.size), TIMEOUT, - GNUNET_YES, &transmit_notify, - handle); - } - if (GNUNET_NO == handle->in_replies) - { - handle->in_replies = GNUNET_YES; - GNUNET_CLIENT_receive (handle->conn, &handle_replies, handle, - GNUNET_TIME_UNIT_FOREVER_REL); - } - return msg_size; -} - - -/** - * Queues a message into handle's send message queue - * - * @param handle the lockmanager handle whose queue will be used - * @param msg the message to be queued - * @param request the locking reqeust responsible for queueing this message - * @return the MessageQueue entity that has been queued - */ -static struct MessageQueue * -queue_message (struct GNUNET_LOCKMANAGER_Handle *handle, - struct GNUNET_LOCKMANAGER_Message *msg, - struct GNUNET_LOCKMANAGER_LockingRequest *request) -{ - struct MessageQueue *queue_entity; - - GNUNET_assert (NULL != msg); - queue_entity = GNUNET_malloc (sizeof (struct MessageQueue)); - queue_entity->msg = msg; - queue_entity->lr = request; - GNUNET_CONTAINER_DLL_insert_tail (handle->mq_head, handle->mq_tail, - queue_entity); - if (NULL == handle->transmit_handle) - { - handle->transmit_handle = - GNUNET_CLIENT_notify_transmit_ready (handle->conn, - ntohs (msg->header.size), TIMEOUT, - GNUNET_YES, &transmit_notify, - handle); - } - return queue_entity; -} - - -/** - * Get the key for the given lock in the 'lock_map'. - * - * @param domain_name - * @param lock_number - * @param key set to the key - */ -static void -get_key (const char *domain_name, uint32_t lock_number, - struct GNUNET_HashCode *key) -{ - uint32_t *last_32; - - GNUNET_CRYPTO_hash (domain_name, strlen (domain_name), key); - last_32 = (uint32_t *) key; - *last_32 ^= lock_number; -} - - -/** - * Hashmap iterator for matching a LockingRequest - * - * @param cls the LockingRequestMatch structure - * @param key current key code - * @param value value in the hash map (struct GNUNET_LOCKMANAGER_LockingRequest) - * @return GNUNET_YES if we should continue to - * iterate, - * GNUNET_NO if not. - */ -static int -match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) -{ - struct LockingRequestMatch *match = cls; - struct GNUNET_LOCKMANAGER_LockingRequest *lr = value; - - if ((match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain))) - { - match->matched_entry = lr; - return GNUNET_NO; - } - return GNUNET_YES; -} - - -/** - * Function to find a LockingRequest associated with the given domain and lock - * attributes in the map - * - * @param map the map where the LockingRequests are stored - * @param domain the locking domain name - * @param lock the lock number - * @return the found LockingRequest; NULL if a matching LockingRequest wasn't - * found - */ -static struct GNUNET_LOCKMANAGER_LockingRequest * -hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map, - const char *domain, uint32_t lock) -{ - struct GNUNET_HashCode hash; - struct LockingRequestMatch lock_match; - - lock_match.matched_entry = NULL; - lock_match.domain = domain; - lock_match.lock = lock; - get_key (domain, lock, &hash); - GNUNET_CONTAINER_multihashmap_get_multiple (map, &hash, &match_iterator, - &lock_match); - return lock_match.matched_entry; -} - - -/** - * Task for calling status change callback for a lock - * - * @param cls the LockingRequest associated with this lock - * @param tc the TaskScheduler context - */ -static void -call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - const struct GNUNET_LOCKMANAGER_LockingRequest *r = cls; - - if (NULL != r->status_cb) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Calling status change for SUCCESS on lock num: %d, domain: %s\n", - r->lock, r->domain); - r->status_cb (r->status_cb_cls, r->domain, r->lock, r->status); - } -} - - -/** - * Function to generate acquire message for a lock - * - * @param domain_name the domain name of the lock - * @param lock the lock number - * @return the generated GNUNET_LOCKMANAGER_Message - */ -static struct GNUNET_LOCKMANAGER_Message * -generate_acquire_msg (const char *domain_name, uint32_t lock) -{ - struct GNUNET_LOCKMANAGER_Message *msg; - size_t domain_name_len; - uint16_t msg_size; - - domain_name_len = strlen (domain_name) + 1; - msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_len; - msg = GNUNET_malloc (msg_size); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE); - msg->header.size = htons (msg_size); - msg->lock = htonl (lock); - memcpy (&msg[1], domain_name, domain_name_len); - return msg; -} - - -/** - * Iterator to call relase on locks; acquire messages are sent for all - * locks. In addition, if a lock is acquired before, it is not released and its - * status callback is called to signal its release - * - * @param cls the lockmanager handle - * @param key current key code - * @param value the Locking request - * @return GNUNET_YES if we should continue to - * iterate, - * GNUNET_NO if not. - */ -static int -release_n_retry_iterator (void *cls, const struct GNUNET_HashCode *key, - void *value) -{ - struct GNUNET_LOCKMANAGER_LockingRequest *r = value; - struct GNUNET_LOCKMANAGER_Handle *h = cls; - struct GNUNET_LOCKMANAGER_Message *msg; - - if (GNUNET_NO == r->acquire_sent) /* an acquire is still in queue */ - return GNUNET_YES; - r->acquire_sent = GNUNET_NO; - msg = generate_acquire_msg (r->domain, r->lock); - r->mqe = queue_message (h, msg, r); - if (GNUNET_LOCKMANAGER_RELEASE == r->status) - return GNUNET_YES; - if (NULL != r->status_cb) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Calling status change for RELEASE on lock num: %d, domain: %s\n", - r->lock, r->domain); - r->status = GNUNET_LOCKMANAGER_RELEASE; - r->status_cb (r->status_cb_cls, r->domain, r->lock, - GNUNET_LOCKMANAGER_RELEASE); - } - return GNUNET_YES; -} - - -/** - * Handler for server replies - * - * @param cls the LOCKMANAGER_Handle - * @param msg received message, NULL on timeout or fatal error - */ -static void -handle_replies (void *cls, const struct GNUNET_MessageHeader *msg) -{ - struct GNUNET_LOCKMANAGER_Handle *handle = cls; - const struct GNUNET_LOCKMANAGER_Message *m; - struct GNUNET_LOCKMANAGER_LockingRequest *lr; - const char *domain; - struct GNUNET_HashCode hash; - uint32_t lock; - uint16_t msize; - - handle->in_replies = GNUNET_NO; - if (NULL == msg) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Lockmanager service not available or went down\n"); - /* Should release all locks and retry to acquire them */ - GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, - &release_n_retry_iterator, handle); - return; - } - handle->in_replies = GNUNET_YES; - GNUNET_CLIENT_receive (handle->conn, &handle_replies, handle, - GNUNET_TIME_UNIT_FOREVER_REL); - if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs (msg->type)) - { - GNUNET_break (0); - return; - } - msize = ntohs (msg->size); - if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message)) - { - GNUNET_break (0); - return; - } - m = (const struct GNUNET_LOCKMANAGER_Message *) msg; - domain = (const char *) &m[1]; - msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); - if ('\0' != domain[msize - 1]) - { - GNUNET_break (0); - return; - } - - lock = ntohl (m->lock); - get_key (domain, lock, &hash); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received SUCCESS message for lock: %d, domain %s\n", lock, domain); - if (NULL == - (lr = hashmap_find_lockingrequest (handle->hashmap, domain, lock))) - { - GNUNET_break (0); - return; - } - if (GNUNET_LOCKMANAGER_SUCCESS == lr->status) - { - GNUNET_break (0); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Changing status for lock: %d in domain: %s to SUCCESS\n", lr->lock, - lr->domain); - lr->status = GNUNET_LOCKMANAGER_SUCCESS; - GNUNET_SCHEDULER_add_continuation (&call_status_cb_task, lr, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); -} - - -/** - * Iterator to free hash map entries. - * - * @param cls the lockmanger handle - * @param key current key code - * @param value the Locking request - * @return GNUNET_YES if we should continue to - * iterate, - * GNUNET_NO if not. - */ -static int -free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) -{ - struct GNUNET_LOCKMANAGER_Handle *h = cls; - struct GNUNET_LOCKMANAGER_LockingRequest *r = value; - - LOG (GNUNET_ERROR_TYPE_DEBUG, "Clearing locking request\n"); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (h->hashmap, key, value)); - GNUNET_free (r->domain); - GNUNET_free (r); - return GNUNET_YES; -} - - -/*******************/ -/* API Definitions */ -/*******************/ - - -/** - * Connect to the lockmanager service - * - * @param cfg the configuration to use - * - * @return upon success the handle to the service; NULL upon error - */ -struct GNUNET_LOCKMANAGER_Handle * -GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - struct GNUNET_LOCKMANAGER_Handle *h; - - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); - h = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_Handle)); - h->conn = GNUNET_CLIENT_connect ("lockmanager", cfg); - if (NULL == h->conn) - { - GNUNET_free (h); - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); - return NULL; - } - h->hashmap = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); - GNUNET_assert (NULL != h->hashmap); - h->in_replies = GNUNET_YES; - GNUNET_CLIENT_receive (h->conn, &handle_replies, h, - GNUNET_TIME_UNIT_FOREVER_REL); - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); - return h; -} - - -/** - * Disconnect from the lockmanager service - * - * @param handle the handle to the lockmanager service - */ -void -GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) -{ - struct MessageQueue *head; - - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); - if (0 != GNUNET_CONTAINER_multihashmap_size (handle->hashmap)) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Some locking requests are still present. Cancel them before " - "calling %s\n", __func__); - GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, &free_iterator, - handle); - } - GNUNET_CONTAINER_multihashmap_destroy (handle->hashmap); - /* Clear the message queue */ - if (NULL != handle->transmit_handle) - { - GNUNET_CLIENT_notify_transmit_ready_cancel (handle->transmit_handle); - } - head = handle->mq_head; - while (NULL != head) - { - GNUNET_CONTAINER_DLL_remove (handle->mq_head, handle->mq_tail, head); - GNUNET_free (head->msg); - GNUNET_free (head); - head = handle->mq_head; - } - GNUNET_CLIENT_disconnect (handle->conn); - GNUNET_free (handle); - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); -} - - -/** - * Tries to acquire the given lock(even if the lock has been lost) until the - * request is called. If the lock is available the status_cb will be - * called. If the lock is busy then the request is queued and status_cb - * will be called when the lock has been made available and acquired by us. - * - * @param handle the handle to the lockmanager service - * - * @param domain_name name of the locking domain. Clients who want to share - * locks must use the same name for the locking domain. Also the - * domain_name should be selected with the prefix - * "GNUNET__" to avoid domain name collisions. - * - * - * @param lock which lock to lock - * - * @param status_cb the callback for signalling when the lock is acquired and - * when it is lost - * - * @param status_cb_cls the closure to the above callback - * - * @return the locking request handle for this request - */ -struct GNUNET_LOCKMANAGER_LockingRequest * -GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, - const char *domain_name, uint32_t lock, - GNUNET_LOCKMANAGER_StatusCallback status_cb, - void *status_cb_cls) -{ - struct GNUNET_LOCKMANAGER_LockingRequest *r; - struct GNUNET_LOCKMANAGER_Message *msg; - struct GNUNET_HashCode hash; - size_t domain_name_length; - - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); - r = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_LockingRequest)); - domain_name_length = strlen (domain_name) + 1; - r->handle = handle; - r->lock = lock; - r->domain = GNUNET_malloc (domain_name_length); - r->status = GNUNET_LOCKMANAGER_RELEASE; - r->status_cb = status_cb; - r->status_cb_cls = status_cb_cls; - r->acquire_sent = GNUNET_NO; - memcpy (r->domain, domain_name, domain_name_length); - msg = generate_acquire_msg (r->domain, r->lock); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Queueing ACQUIRE message\n"); - r->mqe = queue_message (handle, msg, r); - get_key (r->domain, r->lock, &hash); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (r->handle->hashmap, &hash, - r, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); - return r; -} - - -/** - * Function to cancel the locking request generated by - * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired by us then the lock - * is released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any - * status changes resulting due to this call. - * - * @param request the LockingRequest to cancel - */ -void -GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest - *request) -{ - struct GNUNET_LOCKMANAGER_Message *msg; - struct GNUNET_HashCode hash; - uint16_t msg_size; - size_t domain_name_length; - - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); - if (GNUNET_NO == request->acquire_sent) - { - GNUNET_assert (NULL != request->mqe); - if ((NULL != request->handle->transmit_handle) && - (request->handle->mq_head == request->mqe)) - { - GNUNET_CLIENT_notify_transmit_ready_cancel (request-> - handle->transmit_handle); - request->handle->transmit_handle = NULL; - } - GNUNET_CONTAINER_DLL_remove (request->handle->mq_head, - request->handle->mq_tail, request->mqe); - GNUNET_free (request->mqe->msg); - GNUNET_free (request->mqe); - request->status = GNUNET_LOCKMANAGER_RELEASE; - } - if (GNUNET_LOCKMANAGER_SUCCESS == request->status) - { - domain_name_length = strlen (request->domain) + 1; - msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_length; - msg = GNUNET_malloc (msg_size); - msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE); - msg->header.size = htons (msg_size); - msg->lock = htonl (request->lock); - memcpy (&msg[1], request->domain, domain_name_length); - GNUNET_assert (NULL == request->mqe); - (void) queue_message (request->handle, msg, request); - } - get_key (request->domain, request->lock, &hash); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (request->handle->hashmap, - &hash, request)); - GNUNET_free (request->domain); - GNUNET_free (request); - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); -} - -/* end of lockmanager_api.c */ diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c deleted file mode 100644 index fc538e865..000000000 --- a/src/lockmanager/test_lockmanager_api.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2008--2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file lockmanager/test_lockmanager_api.c - * @brief Test cases for lockmanager_api.c - * @author Sree Harsha Totakura - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_lockmanager_service.h" -#include "gnunet_testing_lib.h" - -/** - * Generic logging shortcut - */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) - -#define TIME_REL_SECONDS(min) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) - - -/** - * Enumeration of testing steps - */ -enum Test -{ - TEST_FAIL, - - TEST_INIT, - - LOCK1_ACQUIRE, - - LOCK2_ACQUIRE -}; - - -/** - * The testing result - */ -static enum Test result; - -/** - * Configuration Handle - */ -static const struct GNUNET_CONFIGURATION_Handle *config; - -/** - * The handle to the lockmanager service - */ -static struct GNUNET_LOCKMANAGER_Handle *handle; - -/** - * The locking request - */ -static struct GNUNET_LOCKMANAGER_LockingRequest *request; - -/** - * The second locking request - */ -static struct GNUNET_LOCKMANAGER_LockingRequest *request2; - -/** - * Abort task identifier - */ -static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; - -/** - * Shutdown nicely - * - * @param cls - * @param tc the task context - */ -static void -do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) - { - GNUNET_SCHEDULER_cancel (abort_task_id); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; - } - if (NULL != request) - GNUNET_LOCKMANAGER_cancel_request (request); - if (NULL != request2) - GNUNET_LOCKMANAGER_cancel_request (request2); - GNUNET_LOCKMANAGER_disconnect (handle); - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Shutdown nicely - * - * @param cls - * @param tc the task context - */ -static void -do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; - result = TEST_FAIL; - do_shutdown (cls, tc); -} - -/** - * Callback for lock status changes - * - * @param cls the closure from GNUNET_LOCKMANAGER_lock call - * - * @param domain_name the locking domain of the lock - * - * @param lock the lock for which this status is relevant - * - * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully - * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost - */ -static void -status_cb (void *cls, const char *domain_name, uint32_t lock, - enum GNUNET_LOCKMANAGER_Status status) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Status change callback called on lock: %d of domain: %s\n", lock, - domain_name); - switch (result) - { - case LOCK1_ACQUIRE: - GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); - GNUNET_assert (NULL != request); - //GNUNET_LOCKMANAGER_cancel_request (request); - //request = NULL; - result = LOCK2_ACQUIRE; - request2 = - GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", - 100, &status_cb, NULL); - GNUNET_assert (NULL != request2); - break; - case LOCK2_ACQUIRE: - GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); - GNUNET_assert (NULL != request); - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); - break; - default: - GNUNET_break (0); - } -} - - -/** - * Main point of test execution - */ -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); - config = cfg; - handle = GNUNET_LOCKMANAGER_connect (config); - GNUNET_assert (NULL != handle); - result = LOCK1_ACQUIRE; - request = - GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, - &status_cb, NULL); - abort_task_id = - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (30), &do_abort, NULL); -} - - -/** - * Main function - */ -int -main (int argc, char **argv) -{ - - if (0 != - GNUNET_TESTING_peer_run ("test_lockmanager_api", - "test_lockmanager_api.conf", &run, NULL)) - return 1; - return (TEST_FAIL == result) ? 1 : 0; -} - -/* end of test_lockmanager_api.c */ diff --git a/src/lockmanager/test_lockmanager_api.conf b/src/lockmanager/test_lockmanager_api.conf deleted file mode 100644 index e6b903f6b..000000000 --- a/src/lockmanager/test_lockmanager_api.conf +++ /dev/null @@ -1,64 +0,0 @@ -[lockmanager] -AUTOSTART = NO -PORT = 12112 -ACCEPT_FROM = 127.0.0.1; -HOSTNAME = localhost -# PREFIX = valgrind --leak-check=full -# PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args - -[fs] -AUTOSTART = NO - -[resolver] -AUTOSTART = NO - -[mesh] -AUTOSTART = NO - -[dht] -AUTOSTART = NO - -[dhtcache] -QUOTA = 1 MB -DATABASE = heap - -[transport] -PLUGINS = tcp -ACCEPT_FROM6 = ::1; -ACCEPT_FROM = 127.0.0.1; -NEIGHBOUR_LIMIT = 50 -PORT = 12365 - -[ats] -WAN_QUOTA_OUT = 3932160 -WAN_QUOTA_IN = 3932160 - -[core] -PORT = 12092 - -[arm] -DEFAULTSERVICES = core lockmanager -PORT = 12366 - -[transport-tcp] -TIMEOUT = 300 s -PORT = 12368 - -[TESTING] -NUM_PEERS = 5 -HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat -MAX_CONCURRENT_SSH = 10 -USE_PROGRESSBARS = YES -PEERGROUP_TIMEOUT = 2400 s - -[PATHS] -SERVICEHOME = /tmp/test-lockmanager/ - -[dns] -AUTOSTART = NO - -[nse] -AUTOSTART = NO - -[consensus] -AUTOSTART = NO diff --git a/src/lockmanager/test_lockmanager_api_acquireretry.c b/src/lockmanager/test_lockmanager_api_acquireretry.c deleted file mode 100644 index 59b4f23e2..000000000 --- a/src/lockmanager/test_lockmanager_api_acquireretry.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2008--2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file lockmanager/test_lockmanager_api_acquireretry.c - * @brief Test cases for lockmanager_api where the server crashes and comes - * back; the api should try to acqurie the lock again - * @author Sree Harsha Totakura - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_lockmanager_service.h" -#include "gnunet_testing_lib.h" - -/** - * Generic logging shorthand - */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) - -/** - * Relative seconds shorthand - */ -#define TIME_REL_SECS(sec) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) - -/** - * Various stages in test - */ -enum Test -{ - /** - * Signal test failure - */ - TEST_FAIL, - - /** - * Testing just began - */ - TEST_INIT, - - /** - * Client has successfully acquired the lock - */ - TEST_CLIENT_LOCK_SUCCESS, - - /** - * Client has lost the lock - */ - TEST_CLIENT_LOCK_RELEASE, - - /** - * Client has again acquired the lock - */ - TEST_CLIENT_LOCK_AGAIN_SUCCESS -}; - -/** - * Configuration Handle - */ -static const struct GNUNET_CONFIGURATION_Handle *config; - -/** - * The handle to the lockmanager service - */ -static struct GNUNET_LOCKMANAGER_Handle *handle; - -/** - * The locking request - */ -static struct GNUNET_LOCKMANAGER_LockingRequest *request; - -/** - * Abort task identifier - */ -static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; - -/** - * The test result - */ -enum Test result; - -/** - * Our peer - */ -static struct GNUNET_TESTING_Peer *self; - - -/** - * Shutdown nicely - * - * @param cls - * @param tc the task context - */ -static void -do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) - { - GNUNET_SCHEDULER_cancel (abort_task_id); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; - } - if (NULL != handle) - GNUNET_LOCKMANAGER_disconnect (handle); -} - -/** - * Abort - * - * @param cls - * @param tc the task context - */ -static void -do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; - result = TEST_FAIL; - do_shutdown (cls, tc); -} - - -/** - * Callback for lock status changes - * - * @param cls the handle - * - * @param domain_name the locking domain of the lock - * - * @param lock the lock for which this status is relevant - * - * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully - * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost - */ -static void -status_cb (void *cls, const char *domain_name, uint32_t lock, - enum GNUNET_LOCKMANAGER_Status status) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Status change callback called on lock: %d of domain: %s\n", lock, - domain_name); - switch (result) - { - case TEST_INIT: - GNUNET_assert (handle == cls); - GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); - result = TEST_CLIENT_LOCK_SUCCESS; - /* We should kill the lockmanager process */ - GNUNET_TESTING_peer_stop (self); - break; - case TEST_CLIENT_LOCK_SUCCESS: - GNUNET_assert (handle == cls); - GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status); - result = TEST_CLIENT_LOCK_RELEASE; - /* Now we should start again the lockmanager process */ - GNUNET_TESTING_peer_start (self); - break; - case TEST_CLIENT_LOCK_RELEASE: - GNUNET_assert (handle == cls); - GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); - result = TEST_CLIENT_LOCK_AGAIN_SUCCESS; - GNUNET_LOCKMANAGER_cancel_request (request); - request = NULL; - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), &do_shutdown, NULL); - break; - default: - GNUNET_assert (0); /* We should never reach here */ - } -} - - -/** - * Main point of test execution - */ -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - config = cfg; - self = peer; - result = TEST_INIT; - handle = GNUNET_LOCKMANAGER_connect (config); - GNUNET_assert (NULL != handle); - request = - GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, - &status_cb, handle); - GNUNET_assert (NULL != request); - abort_task_id = - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (30), &do_abort, NULL); -} - - -/** - * Main function - */ -int -main (int argc, char **argv) -{ - if (0 != - GNUNET_TESTING_peer_run ("test_lockmanager_api_acquireretry", - "test_lockmanager_api.conf", &run, NULL)) - return 1; - return (TEST_CLIENT_LOCK_AGAIN_SUCCESS != result) ? 1 : 0; -} - -/* end of test_lockmanager_api_acquireretry.c */ diff --git a/src/lockmanager/test_lockmanager_api_lockrelease.c b/src/lockmanager/test_lockmanager_api_lockrelease.c deleted file mode 100644 index 2ce7bb228..000000000 --- a/src/lockmanager/test_lockmanager_api_lockrelease.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2008--2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file lockmanager/test_lockmanager_api_lockrelease.c - * @brief Test cases for lockmanager_api where client disconnects abruptly - * @author Sree Harsha Totakura - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testing_lib.h" -#include "gnunet_lockmanager_service.h" - -/** - * Generic Logging shorthand - */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) - -/** - * Relative seconds shorthand - */ -#define TIME_REL_SECONDS(min) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) - -/** - * Various steps of the test - */ -enum Test -{ - /** - * Signal test failure - */ - TEST_FAIL, - - /** - * Testing just began - */ - TEST_INIT, - - /** - * Client 1 has got the lock successfully; Client 2 should try to acquire - * the lock now; after some time client 1 has to release the lock - */ - TEST_CLIENT1_LOCK_SUCCESS, - - /** - * Client 2 has got the lock; Should release it and call shutdown - */ - TEST_CLIENT2_LOCK_SUCCESS, -}; - -/** - * The testing result - */ -static enum Test result; - -/** - * Configuration Handle - */ -static const struct GNUNET_CONFIGURATION_Handle *config; - -/** - * The handle to the lockmanager service - */ -static struct GNUNET_LOCKMANAGER_Handle *handle; - -/** - * A second client handle to the lockmanager service - */ -static struct GNUNET_LOCKMANAGER_Handle *handle2; - -/** - * The locking request - */ -static struct GNUNET_LOCKMANAGER_LockingRequest *request; - -/** - * The locking request of second client - */ -static struct GNUNET_LOCKMANAGER_LockingRequest *request2; - -/** - * Abort task identifier - */ -static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; - - -/** - * Shutdown nicely - * - * @param cls - * @param tc the task context - */ -static void -do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) - { - GNUNET_SCHEDULER_cancel (abort_task_id); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; - } - GNUNET_LOCKMANAGER_disconnect (handle); - GNUNET_LOCKMANAGER_disconnect (handle2); -} - - -/** - * Abort - * - * @param cls - * @param tc the task context - */ -static void -do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; - result = TEST_FAIL; - do_shutdown (cls, tc); -} - - -/** - * Callback for lock status changes - * - * @param cls the handle - * - * @param domain_name the locking domain of the lock - * - * @param lock the lock for which this status is relevant - * - * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully - * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost - */ -static void -status_cb (void *cls, const char *domain_name, uint32_t lock, - enum GNUNET_LOCKMANAGER_Status status) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Status change callback called on lock: %d of domain: %s\n", lock, - domain_name); - GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); - switch (result) - { - case TEST_INIT: - GNUNET_assert (handle == cls); - result = TEST_CLIENT1_LOCK_SUCCESS; - request2 = - GNUNET_LOCKMANAGER_acquire_lock (handle2, "GNUNET_LOCKMANAGER_TESTING", - 99, &status_cb, handle2); - GNUNET_assert (NULL != request2); - GNUNET_LOCKMANAGER_cancel_request (request); - request = NULL; - break; - case TEST_CLIENT1_LOCK_SUCCESS: - GNUNET_assert (handle2 == cls); - result = TEST_CLIENT2_LOCK_SUCCESS; - GNUNET_LOCKMANAGER_cancel_request (request2); - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); - break; - default: - GNUNET_assert (0); /* We should never reach here */ - } - -} - - -/** - * Main point of test execution - */ -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); - config = cfg; - result = TEST_INIT; - handle = GNUNET_LOCKMANAGER_connect (config); - GNUNET_assert (NULL != handle); - handle2 = GNUNET_LOCKMANAGER_connect (config); - - request = - GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, - &status_cb, handle); - GNUNET_assert (NULL != request); - abort_task_id = - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), &do_abort, NULL); -} - - -/** - * Main function - */ -int -main (int argc, char **argv) -{ - if (0 != - GNUNET_TESTING_peer_run ("test_lockmanager_api_lockrelease", - "test_lockmanager_api.conf", &run, NULL)) - return 1; - return (TEST_CLIENT2_LOCK_SUCCESS != result) ? 1 : 0; -} - -/* end of test_lockmanager_api_lockrelease.c */ diff --git a/src/lockmanager/test_lockmanager_api_servercrash.c b/src/lockmanager/test_lockmanager_api_servercrash.c deleted file mode 100644 index ffb90a023..000000000 --- a/src/lockmanager/test_lockmanager_api_servercrash.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2008--2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file lockmanager/test_lockmanager_api_servercrash.c - * @brief Test cases for lockmanager_api where the server crashes - * @author Sree Harsha Totakura - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_lockmanager_service.h" -#include "gnunet_testing_lib.h" - -/** - * Generic logging shorthand - */ -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) - -/** - * Relative seconds shorthand - */ -#define TIME_REL_SECONDS(min) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) - -/** - * Various steps of the test - */ -enum Test -{ - /** - * Signal test failure - */ - TEST_FAIL, - - /** - * Testing just began - */ - TEST_INIT, - - /** - * Client 1 has got the lock successfully; Client 2 should try to acquire - * the lock now; after some time client 1 has to release the lock - */ - TEST_CLIENT1_LOCK_SUCCESS, - - /** - * Client 2 has got the lock; Server should crash now; - */ - TEST_CLIENT2_LOCK_SUCCESS, - - /** - * Client 2 should get lock release due to server crash; Should call - * shutdown now - */ - TEST_CLIENT2_SERVER_CRASH_SUCCESS -}; - -/** - * The testing result - */ -static enum Test result; - -/** - * Configuration Handle - */ -static const struct GNUNET_CONFIGURATION_Handle *config; - -/** - * The handle to the lockmanager service - */ -static struct GNUNET_LOCKMANAGER_Handle *handle; - -/** - * A second client handle to the lockmanager service - */ -static struct GNUNET_LOCKMANAGER_Handle *handle2; - -/** - * The locking request - */ -static struct GNUNET_LOCKMANAGER_LockingRequest *request; - -/** - * The locking request of second client - */ -static struct GNUNET_LOCKMANAGER_LockingRequest *request2; - -/** - * Abort task identifier - */ -static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; - -/** - * Our peer - */ -static struct GNUNET_TESTING_Peer *self; - - -/** - * Shutdown nicely - * - * @param cls - * @param tc the task context - */ -static void -do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) - { - GNUNET_SCHEDULER_cancel (abort_task_id); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; - } - if (NULL != handle) - GNUNET_LOCKMANAGER_disconnect (handle); - if (NULL != handle2) - GNUNET_LOCKMANAGER_disconnect (handle2); -} - - -/** - * Abort - * - * @param cls - * @param tc the task context - */ -static void -do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; - result = TEST_FAIL; - do_shutdown (cls, tc); -} - - -/** - * Callback for lock status changes - * - * @param cls the handle - * - * @param domain_name the locking domain of the lock - * - * @param lock the lock for which this status is relevant - * - * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully - * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost - */ -static void -status_cb (void *cls, const char *domain_name, uint32_t lock, - enum GNUNET_LOCKMANAGER_Status status) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Status change callback called on lock: %d of domain: %s\n", lock, - domain_name); - switch (result) - { - case TEST_INIT: - GNUNET_assert (handle == cls); - GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); - result = TEST_CLIENT1_LOCK_SUCCESS; - request2 = - GNUNET_LOCKMANAGER_acquire_lock (handle2, "GNUNET_LOCKMANAGER_TESTING", - 99, &status_cb, handle2); - GNUNET_assert (NULL != request2); - GNUNET_LOCKMANAGER_cancel_request (request); - request = NULL; - break; - case TEST_CLIENT1_LOCK_SUCCESS: - GNUNET_assert (handle2 == cls); - GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); - result = TEST_CLIENT2_LOCK_SUCCESS; - /* We should stop our peer to simulate crash in lockmanager service */ - GNUNET_TESTING_peer_stop (self); - break; - case TEST_CLIENT2_LOCK_SUCCESS: - GNUNET_assert (handle2 == cls); - GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status); - GNUNET_assert (99 == lock); - GNUNET_assert (0 == strcmp (domain_name, "GNUNET_LOCKMANAGER_TESTING")); - result = TEST_CLIENT2_SERVER_CRASH_SUCCESS; - GNUNET_LOCKMANAGER_cancel_request (request2); - request2 = NULL; - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); - break; - default: - GNUNET_assert (0); /* We should never reach here */ - } -} - - -/** - * Main point of test execution - */ -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - config = cfg; - self = peer; - result = TEST_INIT; - handle = GNUNET_LOCKMANAGER_connect (config); - GNUNET_assert (NULL != handle); - handle2 = GNUNET_LOCKMANAGER_connect (config); - - request = - GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, - &status_cb, handle); - GNUNET_assert (NULL != request); - abort_task_id = - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), &do_abort, NULL); -} - - -/** - * Main function - */ -int -main (int argc, char **argv) -{ - if (0 != - GNUNET_TESTING_peer_run ("test_lockmanager_api_servercrash", - "test_lockmanager_api.conf", &run, NULL)) - return 1; - return (TEST_CLIENT2_SERVER_CRASH_SUCCESS != result) ? 1 : 0; -} - -/* end of test_lockmanager_api_servercrash.c */ diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 7022098f7..9133851ca 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c @@ -31,7 +31,7 @@ * peers that connect. * * TODO: - * - handle p2p revocations + * - broadcast p2p revocations * - handle p2p connect (trigger SET union) */ #include "platform.h" -- cgit v1.2.3