diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-10-27 14:49:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-10-27 14:49:03 +0000 |
commit | 6b048559eadd3e57fda24a23d3f3b4681d4e1408 (patch) | |
tree | 88c6f0ab9f0dda3d090f95adfd365078e6ed3b1a /src/testbed/gnunet-service-testbed_connectionpool.c | |
parent | 57d4c0d631fc90945e92f264c841068a8be6565f (diff) | |
download | gnunet-6b048559eadd3e57fda24a23d3f3b4681d4e1408.tar.gz gnunet-6b048559eadd3e57fda24a23d3f3b4681d4e1408.zip |
prepare testbed for #3675 by having an option to establish connections to ATS
Diffstat (limited to 'src/testbed/gnunet-service-testbed_connectionpool.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_connectionpool.c | 113 |
1 files changed, 100 insertions, 13 deletions
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.c b/src/testbed/gnunet-service-testbed_connectionpool.c index 0f65edf15..4ca13ed42 100644 --- a/src/testbed/gnunet-service-testbed_connectionpool.c +++ b/src/testbed/gnunet-service-testbed_connectionpool.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2008--2015 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -79,6 +79,11 @@ struct PooledConnection | |||
79 | struct GNUNET_CORE_Handle *handle_core; | 79 | struct GNUNET_CORE_Handle *handle_core; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * The ATS handle to the peer correspondign to this entry; can be NULL. | ||
83 | */ | ||
84 | struct GNUNET_ATS_ConnectivityHandle *handle_ats_connectivity; | ||
85 | |||
86 | /** | ||
82 | * The operation handle for transport handle | 87 | * The operation handle for transport handle |
83 | */ | 88 | */ |
84 | struct GNUNET_TESTBED_Operation *op_transport; | 89 | struct GNUNET_TESTBED_Operation *op_transport; |
@@ -89,6 +94,11 @@ struct PooledConnection | |||
89 | struct GNUNET_TESTBED_Operation *op_core; | 94 | struct GNUNET_TESTBED_Operation *op_core; |
90 | 95 | ||
91 | /** | 96 | /** |
97 | * The operation handle for ATS handle | ||
98 | */ | ||
99 | struct GNUNET_TESTBED_Operation *op_ats_connectivity; | ||
100 | |||
101 | /** | ||
92 | * The peer identity of this peer. Will be set upon opening a connection to | 102 | * The peer identity of this peer. Will be set upon opening a connection to |
93 | * the peers CORE service. Will be NULL until then and after the CORE | 103 | * the peers CORE service. Will be NULL until then and after the CORE |
94 | * connection is closed | 104 | * connection is closed |
@@ -299,12 +309,20 @@ destroy_pooled_connection (struct PooledConnection *entry) | |||
299 | GNUNET_TESTBED_operation_done (entry->op_transport); | 309 | GNUNET_TESTBED_operation_done (entry->op_transport); |
300 | entry->op_transport = NULL; | 310 | entry->op_transport = NULL; |
301 | } | 311 | } |
312 | if (NULL != entry->handle_ats_connectivity) | ||
313 | GNUNET_assert (NULL != entry->op_ats_connectivity); | ||
314 | if (NULL != entry->op_ats_connectivity) | ||
315 | { | ||
316 | GNUNET_TESTBED_operation_done (entry->op_ats_connectivity); | ||
317 | entry->op_ats_connectivity = NULL; | ||
318 | } | ||
302 | if (NULL != entry->op_core) | 319 | if (NULL != entry->op_core) |
303 | { | 320 | { |
304 | GNUNET_TESTBED_operation_done (entry->op_core); | 321 | GNUNET_TESTBED_operation_done (entry->op_core); |
305 | entry->op_core = NULL; | 322 | entry->op_core = NULL; |
306 | } | 323 | } |
307 | GNUNET_assert (NULL == entry->handle_core); | 324 | GNUNET_assert (NULL == entry->handle_core); |
325 | GNUNET_assert (NULL == entry->handle_ats_connectivity); | ||
308 | GNUNET_assert (NULL == entry->handle_transport); | 326 | GNUNET_assert (NULL == entry->handle_transport); |
309 | GNUNET_CONFIGURATION_destroy (entry->cfg); | 327 | GNUNET_CONFIGURATION_destroy (entry->cfg); |
310 | GNUNET_free (entry); | 328 | GNUNET_free (entry); |
@@ -318,7 +336,8 @@ destroy_pooled_connection (struct PooledConnection *entry) | |||
318 | * @param tc scheduler task context | 336 | * @param tc scheduler task context |
319 | */ | 337 | */ |
320 | static void | 338 | static void |
321 | expire (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 339 | expire (void *cls, |
340 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
322 | { | 341 | { |
323 | struct PooledConnection *entry = cls; | 342 | struct PooledConnection *entry = cls; |
324 | 343 | ||
@@ -392,6 +411,10 @@ search_waiting (const struct PooledConnection *entry, | |||
392 | if (NULL == entry->handle_transport) | 411 | if (NULL == entry->handle_transport) |
393 | continue; | 412 | continue; |
394 | break; | 413 | break; |
414 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | ||
415 | if (NULL == entry->handle_ats_connectivity) | ||
416 | continue; | ||
417 | break; | ||
395 | } | 418 | } |
396 | break; | 419 | break; |
397 | } | 420 | } |
@@ -422,18 +445,27 @@ connection_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
422 | gh_next = NULL; | 445 | gh_next = NULL; |
423 | if (NULL != gh->next) | 446 | if (NULL != gh->next) |
424 | gh_next = search_waiting (entry, gh->next); | 447 | gh_next = search_waiting (entry, gh->next); |
425 | GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); | 448 | GNUNET_CONTAINER_DLL_remove (entry->head_waiting, |
449 | entry->tail_waiting, | ||
450 | gh); | ||
426 | gh->connection_ready_called = 1; | 451 | gh->connection_ready_called = 1; |
427 | if (NULL != gh_next) | 452 | if (NULL != gh_next) |
428 | entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); | 453 | entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, |
429 | if ( (NULL != gh->target) && (NULL != gh->connect_notify_cb) ) | 454 | entry); |
455 | if ( (NULL != gh->target) && | ||
456 | (NULL != gh->connect_notify_cb) ) | ||
430 | { | 457 | { |
431 | GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, entry->tail_notify, | 458 | GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, |
459 | entry->tail_notify, | ||
432 | gh); | 460 | gh); |
433 | gh->notify_waiting = 1; | 461 | gh->notify_waiting = 1; |
434 | } | 462 | } |
435 | LOG_DEBUG ("Connection ready for handle type %u\n", gh->service); | 463 | LOG_DEBUG ("Connection ready for handle type %u\n", |
436 | gh->cb (gh->cb_cls, entry->handle_core, entry->handle_transport, | 464 | gh->service); |
465 | gh->cb (gh->cb_cls, | ||
466 | entry->handle_core, | ||
467 | entry->handle_transport, | ||
468 | entry->handle_ats_connectivity, | ||
437 | entry->peer_identity); | 469 | entry->peer_identity); |
438 | } | 470 | } |
439 | 471 | ||
@@ -448,7 +480,8 @@ connection_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
448 | * @param service the service where this notification has originated | 480 | * @param service the service where this notification has originated |
449 | */ | 481 | */ |
450 | static void | 482 | static void |
451 | peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | 483 | peer_connect_notify_cb (void *cls, |
484 | const struct GNUNET_PeerIdentity *peer, | ||
452 | const enum GST_ConnectionPool_Service service) | 485 | const enum GST_ConnectionPool_Service service) |
453 | { | 486 | { |
454 | struct PooledConnection *entry = cls; | 487 | struct PooledConnection *entry = cls; |
@@ -467,7 +500,9 @@ peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
467 | gh = gh->next; | 500 | gh = gh->next; |
468 | continue; | 501 | continue; |
469 | } | 502 | } |
470 | if (0 != memcmp (gh->target, peer, sizeof (struct GNUNET_PeerIdentity))) | 503 | if (0 != memcmp (gh->target, |
504 | peer, | ||
505 | sizeof (struct GNUNET_PeerIdentity))) | ||
471 | { | 506 | { |
472 | gh = gh->next; | 507 | gh = gh->next; |
473 | continue; | 508 | continue; |
@@ -477,7 +512,9 @@ peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
477 | gh_next = gh->next; | 512 | gh_next = gh->next; |
478 | GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); | 513 | GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); |
479 | gh->notify_waiting = 0; | 514 | gh->notify_waiting = 0; |
480 | LOG_DEBUG ("Peer connected to peer %u at service %u\n", entry->index, gh->service); | 515 | LOG_DEBUG ("Peer connected to peer %u at service %u\n", |
516 | entry->index, | ||
517 | gh->service); | ||
481 | gh = gh_next; | 518 | gh = gh_next; |
482 | cb (cb_cls, peer); | 519 | cb (cb_cls, peer); |
483 | } | 520 | } |
@@ -497,7 +534,9 @@ transport_peer_connect_notify_cb (void *cls, | |||
497 | { | 534 | { |
498 | struct PooledConnection *entry = cls; | 535 | struct PooledConnection *entry = cls; |
499 | 536 | ||
500 | peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT); | 537 | peer_connect_notify_cb (entry, |
538 | peer, | ||
539 | GST_CONNECTIONPOOL_SERVICE_TRANSPORT); | ||
501 | } | 540 | } |
502 | 541 | ||
503 | 542 | ||
@@ -637,7 +676,7 @@ opstart_get_handle_core (void *cls) | |||
637 | 676 | ||
638 | 677 | ||
639 | /** | 678 | /** |
640 | * Function called when the operation responsible for opening a TRANSPORT | 679 | * Function called when the operation responsible for opening a CORE |
641 | * connection is marked as done. | 680 | * connection is marked as done. |
642 | * | 681 | * |
643 | * @param cls the #PooledConnection object | 682 | * @param cls the #PooledConnection object |
@@ -657,6 +696,40 @@ oprelease_get_handle_core (void *cls) | |||
657 | 696 | ||
658 | 697 | ||
659 | /** | 698 | /** |
699 | * Function called when resources for opening a connection to ATS are | ||
700 | * available. | ||
701 | * | ||
702 | * @param cls the #PooledConnection object | ||
703 | */ | ||
704 | static void | ||
705 | opstart_get_handle_ats_connectivity (void *cls) | ||
706 | { | ||
707 | struct PooledConnection *entry = cls; | ||
708 | |||
709 | entry->handle_ats_connectivity = | ||
710 | GNUNET_ATS_connectivity_init (entry->cfg); | ||
711 | } | ||
712 | |||
713 | |||
714 | /** | ||
715 | * Function called when the operation responsible for opening a ATS | ||
716 | * connection is marked as done. | ||
717 | * | ||
718 | * @param cls the #PooledConnection object | ||
719 | */ | ||
720 | static void | ||
721 | oprelease_get_handle_ats_connectivity (void *cls) | ||
722 | { | ||
723 | struct PooledConnection *entry = cls; | ||
724 | |||
725 | if (NULL == entry->handle_ats_connectivity) | ||
726 | return; | ||
727 | GNUNET_ATS_connectivity_done (entry->handle_ats_connectivity); | ||
728 | entry->handle_ats_connectivity = NULL; | ||
729 | } | ||
730 | |||
731 | |||
732 | /** | ||
660 | * This function will be called for every #PooledConnection object in @p map | 733 | * This function will be called for every #PooledConnection object in @p map |
661 | * | 734 | * |
662 | * @param cls NULL | 735 | * @param cls NULL |
@@ -798,6 +871,12 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
798 | LOG_DEBUG ("Found CORE handle for peer %u\n", | 871 | LOG_DEBUG ("Found CORE handle for peer %u\n", |
799 | entry->index); | 872 | entry->index); |
800 | break; | 873 | break; |
874 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | ||
875 | handle = entry->handle_ats_connectivity; | ||
876 | if (NULL != handle) | ||
877 | LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", | ||
878 | entry->index); | ||
879 | break; | ||
801 | } | 880 | } |
802 | } | 881 | } |
803 | else | 882 | else |
@@ -863,6 +942,14 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
863 | &oprelease_get_handle_core); | 942 | &oprelease_get_handle_core); |
864 | entry->op_core = op; | 943 | entry->op_core = op; |
865 | break; | 944 | break; |
945 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | ||
946 | if (NULL != entry->op_ats_connectivity) | ||
947 | return gh; /* Operation pending */ | ||
948 | op = GNUNET_TESTBED_operation_create_ (entry, | ||
949 | &opstart_get_handle_ats_connectivity, | ||
950 | &oprelease_get_handle_ats_connectivity); | ||
951 | entry->op_ats_connectivity = op; | ||
952 | break; | ||
866 | } | 953 | } |
867 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, | 954 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, |
868 | op); | 955 | op); |