diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-30 08:17:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-30 08:17:37 +0000 |
commit | 95f9076a2139f5fb042b944a0658b6cda2fa35db (patch) | |
tree | b0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/hostlist | |
parent | 7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff) |
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/hostlist')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 5 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 71 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_server.c | 19 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 29 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 14 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | 18 |
6 files changed, 71 insertions, 85 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 6a4689af1b..21fab323b9 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c @@ -299,9 +299,8 @@ run (void *cls, GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh, advertising); #endif - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &cleaning_task, - NULL); + GNUNET_SCHEDULER_add_shutdown (&cleaning_task, + NULL); if (NULL == core) { diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index dbf6eaedac..15a82c2d54 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; /** * ID of the task, checking if hostlist download should take plate */ -static struct GNUNET_SCHEDULER_Task * ti_check_download; +static struct GNUNET_SCHEDULER_Task *ti_check_download; /** * ID of the task downloading the hostlist */ -static struct GNUNET_SCHEDULER_Task * ti_download; +static struct GNUNET_SCHEDULER_Task *ti_download; /** * ID of the task saving the hostlsit in a regular intervall */ -static struct GNUNET_SCHEDULER_Task * ti_saving_task; +static struct GNUNET_SCHEDULER_Task *ti_saving_task; /** * ID of the task called to initiate a download */ -static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task; +static struct GNUNET_SCHEDULER_Task *ti_download_dispatcher_task; /** * ID of the task controlling the locking between two hostlist tests */ -static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task; +static struct GNUNET_SCHEDULER_Task *ti_testing_intervall_task; /** * At what time MUST the current hostlist request be done? @@ -719,8 +719,9 @@ clean_up () { CURLMcode mret; - if ((stat_testing_hostlist == GNUNET_YES) && - (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) + if ( (stat_testing_hostlist == GNUNET_YES) && + (GNUNET_NO == stat_download_successful) && + (NULL != hostlist_to_test) ) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ @@ -738,7 +739,7 @@ clean_up () hostlist_to_test = NULL; } - if (multi != NULL) + if (NULL != multi) { mret = curl_multi_remove_handle (multi, curl); if (mret != CURLM_OK) @@ -754,7 +755,7 @@ clean_up () curl_multi_strerror (mret)); multi = NULL; } - if (curl != NULL) + if (NULL != curl) { curl_easy_cleanup (curl); curl = NULL; @@ -847,19 +848,8 @@ task_download (void *cls) int running; struct CURLMsg *msg; CURLMcode mret; - const struct GNUNET_SCHEDULER_TaskContext *tc; ti_download = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shutdown requested while trying to download hostlist from `%s'\n", - current_url); - update_hostlist (); - clean_up (); - return; - } if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -1047,12 +1037,7 @@ download_hostlist () static void task_download_dispatcher (void *cls) { - const struct GNUNET_SCHEDULER_TaskContext *tc; - ti_download_dispatcher_task = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); if (GNUNET_NO == stat_download_in_progress) { @@ -1080,12 +1065,8 @@ task_check (void *cls) { static int once; struct GNUNET_TIME_Relative delay; - const struct GNUNET_SCHEDULER_TaskContext *tc; ti_check_download = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; if (stats == NULL) { curl_global_cleanup (); @@ -1120,7 +1101,8 @@ task_check (void *cls) _("Have %u/%u connections. Will consider downloading hostlist in %s\n"), stat_connection_count, MIN_CONNECTIONS, GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); - ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL); + ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, + &task_check, NULL); } @@ -1132,12 +1114,7 @@ task_check (void *cls) static void task_testing_intervall_reset (void *cls) { - const struct GNUNET_SCHEDULER_TaskContext *tc; - ti_testing_intervall_task = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; stat_testing_allowed = GNUNET_OK; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing new hostlist advertisements is allowed again\n"); @@ -1152,19 +1129,15 @@ task_testing_intervall_reset (void *cls) static void task_hostlist_saving (void *cls) { - const struct GNUNET_SCHEDULER_TaskContext *tc; - ti_saving_task = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; save_hostlist_file (GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlists will be saved to file again in %s\n", GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES)); ti_saving_task = - GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, + GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, + &task_hostlist_saving, NULL); } @@ -1684,7 +1657,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, void GNUNET_HOSTLIST_client_stop () { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Hostlist client shutdown\n"); if (NULL != sget) { GNUNET_STATISTICS_get_cancel (sget); @@ -1693,28 +1667,29 @@ GNUNET_HOSTLIST_client_stop () stats = NULL; if (GNUNET_YES == stat_learning) save_hostlist_file (GNUNET_YES); - if (ti_saving_task != NULL) + if (NULL != ti_saving_task) { GNUNET_SCHEDULER_cancel (ti_saving_task); ti_saving_task = NULL; } - - if (ti_download_dispatcher_task != NULL) + if (NULL != ti_download_dispatcher_task) { GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); ti_download_dispatcher_task = NULL; } - if (ti_testing_intervall_task != NULL) + if (NULL != ti_testing_intervall_task) { GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); ti_testing_intervall_task = NULL; } - if (ti_download != NULL) + if (NULL != ti_download) { GNUNET_SCHEDULER_cancel (ti_download); ti_download = NULL; + update_hostlist (); + clean_up (); } - if (ti_check_download != NULL) + if (NULL != ti_check_download) { GNUNET_SCHEDULER_cancel (ti_check_download); ti_check_download = NULL; diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c index 6e2cb7ee46..5b45af831d 100644 --- a/src/hostlist/gnunet-daemon-hostlist_server.c +++ b/src/hostlist/gnunet-daemon-hostlist_server.c @@ -74,12 +74,12 @@ static struct GNUNET_PEERINFO_NotifyContext *notify; /** * Our primary task for IPv4. */ -static struct GNUNET_SCHEDULER_Task * hostlist_task_v4; +static struct GNUNET_SCHEDULER_Task *hostlist_task_v4; /** * Our primary task for IPv6. */ -static struct GNUNET_SCHEDULER_Task * hostlist_task_v6; +static struct GNUNET_SCHEDULER_Task *hostlist_task_v6; /** * Our canonical response. @@ -632,15 +632,11 @@ static void run_daemon (void *cls) { struct MHD_Daemon *daemon_handle = cls; - const struct GNUNET_SCHEDULER_TaskContext *tc; if (daemon_handle == daemon_handle_v4) hostlist_task_v4 = NULL; else hostlist_task_v6 = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); if (daemon_handle == daemon_handle_v4) hostlist_task_v4 = prepare_daemon (daemon_handle); @@ -675,7 +671,9 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) wrs = GNUNET_NETWORK_fdset_create (); wws = GNUNET_NETWORK_fdset_create (); max = -1; - GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); + GNUNET_assert (MHD_YES == + MHD_get_fdset (daemon_handle, + &rs, &ws, &es, &max)); haveto = MHD_get_timeout (daemon_handle, &timeout); if (haveto == MHD_YES) tv.rel_value_us = (uint64_t) timeout * 1000LL; @@ -683,10 +681,9 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) tv = GNUNET_TIME_UNIT_FOREVER_REL; GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); - ret = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, - tv, wrs, wws, - &run_daemon, daemon_handle); + ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, + tv, wrs, wws, + &run_daemon, daemon_handle); GNUNET_NETWORK_fdset_destroy (wrs); GNUNET_NETWORK_fdset_destroy (wws); return ret; diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 2f99b887d0..5f8ece9b8d 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c @@ -35,7 +35,7 @@ static int ok; -static struct GNUNET_SCHEDULER_Task * timeout_task; +static struct GNUNET_SCHEDULER_Task *timeout_task; struct PeerContext { @@ -100,11 +100,13 @@ timeout_error (void *cls) * @param distance in overlay hops, as given by transport plugin */ static void -notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) +notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer) { if (peer == NULL) return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peers connected, shutting down.\n"); ok = 0; if (timeout_task != NULL) { @@ -116,7 +118,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) static void -process_hello (void *cls, const struct GNUNET_MessageHeader *message) +process_hello (void *cls, + const struct GNUNET_MessageHeader *message) { struct PeerContext *p = cls; @@ -170,8 +173,10 @@ waitpid_task (void *cls) static void stop_arm (struct PeerContext *p) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Asking ARM to stop core service\n"); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &waitpid_task, p); } @@ -187,14 +192,18 @@ shutdown_task (void *cls) static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { GNUNET_assert (ok == 1); ok++; - timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, - NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &timeout_error, + NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, + NULL); setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); } diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index a71b8ecaee..717311be74 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -242,7 +242,9 @@ process_adv_sent_done (void *cls, int success) static int -process_adv_sent (void *cls, const char *subsystem, const char *name, +process_adv_sent (void *cls, + const char *subsystem, + const char *name, uint64_t value, int is_persistent) { if ((value >= 1) && (adv_sent == GNUNET_NO)) @@ -267,13 +269,10 @@ static void check_statistics (void *cls) { char *stat; - const struct GNUNET_SCHEDULER_TaskContext *tc; check_task = NULL; - tc = GNUNET_SCHEDULER_get_task_context (); - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; - GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"), + GNUNET_asprintf (&stat, + gettext_noop ("# advertised URI `%s' downloaded"), current_adv_uri); if (NULL != learn_peer.stats) { @@ -313,7 +312,8 @@ check_statistics (void *cls) * Core handler for p2p hostlist advertisements */ static int -ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer, +ad_arrive_handler (void *cls, + const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message) { char *hostname; diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index 0af16e0659..562eec55bf 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c @@ -100,11 +100,13 @@ timeout_error (void *cls) * @param distance in overlay hops, as given by transport plugin */ static void -notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) +notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer) { if (peer == NULL) return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peers connected, shutting down.\n"); ok = 0; if (timeout_task != NULL) { @@ -116,7 +118,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) static void -process_hello (void *cls, const struct GNUNET_MessageHeader *message) +process_hello (void *cls, + const struct GNUNET_MessageHeader *message) { struct PeerContext *p = cls; @@ -171,7 +174,8 @@ static void stop_arm (struct PeerContext *p) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &waitpid_task, p); } @@ -192,8 +196,10 @@ run (void *cls, char *const *args, const char *cfgfile, { GNUNET_assert (ok == 1); ok++; - timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, + timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &timeout_error, NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &shutdown_task, NULL); setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |