diff options
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/Makefile.am | 2 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed.h | 21 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_cache.c (renamed from src/testbed/gnunet-service-testbed_hc.c) | 102 |
3 files changed, 99 insertions, 26 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 7c6921c11..5977740c5 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -39,7 +39,7 @@ noinst_PROGRAMS = \ | |||
39 | gnunet_service_testbed_SOURCES = \ | 39 | gnunet_service_testbed_SOURCES = \ |
40 | gnunet-service-testbed.c \ | 40 | gnunet-service-testbed.c \ |
41 | gnunet-service-testbed.h \ | 41 | gnunet-service-testbed.h \ |
42 | gnunet-service-testbed_hc.c \ | 42 | gnunet-service-testbed_cache.c \ |
43 | gnunet-service-testbed_oc.c | 43 | gnunet-service-testbed_oc.c |
44 | gnunet_service_testbed_LDADD = $(XLIB) \ | 44 | gnunet_service_testbed_LDADD = $(XLIB) \ |
45 | $(top_builddir)/src/util/libgnunetutil.la \ | 45 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h index d4adf2526..7314122d3 100644 --- a/src/testbed/gnunet-service-testbed.h +++ b/src/testbed/gnunet-service-testbed.h | |||
@@ -803,17 +803,24 @@ GST_cache_add_hello (const unsigned int peer_id, | |||
803 | 803 | ||
804 | 804 | ||
805 | /** | 805 | /** |
806 | * Callback from cache with needed handles set | 806 | * Functions of this type are called when the needed handle is available for |
807 | * usage. These functions are to be registered with either of the functions | ||
808 | * GST_cache_get_handle_transport() or GST_cache_get_handle_core(). The | ||
809 | * corresponding handles will be set and if they are not, then it signals an | ||
810 | * error while opening the handles. | ||
807 | * | 811 | * |
808 | * @param cls the closure passed to GST_cache_get_handle_transport() | 812 | * @param cls the closure passed to GST_cache_get_handle_transport() or |
813 | * GST_cache_get_handle_core() | ||
809 | * @param ch the handle to CORE. Can be NULL if it is not requested | 814 | * @param ch the handle to CORE. Can be NULL if it is not requested |
810 | * @param th the handle to TRANSPORT. Can be NULL if it is not requested | 815 | * @param th the handle to TRANSPORT. Can be NULL if it is not requested |
811 | * @param peer_id the identity of the peer. Will be NULL if ch is NULL. In other | 816 | * @param peer_id the identity of the peer. Will be NULL if ch is NULL. In other |
812 | * cases, its value being NULL means that CORE connection has failed. | 817 | * cases, its value being NULL means that CORE connection has failed. |
813 | */ | 818 | */ |
814 | typedef void (*GST_cache_callback) (void *cls, struct GNUNET_CORE_Handle *ch, | 819 | typedef void (*GST_cache_handle_ready_cb) (void *cls, |
815 | struct GNUNET_TRANSPORT_Handle *th, | 820 | struct GNUNET_CORE_Handle *ch, |
816 | const struct GNUNET_PeerIdentity *peer_id); | 821 | struct GNUNET_TRANSPORT_Handle *th, |
822 | const struct | ||
823 | GNUNET_PeerIdentity *peer_id); | ||
817 | 824 | ||
818 | 825 | ||
819 | /** | 826 | /** |
@@ -855,7 +862,7 @@ typedef void (*GST_cache_peer_connect_notify) (void *cls, | |||
855 | struct GSTCacheGetHandle * | 862 | struct GSTCacheGetHandle * |
856 | GST_cache_get_handle_transport (unsigned int peer_id, | 863 | GST_cache_get_handle_transport (unsigned int peer_id, |
857 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 864 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
858 | GST_cache_callback cb, | 865 | GST_cache_handle_ready_cb cb, |
859 | void *cb_cls, | 866 | void *cb_cls, |
860 | const struct GNUNET_PeerIdentity *target, | 867 | const struct GNUNET_PeerIdentity *target, |
861 | GST_cache_peer_connect_notify connect_notify_cb, | 868 | GST_cache_peer_connect_notify connect_notify_cb, |
@@ -886,7 +893,7 @@ GST_cache_get_handle_transport (unsigned int peer_id, | |||
886 | struct GSTCacheGetHandle * | 893 | struct GSTCacheGetHandle * |
887 | GST_cache_get_handle_core (unsigned int peer_id, | 894 | GST_cache_get_handle_core (unsigned int peer_id, |
888 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 895 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
889 | GST_cache_callback cb, | 896 | GST_cache_handle_ready_cb cb, |
890 | void *cb_cls, | 897 | void *cb_cls, |
891 | const struct GNUNET_PeerIdentity *target, | 898 | const struct GNUNET_PeerIdentity *target, |
892 | GST_cache_peer_connect_notify connect_notify_cb, | 899 | GST_cache_peer_connect_notify connect_notify_cb, |
diff --git a/src/testbed/gnunet-service-testbed_hc.c b/src/testbed/gnunet-service-testbed_cache.c index 575032e56..f91e8c9d9 100644 --- a/src/testbed/gnunet-service-testbed_hc.c +++ b/src/testbed/gnunet-service-testbed_cache.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_hc.h | 22 | * @file testbed/gnunet-service-testbed_cache.h |
23 | * @brief testbed cache implementation | 23 | * @brief testbed cache implementation |
24 | * @author Sree Harsha Totakura | 24 | * @author Sree Harsha Totakura |
25 | */ | 25 | */ |
@@ -121,7 +121,7 @@ struct GSTCacheGetHandle | |||
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_callback 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 |
@@ -296,13 +296,18 @@ cache_lookup (const struct GNUNET_HashCode *key) | |||
296 | } | 296 | } |
297 | 297 | ||
298 | 298 | ||
299 | /** | ||
300 | * Function to disconnect the core and transport handles; free the existing | ||
301 | * configuration; and remove from the LRU cache list. The entry is left to be in | ||
302 | * the hash table so that the HELLO can still be found later | ||
303 | * | ||
304 | * @param entry the cache entry | ||
305 | */ | ||
299 | static void | 306 | static void |
300 | cache_remove (struct CacheEntry *entry) | 307 | close_handles (struct CacheEntry *entry) |
301 | { | 308 | { |
302 | struct ConnectNotifyContext *ctxt; | 309 | struct ConnectNotifyContext *ctxt; |
303 | 310 | ||
304 | /* We keep the entry in the hash table so that the HELLO can still be found | ||
305 | in cache; we will however disconnect the core and transport handles */ | ||
306 | GNUNET_assert (0 == entry->demand); | 311 | GNUNET_assert (0 == entry->demand); |
307 | if ((NULL != entry->next) || (NULL != entry->prev)) | 312 | if ((NULL != entry->next) || (NULL != entry->prev)) |
308 | { | 313 | { |
@@ -336,6 +341,13 @@ cache_remove (struct CacheEntry *entry) | |||
336 | } | 341 | } |
337 | 342 | ||
338 | 343 | ||
344 | /** | ||
345 | * Creates a new cache entry and then puts it into the cache's hashtable. | ||
346 | * | ||
347 | * @param key the hash code to use for inserting the newly created entry | ||
348 | * @param peer_id the index of the peer to tag the newly created entry | ||
349 | * @return the newly created entry | ||
350 | */ | ||
339 | static struct CacheEntry * | 351 | static struct CacheEntry * |
340 | add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id) | 352 | add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id) |
341 | { | 353 | { |
@@ -353,6 +365,17 @@ add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id) | |||
353 | } | 365 | } |
354 | 366 | ||
355 | 367 | ||
368 | /** | ||
369 | * Function to find a suitable GSTCacheGetHandle which is waiting for one of the | ||
370 | * handles in given entry to be available. | ||
371 | * | ||
372 | * @param entry the cache entry whose GSTCacheGetHandle list has to be searched | ||
373 | * @param head the starting list element in the GSTCacheGetHandle where the | ||
374 | * search has to be begin | ||
375 | * @return a suitable GSTCacheGetHandle whose handle ready notify callback | ||
376 | * hasn't been called yet. NULL if no such suitable GSTCacheGetHandle | ||
377 | * is found | ||
378 | */ | ||
356 | static struct GSTCacheGetHandle * | 379 | static struct GSTCacheGetHandle * |
357 | search_suitable_cgh (const struct CacheEntry *entry, | 380 | search_suitable_cgh (const struct CacheEntry *entry, |
358 | const struct GSTCacheGetHandle *head) | 381 | const struct GSTCacheGetHandle *head) |
@@ -380,6 +403,13 @@ search_suitable_cgh (const struct CacheEntry *entry, | |||
380 | } | 403 | } |
381 | 404 | ||
382 | 405 | ||
406 | /** | ||
407 | * Task to call the handle ready notify callback of a queued GSTCacheGetHandle | ||
408 | * of an entry when one or all of its handles are available. | ||
409 | * | ||
410 | * @param cls the cache entry | ||
411 | * @param tc the task context from scheduler | ||
412 | */ | ||
383 | static void | 413 | static void |
384 | call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 414 | call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
385 | { | 415 | { |
@@ -409,13 +439,15 @@ call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
409 | entry->transport_handle_, entry->peer_identity); | 439 | entry->transport_handle_, entry->peer_identity); |
410 | } | 440 | } |
411 | 441 | ||
442 | |||
412 | /** | 443 | /** |
413 | * Function called to notify transport users that another | 444 | * Function called from peer connect notify callbacks from CORE and TRANSPORT |
414 | * peer connected to us. | 445 | * connections. This function calls the pendning peer connect notify callbacks |
446 | * which are queued in an entry. | ||
415 | * | 447 | * |
416 | * @param cls closure | 448 | * @param cls the cache entry |
417 | * @param peer the peer that connected | 449 | * @param peer the peer that connected |
418 | * @param type the type of the handle this notification is for | 450 | * @param type the type of the handle this notification corresponds to |
419 | */ | 451 | */ |
420 | static void | 452 | static void |
421 | peer_connect_notify_cb (void *cls, | 453 | peer_connect_notify_cb (void *cls, |
@@ -476,6 +508,12 @@ transport_peer_connect_notify_cb (void *cls, | |||
476 | } | 508 | } |
477 | 509 | ||
478 | 510 | ||
511 | /** | ||
512 | * Function called when resources for opening a connection to TRANSPORT are | ||
513 | * available. | ||
514 | * | ||
515 | * @param cls the cache entry | ||
516 | */ | ||
479 | static void | 517 | static void |
480 | opstart_get_handle_transport (void *cls) | 518 | opstart_get_handle_transport (void *cls) |
481 | { | 519 | { |
@@ -501,6 +539,12 @@ opstart_get_handle_transport (void *cls) | |||
501 | } | 539 | } |
502 | 540 | ||
503 | 541 | ||
542 | /** | ||
543 | * Function called when the operation responsible for opening a TRANSPORT | ||
544 | * connection is marked as done. | ||
545 | * | ||
546 | * @param cls the cache entry | ||
547 | */ | ||
504 | static void | 548 | static void |
505 | oprelease_get_handle_transport (void *cls) | 549 | oprelease_get_handle_transport (void *cls) |
506 | { | 550 | { |
@@ -551,7 +595,7 @@ core_startup_cb (void *cls, | |||
551 | 595 | ||
552 | 596 | ||
553 | /** | 597 | /** |
554 | * Method called whenever a given peer connects. | 598 | * Method called whenever a given peer connects at CORE level |
555 | * | 599 | * |
556 | * @param cls closure | 600 | * @param cls closure |
557 | * @param peer peer identity this notification is about | 601 | * @param peer peer identity this notification is about |
@@ -568,6 +612,12 @@ core_peer_connect_cb (void *cls, | |||
568 | } | 612 | } |
569 | 613 | ||
570 | 614 | ||
615 | /** | ||
616 | * Function called when resources for opening a connection to CORE are | ||
617 | * available. | ||
618 | * | ||
619 | * @param cls the cache entry | ||
620 | */ | ||
571 | static void | 621 | static void |
572 | opstart_get_handle_core (void *cls) | 622 | opstart_get_handle_core (void *cls) |
573 | { | 623 | { |
@@ -593,6 +643,12 @@ opstart_get_handle_core (void *cls) | |||
593 | } | 643 | } |
594 | 644 | ||
595 | 645 | ||
646 | /** | ||
647 | * Function called when the operation responsible for opening a TRANSPORT | ||
648 | * connection is marked as done. | ||
649 | * | ||
650 | * @param cls the cache entry | ||
651 | */ | ||
596 | static void | 652 | static void |
597 | oprelease_get_handle_core (void *cls) | 653 | oprelease_get_handle_core (void *cls) |
598 | { | 654 | { |
@@ -607,6 +663,15 @@ oprelease_get_handle_core (void *cls) | |||
607 | } | 663 | } |
608 | 664 | ||
609 | 665 | ||
666 | /** | ||
667 | * Function to get a handle with given configuration. The type of the handle is | ||
668 | * implicitly provided in the GSTCacheGetHandle. If the handle is already cached | ||
669 | * before, it will be retured in the given callback; the peer_id is used to | ||
670 | * lookup in the cache; if not, a new operation is started to open the transport | ||
671 | * handle and will be given in the callback when it is available. | ||
672 | * | ||
673 | * @param cls the cache entry | ||
674 | */ | ||
610 | static struct GSTCacheGetHandle * | 675 | static struct GSTCacheGetHandle * |
611 | cache_get_handle (unsigned int peer_id, | 676 | cache_get_handle (unsigned int peer_id, |
612 | struct GSTCacheGetHandle *cgh, | 677 | struct GSTCacheGetHandle *cgh, |
@@ -692,6 +757,7 @@ cache_get_handle (unsigned int peer_id, | |||
692 | return cgh; | 757 | return cgh; |
693 | } | 758 | } |
694 | 759 | ||
760 | |||
695 | /** | 761 | /** |
696 | * Iterator over hash map entries. | 762 | * Iterator over hash map entries. |
697 | * | 763 | * |
@@ -715,7 +781,7 @@ cache_clear_iterator (void *cls, | |||
715 | LOG_DEBUG ("Clearing entry %u of %u\n", ++ncleared, cache_size); | 781 | LOG_DEBUG ("Clearing entry %u of %u\n", ++ncleared, cache_size); |
716 | GNUNET_CONTAINER_multihashmap_remove (cache, key, value); | 782 | GNUNET_CONTAINER_multihashmap_remove (cache, key, value); |
717 | if (0 == entry->demand) | 783 | if (0 == entry->demand) |
718 | cache_remove (entry); | 784 | close_handles (entry); |
719 | GNUNET_free_non_null (entry->hello); | 785 | GNUNET_free_non_null (entry->hello); |
720 | GNUNET_break (NULL == entry->transport_handle_); | 786 | GNUNET_break (NULL == entry->transport_handle_); |
721 | GNUNET_break (NULL == entry->transport_op_); | 787 | GNUNET_break (NULL == entry->transport_op_); |
@@ -794,7 +860,7 @@ GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh) | |||
794 | GNUNET_CONTAINER_DLL_insert_tail (lru_cache_head, lru_cache_tail, entry); | 860 | GNUNET_CONTAINER_DLL_insert_tail (lru_cache_head, lru_cache_tail, entry); |
795 | lru_cache_size++; | 861 | lru_cache_size++; |
796 | if (lru_cache_size > lru_cache_threshold_size) | 862 | if (lru_cache_size > lru_cache_threshold_size) |
797 | cache_remove (lru_cache_head); | 863 | close_handles (lru_cache_head); |
798 | } | 864 | } |
799 | else | 865 | else |
800 | { | 866 | { |
@@ -807,10 +873,10 @@ GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh) | |||
807 | 873 | ||
808 | 874 | ||
809 | /** | 875 | /** |
810 | * Get a transport handle with the given configuration. If the handle is already | 876 | * Get a transport handle with the given configuration. If the handle is |
811 | * cached before, it will be retured in the given callback; the peer_id is used to lookup in the | 877 | * already cached before, it will be retured in the given callback; the peer_id |
812 | * cache. If not a new operation is started to open the transport handle and | 878 | * is used to lookup in the cache; if not, a new operation is started to open the |
813 | * will be given in the callback when it is available. | 879 | * transport handle and will be given in the callback when it is available. |
814 | * | 880 | * |
815 | * @param peer_id the index of the peer | 881 | * @param peer_id the index of the peer |
816 | * @param cfg the configuration with which the transport handle has to be | 882 | * @param cfg the configuration with which the transport handle has to be |
@@ -829,7 +895,7 @@ GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh) | |||
829 | struct GSTCacheGetHandle * | 895 | struct GSTCacheGetHandle * |
830 | GST_cache_get_handle_transport (unsigned int peer_id, | 896 | GST_cache_get_handle_transport (unsigned int peer_id, |
831 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 897 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
832 | GST_cache_callback cb, | 898 | GST_cache_handle_ready_cb cb, |
833 | void *cb_cls, | 899 | void *cb_cls, |
834 | const struct GNUNET_PeerIdentity *target, | 900 | const struct GNUNET_PeerIdentity *target, |
835 | GST_cache_peer_connect_notify connect_notify_cb, | 901 | GST_cache_peer_connect_notify connect_notify_cb, |
@@ -870,7 +936,7 @@ GST_cache_get_handle_transport (unsigned int peer_id, | |||
870 | struct GSTCacheGetHandle * | 936 | struct GSTCacheGetHandle * |
871 | GST_cache_get_handle_core (unsigned int peer_id, | 937 | GST_cache_get_handle_core (unsigned int peer_id, |
872 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 938 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
873 | GST_cache_callback cb, | 939 | GST_cache_handle_ready_cb cb, |
874 | void *cb_cls, | 940 | void *cb_cls, |
875 | const struct GNUNET_PeerIdentity *target, | 941 | const struct GNUNET_PeerIdentity *target, |
876 | GST_cache_peer_connect_notify connect_notify_cb, | 942 | GST_cache_peer_connect_notify connect_notify_cb, |