diff options
Diffstat (limited to 'src/testbed/gnunet-service-testbed_links.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_links.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c index 69cc5dddd..0ee8c6385 100644 --- a/src/testbed/gnunet-service-testbed_links.c +++ b/src/testbed/gnunet-service-testbed_links.c | |||
@@ -180,13 +180,15 @@ struct Neighbour | |||
180 | GNUNET_SCHEDULER_TaskIdentifier notify_task; | 180 | GNUNET_SCHEDULER_TaskIdentifier notify_task; |
181 | 181 | ||
182 | unsigned int reference_cnt; | 182 | unsigned int reference_cnt; |
183 | |||
184 | unsigned int inactive; | ||
185 | |||
183 | 186 | ||
184 | /** | 187 | /** |
185 | * The id of the host this controller is running on | 188 | * The id of the host this controller is running on |
186 | */ | 189 | */ |
187 | uint32_t host_id; | 190 | uint32_t host_id; |
188 | 191 | ||
189 | int8_t inactive; | ||
190 | }; | 192 | }; |
191 | 193 | ||
192 | static struct Neighbour **neighbour_list; | 194 | static struct Neighbour **neighbour_list; |
@@ -753,7 +755,13 @@ trigger_notifications (struct Neighbour *n) | |||
753 | if (NULL == n->controller) | 755 | if (NULL == n->controller) |
754 | return; | 756 | return; |
755 | if (GNUNET_SCHEDULER_NO_TASK != n->notify_task) | 757 | if (GNUNET_SCHEDULER_NO_TASK != n->notify_task) |
756 | return; | 758 | return; |
759 | if (1 == n->inactive) | ||
760 | { | ||
761 | GNUNET_assert (0 == n->reference_cnt); | ||
762 | GNUNET_TESTBED_operation_activate_ (n->conn_op); | ||
763 | n->inactive = 0; | ||
764 | } | ||
757 | n->notify_task = | 765 | n->notify_task = |
758 | GNUNET_SCHEDULER_add_now (&neighbour_connect_notify_task, n->nl_head); | 766 | GNUNET_SCHEDULER_add_now (&neighbour_connect_notify_task, n->nl_head); |
759 | } | 767 | } |
@@ -771,11 +779,6 @@ neighbour_connect_notify_task (void *cls, | |||
771 | GNUNET_assert (NULL != n->controller); | 779 | GNUNET_assert (NULL != n->controller); |
772 | GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); | 780 | GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); |
773 | trigger_notifications (n); | 781 | trigger_notifications (n); |
774 | if ((0 == n->reference_cnt) && (1 == n->inactive)) | ||
775 | { | ||
776 | GNUNET_TESTBED_operation_activate_ (n->conn_op); | ||
777 | n->inactive = 0; | ||
778 | } | ||
779 | n->reference_cnt++; | 782 | n->reference_cnt++; |
780 | h->cb (h->cb_cls, n->controller); | 783 | h->cb (h->cb_cls, n->controller); |
781 | GNUNET_free (h); | 784 | GNUNET_free (h); |
@@ -804,10 +807,14 @@ oprelease_neighbour_conn (void *cls) | |||
804 | GNUNET_assert (0 == n->reference_cnt); | 807 | GNUNET_assert (0 == n->reference_cnt); |
805 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->notify_task); | 808 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->notify_task); |
806 | GNUNET_assert (NULL == n->nl_head); | 809 | GNUNET_assert (NULL == n->nl_head); |
807 | LOG_DEBUG ("Closing connection to controller on host %u\n", n->host_id); | 810 | if (NULL != n->controller) |
808 | GNUNET_TESTBED_controller_disconnect (n->controller); | 811 | { |
809 | n->controller = NULL; | 812 | LOG_DEBUG ("Closing connection to controller on host %u\n", n->host_id); |
813 | GNUNET_TESTBED_controller_disconnect (n->controller); | ||
814 | n->controller = NULL; | ||
815 | } | ||
810 | n->conn_op = NULL; | 816 | n->conn_op = NULL; |
817 | n->inactive = 0; | ||
811 | } | 818 | } |
812 | 819 | ||
813 | struct NeighbourConnectNotification * | 820 | struct NeighbourConnectNotification * |
@@ -842,15 +849,28 @@ void | |||
842 | GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h) | 849 | GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h) |
843 | { | 850 | { |
844 | struct Neighbour *n; | 851 | struct Neighbour *n; |
852 | int cleanup_task; | ||
845 | 853 | ||
854 | cleanup_task = (h == n->nl_head) ? GNUNET_YES : GNUNET_NO; | ||
846 | n = h->n; | 855 | n = h->n; |
847 | if ((h == n->nl_head) && (GNUNET_SCHEDULER_NO_TASK != n->notify_task)) | ||
848 | { | ||
849 | GNUNET_SCHEDULER_cancel (n->notify_task); | ||
850 | n->notify_task = GNUNET_SCHEDULER_NO_TASK; | ||
851 | } | ||
852 | GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); | 856 | GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); |
853 | GNUNET_free (h); | 857 | GNUNET_free (h); |
858 | if (GNUNET_NO == cleanup_task) | ||
859 | return; | ||
860 | if (GNUNET_SCHEDULER_NO_TASK == n->notify_task) | ||
861 | return; | ||
862 | GNUNET_SCHEDULER_cancel (n->notify_task); | ||
863 | n->notify_task = GNUNET_SCHEDULER_NO_TASK; | ||
864 | if (NULL == n->nl_head) | ||
865 | { | ||
866 | if ( (0 == n->reference_cnt) && (0 == n->inactive) ) | ||
867 | { | ||
868 | n->inactive = 1; | ||
869 | GNUNET_TESTBED_operation_inactivate_ (n->conn_op); | ||
870 | } | ||
871 | return; | ||
872 | } | ||
873 | trigger_notifications (n); | ||
854 | } | 874 | } |
855 | 875 | ||
856 | void | 876 | void |
@@ -861,8 +881,8 @@ GST_neighbour_release_connection (struct Neighbour *n) | |||
861 | n->reference_cnt--; | 881 | n->reference_cnt--; |
862 | if (0 == n->reference_cnt) | 882 | if (0 == n->reference_cnt) |
863 | { | 883 | { |
864 | GNUNET_TESTBED_operation_inactivate_ (n->conn_op); | ||
865 | n->inactive = 1; | 884 | n->inactive = 1; |
885 | GNUNET_TESTBED_operation_inactivate_ (n->conn_op); | ||
866 | } | 886 | } |
867 | } | 887 | } |
868 | 888 | ||