aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/gnunet-service-testbed_connectionpool.c230
-rw-r--r--src/testbed/gnunet-service-testbed_connectionpool.h56
2 files changed, 132 insertions, 154 deletions
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.c b/src/testbed/gnunet-service-testbed_connectionpool.c
index d8461f8e2..e173a2349 100644
--- a/src/testbed/gnunet-service-testbed_connectionpool.c
+++ b/src/testbed/gnunet-service-testbed_connectionpool.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -27,7 +27,7 @@
27#include "gnunet-service-testbed.h" 27#include "gnunet-service-testbed.h"
28#include "gnunet-service-testbed_connectionpool.h" 28#include "gnunet-service-testbed_connectionpool.h"
29#include "testbed_api_operations.h" 29#include "testbed_api_operations.h"
30#include "gnunet_transport_core_service.h" 30#include "gnunet_transport_service.h"
31 31
32/** 32/**
33 * Redefine LOG with a changed log component string 33 * Redefine LOG with a changed log component string
@@ -35,14 +35,14 @@
35#ifdef LOG 35#ifdef LOG
36#undef LOG 36#undef LOG
37#endif 37#endif
38#define LOG(kind,...) \ 38#define LOG(kind, ...) \
39 GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__) 39 GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__)
40 40
41 41
42/** 42/**
43 * Time to expire a cache entry 43 * Time to expire a cache entry
44 */ 44 */
45#define CACHE_EXPIRY \ 45#define CACHE_EXPIRY \
46 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 46 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
47 47
48 48
@@ -107,8 +107,8 @@ struct PooledConnection
107 struct GNUNET_PeerIdentity *peer_identity; 107 struct GNUNET_PeerIdentity *peer_identity;
108 108
109 /** 109 /**
110 * The configuration of the peer. Should be not NULL as long as the core_handle 110 * The configuration of the peer. Should be not NULL as long as the
111 * or transport_handle are valid 111 * core_handle or transport_handle are valid
112 */ 112 */
113 struct GNUNET_CONFIGURATION_Handle *cfg; 113 struct GNUNET_CONFIGURATION_Handle *cfg;
114 114
@@ -137,12 +137,12 @@ struct PooledConnection
137 /** 137 /**
138 * The task to expire this connection from the connection pool 138 * The task to expire this connection from the connection pool
139 */ 139 */
140 struct GNUNET_SCHEDULER_Task * expire_task; 140 struct GNUNET_SCHEDULER_Task *expire_task;
141 141
142 /** 142 /**
143 * The task to notify a waiting #GST_ConnectionPool_GetHandle object 143 * The task to notify a waiting #GST_ConnectionPool_GetHandle object
144 */ 144 */
145 struct GNUNET_SCHEDULER_Task * notify_task; 145 struct GNUNET_SCHEDULER_Task *notify_task;
146 146
147 /** 147 /**
148 * Number of active requests using this pooled connection 148 * Number of active requests using this pooled connection
@@ -286,17 +286,16 @@ static void
286destroy_pooled_connection (struct PooledConnection *entry) 286destroy_pooled_connection (struct PooledConnection *entry)
287{ 287{
288 GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify)); 288 GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify));
289 GNUNET_assert ((NULL == entry->head_waiting) && (NULL == 289 GNUNET_assert ((NULL == entry->head_waiting) &&
290 entry->tail_waiting)); 290 (NULL == entry->tail_waiting));
291 GNUNET_assert (0 == entry->demand); 291 GNUNET_assert (0 == entry->demand);
292 expire_task_cancel (entry); 292 expire_task_cancel (entry);
293 if (entry->in_lru) 293 if (entry->in_lru)
294 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); 294 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
295 if (entry->in_pool) 295 if (entry->in_pool)
296 GNUNET_assert (GNUNET_OK == 296 GNUNET_assert (
297 GNUNET_CONTAINER_multihashmap32_remove (map, 297 GNUNET_OK ==
298 entry->index, 298 GNUNET_CONTAINER_multihashmap32_remove (map, entry->index, entry));
299 entry));
300 if (NULL != entry->notify_task) 299 if (NULL != entry->notify_task)
301 { 300 {
302 GNUNET_SCHEDULER_cancel (entry->notify_task); 301 GNUNET_SCHEDULER_cancel (entry->notify_task);
@@ -370,12 +369,12 @@ static void
370add_to_lru (struct PooledConnection *entry) 369add_to_lru (struct PooledConnection *entry)
371{ 370{
372 GNUNET_assert (0 == entry->demand); 371 GNUNET_assert (0 == entry->demand);
373 GNUNET_assert (!entry->in_lru); 372 GNUNET_assert (! entry->in_lru);
374 GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry); 373 GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry);
375 entry->in_lru = GNUNET_YES; 374 entry->in_lru = GNUNET_YES;
376 GNUNET_assert (NULL == entry->expire_task); 375 GNUNET_assert (NULL == entry->expire_task);
377 entry->expire_task = GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, 376 entry->expire_task =
378 &expire, entry); 377 GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire, entry);
379} 378}
380 379
381 380
@@ -404,7 +403,7 @@ search_waiting (const struct PooledConnection *entry,
404 if (NULL == entry->handle_core) 403 if (NULL == entry->handle_core)
405 continue; 404 continue;
406 if (NULL == entry->peer_identity) 405 if (NULL == entry->peer_identity)
407 continue; /* CORE connection isn't ready yet */ 406 continue; /* CORE connection isn't ready yet */
408 break; 407 break;
409 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 408 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
410 if (NULL == entry->handle_transport) 409 if (NULL == entry->handle_transport)
@@ -425,7 +424,8 @@ search_waiting (const struct PooledConnection *entry,
425 * A handle in the #PooledConnection object pointed by @a cls is ready and there 424 * A handle in the #PooledConnection object pointed by @a cls is ready and there
426 * is a #GST_ConnectionPool_GetHandle object waiting in the waiting list. This 425 * is a #GST_ConnectionPool_GetHandle object waiting in the waiting list. This
427 * function retrieves that object and calls the handle ready callback. It 426 * function retrieves that object and calls the handle ready callback. It
428 * further schedules itself if there are similar waiting objects which can be notified. 427 * further schedules itself if there are similar waiting objects which can be
428 * notified.
429 * 429 *
430 * @param cls the #PooledConnection object 430 * @param cls the #PooledConnection object
431 */ 431 */
@@ -443,23 +443,18 @@ connection_ready (void *cls)
443 gh_next = NULL; 443 gh_next = NULL;
444 if (NULL != gh->next) 444 if (NULL != gh->next)
445 gh_next = search_waiting (entry, gh->next); 445 gh_next = search_waiting (entry, gh->next);
446 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, 446 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
447 entry->tail_waiting,
448 gh);
449 gh->connection_ready_called = 1; 447 gh->connection_ready_called = 1;
450 if (NULL != gh_next) 448 if (NULL != gh_next)
451 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, 449 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
452 entry); 450 if ((NULL != gh->target) && (NULL != gh->connect_notify_cb))
453 if ( (NULL != gh->target) &&
454 (NULL != gh->connect_notify_cb) )
455 { 451 {
456 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, 452 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify,
457 entry->tail_notify, 453 entry->tail_notify,
458 gh); 454 gh);
459 gh->notify_waiting = 1; 455 gh->notify_waiting = 1;
460 } 456 }
461 LOG_DEBUG ("Connection ready for handle type %u\n", 457 LOG_DEBUG ("Connection ready for handle type %u\n", gh->service);
462 gh->service);
463 gh->cb (gh->cb_cls, 458 gh->cb (gh->cb_cls,
464 entry->handle_core, 459 entry->handle_core,
465 entry->handle_transport, 460 entry->handle_transport,
@@ -499,9 +494,7 @@ peer_connect_notify_cb (void *cls,
499 gh = gh->next; 494 gh = gh->next;
500 continue; 495 continue;
501 } 496 }
502 if (0 != memcmp (gh->target, 497 if (0 != memcmp (gh->target, peer, sizeof (struct GNUNET_PeerIdentity)))
503 peer,
504 sizeof (struct GNUNET_PeerIdentity)))
505 { 498 {
506 gh = gh->next; 499 gh = gh->next;
507 continue; 500 continue;
@@ -532,13 +525,11 @@ peer_connect_notify_cb (void *cls,
532static void * 525static void *
533transport_peer_connect_notify_cb (void *cls, 526transport_peer_connect_notify_cb (void *cls,
534 const struct GNUNET_PeerIdentity *peer, 527 const struct GNUNET_PeerIdentity *peer,
535 struct GNUNET_MQ_Handle *mq) 528 struct GNUNET_MQ_Handle *mq)
536{ 529{
537 struct PooledConnection *entry = cls; 530 struct PooledConnection *entry = cls;
538 531
539 peer_connect_notify_cb (entry, 532 peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT);
540 peer,
541 GST_CONNECTIONPOOL_SERVICE_TRANSPORT);
542 return NULL; 533 return NULL;
543} 534}
544 535
@@ -555,16 +546,15 @@ opstart_get_handle_transport (void *cls)
555 struct PooledConnection *entry = cls; 546 struct PooledConnection *entry = cls;
556 547
557 GNUNET_assert (NULL != entry); 548 GNUNET_assert (NULL != entry);
558 LOG_DEBUG ("Opening a transport connection to peer %u\n", 549 LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->index);
559 entry->index);
560 entry->handle_transport = 550 entry->handle_transport =
561 GNUNET_TRANSPORT_core_connect (entry->cfg, 551 GNUNET_TRANSPORT_core_connect (entry->cfg,
562 NULL, 552 NULL,
563 NULL, 553 NULL,
564 entry, 554 entry,
565 &transport_peer_connect_notify_cb, 555 &transport_peer_connect_notify_cb,
566 NULL, 556 NULL,
567 NULL); 557 NULL);
568 if (NULL == entry->handle_transport) 558 if (NULL == entry->handle_transport)
569 { 559 {
570 GNUNET_break (0); 560 GNUNET_break (0);
@@ -610,14 +600,12 @@ oprelease_get_handle_transport (void *cls)
610 */ 600 */
611static void * 601static void *
612core_peer_connect_cb (void *cls, 602core_peer_connect_cb (void *cls,
613 const struct GNUNET_PeerIdentity *peer, 603 const struct GNUNET_PeerIdentity *peer,
614 struct GNUNET_MQ_Handle *mq) 604 struct GNUNET_MQ_Handle *mq)
615{ 605{
616 struct PooledConnection *entry = cls; 606 struct PooledConnection *entry = cls;
617 607
618 peer_connect_notify_cb (entry, 608 peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE);
619 peer,
620 GST_CONNECTIONPOOL_SERVICE_CORE);
621 return (void *) peer; 609 return (void *) peer;
622} 610}
623 611
@@ -635,8 +623,7 @@ core_peer_connect_cb (void *cls,
635 * @param my_identity ID of this peer, NULL if we failed 623 * @param my_identity ID of this peer, NULL if we failed
636 */ 624 */
637static void 625static void
638core_startup_cb (void *cls, 626core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
639 const struct GNUNET_PeerIdentity *my_identity)
640{ 627{
641 struct PooledConnection *entry = cls; 628 struct PooledConnection *entry = cls;
642 629
@@ -672,15 +659,14 @@ opstart_get_handle_core (void *cls)
672 struct PooledConnection *entry = cls; 659 struct PooledConnection *entry = cls;
673 660
674 GNUNET_assert (NULL != entry); 661 GNUNET_assert (NULL != entry);
675 LOG_DEBUG ("Opening a CORE connection to peer %u\n", 662 LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->index);
676 entry->index); 663 entry->handle_core =
677 entry->handle_core 664 GNUNET_CORE_connect (entry->cfg,
678 = GNUNET_CORE_connect (entry->cfg, 665 entry, /* closure */
679 entry, /* closure */ 666 &core_startup_cb, /* core startup notify */
680 &core_startup_cb, /* core startup notify */ 667 &core_peer_connect_cb, /* peer connect notify */
681 &core_peer_connect_cb, /* peer connect notify */ 668 NULL, /* peer disconnect notify */
682 NULL, /* peer disconnect notify */ 669 NULL);
683 NULL);
684} 670}
685 671
686 672
@@ -715,8 +701,7 @@ opstart_get_handle_ats_connectivity (void *cls)
715{ 701{
716 struct PooledConnection *entry = cls; 702 struct PooledConnection *entry = cls;
717 703
718 entry->handle_ats_connectivity = 704 entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init (entry->cfg);
719 GNUNET_ATS_connectivity_init (entry->cfg);
720} 705}
721 706
722 707
@@ -749,9 +734,7 @@ oprelease_get_handle_ats_connectivity (void *cls)
749 * #GNUNET_NO if not. 734 * #GNUNET_NO if not.
750 */ 735 */
751static int 736static int
752cleanup_iterator (void *cls, 737cleanup_iterator (void *cls, uint32_t key, void *value)
753 uint32_t key,
754 void *value)
755{ 738{
756 struct PooledConnection *entry = value; 739 struct PooledConnection *entry = value;
757 740
@@ -789,10 +772,9 @@ GST_connection_pool_destroy ()
789 772
790 if (NULL != map) 773 if (NULL != map)
791 { 774 {
792 GNUNET_assert (GNUNET_SYSERR != 775 GNUNET_assert (
793 GNUNET_CONTAINER_multihashmap32_iterate (map, 776 GNUNET_SYSERR !=
794 &cleanup_iterator, 777 GNUNET_CONTAINER_multihashmap32_iterate (map, &cleanup_iterator, NULL));
795 NULL));
796 GNUNET_CONTAINER_multihashmap32_destroy (map); 778 GNUNET_CONTAINER_multihashmap32_destroy (map);
797 map = NULL; 779 map = NULL;
798 } 780 }
@@ -817,9 +799,9 @@ GST_connection_pool_destroy ()
817 * @note @a connect_notify_cb will not be called if @a target is 799 * @note @a connect_notify_cb will not be called if @a target is
818 * already connected @a service level. Use 800 * already connected @a service level. Use
819 * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the 801 * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the
820 * respective @a service's API to check if the target peer is already connected or 802 * respective @a service's API to check if the target peer is already connected
821 * not. @a connect_notify_cb will be called only once or never (in case @a target 803 * or not. @a connect_notify_cb will be called only once or never (in case @a
822 * cannot be connected or is already connected). 804 * target cannot be connected or is already connected).
823 * 805 *
824 * @param peer_id the index of the peer 806 * @param peer_id the index of the peer
825 * @param cfg the configuration with which the transport handle has to be 807 * @param cfg the configuration with which the transport handle has to be
@@ -828,7 +810,8 @@ GST_connection_pool_destroy ()
828 * @param cb the callback to notify when the transport handle is available 810 * @param cb the callback to notify when the transport handle is available
829 * @param cb_cls the closure for @a cb 811 * @param cb_cls the closure for @a cb
830 * @param target the peer identify of the peer whose connection to our TRANSPORT 812 * @param target the peer identify of the peer whose connection to our TRANSPORT
831 * subsystem will be notified through the @a connect_notify_cb. Can be NULL 813 * subsystem will be notified through the @a connect_notify_cb. Can be
814 * NULL
832 * @param connect_notify_cb the callback to call when the @a target peer is 815 * @param connect_notify_cb the callback to call when the @a target peer is
833 * connected. This callback will only be called once or never again (in 816 * connected. This callback will only be called once or never again (in
834 * case the target peer cannot be connected). Can be NULL 817 * case the target peer cannot be connected). Can be NULL
@@ -837,14 +820,15 @@ GST_connection_pool_destroy ()
837 * longer being used 820 * longer being used
838 */ 821 */
839struct GST_ConnectionPool_GetHandle * 822struct GST_ConnectionPool_GetHandle *
840GST_connection_pool_get_handle (unsigned int peer_id, 823GST_connection_pool_get_handle (
841 const struct GNUNET_CONFIGURATION_Handle *cfg, 824 unsigned int peer_id,
842 enum GST_ConnectionPool_Service service, 825 const struct GNUNET_CONFIGURATION_Handle *cfg,
843 GST_connection_pool_connection_ready_cb cb, 826 enum GST_ConnectionPool_Service service,
844 void *cb_cls, 827 GST_connection_pool_connection_ready_cb cb,
845 const struct GNUNET_PeerIdentity *target, 828 void *cb_cls,
846 GST_connection_pool_peer_connect_notify connect_notify_cb, 829 const struct GNUNET_PeerIdentity *target,
847 void *connect_notify_cb_cls) 830 GST_connection_pool_peer_connect_notify connect_notify_cb,
831 void *connect_notify_cb_cls)
848{ 832{
849 struct GST_ConnectionPool_GetHandle *gh; 833 struct GST_ConnectionPool_GetHandle *gh;
850 struct PooledConnection *entry; 834 struct PooledConnection *entry;
@@ -871,20 +855,17 @@ GST_connection_pool_get_handle (unsigned int peer_id,
871 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 855 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
872 handle = entry->handle_transport; 856 handle = entry->handle_transport;
873 if (NULL != handle) 857 if (NULL != handle)
874 LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", 858 LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", entry->index);
875 entry->index);
876 break; 859 break;
877 case GST_CONNECTIONPOOL_SERVICE_CORE: 860 case GST_CONNECTIONPOOL_SERVICE_CORE:
878 handle = entry->handle_core; 861 handle = entry->handle_core;
879 if (NULL != handle) 862 if (NULL != handle)
880 LOG_DEBUG ("Found CORE handle for peer %u\n", 863 LOG_DEBUG ("Found CORE handle for peer %u\n", entry->index);
881 entry->index);
882 break; 864 break;
883 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: 865 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
884 handle = entry->handle_ats_connectivity; 866 handle = entry->handle_ats_connectivity;
885 if (NULL != handle) 867 if (NULL != handle)
886 LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", 868 LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", entry->index);
887 entry->index);
888 break; 869 break;
889 } 870 }
890 } 871 }
@@ -892,14 +873,15 @@ GST_connection_pool_get_handle (unsigned int peer_id,
892 { 873 {
893 entry = GNUNET_new (struct PooledConnection); 874 entry = GNUNET_new (struct PooledConnection);
894 entry->index = peer_id32; 875 entry->index = peer_id32;
895 if ((NULL != map) 876 if ((NULL != map) &&
896 && (GNUNET_CONTAINER_multihashmap32_size (map) < max_size)) 877 (GNUNET_CONTAINER_multihashmap32_size (map) < max_size))
897 { 878 {
898 GNUNET_assert (GNUNET_OK == 879 GNUNET_assert (GNUNET_OK ==
899 GNUNET_CONTAINER_multihashmap32_put (map, 880 GNUNET_CONTAINER_multihashmap32_put (
900 entry->index, 881 map,
901 entry, 882 entry->index,
902 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 883 entry,
884 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
903 entry->in_pool = GNUNET_YES; 885 entry->in_pool = GNUNET_YES;
904 } 886 }
905 else 887 else
@@ -919,16 +901,14 @@ GST_connection_pool_get_handle (unsigned int peer_id,
919 gh->connect_notify_cb = connect_notify_cb; 901 gh->connect_notify_cb = connect_notify_cb;
920 gh->connect_notify_cb_cls = connect_notify_cb_cls; 902 gh->connect_notify_cb_cls = connect_notify_cb_cls;
921 gh->service = service; 903 gh->service = service;
922 GNUNET_CONTAINER_DLL_insert (entry->head_waiting, 904 GNUNET_CONTAINER_DLL_insert (entry->head_waiting, entry->tail_waiting, gh);
923 entry->tail_waiting,
924 gh);
925 if (NULL != handle) 905 if (NULL != handle)
926 { 906 {
927 if (NULL == entry->notify_task) 907 if (NULL == entry->notify_task)
928 { 908 {
929 if (NULL != search_waiting (entry, entry->head_waiting)) 909 if (NULL != search_waiting (entry, entry->head_waiting))
930 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, 910 entry->notify_task =
931 entry); 911 GNUNET_SCHEDULER_add_now (&connection_ready, entry);
932 } 912 }
933 return gh; 913 return gh;
934 } 914 }
@@ -937,7 +917,7 @@ GST_connection_pool_get_handle (unsigned int peer_id,
937 { 917 {
938 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 918 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
939 if (NULL != entry->op_transport) 919 if (NULL != entry->op_transport)
940 return gh; /* Operation pending */ 920 return gh; /* Operation pending */
941 op = GNUNET_TESTBED_operation_create_ (entry, 921 op = GNUNET_TESTBED_operation_create_ (entry,
942 &opstart_get_handle_transport, 922 &opstart_get_handle_transport,
943 &oprelease_get_handle_transport); 923 &oprelease_get_handle_transport);
@@ -945,7 +925,7 @@ GST_connection_pool_get_handle (unsigned int peer_id,
945 break; 925 break;
946 case GST_CONNECTIONPOOL_SERVICE_CORE: 926 case GST_CONNECTIONPOOL_SERVICE_CORE:
947 if (NULL != entry->op_core) 927 if (NULL != entry->op_core)
948 return gh; /* Operation pending */ 928 return gh; /* Operation pending */
949 op = GNUNET_TESTBED_operation_create_ (entry, 929 op = GNUNET_TESTBED_operation_create_ (entry,
950 &opstart_get_handle_core, 930 &opstart_get_handle_core,
951 &oprelease_get_handle_core); 931 &oprelease_get_handle_core);
@@ -953,15 +933,15 @@ GST_connection_pool_get_handle (unsigned int peer_id,
953 break; 933 break;
954 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: 934 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
955 if (NULL != entry->op_ats_connectivity) 935 if (NULL != entry->op_ats_connectivity)
956 return gh; /* Operation pending */ 936 return gh; /* Operation pending */
957 op = GNUNET_TESTBED_operation_create_ (entry, 937 op =
958 &opstart_get_handle_ats_connectivity, 938 GNUNET_TESTBED_operation_create_ (entry,
959 &oprelease_get_handle_ats_connectivity); 939 &opstart_get_handle_ats_connectivity,
940 &oprelease_get_handle_ats_connectivity);
960 entry->op_ats_connectivity = op; 941 entry->op_ats_connectivity = op;
961 break; 942 break;
962 } 943 }
963 GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, 944 GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op);
964 op);
965 GNUNET_TESTBED_operation_begin_wait_ (op); 945 GNUNET_TESTBED_operation_begin_wait_ (op);
966 return gh; 946 return gh;
967} 947}
@@ -973,9 +953,9 @@ GST_connection_pool_get_handle (unsigned int peer_id,
973 * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If 953 * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If
974 * no other objects are using the connection and the connection pool is not full 954 * no other objects are using the connection and the connection pool is not full
975 * then it is placed in a LRU queue. If the connection pool is full, then 955 * then it is placed in a LRU queue. If the connection pool is full, then
976 * connections from the LRU queue are evicted and closed to create place for this 956 * connections from the LRU queue are evicted and closed to create place for
977 * connection. If the connection pool if full and the LRU queue is empty, then 957 * this connection. If the connection pool if full and the LRU queue is empty,
978 * the connection is closed. 958 * then the connection is closed.
979 * 959 *
980 * @param gh the handle 960 * @param gh the handle
981 */ 961 */
@@ -989,14 +969,13 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
989 entry = gh->entry; 969 entry = gh->entry;
990 LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n", 970 LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n",
991 gh, 971 gh,
992 gh->service, entry->index); 972 gh->service,
973 entry->index);
993 if (! gh->connection_ready_called) 974 if (! gh->connection_ready_called)
994 { 975 {
995 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, 976 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
996 entry->tail_waiting, 977 if ((NULL == search_waiting (entry, entry->head_waiting)) &&
997 gh); 978 (NULL != entry->notify_task))
998 if ( (NULL == search_waiting (entry, entry->head_waiting)) &&
999 (NULL != entry->notify_task) )
1000 { 979 {
1001 GNUNET_SCHEDULER_cancel (entry->notify_task); 980 GNUNET_SCHEDULER_cancel (entry->notify_task);
1002 entry->notify_task = NULL; 981 entry->notify_task = NULL;
@@ -1004,22 +983,18 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
1004 } 983 }
1005 if (gh->notify_waiting) 984 if (gh->notify_waiting)
1006 { 985 {
1007 GNUNET_CONTAINER_DLL_remove (entry->head_notify, 986 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
1008 entry->tail_notify,
1009 gh);
1010 gh->notify_waiting = 0; 987 gh->notify_waiting = 0;
1011 } 988 }
1012 GNUNET_free (gh); 989 GNUNET_free (gh);
1013 gh = NULL; 990 gh = NULL;
1014 GNUNET_assert (! entry->in_lru); 991 GNUNET_assert (! entry->in_lru);
1015 if (! entry->in_pool) 992 if (! entry->in_pool)
1016 GNUNET_CONTAINER_DLL_remove (head_not_pooled, 993 GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry);
1017 tail_not_pooled,
1018 entry);
1019 if (NULL != map) 994 if (NULL != map)
1020 { 995 {
1021 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (map, 996 if (GNUNET_YES ==
1022 entry->index)) 997 GNUNET_CONTAINER_multihashmap32_contains (map, entry->index))
1023 goto unallocate; 998 goto unallocate;
1024 if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size) 999 if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size)
1025 { 1000 {
@@ -1028,14 +1003,15 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
1028 destroy_pooled_connection (head_lru); 1003 destroy_pooled_connection (head_lru);
1029 } 1004 }
1030 GNUNET_assert (GNUNET_OK == 1005 GNUNET_assert (GNUNET_OK ==
1031 GNUNET_CONTAINER_multihashmap32_put (map, 1006 GNUNET_CONTAINER_multihashmap32_put (
1032 entry->index, 1007 map,
1033 entry, 1008 entry->index,
1034 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1009 entry,
1010 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1035 entry->in_pool = GNUNET_YES; 1011 entry->in_pool = GNUNET_YES;
1036 } 1012 }
1037 1013
1038 unallocate: 1014unallocate:
1039 GNUNET_assert (0 < entry->demand); 1015 GNUNET_assert (0 < entry->demand);
1040 entry->demand--; 1016 entry->demand--;
1041 if (0 != entry->demand) 1017 if (0 != entry->demand)
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.h b/src/testbed/gnunet-service-testbed_connectionpool.h
index ca4ea22ce..558918c30 100644
--- a/src/testbed/gnunet-service-testbed_connectionpool.h
+++ b/src/testbed/gnunet-service-testbed_connectionpool.h
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -25,7 +25,7 @@
25 */ 25 */
26#include "gnunet_ats_service.h" 26#include "gnunet_ats_service.h"
27#include "gnunet_core_service.h" 27#include "gnunet_core_service.h"
28#include "gnunet_transport_core_service.h" 28#include "gnunet_transport_service.h"
29 29
30/** 30/**
31 * The request handle for obtaining a pooled connection 31 * The request handle for obtaining a pooled connection
@@ -87,13 +87,13 @@ GST_connection_pool_destroy (void);
87 * cases, its value being NULL means that CORE connection has failed. 87 * cases, its value being NULL means that CORE connection has failed.
88 * @param cfg configuration of the peer 88 * @param cfg configuration of the peer
89 */ 89 */
90typedef void 90typedef void (*GST_connection_pool_connection_ready_cb) (
91(*GST_connection_pool_connection_ready_cb) (void *cls, 91 void *cls,
92 struct GNUNET_CORE_Handle *ch, 92 struct GNUNET_CORE_Handle *ch,
93 struct GNUNET_TRANSPORT_CoreHandle *th, 93 struct GNUNET_TRANSPORT_CoreHandle *th,
94 struct GNUNET_ATS_ConnectivityHandle *ac, 94 struct GNUNET_ATS_ConnectivityHandle *ac,
95 const struct GNUNET_PeerIdentity *peer_id, 95 const struct GNUNET_PeerIdentity *peer_id,
96 const struct GNUNET_CONFIGURATION_Handle *cfg); 96 const struct GNUNET_CONFIGURATION_Handle *cfg);
97 97
98 98
99/** 99/**
@@ -104,9 +104,9 @@ typedef void
104 * callback 104 * callback
105 * @param target the peer identity of the target peer 105 * @param target the peer identity of the target peer
106 */ 106 */
107typedef void 107typedef void (*GST_connection_pool_peer_connect_notify) (
108(*GST_connection_pool_peer_connect_notify) (void *cls, 108 void *cls,
109 const struct GNUNET_PeerIdentity *target); 109 const struct GNUNET_PeerIdentity *target);
110 110
111 111
112/** 112/**
@@ -121,9 +121,9 @@ typedef void
121 * @note @a connect_notify_cb will not be called if @a target is 121 * @note @a connect_notify_cb will not be called if @a target is
122 * already connected @a service level. Use 122 * already connected @a service level. Use
123 * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the 123 * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the
124 * respective @a service's API to check if the target peer is already connected or 124 * respective @a service's API to check if the target peer is already connected
125 * not. @a connect_notify_cb will be called only once or never (in case @a target 125 * or not. @a connect_notify_cb will be called only once or never (in case @a
126 * cannot be connected or is already connected). 126 * target cannot be connected or is already connected).
127 * 127 *
128 * @param peer_id the index of the peer 128 * @param peer_id the index of the peer
129 * @param cfg the configuration with which the transport handle has to be 129 * @param cfg the configuration with which the transport handle has to be
@@ -132,7 +132,8 @@ typedef void
132 * @param cb the callback to notify when the transport handle is available 132 * @param cb the callback to notify when the transport handle is available
133 * @param cb_cls the closure for @a cb 133 * @param cb_cls the closure for @a cb
134 * @param target the peer identify of the peer whose connection to our TRANSPORT 134 * @param target the peer identify of the peer whose connection to our TRANSPORT
135 * subsystem will be notified through the @a connect_notify_cb. Can be NULL 135 * subsystem will be notified through the @a connect_notify_cb. Can be
136 * NULL
136 * @param connect_notify_cb the callback to call when the @a target peer is 137 * @param connect_notify_cb the callback to call when the @a target peer is
137 * connected. This callback will only be called once or never again (in 138 * connected. This callback will only be called once or never again (in
138 * case the target peer cannot be connected). Can be NULL 139 * case the target peer cannot be connected). Can be NULL
@@ -141,14 +142,15 @@ typedef void
141 * longer being used 142 * longer being used
142 */ 143 */
143struct GST_ConnectionPool_GetHandle * 144struct GST_ConnectionPool_GetHandle *
144GST_connection_pool_get_handle (unsigned int peer_id, 145GST_connection_pool_get_handle (
145 const struct GNUNET_CONFIGURATION_Handle *cfg, 146 unsigned int peer_id,
146 enum GST_ConnectionPool_Service service, 147 const struct GNUNET_CONFIGURATION_Handle *cfg,
147 GST_connection_pool_connection_ready_cb cb, 148 enum GST_ConnectionPool_Service service,
148 void *cb_cls, 149 GST_connection_pool_connection_ready_cb cb,
149 const struct GNUNET_PeerIdentity *target, 150 void *cb_cls,
150 GST_connection_pool_peer_connect_notify connect_notify_cb, 151 const struct GNUNET_PeerIdentity *target,
151 void *connect_notify_cb_cls); 152 GST_connection_pool_peer_connect_notify connect_notify_cb,
153 void *connect_notify_cb_cls);
152 154
153 155
154/** 156/**
@@ -157,9 +159,9 @@ GST_connection_pool_get_handle (unsigned int peer_id,
157 * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If 159 * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If
158 * no other objects are using the connection and the connection pool is not full 160 * no other objects are using the connection and the connection pool is not full
159 * then it is placed in a LRU queue. If the connection pool is full, then 161 * then it is placed in a LRU queue. If the connection pool is full, then
160 * connections from the LRU queue are evicted and closed to create place for this 162 * connections from the LRU queue are evicted and closed to create place for
161 * connection. If the connection pool if full and the LRU queue is empty, then 163 * this connection. If the connection pool if full and the LRU queue is empty,
162 * the connection is closed. 164 * then the connection is closed.
163 * 165 *
164 * @param gh the handle 166 * @param gh the handle
165 */ 167 */