diff options
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist_client.c')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 104 |
1 files changed, 58 insertions, 46 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index b92f195f8..0751668b3 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; | |||
205 | /** | 205 | /** |
206 | * ID of the task, checking if hostlist download should take plate | 206 | * ID of the task, checking if hostlist download should take plate |
207 | */ | 207 | */ |
208 | static GNUNET_SCHEDULER_TaskIdentifier ti_check_download; | 208 | static struct GNUNET_SCHEDULER_Task * ti_check_download; |
209 | 209 | ||
210 | /** | 210 | /** |
211 | * ID of the task downloading the hostlist | 211 | * ID of the task downloading the hostlist |
212 | */ | 212 | */ |
213 | static GNUNET_SCHEDULER_TaskIdentifier ti_download; | 213 | static struct GNUNET_SCHEDULER_Task * ti_download; |
214 | 214 | ||
215 | /** | 215 | /** |
216 | * ID of the task saving the hostlsit in a regular intervall | 216 | * ID of the task saving the hostlsit in a regular intervall |
217 | */ | 217 | */ |
218 | static GNUNET_SCHEDULER_TaskIdentifier ti_saving_task; | 218 | static struct GNUNET_SCHEDULER_Task * ti_saving_task; |
219 | 219 | ||
220 | /** | 220 | /** |
221 | * ID of the task called to initiate a download | 221 | * ID of the task called to initiate a download |
222 | */ | 222 | */ |
223 | static GNUNET_SCHEDULER_TaskIdentifier ti_download_dispatcher_task; | 223 | static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task; |
224 | 224 | ||
225 | /** | 225 | /** |
226 | * ID of the task controlling the locking between two hostlist tests | 226 | * ID of the task controlling the locking between two hostlist tests |
227 | */ | 227 | */ |
228 | static GNUNET_SCHEDULER_TaskIdentifier ti_testing_intervall_task; | 228 | static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task; |
229 | 229 | ||
230 | /** | 230 | /** |
231 | * At what time MUST the current hostlist request be done? | 231 | * At what time MUST the current hostlist request be done? |
@@ -846,7 +846,7 @@ task_download (void *cls, | |||
846 | struct CURLMsg *msg; | 846 | struct CURLMsg *msg; |
847 | CURLMcode mret; | 847 | CURLMcode mret; |
848 | 848 | ||
849 | ti_download = GNUNET_SCHEDULER_NO_TASK; | 849 | ti_download = NULL; |
850 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 850 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
851 | { | 851 | { |
852 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 852 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1044,7 +1044,7 @@ static void | |||
1044 | task_download_dispatcher (void *cls, | 1044 | task_download_dispatcher (void *cls, |
1045 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1045 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1046 | { | 1046 | { |
1047 | ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK; | 1047 | ti_download_dispatcher_task = NULL; |
1048 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1048 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1049 | return; | 1049 | return; |
1050 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); | 1050 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); |
@@ -1075,7 +1075,7 @@ task_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1075 | static int once; | 1075 | static int once; |
1076 | struct GNUNET_TIME_Relative delay; | 1076 | struct GNUNET_TIME_Relative delay; |
1077 | 1077 | ||
1078 | ti_check_download = GNUNET_SCHEDULER_NO_TASK; | 1078 | ti_check_download = NULL; |
1079 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1079 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1080 | return; | 1080 | return; |
1081 | if (stats == NULL) | 1081 | if (stats == NULL) |
@@ -1084,7 +1084,7 @@ task_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1084 | return; /* in shutdown */ | 1084 | return; /* in shutdown */ |
1085 | } | 1085 | } |
1086 | if ( (stat_connection_count < MIN_CONNECTIONS) && | 1086 | if ( (stat_connection_count < MIN_CONNECTIONS) && |
1087 | (GNUNET_SCHEDULER_NO_TASK == ti_download_dispatcher_task) ) | 1087 | (NULL == ti_download_dispatcher_task) ) |
1088 | ti_download_dispatcher_task = | 1088 | ti_download_dispatcher_task = |
1089 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); | 1089 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1090 | 1090 | ||
@@ -1126,7 +1126,7 @@ static void | |||
1126 | task_testing_intervall_reset (void *cls, | 1126 | task_testing_intervall_reset (void *cls, |
1127 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1127 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1128 | { | 1128 | { |
1129 | ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK; | 1129 | ti_testing_intervall_task = NULL; |
1130 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1130 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1131 | return; | 1131 | return; |
1132 | stat_testing_allowed = GNUNET_OK; | 1132 | stat_testing_allowed = GNUNET_OK; |
@@ -1144,7 +1144,7 @@ task_testing_intervall_reset (void *cls, | |||
1144 | static void | 1144 | static void |
1145 | task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1145 | task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1146 | { | 1146 | { |
1147 | ti_saving_task = GNUNET_SCHEDULER_NO_TASK; | 1147 | ti_saving_task = NULL; |
1148 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1148 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1149 | return; | 1149 | return; |
1150 | save_hostlist_file (GNUNET_NO); | 1150 | save_hostlist_file (GNUNET_NO); |
@@ -1284,7 +1284,7 @@ static void | |||
1284 | primary_task (void *cls, int success) | 1284 | primary_task (void *cls, int success) |
1285 | { | 1285 | { |
1286 | sget = NULL; | 1286 | sget = NULL; |
1287 | GNUNET_assert (stats != NULL); | 1287 | GNUNET_assert (NULL != stats); |
1288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1289 | "Statistics request done, scheduling hostlist download\n"); | 1289 | "Statistics request done, scheduling hostlist download\n"); |
1290 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); | 1290 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
@@ -1310,7 +1310,8 @@ process_stat (void *cls, | |||
1310 | hostlist_delay.rel_value_us = value * 1000LL; | 1310 | hostlist_delay.rel_value_us = value * 1000LL; |
1311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1312 | "Initial time between hostlist downloads is %s\n", | 1312 | "Initial time between hostlist downloads is %s\n", |
1313 | GNUNET_STRINGS_relative_time_to_string (hostlist_delay, GNUNET_YES)); | 1313 | GNUNET_STRINGS_relative_time_to_string (hostlist_delay, |
1314 | GNUNET_YES)); | ||
1314 | return GNUNET_OK; | 1315 | return GNUNET_OK; |
1315 | } | 1316 | } |
1316 | 1317 | ||
@@ -1441,13 +1442,14 @@ save_hostlist_file (int shutdown) | |||
1441 | if (NULL == wh) | 1442 | if (NULL == wh) |
1442 | { | 1443 | { |
1443 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1444 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1444 | _ | 1445 | _("Could not open file `%s' for writing to save hostlists: %s\n"), |
1445 | ("Could not open file `%s' for writing to save hostlists: %s\n"), | 1446 | filename, |
1446 | filename, STRERROR (errno)); | 1447 | STRERROR (errno)); |
1447 | GNUNET_free (filename); | 1448 | GNUNET_free (filename); |
1448 | return; | 1449 | return; |
1449 | } | 1450 | } |
1450 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Writing %u hostlist URIs to `%s'\n"), | 1451 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1452 | _("Writing %u hostlist URIs to `%s'\n"), | ||
1451 | linked_list_size, filename); | 1453 | linked_list_size, filename); |
1452 | /* add code to write hostlists to file using bio */ | 1454 | /* add code to write hostlists to file using bio */ |
1453 | ok = GNUNET_YES; | 1455 | ok = GNUNET_YES; |
@@ -1525,6 +1527,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1525 | transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL); | 1527 | transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL); |
1526 | if (NULL == transport) | 1528 | if (NULL == transport) |
1527 | { | 1529 | { |
1530 | GNUNET_break (0); | ||
1528 | curl_global_cleanup (); | 1531 | curl_global_cleanup (); |
1529 | return GNUNET_SYSERR; | 1532 | return GNUNET_SYSERR; |
1530 | } | 1533 | } |
@@ -1532,8 +1535,9 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1532 | stats = st; | 1535 | stats = st; |
1533 | 1536 | ||
1534 | /* Read proxy configuration */ | 1537 | /* Read proxy configuration */ |
1535 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | 1538 | if (GNUNET_OK == |
1536 | "HOSTLIST", "PROXY", &proxy)) | 1539 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1540 | "HOSTLIST", "PROXY", &proxy)) | ||
1537 | { | 1541 | { |
1538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1539 | "Found proxy host: `%s'\n", | 1543 | "Found proxy host: `%s'\n", |
@@ -1557,23 +1561,26 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1557 | } | 1561 | } |
1558 | 1562 | ||
1559 | /* proxy type */ | 1563 | /* proxy type */ |
1560 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | 1564 | if (GNUNET_OK == |
1561 | "HOSTLIST", "PROXY_TYPE", &proxytype_str)) | 1565 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1566 | "HOSTLIST", | ||
1567 | "PROXY_TYPE", | ||
1568 | &proxytype_str)) | ||
1562 | { | 1569 | { |
1563 | GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str); | 1570 | GNUNET_STRINGS_utf8_toupper (proxytype_str, |
1564 | 1571 | proxytype_str); | |
1565 | proxy_type = CURLPROXY_HTTP; | 1572 | proxy_type = CURLPROXY_HTTP; |
1566 | if (0 == strcmp(proxytype_str, "HTTP")) | 1573 | if (0 == strcmp (proxytype_str, "HTTP")) |
1567 | proxy_type = CURLPROXY_HTTP; | 1574 | proxy_type = CURLPROXY_HTTP; |
1568 | else if (0 == strcmp(proxytype_str, "HTTP_1_0")) | 1575 | else if (0 == strcmp (proxytype_str, "HTTP_1_0")) |
1569 | proxy_type = CURLPROXY_HTTP_1_0; | 1576 | proxy_type = CURLPROXY_HTTP_1_0; |
1570 | else if (0 == strcmp(proxytype_str, "SOCKS4")) | 1577 | else if (0 == strcmp (proxytype_str, "SOCKS4")) |
1571 | proxy_type = CURLPROXY_SOCKS4; | 1578 | proxy_type = CURLPROXY_SOCKS4; |
1572 | else if (0 == strcmp(proxytype_str, "SOCKS5")) | 1579 | else if (0 == strcmp (proxytype_str, "SOCKS5")) |
1573 | proxy_type = CURLPROXY_SOCKS5; | 1580 | proxy_type = CURLPROXY_SOCKS5; |
1574 | else if (0 == strcmp(proxytype_str, "SOCKS4A")) | 1581 | else if (0 == strcmp (proxytype_str, "SOCKS4A")) |
1575 | proxy_type = CURLPROXY_SOCKS4A; | 1582 | proxy_type = CURLPROXY_SOCKS4A; |
1576 | else if (0 == strcmp(proxytype_str, "SOCKS5_HOSTNAME")) | 1583 | else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME")) |
1577 | proxy_type = CURLPROXY_SOCKS5_HOSTNAME; | 1584 | proxy_type = CURLPROXY_SOCKS5_HOSTNAME; |
1578 | else | 1585 | else |
1579 | { | 1586 | { |
@@ -1613,7 +1620,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1613 | "Hostlists will be saved to file again in %s\n", | 1620 | "Hostlists will be saved to file again in %s\n", |
1614 | GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, GNUNET_YES)); | 1621 | GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, GNUNET_YES)); |
1615 | ti_saving_task = | 1622 | ti_saving_task = |
1616 | GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, | 1623 | GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, |
1624 | &task_hostlist_saving, | ||
1617 | NULL); | 1625 | NULL); |
1618 | } | 1626 | } |
1619 | else | 1627 | else |
@@ -1628,22 +1636,26 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1628 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 1636 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
1629 | { | 1637 | { |
1630 | result = remove (filename); | 1638 | result = remove (filename); |
1631 | if (result == 0) | 1639 | if (0 == result) |
1632 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1640 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1633 | _ | 1641 | _("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), |
1634 | ("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), | ||
1635 | filename); | 1642 | filename); |
1636 | else | 1643 | else |
1637 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1644 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
1638 | _("Hostlist file `%s' could not be removed\n"), filename); | 1645 | "remove", |
1646 | filename); | ||
1639 | } | 1647 | } |
1640 | } | 1648 | } |
1641 | GNUNET_free (filename); | 1649 | GNUNET_free (filename); |
1642 | } | 1650 | } |
1651 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1652 | "Loading stats value on hostlist download frequency\n"); | ||
1643 | sget = GNUNET_STATISTICS_get (stats, "hostlist", | 1653 | sget = GNUNET_STATISTICS_get (stats, "hostlist", |
1644 | gettext_noop | 1654 | gettext_noop |
1645 | ("# milliseconds between hostlist downloads"), | 1655 | ("# milliseconds between hostlist downloads"), |
1646 | GNUNET_TIME_UNIT_MINUTES, &primary_task, &process_stat, | 1656 | GNUNET_TIME_UNIT_MINUTES, |
1657 | &primary_task, | ||
1658 | &process_stat, | ||
1647 | NULL); | 1659 | NULL); |
1648 | return GNUNET_OK; | 1660 | return GNUNET_OK; |
1649 | } | 1661 | } |
@@ -1664,31 +1676,31 @@ GNUNET_HOSTLIST_client_stop () | |||
1664 | stats = NULL; | 1676 | stats = NULL; |
1665 | if (GNUNET_YES == stat_learning) | 1677 | if (GNUNET_YES == stat_learning) |
1666 | save_hostlist_file (GNUNET_YES); | 1678 | save_hostlist_file (GNUNET_YES); |
1667 | if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK) | 1679 | if (ti_saving_task != NULL) |
1668 | { | 1680 | { |
1669 | GNUNET_SCHEDULER_cancel (ti_saving_task); | 1681 | GNUNET_SCHEDULER_cancel (ti_saving_task); |
1670 | ti_saving_task = GNUNET_SCHEDULER_NO_TASK; | 1682 | ti_saving_task = NULL; |
1671 | } | 1683 | } |
1672 | 1684 | ||
1673 | if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK) | 1685 | if (ti_download_dispatcher_task != NULL) |
1674 | { | 1686 | { |
1675 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); | 1687 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); |
1676 | ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK; | 1688 | ti_download_dispatcher_task = NULL; |
1677 | } | 1689 | } |
1678 | if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK) | 1690 | if (ti_testing_intervall_task != NULL) |
1679 | { | 1691 | { |
1680 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); | 1692 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); |
1681 | ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK; | 1693 | ti_testing_intervall_task = NULL; |
1682 | } | 1694 | } |
1683 | if (ti_download != GNUNET_SCHEDULER_NO_TASK) | 1695 | if (ti_download != NULL) |
1684 | { | 1696 | { |
1685 | GNUNET_SCHEDULER_cancel (ti_download); | 1697 | GNUNET_SCHEDULER_cancel (ti_download); |
1686 | ti_download = GNUNET_SCHEDULER_NO_TASK; | 1698 | ti_download = NULL; |
1687 | } | 1699 | } |
1688 | if (ti_check_download != GNUNET_SCHEDULER_NO_TASK) | 1700 | if (ti_check_download != NULL) |
1689 | { | 1701 | { |
1690 | GNUNET_SCHEDULER_cancel (ti_check_download); | 1702 | GNUNET_SCHEDULER_cancel (ti_check_download); |
1691 | ti_check_download = GNUNET_SCHEDULER_NO_TASK; | 1703 | ti_check_download = NULL; |
1692 | curl_global_cleanup (); | 1704 | curl_global_cleanup (); |
1693 | } | 1705 | } |
1694 | if (NULL != transport) | 1706 | if (NULL != transport) |