diff options
Diffstat (limited to 'src/transport/gnunet-service-tng.c')
-rw-r--r-- | src/transport/gnunet-service-tng.c | 93 |
1 files changed, 77 insertions, 16 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index f57d08395..3cba49250 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -2772,6 +2772,11 @@ static unsigned int pa_count; | |||
2772 | */ | 2772 | */ |
2773 | static struct GNUNET_TIME_Absolute hello_mono_time; | 2773 | static struct GNUNET_TIME_Absolute hello_mono_time; |
2774 | 2774 | ||
2775 | /** | ||
2776 | * Indication if we have received a shutdown signal | ||
2777 | * and are in the process of cleaning up. | ||
2778 | */ | ||
2779 | static int in_shutdown; | ||
2775 | 2780 | ||
2776 | /** | 2781 | /** |
2777 | * Get an offset into the transmission history buffer for `struct | 2782 | * Get an offset into the transmission history buffer for `struct |
@@ -2805,6 +2810,7 @@ free_incoming_request (struct IncomingRequest *ir) | |||
2805 | GNUNET_assert (ir_total > 0); | 2810 | GNUNET_assert (ir_total > 0); |
2806 | ir_total--; | 2811 | ir_total--; |
2807 | GNUNET_PEERSTORE_watch_cancel (ir->wc); | 2812 | GNUNET_PEERSTORE_watch_cancel (ir->wc); |
2813 | ir->wc = NULL; | ||
2808 | GNUNET_free (ir); | 2814 | GNUNET_free (ir); |
2809 | } | 2815 | } |
2810 | 2816 | ||
@@ -3333,6 +3339,8 @@ free_neighbour (struct Neighbour *neighbour) | |||
3333 | GNUNET_CONTAINER_multipeermap_remove (neighbours, | 3339 | GNUNET_CONTAINER_multipeermap_remove (neighbours, |
3334 | &neighbour->pid, | 3340 | &neighbour->pid, |
3335 | neighbour)); | 3341 | neighbour)); |
3342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3343 | "Freeing neighbour\n"); | ||
3336 | if (NULL != neighbour->reassembly_map) | 3344 | if (NULL != neighbour->reassembly_map) |
3337 | { | 3345 | { |
3338 | GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map, | 3346 | GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map, |
@@ -3499,6 +3507,8 @@ check_link_down (void *cls) | |||
3499 | struct GNUNET_TIME_Absolute dvh_timeout; | 3507 | struct GNUNET_TIME_Absolute dvh_timeout; |
3500 | struct GNUNET_TIME_Absolute q_timeout; | 3508 | struct GNUNET_TIME_Absolute q_timeout; |
3501 | 3509 | ||
3510 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3511 | "Checking if link is down\n"); | ||
3502 | vl->visibility_task = NULL; | 3512 | vl->visibility_task = NULL; |
3503 | dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS; | 3513 | dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS; |
3504 | if (NULL != dv) | 3514 | if (NULL != dv) |
@@ -3660,6 +3670,7 @@ stop_peer_request (void *cls, | |||
3660 | struct PeerRequest *pr = value; | 3670 | struct PeerRequest *pr = value; |
3661 | 3671 | ||
3662 | GNUNET_PEERSTORE_watch_cancel (pr->wc); | 3672 | GNUNET_PEERSTORE_watch_cancel (pr->wc); |
3673 | pr->wc = NULL; | ||
3663 | GNUNET_assert ( | 3674 | GNUNET_assert ( |
3664 | GNUNET_YES == | 3675 | GNUNET_YES == |
3665 | GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, | 3676 | GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, |
@@ -3671,6 +3682,9 @@ stop_peer_request (void *cls, | |||
3671 | } | 3682 | } |
3672 | 3683 | ||
3673 | 3684 | ||
3685 | static void | ||
3686 | do_shutdown (void *cls); | ||
3687 | |||
3674 | /** | 3688 | /** |
3675 | * Called whenever a client is disconnected. Frees our | 3689 | * Called whenever a client is disconnected. Frees our |
3676 | * resources associated with that client. | 3690 | * resources associated with that client. |
@@ -3688,16 +3702,20 @@ client_disconnect_cb (void *cls, | |||
3688 | 3702 | ||
3689 | (void) cls; | 3703 | (void) cls; |
3690 | (void) client; | 3704 | (void) client; |
3691 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3692 | "Client %p disconnected, cleaning up.\n", | ||
3693 | tc); | ||
3694 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); | 3705 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); |
3695 | switch (tc->type) | 3706 | switch (tc->type) |
3696 | { | 3707 | { |
3697 | case CT_NONE: | 3708 | case CT_NONE: |
3709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3710 | "Unknown Client %p disconnected, cleaning up.\n", | ||
3711 | tc); | ||
3698 | break; | 3712 | break; |
3699 | 3713 | ||
3700 | case CT_CORE: { | 3714 | case CT_CORE: { |
3715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3716 | "CORE Client %p disconnected, cleaning up.\n", | ||
3717 | tc); | ||
3718 | |||
3701 | struct PendingMessage *pm; | 3719 | struct PendingMessage *pm; |
3702 | 3720 | ||
3703 | while (NULL != (pm = tc->details.core.pending_msg_head)) | 3721 | while (NULL != (pm = tc->details.core.pending_msg_head)) |
@@ -3712,9 +3730,17 @@ client_disconnect_cb (void *cls, | |||
3712 | break; | 3730 | break; |
3713 | 3731 | ||
3714 | case CT_MONITOR: | 3732 | case CT_MONITOR: |
3733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3734 | "MONITOR Client %p disconnected, cleaning up.\n", | ||
3735 | tc); | ||
3736 | |||
3715 | break; | 3737 | break; |
3716 | 3738 | ||
3717 | case CT_COMMUNICATOR: { | 3739 | case CT_COMMUNICATOR: { |
3740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3741 | "COMMUNICATOR Client %p disconnected, cleaning up.\n", | ||
3742 | tc); | ||
3743 | |||
3718 | struct Queue *q; | 3744 | struct Queue *q; |
3719 | struct AddressListEntry *ale; | 3745 | struct AddressListEntry *ale; |
3720 | 3746 | ||
@@ -3727,6 +3753,10 @@ client_disconnect_cb (void *cls, | |||
3727 | break; | 3753 | break; |
3728 | 3754 | ||
3729 | case CT_APPLICATION: | 3755 | case CT_APPLICATION: |
3756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3757 | "APPLICATION Client %p disconnected, cleaning up.\n", | ||
3758 | tc); | ||
3759 | |||
3730 | GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, | 3760 | GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, |
3731 | &stop_peer_request, | 3761 | &stop_peer_request, |
3732 | tc); | 3762 | tc); |
@@ -3734,6 +3764,12 @@ client_disconnect_cb (void *cls, | |||
3734 | break; | 3764 | break; |
3735 | } | 3765 | } |
3736 | GNUNET_free (tc); | 3766 | GNUNET_free (tc); |
3767 | if ((GNUNET_YES == in_shutdown) && (NULL == clients_head)) | ||
3768 | { | ||
3769 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3770 | "Our last client disconnected\n"); | ||
3771 | do_shutdown (cls); | ||
3772 | } | ||
3737 | } | 3773 | } |
3738 | 3774 | ||
3739 | 3775 | ||
@@ -4163,7 +4199,6 @@ queue_send_msg (struct Queue *queue, | |||
4163 | struct GNUNET_TRANSPORT_SendMessageTo *smt; | 4199 | struct GNUNET_TRANSPORT_SendMessageTo *smt; |
4164 | struct GNUNET_MQ_Envelope *env; | 4200 | struct GNUNET_MQ_Envelope *env; |
4165 | 4201 | ||
4166 | // queue->idle = GNUNET_NO; | ||
4167 | GNUNET_log ( | 4202 | GNUNET_log ( |
4168 | GNUNET_ERROR_TYPE_DEBUG, | 4203 | GNUNET_ERROR_TYPE_DEBUG, |
4169 | "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n", | 4204 | "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n", |
@@ -5164,9 +5199,12 @@ handle_del_address (void *cls, | |||
5164 | ale->address); | 5199 | ale->address); |
5165 | free_address_list_entry (ale); | 5200 | free_address_list_entry (ale); |
5166 | GNUNET_SERVICE_client_continue (tc->client); | 5201 | GNUNET_SERVICE_client_continue (tc->client); |
5202 | return; | ||
5167 | } | 5203 | } |
5168 | GNUNET_break (0); | 5204 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5169 | GNUNET_SERVICE_client_drop (tc->client); | 5205 | "Communicator removed address we did not even have.\n"); |
5206 | GNUNET_SERVICE_client_continue (tc->client); | ||
5207 | // GNUNET_SERVICE_client_drop (tc->client); | ||
5170 | } | 5208 | } |
5171 | 5209 | ||
5172 | 5210 | ||
@@ -8832,6 +8870,8 @@ transmit_on_queue (void *cls) | |||
8832 | queue->idle = GNUNET_YES; | 8870 | queue->idle = GNUNET_YES; |
8833 | return; | 8871 | return; |
8834 | } | 8872 | } |
8873 | /* There is a message pending, we are certainly not idle */ | ||
8874 | queue->idle = GNUNET_NO; | ||
8835 | 8875 | ||
8836 | /* Given selection in `sc`, do transmission */ | 8876 | /* Given selection in `sc`, do transmission */ |
8837 | pm = sc.best; | 8877 | pm = sc.best; |
@@ -8940,7 +8980,8 @@ transmit_on_queue (void *cls) | |||
8940 | 8980 | ||
8941 | OPTIMIZE: Note that in the future this heuristic should likely | 8981 | OPTIMIZE: Note that in the future this heuristic should likely |
8942 | be improved further (measure RTT stability, consider message | 8982 | be improved further (measure RTT stability, consider message |
8943 | urgency and size when delaying ACKs, etc.) */update_pm_next_attempt (pm, | 8983 | urgency and size when delaying ACKs, etc.) */ |
8984 | update_pm_next_attempt (pm, | ||
8944 | GNUNET_TIME_relative_to_absolute ( | 8985 | GNUNET_TIME_relative_to_absolute ( |
8945 | GNUNET_TIME_relative_multiply (queue->pd.aged_rtt, | 8986 | GNUNET_TIME_relative_multiply (queue->pd.aged_rtt, |
8946 | 4))); | 8987 | 4))); |
@@ -9072,7 +9113,6 @@ handle_send_message_ack (void *cls, | |||
9072 | NULL != queue; | 9113 | NULL != queue; |
9073 | queue = queue->next_client) | 9114 | queue = queue->next_client) |
9074 | { | 9115 | { |
9075 | queue->idle = GNUNET_YES; | ||
9076 | schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); | 9116 | schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); |
9077 | } | 9117 | } |
9078 | } | 9118 | } |
@@ -9083,7 +9123,6 @@ handle_send_message_ack (void *cls, | |||
9083 | "# Transmission throttled due to queue queue limit", | 9123 | "# Transmission throttled due to queue queue limit", |
9084 | -1, | 9124 | -1, |
9085 | GNUNET_NO); | 9125 | GNUNET_NO); |
9086 | qe->queue->idle = GNUNET_YES; | ||
9087 | schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); | 9126 | schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); |
9088 | } | 9127 | } |
9089 | 9128 | ||
@@ -10058,13 +10097,17 @@ do_shutdown (void *cls) | |||
10058 | struct LearnLaunchEntry *lle; | 10097 | struct LearnLaunchEntry *lle; |
10059 | 10098 | ||
10060 | (void) cls; | 10099 | (void) cls; |
10061 | 10100 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, | |
10062 | //GNUNET_CONTAINER_multipeermap_iterate (neighbours, | 10101 | &free_neighbour_cb, NULL); |
10063 | //&free_neighbour_cb, NULL); | 10102 | if (NULL != validation_task) |
10064 | if (NULL != peerstore) | ||
10065 | { | 10103 | { |
10066 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); | 10104 | GNUNET_SCHEDULER_cancel (validation_task); |
10067 | peerstore = NULL; | 10105 | validation_task = NULL; |
10106 | } | ||
10107 | if (NULL != dvlearn_task) | ||
10108 | { | ||
10109 | GNUNET_SCHEDULER_cancel (dvlearn_task); | ||
10110 | dvlearn_task = NULL; | ||
10068 | } | 10111 | } |
10069 | if (NULL != GST_stats) | 10112 | if (NULL != GST_stats) |
10070 | { | 10113 | { |
@@ -10110,6 +10153,13 @@ do_shutdown (void *cls) | |||
10110 | GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); | 10153 | GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); |
10111 | GNUNET_free (lle); | 10154 | GNUNET_free (lle); |
10112 | } | 10155 | } |
10156 | if (NULL != peerstore) | ||
10157 | { | ||
10158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
10159 | "Disconnecting from PEERSTORE service\n"); | ||
10160 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); | ||
10161 | peerstore = NULL; | ||
10162 | } | ||
10113 | GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); | 10163 | GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); |
10114 | dvlearn_map = NULL; | 10164 | dvlearn_map = NULL; |
10115 | GNUNET_CONTAINER_heap_destroy (validation_heap); | 10165 | GNUNET_CONTAINER_heap_destroy (validation_heap); |
@@ -10117,6 +10167,16 @@ do_shutdown (void *cls) | |||
10117 | GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL); | 10167 | GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL); |
10118 | GNUNET_CONTAINER_multipeermap_destroy (dv_routes); | 10168 | GNUNET_CONTAINER_multipeermap_destroy (dv_routes); |
10119 | dv_routes = NULL; | 10169 | dv_routes = NULL; |
10170 | GNUNET_SCHEDULER_shutdown (); | ||
10171 | } | ||
10172 | |||
10173 | |||
10174 | static void | ||
10175 | shutdown_task (void *cls) | ||
10176 | { | ||
10177 | in_shutdown = GNUNET_YES; | ||
10178 | if (NULL == clients_head) | ||
10179 | do_shutdown (cls); | ||
10120 | } | 10180 | } |
10121 | 10181 | ||
10122 | 10182 | ||
@@ -10136,6 +10196,7 @@ run (void *cls, | |||
10136 | (void) service; | 10196 | (void) service; |
10137 | /* setup globals */ | 10197 | /* setup globals */ |
10138 | hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c); | 10198 | hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c); |
10199 | in_shutdown = GNUNET_NO; | ||
10139 | GST_cfg = c; | 10200 | GST_cfg = c; |
10140 | backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); | 10201 | backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); |
10141 | pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES); | 10202 | pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES); |
@@ -10165,7 +10226,7 @@ run (void *cls, | |||
10165 | "My identity is `%s'\n", | 10226 | "My identity is `%s'\n", |
10166 | GNUNET_i2s_full (&GST_my_identity)); | 10227 | GNUNET_i2s_full (&GST_my_identity)); |
10167 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); | 10228 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); |
10168 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 10229 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
10169 | peerstore = GNUNET_PEERSTORE_connect (GST_cfg); | 10230 | peerstore = GNUNET_PEERSTORE_connect (GST_cfg); |
10170 | if (NULL == peerstore) | 10231 | if (NULL == peerstore) |
10171 | { | 10232 | { |