diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-06 12:19:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-06 12:19:35 +0000 |
commit | 42c6c351a1e6a8f568e53b34ad95d108c7db34c8 (patch) | |
tree | 10831714fdd8321d36221a1f2e99d0edd9f08023 | |
parent | fc782c430e718d6213ca90620cdf89adf2fa0825 (diff) | |
download | gnunet-42c6c351a1e6a8f568e53b34ad95d108c7db34c8.tar.gz gnunet-42c6c351a1e6a8f568e53b34ad95d108c7db34c8.zip |
-more dead code elimination / house cleaning
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | pkgconfig/gnunetlockmanager.pc.in | 12 | ||||
-rw-r--r-- | pkgconfig/gnunetstream.pc.in | 12 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/include/gnunet_chat_service.h | 253 | ||||
-rw-r--r-- | src/lockmanager/Makefile.am | 84 | ||||
-rw-r--r-- | src/lockmanager/gnunet-service-lockmanager.c | 847 | ||||
-rw-r--r-- | src/lockmanager/lockmanager.conf.in | 12 | ||||
-rw-r--r-- | src/lockmanager/lockmanager.h | 71 | ||||
-rw-r--r-- | src/lockmanager/lockmanager_api.c | 729 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api.c | 202 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api.conf | 64 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_acquireretry.c | 224 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_lockrelease.c | 223 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_servercrash.c | 246 | ||||
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 2 |
16 files changed, 1 insertions, 2985 deletions
diff --git a/configure.ac b/configure.ac index 78c07fa48..78da6668f 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1352,8 +1352,6 @@ src/include/Makefile | |||
1352 | src/include/gnunet_directories.h | 1352 | src/include/gnunet_directories.h |
1353 | src/integration-tests/Makefile | 1353 | src/integration-tests/Makefile |
1354 | src/hostlist/Makefile | 1354 | src/hostlist/Makefile |
1355 | src/lockmanager/Makefile | ||
1356 | src/lockmanager/lockmanager.conf | ||
1357 | src/mesh/Makefile | 1355 | src/mesh/Makefile |
1358 | src/mesh/mesh.conf | 1356 | src/mesh/mesh.conf |
1359 | src/multicast/Makefile | 1357 | src/multicast/Makefile |
@@ -1410,7 +1408,6 @@ pkgconfig/gnunetfragmentation.pc | |||
1410 | pkgconfig/gnunetfs.pc | 1408 | pkgconfig/gnunetfs.pc |
1411 | pkgconfig/gnunetgns.pc | 1409 | pkgconfig/gnunetgns.pc |
1412 | pkgconfig/gnunethello.pc | 1410 | pkgconfig/gnunethello.pc |
1413 | pkgconfig/gnunetlockmanager.pc | ||
1414 | pkgconfig/gnunetmesh.pc | 1411 | pkgconfig/gnunetmesh.pc |
1415 | pkgconfig/gnunetmysql.pc | 1412 | pkgconfig/gnunetmysql.pc |
1416 | pkgconfig/gnunetnamestore.pc | 1413 | pkgconfig/gnunetnamestore.pc |
@@ -1420,7 +1417,6 @@ pkgconfig/gnunetpeerinfo.pc | |||
1420 | pkgconfig/gnunetpostgres.pc | 1417 | pkgconfig/gnunetpostgres.pc |
1421 | pkgconfig/gnunetregex.pc | 1418 | pkgconfig/gnunetregex.pc |
1422 | pkgconfig/gnunetstatistics.pc | 1419 | pkgconfig/gnunetstatistics.pc |
1423 | pkgconfig/gnunetstream.pc | ||
1424 | pkgconfig/gnunettestbed.pc | 1420 | pkgconfig/gnunettestbed.pc |
1425 | pkgconfig/gnunettesting.pc | 1421 | pkgconfig/gnunettesting.pc |
1426 | pkgconfig/gnunettransport.pc | 1422 | pkgconfig/gnunettransport.pc |
diff --git a/pkgconfig/gnunetlockmanager.pc.in b/pkgconfig/gnunetlockmanager.pc.in deleted file mode 100644 index d2c4f7be1..000000000 --- a/pkgconfig/gnunetlockmanager.pc.in +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | prefix=@prefix@ | ||
2 | exec_prefix=@exec_prefix@ | ||
3 | libdir=@libdir@ | ||
4 | includedir=@includedir@ | ||
5 | |||
6 | Name: GNUnet Lockmanager | ||
7 | Description: Provides API for mutual exclusion between GNUnet services | ||
8 | URL: http://gnunet.org | ||
9 | Version: @VERSION@ | ||
10 | Requires: | ||
11 | Libs: -L${libdir} -lgnunetlockmanager | ||
12 | Cflags: -I${includedir} | ||
diff --git a/pkgconfig/gnunetstream.pc.in b/pkgconfig/gnunetstream.pc.in deleted file mode 100644 index 47c4dde07..000000000 --- a/pkgconfig/gnunetstream.pc.in +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | prefix=@prefix@ | ||
2 | exec_prefix=@exec_prefix@ | ||
3 | libdir=@libdir@ | ||
4 | includedir=@includedir@ | ||
5 | |||
6 | Name: GNUnet Stream | ||
7 | Description: Provides API for reliable, in-order communcation between two peers | ||
8 | URL: http://gnunet.org | ||
9 | Version: @VERSION@ | ||
10 | Requires: | ||
11 | Libs: -L${libdir} -lgnunetstream | ||
12 | Cflags: -I${includedir} | ||
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 = \ | |||
66 | topology \ | 66 | topology \ |
67 | regex \ | 67 | regex \ |
68 | mesh \ | 68 | mesh \ |
69 | lockmanager \ | ||
70 | dns \ | 69 | dns \ |
71 | identity \ | 70 | identity \ |
72 | set \ | 71 | 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2011 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 3, 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 include/gnunet_chat_service.h | ||
23 | * @brief API for chatting via GNUnet | ||
24 | * @author Christian Grothoff | ||
25 | * @author Nathan Evans | ||
26 | * @author Vitaly Minko | ||
27 | */ | ||
28 | |||
29 | #ifndef GNUNET_CHAT_SERVICE_H | ||
30 | #define GNUNET_CHAT_SERVICE_H | ||
31 | |||
32 | #include "gnunet_util_lib.h" | ||
33 | |||
34 | #ifdef __cplusplus | ||
35 | extern "C" | ||
36 | { | ||
37 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
38 | } | ||
39 | #endif | ||
40 | #endif | ||
41 | |||
42 | |||
43 | #define GNUNET_CHAT_VERSION 0x00000003 | ||
44 | #define MAX_MESSAGE_LENGTH (32 * 1024) | ||
45 | |||
46 | /** | ||
47 | * Options for messaging. Compatible options can be OR'ed together. | ||
48 | */ | ||
49 | enum GNUNET_CHAT_MsgOptions | ||
50 | { | ||
51 | /** | ||
52 | * No special options. | ||
53 | */ | ||
54 | GNUNET_CHAT_MSG_OPTION_NONE = 0, | ||
55 | |||
56 | /** | ||
57 | * Encrypt the message so that only the receiver can decrypt it. | ||
58 | */ | ||
59 | GNUNET_CHAT_MSG_PRIVATE = 1, | ||
60 | |||
61 | /** | ||
62 | * Hide the identity of the sender. | ||
63 | */ | ||
64 | GNUNET_CHAT_MSG_ANONYMOUS = 2, | ||
65 | |||
66 | /** | ||
67 | * Sign the content, authenticating the sender (using the provided private | ||
68 | * key, which may represent a pseudonym). | ||
69 | */ | ||
70 | GNUNET_CHAT_MSG_AUTHENTICATED = 4, | ||
71 | |||
72 | /** | ||
73 | * Require signed acknowledgment before completing delivery (and of course, | ||
74 | * only acknowledge if delivery is guaranteed). | ||
75 | */ | ||
76 | GNUNET_CHAT_MSG_ACKNOWLEDGED = 8, | ||
77 | |||
78 | /** | ||
79 | * Authenticate for the receiver, but ensure that receiver cannot prove | ||
80 | * authenticity to third parties later. (not yet implemented) | ||
81 | */ | ||
82 | GNUNET_CHAT_MSG_OFF_THE_RECORD = 16, | ||
83 | |||
84 | }; | ||
85 | |||
86 | /** | ||
87 | * Handle for a (joined) chat room. | ||
88 | */ | ||
89 | struct GNUNET_CHAT_Room; | ||
90 | |||
91 | /** | ||
92 | * Callback used for notification that we have joined the room. | ||
93 | * | ||
94 | * @param cls closure | ||
95 | * @return GNUNET_OK | ||
96 | */ | ||
97 | typedef int (*GNUNET_CHAT_JoinCallback) (void *cls); | ||
98 | |||
99 | /** | ||
100 | * Callback used for notification about incoming messages. | ||
101 | * | ||
102 | * @param cls closure | ||
103 | * @param room in which room was the message received? | ||
104 | * @param sender what is the ID of the sender? (maybe NULL) | ||
105 | * @param member_info information about the joining member | ||
106 | * @param message the message text | ||
107 | * @param timestamp when was the message sent? | ||
108 | * @param options options for the message | ||
109 | * @return GNUNET_OK to accept the message now, GNUNET_NO to | ||
110 | * accept (but user is away), GNUNET_SYSERR to signal denied delivery | ||
111 | */ | ||
112 | typedef int (*GNUNET_CHAT_MessageCallback) (void *cls, | ||
113 | struct GNUNET_CHAT_Room * room, | ||
114 | const struct GNUNET_HashCode * sender, | ||
115 | const struct | ||
116 | GNUNET_CONTAINER_MetaData * | ||
117 | member_info, const char *message, | ||
118 | struct GNUNET_TIME_Absolute | ||
119 | timestamp, | ||
120 | enum GNUNET_CHAT_MsgOptions | ||
121 | options); | ||
122 | |||
123 | /** | ||
124 | * Callback used for notification that another room member has joined or left. | ||
125 | * | ||
126 | * @param cls closure | ||
127 | * @param member_info will be non-null if the member is joining, NULL if he is | ||
128 | * leaving | ||
129 | * @param member_id hash of public key of the user (for unique identification) | ||
130 | * @param options what types of messages is this member willing to receive? | ||
131 | * @return GNUNET_OK | ||
132 | */ | ||
133 | typedef int (*GNUNET_CHAT_MemberListCallback) (void *cls, | ||
134 | const struct | ||
135 | GNUNET_CONTAINER_MetaData * | ||
136 | member_info, | ||
137 | const struct | ||
138 | GNUNET_CRYPTO_RsaPublicKey | ||
139 | * member_id, | ||
140 | enum GNUNET_CHAT_MsgOptions | ||
141 | options); | ||
142 | |||
143 | /** | ||
144 | * Callback used for message delivery confirmations. | ||
145 | * | ||
146 | * @param cls closure | ||
147 | * @param room in which room was the message received? | ||
148 | * @param orig_seq_number sequence number of the original message | ||
149 | * @param timestamp when was the message received? | ||
150 | * @param receiver who is confirming the receipt? | ||
151 | * @return GNUNET_OK to continue, GNUNET_SYSERR to refuse processing further | ||
152 | * confirmations from anyone for this message | ||
153 | */ | ||
154 | typedef int (*GNUNET_CHAT_MessageConfirmation) (void *cls, | ||
155 | struct GNUNET_CHAT_Room * room, | ||
156 | uint32_t orig_seq_number, | ||
157 | struct GNUNET_TIME_Absolute | ||
158 | timestamp, | ||
159 | const struct GNUNET_HashCode * | ||
160 | receiver); | ||
161 | |||
162 | /** | ||
163 | * Join a chat room. | ||
164 | * | ||
165 | * @param cfg configuration | ||
166 | * @param nick_name nickname of the user joining (used to | ||
167 | * determine which public key to use); | ||
168 | * the nickname should probably also | ||
169 | * be used in the member_info (as "EXTRACTOR_TITLE") | ||
170 | * @param member_info information about the joining member | ||
171 | * @param room_name name of the room | ||
172 | * @param msg_options message options of the joining user | ||
173 | * @param joinCallback which function to call when we've joined the room | ||
174 | * @param join_cls argument to callback | ||
175 | * @param messageCallback which function to call if a message has | ||
176 | * been received? | ||
177 | * @param message_cls argument to callback | ||
178 | * @param memberCallback which function to call for join/leave notifications | ||
179 | * @param member_cls argument to callback | ||
180 | * @param confirmationCallback which function to call for confirmations | ||
181 | * (maybe NULL) | ||
182 | * @param confirmation_cls argument to callback | ||
183 | * @param me member ID (pseudonym) | ||
184 | * @return NULL on error | ||
185 | */ | ||
186 | struct GNUNET_CHAT_Room * | ||
187 | GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
188 | const char *nick_name, | ||
189 | struct GNUNET_CONTAINER_MetaData *member_info, | ||
190 | const char *room_name, | ||
191 | enum GNUNET_CHAT_MsgOptions msg_options, | ||
192 | GNUNET_CHAT_JoinCallback joinCallback, void *join_cls, | ||
193 | GNUNET_CHAT_MessageCallback messageCallback, | ||
194 | void *message_cls, | ||
195 | GNUNET_CHAT_MemberListCallback memberCallback, | ||
196 | void *member_cls, | ||
197 | GNUNET_CHAT_MessageConfirmation confirmationCallback, | ||
198 | void *confirmation_cls, struct GNUNET_HashCode * me); | ||
199 | |||
200 | /** | ||
201 | * Send a message. | ||
202 | * | ||
203 | * @param room handle for the chat room | ||
204 | * @param message message to be sent | ||
205 | * @param options options for the message | ||
206 | * @param receiver use NULL to send to everyone in the room | ||
207 | * @param sequence_number where to write the sequence id of the message | ||
208 | */ | ||
209 | void | ||
210 | GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, const char *message, | ||
211 | enum GNUNET_CHAT_MsgOptions options, | ||
212 | const struct GNUNET_CRYPTO_RsaPublicKey | ||
213 | *receiver, uint32_t * sequence_number); | ||
214 | |||
215 | |||
216 | /** | ||
217 | * Leave a chat room. | ||
218 | */ | ||
219 | void | ||
220 | GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room); | ||
221 | |||
222 | |||
223 | #if 0 | ||
224 | /* these are not yet implemented / supported */ | ||
225 | /** | ||
226 | * Callback function to iterate over rooms. | ||
227 | * | ||
228 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | ||
229 | */ | ||
230 | typedef int (*GNUNET_CHAT_RoomIterator) (const char *room, const char *topic, | ||
231 | void *cls); | ||
232 | |||
233 | /** | ||
234 | * List all of the (publically visible) chat rooms. | ||
235 | * @return number of rooms on success, GNUNET_SYSERR if iterator aborted | ||
236 | */ | ||
237 | int | ||
238 | GNUNET_CHAT_list_rooms (struct GNUNET_GE_Context *ectx, | ||
239 | struct GNUNET_GC_Configuration *cfg, | ||
240 | GNUNET_CHAT_RoomIterator it, void *cls); | ||
241 | #endif | ||
242 | |||
243 | |||
244 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
245 | { | ||
246 | #endif | ||
247 | #ifdef __cplusplus | ||
248 | } | ||
249 | #endif | ||
250 | |||
251 | #endif | ||
252 | |||
253 | /* 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 @@ | |||
1 | AM_CPPFLAGS = -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 | libexecdir= $(pkglibdir)/libexec/ | ||
15 | |||
16 | pkgcfg_DATA = \ | ||
17 | lockmanager.conf | ||
18 | |||
19 | libexec_PROGRAMS = \ | ||
20 | gnunet-service-lockmanager | ||
21 | |||
22 | lib_LTLIBRARIES = \ | ||
23 | libgnunetlockmanager.la | ||
24 | |||
25 | gnunet_service_lockmanager_SOURCES = \ | ||
26 | gnunet-service-lockmanager.c \ | ||
27 | lockmanager.h | ||
28 | gnunet_service_lockmanager_LDADD = \ | ||
29 | $(top_builddir)/src/util/libgnunetutil.la | ||
30 | gnunet_service_lockmanager_DEPENDENCIES = \ | ||
31 | $(top_builddir)/src/util/libgnunetutil.la | ||
32 | |||
33 | libgnunetlockmanager_la_SOURCES = \ | ||
34 | lockmanager_api.c lockmanager.h | ||
35 | libgnunetlockmanager_la_LIBADD = \ | ||
36 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
37 | $(XLIB) \ | ||
38 | $(LTLIBINTL) | ||
39 | libgnunetlockmanager_la_LDFLAGS = \ | ||
40 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | ||
41 | -version-info 0:0:0 | ||
42 | |||
43 | if HAVE_TESTING | ||
44 | check_PROGRAMS = \ | ||
45 | test_lockmanager_api \ | ||
46 | test_lockmanager_api_lockrelease \ | ||
47 | test_lockmanager_api_servercrash \ | ||
48 | test_lockmanager_api_acquireretry | ||
49 | endif | ||
50 | |||
51 | EXTRA_DIST = \ | ||
52 | test_lockmanager_api.conf | ||
53 | |||
54 | if ENABLE_TEST_RUN | ||
55 | TESTS = $(check_PROGRAMS) | ||
56 | endif | ||
57 | |||
58 | test_lockmanager_api_SOURCES = \ | ||
59 | test_lockmanager_api.c | ||
60 | test_lockmanager_api_LDADD = \ | ||
61 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
62 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
63 | libgnunetlockmanager.la | ||
64 | |||
65 | test_lockmanager_api_lockrelease_SOURCES = \ | ||
66 | test_lockmanager_api_lockrelease.c | ||
67 | test_lockmanager_api_lockrelease_LDADD = \ | ||
68 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
69 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
70 | libgnunetlockmanager.la | ||
71 | |||
72 | test_lockmanager_api_servercrash_SOURCES = \ | ||
73 | test_lockmanager_api_servercrash.c | ||
74 | test_lockmanager_api_servercrash_LDADD = \ | ||
75 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
76 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
77 | libgnunetlockmanager.la | ||
78 | |||
79 | test_lockmanager_api_acquireretry_SOURCES = \ | ||
80 | test_lockmanager_api_acquireretry.c | ||
81 | test_lockmanager_api_acquireretry_LDADD = \ | ||
82 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
83 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
84 | 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008--2013 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 3, 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_util_lib.h" | ||
29 | #include "gnunet_protocols.h" | ||
30 | |||
31 | #include "lockmanager.h" | ||
32 | |||
33 | |||
34 | #define LOG(kind,...) \ | ||
35 | GNUNET_log (kind, __VA_ARGS__) | ||
36 | |||
37 | #define TIME_REL_MINS(min) \ | ||
38 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, min) | ||
39 | |||
40 | #define TIMEOUT TIME_REL_MINS(3) | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Doubly linked list of clients having connections to us | ||
45 | */ | ||
46 | struct ClientList; | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Doubly linked list of clients waiting for a lock | ||
51 | */ | ||
52 | struct WaitList | ||
53 | { | ||
54 | /** | ||
55 | * The next client structure | ||
56 | */ | ||
57 | struct WaitList *next; | ||
58 | |||
59 | /** | ||
60 | * The prev client structure | ||
61 | */ | ||
62 | struct WaitList *prev; | ||
63 | |||
64 | /** | ||
65 | * Pointer to the client | ||
66 | */ | ||
67 | struct ClientList *cl_entry; | ||
68 | }; | ||
69 | |||
70 | |||
71 | /** | ||
72 | * Structure representing a Lock | ||
73 | */ | ||
74 | struct Lock | ||
75 | { | ||
76 | /** | ||
77 | * List head of clients waiting for this lock | ||
78 | */ | ||
79 | struct WaitList *wl_head; | ||
80 | |||
81 | /** | ||
82 | * List tail of clients waiting for this lock | ||
83 | */ | ||
84 | struct WaitList *wl_tail; | ||
85 | |||
86 | /** | ||
87 | * The client which is currently holding this lock | ||
88 | */ | ||
89 | struct ClientList *cl_entry; | ||
90 | |||
91 | /** | ||
92 | * The name of the locking domain this lock belongs to | ||
93 | */ | ||
94 | char *domain_name; | ||
95 | |||
96 | /** | ||
97 | * The number of this lock | ||
98 | */ | ||
99 | uint32_t lock_num; | ||
100 | }; | ||
101 | |||
102 | |||
103 | /** | ||
104 | * A Lock element for a doubly linked list | ||
105 | */ | ||
106 | struct LockList | ||
107 | { | ||
108 | /** | ||
109 | * The next element pointer | ||
110 | */ | ||
111 | struct LockList *next; | ||
112 | |||
113 | /** | ||
114 | * Pointer to the previous element | ||
115 | */ | ||
116 | struct LockList *prev; | ||
117 | |||
118 | /** | ||
119 | * Pointer to the Lock | ||
120 | */ | ||
121 | struct Lock *lock; | ||
122 | }; | ||
123 | |||
124 | |||
125 | /** | ||
126 | * Doubly linked list of clients having connections to us | ||
127 | */ | ||
128 | struct ClientList | ||
129 | { | ||
130 | |||
131 | /** | ||
132 | * The next client structure | ||
133 | */ | ||
134 | struct ClientList *next; | ||
135 | |||
136 | /** | ||
137 | * The previous client structure | ||
138 | */ | ||
139 | struct ClientList *prev; | ||
140 | |||
141 | /** | ||
142 | * Head of the doubly linked list of the currently held locks by this client | ||
143 | */ | ||
144 | struct LockList *ll_head; | ||
145 | |||
146 | /** | ||
147 | * Tail of the doubly linked list of the currently held locks by this client | ||
148 | */ | ||
149 | struct LockList *ll_tail; | ||
150 | |||
151 | /** | ||
152 | * Pointer to the client | ||
153 | */ | ||
154 | struct GNUNET_SERVER_Client *client; | ||
155 | }; | ||
156 | |||
157 | |||
158 | /** | ||
159 | * Structure for matching a lock | ||
160 | */ | ||
161 | struct LockMatch | ||
162 | { | ||
163 | /** | ||
164 | * The matched LockingRequest entry; Should be NULL if no entry is found | ||
165 | */ | ||
166 | struct Lock *matched_entry; | ||
167 | |||
168 | /** | ||
169 | * The locking domain name of the lock | ||
170 | */ | ||
171 | const char *domain_name; | ||
172 | |||
173 | /** | ||
174 | * The lock number | ||
175 | */ | ||
176 | uint32_t lock_num; | ||
177 | }; | ||
178 | |||
179 | |||
180 | /** | ||
181 | * Map of lock-keys to the 'struct LockList' entry for the key. | ||
182 | */ | ||
183 | static struct GNUNET_CONTAINER_MultiHashMap *lock_map; | ||
184 | |||
185 | /** | ||
186 | * Head of the doubly linked list of clients currently connected | ||
187 | */ | ||
188 | static struct ClientList *cl_head; | ||
189 | |||
190 | /** | ||
191 | * Tail of the doubly linked list of clients currently connected | ||
192 | */ | ||
193 | static struct ClientList *cl_tail; | ||
194 | |||
195 | |||
196 | /** | ||
197 | * Get the key for the given lock in the 'lock_map'. | ||
198 | * | ||
199 | * @param domain_name | ||
200 | * @param lock_number | ||
201 | * @param key set to the key | ||
202 | */ | ||
203 | static void | ||
204 | get_key (const char *domain_name, uint32_t lock_number, | ||
205 | struct GNUNET_HashCode *key) | ||
206 | { | ||
207 | uint32_t *last_32; | ||
208 | |||
209 | GNUNET_CRYPTO_hash (domain_name, strlen (domain_name), key); | ||
210 | last_32 = (uint32_t *) key; | ||
211 | *last_32 ^= lock_number; | ||
212 | } | ||
213 | |||
214 | |||
215 | /** | ||
216 | * Hashmap iterator for matching a lock | ||
217 | * | ||
218 | * @param cls the LockMatch structure | ||
219 | * @param key current key code | ||
220 | * @param value value in the hash map (struct Lock) | ||
221 | * @return GNUNET_YES if we should continue to | ||
222 | * iterate, | ||
223 | * GNUNET_NO if not. | ||
224 | */ | ||
225 | static int | ||
226 | match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
227 | { | ||
228 | struct LockMatch *match = cls; | ||
229 | struct Lock *lock = value; | ||
230 | |||
231 | if ((match->lock_num == lock->lock_num) && | ||
232 | (0 == strcmp (match->domain_name, lock->domain_name))) | ||
233 | { | ||
234 | match->matched_entry = lock; | ||
235 | return GNUNET_NO; | ||
236 | } | ||
237 | return GNUNET_YES; | ||
238 | } | ||
239 | |||
240 | |||
241 | /** | ||
242 | * Function to search for a lock in the global lock hashmap | ||
243 | * | ||
244 | * @param domain_name the name of the locking domain | ||
245 | * @param lock_num the number of the lock | ||
246 | * @return the lock if found; NULL if not | ||
247 | */ | ||
248 | static struct Lock * | ||
249 | find_lock (const char *domain_name, const uint32_t lock_num) | ||
250 | { | ||
251 | struct LockMatch match; | ||
252 | struct GNUNET_HashCode key; | ||
253 | |||
254 | match.lock_num = lock_num; | ||
255 | match.domain_name = domain_name; | ||
256 | match.matched_entry = NULL; | ||
257 | get_key (domain_name, lock_num, &key); | ||
258 | GNUNET_CONTAINER_multihashmap_get_multiple (lock_map, &key, &match_iterator, | ||
259 | &match); | ||
260 | return match.matched_entry; | ||
261 | } | ||
262 | |||
263 | |||
264 | /** | ||
265 | * Adds a lock to the global lock hashmap | ||
266 | * | ||
267 | * @param domain_name the name of the lock's locking domain | ||
268 | * @param lock_num the lock number | ||
269 | * @return pointer to the lock structure which is added to lock map | ||
270 | */ | ||
271 | static struct Lock * | ||
272 | add_lock (const char *domain_name, uint32_t lock_num) | ||
273 | { | ||
274 | struct Lock *lock; | ||
275 | struct GNUNET_HashCode key; | ||
276 | size_t domain_name_len; | ||
277 | |||
278 | lock = GNUNET_malloc (sizeof (struct Lock)); | ||
279 | domain_name_len = strlen (domain_name) + 1; | ||
280 | lock->domain_name = GNUNET_malloc (domain_name_len); | ||
281 | strncpy (lock->domain_name, domain_name, domain_name_len); | ||
282 | lock->lock_num = lock_num; | ||
283 | get_key (domain_name, lock_num, &key); | ||
284 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
285 | "Adding a lock with num: %d and domain: %s to the lock map\n", | ||
286 | lock->lock_num, lock->domain_name); | ||
287 | GNUNET_CONTAINER_multihashmap_put (lock_map, &key, lock, | ||
288 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
289 | return lock; | ||
290 | } | ||
291 | |||
292 | |||
293 | /** | ||
294 | * Removes a lock from the lock map. The WaitList of the lock should be empty | ||
295 | * | ||
296 | * @param lock the lock to remove | ||
297 | */ | ||
298 | static void | ||
299 | remove_lock (struct Lock *lock) | ||
300 | { | ||
301 | struct GNUNET_HashCode key; | ||
302 | |||
303 | GNUNET_assert (NULL == lock->wl_head); | ||
304 | get_key (lock->domain_name, lock->lock_num, &key); | ||
305 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
306 | "Removing lock with num: %u, domain: %s from lock map\n", lock->lock_num, | ||
307 | lock->domain_name); | ||
308 | GNUNET_assert (GNUNET_YES == | ||
309 | GNUNET_CONTAINER_multihashmap_remove (lock_map, &key, lock)); | ||
310 | GNUNET_free (lock->domain_name); | ||
311 | GNUNET_free (lock); | ||
312 | } | ||
313 | |||
314 | |||
315 | /** | ||
316 | * Find the LockList entry corresponding to the given Lock in a ClientList | ||
317 | * entry | ||
318 | * | ||
319 | * @param cl_entry the ClientList entry whose lock list has to be searched | ||
320 | * @param lock the lock which has to be matched | ||
321 | * @return the matching LockList entry; NULL if no match is found | ||
322 | */ | ||
323 | static struct LockList * | ||
324 | cl_ll_find_lock (struct ClientList *cl_entry, const struct Lock *lock) | ||
325 | { | ||
326 | struct LockList *ll_entry; | ||
327 | |||
328 | for (ll_entry = cl_entry->ll_head; NULL != ll_entry; | ||
329 | ll_entry = ll_entry->next) | ||
330 | { | ||
331 | if (lock == ll_entry->lock) | ||
332 | return ll_entry; | ||
333 | } | ||
334 | return NULL; | ||
335 | } | ||
336 | |||
337 | |||
338 | /** | ||
339 | * Function to append a lock to the lock list of a ClientList entry | ||
340 | * | ||
341 | * @param cl_entry the client which currently owns this lock | ||
342 | * @param lock the lock to be added to the cl_entry's lock list | ||
343 | */ | ||
344 | static void | ||
345 | cl_ll_add_lock (struct ClientList *cl_entry, struct Lock *lock) | ||
346 | { | ||
347 | struct LockList *ll_entry; | ||
348 | |||
349 | ll_entry = GNUNET_malloc (sizeof (struct LockList)); | ||
350 | ll_entry->lock = lock; | ||
351 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
352 | "Adding a lock with num: %u and domain: %s to lock list\n", | ||
353 | lock->lock_num, lock->domain_name); | ||
354 | GNUNET_CONTAINER_DLL_insert_tail (cl_entry->ll_head, cl_entry->ll_tail, | ||
355 | ll_entry); | ||
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * Function to delete a lock from the lock list of the given ClientList entry | ||
361 | * | ||
362 | * @param cl_entry the ClientList entry | ||
363 | * @param ll_entry the LockList entry to be deleted | ||
364 | */ | ||
365 | static void | ||
366 | cl_ll_remove_lock (struct ClientList *cl_entry, struct LockList *ll_entry) | ||
367 | { | ||
368 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
369 | "Removing lock with num: %u, domain: %s from lock list of a client\n", | ||
370 | ll_entry->lock->lock_num, ll_entry->lock->domain_name); | ||
371 | GNUNET_assert (NULL != cl_entry->ll_head); | ||
372 | GNUNET_CONTAINER_DLL_remove (cl_entry->ll_head, cl_entry->ll_tail, ll_entry); | ||
373 | GNUNET_free (ll_entry); | ||
374 | } | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Find a WaitList entry in the waiting list of a lock | ||
379 | * | ||
380 | * @param lock the lock whose wait list has to be searched | ||
381 | * @param cl_entry the ClientList entry to be searched | ||
382 | * @return the WaitList entry matching the given cl_entry; NULL if not match | ||
383 | * was found | ||
384 | */ | ||
385 | static struct WaitList * | ||
386 | lock_wl_find (const struct Lock *lock, const struct ClientList *cl_entry) | ||
387 | { | ||
388 | struct WaitList *wl_entry; | ||
389 | |||
390 | for (wl_entry = lock->wl_head; NULL != wl_entry; wl_entry = wl_entry->next) | ||
391 | { | ||
392 | if (cl_entry == wl_entry->cl_entry) | ||
393 | return wl_entry; | ||
394 | } | ||
395 | return NULL; | ||
396 | } | ||
397 | |||
398 | |||
399 | /** | ||
400 | * Add a client to the wait list of given lock | ||
401 | * | ||
402 | * @param lock the lock list entry of a lock | ||
403 | * @param cl_entry the client to queue for the lock's wait list | ||
404 | */ | ||
405 | static void | ||
406 | lock_wl_add_client (struct Lock *lock, struct ClientList *cl_entry) | ||
407 | { | ||
408 | struct WaitList *wl_entry; | ||
409 | |||
410 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
411 | "Adding a client to lock's wait list (lock num: %u, domain: %s)\n", | ||
412 | lock->lock_num, lock->domain_name); | ||
413 | wl_entry = GNUNET_malloc (sizeof (struct WaitList)); | ||
414 | wl_entry->cl_entry = cl_entry; | ||
415 | GNUNET_CONTAINER_DLL_insert_tail (lock->wl_head, lock->wl_tail, wl_entry); | ||
416 | } | ||
417 | |||
418 | |||
419 | /** | ||
420 | * Remove an entry from the wait list of the given lock | ||
421 | * | ||
422 | * @param lock the lock | ||
423 | * @param wl_entry the wait list entry to be removed | ||
424 | */ | ||
425 | static void | ||
426 | lock_wl_remove (struct Lock *lock, struct WaitList *wl_entry) | ||
427 | { | ||
428 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
429 | "Removing client from wait list of lock with num: %u, domain: %s\n", | ||
430 | lock->lock_num, lock->domain_name); | ||
431 | GNUNET_CONTAINER_DLL_remove (lock->wl_head, lock->wl_tail, wl_entry); | ||
432 | GNUNET_free (wl_entry); | ||
433 | } | ||
434 | |||
435 | |||
436 | /** | ||
437 | * Search for a client in the client list | ||
438 | * | ||
439 | * @param client the client to be searched for | ||
440 | * @return the ClientList entry; NULL if the client is not found | ||
441 | */ | ||
442 | static struct ClientList * | ||
443 | cl_find_client (const struct GNUNET_SERVER_Client *client) | ||
444 | { | ||
445 | struct ClientList *current; | ||
446 | |||
447 | for (current = cl_head; NULL != current; current = current->next) | ||
448 | if (client == current->client) | ||
449 | return current; | ||
450 | return NULL; | ||
451 | } | ||
452 | |||
453 | |||
454 | /** | ||
455 | * Append a client to the client list | ||
456 | * | ||
457 | * @param client the client to be appended to the list | ||
458 | * @return the client list entry which is added to the client list | ||
459 | */ | ||
460 | static struct ClientList * | ||
461 | cl_add_client (struct GNUNET_SERVER_Client *client) | ||
462 | { | ||
463 | struct ClientList *new_client; | ||
464 | |||
465 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding a client to the client list\n"); | ||
466 | new_client = GNUNET_malloc (sizeof (struct ClientList)); | ||
467 | GNUNET_SERVER_client_keep (client); | ||
468 | new_client->client = client; | ||
469 | GNUNET_CONTAINER_DLL_insert_tail (cl_head, cl_tail, new_client); | ||
470 | return new_client; | ||
471 | } | ||
472 | |||
473 | |||
474 | /** | ||
475 | * Delete the given client from the client list. The LockList should be empty | ||
476 | * | ||
477 | * @param cl_entry the client list entry to delete | ||
478 | */ | ||
479 | static void | ||
480 | cl_remove_client (struct ClientList *cl_entry) | ||
481 | { | ||
482 | GNUNET_assert (NULL == cl_entry->ll_head); | ||
483 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing a client from the client list\n"); | ||
484 | GNUNET_SERVER_client_drop (cl_entry->client); | ||
485 | GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl_entry); | ||
486 | GNUNET_free (cl_entry); | ||
487 | } | ||
488 | |||
489 | |||
490 | /** | ||
491 | * Transmit notify for sending message to client | ||
492 | * | ||
493 | * @param cls the message to send | ||
494 | * @param size number of bytes available in buf | ||
495 | * @param buf where the callee should write the message | ||
496 | * @return number of bytes written to buf | ||
497 | */ | ||
498 | static size_t | ||
499 | transmit_notify (void *cls, size_t size, void *buf) | ||
500 | { | ||
501 | struct GNUNET_LOCKMANAGER_Message *msg = cls; | ||
502 | uint16_t msg_size; | ||
503 | |||
504 | if ((0 == size) || (NULL == buf)) | ||
505 | { | ||
506 | /* FIXME: Timed out -- requeue? */ | ||
507 | return 0; | ||
508 | } | ||
509 | msg_size = ntohs (msg->header.size); | ||
510 | GNUNET_assert (size >= msg_size); | ||
511 | memcpy (buf, msg, msg_size); | ||
512 | GNUNET_free (msg); | ||
513 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Message of size %u sent\n", msg_size); | ||
514 | return msg_size; | ||
515 | } | ||
516 | |||
517 | |||
518 | /** | ||
519 | * Send SUCCESS message to the client | ||
520 | * | ||
521 | * @param client the client to which the message has to be sent | ||
522 | * @param domain_name the locking domain of the successfully acquried lock | ||
523 | * @param lock_num the number of the successfully acquired lock | ||
524 | */ | ||
525 | static void | ||
526 | send_success_msg (struct GNUNET_SERVER_Client *client, const char *domain_name, | ||
527 | int lock_num) | ||
528 | { | ||
529 | struct GNUNET_LOCKMANAGER_Message *reply; | ||
530 | size_t domain_name_len; | ||
531 | uint16_t reply_size; | ||
532 | |||
533 | domain_name_len = strlen (domain_name) + 1; | ||
534 | reply_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_len; | ||
535 | reply = GNUNET_malloc (reply_size); | ||
536 | reply->header.size = htons (reply_size); | ||
537 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS); | ||
538 | reply->lock = htonl (lock_num); | ||
539 | strncpy ((char *) &reply[1], domain_name, domain_name_len); | ||
540 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
541 | "Sending SUCCESS message for lock with num: %u, domain: %s\n", lock_num, | ||
542 | domain_name); | ||
543 | GNUNET_SERVER_notify_transmit_ready (client, reply_size, TIMEOUT, | ||
544 | &transmit_notify, reply); | ||
545 | } | ||
546 | |||
547 | |||
548 | /** | ||
549 | * Handler for GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE | ||
550 | * | ||
551 | * @param cls NULL | ||
552 | * @param client the client sending this message | ||
553 | * @param message GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE message | ||
554 | */ | ||
555 | static void | ||
556 | handle_acquire (void *cls, struct GNUNET_SERVER_Client *client, | ||
557 | const struct GNUNET_MessageHeader *message) | ||
558 | { | ||
559 | const struct GNUNET_LOCKMANAGER_Message *request; | ||
560 | const char *domain_name; | ||
561 | struct Lock *lock; | ||
562 | struct ClientList *cl_entry; | ||
563 | uint32_t lock_num; | ||
564 | uint16_t msize; | ||
565 | |||
566 | msize = htons (message->size); | ||
567 | if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message)) | ||
568 | { | ||
569 | GNUNET_break (0); | ||
570 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
571 | return; | ||
572 | } | ||
573 | request = (struct GNUNET_LOCKMANAGER_Message *) message; | ||
574 | domain_name = (const char *) &request[1]; | ||
575 | msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); | ||
576 | if ('\0' != domain_name[msize - 1]) | ||
577 | { | ||
578 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
579 | "Bad domain `%.*s' - byte with index %u is %X, not 0.\n", msize, | ||
580 | domain_name, msize - 1, (unsigned int) domain_name[msize - 1]); | ||
581 | GNUNET_break (0); | ||
582 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
583 | return; | ||
584 | } | ||
585 | lock_num = ntohl (request->lock); | ||
586 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
587 | "Received an ACQUIRE message for lock num: %u domain: %s\n", lock_num, | ||
588 | domain_name); | ||
589 | if (NULL == (cl_entry = cl_find_client (client))) | ||
590 | cl_entry = cl_add_client (client); /* Add client if not in client list */ | ||
591 | if (NULL != (lock = find_lock (domain_name, lock_num))) | ||
592 | { | ||
593 | if (lock->cl_entry == cl_entry) | ||
594 | { /* Client is requesting a lock it already owns */ | ||
595 | GNUNET_break_op (0); | ||
596 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
597 | return; | ||
598 | } | ||
599 | lock_wl_add_client (lock, cl_entry); | ||
600 | cl_ll_add_lock (cl_entry, lock); | ||
601 | } | ||
602 | else /* Lock not present */ | ||
603 | { | ||
604 | lock = add_lock (domain_name, lock_num); | ||
605 | lock->cl_entry = cl_entry; | ||
606 | cl_ll_add_lock (cl_entry, lock); | ||
607 | send_success_msg (cl_entry->client, domain_name, lock_num); | ||
608 | } | ||
609 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
610 | } | ||
611 | |||
612 | |||
613 | /** | ||
614 | * This function gives the lock to the first client in the wait list of the | ||
615 | * lock. If no clients are currently waiting for this lock, the lock is then | ||
616 | * destroyed. | ||
617 | * | ||
618 | * @param lock the lock which has to be processed for release | ||
619 | */ | ||
620 | static void | ||
621 | process_lock_release (struct Lock *lock) | ||
622 | { | ||
623 | struct WaitList *wl_entry; | ||
624 | |||
625 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
626 | "Processing lock release for lock with num: %u, domain: %s\n", | ||
627 | lock->lock_num, lock->domain_name); | ||
628 | wl_entry = lock->wl_head; | ||
629 | if (NULL == wl_entry) | ||
630 | { | ||
631 | remove_lock (lock); /* No clients waiting for this lock - delete */ | ||
632 | return; | ||
633 | } | ||
634 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving lock to a client from wait list\n"); | ||
635 | lock->cl_entry = wl_entry->cl_entry; | ||
636 | lock_wl_remove (lock, wl_entry); | ||
637 | send_success_msg (lock->cl_entry->client, lock->domain_name, lock->lock_num); | ||
638 | } | ||
639 | |||
640 | |||
641 | /** | ||
642 | * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE | ||
643 | * | ||
644 | * @param cls NULL | ||
645 | * @param client the client sending this message | ||
646 | * @param message the LOCKMANAGER_RELEASE message | ||
647 | */ | ||
648 | static void | ||
649 | handle_release (void *cls, struct GNUNET_SERVER_Client *client, | ||
650 | const struct GNUNET_MessageHeader *message) | ||
651 | { | ||
652 | const struct GNUNET_LOCKMANAGER_Message *request; | ||
653 | struct ClientList *cl_entry; | ||
654 | struct WaitList *wl_entry; | ||
655 | struct LockList *ll_entry; | ||
656 | const char *domain_name; | ||
657 | struct Lock *lock; | ||
658 | uint32_t lock_num; | ||
659 | uint16_t msize; | ||
660 | |||
661 | msize = ntohs (message->size); | ||
662 | if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message)) | ||
663 | { | ||
664 | GNUNET_break (0); | ||
665 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
666 | return; | ||
667 | } | ||
668 | request = (const struct GNUNET_LOCKMANAGER_Message *) message; | ||
669 | domain_name = (const char *) &request[1]; | ||
670 | msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); | ||
671 | if ('\0' != domain_name[msize - 1]) | ||
672 | { | ||
673 | GNUNET_break (0); | ||
674 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
675 | return; | ||
676 | |||
677 | |||
678 | } | ||
679 | lock_num = ntohl (request->lock); | ||
680 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
681 | "Received RELEASE message for lock with num: %d, domain: %s\n", lock_num, | ||
682 | domain_name); | ||
683 | if (NULL == (cl_entry = cl_find_client (client))) | ||
684 | { | ||
685 | GNUNET_break (0); | ||
686 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
687 | return; | ||
688 | } | ||
689 | lock = find_lock (domain_name, lock_num); | ||
690 | if (NULL == lock) | ||
691 | { | ||
692 | GNUNET_break (0); | ||
693 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
694 | return; | ||
695 | } | ||
696 | if (NULL == (ll_entry = cl_ll_find_lock (cl_entry, lock))) | ||
697 | { | ||
698 | GNUNET_break (0); | ||
699 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
700 | return; | ||
701 | } | ||
702 | cl_ll_remove_lock (cl_entry, ll_entry); | ||
703 | if (cl_entry == lock->cl_entry) | ||
704 | { | ||
705 | process_lock_release (lock); | ||
706 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
707 | return; | ||
708 | } | ||
709 | /* remove 'client' from wait list (check that it is not there...) */ | ||
710 | if (NULL != (wl_entry = lock_wl_find (lock, cl_entry))) | ||
711 | { | ||
712 | lock_wl_remove (lock, wl_entry); | ||
713 | } | ||
714 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
715 | } | ||
716 | |||
717 | |||
718 | /** | ||
719 | * Callback for client disconnect | ||
720 | * | ||
721 | * @param cls NULL | ||
722 | * @param client the client which has disconnected | ||
723 | */ | ||
724 | static void | ||
725 | client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | ||
726 | { | ||
727 | struct ClientList *cl_entry; | ||
728 | struct LockList *ll_entry; | ||
729 | struct Lock *lock; | ||
730 | struct WaitList *wl_entry; | ||
731 | |||
732 | if (NULL == client) | ||
733 | return; | ||
734 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
735 | "A client has been disconnected -- freeing its locks and resources\n"); | ||
736 | cl_entry = cl_find_client (client); | ||
737 | if (NULL == cl_entry) | ||
738 | return; | ||
739 | while (NULL != (ll_entry = cl_entry->ll_head)) | ||
740 | { | ||
741 | lock = ll_entry->lock; | ||
742 | cl_ll_remove_lock (cl_entry, ll_entry); | ||
743 | if (lock->cl_entry == cl_entry) | ||
744 | process_lock_release (lock); | ||
745 | else | ||
746 | { | ||
747 | wl_entry = lock_wl_find (lock, cl_entry); | ||
748 | GNUNET_assert (NULL != wl_entry); | ||
749 | lock_wl_remove (lock, wl_entry); | ||
750 | } | ||
751 | } | ||
752 | cl_remove_client (cl_entry); | ||
753 | } | ||
754 | |||
755 | |||
756 | /** | ||
757 | * Hashmap Iterator to delete lock entries in hash map | ||
758 | * | ||
759 | * @param cls NULL | ||
760 | * @param key current key code | ||
761 | * @param value value in the hash map | ||
762 | * @return GNUNET_YES if we should continue to | ||
763 | * iterate, | ||
764 | * GNUNET_NO if not. | ||
765 | */ | ||
766 | static int | ||
767 | lock_delete_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
768 | { | ||
769 | struct Lock *lock = value; | ||
770 | |||
771 | GNUNET_assert (NULL != lock); | ||
772 | while (NULL != lock->wl_head) | ||
773 | { | ||
774 | lock_wl_remove (lock, lock->wl_head); | ||
775 | } | ||
776 | GNUNET_assert (GNUNET_YES == | ||
777 | GNUNET_CONTAINER_multihashmap_remove (lock_map, key, lock)); | ||
778 | GNUNET_free (lock->domain_name); | ||
779 | GNUNET_free (lock); | ||
780 | return GNUNET_YES; | ||
781 | } | ||
782 | |||
783 | |||
784 | /** | ||
785 | * Task to clean up and shutdown nicely | ||
786 | * | ||
787 | * @param cls NULL | ||
788 | * @param tc the TaskContext from scheduler | ||
789 | */ | ||
790 | static void | ||
791 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
792 | { | ||
793 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down lock manager\n"); | ||
794 | /* Clean the global ClientList */ | ||
795 | while (NULL != cl_head) | ||
796 | { | ||
797 | while (NULL != cl_head->ll_head) /* Clear the LockList */ | ||
798 | { | ||
799 | cl_ll_remove_lock (cl_head, cl_head->ll_head); | ||
800 | } | ||
801 | cl_remove_client (cl_head); | ||
802 | } | ||
803 | /* Clean the global hash table */ | ||
804 | GNUNET_CONTAINER_multihashmap_iterate (lock_map, &lock_delete_iterator, NULL); | ||
805 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (lock_map)); | ||
806 | GNUNET_CONTAINER_multihashmap_destroy (lock_map); | ||
807 | lock_map = NULL; | ||
808 | } | ||
809 | |||
810 | |||
811 | /** | ||
812 | * Lock manager setup | ||
813 | * | ||
814 | * @param cls closure | ||
815 | * @param server the initialized server | ||
816 | * @param cfg configuration to use | ||
817 | */ | ||
818 | static void | ||
819 | lockmanager_run (void *cls, struct GNUNET_SERVER_Handle *server, | ||
820 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
821 | { | ||
822 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { | ||
823 | {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0}, | ||
824 | {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0}, | ||
825 | {NULL} | ||
826 | }; | ||
827 | GNUNET_SERVER_add_handlers (server, message_handlers); | ||
828 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); | ||
829 | lock_map = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); | ||
830 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | ||
831 | NULL); | ||
832 | } | ||
833 | |||
834 | |||
835 | /** | ||
836 | * The starting point of execution | ||
837 | */ | ||
838 | int | ||
839 | main (int argc, char *const *argv) | ||
840 | { | ||
841 | return (GNUNET_OK == | ||
842 | GNUNET_SERVICE_run (argc, argv, "lockmanager", | ||
843 | GNUNET_SERVICE_OPTION_NONE, &lockmanager_run, | ||
844 | NULL)) ? 0 : 1; | ||
845 | } | ||
846 | |||
847 | /* 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 @@ | |||
1 | [lockmanager] | ||
2 | AUTOSTART = YES | ||
3 | @UNIXONLY@ PORT = 2100 | ||
4 | HOSTNAME = localhost | ||
5 | HOME = $SERVICEHOME | ||
6 | BINARY = gnunet-service-lockmanager | ||
7 | ACCEPT_FROM = 127.0.0.1; | ||
8 | ACCEPT_FROM6 = ::1; | ||
9 | UNIXPATH = /tmp/gnunet-service-lockmanager.sock | ||
10 | UNIX_MATCH_UID = YES | ||
11 | UNIX_MATCH_GID = YES | ||
12 | |||
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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008--2013 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 3, 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 deleted file mode 100644 index 8f66cf00b..000000000 --- a/src/lockmanager/lockmanager_api.c +++ /dev/null | |||
@@ -1,729 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008--2013 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 3, 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 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_lockmanager_service.h" | ||
31 | #include "gnunet_protocols.h" | ||
32 | |||
33 | #include "lockmanager.h" | ||
34 | |||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log_from (kind, "lockmanager-api",__VA_ARGS__) | ||
37 | |||
38 | #define TIME_REL_MINS(min) \ | ||
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, min) | ||
40 | |||
41 | #define TIMEOUT TIME_REL_MINS(3) | ||
42 | |||
43 | |||
44 | /** | ||
45 | * The message queue | ||
46 | */ | ||
47 | struct MessageQueue | ||
48 | { | ||
49 | /** | ||
50 | * The next pointer for doubly linked list | ||
51 | */ | ||
52 | struct MessageQueue *next; | ||
53 | |||
54 | /** | ||
55 | * The prev pointer for doubly linked list | ||
56 | */ | ||
57 | struct MessageQueue *prev; | ||
58 | |||
59 | /** | ||
60 | * The LOCKMANAGER Message | ||
61 | */ | ||
62 | struct GNUNET_LOCKMANAGER_Message *msg; | ||
63 | |||
64 | /** | ||
65 | * If this is a AQUIRE_LOCK message, this is the | ||
66 | * affiliated locking request. | ||
67 | */ | ||
68 | struct GNUNET_LOCKMANAGER_LockingRequest *lr; | ||
69 | }; | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Handler for the lockmanager service | ||
74 | */ | ||
75 | struct GNUNET_LOCKMANAGER_Handle | ||
76 | { | ||
77 | /** | ||
78 | * The client connection to the service | ||
79 | */ | ||
80 | struct GNUNET_CLIENT_Connection *conn; | ||
81 | |||
82 | /** | ||
83 | * The transmit handle for transmissions using conn | ||
84 | */ | ||
85 | struct GNUNET_CLIENT_TransmitHandle *transmit_handle; | ||
86 | |||
87 | /** | ||
88 | * Hashmap handle | ||
89 | */ | ||
90 | struct GNUNET_CONTAINER_MultiHashMap *hashmap; | ||
91 | |||
92 | /** | ||
93 | * Double linked list head for message queue | ||
94 | */ | ||
95 | struct MessageQueue *mq_head; | ||
96 | |||
97 | /** | ||
98 | * Double linked list tail for message queue | ||
99 | */ | ||
100 | struct MessageQueue *mq_tail; | ||
101 | |||
102 | /** | ||
103 | * Are we currently handling replies? | ||
104 | */ | ||
105 | int in_replies; | ||
106 | }; | ||
107 | |||
108 | |||
109 | /** | ||
110 | * Structure for Locking Request | ||
111 | */ | ||
112 | struct GNUNET_LOCKMANAGER_LockingRequest | ||
113 | { | ||
114 | /** | ||
115 | * The handle associated with this request | ||
116 | */ | ||
117 | struct GNUNET_LOCKMANAGER_Handle *handle; | ||
118 | |||
119 | /** | ||
120 | * The status callback | ||
121 | */ | ||
122 | GNUNET_LOCKMANAGER_StatusCallback status_cb; | ||
123 | |||
124 | /** | ||
125 | * Entry in the request message queue for aquiring this | ||
126 | * lock; NULL after request has been sent. | ||
127 | */ | ||
128 | struct MessageQueue *mqe; | ||
129 | |||
130 | /** | ||
131 | * Closure for the status callback | ||
132 | */ | ||
133 | void *status_cb_cls; | ||
134 | |||
135 | /** | ||
136 | * The locking domain of this request | ||
137 | */ | ||
138 | char *domain; | ||
139 | |||
140 | /** | ||
141 | * The lock | ||
142 | */ | ||
143 | uint32_t lock; | ||
144 | |||
145 | /** | ||
146 | * The status of the lock | ||
147 | */ | ||
148 | enum GNUNET_LOCKMANAGER_Status status; | ||
149 | |||
150 | /** | ||
151 | * set to GNUNET_YES if acquire message for this lock is till in messga queue | ||
152 | */ | ||
153 | int acquire_sent; | ||
154 | }; | ||
155 | |||
156 | |||
157 | /** | ||
158 | * Structure for matching a lock | ||
159 | */ | ||
160 | struct LockingRequestMatch | ||
161 | { | ||
162 | /** | ||
163 | * The matched LockingRequest entry; Should be NULL if no entry is found | ||
164 | */ | ||
165 | struct GNUNET_LOCKMANAGER_LockingRequest *matched_entry; | ||
166 | |||
167 | /** | ||
168 | * The locking domain name of the lock | ||
169 | */ | ||
170 | const char *domain; | ||
171 | |||
172 | /** | ||
173 | * The lock number | ||
174 | */ | ||
175 | uint32_t lock; | ||
176 | }; | ||
177 | |||
178 | |||
179 | /** | ||
180 | * Handler for server replies | ||
181 | * | ||
182 | * @param cls the LOCKMANAGER_Handle | ||
183 | * @param msg received message, NULL on timeout or fatal error | ||
184 | */ | ||
185 | static void | ||
186 | handle_replies (void *cls, const struct GNUNET_MessageHeader *msg); | ||
187 | |||
188 | |||
189 | /** | ||
190 | * Transmit notify for sending message to server | ||
191 | * | ||
192 | * @param cls the lockmanager handle | ||
193 | * @param size number of bytes available in buf | ||
194 | * @param buf where the callee should write the message | ||
195 | * @return number of bytes written to buf | ||
196 | */ | ||
197 | static size_t | ||
198 | transmit_notify (void *cls, size_t size, void *buf) | ||
199 | { | ||
200 | struct GNUNET_LOCKMANAGER_Handle *handle = cls; | ||
201 | struct MessageQueue *queue_entity; | ||
202 | uint16_t msg_size; | ||
203 | |||
204 | handle->transmit_handle = NULL; | ||
205 | queue_entity = handle->mq_head; | ||
206 | GNUNET_assert (NULL != queue_entity); | ||
207 | if ((0 == size) || (NULL == buf)) | ||
208 | { | ||
209 | handle->transmit_handle = | ||
210 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, | ||
211 | ntohs (queue_entity->msg-> | ||
212 | header.size), | ||
213 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
214 | GNUNET_YES, &transmit_notify, | ||
215 | handle); | ||
216 | return 0; | ||
217 | } | ||
218 | msg_size = ntohs (queue_entity->msg->header.size); | ||
219 | GNUNET_assert (size >= msg_size); | ||
220 | memcpy (buf, queue_entity->msg, msg_size); | ||
221 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Message of size %u sent\n", msg_size); | ||
222 | if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE == | ||
223 | ntohs (queue_entity->msg->header.type)) | ||
224 | { | ||
225 | GNUNET_break (GNUNET_NO == queue_entity->lr->acquire_sent); | ||
226 | queue_entity->lr->acquire_sent = GNUNET_YES; | ||
227 | queue_entity->lr->mqe = NULL; | ||
228 | } | ||
229 | GNUNET_free (queue_entity->msg); | ||
230 | GNUNET_CONTAINER_DLL_remove (handle->mq_head, handle->mq_tail, queue_entity); | ||
231 | GNUNET_free (queue_entity); | ||
232 | queue_entity = handle->mq_head; | ||
233 | if (NULL != queue_entity) | ||
234 | { | ||
235 | handle->transmit_handle = | ||
236 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, | ||
237 | ntohs (queue_entity->msg-> | ||
238 | header.size), TIMEOUT, | ||
239 | GNUNET_YES, &transmit_notify, | ||
240 | handle); | ||
241 | } | ||
242 | if (GNUNET_NO == handle->in_replies) | ||
243 | { | ||
244 | handle->in_replies = GNUNET_YES; | ||
245 | GNUNET_CLIENT_receive (handle->conn, &handle_replies, handle, | ||
246 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
247 | } | ||
248 | return msg_size; | ||
249 | } | ||
250 | |||
251 | |||
252 | /** | ||
253 | * Queues a message into handle's send message queue | ||
254 | * | ||
255 | * @param handle the lockmanager handle whose queue will be used | ||
256 | * @param msg the message to be queued | ||
257 | * @param request the locking reqeust responsible for queueing this message | ||
258 | * @return the MessageQueue entity that has been queued | ||
259 | */ | ||
260 | static struct MessageQueue * | ||
261 | queue_message (struct GNUNET_LOCKMANAGER_Handle *handle, | ||
262 | struct GNUNET_LOCKMANAGER_Message *msg, | ||
263 | struct GNUNET_LOCKMANAGER_LockingRequest *request) | ||
264 | { | ||
265 | struct MessageQueue *queue_entity; | ||
266 | |||
267 | GNUNET_assert (NULL != msg); | ||
268 | queue_entity = GNUNET_malloc (sizeof (struct MessageQueue)); | ||
269 | queue_entity->msg = msg; | ||
270 | queue_entity->lr = request; | ||
271 | GNUNET_CONTAINER_DLL_insert_tail (handle->mq_head, handle->mq_tail, | ||
272 | queue_entity); | ||
273 | if (NULL == handle->transmit_handle) | ||
274 | { | ||
275 | handle->transmit_handle = | ||
276 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, | ||
277 | ntohs (msg->header.size), TIMEOUT, | ||
278 | GNUNET_YES, &transmit_notify, | ||
279 | handle); | ||
280 | } | ||
281 | return queue_entity; | ||
282 | } | ||
283 | |||
284 | |||
285 | /** | ||
286 | * Get the key for the given lock in the 'lock_map'. | ||
287 | * | ||
288 | * @param domain_name | ||
289 | * @param lock_number | ||
290 | * @param key set to the key | ||
291 | */ | ||
292 | static void | ||
293 | get_key (const char *domain_name, uint32_t lock_number, | ||
294 | struct GNUNET_HashCode *key) | ||
295 | { | ||
296 | uint32_t *last_32; | ||
297 | |||
298 | GNUNET_CRYPTO_hash (domain_name, strlen (domain_name), key); | ||
299 | last_32 = (uint32_t *) key; | ||
300 | *last_32 ^= lock_number; | ||
301 | } | ||
302 | |||
303 | |||
304 | /** | ||
305 | * Hashmap iterator for matching a LockingRequest | ||
306 | * | ||
307 | * @param cls the LockingRequestMatch structure | ||
308 | * @param key current key code | ||
309 | * @param value value in the hash map (struct GNUNET_LOCKMANAGER_LockingRequest) | ||
310 | * @return GNUNET_YES if we should continue to | ||
311 | * iterate, | ||
312 | * GNUNET_NO if not. | ||
313 | */ | ||
314 | static int | ||
315 | match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
316 | { | ||
317 | struct LockingRequestMatch *match = cls; | ||
318 | struct GNUNET_LOCKMANAGER_LockingRequest *lr = value; | ||
319 | |||
320 | if ((match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain))) | ||
321 | { | ||
322 | match->matched_entry = lr; | ||
323 | return GNUNET_NO; | ||
324 | } | ||
325 | return GNUNET_YES; | ||
326 | } | ||
327 | |||
328 | |||
329 | /** | ||
330 | * Function to find a LockingRequest associated with the given domain and lock | ||
331 | * attributes in the map | ||
332 | * | ||
333 | * @param map the map where the LockingRequests are stored | ||
334 | * @param domain the locking domain name | ||
335 | * @param lock the lock number | ||
336 | * @return the found LockingRequest; NULL if a matching LockingRequest wasn't | ||
337 | * found | ||
338 | */ | ||
339 | static struct GNUNET_LOCKMANAGER_LockingRequest * | ||
340 | hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map, | ||
341 | const char *domain, uint32_t lock) | ||
342 | { | ||
343 | struct GNUNET_HashCode hash; | ||
344 | struct LockingRequestMatch lock_match; | ||
345 | |||
346 | lock_match.matched_entry = NULL; | ||
347 | lock_match.domain = domain; | ||
348 | lock_match.lock = lock; | ||
349 | get_key (domain, lock, &hash); | ||
350 | GNUNET_CONTAINER_multihashmap_get_multiple (map, &hash, &match_iterator, | ||
351 | &lock_match); | ||
352 | return lock_match.matched_entry; | ||
353 | } | ||
354 | |||
355 | |||
356 | /** | ||
357 | * Task for calling status change callback for a lock | ||
358 | * | ||
359 | * @param cls the LockingRequest associated with this lock | ||
360 | * @param tc the TaskScheduler context | ||
361 | */ | ||
362 | static void | ||
363 | call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
364 | { | ||
365 | const struct GNUNET_LOCKMANAGER_LockingRequest *r = cls; | ||
366 | |||
367 | if (NULL != r->status_cb) | ||
368 | { | ||
369 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
370 | "Calling status change for SUCCESS on lock num: %d, domain: %s\n", | ||
371 | r->lock, r->domain); | ||
372 | r->status_cb (r->status_cb_cls, r->domain, r->lock, r->status); | ||
373 | } | ||
374 | } | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Function to generate acquire message for a lock | ||
379 | * | ||
380 | * @param domain_name the domain name of the lock | ||
381 | * @param lock the lock number | ||
382 | * @return the generated GNUNET_LOCKMANAGER_Message | ||
383 | */ | ||
384 | static struct GNUNET_LOCKMANAGER_Message * | ||
385 | generate_acquire_msg (const char *domain_name, uint32_t lock) | ||
386 | { | ||
387 | struct GNUNET_LOCKMANAGER_Message *msg; | ||
388 | size_t domain_name_len; | ||
389 | uint16_t msg_size; | ||
390 | |||
391 | domain_name_len = strlen (domain_name) + 1; | ||
392 | msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_len; | ||
393 | msg = GNUNET_malloc (msg_size); | ||
394 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE); | ||
395 | msg->header.size = htons (msg_size); | ||
396 | msg->lock = htonl (lock); | ||
397 | memcpy (&msg[1], domain_name, domain_name_len); | ||
398 | return msg; | ||
399 | } | ||
400 | |||
401 | |||
402 | /** | ||
403 | * Iterator to call relase on locks; acquire messages are sent for all | ||
404 | * locks. In addition, if a lock is acquired before, it is not released and its | ||
405 | * status callback is called to signal its release | ||
406 | * | ||
407 | * @param cls the lockmanager handle | ||
408 | * @param key current key code | ||
409 | * @param value the Locking request | ||
410 | * @return GNUNET_YES if we should continue to | ||
411 | * iterate, | ||
412 | * GNUNET_NO if not. | ||
413 | */ | ||
414 | static int | ||
415 | release_n_retry_iterator (void *cls, const struct GNUNET_HashCode *key, | ||
416 | void *value) | ||
417 | { | ||
418 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; | ||
419 | struct GNUNET_LOCKMANAGER_Handle *h = cls; | ||
420 | struct GNUNET_LOCKMANAGER_Message *msg; | ||
421 | |||
422 | if (GNUNET_NO == r->acquire_sent) /* an acquire is still in queue */ | ||
423 | return GNUNET_YES; | ||
424 | r->acquire_sent = GNUNET_NO; | ||
425 | msg = generate_acquire_msg (r->domain, r->lock); | ||
426 | r->mqe = queue_message (h, msg, r); | ||
427 | if (GNUNET_LOCKMANAGER_RELEASE == r->status) | ||
428 | return GNUNET_YES; | ||
429 | if (NULL != r->status_cb) | ||
430 | { | ||
431 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
432 | "Calling status change for RELEASE on lock num: %d, domain: %s\n", | ||
433 | r->lock, r->domain); | ||
434 | r->status = GNUNET_LOCKMANAGER_RELEASE; | ||
435 | r->status_cb (r->status_cb_cls, r->domain, r->lock, | ||
436 | GNUNET_LOCKMANAGER_RELEASE); | ||
437 | } | ||
438 | return GNUNET_YES; | ||
439 | } | ||
440 | |||
441 | |||
442 | /** | ||
443 | * Handler for server replies | ||
444 | * | ||
445 | * @param cls the LOCKMANAGER_Handle | ||
446 | * @param msg received message, NULL on timeout or fatal error | ||
447 | */ | ||
448 | static void | ||
449 | handle_replies (void *cls, const struct GNUNET_MessageHeader *msg) | ||
450 | { | ||
451 | struct GNUNET_LOCKMANAGER_Handle *handle = cls; | ||
452 | const struct GNUNET_LOCKMANAGER_Message *m; | ||
453 | struct GNUNET_LOCKMANAGER_LockingRequest *lr; | ||
454 | const char *domain; | ||
455 | struct GNUNET_HashCode hash; | ||
456 | uint32_t lock; | ||
457 | uint16_t msize; | ||
458 | |||
459 | handle->in_replies = GNUNET_NO; | ||
460 | if (NULL == msg) | ||
461 | { | ||
462 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
463 | "Lockmanager service not available or went down\n"); | ||
464 | /* Should release all locks and retry to acquire them */ | ||
465 | GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, | ||
466 | &release_n_retry_iterator, handle); | ||
467 | return; | ||
468 | } | ||
469 | handle->in_replies = GNUNET_YES; | ||
470 | GNUNET_CLIENT_receive (handle->conn, &handle_replies, handle, | ||
471 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
472 | if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs (msg->type)) | ||
473 | { | ||
474 | GNUNET_break (0); | ||
475 | return; | ||
476 | } | ||
477 | msize = ntohs (msg->size); | ||
478 | if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message)) | ||
479 | { | ||
480 | GNUNET_break (0); | ||
481 | return; | ||
482 | } | ||
483 | m = (const struct GNUNET_LOCKMANAGER_Message *) msg; | ||
484 | domain = (const char *) &m[1]; | ||
485 | msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); | ||
486 | if ('\0' != domain[msize - 1]) | ||
487 | { | ||
488 | GNUNET_break (0); | ||
489 | return; | ||
490 | } | ||
491 | |||
492 | lock = ntohl (m->lock); | ||
493 | get_key (domain, lock, &hash); | ||
494 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
495 | "Received SUCCESS message for lock: %d, domain %s\n", lock, domain); | ||
496 | if (NULL == | ||
497 | (lr = hashmap_find_lockingrequest (handle->hashmap, domain, lock))) | ||
498 | { | ||
499 | GNUNET_break (0); | ||
500 | return; | ||
501 | } | ||
502 | if (GNUNET_LOCKMANAGER_SUCCESS == lr->status) | ||
503 | { | ||
504 | GNUNET_break (0); | ||
505 | return; | ||
506 | } | ||
507 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
508 | "Changing status for lock: %d in domain: %s to SUCCESS\n", lr->lock, | ||
509 | lr->domain); | ||
510 | lr->status = GNUNET_LOCKMANAGER_SUCCESS; | ||
511 | GNUNET_SCHEDULER_add_continuation (&call_status_cb_task, lr, | ||
512 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
513 | } | ||
514 | |||
515 | |||
516 | /** | ||
517 | * Iterator to free hash map entries. | ||
518 | * | ||
519 | * @param cls the lockmanger handle | ||
520 | * @param key current key code | ||
521 | * @param value the Locking request | ||
522 | * @return GNUNET_YES if we should continue to | ||
523 | * iterate, | ||
524 | * GNUNET_NO if not. | ||
525 | */ | ||
526 | static int | ||
527 | free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
528 | { | ||
529 | struct GNUNET_LOCKMANAGER_Handle *h = cls; | ||
530 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; | ||
531 | |||
532 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Clearing locking request\n"); | ||
533 | GNUNET_assert (GNUNET_YES == | ||
534 | GNUNET_CONTAINER_multihashmap_remove (h->hashmap, key, value)); | ||
535 | GNUNET_free (r->domain); | ||
536 | GNUNET_free (r); | ||
537 | return GNUNET_YES; | ||
538 | } | ||
539 | |||
540 | |||
541 | /*******************/ | ||
542 | /* API Definitions */ | ||
543 | /*******************/ | ||
544 | |||
545 | |||
546 | /** | ||
547 | * Connect to the lockmanager service | ||
548 | * | ||
549 | * @param cfg the configuration to use | ||
550 | * | ||
551 | * @return upon success the handle to the service; NULL upon error | ||
552 | */ | ||
553 | struct GNUNET_LOCKMANAGER_Handle * | ||
554 | GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
555 | { | ||
556 | struct GNUNET_LOCKMANAGER_Handle *h; | ||
557 | |||
558 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | ||
559 | h = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_Handle)); | ||
560 | h->conn = GNUNET_CLIENT_connect ("lockmanager", cfg); | ||
561 | if (NULL == h->conn) | ||
562 | { | ||
563 | GNUNET_free (h); | ||
564 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
565 | return NULL; | ||
566 | } | ||
567 | h->hashmap = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); | ||
568 | GNUNET_assert (NULL != h->hashmap); | ||
569 | h->in_replies = GNUNET_YES; | ||
570 | GNUNET_CLIENT_receive (h->conn, &handle_replies, h, | ||
571 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
572 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
573 | return h; | ||
574 | } | ||
575 | |||
576 | |||
577 | /** | ||
578 | * Disconnect from the lockmanager service | ||
579 | * | ||
580 | * @param handle the handle to the lockmanager service | ||
581 | */ | ||
582 | void | ||
583 | GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) | ||
584 | { | ||
585 | struct MessageQueue *head; | ||
586 | |||
587 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | ||
588 | if (0 != GNUNET_CONTAINER_multihashmap_size (handle->hashmap)) | ||
589 | { | ||
590 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
591 | "Some locking requests are still present. Cancel them before " | ||
592 | "calling %s\n", __func__); | ||
593 | GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, &free_iterator, | ||
594 | handle); | ||
595 | } | ||
596 | GNUNET_CONTAINER_multihashmap_destroy (handle->hashmap); | ||
597 | /* Clear the message queue */ | ||
598 | if (NULL != handle->transmit_handle) | ||
599 | { | ||
600 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->transmit_handle); | ||
601 | } | ||
602 | head = handle->mq_head; | ||
603 | while (NULL != head) | ||
604 | { | ||
605 | GNUNET_CONTAINER_DLL_remove (handle->mq_head, handle->mq_tail, head); | ||
606 | GNUNET_free (head->msg); | ||
607 | GNUNET_free (head); | ||
608 | head = handle->mq_head; | ||
609 | } | ||
610 | GNUNET_CLIENT_disconnect (handle->conn); | ||
611 | GNUNET_free (handle); | ||
612 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
613 | } | ||
614 | |||
615 | |||
616 | /** | ||
617 | * Tries to acquire the given lock(even if the lock has been lost) until the | ||
618 | * request is called. If the lock is available the status_cb will be | ||
619 | * called. If the lock is busy then the request is queued and status_cb | ||
620 | * will be called when the lock has been made available and acquired by us. | ||
621 | * | ||
622 | * @param handle the handle to the lockmanager service | ||
623 | * | ||
624 | * @param domain_name name of the locking domain. Clients who want to share | ||
625 | * locks must use the same name for the locking domain. Also the | ||
626 | * domain_name should be selected with the prefix | ||
627 | * "GNUNET_<PROGRAM_NAME>_" to avoid domain name collisions. | ||
628 | * | ||
629 | * | ||
630 | * @param lock which lock to lock | ||
631 | * | ||
632 | * @param status_cb the callback for signalling when the lock is acquired and | ||
633 | * when it is lost | ||
634 | * | ||
635 | * @param status_cb_cls the closure to the above callback | ||
636 | * | ||
637 | * @return the locking request handle for this request | ||
638 | */ | ||
639 | struct GNUNET_LOCKMANAGER_LockingRequest * | ||
640 | GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | ||
641 | const char *domain_name, uint32_t lock, | ||
642 | GNUNET_LOCKMANAGER_StatusCallback status_cb, | ||
643 | void *status_cb_cls) | ||
644 | { | ||
645 | struct GNUNET_LOCKMANAGER_LockingRequest *r; | ||
646 | struct GNUNET_LOCKMANAGER_Message *msg; | ||
647 | struct GNUNET_HashCode hash; | ||
648 | size_t domain_name_length; | ||
649 | |||
650 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | ||
651 | r = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_LockingRequest)); | ||
652 | domain_name_length = strlen (domain_name) + 1; | ||
653 | r->handle = handle; | ||
654 | r->lock = lock; | ||
655 | r->domain = GNUNET_malloc (domain_name_length); | ||
656 | r->status = GNUNET_LOCKMANAGER_RELEASE; | ||
657 | r->status_cb = status_cb; | ||
658 | r->status_cb_cls = status_cb_cls; | ||
659 | r->acquire_sent = GNUNET_NO; | ||
660 | memcpy (r->domain, domain_name, domain_name_length); | ||
661 | msg = generate_acquire_msg (r->domain, r->lock); | ||
662 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Queueing ACQUIRE message\n"); | ||
663 | r->mqe = queue_message (handle, msg, r); | ||
664 | get_key (r->domain, r->lock, &hash); | ||
665 | GNUNET_assert (GNUNET_OK == | ||
666 | GNUNET_CONTAINER_multihashmap_put (r->handle->hashmap, &hash, | ||
667 | r, | ||
668 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
669 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
670 | return r; | ||
671 | } | ||
672 | |||
673 | |||
674 | /** | ||
675 | * Function to cancel the locking request generated by | ||
676 | * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired by us then the lock | ||
677 | * is released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any | ||
678 | * status changes resulting due to this call. | ||
679 | * | ||
680 | * @param request the LockingRequest to cancel | ||
681 | */ | ||
682 | void | ||
683 | GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest | ||
684 | *request) | ||
685 | { | ||
686 | struct GNUNET_LOCKMANAGER_Message *msg; | ||
687 | struct GNUNET_HashCode hash; | ||
688 | uint16_t msg_size; | ||
689 | size_t domain_name_length; | ||
690 | |||
691 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | ||
692 | if (GNUNET_NO == request->acquire_sent) | ||
693 | { | ||
694 | GNUNET_assert (NULL != request->mqe); | ||
695 | if ((NULL != request->handle->transmit_handle) && | ||
696 | (request->handle->mq_head == request->mqe)) | ||
697 | { | ||
698 | GNUNET_CLIENT_notify_transmit_ready_cancel (request-> | ||
699 | handle->transmit_handle); | ||
700 | request->handle->transmit_handle = NULL; | ||
701 | } | ||
702 | GNUNET_CONTAINER_DLL_remove (request->handle->mq_head, | ||
703 | request->handle->mq_tail, request->mqe); | ||
704 | GNUNET_free (request->mqe->msg); | ||
705 | GNUNET_free (request->mqe); | ||
706 | request->status = GNUNET_LOCKMANAGER_RELEASE; | ||
707 | } | ||
708 | if (GNUNET_LOCKMANAGER_SUCCESS == request->status) | ||
709 | { | ||
710 | domain_name_length = strlen (request->domain) + 1; | ||
711 | msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_length; | ||
712 | msg = GNUNET_malloc (msg_size); | ||
713 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE); | ||
714 | msg->header.size = htons (msg_size); | ||
715 | msg->lock = htonl (request->lock); | ||
716 | memcpy (&msg[1], request->domain, domain_name_length); | ||
717 | GNUNET_assert (NULL == request->mqe); | ||
718 | (void) queue_message (request->handle, msg, request); | ||
719 | } | ||
720 | get_key (request->domain, request->lock, &hash); | ||
721 | GNUNET_assert (GNUNET_YES == | ||
722 | GNUNET_CONTAINER_multihashmap_remove (request->handle->hashmap, | ||
723 | &hash, request)); | ||
724 | GNUNET_free (request->domain); | ||
725 | GNUNET_free (request); | ||
726 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | ||
727 | } | ||
728 | |||
729 | /* 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008--2013 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 3, 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/test_lockmanager_api.c | ||
23 | * @brief Test cases for lockmanager_api.c | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_lockmanager_service.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | |||
32 | /** | ||
33 | * Generic logging shortcut | ||
34 | */ | ||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
38 | #define TIME_REL_SECONDS(min) \ | ||
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Enumeration of testing steps | ||
44 | */ | ||
45 | enum Test | ||
46 | { | ||
47 | TEST_FAIL, | ||
48 | |||
49 | TEST_INIT, | ||
50 | |||
51 | LOCK1_ACQUIRE, | ||
52 | |||
53 | LOCK2_ACQUIRE | ||
54 | }; | ||
55 | |||
56 | |||
57 | /** | ||
58 | * The testing result | ||
59 | */ | ||
60 | static enum Test result; | ||
61 | |||
62 | /** | ||
63 | * Configuration Handle | ||
64 | */ | ||
65 | static const struct GNUNET_CONFIGURATION_Handle *config; | ||
66 | |||
67 | /** | ||
68 | * The handle to the lockmanager service | ||
69 | */ | ||
70 | static struct GNUNET_LOCKMANAGER_Handle *handle; | ||
71 | |||
72 | /** | ||
73 | * The locking request | ||
74 | */ | ||
75 | static struct GNUNET_LOCKMANAGER_LockingRequest *request; | ||
76 | |||
77 | /** | ||
78 | * The second locking request | ||
79 | */ | ||
80 | static struct GNUNET_LOCKMANAGER_LockingRequest *request2; | ||
81 | |||
82 | /** | ||
83 | * Abort task identifier | ||
84 | */ | ||
85 | static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; | ||
86 | |||
87 | /** | ||
88 | * Shutdown nicely | ||
89 | * | ||
90 | * @param cls | ||
91 | * @param tc the task context | ||
92 | */ | ||
93 | static void | ||
94 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
95 | { | ||
96 | if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) | ||
97 | { | ||
98 | GNUNET_SCHEDULER_cancel (abort_task_id); | ||
99 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
100 | } | ||
101 | if (NULL != request) | ||
102 | GNUNET_LOCKMANAGER_cancel_request (request); | ||
103 | if (NULL != request2) | ||
104 | GNUNET_LOCKMANAGER_cancel_request (request2); | ||
105 | GNUNET_LOCKMANAGER_disconnect (handle); | ||
106 | GNUNET_SCHEDULER_shutdown (); | ||
107 | } | ||
108 | |||
109 | |||
110 | /** | ||
111 | * Shutdown nicely | ||
112 | * | ||
113 | * @param cls | ||
114 | * @param tc the task context | ||
115 | */ | ||
116 | static void | ||
117 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
118 | { | ||
119 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); | ||
120 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
121 | result = TEST_FAIL; | ||
122 | do_shutdown (cls, tc); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * Callback for lock status changes | ||
127 | * | ||
128 | * @param cls the closure from GNUNET_LOCKMANAGER_lock call | ||
129 | * | ||
130 | * @param domain_name the locking domain of the lock | ||
131 | * | ||
132 | * @param lock the lock for which this status is relevant | ||
133 | * | ||
134 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | ||
135 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | ||
136 | */ | ||
137 | static void | ||
138 | status_cb (void *cls, const char *domain_name, uint32_t lock, | ||
139 | enum GNUNET_LOCKMANAGER_Status status) | ||
140 | { | ||
141 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
142 | "Status change callback called on lock: %d of domain: %s\n", lock, | ||
143 | domain_name); | ||
144 | switch (result) | ||
145 | { | ||
146 | case LOCK1_ACQUIRE: | ||
147 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
148 | GNUNET_assert (NULL != request); | ||
149 | //GNUNET_LOCKMANAGER_cancel_request (request); | ||
150 | //request = NULL; | ||
151 | result = LOCK2_ACQUIRE; | ||
152 | request2 = | ||
153 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", | ||
154 | 100, &status_cb, NULL); | ||
155 | GNUNET_assert (NULL != request2); | ||
156 | break; | ||
157 | case LOCK2_ACQUIRE: | ||
158 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
159 | GNUNET_assert (NULL != request); | ||
160 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); | ||
161 | break; | ||
162 | default: | ||
163 | GNUNET_break (0); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | |||
168 | /** | ||
169 | * Main point of test execution | ||
170 | */ | ||
171 | static void | ||
172 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
173 | struct GNUNET_TESTING_Peer *peer) | ||
174 | { | ||
175 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); | ||
176 | config = cfg; | ||
177 | handle = GNUNET_LOCKMANAGER_connect (config); | ||
178 | GNUNET_assert (NULL != handle); | ||
179 | result = LOCK1_ACQUIRE; | ||
180 | request = | ||
181 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, | ||
182 | &status_cb, NULL); | ||
183 | abort_task_id = | ||
184 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (30), &do_abort, NULL); | ||
185 | } | ||
186 | |||
187 | |||
188 | /** | ||
189 | * Main function | ||
190 | */ | ||
191 | int | ||
192 | main (int argc, char **argv) | ||
193 | { | ||
194 | |||
195 | if (0 != | ||
196 | GNUNET_TESTING_peer_run ("test_lockmanager_api", | ||
197 | "test_lockmanager_api.conf", &run, NULL)) | ||
198 | return 1; | ||
199 | return (TEST_FAIL == result) ? 1 : 0; | ||
200 | } | ||
201 | |||
202 | /* 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 @@ | |||
1 | [lockmanager] | ||
2 | AUTOSTART = NO | ||
3 | PORT = 12112 | ||
4 | ACCEPT_FROM = 127.0.0.1; | ||
5 | HOSTNAME = localhost | ||
6 | # PREFIX = valgrind --leak-check=full | ||
7 | # PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args | ||
8 | |||
9 | [fs] | ||
10 | AUTOSTART = NO | ||
11 | |||
12 | [resolver] | ||
13 | AUTOSTART = NO | ||
14 | |||
15 | [mesh] | ||
16 | AUTOSTART = NO | ||
17 | |||
18 | [dht] | ||
19 | AUTOSTART = NO | ||
20 | |||
21 | [dhtcache] | ||
22 | QUOTA = 1 MB | ||
23 | DATABASE = heap | ||
24 | |||
25 | [transport] | ||
26 | PLUGINS = tcp | ||
27 | ACCEPT_FROM6 = ::1; | ||
28 | ACCEPT_FROM = 127.0.0.1; | ||
29 | NEIGHBOUR_LIMIT = 50 | ||
30 | PORT = 12365 | ||
31 | |||
32 | [ats] | ||
33 | WAN_QUOTA_OUT = 3932160 | ||
34 | WAN_QUOTA_IN = 3932160 | ||
35 | |||
36 | [core] | ||
37 | PORT = 12092 | ||
38 | |||
39 | [arm] | ||
40 | DEFAULTSERVICES = core lockmanager | ||
41 | PORT = 12366 | ||
42 | |||
43 | [transport-tcp] | ||
44 | TIMEOUT = 300 s | ||
45 | PORT = 12368 | ||
46 | |||
47 | [TESTING] | ||
48 | NUM_PEERS = 5 | ||
49 | HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat | ||
50 | MAX_CONCURRENT_SSH = 10 | ||
51 | USE_PROGRESSBARS = YES | ||
52 | PEERGROUP_TIMEOUT = 2400 s | ||
53 | |||
54 | [PATHS] | ||
55 | SERVICEHOME = /tmp/test-lockmanager/ | ||
56 | |||
57 | [dns] | ||
58 | AUTOSTART = NO | ||
59 | |||
60 | [nse] | ||
61 | AUTOSTART = NO | ||
62 | |||
63 | [consensus] | ||
64 | 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008--2013 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 3, 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/test_lockmanager_api_acquireretry.c | ||
23 | * @brief Test cases for lockmanager_api where the server crashes and comes | ||
24 | * back; the api should try to acqurie the lock again | ||
25 | * @author Sree Harsha Totakura | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_lockmanager_service.h" | ||
31 | #include "gnunet_testing_lib.h" | ||
32 | |||
33 | /** | ||
34 | * Generic logging shorthand | ||
35 | */ | ||
36 | #define LOG(kind,...) \ | ||
37 | GNUNET_log (kind, __VA_ARGS__) | ||
38 | |||
39 | /** | ||
40 | * Relative seconds shorthand | ||
41 | */ | ||
42 | #define TIME_REL_SECS(sec) \ | ||
43 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | ||
44 | |||
45 | /** | ||
46 | * Various stages in test | ||
47 | */ | ||
48 | enum Test | ||
49 | { | ||
50 | /** | ||
51 | * Signal test failure | ||
52 | */ | ||
53 | TEST_FAIL, | ||
54 | |||
55 | /** | ||
56 | * Testing just began | ||
57 | */ | ||
58 | TEST_INIT, | ||
59 | |||
60 | /** | ||
61 | * Client has successfully acquired the lock | ||
62 | */ | ||
63 | TEST_CLIENT_LOCK_SUCCESS, | ||
64 | |||
65 | /** | ||
66 | * Client has lost the lock | ||
67 | */ | ||
68 | TEST_CLIENT_LOCK_RELEASE, | ||
69 | |||
70 | /** | ||
71 | * Client has again acquired the lock | ||
72 | */ | ||
73 | TEST_CLIENT_LOCK_AGAIN_SUCCESS | ||
74 | }; | ||
75 | |||
76 | /** | ||
77 | * Configuration Handle | ||
78 | */ | ||
79 | static const struct GNUNET_CONFIGURATION_Handle *config; | ||
80 | |||
81 | /** | ||
82 | * The handle to the lockmanager service | ||
83 | */ | ||
84 | static struct GNUNET_LOCKMANAGER_Handle *handle; | ||
85 | |||
86 | /** | ||
87 | * The locking request | ||
88 | */ | ||
89 | static struct GNUNET_LOCKMANAGER_LockingRequest *request; | ||
90 | |||
91 | /** | ||
92 | * Abort task identifier | ||
93 | */ | ||
94 | static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; | ||
95 | |||
96 | /** | ||
97 | * The test result | ||
98 | */ | ||
99 | enum Test result; | ||
100 | |||
101 | /** | ||
102 | * Our peer | ||
103 | */ | ||
104 | static struct GNUNET_TESTING_Peer *self; | ||
105 | |||
106 | |||
107 | /** | ||
108 | * Shutdown nicely | ||
109 | * | ||
110 | * @param cls | ||
111 | * @param tc the task context | ||
112 | */ | ||
113 | static void | ||
114 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
115 | { | ||
116 | if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) | ||
117 | { | ||
118 | GNUNET_SCHEDULER_cancel (abort_task_id); | ||
119 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
120 | } | ||
121 | if (NULL != handle) | ||
122 | GNUNET_LOCKMANAGER_disconnect (handle); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * Abort | ||
127 | * | ||
128 | * @param cls | ||
129 | * @param tc the task context | ||
130 | */ | ||
131 | static void | ||
132 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
133 | { | ||
134 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); | ||
135 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
136 | result = TEST_FAIL; | ||
137 | do_shutdown (cls, tc); | ||
138 | } | ||
139 | |||
140 | |||
141 | /** | ||
142 | * Callback for lock status changes | ||
143 | * | ||
144 | * @param cls the handle | ||
145 | * | ||
146 | * @param domain_name the locking domain of the lock | ||
147 | * | ||
148 | * @param lock the lock for which this status is relevant | ||
149 | * | ||
150 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | ||
151 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | ||
152 | */ | ||
153 | static void | ||
154 | status_cb (void *cls, const char *domain_name, uint32_t lock, | ||
155 | enum GNUNET_LOCKMANAGER_Status status) | ||
156 | { | ||
157 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
158 | "Status change callback called on lock: %d of domain: %s\n", lock, | ||
159 | domain_name); | ||
160 | switch (result) | ||
161 | { | ||
162 | case TEST_INIT: | ||
163 | GNUNET_assert (handle == cls); | ||
164 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
165 | result = TEST_CLIENT_LOCK_SUCCESS; | ||
166 | /* We should kill the lockmanager process */ | ||
167 | GNUNET_TESTING_peer_stop (self); | ||
168 | break; | ||
169 | case TEST_CLIENT_LOCK_SUCCESS: | ||
170 | GNUNET_assert (handle == cls); | ||
171 | GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status); | ||
172 | result = TEST_CLIENT_LOCK_RELEASE; | ||
173 | /* Now we should start again the lockmanager process */ | ||
174 | GNUNET_TESTING_peer_start (self); | ||
175 | break; | ||
176 | case TEST_CLIENT_LOCK_RELEASE: | ||
177 | GNUNET_assert (handle == cls); | ||
178 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
179 | result = TEST_CLIENT_LOCK_AGAIN_SUCCESS; | ||
180 | GNUNET_LOCKMANAGER_cancel_request (request); | ||
181 | request = NULL; | ||
182 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), &do_shutdown, NULL); | ||
183 | break; | ||
184 | default: | ||
185 | GNUNET_assert (0); /* We should never reach here */ | ||
186 | } | ||
187 | } | ||
188 | |||
189 | |||
190 | /** | ||
191 | * Main point of test execution | ||
192 | */ | ||
193 | static void | ||
194 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
195 | struct GNUNET_TESTING_Peer *peer) | ||
196 | { | ||
197 | config = cfg; | ||
198 | self = peer; | ||
199 | result = TEST_INIT; | ||
200 | handle = GNUNET_LOCKMANAGER_connect (config); | ||
201 | GNUNET_assert (NULL != handle); | ||
202 | request = | ||
203 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, | ||
204 | &status_cb, handle); | ||
205 | GNUNET_assert (NULL != request); | ||
206 | abort_task_id = | ||
207 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (30), &do_abort, NULL); | ||
208 | } | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Main function | ||
213 | */ | ||
214 | int | ||
215 | main (int argc, char **argv) | ||
216 | { | ||
217 | if (0 != | ||
218 | GNUNET_TESTING_peer_run ("test_lockmanager_api_acquireretry", | ||
219 | "test_lockmanager_api.conf", &run, NULL)) | ||
220 | return 1; | ||
221 | return (TEST_CLIENT_LOCK_AGAIN_SUCCESS != result) ? 1 : 0; | ||
222 | } | ||
223 | |||
224 | /* 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008--2013 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 3, 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/test_lockmanager_api_lockrelease.c | ||
23 | * @brief Test cases for lockmanager_api where client disconnects abruptly | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testing_lib.h" | ||
30 | #include "gnunet_lockmanager_service.h" | ||
31 | |||
32 | /** | ||
33 | * Generic Logging shorthand | ||
34 | */ | ||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
38 | /** | ||
39 | * Relative seconds shorthand | ||
40 | */ | ||
41 | #define TIME_REL_SECONDS(min) \ | ||
42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) | ||
43 | |||
44 | /** | ||
45 | * Various steps of the test | ||
46 | */ | ||
47 | enum Test | ||
48 | { | ||
49 | /** | ||
50 | * Signal test failure | ||
51 | */ | ||
52 | TEST_FAIL, | ||
53 | |||
54 | /** | ||
55 | * Testing just began | ||
56 | */ | ||
57 | TEST_INIT, | ||
58 | |||
59 | /** | ||
60 | * Client 1 has got the lock successfully; Client 2 should try to acquire | ||
61 | * the lock now; after some time client 1 has to release the lock | ||
62 | */ | ||
63 | TEST_CLIENT1_LOCK_SUCCESS, | ||
64 | |||
65 | /** | ||
66 | * Client 2 has got the lock; Should release it and call shutdown | ||
67 | */ | ||
68 | TEST_CLIENT2_LOCK_SUCCESS, | ||
69 | }; | ||
70 | |||
71 | /** | ||
72 | * The testing result | ||
73 | */ | ||
74 | static enum Test result; | ||
75 | |||
76 | /** | ||
77 | * Configuration Handle | ||
78 | */ | ||
79 | static const struct GNUNET_CONFIGURATION_Handle *config; | ||
80 | |||
81 | /** | ||
82 | * The handle to the lockmanager service | ||
83 | */ | ||
84 | static struct GNUNET_LOCKMANAGER_Handle *handle; | ||
85 | |||
86 | /** | ||
87 | * A second client handle to the lockmanager service | ||
88 | */ | ||
89 | static struct GNUNET_LOCKMANAGER_Handle *handle2; | ||
90 | |||
91 | /** | ||
92 | * The locking request | ||
93 | */ | ||
94 | static struct GNUNET_LOCKMANAGER_LockingRequest *request; | ||
95 | |||
96 | /** | ||
97 | * The locking request of second client | ||
98 | */ | ||
99 | static struct GNUNET_LOCKMANAGER_LockingRequest *request2; | ||
100 | |||
101 | /** | ||
102 | * Abort task identifier | ||
103 | */ | ||
104 | static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; | ||
105 | |||
106 | |||
107 | /** | ||
108 | * Shutdown nicely | ||
109 | * | ||
110 | * @param cls | ||
111 | * @param tc the task context | ||
112 | */ | ||
113 | static void | ||
114 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
115 | { | ||
116 | if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) | ||
117 | { | ||
118 | GNUNET_SCHEDULER_cancel (abort_task_id); | ||
119 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
120 | } | ||
121 | GNUNET_LOCKMANAGER_disconnect (handle); | ||
122 | GNUNET_LOCKMANAGER_disconnect (handle2); | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Abort | ||
128 | * | ||
129 | * @param cls | ||
130 | * @param tc the task context | ||
131 | */ | ||
132 | static void | ||
133 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
134 | { | ||
135 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); | ||
136 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
137 | result = TEST_FAIL; | ||
138 | do_shutdown (cls, tc); | ||
139 | } | ||
140 | |||
141 | |||
142 | /** | ||
143 | * Callback for lock status changes | ||
144 | * | ||
145 | * @param cls the handle | ||
146 | * | ||
147 | * @param domain_name the locking domain of the lock | ||
148 | * | ||
149 | * @param lock the lock for which this status is relevant | ||
150 | * | ||
151 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | ||
152 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | ||
153 | */ | ||
154 | static void | ||
155 | status_cb (void *cls, const char *domain_name, uint32_t lock, | ||
156 | enum GNUNET_LOCKMANAGER_Status status) | ||
157 | { | ||
158 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
159 | "Status change callback called on lock: %d of domain: %s\n", lock, | ||
160 | domain_name); | ||
161 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
162 | switch (result) | ||
163 | { | ||
164 | case TEST_INIT: | ||
165 | GNUNET_assert (handle == cls); | ||
166 | result = TEST_CLIENT1_LOCK_SUCCESS; | ||
167 | request2 = | ||
168 | GNUNET_LOCKMANAGER_acquire_lock (handle2, "GNUNET_LOCKMANAGER_TESTING", | ||
169 | 99, &status_cb, handle2); | ||
170 | GNUNET_assert (NULL != request2); | ||
171 | GNUNET_LOCKMANAGER_cancel_request (request); | ||
172 | request = NULL; | ||
173 | break; | ||
174 | case TEST_CLIENT1_LOCK_SUCCESS: | ||
175 | GNUNET_assert (handle2 == cls); | ||
176 | result = TEST_CLIENT2_LOCK_SUCCESS; | ||
177 | GNUNET_LOCKMANAGER_cancel_request (request2); | ||
178 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); | ||
179 | break; | ||
180 | default: | ||
181 | GNUNET_assert (0); /* We should never reach here */ | ||
182 | } | ||
183 | |||
184 | } | ||
185 | |||
186 | |||
187 | /** | ||
188 | * Main point of test execution | ||
189 | */ | ||
190 | static void | ||
191 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
192 | struct GNUNET_TESTING_Peer *peer) | ||
193 | { | ||
194 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); | ||
195 | config = cfg; | ||
196 | result = TEST_INIT; | ||
197 | handle = GNUNET_LOCKMANAGER_connect (config); | ||
198 | GNUNET_assert (NULL != handle); | ||
199 | handle2 = GNUNET_LOCKMANAGER_connect (config); | ||
200 | |||
201 | request = | ||
202 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, | ||
203 | &status_cb, handle); | ||
204 | GNUNET_assert (NULL != request); | ||
205 | abort_task_id = | ||
206 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), &do_abort, NULL); | ||
207 | } | ||
208 | |||
209 | |||
210 | /** | ||
211 | * Main function | ||
212 | */ | ||
213 | int | ||
214 | main (int argc, char **argv) | ||
215 | { | ||
216 | if (0 != | ||
217 | GNUNET_TESTING_peer_run ("test_lockmanager_api_lockrelease", | ||
218 | "test_lockmanager_api.conf", &run, NULL)) | ||
219 | return 1; | ||
220 | return (TEST_CLIENT2_LOCK_SUCCESS != result) ? 1 : 0; | ||
221 | } | ||
222 | |||
223 | /* 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008--2013 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 3, 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/test_lockmanager_api_servercrash.c | ||
23 | * @brief Test cases for lockmanager_api where the server crashes | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_lockmanager_service.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | |||
32 | /** | ||
33 | * Generic logging shorthand | ||
34 | */ | ||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
38 | /** | ||
39 | * Relative seconds shorthand | ||
40 | */ | ||
41 | #define TIME_REL_SECONDS(min) \ | ||
42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min) | ||
43 | |||
44 | /** | ||
45 | * Various steps of the test | ||
46 | */ | ||
47 | enum Test | ||
48 | { | ||
49 | /** | ||
50 | * Signal test failure | ||
51 | */ | ||
52 | TEST_FAIL, | ||
53 | |||
54 | /** | ||
55 | * Testing just began | ||
56 | */ | ||
57 | TEST_INIT, | ||
58 | |||
59 | /** | ||
60 | * Client 1 has got the lock successfully; Client 2 should try to acquire | ||
61 | * the lock now; after some time client 1 has to release the lock | ||
62 | */ | ||
63 | TEST_CLIENT1_LOCK_SUCCESS, | ||
64 | |||
65 | /** | ||
66 | * Client 2 has got the lock; Server should crash now; | ||
67 | */ | ||
68 | TEST_CLIENT2_LOCK_SUCCESS, | ||
69 | |||
70 | /** | ||
71 | * Client 2 should get lock release due to server crash; Should call | ||
72 | * shutdown now | ||
73 | */ | ||
74 | TEST_CLIENT2_SERVER_CRASH_SUCCESS | ||
75 | }; | ||
76 | |||
77 | /** | ||
78 | * The testing result | ||
79 | */ | ||
80 | static enum Test result; | ||
81 | |||
82 | /** | ||
83 | * Configuration Handle | ||
84 | */ | ||
85 | static const struct GNUNET_CONFIGURATION_Handle *config; | ||
86 | |||
87 | /** | ||
88 | * The handle to the lockmanager service | ||
89 | */ | ||
90 | static struct GNUNET_LOCKMANAGER_Handle *handle; | ||
91 | |||
92 | /** | ||
93 | * A second client handle to the lockmanager service | ||
94 | */ | ||
95 | static struct GNUNET_LOCKMANAGER_Handle *handle2; | ||
96 | |||
97 | /** | ||
98 | * The locking request | ||
99 | */ | ||
100 | static struct GNUNET_LOCKMANAGER_LockingRequest *request; | ||
101 | |||
102 | /** | ||
103 | * The locking request of second client | ||
104 | */ | ||
105 | static struct GNUNET_LOCKMANAGER_LockingRequest *request2; | ||
106 | |||
107 | /** | ||
108 | * Abort task identifier | ||
109 | */ | ||
110 | static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; | ||
111 | |||
112 | /** | ||
113 | * Our peer | ||
114 | */ | ||
115 | static struct GNUNET_TESTING_Peer *self; | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Shutdown nicely | ||
120 | * | ||
121 | * @param cls | ||
122 | * @param tc the task context | ||
123 | */ | ||
124 | static void | ||
125 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
126 | { | ||
127 | if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) | ||
128 | { | ||
129 | GNUNET_SCHEDULER_cancel (abort_task_id); | ||
130 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
131 | } | ||
132 | if (NULL != handle) | ||
133 | GNUNET_LOCKMANAGER_disconnect (handle); | ||
134 | if (NULL != handle2) | ||
135 | GNUNET_LOCKMANAGER_disconnect (handle2); | ||
136 | } | ||
137 | |||
138 | |||
139 | /** | ||
140 | * Abort | ||
141 | * | ||
142 | * @param cls | ||
143 | * @param tc the task context | ||
144 | */ | ||
145 | static void | ||
146 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
147 | { | ||
148 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); | ||
149 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
150 | result = TEST_FAIL; | ||
151 | do_shutdown (cls, tc); | ||
152 | } | ||
153 | |||
154 | |||
155 | /** | ||
156 | * Callback for lock status changes | ||
157 | * | ||
158 | * @param cls the handle | ||
159 | * | ||
160 | * @param domain_name the locking domain of the lock | ||
161 | * | ||
162 | * @param lock the lock for which this status is relevant | ||
163 | * | ||
164 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | ||
165 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | ||
166 | */ | ||
167 | static void | ||
168 | status_cb (void *cls, const char *domain_name, uint32_t lock, | ||
169 | enum GNUNET_LOCKMANAGER_Status status) | ||
170 | { | ||
171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
172 | "Status change callback called on lock: %d of domain: %s\n", lock, | ||
173 | domain_name); | ||
174 | switch (result) | ||
175 | { | ||
176 | case TEST_INIT: | ||
177 | GNUNET_assert (handle == cls); | ||
178 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
179 | result = TEST_CLIENT1_LOCK_SUCCESS; | ||
180 | request2 = | ||
181 | GNUNET_LOCKMANAGER_acquire_lock (handle2, "GNUNET_LOCKMANAGER_TESTING", | ||
182 | 99, &status_cb, handle2); | ||
183 | GNUNET_assert (NULL != request2); | ||
184 | GNUNET_LOCKMANAGER_cancel_request (request); | ||
185 | request = NULL; | ||
186 | break; | ||
187 | case TEST_CLIENT1_LOCK_SUCCESS: | ||
188 | GNUNET_assert (handle2 == cls); | ||
189 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
190 | result = TEST_CLIENT2_LOCK_SUCCESS; | ||
191 | /* We should stop our peer to simulate crash in lockmanager service */ | ||
192 | GNUNET_TESTING_peer_stop (self); | ||
193 | break; | ||
194 | case TEST_CLIENT2_LOCK_SUCCESS: | ||
195 | GNUNET_assert (handle2 == cls); | ||
196 | GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status); | ||
197 | GNUNET_assert (99 == lock); | ||
198 | GNUNET_assert (0 == strcmp (domain_name, "GNUNET_LOCKMANAGER_TESTING")); | ||
199 | result = TEST_CLIENT2_SERVER_CRASH_SUCCESS; | ||
200 | GNUNET_LOCKMANAGER_cancel_request (request2); | ||
201 | request2 = NULL; | ||
202 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); | ||
203 | break; | ||
204 | default: | ||
205 | GNUNET_assert (0); /* We should never reach here */ | ||
206 | } | ||
207 | } | ||
208 | |||
209 | |||
210 | /** | ||
211 | * Main point of test execution | ||
212 | */ | ||
213 | static void | ||
214 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
215 | struct GNUNET_TESTING_Peer *peer) | ||
216 | { | ||
217 | config = cfg; | ||
218 | self = peer; | ||
219 | result = TEST_INIT; | ||
220 | handle = GNUNET_LOCKMANAGER_connect (config); | ||
221 | GNUNET_assert (NULL != handle); | ||
222 | handle2 = GNUNET_LOCKMANAGER_connect (config); | ||
223 | |||
224 | request = | ||
225 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, | ||
226 | &status_cb, handle); | ||
227 | GNUNET_assert (NULL != request); | ||
228 | abort_task_id = | ||
229 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), &do_abort, NULL); | ||
230 | } | ||
231 | |||
232 | |||
233 | /** | ||
234 | * Main function | ||
235 | */ | ||
236 | int | ||
237 | main (int argc, char **argv) | ||
238 | { | ||
239 | if (0 != | ||
240 | GNUNET_TESTING_peer_run ("test_lockmanager_api_servercrash", | ||
241 | "test_lockmanager_api.conf", &run, NULL)) | ||
242 | return 1; | ||
243 | return (TEST_CLIENT2_SERVER_CRASH_SUCCESS != result) ? 1 : 0; | ||
244 | } | ||
245 | |||
246 | /* 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 @@ | |||
31 | * peers that connect. | 31 | * peers that connect. |
32 | * | 32 | * |
33 | * TODO: | 33 | * TODO: |
34 | * - handle p2p revocations | 34 | * - broadcast p2p revocations |
35 | * - handle p2p connect (trigger SET union) | 35 | * - handle p2p connect (trigger SET union) |
36 | */ | 36 | */ |
37 | #include "platform.h" | 37 | #include "platform.h" |