aboutsummaryrefslogtreecommitdiff
path: root/src/lockmanager
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-06-20 14:24:45 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-06-20 14:24:45 +0000
commit7a35bd8a7522bb9166430d9967382cc1082d23ac (patch)
tree8ebad6d7ad6e0ab4fb878a00df10a60e1d9a77dc /src/lockmanager
parentc5576791b6963e7375b25574e2fdcd2c216bc04d (diff)
downloadgnunet-7a35bd8a7522bb9166430d9967382cc1082d23ac.tar.gz
gnunet-7a35bd8a7522bb9166430d9967382cc1082d23ac.zip
-fixed reply handling
Diffstat (limited to 'src/lockmanager')
-rw-r--r--src/lockmanager/Makefile.am1
-rw-r--r--src/lockmanager/lockmanager_api.c15
-rw-r--r--src/lockmanager/test_lockmanager_api.c107
3 files changed, 25 insertions, 98 deletions
diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am
index d08d02a85..bf2ad5d38 100644
--- a/src/lockmanager/Makefile.am
+++ b/src/lockmanager/Makefile.am
@@ -55,6 +55,7 @@ test_lockmanager_api_SOURCES = \
55 test_lockmanager_api.c 55 test_lockmanager_api.c
56test_lockmanager_api_LDADD = \ 56test_lockmanager_api_LDADD = \
57 $(top_builddir)/src/util/libgnunetutil.la \ 57 $(top_builddir)/src/util/libgnunetutil.la \
58 $(top_builddir)/src/testing/libgnunettesting.la \
58 libgnunetlockmanager.la 59 libgnunetlockmanager.la
59 60
60test_lockmanager_api_lockrelease_SOURCES = \ 61test_lockmanager_api_lockrelease_SOURCES = \
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c
index bfdb2c182..77773ed36 100644
--- a/src/lockmanager/lockmanager_api.c
+++ b/src/lockmanager/lockmanager_api.c
@@ -24,11 +24,6 @@
24 * @author Sree Harsha Totakura 24 * @author Sree Harsha Totakura
25 */ 25 */
26 26
27/**
28 * To be fixed:
29 * Should the handle be freed when the connection to service is lost?
30 * Should cancel_request have a call back (else simultaneous calls break)
31 */
32 27
33#include "platform.h" 28#include "platform.h"
34#include "gnunet_common.h" 29#include "gnunet_common.h"
@@ -244,11 +239,11 @@ transmit_notify (void *cls, size_t size, void *buf)
244 } 239 }
245 if (GNUNET_NO == handle->in_replies) 240 if (GNUNET_NO == handle->in_replies)
246 { 241 {
242 handle->in_replies = GNUNET_YES;
247 GNUNET_CLIENT_receive (handle->conn, 243 GNUNET_CLIENT_receive (handle->conn,
248 &handle_replies, 244 &handle_replies,
249 handle, 245 handle,
250 GNUNET_TIME_UNIT_FOREVER_REL); 246 GNUNET_TIME_UNIT_FOREVER_REL);
251 handle->in_replies = GNUNET_YES;
252 } 247 }
253 return msg_size; 248 return msg_size;
254} 249}
@@ -325,7 +320,7 @@ match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
325 320
326 if ( (match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain)) ) 321 if ( (match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain)) )
327 { 322 {
328 match->matched_entry = lr; 323 match->matched_entry = lr;
329 return GNUNET_NO; 324 return GNUNET_NO;
330 } 325 }
331 return GNUNET_YES; 326 return GNUNET_YES;
@@ -478,11 +473,11 @@ handle_replies (void *cls,
478 handle); 473 handle);
479 return; 474 return;
480 } 475 }
476 handle->in_replies = GNUNET_YES;
481 GNUNET_CLIENT_receive (handle->conn, 477 GNUNET_CLIENT_receive (handle->conn,
482 &handle_replies, 478 &handle_replies,
483 handle, 479 handle,
484 GNUNET_TIME_UNIT_FOREVER_REL); 480 GNUNET_TIME_UNIT_FOREVER_REL);
485 handle->in_replies = GNUNET_YES;
486 if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type)) 481 if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type))
487 { 482 {
488 GNUNET_break (0); 483 GNUNET_break (0);
@@ -588,11 +583,11 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
588 } 583 }
589 h->hashmap = GNUNET_CONTAINER_multihashmap_create (15); 584 h->hashmap = GNUNET_CONTAINER_multihashmap_create (15);
590 GNUNET_assert (NULL != h->hashmap); 585 GNUNET_assert (NULL != h->hashmap);
586 h->in_replies = GNUNET_YES;
591 GNUNET_CLIENT_receive (h->conn, 587 GNUNET_CLIENT_receive (h->conn,
592 &handle_replies, 588 &handle_replies,
593 h, 589 h,
594 GNUNET_TIME_UNIT_FOREVER_REL); 590 GNUNET_TIME_UNIT_FOREVER_REL);
595 h->in_replies = GNUNET_YES;
596 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); 591 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
597 return h; 592 return h;
598} 593}
diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c
index f9f7aac0c..4cc745401 100644
--- a/src/lockmanager/test_lockmanager_api.c
+++ b/src/lockmanager/test_lockmanager_api.c
@@ -27,11 +27,11 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_lockmanager_service.h" 29#include "gnunet_lockmanager_service.h"
30#include "gnunet_testing_lib-new.h"
30 31
31#define VERBOSE GNUNET_YES 32/**
32 33 * Generic logging shortcut
33#define VERBOSE_ARM 1 34 */
34
35#define LOG(kind,...) \ 35#define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__) 36 GNUNET_log (kind, __VA_ARGS__)
37 37
@@ -60,14 +60,9 @@ enum Test
60static enum Test result; 60static enum Test result;
61 61
62/** 62/**
63 * The process id of the GNUNET ARM process
64 */
65static struct GNUNET_OS_Process *arm_pid = NULL;
66
67/**
68 * Configuration Handle 63 * Configuration Handle
69 */ 64 */
70static struct GNUNET_CONFIGURATION_Handle *config; 65static const struct GNUNET_CONFIGURATION_Handle *config;
71 66
72/** 67/**
73 * The handle to the lockmanager service 68 * The handle to the lockmanager service
@@ -108,16 +103,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
108 if (NULL != request2) 103 if (NULL != request2)
109 GNUNET_LOCKMANAGER_cancel_request (request2); 104 GNUNET_LOCKMANAGER_cancel_request (request2);
110 GNUNET_LOCKMANAGER_disconnect (handle); 105 GNUNET_LOCKMANAGER_disconnect (handle);
111 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) 106 GNUNET_SCHEDULER_shutdown ();
112 {
113 LOG (GNUNET_ERROR_TYPE_DEBUG,
114 "Kill gnunet-service-arm manually\n");
115 }
116 GNUNET_OS_process_wait (arm_pid);
117 GNUNET_OS_process_destroy (arm_pid);
118
119 if (NULL != config)
120 GNUNET_CONFIGURATION_destroy (config);
121} 107}
122 108
123 109
@@ -186,14 +172,15 @@ status_cb (void *cls,
186 172
187 173
188/** 174/**
189 * Testing function 175 * Main point of test execution
190 *
191 * @param cls NULL
192 * @param tc the task context
193 */ 176 */
194static void 177static void
195test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 178run (void *cls,
196{ 179 const struct GNUNET_CONFIGURATION_Handle *cfg,
180 const struct GNUNET_TESTING_Peer *peer)
181{
182 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
183 config = cfg;
197 handle = GNUNET_LOCKMANAGER_connect (config); 184 handle = GNUNET_LOCKMANAGER_connect (config);
198 GNUNET_assert (NULL != handle); 185 GNUNET_assert (NULL != handle);
199 result = LOCK1_ACQUIRE; 186 result = LOCK1_ACQUIRE;
@@ -202,78 +189,22 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
202 99, 189 99,
203 &status_cb, 190 &status_cb,
204 NULL); 191 NULL);
205 abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), 192 abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (30),
206 &do_abort, 193 &do_abort,
207 NULL); 194 NULL);
208} 195}
209 196
210 197
211/** 198/**
212 * Main point of test execution
213 */
214static void
215run (void *cls, char *const *args, const char *cfgfile,
216 const struct GNUNET_CONFIGURATION_Handle *cfg)
217{
218 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
219 config = GNUNET_CONFIGURATION_dup (cfg);
220 arm_pid =
221 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
222 "gnunet-service-arm",
223#if VERBOSE_ARM
224 "-L", "DEBUG",
225#endif
226 "-c", "test_lockmanager_api.conf", NULL);
227
228 GNUNET_assert (NULL != arm_pid);
229 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (3),
230 &test,
231 NULL);
232}
233
234
235/**
236 * Main function 199 * Main function
237 */ 200 */
238int main (int argc, char **argv) 201int main (int argc, char **argv)
239{ 202{
240 int ret;
241
242 char *const argv2[] = { "test_lockmanager_api",
243 "-c", "test_lockmanager_api.conf",
244#if VERBOSE
245 "-L", "DEBUG",
246#endif
247 NULL
248 };
249
250 struct GNUNET_GETOPT_CommandLineOption options[] = {
251 GNUNET_GETOPT_OPTION_END
252 };
253
254 GNUNET_log_setup ("test_lockmanager_api",
255#if VERBOSE
256 "DEBUG",
257#else
258 "WARNING",
259#endif
260 NULL);
261 203
262 ret = 204 if (0 != GNUNET_TESTING_service_run_restartable ("test_lockmanager_api",
263 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 205 "arm",
264 "test_lockmanager_api", "nohelp", options, &run, NULL); 206 "test_lockmanager_api.conf",
265 207 &run, NULL))
266 if (GNUNET_OK != ret)
267 {
268 LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
269 ret);
270 return 1;
271 }
272 if (TEST_FAIL == result)
273 {
274 LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
275 return 1; 208 return 1;
276 } 209 return (TEST_FAIL == result) ? 1 : 0;
277 LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n");
278 return 0;
279} 210}