aboutsummaryrefslogtreecommitdiff
path: root/src/lockmanager
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-09 12:25:27 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-09 12:25:27 +0000
commit67f274426cf8ffd0b0c5d71396f69e5366149cb6 (patch)
treee262d00ed6bb5b57532a3849920f62817875207e /src/lockmanager
parentb89504002afc3cc5e63933366e7b22801b05b6b9 (diff)
downloadgnunet-67f274426cf8ffd0b0c5d71396f69e5366149cb6.tar.gz
gnunet-67f274426cf8ffd0b0c5d71396f69e5366149cb6.zip
-stylistic fixes
Diffstat (limited to 'src/lockmanager')
-rw-r--r--src/lockmanager/gnunet-service-lockmanager.c150
1 files changed, 44 insertions, 106 deletions
diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c
index f7c01b1af..3a7a729c3 100644
--- a/src/lockmanager/gnunet-service-lockmanager.c
+++ b/src/lockmanager/gnunet-service-lockmanager.c
@@ -33,7 +33,6 @@
33 33
34#include "lockmanager.h" 34#include "lockmanager.h"
35 35
36#define VERBOSE GNUNET_YES
37 36
38#define LOG(kind,...) \ 37#define LOG(kind,...) \
39 GNUNET_log (kind, __VA_ARGS__) 38 GNUNET_log (kind, __VA_ARGS__)
@@ -45,6 +44,12 @@
45 44
46 45
47/** 46/**
47 * Doubly linked list of clients having connections to us
48 */
49struct ClientList;
50
51
52/**
48 * Doubly linked list of clients waiting for a lock 53 * Doubly linked list of clients waiting for a lock
49 */ 54 */
50struct WaitList 55struct WaitList
@@ -161,30 +166,18 @@ static struct ClientList *cl_tail;
161 * it will be the last element in the locks list 166 * it will be the last element in the locks list
162 * @return GNUNET_YES if a matching lock is present in lock_list; GNUNET_NO if not 167 * @return GNUNET_YES if a matching lock is present in lock_list; GNUNET_NO if not
163 */ 168 */
164static int 169static struct LockList *
165ll_find_lock (const char *domain_name, 170ll_find_lock (const char *domain_name,
166 const uint32_t lock_num, 171 const uint32_t lock_num)
167 struct LockList **ret) 172
168{ 173{
169 struct LockList *current_lock; 174 struct LockList *current_lock;
170
171 current_lock = ll_head;
172 175
173 while (NULL != current_lock) 176 for (current_lock = ll_head; NULL != current_lock; current_lock = current_lock->next)
174 { 177 if ( (lock_num == current_lock->lock_num) &&
175 if ( (0 == strcmp (domain_name, current_lock->domain_name)) 178 (0 == strcmp (domain_name, current_lock->domain_name)) )
176 && (lock_num == current_lock->lock_num)) 179 return current_lock;
177 { 180 return NULL;
178 if (NULL != ret)
179 *ret = current_lock;
180 return GNUNET_YES;
181 }
182
183 current_lock = current_lock->next;
184 }
185 if (NULL != ret)
186 *ret = current_lock;
187 return GNUNET_NO;
188} 181}
189 182
190 183
@@ -197,28 +190,15 @@ ll_find_lock (const char *domain_name,
197 * it will be the last element in the locks list 190 * it will be the last element in the locks list
198 * @return GNUNET_YES if a matching lock is present in lock_list; GNUNET_NO if not 191 * @return GNUNET_YES if a matching lock is present in lock_list; GNUNET_NO if not
199 */ 192 */
200static int 193static struct LockList *
201ll_find_lock_by_owner (const struct GNUNET_SERVER_Client *client, 194ll_find_lock_by_owner (const struct GNUNET_SERVER_Client *client)
202 struct LockList **ret)
203{ 195{
204 struct LockList *current_lock; 196 struct LockList *current_lock;
205 197
206 current_lock = ll_head; 198 for (current_lock = ll_head; NULL != current_lock; current_lock = current_lock->next)
207 199 if (client == current_lock->client)
208 while (NULL != current_lock) 200 return current_lock;
209 { 201 return NULL;
210 if (client == current_lock->client)
211 {
212 if (NULL != ret)
213 *ret = current_lock;
214 return GNUNET_YES;
215 }
216
217 current_lock = current_lock->next;
218 }
219 if (NULL != ret)
220 *ret = current_lock;
221 return GNUNET_NO;
222} 202}
223 203
224 204
@@ -346,7 +326,6 @@ ll_wl_remove_client (struct LockList *lock,
346 GNUNET_CONTAINER_DLL_remove (lock->wait_list_head, 326 GNUNET_CONTAINER_DLL_remove (lock->wait_list_head,
347 lock->wait_list_tail, 327 lock->wait_list_tail,
348 wl_client); 328 wl_client);
349
350 GNUNET_free (wl_client); 329 GNUNET_free (wl_client);
351} 330}
352 331
@@ -359,29 +338,15 @@ ll_wl_remove_client (struct LockList *lock,
359 * else to the tail of the client list 338 * else to the tail of the client list
360 * @return GNUNET_YES if the client is present; GNUNET_NO if not 339 * @return GNUNET_YES if the client is present; GNUNET_NO if not
361 */ 340 */
362static int 341static struct ClientList *
363cl_find_client (const struct GNUNET_SERVER_Client *client, 342cl_find_client (const struct GNUNET_SERVER_Client *client)
364 struct ClientList **ret)
365{ 343{
366 struct ClientList *current; 344 struct ClientList *current;
367 345
368 current = cl_head; 346 for (current = cl_head; NULL != current; current = current->next)
369
370 while (NULL != current)
371 {
372 if (client == current->client) 347 if (client == current->client)
373 { 348 return current;
374 if (NULL != ret) 349 return NULL;
375 *ret = current;
376 return GNUNET_YES;
377 }
378
379 current = current->next;
380 }
381
382 if (NULL != ret)
383 *ret = current;
384 return GNUNET_NO;
385} 350}
386 351
387 352
@@ -501,24 +466,18 @@ handle_acquire (void *cls,
501 const char *domain_name; 466 const char *domain_name;
502 struct LockList *ll_entry; 467 struct LockList *ll_entry;
503 uint32_t lock_num; 468 uint32_t lock_num;
504
505 469
506 LOG (GNUNET_ERROR_TYPE_DEBUG, 470 LOG (GNUNET_ERROR_TYPE_DEBUG,
507 "Received an ACQUIRE message\n"); 471 "Received an ACQUIRE message\n");
508
509
510 /* Check if the client is in client list */ 472 /* Check if the client is in client list */
511 if (GNUNET_NO == cl_find_client (client, NULL)) 473 if (NULL == cl_find_client (client))
512 { 474 cl_add_client (client);
513 cl_add_client (client);
514 }
515 475
516 request = (struct GNUNET_LOCKMANAGER_Message *) message; 476 request = (struct GNUNET_LOCKMANAGER_Message *) message;
517 lock_num = ntohl (request->lock); 477 lock_num = ntohl (request->lock);
518 domain_name = (char *) &request[1]; 478 domain_name = (char *) &request[1];
519 if (GNUNET_YES == ll_find_lock (domain_name, 479 if (NULL != (ll_entry = ll_find_lock (domain_name,
520 lock_num, 480 lock_num)))
521 &ll_entry))
522 {/* Add client to the lock's wait list */ 481 {/* Add client to the lock's wait list */
523 ll_wl_add_client (ll_entry, client); 482 ll_wl_add_client (ll_entry, client);
524 } 483 }
@@ -555,7 +514,7 @@ process_lock_release (struct LockList *ll_entry)
555 { 514 {
556 ll_wl_remove_client(ll_entry, wl_entry); 515 ll_wl_remove_client(ll_entry, wl_entry);
557 516
558 if (GNUNET_NO == cl_find_client (wl_entry->client, NULL)) 517 if (NULL == cl_find_client (wl_entry->client))
559 { 518 {
560 LOG (GNUNET_ERROR_TYPE_DEBUG, 519 LOG (GNUNET_ERROR_TYPE_DEBUG,
561 "Removing disconnected client from wait list\n"); 520 "Removing disconnected client from wait list\n");
@@ -601,7 +560,7 @@ handle_release (void *cls,
601 "Received a RELEASE message on lock with num: %d, domain: %s\n", 560 "Received a RELEASE message on lock with num: %d, domain: %s\n",
602 lock_num, domain_name); 561 lock_num, domain_name);
603 GNUNET_SERVER_receive_done (client, GNUNET_OK); 562 GNUNET_SERVER_receive_done (client, GNUNET_OK);
604 if (GNUNET_YES == ll_find_lock (domain_name, lock_num, &ll_entry)) 563 if (NULL != (ll_entry = ll_find_lock (domain_name, lock_num)))
605 { 564 {
606 if (client != ll_entry->client) 565 if (client != ll_entry->client)
607 { 566 {
@@ -612,8 +571,8 @@ handle_release (void *cls,
612 } 571 }
613 else 572 else
614 { 573 {
615 LOG (GNUNET_ERROR_TYPE_DEBUG, 574 LOG (GNUNET_ERROR_TYPE_WARNING,
616 "\t give lock doesn't exist\n"); 575 _("Client tried to release lock that it doesn't exist\n"));
617 } 576 }
618} 577}
619 578
@@ -628,21 +587,16 @@ static void
628client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) 587client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
629{ 588{
630 struct ClientList *cl_entry; 589 struct ClientList *cl_entry;
590 struct LockList *ll_entry;
631 591
632 LOG (GNUNET_ERROR_TYPE_DEBUG, 592 LOG (GNUNET_ERROR_TYPE_DEBUG,
633 "A client has been disconnected -- freeing its locks and resources\n"); 593 "A client has been disconnected -- freeing its locks and resources\n");
634 594 cl_entry = cl_find_client (client);
635 if (GNUNET_YES == cl_find_client (client, &cl_entry)) 595 if (NULL == cl_entry)
636 { 596 return;
637 struct LockList *ll_entry; 597 cl_remove_client (cl_entry);
638 598 while (NULL != (ll_entry = ll_find_lock_by_owner (client)))
639 cl_remove_client (cl_entry); 599 process_lock_release (ll_entry);
640 while (GNUNET_YES == ll_find_lock_by_owner (client, &ll_entry))
641 {
642 process_lock_release (ll_entry);
643 }
644 }
645 else GNUNET_break (0);
646} 600}
647 601
648 602
@@ -664,34 +618,20 @@ lockmanager_run (void *cls,
664 {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0}, 618 {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0},
665 {NULL} 619 {NULL}
666 }; 620 };
667
668 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lockmanager\n");
669 GNUNET_SERVER_add_handlers (server, 621 GNUNET_SERVER_add_handlers (server,
670 message_handlers); 622 message_handlers);
671 GNUNET_SERVER_disconnect_notify (server, 623 GNUNET_SERVER_disconnect_notify (server,
672 &client_disconnect_cb, 624 &client_disconnect_cb,
673 NULL); 625 NULL);
674
675
676} 626}
677 627
628
678/** 629/**
679 * The starting point of execution 630 * The starting point of execution
680 */ 631 */
681int main (int argc, char *const *argv) 632int main (int argc, char *const *argv)
682{ 633{
683 int ret; 634 return
684
685 GNUNET_log_setup ("lockmanager",
686#if VERBOSE
687 "DEBUG",
688#else
689 "WARNING",
690#endif
691 NULL);
692
693 LOG (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
694 ret =
695 (GNUNET_OK == 635 (GNUNET_OK ==
696 GNUNET_SERVICE_run (argc, 636 GNUNET_SERVICE_run (argc,
697 argv, 637 argv,
@@ -699,6 +639,4 @@ int main (int argc, char *const *argv)
699 GNUNET_SERVICE_OPTION_NONE, 639 GNUNET_SERVICE_OPTION_NONE,
700 &lockmanager_run, 640 &lockmanager_run,
701 NULL)) ? 0 : 1; 641 NULL)) ? 0 : 1;
702 LOG (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");
703 return ret;
704} 642}