diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-24 01:10:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-24 01:10:47 +0000 |
commit | f1f603c7d0b3f03dca46a4f313472288eb080eb1 (patch) | |
tree | 3a29966b02dfb83e0a8a8d5c42b3116380209fb0 /src/hostlist | |
parent | 53cd5b8eda2fa8db86b0907a62a39598981d008a (diff) |
making GNUNET_SCHEDULER_cancel() perform in O(1) instead of O(n) to help or even fully address #3247
Diffstat (limited to 'src/hostlist')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 21 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 104 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_server.c | 22 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 8 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 16 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | 8 |
6 files changed, 100 insertions, 79 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 62ecc5dfd1..833f24ece0 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c @@ -275,16 +275,24 @@ run (void *cls, return; } stats = GNUNET_STATISTICS_create ("hostlist", cfg); + if (NULL == stats) + { + GNUNET_break (0); + return; + } if (bootstrapping) - GNUNET_HOSTLIST_client_start (cfg, stats, &client_ch, &client_dh, - &client_adv_handler, learning); + GNUNET_HOSTLIST_client_start (cfg, stats, + &client_ch, + &client_dh, + &client_adv_handler, + learning); core = GNUNET_CORE_connect (cfg, NULL, &core_init, &connect_handler, - &disconnect_handler, NULL, - GNUNET_NO, NULL, - GNUNET_NO, + &disconnect_handler, + NULL, GNUNET_NO, + NULL, GNUNET_NO, learning ? learn_handlers : no_learn_handlers); @@ -346,7 +354,8 @@ main (int argc, char *const *argv) GNUNET_log_setup ("hostlist", "WARNING", NULL); ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "hostlist", + GNUNET_PROGRAM_run (argc, argv, + "hostlist", _("GNUnet hostlist server and client"), options, &run, NULL)) ? 0 : 1; diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index b92f195f88..0751668b33 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/hostlist/gnunet-daemon-hostlist_client.c @@ -205,27 +205,27 @@ static struct GNUNET_TIME_Relative hostlist_delay; /** * ID of the task, checking if hostlist download should take plate */ -static GNUNET_SCHEDULER_TaskIdentifier ti_check_download; +static struct GNUNET_SCHEDULER_Task * ti_check_download; /** * ID of the task downloading the hostlist */ -static GNUNET_SCHEDULER_TaskIdentifier ti_download; +static struct GNUNET_SCHEDULER_Task * ti_download; /** * ID of the task saving the hostlsit in a regular intervall */ -static GNUNET_SCHEDULER_TaskIdentifier ti_saving_task; +static struct GNUNET_SCHEDULER_Task * ti_saving_task; /** * ID of the task called to initiate a download */ -static GNUNET_SCHEDULER_TaskIdentifier 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 GNUNET_SCHEDULER_TaskIdentifier ti_testing_intervall_task; +static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task; /** * At what time MUST the current hostlist request be done? @@ -846,7 +846,7 @@ task_download (void *cls, struct CURLMsg *msg; CURLMcode mret; - ti_download = GNUNET_SCHEDULER_NO_TASK; + ti_download = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1044,7 +1044,7 @@ static void task_download_dispatcher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK; + ti_download_dispatcher_task = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); @@ -1075,7 +1075,7 @@ task_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static int once; struct GNUNET_TIME_Relative delay; - ti_check_download = GNUNET_SCHEDULER_NO_TASK; + ti_check_download = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; if (stats == NULL) @@ -1084,7 +1084,7 @@ task_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; /* in shutdown */ } if ( (stat_connection_count < MIN_CONNECTIONS) && - (GNUNET_SCHEDULER_NO_TASK == ti_download_dispatcher_task) ) + (NULL == ti_download_dispatcher_task) ) ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); @@ -1126,7 +1126,7 @@ static void task_testing_intervall_reset (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK; + ti_testing_intervall_task = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; stat_testing_allowed = GNUNET_OK; @@ -1144,7 +1144,7 @@ task_testing_intervall_reset (void *cls, static void task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - ti_saving_task = GNUNET_SCHEDULER_NO_TASK; + ti_saving_task = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; save_hostlist_file (GNUNET_NO); @@ -1284,7 +1284,7 @@ static void primary_task (void *cls, int success) { sget = NULL; - GNUNET_assert (stats != NULL); + GNUNET_assert (NULL != stats); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Statistics request done, scheduling hostlist download\n"); ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); @@ -1310,7 +1310,8 @@ process_stat (void *cls, hostlist_delay.rel_value_us = value * 1000LL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initial time between hostlist downloads is %s\n", - GNUNET_STRINGS_relative_time_to_string (hostlist_delay, GNUNET_YES)); + GNUNET_STRINGS_relative_time_to_string (hostlist_delay, + GNUNET_YES)); return GNUNET_OK; } @@ -1441,13 +1442,14 @@ save_hostlist_file (int shutdown) if (NULL == wh) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ - ("Could not open file `%s' for writing to save hostlists: %s\n"), - filename, STRERROR (errno)); + _("Could not open file `%s' for writing to save hostlists: %s\n"), + filename, + STRERROR (errno)); GNUNET_free (filename); return; } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Writing %u hostlist URIs to `%s'\n"), + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Writing %u hostlist URIs to `%s'\n"), linked_list_size, filename); /* add code to write hostlists to file using bio */ ok = GNUNET_YES; @@ -1525,6 +1527,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL); if (NULL == transport) { + GNUNET_break (0); curl_global_cleanup (); return GNUNET_SYSERR; } @@ -1532,8 +1535,9 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, stats = st; /* Read proxy configuration */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, - "HOSTLIST", "PROXY", &proxy)) + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, + "HOSTLIST", "PROXY", &proxy)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", @@ -1557,23 +1561,26 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, } /* proxy type */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, - "HOSTLIST", "PROXY_TYPE", &proxytype_str)) + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, + "HOSTLIST", + "PROXY_TYPE", + &proxytype_str)) { - GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str); - + GNUNET_STRINGS_utf8_toupper (proxytype_str, + proxytype_str); proxy_type = CURLPROXY_HTTP; - if (0 == strcmp(proxytype_str, "HTTP")) + if (0 == strcmp (proxytype_str, "HTTP")) proxy_type = CURLPROXY_HTTP; - else if (0 == strcmp(proxytype_str, "HTTP_1_0")) + else if (0 == strcmp (proxytype_str, "HTTP_1_0")) proxy_type = CURLPROXY_HTTP_1_0; - else if (0 == strcmp(proxytype_str, "SOCKS4")) + else if (0 == strcmp (proxytype_str, "SOCKS4")) proxy_type = CURLPROXY_SOCKS4; - else if (0 == strcmp(proxytype_str, "SOCKS5")) + else if (0 == strcmp (proxytype_str, "SOCKS5")) proxy_type = CURLPROXY_SOCKS5; - else if (0 == strcmp(proxytype_str, "SOCKS4A")) + else if (0 == strcmp (proxytype_str, "SOCKS4A")) proxy_type = CURLPROXY_SOCKS4A; - else if (0 == strcmp(proxytype_str, "SOCKS5_HOSTNAME")) + else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME")) proxy_type = CURLPROXY_SOCKS5_HOSTNAME; else { @@ -1613,7 +1620,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, "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); } else @@ -1628,22 +1636,26 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, if (GNUNET_YES == GNUNET_DISK_file_test (filename)) { result = remove (filename); - if (result == 0) + if (0 == result) GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ - ("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), + _("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), filename); else - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Hostlist file `%s' could not be removed\n"), filename); + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "remove", + filename); } } GNUNET_free (filename); } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Loading stats value on hostlist download frequency\n"); sget = GNUNET_STATISTICS_get (stats, "hostlist", gettext_noop ("# milliseconds between hostlist downloads"), - GNUNET_TIME_UNIT_MINUTES, &primary_task, &process_stat, + GNUNET_TIME_UNIT_MINUTES, + &primary_task, + &process_stat, NULL); return GNUNET_OK; } @@ -1664,31 +1676,31 @@ GNUNET_HOSTLIST_client_stop () stats = NULL; if (GNUNET_YES == stat_learning) save_hostlist_file (GNUNET_YES); - if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK) + if (ti_saving_task != NULL) { GNUNET_SCHEDULER_cancel (ti_saving_task); - ti_saving_task = GNUNET_SCHEDULER_NO_TASK; + ti_saving_task = NULL; } - if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK) + if (ti_download_dispatcher_task != NULL) { GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); - ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK; + ti_download_dispatcher_task = NULL; } - if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK) + if (ti_testing_intervall_task != NULL) { GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); - ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK; + ti_testing_intervall_task = NULL; } - if (ti_download != GNUNET_SCHEDULER_NO_TASK) + if (ti_download != NULL) { GNUNET_SCHEDULER_cancel (ti_download); - ti_download = GNUNET_SCHEDULER_NO_TASK; + ti_download = NULL; } - if (ti_check_download != GNUNET_SCHEDULER_NO_TASK) + if (ti_check_download != NULL) { GNUNET_SCHEDULER_cancel (ti_check_download); - ti_check_download = GNUNET_SCHEDULER_NO_TASK; + ti_check_download = NULL; curl_global_cleanup (); } if (NULL != transport) diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c index 9c8b145981..542fa1a98d 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 GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v4; +static struct GNUNET_SCHEDULER_Task * hostlist_task_v4; /** * Our primary task for IPv6. */ -static GNUNET_SCHEDULER_TaskIdentifier hostlist_task_v6; +static struct GNUNET_SCHEDULER_Task * hostlist_task_v6; /** * Our canonical response. @@ -618,7 +618,7 @@ process_notify (void *cls, * Function that queries MHD's select sets and * starts the task waiting for them. */ -static GNUNET_SCHEDULER_TaskIdentifier +static struct GNUNET_SCHEDULER_Task * prepare_daemon (struct MHD_Daemon *daemon_handle); @@ -636,9 +636,9 @@ run_daemon (void *cls, struct MHD_Daemon *daemon_handle = cls; if (daemon_handle == daemon_handle_v4) - hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK; + hostlist_task_v4 = NULL; else - hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK; + hostlist_task_v6 = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; @@ -656,10 +656,10 @@ run_daemon (void *cls, * * @param daemon_handle HTTP server to prepare to run */ -static GNUNET_SCHEDULER_TaskIdentifier +static struct GNUNET_SCHEDULER_Task * prepare_daemon (struct MHD_Daemon *daemon_handle) { - GNUNET_SCHEDULER_TaskIdentifier ret; + struct GNUNET_SCHEDULER_Task * ret; fd_set rs; fd_set ws; fd_set es; @@ -917,15 +917,15 @@ GNUNET_HOSTLIST_server_stop () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); - if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v6) + if (NULL != hostlist_task_v6) { GNUNET_SCHEDULER_cancel (hostlist_task_v6); - hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK; + hostlist_task_v6 = NULL; } - if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v4) + if (NULL != hostlist_task_v4) { GNUNET_SCHEDULER_cancel (hostlist_task_v4); - hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK; + hostlist_task_v4 = NULL; } if (NULL != daemon_handle_v4) { diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index a39f346aea..21cd164bc2 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 GNUNET_SCHEDULER_TaskIdentifier timeout_task; +static struct GNUNET_SCHEDULER_Task * timeout_task; struct PeerContext { @@ -83,7 +83,7 @@ clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - timeout_task = GNUNET_SCHEDULER_NO_TASK; + timeout_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout trying to connect peers, test failed.\n"); clean_up (NULL, tc); @@ -106,10 +106,10 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); ok = 0; - if (timeout_task != GNUNET_SCHEDULER_NO_TASK) + if (timeout_task != NULL) { GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = GNUNET_SCHEDULER_NO_TASK; + timeout_task = NULL; } GNUNET_SCHEDULER_add_now (&clean_up, NULL); } diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index 9f4d8e3d70..5f497f2429 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -64,9 +64,9 @@ static char *current_adv_uri; static const struct GNUNET_CONFIGURATION_Handle *cfg; -static GNUNET_SCHEDULER_TaskIdentifier timeout_task; +static struct GNUNET_SCHEDULER_Task * timeout_task; -static GNUNET_SCHEDULER_TaskIdentifier check_task; +static struct GNUNET_SCHEDULER_Task * check_task; static struct PeerContext adv_peer; @@ -83,10 +83,10 @@ static void shutdown_testcase () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown testcase....\n"); - if (timeout_task != GNUNET_SCHEDULER_NO_TASK) + if (timeout_task != NULL) { GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = GNUNET_SCHEDULER_NO_TASK; + timeout_task = NULL; } if (NULL != download_stats) { @@ -113,10 +113,10 @@ shutdown_testcase () GNUNET_STATISTICS_destroy (learn_peer.stats, GNUNET_NO); learn_peer.stats = NULL; } - if (check_task != GNUNET_SCHEDULER_NO_TASK) + if (check_task != NULL) { GNUNET_SCHEDULER_cancel (check_task); - check_task = GNUNET_SCHEDULER_NO_TASK; + check_task = NULL; } if (NULL != current_adv_uri) { @@ -168,7 +168,7 @@ shutdown_testcase () static void timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - timeout_task = GNUNET_SCHEDULER_NO_TASK; + timeout_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout while executing testcase, test failed.\n"); timeout = GNUNET_YES; @@ -269,7 +269,7 @@ check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { char *stat; - check_task = GNUNET_SCHEDULER_NO_TASK; + check_task = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"), diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index 1962bcd457..5ff97ff6ba 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c @@ -35,7 +35,7 @@ static int ok; -static GNUNET_SCHEDULER_TaskIdentifier timeout_task; +static struct GNUNET_SCHEDULER_Task * timeout_task; struct PeerContext { @@ -83,7 +83,7 @@ clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - timeout_task = GNUNET_SCHEDULER_NO_TASK; + timeout_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout trying to connect peers, test failed.\n"); clean_up (NULL, tc); @@ -106,10 +106,10 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); ok = 0; - if (timeout_task != GNUNET_SCHEDULER_NO_TASK) + if (timeout_task != NULL) { GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = GNUNET_SCHEDULER_NO_TASK; + timeout_task = NULL; } GNUNET_SCHEDULER_add_now (&clean_up, NULL); } |