aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/gnunet-daemon-hostlist_client.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
committerChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
commit95f9076a2139f5fb042b944a0658b6cda2fa35db (patch)
treeb0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/hostlist/gnunet-daemon-hostlist_client.c
parent7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff)
downloadgnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz
gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist_client.c')
-rw-r--r--src/hostlist/gnunet-daemon-hostlist_client.c71
1 files changed, 23 insertions, 48 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c
index dbf6eaeda..15a82c2d5 100644
--- a/src/hostlist/gnunet-daemon-hostlist_client.c
+++ b/src/hostlist/gnunet-daemon-hostlist_client.c
@@ -210,27 +210,27 @@ static struct GNUNET_TIME_Relative hostlist_delay;
210/** 210/**
211 * ID of the task, checking if hostlist download should take plate 211 * ID of the task, checking if hostlist download should take plate
212 */ 212 */
213static struct GNUNET_SCHEDULER_Task * ti_check_download; 213static struct GNUNET_SCHEDULER_Task *ti_check_download;
214 214
215/** 215/**
216 * ID of the task downloading the hostlist 216 * ID of the task downloading the hostlist
217 */ 217 */
218static struct GNUNET_SCHEDULER_Task * ti_download; 218static struct GNUNET_SCHEDULER_Task *ti_download;
219 219
220/** 220/**
221 * ID of the task saving the hostlsit in a regular intervall 221 * ID of the task saving the hostlsit in a regular intervall
222 */ 222 */
223static struct GNUNET_SCHEDULER_Task * ti_saving_task; 223static struct GNUNET_SCHEDULER_Task *ti_saving_task;
224 224
225/** 225/**
226 * ID of the task called to initiate a download 226 * ID of the task called to initiate a download
227 */ 227 */
228static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task; 228static struct GNUNET_SCHEDULER_Task *ti_download_dispatcher_task;
229 229
230/** 230/**
231 * ID of the task controlling the locking between two hostlist tests 231 * ID of the task controlling the locking between two hostlist tests
232 */ 232 */
233static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task; 233static struct GNUNET_SCHEDULER_Task *ti_testing_intervall_task;
234 234
235/** 235/**
236 * At what time MUST the current hostlist request be done? 236 * At what time MUST the current hostlist request be done?
@@ -719,8 +719,9 @@ clean_up ()
719{ 719{
720 CURLMcode mret; 720 CURLMcode mret;
721 721
722 if ((stat_testing_hostlist == GNUNET_YES) && 722 if ( (stat_testing_hostlist == GNUNET_YES) &&
723 (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) 723 (GNUNET_NO == stat_download_successful) &&
724 (NULL != hostlist_to_test) )
724 { 725 {
725 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 726 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
726 _ 727 _
@@ -738,7 +739,7 @@ clean_up ()
738 hostlist_to_test = NULL; 739 hostlist_to_test = NULL;
739 } 740 }
740 741
741 if (multi != NULL) 742 if (NULL != multi)
742 { 743 {
743 mret = curl_multi_remove_handle (multi, curl); 744 mret = curl_multi_remove_handle (multi, curl);
744 if (mret != CURLM_OK) 745 if (mret != CURLM_OK)
@@ -754,7 +755,7 @@ clean_up ()
754 curl_multi_strerror (mret)); 755 curl_multi_strerror (mret));
755 multi = NULL; 756 multi = NULL;
756 } 757 }
757 if (curl != NULL) 758 if (NULL != curl)
758 { 759 {
759 curl_easy_cleanup (curl); 760 curl_easy_cleanup (curl);
760 curl = NULL; 761 curl = NULL;
@@ -847,19 +848,8 @@ task_download (void *cls)
847 int running; 848 int running;
848 struct CURLMsg *msg; 849 struct CURLMsg *msg;
849 CURLMcode mret; 850 CURLMcode mret;
850 const struct GNUNET_SCHEDULER_TaskContext *tc;
851 851
852 ti_download = NULL; 852 ti_download = NULL;
853 tc = GNUNET_SCHEDULER_get_task_context ();
854 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
855 {
856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
857 "Shutdown requested while trying to download hostlist from `%s'\n",
858 current_url);
859 update_hostlist ();
860 clean_up ();
861 return;
862 }
863 if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us) 853 if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
864 { 854 {
865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 855 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1047,12 +1037,7 @@ download_hostlist ()
1047static void 1037static void
1048task_download_dispatcher (void *cls) 1038task_download_dispatcher (void *cls)
1049{ 1039{
1050 const struct GNUNET_SCHEDULER_TaskContext *tc;
1051
1052 ti_download_dispatcher_task = NULL; 1040 ti_download_dispatcher_task = NULL;
1053 tc = GNUNET_SCHEDULER_get_task_context ();
1054 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1055 return;
1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); 1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
1057 if (GNUNET_NO == stat_download_in_progress) 1042 if (GNUNET_NO == stat_download_in_progress)
1058 { 1043 {
@@ -1080,12 +1065,8 @@ task_check (void *cls)
1080{ 1065{
1081 static int once; 1066 static int once;
1082 struct GNUNET_TIME_Relative delay; 1067 struct GNUNET_TIME_Relative delay;
1083 const struct GNUNET_SCHEDULER_TaskContext *tc;
1084 1068
1085 ti_check_download = NULL; 1069 ti_check_download = NULL;
1086 tc = GNUNET_SCHEDULER_get_task_context ();
1087 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1088 return;
1089 if (stats == NULL) 1070 if (stats == NULL)
1090 { 1071 {
1091 curl_global_cleanup (); 1072 curl_global_cleanup ();
@@ -1120,7 +1101,8 @@ task_check (void *cls)
1120 _("Have %u/%u connections. Will consider downloading hostlist in %s\n"), 1101 _("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
1121 stat_connection_count, MIN_CONNECTIONS, 1102 stat_connection_count, MIN_CONNECTIONS,
1122 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 1103 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1123 ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL); 1104 ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
1105 &task_check, NULL);
1124} 1106}
1125 1107
1126 1108
@@ -1132,12 +1114,7 @@ task_check (void *cls)
1132static void 1114static void
1133task_testing_intervall_reset (void *cls) 1115task_testing_intervall_reset (void *cls)
1134{ 1116{
1135 const struct GNUNET_SCHEDULER_TaskContext *tc;
1136
1137 ti_testing_intervall_task = NULL; 1117 ti_testing_intervall_task = NULL;
1138 tc = GNUNET_SCHEDULER_get_task_context ();
1139 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1140 return;
1141 stat_testing_allowed = GNUNET_OK; 1118 stat_testing_allowed = GNUNET_OK;
1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1143 "Testing new hostlist advertisements is allowed again\n"); 1120 "Testing new hostlist advertisements is allowed again\n");
@@ -1152,19 +1129,15 @@ task_testing_intervall_reset (void *cls)
1152static void 1129static void
1153task_hostlist_saving (void *cls) 1130task_hostlist_saving (void *cls)
1154{ 1131{
1155 const struct GNUNET_SCHEDULER_TaskContext *tc;
1156
1157 ti_saving_task = NULL; 1132 ti_saving_task = NULL;
1158 tc = GNUNET_SCHEDULER_get_task_context ();
1159 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1160 return;
1161 save_hostlist_file (GNUNET_NO); 1133 save_hostlist_file (GNUNET_NO);
1162 1134
1163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1164 "Hostlists will be saved to file again in %s\n", 1136 "Hostlists will be saved to file again in %s\n",
1165 GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES)); 1137 GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES));
1166 ti_saving_task = 1138 ti_saving_task =
1167 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, 1139 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
1140 &task_hostlist_saving,
1168 NULL); 1141 NULL);
1169} 1142}
1170 1143
@@ -1684,7 +1657,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1684void 1657void
1685GNUNET_HOSTLIST_client_stop () 1658GNUNET_HOSTLIST_client_stop ()
1686{ 1659{
1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); 1660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1661 "Hostlist client shutdown\n");
1688 if (NULL != sget) 1662 if (NULL != sget)
1689 { 1663 {
1690 GNUNET_STATISTICS_get_cancel (sget); 1664 GNUNET_STATISTICS_get_cancel (sget);
@@ -1693,28 +1667,29 @@ GNUNET_HOSTLIST_client_stop ()
1693 stats = NULL; 1667 stats = NULL;
1694 if (GNUNET_YES == stat_learning) 1668 if (GNUNET_YES == stat_learning)
1695 save_hostlist_file (GNUNET_YES); 1669 save_hostlist_file (GNUNET_YES);
1696 if (ti_saving_task != NULL) 1670 if (NULL != ti_saving_task)
1697 { 1671 {
1698 GNUNET_SCHEDULER_cancel (ti_saving_task); 1672 GNUNET_SCHEDULER_cancel (ti_saving_task);
1699 ti_saving_task = NULL; 1673 ti_saving_task = NULL;
1700 } 1674 }
1701 1675 if (NULL != ti_download_dispatcher_task)
1702 if (ti_download_dispatcher_task != NULL)
1703 { 1676 {
1704 GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); 1677 GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
1705 ti_download_dispatcher_task = NULL; 1678 ti_download_dispatcher_task = NULL;
1706 } 1679 }
1707 if (ti_testing_intervall_task != NULL) 1680 if (NULL != ti_testing_intervall_task)
1708 { 1681 {
1709 GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); 1682 GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
1710 ti_testing_intervall_task = NULL; 1683 ti_testing_intervall_task = NULL;
1711 } 1684 }
1712 if (ti_download != NULL) 1685 if (NULL != ti_download)
1713 { 1686 {
1714 GNUNET_SCHEDULER_cancel (ti_download); 1687 GNUNET_SCHEDULER_cancel (ti_download);
1715 ti_download = NULL; 1688 ti_download = NULL;
1689 update_hostlist ();
1690 clean_up ();
1716 } 1691 }
1717 if (ti_check_download != NULL) 1692 if (NULL != ti_check_download)
1718 { 1693 {
1719 GNUNET_SCHEDULER_cancel (ti_check_download); 1694 GNUNET_SCHEDULER_cancel (ti_check_download);
1720 ti_check_download = NULL; 1695 ti_check_download = NULL;