diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-31 11:07:36 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-31 11:07:36 +0000 |
commit | 15d80d658da613fa1bf8b099ae1fa6ff4bc4e08e (patch) | |
tree | 789aca33e8d8fb69db027cade8dbce12ed93b0a3 /src/lockmanager | |
parent | 0239d1f2146bda38584953bdb6a90d91f3bad3fb (diff) | |
download | gnunet-15d80d658da613fa1bf8b099ae1fa6ff4bc4e08e.tar.gz gnunet-15d80d658da613fa1bf8b099ae1fa6ff4bc4e08e.zip |
indentation standard
Diffstat (limited to 'src/lockmanager')
-rw-r--r-- | src/lockmanager/gnunet-service-lockmanager.c | 244 | ||||
-rw-r--r-- | src/lockmanager/lockmanager_api.c | 212 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api.c | 71 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_acquireretry.c | 57 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_lockrelease.c | 65 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_servercrash.c | 65 |
6 files changed, 287 insertions, 427 deletions
diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c index c0a32e79c..9d69a180a 100644 --- a/src/lockmanager/gnunet-service-lockmanager.c +++ b/src/lockmanager/gnunet-service-lockmanager.c | |||
@@ -58,7 +58,7 @@ struct WaitList | |||
58 | * The next client structure | 58 | * The next client structure |
59 | */ | 59 | */ |
60 | struct WaitList *next; | 60 | struct WaitList *next; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * The prev client structure | 63 | * The prev client structure |
64 | */ | 64 | */ |
@@ -204,15 +204,12 @@ static struct ClientList *cl_tail; | |||
204 | * @param key set to the key | 204 | * @param key set to the key |
205 | */ | 205 | */ |
206 | static void | 206 | static void |
207 | get_key (const char *domain_name, | 207 | get_key (const char *domain_name, uint32_t lock_number, |
208 | uint32_t lock_number, | 208 | struct GNUNET_HashCode *key) |
209 | struct GNUNET_HashCode *key) | ||
210 | { | 209 | { |
211 | uint32_t *last_32; | 210 | uint32_t *last_32; |
212 | 211 | ||
213 | GNUNET_CRYPTO_hash (domain_name, | 212 | GNUNET_CRYPTO_hash (domain_name, strlen (domain_name), key); |
214 | strlen (domain_name), | ||
215 | key); | ||
216 | last_32 = (uint32_t *) key; | 213 | last_32 = (uint32_t *) key; |
217 | *last_32 ^= lock_number; | 214 | *last_32 ^= lock_number; |
218 | } | 215 | } |
@@ -226,7 +223,7 @@ get_key (const char *domain_name, | |||
226 | * @param value value in the hash map (struct Lock) | 223 | * @param value value in the hash map (struct Lock) |
227 | * @return GNUNET_YES if we should continue to | 224 | * @return GNUNET_YES if we should continue to |
228 | * iterate, | 225 | * iterate, |
229 | * GNUNET_NO if not. | 226 | * GNUNET_NO if not. |
230 | */ | 227 | */ |
231 | static int | 228 | static int |
232 | match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | 229 | match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) |
@@ -234,10 +231,10 @@ match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
234 | struct LockMatch *match = cls; | 231 | struct LockMatch *match = cls; |
235 | struct Lock *lock = value; | 232 | struct Lock *lock = value; |
236 | 233 | ||
237 | if ( (match->lock_num == lock->lock_num) | 234 | if ((match->lock_num == lock->lock_num) && |
238 | && (0 == strcmp (match->domain_name, lock->domain_name)) ) | 235 | (0 == strcmp (match->domain_name, lock->domain_name))) |
239 | { | 236 | { |
240 | match->matched_entry = lock; | 237 | match->matched_entry = lock; |
241 | return GNUNET_NO; | 238 | return GNUNET_NO; |
242 | } | 239 | } |
243 | return GNUNET_YES; | 240 | return GNUNET_YES; |
@@ -252,9 +249,7 @@ match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
252 | * @return the lock if found; NULL if not | 249 | * @return the lock if found; NULL if not |
253 | */ | 250 | */ |
254 | static struct Lock * | 251 | static struct Lock * |
255 | find_lock (const char *domain_name, | 252 | find_lock (const char *domain_name, const uint32_t lock_num) |
256 | const uint32_t lock_num) | ||
257 | |||
258 | { | 253 | { |
259 | struct LockMatch match; | 254 | struct LockMatch match; |
260 | struct GNUNET_HashCode key; | 255 | struct GNUNET_HashCode key; |
@@ -263,9 +258,7 @@ find_lock (const char *domain_name, | |||
263 | match.domain_name = domain_name; | 258 | match.domain_name = domain_name; |
264 | match.matched_entry = NULL; | 259 | match.matched_entry = NULL; |
265 | get_key (domain_name, lock_num, &key); | 260 | get_key (domain_name, lock_num, &key); |
266 | GNUNET_CONTAINER_multihashmap_get_multiple (lock_map, | 261 | GNUNET_CONTAINER_multihashmap_get_multiple (lock_map, &key, &match_iterator, |
267 | &key, | ||
268 | &match_iterator, | ||
269 | &match); | 262 | &match); |
270 | return match.matched_entry; | 263 | return match.matched_entry; |
271 | } | 264 | } |
@@ -279,8 +272,7 @@ find_lock (const char *domain_name, | |||
279 | * @return pointer to the lock structure which is added to lock map | 272 | * @return pointer to the lock structure which is added to lock map |
280 | */ | 273 | */ |
281 | static struct Lock * | 274 | static struct Lock * |
282 | add_lock (const char *domain_name, | 275 | add_lock (const char *domain_name, uint32_t lock_num) |
283 | uint32_t lock_num) | ||
284 | { | 276 | { |
285 | struct Lock *lock; | 277 | struct Lock *lock; |
286 | struct GNUNET_HashCode key; | 278 | struct GNUNET_HashCode key; |
@@ -295,9 +287,7 @@ add_lock (const char *domain_name, | |||
295 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 287 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Adding a lock with num: %d and domain: %s to the lock map\n", | 288 | "Adding a lock with num: %d and domain: %s to the lock map\n", |
297 | lock->lock_num, lock->domain_name); | 289 | lock->lock_num, lock->domain_name); |
298 | GNUNET_CONTAINER_multihashmap_put (lock_map, | 290 | GNUNET_CONTAINER_multihashmap_put (lock_map, &key, lock, |
299 | &key, | ||
300 | lock, | ||
301 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 291 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
302 | return lock; | 292 | return lock; |
303 | } | 293 | } |
@@ -312,16 +302,14 @@ static void | |||
312 | remove_lock (struct Lock *lock) | 302 | remove_lock (struct Lock *lock) |
313 | { | 303 | { |
314 | struct GNUNET_HashCode key; | 304 | struct GNUNET_HashCode key; |
315 | 305 | ||
316 | GNUNET_assert (NULL == lock->wl_head); | 306 | GNUNET_assert (NULL == lock->wl_head); |
317 | get_key (lock->domain_name, | 307 | get_key (lock->domain_name, lock->lock_num, &key); |
318 | lock->lock_num, | ||
319 | &key); | ||
320 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 308 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
321 | "Removing lock with num: %u, domain: %s from lock map\n", | 309 | "Removing lock with num: %u, domain: %s from lock map\n", lock->lock_num, |
322 | lock->lock_num, lock->domain_name); | 310 | lock->domain_name); |
323 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove | 311 | GNUNET_assert (GNUNET_YES == |
324 | (lock_map, &key, lock)); | 312 | GNUNET_CONTAINER_multihashmap_remove (lock_map, &key, lock)); |
325 | GNUNET_free (lock->domain_name); | 313 | GNUNET_free (lock->domain_name); |
326 | GNUNET_free (lock); | 314 | GNUNET_free (lock); |
327 | } | 315 | } |
@@ -336,13 +324,12 @@ remove_lock (struct Lock *lock) | |||
336 | * @return the matching LockList entry; NULL if no match is found | 324 | * @return the matching LockList entry; NULL if no match is found |
337 | */ | 325 | */ |
338 | static struct LockList * | 326 | static struct LockList * |
339 | cl_ll_find_lock (struct ClientList *cl_entry, | 327 | cl_ll_find_lock (struct ClientList *cl_entry, const struct Lock *lock) |
340 | const struct Lock *lock) | ||
341 | { | 328 | { |
342 | struct LockList *ll_entry; | 329 | struct LockList *ll_entry; |
343 | 330 | ||
344 | for (ll_entry = cl_entry->ll_head; | 331 | for (ll_entry = cl_entry->ll_head; NULL != ll_entry; |
345 | NULL != ll_entry; ll_entry = ll_entry->next) | 332 | ll_entry = ll_entry->next) |
346 | { | 333 | { |
347 | if (lock == ll_entry->lock) | 334 | if (lock == ll_entry->lock) |
348 | return ll_entry; | 335 | return ll_entry; |
@@ -358,8 +345,7 @@ cl_ll_find_lock (struct ClientList *cl_entry, | |||
358 | * @param lock the lock to be added to the cl_entry's lock list | 345 | * @param lock the lock to be added to the cl_entry's lock list |
359 | */ | 346 | */ |
360 | static void | 347 | static void |
361 | cl_ll_add_lock (struct ClientList *cl_entry, | 348 | cl_ll_add_lock (struct ClientList *cl_entry, struct Lock *lock) |
362 | struct Lock *lock) | ||
363 | { | 349 | { |
364 | struct LockList *ll_entry; | 350 | struct LockList *ll_entry; |
365 | 351 | ||
@@ -368,8 +354,7 @@ cl_ll_add_lock (struct ClientList *cl_entry, | |||
368 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 354 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
369 | "Adding a lock with num: %u and domain: %s to lock list\n", | 355 | "Adding a lock with num: %u and domain: %s to lock list\n", |
370 | lock->lock_num, lock->domain_name); | 356 | lock->lock_num, lock->domain_name); |
371 | GNUNET_CONTAINER_DLL_insert_tail (cl_entry->ll_head, | 357 | GNUNET_CONTAINER_DLL_insert_tail (cl_entry->ll_head, cl_entry->ll_tail, |
372 | cl_entry->ll_tail, | ||
373 | ll_entry); | 358 | ll_entry); |
374 | } | 359 | } |
375 | 360 | ||
@@ -381,17 +366,13 @@ cl_ll_add_lock (struct ClientList *cl_entry, | |||
381 | * @param ll_entry the LockList entry to be deleted | 366 | * @param ll_entry the LockList entry to be deleted |
382 | */ | 367 | */ |
383 | static void | 368 | static void |
384 | cl_ll_remove_lock (struct ClientList *cl_entry, | 369 | cl_ll_remove_lock (struct ClientList *cl_entry, struct LockList *ll_entry) |
385 | struct LockList *ll_entry) | ||
386 | { | 370 | { |
387 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 371 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
388 | "Removing lock with num: %u, domain: %s from lock list of a client\n", | 372 | "Removing lock with num: %u, domain: %s from lock list of a client\n", |
389 | ll_entry->lock->lock_num, | 373 | ll_entry->lock->lock_num, ll_entry->lock->domain_name); |
390 | ll_entry->lock->domain_name); | ||
391 | GNUNET_assert (NULL != cl_entry->ll_head); | 374 | GNUNET_assert (NULL != cl_entry->ll_head); |
392 | GNUNET_CONTAINER_DLL_remove (cl_entry->ll_head, | 375 | GNUNET_CONTAINER_DLL_remove (cl_entry->ll_head, cl_entry->ll_tail, ll_entry); |
393 | cl_entry->ll_tail, | ||
394 | ll_entry); | ||
395 | GNUNET_free (ll_entry); | 376 | GNUNET_free (ll_entry); |
396 | } | 377 | } |
397 | 378 | ||
@@ -405,14 +386,11 @@ cl_ll_remove_lock (struct ClientList *cl_entry, | |||
405 | * was found | 386 | * was found |
406 | */ | 387 | */ |
407 | static struct WaitList * | 388 | static struct WaitList * |
408 | lock_wl_find (const struct Lock *lock, | 389 | lock_wl_find (const struct Lock *lock, const struct ClientList *cl_entry) |
409 | const struct ClientList *cl_entry) | ||
410 | { | 390 | { |
411 | struct WaitList *wl_entry; | 391 | struct WaitList *wl_entry; |
412 | 392 | ||
413 | for (wl_entry = lock->wl_head; | 393 | for (wl_entry = lock->wl_head; NULL != wl_entry; wl_entry = wl_entry->next) |
414 | NULL != wl_entry; | ||
415 | wl_entry = wl_entry->next) | ||
416 | { | 394 | { |
417 | if (cl_entry == wl_entry->cl_entry) | 395 | if (cl_entry == wl_entry->cl_entry) |
418 | return wl_entry; | 396 | return wl_entry; |
@@ -428,20 +406,16 @@ lock_wl_find (const struct Lock *lock, | |||
428 | * @param cl_entry the client to queue for the lock's wait list | 406 | * @param cl_entry the client to queue for the lock's wait list |
429 | */ | 407 | */ |
430 | static void | 408 | static void |
431 | lock_wl_add_client (struct Lock *lock, | 409 | lock_wl_add_client (struct Lock *lock, struct ClientList *cl_entry) |
432 | struct ClientList *cl_entry) | ||
433 | { | 410 | { |
434 | struct WaitList *wl_entry; | 411 | struct WaitList *wl_entry; |
435 | 412 | ||
436 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 413 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
437 | "Adding a client to lock's wait list (lock num: %u, domain: %s)\n", | 414 | "Adding a client to lock's wait list (lock num: %u, domain: %s)\n", |
438 | lock->lock_num, | 415 | lock->lock_num, lock->domain_name); |
439 | lock->domain_name); | ||
440 | wl_entry = GNUNET_malloc (sizeof (struct WaitList)); | 416 | wl_entry = GNUNET_malloc (sizeof (struct WaitList)); |
441 | wl_entry->cl_entry = cl_entry; | 417 | wl_entry->cl_entry = cl_entry; |
442 | GNUNET_CONTAINER_DLL_insert_tail (lock->wl_head, | 418 | GNUNET_CONTAINER_DLL_insert_tail (lock->wl_head, lock->wl_tail, wl_entry); |
443 | lock->wl_tail, | ||
444 | wl_entry); | ||
445 | } | 419 | } |
446 | 420 | ||
447 | 421 | ||
@@ -452,15 +426,12 @@ lock_wl_add_client (struct Lock *lock, | |||
452 | * @param wl_entry the wait list entry to be removed | 426 | * @param wl_entry the wait list entry to be removed |
453 | */ | 427 | */ |
454 | static void | 428 | static void |
455 | lock_wl_remove (struct Lock *lock, | 429 | lock_wl_remove (struct Lock *lock, struct WaitList *wl_entry) |
456 | struct WaitList *wl_entry) | ||
457 | { | 430 | { |
458 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 431 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
459 | "Removing client from wait list of lock with num: %u, domain: %s\n", | 432 | "Removing client from wait list of lock with num: %u, domain: %s\n", |
460 | lock->lock_num, lock->domain_name); | 433 | lock->lock_num, lock->domain_name); |
461 | GNUNET_CONTAINER_DLL_remove (lock->wl_head, | 434 | GNUNET_CONTAINER_DLL_remove (lock->wl_head, lock->wl_tail, wl_entry); |
462 | lock->wl_tail, | ||
463 | wl_entry); | ||
464 | GNUNET_free (wl_entry); | 435 | GNUNET_free (wl_entry); |
465 | } | 436 | } |
466 | 437 | ||
@@ -472,7 +443,7 @@ lock_wl_remove (struct Lock *lock, | |||
472 | * @return the ClientList entry; NULL if the client is not found | 443 | * @return the ClientList entry; NULL if the client is not found |
473 | */ | 444 | */ |
474 | static struct ClientList * | 445 | static struct ClientList * |
475 | cl_find_client (const struct GNUNET_SERVER_Client *client) | 446 | cl_find_client (const struct GNUNET_SERVER_Client *client) |
476 | { | 447 | { |
477 | struct ClientList *current; | 448 | struct ClientList *current; |
478 | 449 | ||
@@ -493,15 +464,12 @@ static struct ClientList * | |||
493 | cl_add_client (struct GNUNET_SERVER_Client *client) | 464 | cl_add_client (struct GNUNET_SERVER_Client *client) |
494 | { | 465 | { |
495 | struct ClientList *new_client; | 466 | struct ClientList *new_client; |
496 | 467 | ||
497 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 468 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding a client to the client list\n"); |
498 | "Adding a client to the client list\n"); | ||
499 | new_client = GNUNET_malloc (sizeof (struct ClientList)); | 469 | new_client = GNUNET_malloc (sizeof (struct ClientList)); |
500 | GNUNET_SERVER_client_keep (client); | 470 | GNUNET_SERVER_client_keep (client); |
501 | new_client->client = client; | 471 | new_client->client = client; |
502 | GNUNET_CONTAINER_DLL_insert_tail (cl_head, | 472 | GNUNET_CONTAINER_DLL_insert_tail (cl_head, cl_tail, new_client); |
503 | cl_tail, | ||
504 | new_client); | ||
505 | return new_client; | 473 | return new_client; |
506 | } | 474 | } |
507 | 475 | ||
@@ -515,12 +483,9 @@ static void | |||
515 | cl_remove_client (struct ClientList *cl_entry) | 483 | cl_remove_client (struct ClientList *cl_entry) |
516 | { | 484 | { |
517 | GNUNET_assert (NULL == cl_entry->ll_head); | 485 | GNUNET_assert (NULL == cl_entry->ll_head); |
518 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 486 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing a client from the client list\n"); |
519 | "Removing a client from the client list\n"); | ||
520 | GNUNET_SERVER_client_drop (cl_entry->client); | 487 | GNUNET_SERVER_client_drop (cl_entry->client); |
521 | GNUNET_CONTAINER_DLL_remove (cl_head, | 488 | GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl_entry); |
522 | cl_tail, | ||
523 | cl_entry); | ||
524 | GNUNET_free (cl_entry); | 489 | GNUNET_free (cl_entry); |
525 | } | 490 | } |
526 | 491 | ||
@@ -533,7 +498,7 @@ cl_remove_client (struct ClientList *cl_entry) | |||
533 | * @param buf where the callee should write the message | 498 | * @param buf where the callee should write the message |
534 | * @return number of bytes written to buf | 499 | * @return number of bytes written to buf |
535 | */ | 500 | */ |
536 | static size_t | 501 | static size_t |
537 | transmit_notify (void *cls, size_t size, void *buf) | 502 | transmit_notify (void *cls, size_t size, void *buf) |
538 | { | 503 | { |
539 | struct GNUNET_LOCKMANAGER_Message *msg = cls; | 504 | struct GNUNET_LOCKMANAGER_Message *msg = cls; |
@@ -548,8 +513,7 @@ transmit_notify (void *cls, size_t size, void *buf) | |||
548 | GNUNET_assert (size >= msg_size); | 513 | GNUNET_assert (size >= msg_size); |
549 | memcpy (buf, msg, msg_size); | 514 | memcpy (buf, msg, msg_size); |
550 | GNUNET_free (msg); | 515 | GNUNET_free (msg); |
551 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 516 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Message of size %u sent\n", msg_size); |
552 | "Message of size %u sent\n", msg_size); | ||
553 | return msg_size; | 517 | return msg_size; |
554 | } | 518 | } |
555 | 519 | ||
@@ -562,8 +526,7 @@ transmit_notify (void *cls, size_t size, void *buf) | |||
562 | * @param lock_num the number of the successfully acquired lock | 526 | * @param lock_num the number of the successfully acquired lock |
563 | */ | 527 | */ |
564 | static void | 528 | static void |
565 | send_success_msg (struct GNUNET_SERVER_Client *client, | 529 | send_success_msg (struct GNUNET_SERVER_Client *client, const char *domain_name, |
566 | const char *domain_name, | ||
567 | int lock_num) | 530 | int lock_num) |
568 | { | 531 | { |
569 | struct GNUNET_LOCKMANAGER_Message *reply; | 532 | struct GNUNET_LOCKMANAGER_Message *reply; |
@@ -578,13 +541,10 @@ send_success_msg (struct GNUNET_SERVER_Client *client, | |||
578 | reply->lock = htonl (lock_num); | 541 | reply->lock = htonl (lock_num); |
579 | strncpy ((char *) &reply[1], domain_name, domain_name_len); | 542 | strncpy ((char *) &reply[1], domain_name, domain_name_len); |
580 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 543 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
581 | "Sending SUCCESS message for lock with num: %u, domain: %s\n", | 544 | "Sending SUCCESS message for lock with num: %u, domain: %s\n", lock_num, |
582 | lock_num, domain_name); | 545 | domain_name); |
583 | GNUNET_SERVER_notify_transmit_ready (client, | 546 | GNUNET_SERVER_notify_transmit_ready (client, reply_size, TIMEOUT, |
584 | reply_size, | 547 | &transmit_notify, reply); |
585 | TIMEOUT, | ||
586 | &transmit_notify, | ||
587 | reply); | ||
588 | } | 548 | } |
589 | 549 | ||
590 | 550 | ||
@@ -596,8 +556,7 @@ send_success_msg (struct GNUNET_SERVER_Client *client, | |||
596 | * @param message GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE message | 556 | * @param message GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE message |
597 | */ | 557 | */ |
598 | static void | 558 | static void |
599 | handle_acquire (void *cls, | 559 | handle_acquire (void *cls, struct GNUNET_SERVER_Client *client, |
600 | struct GNUNET_SERVER_Client *client, | ||
601 | const struct GNUNET_MessageHeader *message) | 560 | const struct GNUNET_MessageHeader *message) |
602 | { | 561 | { |
603 | const struct GNUNET_LOCKMANAGER_Message *request; | 562 | const struct GNUNET_LOCKMANAGER_Message *request; |
@@ -625,14 +584,14 @@ handle_acquire (void *cls, | |||
625 | } | 584 | } |
626 | lock_num = ntohl (request->lock); | 585 | lock_num = ntohl (request->lock); |
627 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 586 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
628 | "Received an ACQUIRE message for lock num: %u domain: %s\n", | 587 | "Received an ACQUIRE message for lock num: %u domain: %s\n", lock_num, |
629 | lock_num, domain_name); | 588 | domain_name); |
630 | if (NULL == (cl_entry = cl_find_client (client))) | 589 | if (NULL == (cl_entry = cl_find_client (client))) |
631 | cl_entry = cl_add_client (client); /* Add client if not in client list */ | 590 | cl_entry = cl_add_client (client); /* Add client if not in client list */ |
632 | if (NULL != (lock = find_lock (domain_name,lock_num))) | 591 | if (NULL != (lock = find_lock (domain_name, lock_num))) |
633 | { | 592 | { |
634 | if (lock->cl_entry == cl_entry) | 593 | if (lock->cl_entry == cl_entry) |
635 | { /* Client is requesting a lock it already owns */ | 594 | { /* Client is requesting a lock it already owns */ |
636 | GNUNET_break (0); | 595 | GNUNET_break (0); |
637 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 596 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
638 | return; | 597 | return; |
@@ -669,16 +628,13 @@ process_lock_release (struct Lock *lock) | |||
669 | wl_entry = lock->wl_head; | 628 | wl_entry = lock->wl_head; |
670 | if (NULL == wl_entry) | 629 | if (NULL == wl_entry) |
671 | { | 630 | { |
672 | remove_lock (lock); /* No clients waiting for this lock - delete */ | 631 | remove_lock (lock); /* No clients waiting for this lock - delete */ |
673 | return; | 632 | return; |
674 | } | 633 | } |
675 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 634 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving lock to a client from wait list\n"); |
676 | "Giving lock to a client from wait list\n"); | ||
677 | lock->cl_entry = wl_entry->cl_entry; | 635 | lock->cl_entry = wl_entry->cl_entry; |
678 | lock_wl_remove(lock, wl_entry); | 636 | lock_wl_remove (lock, wl_entry); |
679 | send_success_msg (lock->cl_entry->client, | 637 | send_success_msg (lock->cl_entry->client, lock->domain_name, lock->lock_num); |
680 | lock->domain_name, | ||
681 | lock->lock_num); | ||
682 | return; | 638 | return; |
683 | } | 639 | } |
684 | 640 | ||
@@ -691,8 +647,7 @@ process_lock_release (struct Lock *lock) | |||
691 | * @param message the LOCKMANAGER_RELEASE message | 647 | * @param message the LOCKMANAGER_RELEASE message |
692 | */ | 648 | */ |
693 | static void | 649 | static void |
694 | handle_release (void *cls, | 650 | handle_release (void *cls, struct GNUNET_SERVER_Client *client, |
695 | struct GNUNET_SERVER_Client *client, | ||
696 | const struct GNUNET_MessageHeader *message) | 651 | const struct GNUNET_MessageHeader *message) |
697 | { | 652 | { |
698 | const struct GNUNET_LOCKMANAGER_Message *request; | 653 | const struct GNUNET_LOCKMANAGER_Message *request; |
@@ -706,7 +661,7 @@ handle_release (void *cls, | |||
706 | 661 | ||
707 | msize = ntohs (message->size); | 662 | msize = ntohs (message->size); |
708 | if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message)) | 663 | if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message)) |
709 | { | 664 | { |
710 | GNUNET_break (0); | 665 | GNUNET_break (0); |
711 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 666 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
712 | return; | 667 | return; |
@@ -714,27 +669,27 @@ handle_release (void *cls, | |||
714 | request = (const struct GNUNET_LOCKMANAGER_Message *) message; | 669 | request = (const struct GNUNET_LOCKMANAGER_Message *) message; |
715 | domain_name = (const char *) &request[1]; | 670 | domain_name = (const char *) &request[1]; |
716 | msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); | 671 | msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); |
717 | if ('\0' != domain_name[msize-1]) | 672 | if ('\0' != domain_name[msize - 1]) |
718 | { | 673 | { |
719 | GNUNET_break (0); | 674 | GNUNET_break (0); |
720 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 675 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
721 | return; | 676 | return; |
722 | 677 | ||
723 | 678 | ||
724 | } | 679 | } |
725 | lock_num = ntohl (request->lock); | 680 | lock_num = ntohl (request->lock); |
726 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 681 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
727 | "Received RELEASE message for lock with num: %d, domain: %s\n", | 682 | "Received RELEASE message for lock with num: %d, domain: %s\n", lock_num, |
728 | lock_num, domain_name); | 683 | domain_name); |
729 | if (NULL == (cl_entry = cl_find_client (client))) | 684 | if (NULL == (cl_entry = cl_find_client (client))) |
730 | { | 685 | { |
731 | GNUNET_break(0); | 686 | GNUNET_break (0); |
732 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 687 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
733 | return; | 688 | return; |
734 | } | 689 | } |
735 | lock = find_lock (domain_name, lock_num); | 690 | lock = find_lock (domain_name, lock_num); |
736 | if(NULL == lock) | 691 | if (NULL == lock) |
737 | { | 692 | { |
738 | GNUNET_break (0); | 693 | GNUNET_break (0); |
739 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 694 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
740 | return; | 695 | return; |
@@ -777,7 +732,7 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | |||
777 | if (NULL == client) | 732 | if (NULL == client) |
778 | return; | 733 | return; |
779 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 734 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
780 | "A client has been disconnected -- freeing its locks and resources\n"); | 735 | "A client has been disconnected -- freeing its locks and resources\n"); |
781 | cl_entry = cl_find_client (client); | 736 | cl_entry = cl_find_client (client); |
782 | if (NULL == cl_entry) | 737 | if (NULL == cl_entry) |
783 | return; | 738 | return; |
@@ -801,10 +756,8 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | |||
801 | * iterate, | 756 | * iterate, |
802 | * GNUNET_NO if not. | 757 | * GNUNET_NO if not. |
803 | */ | 758 | */ |
804 | static int | 759 | static int |
805 | lock_delete_iterator (void *cls, | 760 | lock_delete_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) |
806 | const struct GNUNET_HashCode * key, | ||
807 | void *value) | ||
808 | { | 761 | { |
809 | struct Lock *lock = value; | 762 | struct Lock *lock = value; |
810 | 763 | ||
@@ -813,10 +766,8 @@ lock_delete_iterator (void *cls, | |||
813 | { | 766 | { |
814 | lock_wl_remove (lock, lock->wl_head); | 767 | lock_wl_remove (lock, lock->wl_head); |
815 | } | 768 | } |
816 | GNUNET_assert (GNUNET_YES == | 769 | GNUNET_assert (GNUNET_YES == |
817 | GNUNET_CONTAINER_multihashmap_remove(lock_map, | 770 | GNUNET_CONTAINER_multihashmap_remove (lock_map, key, lock)); |
818 | key, | ||
819 | lock)); | ||
820 | GNUNET_free (lock->domain_name); | 771 | GNUNET_free (lock->domain_name); |
821 | GNUNET_free (lock); | 772 | GNUNET_free (lock); |
822 | return GNUNET_YES; | 773 | return GNUNET_YES; |
@@ -830,24 +781,20 @@ lock_delete_iterator (void *cls, | |||
830 | * @param tc the TaskContext from scheduler | 781 | * @param tc the TaskContext from scheduler |
831 | */ | 782 | */ |
832 | static void | 783 | static void |
833 | shutdown_task (void *cls, | 784 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
834 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
835 | { | 785 | { |
836 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 786 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down lock manager\n"); |
837 | "Shutting down lock manager\n"); | ||
838 | /* Clean the global ClientList */ | 787 | /* Clean the global ClientList */ |
839 | while (NULL != cl_head) | 788 | while (NULL != cl_head) |
840 | { | 789 | { |
841 | while (NULL != cl_head->ll_head) /* Clear the LockList */ | 790 | while (NULL != cl_head->ll_head) /* Clear the LockList */ |
842 | { | 791 | { |
843 | cl_ll_remove_lock (cl_head, cl_head->ll_head); | 792 | cl_ll_remove_lock (cl_head, cl_head->ll_head); |
844 | } | 793 | } |
845 | cl_remove_client (cl_head); | 794 | cl_remove_client (cl_head); |
846 | } | 795 | } |
847 | /* Clean the global hash table */ | 796 | /* Clean the global hash table */ |
848 | GNUNET_CONTAINER_multihashmap_iterate (lock_map, | 797 | GNUNET_CONTAINER_multihashmap_iterate (lock_map, &lock_delete_iterator, NULL); |
849 | &lock_delete_iterator, | ||
850 | NULL); | ||
851 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (lock_map)); | 798 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (lock_map)); |
852 | GNUNET_CONTAINER_multihashmap_destroy (lock_map); | 799 | GNUNET_CONTAINER_multihashmap_destroy (lock_map); |
853 | } | 800 | } |
@@ -860,25 +807,19 @@ shutdown_task (void *cls, | |||
860 | * @param server the initialized server | 807 | * @param server the initialized server |
861 | * @param cfg configuration to use | 808 | * @param cfg configuration to use |
862 | */ | 809 | */ |
863 | static void | 810 | static void |
864 | lockmanager_run (void *cls, | 811 | lockmanager_run (void *cls, struct GNUNET_SERVER_Handle *server, |
865 | struct GNUNET_SERVER_Handle * server, | ||
866 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 812 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
867 | { | 813 | { |
868 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = | 814 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { |
869 | { | 815 | {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0}, |
870 | {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0}, | 816 | {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0}, |
871 | {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0}, | 817 | {NULL} |
872 | {NULL} | 818 | }; |
873 | }; | 819 | GNUNET_SERVER_add_handlers (server, message_handlers); |
874 | GNUNET_SERVER_add_handlers (server, | 820 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); |
875 | message_handlers); | ||
876 | GNUNET_SERVER_disconnect_notify (server, | ||
877 | &client_disconnect_cb, | ||
878 | NULL); | ||
879 | lock_map = GNUNET_CONTAINER_multihashmap_create (30); | 821 | lock_map = GNUNET_CONTAINER_multihashmap_create (30); |
880 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 822 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
881 | &shutdown_task, | ||
882 | NULL); | 823 | NULL); |
883 | } | 824 | } |
884 | 825 | ||
@@ -886,16 +827,13 @@ lockmanager_run (void *cls, | |||
886 | /** | 827 | /** |
887 | * The starting point of execution | 828 | * The starting point of execution |
888 | */ | 829 | */ |
889 | int main (int argc, char *const *argv) | 830 | int |
831 | main (int argc, char *const *argv) | ||
890 | { | 832 | { |
891 | return | 833 | return (GNUNET_OK == |
892 | (GNUNET_OK == | 834 | GNUNET_SERVICE_run (argc, argv, "lockmanager", |
893 | GNUNET_SERVICE_run (argc, | 835 | GNUNET_SERVICE_OPTION_NONE, &lockmanager_run, |
894 | argv, | 836 | NULL)) ? 0 : 1; |
895 | "lockmanager", | ||
896 | GNUNET_SERVICE_OPTION_NONE, | ||
897 | &lockmanager_run, | ||
898 | NULL)) ? 0 : 1; | ||
899 | } | 837 | } |
900 | 838 | ||
901 | /* end of gnunet-service-lockmanager.c */ | 839 | /* end of gnunet-service-lockmanager.c */ |
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c index d648d1c5c..8adf486ee 100644 --- a/src/lockmanager/lockmanager_api.c +++ b/src/lockmanager/lockmanager_api.c | |||
@@ -58,7 +58,7 @@ struct MessageQueue | |||
58 | * The prev pointer for doubly linked list | 58 | * The prev pointer for doubly linked list |
59 | */ | 59 | */ |
60 | struct MessageQueue *prev; | 60 | struct MessageQueue *prev; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * The LOCKMANAGER Message | 63 | * The LOCKMANAGER Message |
64 | */ | 64 | */ |
@@ -139,7 +139,7 @@ struct GNUNET_LOCKMANAGER_LockingRequest | |||
139 | * The locking domain of this request | 139 | * The locking domain of this request |
140 | */ | 140 | */ |
141 | char *domain; | 141 | char *domain; |
142 | 142 | ||
143 | /** | 143 | /** |
144 | * The lock | 144 | * The lock |
145 | */ | 145 | */ |
@@ -149,7 +149,7 @@ struct GNUNET_LOCKMANAGER_LockingRequest | |||
149 | * The status of the lock | 149 | * The status of the lock |
150 | */ | 150 | */ |
151 | enum GNUNET_LOCKMANAGER_Status status; | 151 | enum GNUNET_LOCKMANAGER_Status status; |
152 | 152 | ||
153 | /** | 153 | /** |
154 | * set to GNUNET_YES if acquire message for this lock is till in messga queue | 154 | * set to GNUNET_YES if acquire message for this lock is till in messga queue |
155 | */ | 155 | */ |
@@ -185,9 +185,8 @@ struct LockingRequestMatch | |||
185 | * @param cls the LOCKMANAGER_Handle | 185 | * @param cls the LOCKMANAGER_Handle |
186 | * @param msg received message, NULL on timeout or fatal error | 186 | * @param msg received message, NULL on timeout or fatal error |
187 | */ | 187 | */ |
188 | static void | 188 | static void |
189 | handle_replies (void *cls, | 189 | handle_replies (void *cls, const struct GNUNET_MessageHeader *msg); |
190 | const struct GNUNET_MessageHeader *msg); | ||
191 | 190 | ||
192 | 191 | ||
193 | /** | 192 | /** |
@@ -198,7 +197,7 @@ handle_replies (void *cls, | |||
198 | * @param buf where the callee should write the message | 197 | * @param buf where the callee should write the message |
199 | * @return number of bytes written to buf | 198 | * @return number of bytes written to buf |
200 | */ | 199 | */ |
201 | static size_t | 200 | static size_t |
202 | transmit_notify (void *cls, size_t size, void *buf) | 201 | transmit_notify (void *cls, size_t size, void *buf) |
203 | { | 202 | { |
204 | struct GNUNET_LOCKMANAGER_Handle *handle = cls; | 203 | struct GNUNET_LOCKMANAGER_Handle *handle = cls; |
@@ -211,50 +210,42 @@ transmit_notify (void *cls, size_t size, void *buf) | |||
211 | if ((0 == size) || (NULL == buf)) | 210 | if ((0 == size) || (NULL == buf)) |
212 | { | 211 | { |
213 | handle->transmit_handle = | 212 | handle->transmit_handle = |
214 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, | 213 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, |
215 | ntohs | 214 | ntohs (queue_entity->msg-> |
216 | (queue_entity->msg->header.size), | 215 | header.size), |
217 | GNUNET_TIME_UNIT_FOREVER_REL, | 216 | GNUNET_TIME_UNIT_FOREVER_REL, |
218 | GNUNET_YES, | 217 | GNUNET_YES, &transmit_notify, |
219 | &transmit_notify, | 218 | handle); |
220 | handle); | ||
221 | return 0; | 219 | return 0; |
222 | } | 220 | } |
223 | msg_size = ntohs (queue_entity->msg->header.size); | 221 | msg_size = ntohs (queue_entity->msg->header.size); |
224 | GNUNET_assert (size >= msg_size); | 222 | GNUNET_assert (size >= msg_size); |
225 | memcpy (buf, queue_entity->msg, msg_size); | 223 | memcpy (buf, queue_entity->msg, msg_size); |
226 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 224 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Message of size %u sent\n", msg_size); |
227 | "Message of size %u sent\n", msg_size); | 225 | if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE == |
228 | if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE | 226 | ntohs (queue_entity->msg->header.type)) |
229 | == ntohs (queue_entity->msg->header.type)) | ||
230 | { | 227 | { |
231 | GNUNET_break (GNUNET_NO == queue_entity->lr->acquire_sent); | 228 | GNUNET_break (GNUNET_NO == queue_entity->lr->acquire_sent); |
232 | queue_entity->lr->acquire_sent = GNUNET_YES; | 229 | queue_entity->lr->acquire_sent = GNUNET_YES; |
233 | queue_entity->lr->mqe = NULL; | 230 | queue_entity->lr->mqe = NULL; |
234 | } | 231 | } |
235 | GNUNET_free (queue_entity->msg); | 232 | GNUNET_free (queue_entity->msg); |
236 | GNUNET_CONTAINER_DLL_remove (handle->mq_head, | 233 | GNUNET_CONTAINER_DLL_remove (handle->mq_head, handle->mq_tail, queue_entity); |
237 | handle->mq_tail, | ||
238 | queue_entity); | ||
239 | GNUNET_free (queue_entity); | 234 | GNUNET_free (queue_entity); |
240 | queue_entity = handle->mq_head; | 235 | queue_entity = handle->mq_head; |
241 | if (NULL != queue_entity) | 236 | if (NULL != queue_entity) |
242 | { | 237 | { |
243 | handle->transmit_handle = | 238 | handle->transmit_handle = |
244 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, | 239 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, |
245 | ntohs | 240 | ntohs (queue_entity->msg-> |
246 | (queue_entity->msg->header.size), | 241 | header.size), TIMEOUT, |
247 | TIMEOUT, | 242 | GNUNET_YES, &transmit_notify, |
248 | GNUNET_YES, | 243 | handle); |
249 | &transmit_notify, | ||
250 | handle); | ||
251 | } | 244 | } |
252 | if (GNUNET_NO == handle->in_replies) | 245 | if (GNUNET_NO == handle->in_replies) |
253 | { | 246 | { |
254 | handle->in_replies = GNUNET_YES; | 247 | handle->in_replies = GNUNET_YES; |
255 | GNUNET_CLIENT_receive (handle->conn, | 248 | GNUNET_CLIENT_receive (handle->conn, &handle_replies, handle, |
256 | &handle_replies, | ||
257 | handle, | ||
258 | GNUNET_TIME_UNIT_FOREVER_REL); | 249 | GNUNET_TIME_UNIT_FOREVER_REL); |
259 | } | 250 | } |
260 | return msg_size; | 251 | return msg_size; |
@@ -280,18 +271,15 @@ queue_message (struct GNUNET_LOCKMANAGER_Handle *handle, | |||
280 | queue_entity = GNUNET_malloc (sizeof (struct MessageQueue)); | 271 | queue_entity = GNUNET_malloc (sizeof (struct MessageQueue)); |
281 | queue_entity->msg = msg; | 272 | queue_entity->msg = msg; |
282 | queue_entity->lr = request; | 273 | queue_entity->lr = request; |
283 | GNUNET_CONTAINER_DLL_insert_tail (handle->mq_head, | 274 | GNUNET_CONTAINER_DLL_insert_tail (handle->mq_head, handle->mq_tail, |
284 | handle->mq_tail, | ||
285 | queue_entity); | 275 | queue_entity); |
286 | if (NULL == handle->transmit_handle) | 276 | if (NULL == handle->transmit_handle) |
287 | { | 277 | { |
288 | handle->transmit_handle = | 278 | handle->transmit_handle = |
289 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, | 279 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, |
290 | ntohs (msg->header.size), | 280 | ntohs (msg->header.size), TIMEOUT, |
291 | TIMEOUT, | 281 | GNUNET_YES, &transmit_notify, |
292 | GNUNET_YES, | 282 | handle); |
293 | &transmit_notify, | ||
294 | handle); | ||
295 | } | 283 | } |
296 | return queue_entity; | 284 | return queue_entity; |
297 | } | 285 | } |
@@ -305,15 +293,12 @@ queue_message (struct GNUNET_LOCKMANAGER_Handle *handle, | |||
305 | * @param key set to the key | 293 | * @param key set to the key |
306 | */ | 294 | */ |
307 | static void | 295 | static void |
308 | get_key (const char *domain_name, | 296 | get_key (const char *domain_name, uint32_t lock_number, |
309 | uint32_t lock_number, | 297 | struct GNUNET_HashCode *key) |
310 | struct GNUNET_HashCode *key) | ||
311 | { | 298 | { |
312 | uint32_t *last_32; | 299 | uint32_t *last_32; |
313 | 300 | ||
314 | GNUNET_CRYPTO_hash (domain_name, | 301 | GNUNET_CRYPTO_hash (domain_name, strlen (domain_name), key); |
315 | strlen (domain_name), | ||
316 | key); | ||
317 | last_32 = (uint32_t *) key; | 302 | last_32 = (uint32_t *) key; |
318 | *last_32 ^= lock_number; | 303 | *last_32 ^= lock_number; |
319 | } | 304 | } |
@@ -327,7 +312,7 @@ get_key (const char *domain_name, | |||
327 | * @param value value in the hash map (struct GNUNET_LOCKMANAGER_LockingRequest) | 312 | * @param value value in the hash map (struct GNUNET_LOCKMANAGER_LockingRequest) |
328 | * @return GNUNET_YES if we should continue to | 313 | * @return GNUNET_YES if we should continue to |
329 | * iterate, | 314 | * iterate, |
330 | * GNUNET_NO if not. | 315 | * GNUNET_NO if not. |
331 | */ | 316 | */ |
332 | static int | 317 | static int |
333 | match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | 318 | match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) |
@@ -335,7 +320,7 @@ match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
335 | struct LockingRequestMatch *match = cls; | 320 | struct LockingRequestMatch *match = cls; |
336 | struct GNUNET_LOCKMANAGER_LockingRequest *lr = value; | 321 | struct GNUNET_LOCKMANAGER_LockingRequest *lr = value; |
337 | 322 | ||
338 | if ( (match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain)) ) | 323 | if ((match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain))) |
339 | { | 324 | { |
340 | match->matched_entry = lr; | 325 | match->matched_entry = lr; |
341 | return GNUNET_NO; | 326 | return GNUNET_NO; |
@@ -352,12 +337,11 @@ match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
352 | * @param domain the locking domain name | 337 | * @param domain the locking domain name |
353 | * @param lock the lock number | 338 | * @param lock the lock number |
354 | * @return the found LockingRequest; NULL if a matching LockingRequest wasn't | 339 | * @return the found LockingRequest; NULL if a matching LockingRequest wasn't |
355 | * found | 340 | * found |
356 | */ | 341 | */ |
357 | static struct GNUNET_LOCKMANAGER_LockingRequest * | 342 | static struct GNUNET_LOCKMANAGER_LockingRequest * |
358 | hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map, | 343 | hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map, |
359 | const char *domain, | 344 | const char *domain, uint32_t lock) |
360 | uint32_t lock) | ||
361 | { | 345 | { |
362 | struct GNUNET_HashCode hash; | 346 | struct GNUNET_HashCode hash; |
363 | struct LockingRequestMatch lock_match; | 347 | struct LockingRequestMatch lock_match; |
@@ -366,9 +350,7 @@ hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map, | |||
366 | lock_match.domain = domain; | 350 | lock_match.domain = domain; |
367 | lock_match.lock = lock; | 351 | lock_match.lock = lock; |
368 | get_key (domain, lock, &hash); | 352 | get_key (domain, lock, &hash); |
369 | GNUNET_CONTAINER_multihashmap_get_multiple (map, | 353 | GNUNET_CONTAINER_multihashmap_get_multiple (map, &hash, &match_iterator, |
370 | &hash, | ||
371 | &match_iterator, | ||
372 | &lock_match); | 354 | &lock_match); |
373 | return lock_match.matched_entry; | 355 | return lock_match.matched_entry; |
374 | } | 356 | } |
@@ -390,10 +372,7 @@ call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
390 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 372 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
391 | "Calling status change for SUCCESS on lock num: %d, domain: %s\n", | 373 | "Calling status change for SUCCESS on lock num: %d, domain: %s\n", |
392 | r->lock, r->domain); | 374 | r->lock, r->domain); |
393 | r->status_cb (r->status_cb_cls, | 375 | r->status_cb (r->status_cb_cls, r->domain, r->lock, r->status); |
394 | r->domain, | ||
395 | r->lock, | ||
396 | r->status); | ||
397 | } | 376 | } |
398 | } | 377 | } |
399 | 378 | ||
@@ -410,8 +389,8 @@ generate_acquire_msg (const char *domain_name, uint32_t lock) | |||
410 | { | 389 | { |
411 | struct GNUNET_LOCKMANAGER_Message *msg; | 390 | struct GNUNET_LOCKMANAGER_Message *msg; |
412 | size_t domain_name_len; | 391 | size_t domain_name_len; |
413 | uint16_t msg_size; | 392 | uint16_t msg_size; |
414 | 393 | ||
415 | domain_name_len = strlen (domain_name) + 1; | 394 | domain_name_len = strlen (domain_name) + 1; |
416 | msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_len; | 395 | msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_len; |
417 | msg = GNUNET_malloc (msg_size); | 396 | msg = GNUNET_malloc (msg_size); |
@@ -436,15 +415,14 @@ generate_acquire_msg (const char *domain_name, uint32_t lock) | |||
436 | * GNUNET_NO if not. | 415 | * GNUNET_NO if not. |
437 | */ | 416 | */ |
438 | static int | 417 | static int |
439 | release_n_retry_iterator (void *cls, | 418 | release_n_retry_iterator (void *cls, const struct GNUNET_HashCode *key, |
440 | const struct GNUNET_HashCode * key, | ||
441 | void *value) | 419 | void *value) |
442 | { | 420 | { |
443 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; | 421 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; |
444 | struct GNUNET_LOCKMANAGER_Handle *h = cls; | 422 | struct GNUNET_LOCKMANAGER_Handle *h = cls; |
445 | struct GNUNET_LOCKMANAGER_Message *msg; | 423 | struct GNUNET_LOCKMANAGER_Message *msg; |
446 | 424 | ||
447 | if (GNUNET_NO == r->acquire_sent) /* an acquire is still in queue */ | 425 | if (GNUNET_NO == r->acquire_sent) /* an acquire is still in queue */ |
448 | return GNUNET_YES; | 426 | return GNUNET_YES; |
449 | r->acquire_sent = GNUNET_NO; | 427 | r->acquire_sent = GNUNET_NO; |
450 | msg = generate_acquire_msg (r->domain, r->lock); | 428 | msg = generate_acquire_msg (r->domain, r->lock); |
@@ -457,9 +435,7 @@ release_n_retry_iterator (void *cls, | |||
457 | "Calling status change for RELEASE on lock num: %d, domain: %s\n", | 435 | "Calling status change for RELEASE on lock num: %d, domain: %s\n", |
458 | r->lock, r->domain); | 436 | r->lock, r->domain); |
459 | r->status = GNUNET_LOCKMANAGER_RELEASE; | 437 | r->status = GNUNET_LOCKMANAGER_RELEASE; |
460 | r->status_cb (r->status_cb_cls, | 438 | r->status_cb (r->status_cb_cls, r->domain, r->lock, |
461 | r->domain, | ||
462 | r->lock, | ||
463 | GNUNET_LOCKMANAGER_RELEASE); | 439 | GNUNET_LOCKMANAGER_RELEASE); |
464 | } | 440 | } |
465 | return GNUNET_YES; | 441 | return GNUNET_YES; |
@@ -472,9 +448,8 @@ release_n_retry_iterator (void *cls, | |||
472 | * @param cls the LOCKMANAGER_Handle | 448 | * @param cls the LOCKMANAGER_Handle |
473 | * @param msg received message, NULL on timeout or fatal error | 449 | * @param msg received message, NULL on timeout or fatal error |
474 | */ | 450 | */ |
475 | static void | 451 | static void |
476 | handle_replies (void *cls, | 452 | handle_replies (void *cls, const struct GNUNET_MessageHeader *msg) |
477 | const struct GNUNET_MessageHeader *msg) | ||
478 | { | 453 | { |
479 | struct GNUNET_LOCKMANAGER_Handle *handle = cls; | 454 | struct GNUNET_LOCKMANAGER_Handle *handle = cls; |
480 | const struct GNUNET_LOCKMANAGER_Message *m; | 455 | const struct GNUNET_LOCKMANAGER_Message *m; |
@@ -488,19 +463,16 @@ handle_replies (void *cls, | |||
488 | if (NULL == msg) | 463 | if (NULL == msg) |
489 | { | 464 | { |
490 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 465 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
491 | "Lockmanager service not available or went down\n"); | 466 | "Lockmanager service not available or went down\n"); |
492 | /* Should release all locks and retry to acquire them */ | 467 | /* Should release all locks and retry to acquire them */ |
493 | GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, | 468 | GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, |
494 | &release_n_retry_iterator, | 469 | &release_n_retry_iterator, handle); |
495 | handle); | ||
496 | return; | 470 | return; |
497 | } | 471 | } |
498 | handle->in_replies = GNUNET_YES; | 472 | handle->in_replies = GNUNET_YES; |
499 | GNUNET_CLIENT_receive (handle->conn, | 473 | GNUNET_CLIENT_receive (handle->conn, &handle_replies, handle, |
500 | &handle_replies, | ||
501 | handle, | ||
502 | GNUNET_TIME_UNIT_FOREVER_REL); | 474 | GNUNET_TIME_UNIT_FOREVER_REL); |
503 | if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type)) | 475 | if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs (msg->type)) |
504 | { | 476 | { |
505 | GNUNET_break (0); | 477 | GNUNET_break (0); |
506 | return; | 478 | return; |
@@ -514,20 +486,18 @@ handle_replies (void *cls, | |||
514 | m = (const struct GNUNET_LOCKMANAGER_Message *) msg; | 486 | m = (const struct GNUNET_LOCKMANAGER_Message *) msg; |
515 | domain = (const char *) &m[1]; | 487 | domain = (const char *) &m[1]; |
516 | msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); | 488 | msize -= sizeof (struct GNUNET_LOCKMANAGER_Message); |
517 | if ('\0' != domain[msize-1]) | 489 | if ('\0' != domain[msize - 1]) |
518 | { | 490 | { |
519 | GNUNET_break (0); | 491 | GNUNET_break (0); |
520 | return; | 492 | return; |
521 | } | 493 | } |
522 | 494 | ||
523 | lock = ntohl (m->lock); | 495 | lock = ntohl (m->lock); |
524 | get_key (domain, lock, &hash); | 496 | get_key (domain, lock, &hash); |
525 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 497 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
526 | "Received SUCCESS message for lock: %d, domain %s\n", | 498 | "Received SUCCESS message for lock: %d, domain %s\n", lock, domain); |
527 | lock, domain); | 499 | if (NULL == |
528 | if (NULL == (lr = hashmap_find_lockingrequest (handle->hashmap, | 500 | (lr = hashmap_find_lockingrequest (handle->hashmap, domain, lock))) |
529 | domain, | ||
530 | lock))) | ||
531 | { | 501 | { |
532 | GNUNET_break (0); | 502 | GNUNET_break (0); |
533 | return; | 503 | return; |
@@ -538,11 +508,10 @@ handle_replies (void *cls, | |||
538 | return; | 508 | return; |
539 | } | 509 | } |
540 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 510 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
541 | "Changing status for lock: %d in domain: %s to SUCCESS\n", | 511 | "Changing status for lock: %d in domain: %s to SUCCESS\n", lr->lock, |
542 | lr->lock, lr->domain); | 512 | lr->domain); |
543 | lr->status = GNUNET_LOCKMANAGER_SUCCESS; | 513 | lr->status = GNUNET_LOCKMANAGER_SUCCESS; |
544 | GNUNET_SCHEDULER_add_continuation (&call_status_cb_task, | 514 | GNUNET_SCHEDULER_add_continuation (&call_status_cb_task, lr, |
545 | lr, | ||
546 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 515 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
547 | } | 516 | } |
548 | 517 | ||
@@ -558,19 +527,14 @@ handle_replies (void *cls, | |||
558 | * GNUNET_NO if not. | 527 | * GNUNET_NO if not. |
559 | */ | 528 | */ |
560 | static int | 529 | static int |
561 | free_iterator(void *cls, | 530 | free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) |
562 | const struct GNUNET_HashCode * key, | ||
563 | void *value) | ||
564 | { | 531 | { |
565 | struct GNUNET_LOCKMANAGER_Handle *h = cls; | 532 | struct GNUNET_LOCKMANAGER_Handle *h = cls; |
566 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; | 533 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; |
567 | 534 | ||
568 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 535 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Clearing locking request\n"); |
569 | "Clearing locking request\n"); | 536 | GNUNET_assert (GNUNET_YES == |
570 | GNUNET_assert (GNUNET_YES == | 537 | GNUNET_CONTAINER_multihashmap_remove (h->hashmap, key, value)); |
571 | GNUNET_CONTAINER_multihashmap_remove (h->hashmap, | ||
572 | key, | ||
573 | value)); | ||
574 | GNUNET_free (r->domain); | 538 | GNUNET_free (r->domain); |
575 | GNUNET_free (r); | 539 | GNUNET_free (r); |
576 | return GNUNET_YES; | 540 | return GNUNET_YES; |
@@ -602,14 +566,12 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
602 | GNUNET_free (h); | 566 | GNUNET_free (h); |
603 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | 567 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); |
604 | return NULL; | 568 | return NULL; |
605 | } | 569 | } |
606 | h->hashmap = GNUNET_CONTAINER_multihashmap_create (15); | 570 | h->hashmap = GNUNET_CONTAINER_multihashmap_create (15); |
607 | GNUNET_assert (NULL != h->hashmap); | 571 | GNUNET_assert (NULL != h->hashmap); |
608 | h->in_replies = GNUNET_YES; | 572 | h->in_replies = GNUNET_YES; |
609 | GNUNET_CLIENT_receive (h->conn, | 573 | GNUNET_CLIENT_receive (h->conn, &handle_replies, h, |
610 | &handle_replies, | 574 | GNUNET_TIME_UNIT_FOREVER_REL); |
611 | h, | ||
612 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
613 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | 575 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); |
614 | return h; | 576 | return h; |
615 | } | 577 | } |
@@ -631,8 +593,7 @@ GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) | |||
631 | LOG (GNUNET_ERROR_TYPE_WARNING, | 593 | LOG (GNUNET_ERROR_TYPE_WARNING, |
632 | "Some locking requests are still present. Cancel them before " | 594 | "Some locking requests are still present. Cancel them before " |
633 | "calling %s\n", __func__); | 595 | "calling %s\n", __func__); |
634 | GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, | 596 | GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, &free_iterator, |
635 | &free_iterator, | ||
636 | handle); | 597 | handle); |
637 | } | 598 | } |
638 | GNUNET_CONTAINER_multihashmap_destroy (handle->hashmap); | 599 | GNUNET_CONTAINER_multihashmap_destroy (handle->hashmap); |
@@ -644,9 +605,7 @@ GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) | |||
644 | head = handle->mq_head; | 605 | head = handle->mq_head; |
645 | while (NULL != head) | 606 | while (NULL != head) |
646 | { | 607 | { |
647 | GNUNET_CONTAINER_DLL_remove (handle->mq_head, | 608 | GNUNET_CONTAINER_DLL_remove (handle->mq_head, handle->mq_tail, head); |
648 | handle->mq_tail, | ||
649 | head); | ||
650 | GNUNET_free (head->msg); | 609 | GNUNET_free (head->msg); |
651 | GNUNET_free (head); | 610 | GNUNET_free (head); |
652 | head = handle->mq_head; | 611 | head = handle->mq_head; |
@@ -682,17 +641,15 @@ GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) | |||
682 | */ | 641 | */ |
683 | struct GNUNET_LOCKMANAGER_LockingRequest * | 642 | struct GNUNET_LOCKMANAGER_LockingRequest * |
684 | GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | 643 | GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, |
685 | const char *domain_name, | 644 | const char *domain_name, uint32_t lock, |
686 | uint32_t lock, | 645 | GNUNET_LOCKMANAGER_StatusCallback status_cb, |
687 | GNUNET_LOCKMANAGER_StatusCallback | ||
688 | status_cb, | ||
689 | void *status_cb_cls) | 646 | void *status_cb_cls) |
690 | { | 647 | { |
691 | struct GNUNET_LOCKMANAGER_LockingRequest *r; | 648 | struct GNUNET_LOCKMANAGER_LockingRequest *r; |
692 | struct GNUNET_LOCKMANAGER_Message *msg; | 649 | struct GNUNET_LOCKMANAGER_Message *msg; |
693 | struct GNUNET_HashCode hash; | 650 | struct GNUNET_HashCode hash; |
694 | size_t domain_name_length; | 651 | size_t domain_name_length; |
695 | 652 | ||
696 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | 653 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); |
697 | r = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_LockingRequest)); | 654 | r = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_LockingRequest)); |
698 | domain_name_length = strlen (domain_name) + 1; | 655 | domain_name_length = strlen (domain_name) + 1; |
@@ -705,14 +662,13 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | |||
705 | r->acquire_sent = GNUNET_NO; | 662 | r->acquire_sent = GNUNET_NO; |
706 | memcpy (r->domain, domain_name, domain_name_length); | 663 | memcpy (r->domain, domain_name, domain_name_length); |
707 | msg = generate_acquire_msg (r->domain, r->lock); | 664 | msg = generate_acquire_msg (r->domain, r->lock); |
708 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Queueing ACQUIRE message\n"); | 665 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Queueing ACQUIRE message\n"); |
709 | r->mqe = queue_message (handle, msg, r); | 666 | r->mqe = queue_message (handle, msg, r); |
710 | get_key (r->domain, r->lock, &hash); | 667 | get_key (r->domain, r->lock, &hash); |
711 | GNUNET_assert (GNUNET_OK == | 668 | GNUNET_assert (GNUNET_OK == |
712 | GNUNET_CONTAINER_multihashmap_put (r->handle->hashmap, | 669 | GNUNET_CONTAINER_multihashmap_put (r->handle->hashmap, &hash, |
713 | &hash, | 670 | r, |
714 | r, | 671 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
715 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
716 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | 672 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); |
717 | return r; | 673 | return r; |
718 | } | 674 | } |
@@ -739,16 +695,15 @@ GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest | |||
739 | if (GNUNET_NO == request->acquire_sent) | 695 | if (GNUNET_NO == request->acquire_sent) |
740 | { | 696 | { |
741 | GNUNET_assert (NULL != request->mqe); | 697 | GNUNET_assert (NULL != request->mqe); |
742 | if ((NULL != request->handle->transmit_handle) | 698 | if ((NULL != request->handle->transmit_handle) && |
743 | && (request->handle->mq_head == request->mqe)) | 699 | (request->handle->mq_head == request->mqe)) |
744 | { | 700 | { |
745 | GNUNET_CLIENT_notify_transmit_ready_cancel | 701 | GNUNET_CLIENT_notify_transmit_ready_cancel (request-> |
746 | (request->handle->transmit_handle); | 702 | handle->transmit_handle); |
747 | request->handle->transmit_handle = NULL; | 703 | request->handle->transmit_handle = NULL; |
748 | } | 704 | } |
749 | GNUNET_CONTAINER_DLL_remove (request->handle->mq_head, | 705 | GNUNET_CONTAINER_DLL_remove (request->handle->mq_head, |
750 | request->handle->mq_tail, | 706 | request->handle->mq_tail, request->mqe); |
751 | request->mqe); | ||
752 | GNUNET_free (request->mqe->msg); | 707 | GNUNET_free (request->mqe->msg); |
753 | GNUNET_free (request->mqe); | 708 | GNUNET_free (request->mqe); |
754 | request->status = GNUNET_LOCKMANAGER_RELEASE; | 709 | request->status = GNUNET_LOCKMANAGER_RELEASE; |
@@ -756,8 +711,7 @@ GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest | |||
756 | if (GNUNET_LOCKMANAGER_SUCCESS == request->status) | 711 | if (GNUNET_LOCKMANAGER_SUCCESS == request->status) |
757 | { | 712 | { |
758 | domain_name_length = strlen (request->domain) + 1; | 713 | domain_name_length = strlen (request->domain) + 1; |
759 | msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) | 714 | msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_length; |
760 | + domain_name_length; | ||
761 | msg = GNUNET_malloc (msg_size); | 715 | msg = GNUNET_malloc (msg_size); |
762 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE); | 716 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE); |
763 | msg->header.size = htons (msg_size); | 717 | msg->header.size = htons (msg_size); |
@@ -768,8 +722,8 @@ GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest | |||
768 | } | 722 | } |
769 | get_key (request->domain, request->lock, &hash); | 723 | get_key (request->domain, request->lock, &hash); |
770 | GNUNET_assert (GNUNET_YES == | 724 | GNUNET_assert (GNUNET_YES == |
771 | GNUNET_CONTAINER_multihashmap_remove | 725 | GNUNET_CONTAINER_multihashmap_remove (request->handle->hashmap, |
772 | (request->handle->hashmap, &hash, request)); | 726 | &hash, request)); |
773 | GNUNET_free (request->domain); | 727 | GNUNET_free (request->domain); |
774 | GNUNET_free (request); | 728 | GNUNET_free (request); |
775 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | 729 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); |
diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c index 7d8e75814..1bb84364f 100644 --- a/src/lockmanager/test_lockmanager_api.c +++ b/src/lockmanager/test_lockmanager_api.c | |||
@@ -43,15 +43,15 @@ | |||
43 | * Enumeration of testing steps | 43 | * Enumeration of testing steps |
44 | */ | 44 | */ |
45 | enum Test | 45 | enum Test |
46 | { | 46 | { |
47 | TEST_FAIL, | 47 | TEST_FAIL, |
48 | 48 | ||
49 | TEST_INIT, | 49 | TEST_INIT, |
50 | 50 | ||
51 | LOCK1_ACQUIRE, | 51 | LOCK1_ACQUIRE, |
52 | 52 | ||
53 | LOCK2_ACQUIRE | 53 | LOCK2_ACQUIRE |
54 | }; | 54 | }; |
55 | 55 | ||
56 | 56 | ||
57 | /** | 57 | /** |
@@ -94,10 +94,10 @@ static void | |||
94 | do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | 94 | do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) |
95 | { | 95 | { |
96 | if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) | 96 | if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) |
97 | { | 97 | { |
98 | GNUNET_SCHEDULER_cancel (abort_task_id); | 98 | GNUNET_SCHEDULER_cancel (abort_task_id); |
99 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | 99 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; |
100 | } | 100 | } |
101 | if (NULL != request) | 101 | if (NULL != request) |
102 | GNUNET_LOCKMANAGER_cancel_request (request); | 102 | GNUNET_LOCKMANAGER_cancel_request (request); |
103 | if (NULL != request2) | 103 | if (NULL != request2) |
@@ -127,22 +127,20 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
127 | * | 127 | * |
128 | * @param cls the closure from GNUNET_LOCKMANAGER_lock call | 128 | * @param cls the closure from GNUNET_LOCKMANAGER_lock call |
129 | * | 129 | * |
130 | * @param domain_name the locking domain of the lock | 130 | * @param domain_name the locking domain of the lock |
131 | * | 131 | * |
132 | * @param lock the lock for which this status is relevant | 132 | * @param lock the lock for which this status is relevant |
133 | * | 133 | * |
134 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | 134 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully |
135 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | 135 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost |
136 | */ | 136 | */ |
137 | static void | 137 | static void |
138 | status_cb (void *cls, | 138 | status_cb (void *cls, const char *domain_name, uint32_t lock, |
139 | const char *domain_name, | ||
140 | uint32_t lock, | ||
141 | enum GNUNET_LOCKMANAGER_Status status) | 139 | enum GNUNET_LOCKMANAGER_Status status) |
142 | { | 140 | { |
143 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 141 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
144 | "Status change callback called on lock: %d of domain: %s\n", | 142 | "Status change callback called on lock: %d of domain: %s\n", lock, |
145 | lock, domain_name); | 143 | domain_name); |
146 | switch (result) | 144 | switch (result) |
147 | { | 145 | { |
148 | case LOCK1_ACQUIRE: | 146 | case LOCK1_ACQUIRE: |
@@ -151,23 +149,19 @@ status_cb (void *cls, | |||
151 | //GNUNET_LOCKMANAGER_cancel_request (request); | 149 | //GNUNET_LOCKMANAGER_cancel_request (request); |
152 | //request = NULL; | 150 | //request = NULL; |
153 | result = LOCK2_ACQUIRE; | 151 | result = LOCK2_ACQUIRE; |
154 | request2 = GNUNET_LOCKMANAGER_acquire_lock (handle, | 152 | request2 = |
155 | "GNUNET_LOCKMANAGER_TESTING", | 153 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", |
156 | 100, | 154 | 100, &status_cb, NULL); |
157 | &status_cb, | ||
158 | NULL); | ||
159 | GNUNET_assert (NULL != request2); | 155 | GNUNET_assert (NULL != request2); |
160 | break; | 156 | break; |
161 | case LOCK2_ACQUIRE: | 157 | case LOCK2_ACQUIRE: |
162 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | 158 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); |
163 | GNUNET_assert (NULL != request); | 159 | GNUNET_assert (NULL != request); |
164 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), | 160 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); |
165 | &do_shutdown, | ||
166 | NULL); | ||
167 | break; | 161 | break; |
168 | default: | 162 | default: |
169 | GNUNET_break (0); | 163 | GNUNET_break (0); |
170 | } | 164 | } |
171 | } | 165 | } |
172 | 166 | ||
173 | 167 | ||
@@ -175,8 +169,7 @@ status_cb (void *cls, | |||
175 | * Main point of test execution | 169 | * Main point of test execution |
176 | */ | 170 | */ |
177 | static void | 171 | static void |
178 | run (void *cls, | 172 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
179 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
180 | struct GNUNET_TESTING_Peer *peer) | 173 | struct GNUNET_TESTING_Peer *peer) |
181 | { | 174 | { |
182 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); | 175 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); |
@@ -184,26 +177,24 @@ run (void *cls, | |||
184 | handle = GNUNET_LOCKMANAGER_connect (config); | 177 | handle = GNUNET_LOCKMANAGER_connect (config); |
185 | GNUNET_assert (NULL != handle); | 178 | GNUNET_assert (NULL != handle); |
186 | result = LOCK1_ACQUIRE; | 179 | result = LOCK1_ACQUIRE; |
187 | request = GNUNET_LOCKMANAGER_acquire_lock (handle, | 180 | request = |
188 | "GNUNET_LOCKMANAGER_TESTING", | 181 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, |
189 | 99, | 182 | &status_cb, NULL); |
190 | &status_cb, | 183 | abort_task_id = |
191 | NULL); | 184 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (30), &do_abort, NULL); |
192 | abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (30), | ||
193 | &do_abort, | ||
194 | NULL); | ||
195 | } | 185 | } |
196 | 186 | ||
197 | 187 | ||
198 | /** | 188 | /** |
199 | * Main function | 189 | * Main function |
200 | */ | 190 | */ |
201 | int main (int argc, char **argv) | 191 | int |
192 | main (int argc, char **argv) | ||
202 | { | 193 | { |
203 | 194 | ||
204 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api", | 195 | if (0 != |
205 | "test_lockmanager_api.conf", | 196 | GNUNET_TESTING_peer_run ("test_lockmanager_api", |
206 | &run, NULL)) | 197 | "test_lockmanager_api.conf", &run, NULL)) |
207 | return 1; | 198 | return 1; |
208 | return (TEST_FAIL == result) ? 1 : 0; | 199 | return (TEST_FAIL == result) ? 1 : 0; |
209 | } | 200 | } |
diff --git a/src/lockmanager/test_lockmanager_api_acquireretry.c b/src/lockmanager/test_lockmanager_api_acquireretry.c index f3fc475f0..a90e2784a 100644 --- a/src/lockmanager/test_lockmanager_api_acquireretry.c +++ b/src/lockmanager/test_lockmanager_api_acquireretry.c | |||
@@ -46,32 +46,32 @@ | |||
46 | * Various stages in test | 46 | * Various stages in test |
47 | */ | 47 | */ |
48 | enum Test | 48 | enum Test |
49 | { | 49 | { |
50 | /** | 50 | /** |
51 | * Signal test failure | 51 | * Signal test failure |
52 | */ | 52 | */ |
53 | TEST_FAIL, | 53 | TEST_FAIL, |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Testing just began | 56 | * Testing just began |
57 | */ | 57 | */ |
58 | TEST_INIT, | 58 | TEST_INIT, |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Client has successfully acquired the lock | 61 | * Client has successfully acquired the lock |
62 | */ | 62 | */ |
63 | TEST_CLIENT_LOCK_SUCCESS, | 63 | TEST_CLIENT_LOCK_SUCCESS, |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Client has lost the lock | 66 | * Client has lost the lock |
67 | */ | 67 | */ |
68 | TEST_CLIENT_LOCK_RELEASE, | 68 | TEST_CLIENT_LOCK_RELEASE, |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Client has again acquired the lock | 71 | * Client has again acquired the lock |
72 | */ | 72 | */ |
73 | TEST_CLIENT_LOCK_AGAIN_SUCCESS | 73 | TEST_CLIENT_LOCK_AGAIN_SUCCESS |
74 | }; | 74 | }; |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * Configuration Handle | 77 | * Configuration Handle |
@@ -143,22 +143,20 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
143 | * | 143 | * |
144 | * @param cls the handle | 144 | * @param cls the handle |
145 | * | 145 | * |
146 | * @param domain_name the locking domain of the lock | 146 | * @param domain_name the locking domain of the lock |
147 | * | 147 | * |
148 | * @param lock the lock for which this status is relevant | 148 | * @param lock the lock for which this status is relevant |
149 | * | 149 | * |
150 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | 150 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully |
151 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | 151 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost |
152 | */ | 152 | */ |
153 | static void | 153 | static void |
154 | status_cb (void *cls, | 154 | status_cb (void *cls, const char *domain_name, uint32_t lock, |
155 | const char *domain_name, | ||
156 | uint32_t lock, | ||
157 | enum GNUNET_LOCKMANAGER_Status status) | 155 | enum GNUNET_LOCKMANAGER_Status status) |
158 | { | 156 | { |
159 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 157 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
160 | "Status change callback called on lock: %d of domain: %s\n", | 158 | "Status change callback called on lock: %d of domain: %s\n", lock, |
161 | lock, domain_name); | 159 | domain_name); |
162 | switch (result) | 160 | switch (result) |
163 | { | 161 | { |
164 | case TEST_INIT: | 162 | case TEST_INIT: |
@@ -181,7 +179,7 @@ status_cb (void *cls, | |||
181 | result = TEST_CLIENT_LOCK_AGAIN_SUCCESS; | 179 | result = TEST_CLIENT_LOCK_AGAIN_SUCCESS; |
182 | GNUNET_LOCKMANAGER_cancel_request (request); | 180 | GNUNET_LOCKMANAGER_cancel_request (request); |
183 | request = NULL; | 181 | request = NULL; |
184 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(1), &do_shutdown, NULL); | 182 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), &do_shutdown, NULL); |
185 | break; | 183 | break; |
186 | default: | 184 | default: |
187 | GNUNET_assert (0); /* We should never reach here */ | 185 | GNUNET_assert (0); /* We should never reach here */ |
@@ -193,8 +191,7 @@ status_cb (void *cls, | |||
193 | * Main point of test execution | 191 | * Main point of test execution |
194 | */ | 192 | */ |
195 | static void | 193 | static void |
196 | run (void *cls, | 194 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
197 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
198 | struct GNUNET_TESTING_Peer *peer) | 195 | struct GNUNET_TESTING_Peer *peer) |
199 | { | 196 | { |
200 | config = cfg; | 197 | config = cfg; |
@@ -202,26 +199,24 @@ run (void *cls, | |||
202 | result = TEST_INIT; | 199 | result = TEST_INIT; |
203 | handle = GNUNET_LOCKMANAGER_connect (config); | 200 | handle = GNUNET_LOCKMANAGER_connect (config); |
204 | GNUNET_assert (NULL != handle); | 201 | GNUNET_assert (NULL != handle); |
205 | request = GNUNET_LOCKMANAGER_acquire_lock (handle, | 202 | request = |
206 | "GNUNET_LOCKMANAGER_TESTING", | 203 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, |
207 | 99, | 204 | &status_cb, handle); |
208 | &status_cb, | ||
209 | handle); | ||
210 | GNUNET_assert (NULL != request); | 205 | GNUNET_assert (NULL != request); |
211 | abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (30), | 206 | abort_task_id = |
212 | &do_abort, | 207 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (30), &do_abort, NULL); |
213 | NULL); | ||
214 | } | 208 | } |
215 | 209 | ||
216 | 210 | ||
217 | /** | 211 | /** |
218 | * Main function | 212 | * Main function |
219 | */ | 213 | */ |
220 | int main (int argc, char **argv) | 214 | int |
215 | main (int argc, char **argv) | ||
221 | { | 216 | { |
222 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api_acquireretry", | 217 | if (0 != |
223 | "test_lockmanager_api.conf", | 218 | GNUNET_TESTING_peer_run ("test_lockmanager_api_acquireretry", |
224 | &run, NULL)) | 219 | "test_lockmanager_api.conf", &run, NULL)) |
225 | return 1; | 220 | return 1; |
226 | return (TEST_CLIENT_LOCK_AGAIN_SUCCESS != result) ? 1 : 0; | 221 | return (TEST_CLIENT_LOCK_AGAIN_SUCCESS != result) ? 1 : 0; |
227 | } | 222 | } |
diff --git a/src/lockmanager/test_lockmanager_api_lockrelease.c b/src/lockmanager/test_lockmanager_api_lockrelease.c index 74790a407..3dccf3520 100644 --- a/src/lockmanager/test_lockmanager_api_lockrelease.c +++ b/src/lockmanager/test_lockmanager_api_lockrelease.c | |||
@@ -45,28 +45,28 @@ | |||
45 | * Various steps of the test | 45 | * Various steps of the test |
46 | */ | 46 | */ |
47 | enum Test | 47 | enum Test |
48 | { | 48 | { |
49 | /** | 49 | /** |
50 | * Signal test failure | 50 | * Signal test failure |
51 | */ | 51 | */ |
52 | TEST_FAIL, | 52 | TEST_FAIL, |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Testing just began | 55 | * Testing just began |
56 | */ | 56 | */ |
57 | TEST_INIT, | 57 | TEST_INIT, |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Client 1 has got the lock successfully; Client 2 should try to acquire | 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 | 61 | * the lock now; after some time client 1 has to release the lock |
62 | */ | 62 | */ |
63 | TEST_CLIENT1_LOCK_SUCCESS, | 63 | TEST_CLIENT1_LOCK_SUCCESS, |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Client 2 has got the lock; Should release it and call shutdown | 66 | * Client 2 has got the lock; Should release it and call shutdown |
67 | */ | 67 | */ |
68 | TEST_CLIENT2_LOCK_SUCCESS, | 68 | TEST_CLIENT2_LOCK_SUCCESS, |
69 | }; | 69 | }; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * The testing result | 72 | * The testing result |
@@ -117,7 +117,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
117 | { | 117 | { |
118 | GNUNET_SCHEDULER_cancel (abort_task_id); | 118 | GNUNET_SCHEDULER_cancel (abort_task_id); |
119 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | 119 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; |
120 | } | 120 | } |
121 | GNUNET_LOCKMANAGER_disconnect (handle); | 121 | GNUNET_LOCKMANAGER_disconnect (handle); |
122 | GNUNET_LOCKMANAGER_disconnect (handle2); | 122 | GNUNET_LOCKMANAGER_disconnect (handle2); |
123 | } | 123 | } |
@@ -144,33 +144,29 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
144 | * | 144 | * |
145 | * @param cls the handle | 145 | * @param cls the handle |
146 | * | 146 | * |
147 | * @param domain_name the locking domain of the lock | 147 | * @param domain_name the locking domain of the lock |
148 | * | 148 | * |
149 | * @param lock the lock for which this status is relevant | 149 | * @param lock the lock for which this status is relevant |
150 | * | 150 | * |
151 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | 151 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully |
152 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | 152 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost |
153 | */ | 153 | */ |
154 | static void | 154 | static void |
155 | status_cb (void *cls, | 155 | status_cb (void *cls, const char *domain_name, uint32_t lock, |
156 | const char *domain_name, | ||
157 | uint32_t lock, | ||
158 | enum GNUNET_LOCKMANAGER_Status status) | 156 | enum GNUNET_LOCKMANAGER_Status status) |
159 | { | 157 | { |
160 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 158 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
161 | "Status change callback called on lock: %d of domain: %s\n", | 159 | "Status change callback called on lock: %d of domain: %s\n", lock, |
162 | lock, domain_name); | 160 | domain_name); |
163 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | 161 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); |
164 | switch (result) | 162 | switch (result) |
165 | { | 163 | { |
166 | case TEST_INIT: | 164 | case TEST_INIT: |
167 | GNUNET_assert (handle == cls); | 165 | GNUNET_assert (handle == cls); |
168 | result = TEST_CLIENT1_LOCK_SUCCESS; | 166 | result = TEST_CLIENT1_LOCK_SUCCESS; |
169 | request2 = GNUNET_LOCKMANAGER_acquire_lock (handle2, | 167 | request2 = |
170 | "GNUNET_LOCKMANAGER_TESTING", | 168 | GNUNET_LOCKMANAGER_acquire_lock (handle2, "GNUNET_LOCKMANAGER_TESTING", |
171 | 99, | 169 | 99, &status_cb, handle2); |
172 | &status_cb, | ||
173 | handle2); | ||
174 | GNUNET_assert (NULL != request2); | 170 | GNUNET_assert (NULL != request2); |
175 | GNUNET_LOCKMANAGER_cancel_request (request); | 171 | GNUNET_LOCKMANAGER_cancel_request (request); |
176 | request = NULL; | 172 | request = NULL; |
@@ -179,9 +175,7 @@ status_cb (void *cls, | |||
179 | GNUNET_assert (handle2 == cls); | 175 | GNUNET_assert (handle2 == cls); |
180 | result = TEST_CLIENT2_LOCK_SUCCESS; | 176 | result = TEST_CLIENT2_LOCK_SUCCESS; |
181 | GNUNET_LOCKMANAGER_cancel_request (request2); | 177 | GNUNET_LOCKMANAGER_cancel_request (request2); |
182 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), | 178 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); |
183 | &do_shutdown, | ||
184 | NULL); | ||
185 | break; | 179 | break; |
186 | default: | 180 | default: |
187 | GNUNET_assert (0); /* We should never reach here */ | 181 | GNUNET_assert (0); /* We should never reach here */ |
@@ -194,8 +188,7 @@ status_cb (void *cls, | |||
194 | * Main point of test execution | 188 | * Main point of test execution |
195 | */ | 189 | */ |
196 | static void | 190 | static void |
197 | run (void *cls, | 191 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
198 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
199 | struct GNUNET_TESTING_Peer *peer) | 192 | struct GNUNET_TESTING_Peer *peer) |
200 | { | 193 | { |
201 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); | 194 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n"); |
@@ -204,27 +197,25 @@ run (void *cls, | |||
204 | handle = GNUNET_LOCKMANAGER_connect (config); | 197 | handle = GNUNET_LOCKMANAGER_connect (config); |
205 | GNUNET_assert (NULL != handle); | 198 | GNUNET_assert (NULL != handle); |
206 | handle2 = GNUNET_LOCKMANAGER_connect (config); | 199 | handle2 = GNUNET_LOCKMANAGER_connect (config); |
207 | 200 | ||
208 | request = GNUNET_LOCKMANAGER_acquire_lock (handle, | 201 | request = |
209 | "GNUNET_LOCKMANAGER_TESTING", | 202 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, |
210 | 99, | 203 | &status_cb, handle); |
211 | &status_cb, | ||
212 | handle); | ||
213 | GNUNET_assert (NULL != request); | 204 | GNUNET_assert (NULL != request); |
214 | abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), | 205 | abort_task_id = |
215 | &do_abort, | 206 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), &do_abort, NULL); |
216 | NULL); | ||
217 | } | 207 | } |
218 | 208 | ||
219 | 209 | ||
220 | /** | 210 | /** |
221 | * Main function | 211 | * Main function |
222 | */ | 212 | */ |
223 | int main (int argc, char **argv) | 213 | int |
214 | main (int argc, char **argv) | ||
224 | { | 215 | { |
225 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api_lockrelease", | 216 | if (0 != |
226 | "test_lockmanager_api.conf", | 217 | GNUNET_TESTING_peer_run ("test_lockmanager_api_lockrelease", |
227 | &run, NULL)) | 218 | "test_lockmanager_api.conf", &run, NULL)) |
228 | return 1; | 219 | return 1; |
229 | return (TEST_CLIENT2_LOCK_SUCCESS != result) ? 1 : 0; | 220 | return (TEST_CLIENT2_LOCK_SUCCESS != result) ? 1 : 0; |
230 | } | 221 | } |
diff --git a/src/lockmanager/test_lockmanager_api_servercrash.c b/src/lockmanager/test_lockmanager_api_servercrash.c index 76cc85d0d..694dcd5fb 100644 --- a/src/lockmanager/test_lockmanager_api_servercrash.c +++ b/src/lockmanager/test_lockmanager_api_servercrash.c | |||
@@ -45,34 +45,34 @@ | |||
45 | * Various steps of the test | 45 | * Various steps of the test |
46 | */ | 46 | */ |
47 | enum Test | 47 | enum Test |
48 | { | 48 | { |
49 | /** | 49 | /** |
50 | * Signal test failure | 50 | * Signal test failure |
51 | */ | 51 | */ |
52 | TEST_FAIL, | 52 | TEST_FAIL, |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Testing just began | 55 | * Testing just began |
56 | */ | 56 | */ |
57 | TEST_INIT, | 57 | TEST_INIT, |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Client 1 has got the lock successfully; Client 2 should try to acquire | 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 | 61 | * the lock now; after some time client 1 has to release the lock |
62 | */ | 62 | */ |
63 | TEST_CLIENT1_LOCK_SUCCESS, | 63 | TEST_CLIENT1_LOCK_SUCCESS, |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Client 2 has got the lock; Server should crash now; | 66 | * Client 2 has got the lock; Server should crash now; |
67 | */ | 67 | */ |
68 | TEST_CLIENT2_LOCK_SUCCESS, | 68 | TEST_CLIENT2_LOCK_SUCCESS, |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Client 2 should get lock release due to server crash; Should call | 71 | * Client 2 should get lock release due to server crash; Should call |
72 | * shutdown now | 72 | * shutdown now |
73 | */ | 73 | */ |
74 | TEST_CLIENT2_SERVER_CRASH_SUCCESS | 74 | TEST_CLIENT2_SERVER_CRASH_SUCCESS |
75 | }; | 75 | }; |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * The testing result | 78 | * The testing result |
@@ -157,33 +157,29 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
157 | * | 157 | * |
158 | * @param cls the handle | 158 | * @param cls the handle |
159 | * | 159 | * |
160 | * @param domain_name the locking domain of the lock | 160 | * @param domain_name the locking domain of the lock |
161 | * | 161 | * |
162 | * @param lock the lock for which this status is relevant | 162 | * @param lock the lock for which this status is relevant |
163 | * | 163 | * |
164 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | 164 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully |
165 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | 165 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost |
166 | */ | 166 | */ |
167 | static void | 167 | static void |
168 | status_cb (void *cls, | 168 | status_cb (void *cls, const char *domain_name, uint32_t lock, |
169 | const char *domain_name, | ||
170 | uint32_t lock, | ||
171 | enum GNUNET_LOCKMANAGER_Status status) | 169 | enum GNUNET_LOCKMANAGER_Status status) |
172 | { | 170 | { |
173 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 171 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
174 | "Status change callback called on lock: %d of domain: %s\n", | 172 | "Status change callback called on lock: %d of domain: %s\n", lock, |
175 | lock, domain_name); | 173 | domain_name); |
176 | switch (result) | 174 | switch (result) |
177 | { | 175 | { |
178 | case TEST_INIT: | 176 | case TEST_INIT: |
179 | GNUNET_assert (handle == cls); | 177 | GNUNET_assert (handle == cls); |
180 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | 178 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); |
181 | result = TEST_CLIENT1_LOCK_SUCCESS; | 179 | result = TEST_CLIENT1_LOCK_SUCCESS; |
182 | request2 = GNUNET_LOCKMANAGER_acquire_lock (handle2, | 180 | request2 = |
183 | "GNUNET_LOCKMANAGER_TESTING", | 181 | GNUNET_LOCKMANAGER_acquire_lock (handle2, "GNUNET_LOCKMANAGER_TESTING", |
184 | 99, | 182 | 99, &status_cb, handle2); |
185 | &status_cb, | ||
186 | handle2); | ||
187 | GNUNET_assert (NULL != request2); | 183 | GNUNET_assert (NULL != request2); |
188 | GNUNET_LOCKMANAGER_cancel_request (request); | 184 | GNUNET_LOCKMANAGER_cancel_request (request); |
189 | request = NULL; | 185 | request = NULL; |
@@ -203,9 +199,7 @@ status_cb (void *cls, | |||
203 | result = TEST_CLIENT2_SERVER_CRASH_SUCCESS; | 199 | result = TEST_CLIENT2_SERVER_CRASH_SUCCESS; |
204 | GNUNET_LOCKMANAGER_cancel_request (request2); | 200 | GNUNET_LOCKMANAGER_cancel_request (request2); |
205 | request2 = NULL; | 201 | request2 = NULL; |
206 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), | 202 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL); |
207 | &do_shutdown, | ||
208 | NULL); | ||
209 | break; | 203 | break; |
210 | default: | 204 | default: |
211 | GNUNET_assert (0); /* We should never reach here */ | 205 | GNUNET_assert (0); /* We should never reach here */ |
@@ -217,8 +211,7 @@ status_cb (void *cls, | |||
217 | * Main point of test execution | 211 | * Main point of test execution |
218 | */ | 212 | */ |
219 | static void | 213 | static void |
220 | run (void *cls, | 214 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
221 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
222 | struct GNUNET_TESTING_Peer *peer) | 215 | struct GNUNET_TESTING_Peer *peer) |
223 | { | 216 | { |
224 | config = cfg; | 217 | config = cfg; |
@@ -227,27 +220,25 @@ run (void *cls, | |||
227 | handle = GNUNET_LOCKMANAGER_connect (config); | 220 | handle = GNUNET_LOCKMANAGER_connect (config); |
228 | GNUNET_assert (NULL != handle); | 221 | GNUNET_assert (NULL != handle); |
229 | handle2 = GNUNET_LOCKMANAGER_connect (config); | 222 | handle2 = GNUNET_LOCKMANAGER_connect (config); |
230 | 223 | ||
231 | request = GNUNET_LOCKMANAGER_acquire_lock (handle, | 224 | request = |
232 | "GNUNET_LOCKMANAGER_TESTING", | 225 | GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99, |
233 | 99, | 226 | &status_cb, handle); |
234 | &status_cb, | ||
235 | handle); | ||
236 | GNUNET_assert (NULL != request); | 227 | GNUNET_assert (NULL != request); |
237 | abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), | 228 | abort_task_id = |
238 | &do_abort, | 229 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), &do_abort, NULL); |
239 | NULL); | ||
240 | } | 230 | } |
241 | 231 | ||
242 | 232 | ||
243 | /** | 233 | /** |
244 | * Main function | 234 | * Main function |
245 | */ | 235 | */ |
246 | int main (int argc, char **argv) | 236 | int |
237 | main (int argc, char **argv) | ||
247 | { | 238 | { |
248 | if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api_servercrash", | 239 | if (0 != |
249 | "test_lockmanager_api.conf", | 240 | GNUNET_TESTING_peer_run ("test_lockmanager_api_servercrash", |
250 | &run, NULL)) | 241 | "test_lockmanager_api.conf", &run, NULL)) |
251 | return 1; | 242 | return 1; |
252 | return (TEST_CLIENT2_SERVER_CRASH_SUCCESS != result) ? 1 : 0; | 243 | return (TEST_CLIENT2_SERVER_CRASH_SUCCESS != result) ? 1 : 0; |
253 | } | 244 | } |