diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-04-26 16:17:49 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-04-26 16:17:49 +0000 |
commit | b359f8b639e14efeb5ae54d43395a249f9859536 (patch) | |
tree | efc2da0d84f24ad91021ea442e12f55eb170f969 /src/lockmanager | |
parent | 21808116e6a8c87e100f0f382bf8d22d61aa75e8 (diff) | |
download | gnunet-b359f8b639e14efeb5ae54d43395a249f9859536.tar.gz gnunet-b359f8b639e14efeb5ae54d43395a249f9859536.zip |
-lockmanager build skeleton
Diffstat (limited to 'src/lockmanager')
-rw-r--r-- | src/lockmanager/Makefile.am | 38 | ||||
-rw-r--r-- | src/lockmanager/README | 9 | ||||
-rw-r--r-- | src/lockmanager/gnunet-service-lockmanager.c | 119 | ||||
-rw-r--r-- | src/lockmanager/lockmanager.conf.in | 13 | ||||
-rw-r--r-- | src/lockmanager/lockmanager.h | 71 | ||||
-rw-r--r-- | src/lockmanager/lockmanager_api.c | 80 |
6 files changed, 326 insertions, 4 deletions
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 @@ | |||
1 | INCLUDES = -I$(top_srcdir)/src/include | ||
2 | |||
3 | if MINGW | ||
4 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | ||
5 | endif | ||
6 | |||
7 | if USE_COVERAGE | ||
8 | AM_CFLAGS = --coverage -O0 | ||
9 | XLIB = -lgcov | ||
10 | endif | ||
11 | |||
12 | pkgcfgdir= $(pkgdatadir)/config.d/ | ||
13 | |||
14 | pkgcfg_DATA = \ | ||
15 | lockmanager.conf | ||
16 | |||
17 | bin_PROGRAMS = \ | ||
18 | gnunet-service-lockmanager | ||
19 | |||
20 | lib_LTLIBRARIES = \ | ||
21 | libgnunetlockmanager.la | ||
22 | |||
23 | gnunet_service_lockmanager_SOURCES = \ | ||
24 | gnunet-service-lockmanager.c \ | ||
25 | lockmanager.h | ||
26 | gnunet_service_lockmanager_LDADD = \ | ||
27 | $(top_builddir)/src/util/libgnunetutil.la | ||
28 | gnunet_service_lockmanager_DEPENDENCIES = \ | ||
29 | $(top_builddir)/src/util/libgnunetutil.la | ||
30 | |||
31 | libgnunetlockmanager_la_SOURCES = \ | ||
32 | lockmanager_api.c lockmanager.h | ||
33 | libgnunetlockmanager_la_LIBADD = \ | ||
34 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
35 | $(XLIB) | ||
36 | libgnunetlockmanager_la_LDFLAGS = \ | ||
37 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | ||
38 | -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 | |||
3 | checks upon a resource which should be protected from concurrent access. | 3 | checks upon a resource which should be protected from concurrent access. |
4 | 4 | ||
5 | Locking is managed through locking-domains. A locking-domain is a string which | 5 | Locking is managed through locking-domains. A locking-domain is a string which |
6 | uniquely identifies a group of locks. Locks are represented as unsigned | 6 | uniquely identifies a group of locks. Locks are represented as unsigned 32-bit |
7 | integers. When a critical resource has to be protected against simulataneous | 7 | integers. When a critical resource has to be protected against simulataneous |
8 | access by 2 programs. Both of them should connect to the lockmanager using the | 8 | access by 2 programs, both of them should connect to the lockmanager using the |
9 | same locking-domain and try to lock a lock. Since only one of them can acquire | 9 | same locking-domain and try to acquire a lock with the same number. Since only |
10 | the lock the other will be denied locking until the other releases it. \ No newline at end of file | 10 | one of them can acquire the lock the other will be denied locking until the |
11 | 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file lockmanager/gnunet-service-lockmanager.c | ||
23 | * @brief implementation of the LOCKMANAGER service | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_common.h" | ||
29 | #include "gnunet_protocols.h" | ||
30 | #include "gnunet_service_lib.h" | ||
31 | #include "gnunet_server_lib.h" | ||
32 | |||
33 | #include "lockmanager.h" | ||
34 | |||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log_from (kind, "gnunet-service-lockmanager",__VA_ARGS__) | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Handler for GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE | ||
41 | * | ||
42 | * @param | ||
43 | * @return | ||
44 | */ | ||
45 | static void | ||
46 | handle_acquire (void *cls, | ||
47 | struct GNUNET_SERVER_Client *client, | ||
48 | const struct GNUNET_MessageHeader *message) | ||
49 | { | ||
50 | // const struct GNUNET_LOCKMANAGER_Message *msg = message; | ||
51 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
52 | "Received a ACQUIRE message\n"); | ||
53 | |||
54 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
55 | } | ||
56 | |||
57 | |||
58 | /** | ||
59 | * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE | ||
60 | * | ||
61 | * @param | ||
62 | * @return | ||
63 | */ | ||
64 | static void | ||
65 | handle_release (void *cls, | ||
66 | struct GNUNET_SERVER_Client *client, | ||
67 | const struct GNUNET_MessageHeader *message) | ||
68 | { | ||
69 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
70 | "Received a RELEASE message\n"); | ||
71 | |||
72 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
73 | } | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Lock manager setup | ||
78 | * | ||
79 | * @param cls closure | ||
80 | * @param server the initialized server | ||
81 | * @param cfg configuration to use | ||
82 | */ | ||
83 | static void | ||
84 | lockmanager_run (void *cls, | ||
85 | struct GNUNET_SERVER_Handle * server, | ||
86 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
87 | { | ||
88 | struct GNUNET_SERVER_MessageHandler message_handlers[] = | ||
89 | { | ||
90 | {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0}, | ||
91 | {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0}, | ||
92 | {NULL} | ||
93 | }; | ||
94 | |||
95 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lockmanager\n"); | ||
96 | GNUNET_SERVER_add_handlers (server, | ||
97 | message_handlers); | ||
98 | |||
99 | } | ||
100 | |||
101 | /** | ||
102 | * The starting point of execution | ||
103 | */ | ||
104 | int main (int argc, char *const *argv) | ||
105 | { | ||
106 | int ret; | ||
107 | |||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n"); | ||
109 | ret = | ||
110 | (GNUNET_OK == | ||
111 | GNUNET_SERVICE_run (argc, | ||
112 | argv, | ||
113 | "lockmanager", | ||
114 | GNUNET_SERVICE_OPTION_NONE, | ||
115 | &lockmanager_run, | ||
116 | NULL)) ? 0 : 1; | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n"); | ||
118 | return ret; | ||
119 | } | ||
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 @@ | |||
1 | [lockmanager] | ||
2 | AUTOSTART = YES | ||
3 | @UNIXONLY@ PORT = 2100 | ||
4 | HOSTNAME = localhost | ||
5 | HOME = $SERVICEHOME | ||
6 | CONFIG = $DEFAULTCONFIG | ||
7 | BINARY = gnunet-service-lockmanger | ||
8 | ACCEPT_FROM = 127.0.0.1; | ||
9 | ACCEPT_FROM6 = ::1; | ||
10 | UNIXPATH = /tmp/gnunet-service-lockmanager.sock | ||
11 | UNIX_MATCH_UID = YES | ||
12 | UNIX_MATCH_GID = YES | ||
13 | |||
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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file lockmanager/lockmanager.h | ||
23 | * @brief client-server protocol messages for LOCKMANAGER service | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #ifndef LOCKMANAGER_H | ||
28 | #define LOCKMANAGER_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_common.h" | ||
39 | |||
40 | /** | ||
41 | * Structure of Lockmanager message | ||
42 | */ | ||
43 | struct GNUNET_LOCKMANAGER_Message | ||
44 | { | ||
45 | /** | ||
46 | * The generic message header | ||
47 | */ | ||
48 | struct GNUNET_MessageHeader header; | ||
49 | |||
50 | /** | ||
51 | * The lock | ||
52 | */ | ||
53 | uint32_t lock; | ||
54 | |||
55 | /** | ||
56 | * The locking domain name(NULL terminated string of characters) should | ||
57 | * follow here. The size of the header should include the size of this string | ||
58 | * with its trailing NULL | ||
59 | */ | ||
60 | }; | ||
61 | |||
62 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
63 | { | ||
64 | #endif | ||
65 | #ifdef __cplusplus | ||
66 | } | ||
67 | #endif | ||
68 | |||
69 | /* ifndef LOCKMANAGER_H */ | ||
70 | #endif | ||
71 | /* 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file lockmanager/lockmanager_api.c | ||
23 | * @brief API implementation of gnunet_lockmanager_service.h | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_common.h" | ||
29 | #include "gnunet_protocols.h" | ||
30 | #include "gnunet_client_lib.h" | ||
31 | |||
32 | #include "lockmanager.h" | ||
33 | |||
34 | #define LOG(kind,...) \ | ||
35 | GNUNET_log_from (kind, "gnunet-service-lockmanager",__VA_ARGS__) | ||
36 | |||
37 | /** | ||
38 | * Handler for the lockmanager service | ||
39 | */ | ||
40 | struct GNUNET_LOCKMANAGER_Handle | ||
41 | { | ||
42 | /** | ||
43 | * The client connection to the service | ||
44 | */ | ||
45 | struct GNUNET_CLIENT_Connection *conn; | ||
46 | }; | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Connect to the lockmanager service | ||
51 | * | ||
52 | * @param cfg the configuration to use | ||
53 | * | ||
54 | * @return upon success the handle to the service; NULL upon error | ||
55 | */ | ||
56 | struct GNUNET_LOCKMANAGER_Handle * | ||
57 | GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
58 | { | ||
59 | struct GNUNET_LOCKMANAGER_Handle *h; | ||
60 | |||
61 | h = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_Handle)); | ||
62 | h->conn = GNUNET_CLIENT_connect ("lockmanager", cfg); | ||
63 | if (NULL == h->conn) | ||
64 | { | ||
65 | GNUNET_free (h); | ||
66 | return NULL; | ||
67 | } | ||
68 | return NULL; | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * Disconnect from the lockmanager service | ||
73 | * | ||
74 | * @param handle the handle to the lockmanager service | ||
75 | */ | ||
76 | void | ||
77 | GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) | ||
78 | { | ||
79 | |||
80 | } | ||