summaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_cache.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-02-01 20:23:00 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-02-01 20:23:00 +0000
commit3da727fad649c8c477fa6a2f02e6230780abe94f (patch)
treee300a0db7b8c3c947d2f151fb8709df18f3bbde5 /src/testbed/gnunet-service-testbed_cache.c
parenta7384ba9634781fa115a93645d255e525614a86e (diff)
downloadgnunet-3da727fad649c8c477fa6a2f02e6230780abe94f.tar.gz
gnunet-3da727fad649c8c477fa6a2f02e6230780abe94f.zip
- doc & indent
Diffstat (limited to 'src/testbed/gnunet-service-testbed_cache.c')
-rw-r--r--src/testbed/gnunet-service-testbed_cache.c118
1 files changed, 54 insertions, 64 deletions
diff --git a/src/testbed/gnunet-service-testbed_cache.c b/src/testbed/gnunet-service-testbed_cache.c
index 9e65db9e8..46c7d4fce 100644
--- a/src/testbed/gnunet-service-testbed_cache.c
+++ b/src/testbed/gnunet-service-testbed_cache.c
@@ -117,12 +117,12 @@ struct GSTCacheGetHandle
117 * The cache entry object this handle corresponds to 117 * The cache entry object this handle corresponds to
118 */ 118 */
119 struct CacheEntry *entry; 119 struct CacheEntry *entry;
120 120
121 /** 121 /**
122 * The cache callback to call when a handle is available 122 * The cache callback to call when a handle is available
123 */ 123 */
124 GST_cache_handle_ready_cb cb; 124 GST_cache_handle_ready_cb cb;
125 125
126 /** 126 /**
127 * The closure for the above callback 127 * The closure for the above callback
128 */ 128 */
@@ -130,7 +130,7 @@ struct GSTCacheGetHandle
130 130
131 /** 131 /**
132 * The peer connect notify context created for this handle; can be NULL 132 * The peer connect notify context created for this handle; can be NULL
133 */ 133 */
134 struct ConnectNotifyContext *nctxt; 134 struct ConnectNotifyContext *nctxt;
135 135
136 /** 136 /**
@@ -147,7 +147,7 @@ struct GSTCacheGetHandle
147/** 147/**
148 * Cache entry 148 * Cache entry
149 */ 149 */
150struct CacheEntry 150struct CacheEntry
151{ 151{
152 /** 152 /**
153 * DLL next ptr for least recently used cache entries 153 * DLL next ptr for least recently used cache entries
@@ -312,7 +312,7 @@ static void
312close_handles (struct CacheEntry *entry) 312close_handles (struct CacheEntry *entry)
313{ 313{
314 struct ConnectNotifyContext *ctxt; 314 struct ConnectNotifyContext *ctxt;
315 315
316 GNUNET_assert (0 == entry->demand); 316 GNUNET_assert (0 == entry->demand);
317 if (GNUNET_YES == entry->in_lru) 317 if (GNUNET_YES == entry->in_lru)
318 { 318 {
@@ -363,8 +363,7 @@ add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id)
363 entry->peer_id = peer_id; 363 entry->peer_id = peer_id;
364 memcpy (&entry->key, key, sizeof (struct GNUNET_HashCode)); 364 memcpy (&entry->key, key, sizeof (struct GNUNET_HashCode));
365 GNUNET_assert (GNUNET_OK == 365 GNUNET_assert (GNUNET_OK ==
366 GNUNET_CONTAINER_multihashmap_put (cache, &entry->key, 366 GNUNET_CONTAINER_multihashmap_put (cache, &entry->key, entry,
367 entry,
368 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 367 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
369 cache_size++; 368 cache_size++;
370 return entry; 369 return entry;
@@ -388,7 +387,7 @@ search_suitable_cgh (const struct CacheEntry *entry,
388{ 387{
389 const struct GSTCacheGetHandle *cgh; 388 const struct GSTCacheGetHandle *cgh;
390 389
391 for (cgh=head; NULL != cgh; cgh=cgh->next) 390 for (cgh = head; NULL != cgh; cgh = cgh->next)
392 { 391 {
393 if (GNUNET_YES == cgh->notify_called) 392 if (GNUNET_YES == cgh->notify_called)
394 return NULL; 393 return NULL;
@@ -404,7 +403,7 @@ search_suitable_cgh (const struct CacheEntry *entry,
404 break; 403 break;
405 } 404 }
406 break; 405 break;
407 } 406 }
408 return (struct GSTCacheGetHandle *) cgh; 407 return (struct GSTCacheGetHandle *) cgh;
409} 408}
410 409
@@ -422,7 +421,7 @@ call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
422 struct CacheEntry *entry = cls; 421 struct CacheEntry *entry = cls;
423 struct GSTCacheGetHandle *cgh; 422 struct GSTCacheGetHandle *cgh;
424 const struct GSTCacheGetHandle *cgh2; 423 const struct GSTCacheGetHandle *cgh2;
425 424
426 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->notify_task); 425 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->notify_task);
427 entry->notify_task = GNUNET_SCHEDULER_NO_TASK; 426 entry->notify_task = GNUNET_SCHEDULER_NO_TASK;
428 cgh = search_suitable_cgh (entry, entry->cgh_qhead); 427 cgh = search_suitable_cgh (entry, entry->cgh_qhead);
@@ -436,13 +435,13 @@ call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
436 if (NULL != cgh2) 435 if (NULL != cgh2)
437 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry); 436 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
438 if (NULL != cgh->nctxt) 437 if (NULL != cgh->nctxt)
439 {/* Register the peer connect notify callback */ 438 { /* Register the peer connect notify callback */
440 GNUNET_CONTAINER_DLL_insert_tail (entry->nctxt_qhead, entry->nctxt_qtail, 439 GNUNET_CONTAINER_DLL_insert_tail (entry->nctxt_qhead, entry->nctxt_qtail,
441 cgh->nctxt); 440 cgh->nctxt);
442 } 441 }
443 LOG_DEBUG ("Calling notify for handle type %u\n", cgh->type); 442 LOG_DEBUG ("Calling notify for handle type %u\n", cgh->type);
444 cgh->cb (cgh->cb_cls, entry->core_handle, 443 cgh->cb (cgh->cb_cls, entry->core_handle, entry->transport_handle_,
445 entry->transport_handle_, entry->peer_identity); 444 entry->peer_identity);
446} 445}
447 446
448 447
@@ -455,9 +454,8 @@ call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
455 * @param peer the peer that connected 454 * @param peer the peer that connected
456 * @param type the type of the handle this notification corresponds to 455 * @param type the type of the handle this notification corresponds to
457 */ 456 */
458static void 457static void
459peer_connect_notify_cb (void *cls, 458peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
460 const struct GNUNET_PeerIdentity *peer,
461 const enum CacheGetType type) 459 const enum CacheGetType type)
462{ 460{
463 struct CacheEntry *entry = cls; 461 struct CacheEntry *entry = cls;
@@ -466,8 +464,8 @@ peer_connect_notify_cb (void *cls,
466 GST_cache_peer_connect_notify cb; 464 GST_cache_peer_connect_notify cb;
467 void *cb_cls; 465 void *cb_cls;
468 466
469 467
470 for (ctxt=entry->nctxt_qhead; NULL != ctxt;) 468 for (ctxt = entry->nctxt_qhead; NULL != ctxt;)
471 { 469 {
472 GNUNET_assert (NULL != ctxt->cgh); 470 GNUNET_assert (NULL != ctxt->cgh);
473 if (type != ctxt->cgh->type) 471 if (type != ctxt->cgh->type)
@@ -487,11 +485,11 @@ peer_connect_notify_cb (void *cls,
487 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt); 485 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt);
488 GNUNET_free (ctxt); 486 GNUNET_free (ctxt);
489 ctxt = ctxt2; 487 ctxt = ctxt2;
490 cb (cb_cls, peer); 488 cb (cb_cls, peer);
491 } 489 }
492 if (NULL == ctxt) 490 if (NULL == ctxt)
493 return; 491 return;
494 492
495} 493}
496 494
497 495
@@ -504,7 +502,7 @@ peer_connect_notify_cb (void *cls,
504 * @param ats performance data 502 * @param ats performance data
505 * @param ats_count number of entries in ats (excluding 0-termination) 503 * @param ats_count number of entries in ats (excluding 0-termination)
506 */ 504 */
507static void 505static void
508transport_peer_connect_notify_cb (void *cls, 506transport_peer_connect_notify_cb (void *cls,
509 const struct GNUNET_PeerIdentity *peer, 507 const struct GNUNET_PeerIdentity *peer,
510 const struct GNUNET_ATS_Information *ats, 508 const struct GNUNET_ATS_Information *ats,
@@ -527,10 +525,8 @@ opstart_get_handle_transport (void *cls)
527 525
528 GNUNET_assert (NULL != entry); 526 GNUNET_assert (NULL != entry);
529 LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id); 527 LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id);
530 entry->transport_handle_ = 528 entry->transport_handle_ =
531 GNUNET_TRANSPORT_connect (entry->cfg, 529 GNUNET_TRANSPORT_connect (entry->cfg, NULL, entry, NULL,
532 NULL, entry,
533 NULL,
534 &transport_peer_connect_notify_cb, NULL); 530 &transport_peer_connect_notify_cb, NULL);
535 if (NULL == entry->transport_handle_) 531 if (NULL == entry->transport_handle_)
536 { 532 {
@@ -556,7 +552,7 @@ static void
556oprelease_get_handle_transport (void *cls) 552oprelease_get_handle_transport (void *cls)
557{ 553{
558 struct CacheEntry *entry = cls; 554 struct CacheEntry *entry = cls;
559 555
560 if (NULL == entry->transport_handle_) 556 if (NULL == entry->transport_handle_)
561 return; 557 return;
562 GNUNET_TRANSPORT_disconnect (entry->transport_handle_); 558 GNUNET_TRANSPORT_disconnect (entry->transport_handle_);
@@ -577,9 +573,8 @@ oprelease_get_handle_transport (void *cls)
577 * @param server handle to the server, NULL if we failed 573 * @param server handle to the server, NULL if we failed
578 * @param my_identity ID of this peer, NULL if we failed 574 * @param my_identity ID of this peer, NULL if we failed
579 */ 575 */
580static void 576static void
581core_startup_cb (void *cls, 577core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
582 struct GNUNET_CORE_Handle * server,
583 const struct GNUNET_PeerIdentity *my_identity) 578 const struct GNUNET_PeerIdentity *my_identity)
584{ 579{
585 struct CacheEntry *entry = cls; 580 struct CacheEntry *entry = cls;
@@ -595,7 +590,7 @@ core_startup_cb (void *cls,
595 memcpy (entry->peer_identity, my_identity, 590 memcpy (entry->peer_identity, my_identity,
596 sizeof (struct GNUNET_PeerIdentity)); 591 sizeof (struct GNUNET_PeerIdentity));
597 if (0 == entry->demand) 592 if (0 == entry->demand)
598 return; 593 return;
599 if (GNUNET_SCHEDULER_NO_TASK != entry->notify_task) 594 if (GNUNET_SCHEDULER_NO_TASK != entry->notify_task)
600 return; 595 return;
601 if (NULL != search_suitable_cgh (entry, entry->cgh_qhead)) 596 if (NULL != search_suitable_cgh (entry, entry->cgh_qhead))
@@ -611,12 +606,11 @@ core_startup_cb (void *cls,
611 * @param atsi performance data for the connection 606 * @param atsi performance data for the connection
612 * @param atsi_count number of records in 'atsi' 607 * @param atsi_count number of records in 'atsi'
613 */ 608 */
614static void 609static void
615core_peer_connect_cb (void *cls, 610core_peer_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
616 const struct GNUNET_PeerIdentity * peer, 611 const struct GNUNET_ATS_Information *atsi,
617 const struct GNUNET_ATS_Information * atsi,
618 unsigned int atsi_count) 612 unsigned int atsi_count)
619{ 613{
620 peer_connect_notify_cb (cls, peer, CGT_CORE_HANDLE); 614 peer_connect_notify_cb (cls, peer, CGT_CORE_HANDLE);
621} 615}
622 616
@@ -631,6 +625,7 @@ static void
631opstart_get_handle_core (void *cls) 625opstart_get_handle_core (void *cls)
632{ 626{
633 struct CacheEntry *entry = cls; 627 struct CacheEntry *entry = cls;
628
634 const struct GNUNET_CORE_MessageHandler no_handlers[] = { 629 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
635 {NULL, 0, 0} 630 {NULL, 0, 0}
636 }; 631 };
@@ -638,17 +633,15 @@ opstart_get_handle_core (void *cls)
638 GNUNET_assert (NULL != entry); 633 GNUNET_assert (NULL != entry);
639 LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->peer_id); 634 LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->peer_id);
640 /* void?: We also get the handle when the connection to CORE is successful */ 635 /* void?: We also get the handle when the connection to CORE is successful */
641 (void) GNUNET_CORE_connect (entry->cfg, 636 (void) GNUNET_CORE_connect (entry->cfg, entry, /* closure */
642 entry, 637 &core_startup_cb, /* core startup notify */
643 &core_startup_cb, 638 &core_peer_connect_cb, /* peer connect notify */
644 &core_peer_connect_cb, 639 NULL, /* peer disconnect notify */
645 NULL, /* disconnect cb */ 640 NULL, /* inbound notify */
646 NULL, /* inbound notify */ 641 GNUNET_NO, /* inbound header only? */
647 GNUNET_NO, 642 NULL, /* outbound notify */
648 NULL, /* outbound notify */ 643 GNUNET_NO, /* outbound header only? */
649 GNUNET_NO,
650 no_handlers); 644 no_handlers);
651 //GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == entry->notify_task);
652} 645}
653 646
654 647
@@ -662,7 +655,7 @@ static void
662oprelease_get_handle_core (void *cls) 655oprelease_get_handle_core (void *cls)
663{ 656{
664 struct CacheEntry *entry = cls; 657 struct CacheEntry *entry = cls;
665 658
666 if (NULL == entry->core_handle) 659 if (NULL == entry->core_handle)
667 return; 660 return;
668 GNUNET_CORE_disconnect (entry->core_handle); 661 GNUNET_CORE_disconnect (entry->core_handle);
@@ -682,8 +675,7 @@ oprelease_get_handle_core (void *cls)
682 * @param cls the cache entry 675 * @param cls the cache entry
683 */ 676 */
684static struct GSTCacheGetHandle * 677static struct GSTCacheGetHandle *
685cache_get_handle (unsigned int peer_id, 678cache_get_handle (unsigned int peer_id, struct GSTCacheGetHandle *cgh,
686 struct GSTCacheGetHandle *cgh,
687 const struct GNUNET_CONFIGURATION_Handle *cfg, 679 const struct GNUNET_CONFIGURATION_Handle *cfg,
688 const struct GNUNET_PeerIdentity *target, 680 const struct GNUNET_PeerIdentity *target,
689 GST_cache_peer_connect_notify connect_notify_cb, 681 GST_cache_peer_connect_notify connect_notify_cb,
@@ -714,7 +706,8 @@ cache_get_handle (unsigned int peer_id,
714 case CGT_TRANSPORT_HANDLE: 706 case CGT_TRANSPORT_HANDLE:
715 handle = entry->transport_handle_; 707 handle = entry->transport_handle_;
716 if (NULL != handle) 708 if (NULL != handle)
717 LOG_DEBUG ("Found TRANSPORT handle in cache for peer %u\n", entry->peer_id); 709 LOG_DEBUG ("Found TRANSPORT handle in cache for peer %u\n",
710 entry->peer_id);
718 break; 711 break;
719 case CGT_CORE_HANDLE: 712 case CGT_CORE_HANDLE:
720 handle = entry->core_handle; 713 handle = entry->core_handle;
@@ -780,9 +773,7 @@ cache_get_handle (unsigned int peer_id,
780 * GNUNET_NO if not. 773 * GNUNET_NO if not.
781 */ 774 */
782static int 775static int
783cache_clear_iterator (void *cls, 776cache_clear_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
784 const struct GNUNET_HashCode * key,
785 void *value)
786{ 777{
787 struct CacheEntry *entry = value; 778 struct CacheEntry *entry = value;
788 static unsigned int ncleared; 779 static unsigned int ncleared;
@@ -862,12 +853,13 @@ GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh)
862 { 853 {
863 GNUNET_assert (cgh == cgh->nctxt->cgh); 854 GNUNET_assert (cgh == cgh->nctxt->cgh);
864 if (GNUNET_YES == cgh->notify_called) 855 if (GNUNET_YES == cgh->notify_called)
865 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, cgh->nctxt); 856 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail,
857 cgh->nctxt);
866 GNUNET_free (cgh->nctxt); 858 GNUNET_free (cgh->nctxt);
867 } 859 }
868 GNUNET_free (cgh); 860 GNUNET_free (cgh);
869 if (0 == entry->demand) 861 if (0 == entry->demand)
870 { 862 {
871 GNUNET_CONTAINER_DLL_insert_tail (lru_cache_head, lru_cache_tail, entry); 863 GNUNET_CONTAINER_DLL_insert_tail (lru_cache_head, lru_cache_tail, entry);
872 lru_cache_size++; 864 lru_cache_size++;
873 entry->in_lru = GNUNET_YES; 865 entry->in_lru = GNUNET_YES;
@@ -907,8 +899,7 @@ GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh)
907struct GSTCacheGetHandle * 899struct GSTCacheGetHandle *
908GST_cache_get_handle_transport (unsigned int peer_id, 900GST_cache_get_handle_transport (unsigned int peer_id,
909 const struct GNUNET_CONFIGURATION_Handle *cfg, 901 const struct GNUNET_CONFIGURATION_Handle *cfg,
910 GST_cache_handle_ready_cb cb, 902 GST_cache_handle_ready_cb cb, void *cb_cls,
911 void *cb_cls,
912 const struct GNUNET_PeerIdentity *target, 903 const struct GNUNET_PeerIdentity *target,
913 GST_cache_peer_connect_notify connect_notify_cb, 904 GST_cache_peer_connect_notify connect_notify_cb,
914 void *connect_notify_cb_cls) 905 void *connect_notify_cb_cls)
@@ -919,8 +910,8 @@ GST_cache_get_handle_transport (unsigned int peer_id,
919 cgh->cb = cb; 910 cgh->cb = cb;
920 cgh->cb_cls = cb_cls; 911 cgh->cb_cls = cb_cls;
921 cgh->type = CGT_TRANSPORT_HANDLE; 912 cgh->type = CGT_TRANSPORT_HANDLE;
922 return cache_get_handle (peer_id, cgh, cfg, 913 return cache_get_handle (peer_id, cgh, cfg, target, connect_notify_cb,
923 target, connect_notify_cb, connect_notify_cb_cls); 914 connect_notify_cb_cls);
924} 915}
925 916
926 917
@@ -948,8 +939,7 @@ GST_cache_get_handle_transport (unsigned int peer_id,
948struct GSTCacheGetHandle * 939struct GSTCacheGetHandle *
949GST_cache_get_handle_core (unsigned int peer_id, 940GST_cache_get_handle_core (unsigned int peer_id,
950 const struct GNUNET_CONFIGURATION_Handle *cfg, 941 const struct GNUNET_CONFIGURATION_Handle *cfg,
951 GST_cache_handle_ready_cb cb, 942 GST_cache_handle_ready_cb cb, void *cb_cls,
952 void *cb_cls,
953 const struct GNUNET_PeerIdentity *target, 943 const struct GNUNET_PeerIdentity *target,
954 GST_cache_peer_connect_notify connect_notify_cb, 944 GST_cache_peer_connect_notify connect_notify_cb,
955 void *connect_notify_cb_cls) 945 void *connect_notify_cb_cls)
@@ -960,8 +950,8 @@ GST_cache_get_handle_core (unsigned int peer_id,
960 cgh->cb = cb; 950 cgh->cb = cb;
961 cgh->cb_cls = cb_cls; 951 cgh->cb_cls = cb_cls;
962 cgh->type = CGT_CORE_HANDLE; 952 cgh->type = CGT_CORE_HANDLE;
963 return cache_get_handle (peer_id, cgh, cfg, 953 return cache_get_handle (peer_id, cgh, cfg, target, connect_notify_cb,
964 target, connect_notify_cb, connect_notify_cb_cls); 954 connect_notify_cb_cls);
965} 955}
966 956
967 957
@@ -976,7 +966,7 @@ GST_cache_lookup_hello (const unsigned int peer_id)
976{ 966{
977 struct CacheEntry *entry; 967 struct CacheEntry *entry;
978 struct GNUNET_HashCode key; 968 struct GNUNET_HashCode key;
979 969
980 LOG_DEBUG ("Looking up HELLO for peer %u\n", peer_id); 970 LOG_DEBUG ("Looking up HELLO for peer %u\n", peer_id);
981 GNUNET_CRYPTO_hash (&peer_id, sizeof (peer_id), &key); 971 GNUNET_CRYPTO_hash (&peer_id, sizeof (peer_id), &key);
982 entry = cache_lookup (&key); 972 entry = cache_lookup (&key);