From b359f8b639e14efeb5ae54d43395a249f9859536 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Thu, 26 Apr 2012 16:17:49 +0000 Subject: [PATCH] -lockmanager build skeleton --- src/lockmanager/Makefile.am | 38 ++++++ src/lockmanager/README | 9 +- src/lockmanager/gnunet-service-lockmanager.c | 119 +++++++++++++++++++ src/lockmanager/lockmanager.conf.in | 13 ++ src/lockmanager/lockmanager.h | 71 +++++++++++ src/lockmanager/lockmanager_api.c | 80 +++++++++++++ 6 files changed, 326 insertions(+), 4 deletions(-) create mode 100644 src/lockmanager/Makefile.am create mode 100644 src/lockmanager/gnunet-service-lockmanager.c create mode 100644 src/lockmanager/lockmanager.conf.in create mode 100644 src/lockmanager/lockmanager.h create mode 100644 src/lockmanager/lockmanager_api.c diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am new file mode 100644 index 000000000..d6e3a5e4e --- /dev/null +++ b/src/lockmanager/Makefile.am @@ -0,0 +1,38 @@ +INCLUDES = -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/ + +pkgcfg_DATA = \ + lockmanager.conf + +bin_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) +libgnunetlockmanager_la_LDFLAGS = \ + $(GN_LIB_LDFLAGS) $(WINFLAGS) \ + -version-info 0:0:0 \ No newline at end of file diff --git a/src/lockmanager/README b/src/lockmanager/README index ef38e990c..8d9339e4d 100644 --- a/src/lockmanager/README +++ b/src/lockmanager/README @@ -3,8 +3,9 @@ programs. This service eliminates the need for programs to maintain their own checks upon a resource which should be protected from concurrent access. Locking is managed through locking-domains. A locking-domain is a string which -uniquely identifies a group of locks. Locks are represented as unsigned +uniquely identifies a group of locks. Locks are represented as unsigned 32-bit integers. When a critical resource has to be protected against simulataneous -access by 2 programs. Both of them should connect to the lockmanager using the -same locking-domain and try to lock a lock. Since only one of them can acquire -the lock the other will be denied locking until the other releases it. \ No newline at end of file +access by 2 programs, both of them should connect to the lockmanager using the +same locking-domain and try to acquire a lock with the same number. Since only +one of them can acquire the lock the other will be denied locking until the +it the lock is released. \ No newline at end of file diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c new file mode 100644 index 000000000..1c228cc3a --- /dev/null +++ b/src/lockmanager/gnunet-service-lockmanager.c @@ -0,0 +1,119 @@ +/* + This file is part of GNUnet. + (C) 2012 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 2, 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_common.h" +#include "gnunet_protocols.h" +#include "gnunet_service_lib.h" +#include "gnunet_server_lib.h" + +#include "lockmanager.h" + +#define LOG(kind,...) \ + GNUNET_log_from (kind, "gnunet-service-lockmanager",__VA_ARGS__) + + +/** + * Handler for GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE + * + * @param + * @return + */ +static void +handle_acquire (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + // const struct GNUNET_LOCKMANAGER_Message *msg = message; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received a ACQUIRE message\n"); + + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + + +/** + * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE + * + * @param + * @return + */ +static void +handle_release (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received a RELEASE message\n"); + + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + + +/** + * 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) +{ + 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} + }; + + LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lockmanager\n"); + GNUNET_SERVER_add_handlers (server, + message_handlers); + +} + +/** + * The starting point of execution + */ +int main (int argc, char *const *argv) +{ + int ret; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n"); + ret = + (GNUNET_OK == + GNUNET_SERVICE_run (argc, + argv, + "lockmanager", + GNUNET_SERVICE_OPTION_NONE, + &lockmanager_run, + NULL)) ? 0 : 1; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n"); + return ret; +} diff --git a/src/lockmanager/lockmanager.conf.in b/src/lockmanager/lockmanager.conf.in new file mode 100644 index 000000000..6a91b3e25 --- /dev/null +++ b/src/lockmanager/lockmanager.conf.in @@ -0,0 +1,13 @@ +[lockmanager] +AUTOSTART = YES +@UNIXONLY@ PORT = 2100 +HOSTNAME = localhost +HOME = $SERVICEHOME +CONFIG = $DEFAULTCONFIG +BINARY = gnunet-service-lockmanger +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 new file mode 100644 index 000000000..346c43eb2 --- /dev/null +++ b/src/lockmanager/lockmanager.h @@ -0,0 +1,71 @@ +/* + This file is part of GNUnet. + (C) 2012 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 2, 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 new file mode 100644 index 000000000..e8d18666b --- /dev/null +++ b/src/lockmanager/lockmanager_api.c @@ -0,0 +1,80 @@ +/* + This file is part of GNUnet. + (C) 2012 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 2, 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_common.h" +#include "gnunet_protocols.h" +#include "gnunet_client_lib.h" + +#include "lockmanager.h" + +#define LOG(kind,...) \ + GNUNET_log_from (kind, "gnunet-service-lockmanager",__VA_ARGS__) + +/** + * Handler for the lockmanager service + */ +struct GNUNET_LOCKMANAGER_Handle +{ + /** + * The client connection to the service + */ + struct GNUNET_CLIENT_Connection *conn; +}; + + +/** + * 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; + + h = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_Handle)); + h->conn = GNUNET_CLIENT_connect ("lockmanager", cfg); + if (NULL == h->conn) + { + GNUNET_free (h); + return NULL; + } + return NULL; +} + +/** + * Disconnect from the lockmanager service + * + * @param handle the handle to the lockmanager service + */ +void +GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) +{ + +} -- 2.25.1