GNUnet 0.22.1
gnunet-daemon-hostlist_client.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2010, 2014, 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "platform.h"
28#include "gnunet_util_lib.h"
32/* Just included for the right curl.h */
33#include "gnunet_curl_lib.h"
34
35
40#define MIN_CONNECTIONS 4
41
45#define MAX_NUMBER_HOSTLISTS 30
46
50#define SAVING_INTERVAL \
51 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
52
56#define TESTING_INTERVAL \
57 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
58
62#define WAITING_INTERVAL \
63 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
64
72#define HOSTLIST_INITIAL 10000
73
77#define HOSTLIST_FAILED_DOWNLOAD 100
78
82#define HOSTLIST_SUCCESSFUL_DOWNLOAD 100
83
87#define HOSTLIST_SUCCESSFUL_HELLO 1
88
89
94{
98 struct Hostlist *prev;
99
103 struct Hostlist *next;
104
108 const char *hostlist_uri;
109
118 uint64_t quality;
119
124
129
133 uint32_t hello_count;
134
138 uint32_t times_used;
139};
140
145{
150
155
160};
161
165static const struct GNUNET_CONFIGURATION_Handle *cfg;
166
171
175static char *proxy;
176
180static char *proxy_username;
181
185static char *proxy_password;
186
190static curl_proxytype proxy_type;
191
195static size_t download_pos;
196
200static char *current_url;
201
205static CURL *curl;
206
210static CURLM *multi;
211
215static uint32_t stat_bytes_downloaded;
216
221
226
231
236
241
246
251
256
261
266
271
276
280static unsigned int linked_list_size;
281
286
291
295static int stat_bogus_url;
296
301
306
311
315static unsigned int stat_use_bootstrap;
316
320static int stat_learning;
321
325static unsigned int stat_download_successful;
326
330static unsigned int stat_hellos_obtained;
331
335static unsigned int stat_connection_count;
336
341
342
343static void
344shc_cont (void *cls, int success)
345{
346 struct StoreHelloEntry *she = cls;
347
348 she->sc = NULL;
349 if (GNUNET_YES == success)
351 "Hostlist entry stored successfully!\n");
352 else
354 "Error storing hostlist entry!\n");
356 GNUNET_free (she);
357}
358
359
369static size_t
370callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
371{
372 static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1];
373 struct StoreHelloEntry *she;
374 const char *cbuf = ptr;
375 const struct GNUNET_MessageHeader *msg;
376 size_t total;
377 size_t cpy;
378 size_t left;
379 uint16_t msize;
380
381 total = size * nmemb;
382 stat_bytes_downloaded += total;
383 if ((total == 0) || (stat_bogus_url))
384 {
385 return total; /* ok, no data or bogus data */
386 }
387
390 "# bytes downloaded from hostlist servers"),
391 (int64_t) total,
392 GNUNET_NO);
393 left = total;
394 while ((left > 0) || (download_pos > 0))
395 {
397 GNUNET_memcpy (&download_buffer[download_pos], cbuf, cpy);
398 cbuf += cpy;
399 download_pos += cpy;
400 left -= cpy;
401 if (download_pos < sizeof(struct GNUNET_MessageHeader))
402 {
403 GNUNET_assert (0 == left);
404 break;
405 }
406 msg = (const struct GNUNET_MessageHeader *) download_buffer;
407 msize = ntohs (msg->size);
408 if (msize < sizeof(struct GNUNET_MessageHeader))
409 {
411 stats,
412 gettext_noop ("# invalid HELLOs downloaded from hostlist servers"),
413 1,
414 GNUNET_NO);
416 _ ("Invalid `%s' message received from hostlist at `%s'\n"),
417 "HELLO",
420 stat_bogus_url = 1;
421 return total;
422 }
423 if (download_pos < msize)
424 {
425 GNUNET_assert (left == 0);
426 break;
427 }
429 "Received valid `%s' message from hostlist server.\n",
430 "HELLO");
432 stats,
433 gettext_noop ("# valid HELLOs downloaded from hostlist servers"),
434 1,
435 GNUNET_NO);
437 she = GNUNET_new (struct StoreHelloEntry);
439 msg,
440 shc_cont,
441 she);
442 if (NULL != she->sc)
443 {
445 }
446 else
447 GNUNET_free (she);
448 memmove (download_buffer, &download_buffer[msize], download_pos - msize);
449 download_pos -= msize;
450 }
451 return total;
452}
453
454
460static char *
462{
463 char *servers;
464 char *ret;
465 size_t urls;
466 size_t pos;
467
469 "HOSTLIST",
470 "SERVERS",
471 &servers))
472 {
474 "hostlist",
475 "SERVERS");
476 return NULL;
477 }
478
479 urls = 0;
480 if (strlen (servers) > 0)
481 {
482 urls++;
483 pos = strlen (servers) - 1;
484 while (pos > 0)
485 {
486 if (servers[pos] == ' ')
487 urls++;
488 pos--;
489 }
490 }
491 if (urls == 0)
492 {
494 "hostlist",
495 "SERVERS");
496 GNUNET_free (servers);
497 return NULL;
498 }
499
501 pos = strlen (servers) - 1;
502 while (pos > 0)
503 {
504 if (servers[pos] == ' ')
505 {
506 urls--;
507 servers[pos] = '\0';
508 }
509 if (urls == 0)
510 {
511 pos++;
512 break;
513 }
514 pos--;
515 }
516 ret = GNUNET_strdup (&servers[pos]);
517 GNUNET_free (servers);
518 return ret;
519}
520
521
526static char *
528{
529 uint32_t index;
530 unsigned int counter;
531 struct Hostlist *pos;
532
534 {
536 "Using preconfigured bootstrap server\n");
537 current_hostlist = NULL;
538 return get_bootstrap_server ();
539 }
540
542 {
544 "Testing new advertised hostlist if it is obtainable\n");
547 }
548
550 {
552 "Using preconfigured bootstrap server\n");
553 current_hostlist = NULL;
554 return get_bootstrap_server ();
555 }
556 index =
558 counter = 0;
559 pos = linked_list_head;
560 while (counter < index)
561 {
562 pos = pos->next;
563 counter++;
564 }
566 "Using learned hostlist `%s'\n",
567 pos->hostlist_uri);
568 current_hostlist = pos;
569 return GNUNET_strdup (pos->hostlist_uri);
570}
571
572
573#define CURL_EASY_SETOPT(c, a, b) \
574 do \
575 { \
576 ret = curl_easy_setopt (c, a, b); \
577 if (CURLE_OK != ret) \
578 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
579 _ ("%s failed at %s:%d: `%s'\n"), \
580 "curl_easy_setopt", \
581 __FILE__, \
582 __LINE__, \
583 curl_easy_strerror (ret)); \
584 } while (0)
585
586
592static void
593save_hostlist_file (int shutdown);
594
595
603static uint64_t
604checked_add (uint64_t val1, uint64_t val2)
605{
606 static uint64_t temp;
607 static uint64_t maxv;
608
609 maxv = 0;
610 maxv--;
611
612 temp = val1 + val2;
613 if (temp < val1)
614 return maxv;
615 return temp;
616}
617
618
626static uint64_t
627checked_sub (uint64_t val1, uint64_t val2)
628{
629 if (val1 <= val2)
630 return 0;
631 return(val1 - val2);
632}
633
634
641static int
643{
644 struct Hostlist *pos;
645
646 pos = linked_list_head;
647 while (pos != NULL)
648 {
649 if (0 == strcmp (pos->hostlist_uri, uri))
650 return GNUNET_YES;
651 pos = pos->next;
652 }
653 return GNUNET_NO;
654}
655
656
661static struct Hostlist *
663{
664 struct Hostlist *pos;
665 struct Hostlist *lowest;
666
667 if (linked_list_size == 0)
668 return NULL;
669 lowest = linked_list_head;
670 pos = linked_list_head->next;
671 while (pos != NULL)
672 {
673 if (pos->quality < lowest->quality)
674 lowest = pos;
675 pos = pos->next;
676 }
677 return lowest;
678}
679
680
686static void
688{
689 struct Hostlist *lowest_quality;
690
692 {
693 /* No free entries available, replace existing entry */
694 lowest_quality = linked_list_get_lowest_quality ();
695 GNUNET_assert (lowest_quality != NULL);
696 GNUNET_log (
698 "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n",
699 lowest_quality->hostlist_uri,
700 (unsigned long long) lowest_quality->quality);
703 lowest_quality);
705 GNUNET_free (lowest_quality);
706 }
712 gettext_noop ("# advertised hostlist URIs"),
714 GNUNET_NO);
716}
717
718
722static void
724{
725 char *stat;
726
727 if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) ||
729 {
731 "Updating hostlist statistics for URI `%s'\n",
739 {
743 GNUNET_asprintf (&stat,
744 gettext_noop ("# advertised URI `%s' downloaded"),
746
748 GNUNET_free (stat);
749 }
750 else
753 }
754 current_hostlist = NULL;
755 /* Alternating the usage of preconfigured and learned hostlists */
756
758 return;
759
761 {
764 else
766 }
767 else
769}
770
771
776static void
778{
779 CURLMcode mret;
780
783 {
784 GNUNET_log (
786 _ (
787 "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"),
789 }
790
792 {
794 }
795 if (NULL != hostlist_to_test)
796 {
798 hostlist_to_test = NULL;
799 }
800
801 if (NULL != multi)
802 {
803 mret = curl_multi_remove_handle (multi, curl);
804 if (mret != CURLM_OK)
805 {
807 _ ("%s failed at %s:%d: `%s'\n"),
808 "curl_multi_remove_handle",
809 __FILE__,
810 __LINE__,
811 curl_multi_strerror (mret));
812 }
813 mret = curl_multi_cleanup (multi);
814 if (mret != CURLM_OK)
816 _ ("%s failed at %s:%d: `%s'\n"),
817 "curl_multi_cleanup",
818 __FILE__,
819 __LINE__,
820 curl_multi_strerror (mret));
821 multi = NULL;
822 }
823 if (NULL != curl)
824 {
825 curl_easy_cleanup (curl);
826 curl = NULL;
827 }
829 current_url = NULL;
832}
833
834
841static void
842task_download (void *cls);
843
844
849static void
851{
852 CURLMcode mret;
853 fd_set rs;
854 fd_set ws;
855 fd_set es;
856 int max;
857 struct GNUNET_NETWORK_FDSet *grs;
858 struct GNUNET_NETWORK_FDSet *gws;
859 long timeout;
860 struct GNUNET_TIME_Relative rtime;
861
862 max = -1;
863 FD_ZERO (&rs);
864 FD_ZERO (&ws);
865 FD_ZERO (&es);
866 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
867 if (mret != CURLM_OK)
868 {
870 _ ("%s failed at %s:%d: `%s'\n"),
871 "curl_multi_fdset",
872 __FILE__,
873 __LINE__,
874 curl_multi_strerror (mret));
875 clean_up ();
876 return;
877 }
878 mret = curl_multi_timeout (multi, &timeout);
879 if (mret != CURLM_OK)
880 {
882 _ ("%s failed at %s:%d: `%s'\n"),
883 "curl_multi_timeout",
884 __FILE__,
885 __LINE__,
886 curl_multi_strerror (mret));
887 clean_up ();
888 return;
889 }
898 "Scheduling task for hostlist download using cURL\n");
900 rtime,
901 grs,
902 gws,
904 multi);
907}
908
909
910static void
911task_download (void *cls)
912{
913 int running;
914 struct CURLMsg *msg;
915 CURLMcode mret;
916
917 ti_download = NULL;
918 if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
919 {
921 _ ("Timeout trying to download hostlist from `%s'\n"),
924 clean_up ();
925 return;
926 }
928 "Ready for processing hostlist client request\n");
929 do
930 {
931 running = 0;
933 {
935 _ (
936 "Download limit of %u bytes exceeded, stopping download\n"),
938 clean_up ();
939 return;
940 }
941 mret = curl_multi_perform (multi, &running);
942 if (running == 0)
943 {
944 do
945 {
946 msg = curl_multi_info_read (multi, &running);
947 GNUNET_break (msg != NULL);
948 if (msg == NULL)
949 break;
950 switch (msg->msg)
951 {
952 case CURLMSG_DONE:
953 if ((msg->data.result != CURLE_OK) &&
954 (msg->data.result != CURLE_GOT_NOTHING))
956 _ ("Download of hostlist from `%s' failed: `%s'\n"),
958 curl_easy_strerror (msg->data.result));
959 else
960 {
962 _ ("Download of hostlist `%s' completed.\n"),
967 {
968 GNUNET_log (
970 _ ("Adding successfully tested hostlist `%s' datastore.\n"),
973 hostlist_to_test = NULL;
975 }
976 }
977 clean_up ();
978 return;
979
980 default:
981 break;
982 }
983 }
984 while ((running > 0));
985 }
986 }
987 while (mret == CURLM_CALL_MULTI_PERFORM);
988
989 if (mret != CURLM_OK)
990 {
992 _ ("%s failed at %s:%d: `%s'\n"),
993 "curl_multi_perform",
994 __FILE__,
995 __LINE__,
996 curl_multi_strerror (mret));
997 clean_up ();
998 }
1000}
1001
1002
1007static void
1009{
1010 CURLcode ret;
1011 CURLMcode mret;
1012
1013
1015 if (current_url == NULL)
1016 return;
1017 curl = curl_easy_init ();
1018 multi = NULL;
1019 if (curl == NULL)
1020 {
1021 GNUNET_break (0);
1022 clean_up ();
1023 return;
1024 }
1026 _ ("Bootstrapping using hostlist at `%s'.\n"),
1027 current_url);
1028
1033
1035 gettext_noop ("# hostlist downloads initiated"),
1036 1,
1037 GNUNET_NO);
1038 if (NULL != proxy)
1039 {
1040 CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy);
1041 CURL_EASY_SETOPT (curl, CURLOPT_PROXYTYPE, proxy_type);
1042 if (NULL != proxy_username)
1043 CURL_EASY_SETOPT (curl, CURLOPT_PROXYUSERNAME, proxy_username);
1044 if (NULL != proxy_password)
1045 CURL_EASY_SETOPT (curl, CURLOPT_PROXYPASSWORD, proxy_password);
1046 }
1047 download_pos = 0;
1048 stat_bogus_url = 0;
1049 CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download);
1050 if (ret != CURLE_OK)
1051 {
1052 clean_up ();
1053 return;
1054 }
1055 CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL);
1056 if (ret != CURLE_OK)
1057 {
1058 clean_up ();
1059 return;
1060 }
1061 CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
1062#ifdef CURLOPT_REDIR_PROTOCOLS_STR
1063 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1064 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl,
1065 CURLOPT_REDIR_PROTOCOLS_STR,
1066 "https"));
1067 else
1068 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl,
1069 CURLOPT_REDIR_PROTOCOLS_STR,
1070 "http,https"));
1071#else
1072#ifdef CURLOPT_REDIR_PROTOCOLS
1073 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1074 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS,
1075 CURLPROTO_HTTPS));
1076 else
1077 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS,
1078 CURLPROTO_HTTP
1079 | CURLPROTO_HTTPS));
1080#endif
1081#endif
1082#ifdef CURLOPT_PROTOCOLS_STR
1083 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1084 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR,
1085 "https"));
1086 else
1087 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR,
1088 "http,https"));
1089#else
1090#ifdef CURLOPT_PROTOCOLS
1091 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1092 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS,
1093 CURLPROTO_HTTPS));
1094 else
1095 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS,
1096 CURLPROTO_HTTP
1097 | CURLPROTO_HTTPS));
1098#endif
1099#endif
1100 CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
1101 /* no need to abort if the above failed */
1102 CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url);
1103 if (ret != CURLE_OK)
1104 {
1105 clean_up ();
1106 return;
1107 }
1108 CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1);
1109#if 0
1110 CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1);
1111#endif
1112 CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE);
1113 if (0 == strncmp (current_url, "http", 4))
1114 CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet");
1115 CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L);
1116 CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L);
1117 multi = curl_multi_init ();
1118 if (multi == NULL)
1119 {
1120 GNUNET_break (0);
1121 /* clean_up (); */
1122 return;
1123 }
1124 mret = curl_multi_add_handle (multi, curl);
1125 if (mret != CURLM_OK)
1126 {
1128 _ ("%s failed at %s:%d: `%s'\n"),
1129 "curl_multi_add_handle",
1130 __FILE__,
1131 __LINE__,
1132 curl_multi_strerror (mret));
1133 mret = curl_multi_cleanup (multi);
1134 if (mret != CURLM_OK)
1136 _ ("%s failed at %s:%d: `%s'\n"),
1137 "curl_multi_cleanup",
1138 __FILE__,
1139 __LINE__,
1140 curl_multi_strerror (mret));
1141 multi = NULL;
1142 clean_up ();
1143 return;
1144 }
1147}
1148
1149
1150static void
1152{
1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
1156 {
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n");
1159 }
1160 else
1161 {
1163 "Download in progress, have to wait...\n");
1167 NULL);
1168 }
1169}
1170
1171
1177static void
1178task_check (void *cls)
1179{
1180 static int once;
1181 struct GNUNET_TIME_Relative delay;
1182
1183 ti_check_download = NULL;
1184 if (stats == NULL)
1185 {
1186 curl_global_cleanup ();
1187 return; /* in shutdown */
1188 }
1193
1194 delay = hostlist_delay;
1197 else
1200 GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count))
1203 (1 + stat_connection_count));
1205 gettext_noop (
1206 "# milliseconds between hostlist downloads"),
1208 GNUNET_YES);
1209 if (0 == once)
1210 {
1211 delay = GNUNET_TIME_UNIT_ZERO;
1212 once = 1;
1213 }
1214 GNUNET_log (
1216 _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
1221}
1222
1223
1229static void
1231{
1235 "Testing new hostlist advertisements is allowed again\n");
1236}
1237
1238
1244static void
1246{
1247 ti_saving_task = NULL;
1249
1251 "Hostlists will be saved to file again in %s\n",
1253 GNUNET_YES));
1256}
1257
1258
1266static void *
1268 const struct GNUNET_PeerIdentity *peer,
1269 struct GNUNET_MQ_Handle *mq)
1270{
1274 gettext_noop ("# active connections"),
1275 1,
1276 GNUNET_NO);
1277 return NULL;
1278}
1279
1280
1287static void
1289 const struct GNUNET_PeerIdentity *peer,
1290 void *internal_cls)
1291{
1295 gettext_noop ("# active connections"),
1296 -1,
1297 GNUNET_NO);
1298}
1299
1300
1306static void
1308{
1309 size_t uri_size;
1310 struct Hostlist *hostlist;
1311
1312 uri_size = strlen (uri) + 1;
1314 "Hostlist client received advertisement containing URI `%s'\n",
1315 uri);
1317 {
1318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri);
1319 return;
1320 }
1321
1323 {
1324 GNUNET_log (
1326 "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
1327 return;
1328 }
1330 {
1331 GNUNET_log (
1333 "Currently not accepting new advertisements: we are already testing a hostlist\n");
1334 return;
1335 }
1336
1337 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + uri_size);
1338 hostlist->hostlist_uri = (const char *) &hostlist[1];
1339 GNUNET_memcpy (&hostlist[1], uri, uri_size);
1341 hostlist->quality = HOSTLIST_INITIAL;
1342 hostlist_to_test = hostlist;
1343
1349 NULL);
1350
1352 "Testing new hostlist advertisements is locked for the next %s\n",
1354 GNUNET_YES));
1355
1358}
1359
1360
1369static void
1370primary_task (void *cls, int success)
1371{
1372 if (NULL != ti_check_download)
1373 {
1375 ti_check_download = NULL;
1376 }
1377 sget = NULL;
1378 GNUNET_assert (NULL != stats);
1380 "Statistics request done, scheduling hostlist download\n");
1382}
1383
1384
1391static void
1393{
1395 sget = NULL;
1397}
1398
1399
1409static int
1410process_stat (void *cls,
1411 const char *subsystem,
1412 const char *name,
1413 uint64_t value,
1414 int is_persistent)
1415{
1418 "Initial time between hostlist downloads is %s\n",
1420 GNUNET_YES));
1421 return GNUNET_OK;
1422}
1423
1424
1428static void
1430{
1431 char *filename;
1432 char *uri;
1433 char *emsg;
1434 struct Hostlist *hostlist;
1435 uint32_t times_used;
1436 uint32_t hellos_returned;
1437 uint64_t quality;
1438 uint64_t last_used;
1439 uint64_t created;
1440 uint32_t counter;
1441 struct GNUNET_BIO_ReadHandle *rh;
1442
1443 uri = NULL;
1445 "HOSTLIST",
1446 "HOSTLISTFILE",
1447 &filename))
1448 {
1450 "hostlist",
1451 "HOSTLISTFILE");
1452 return;
1453 }
1454
1456 _ ("Loading saved hostlist entries from file `%s' \n"),
1457 filename);
1459 {
1461 _ ("Hostlist file `%s' does not exist\n"),
1462 filename);
1464 return;
1465 }
1466
1468 if (NULL == rh)
1469 {
1471 _ (
1472 "Could not open file `%s' for reading to load hostlists: %s\n"),
1473 filename,
1474 strerror (errno));
1476 return;
1477 }
1478
1479 counter = 0;
1480 {
1481 struct GNUNET_BIO_ReadSpec rs[] = {
1482 GNUNET_BIO_read_spec_int32 ("times used", (int32_t *) &times_used),
1483 GNUNET_BIO_read_spec_int64 ("quality", (int64_t *) &quality),
1484 GNUNET_BIO_read_spec_int64 ("last used", (int64_t *) &last_used),
1485 GNUNET_BIO_read_spec_int64 ("created", (int64_t *) &created),
1486 GNUNET_BIO_read_spec_int32 ("hellos returned",
1487 (int32_t *) &hellos_returned),
1489 };
1490 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN))
1491 &&
1492 (NULL != uri) &&
1494 {
1495 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1);
1496 hostlist->hello_count = hellos_returned;
1497 hostlist->hostlist_uri = (const char *) &hostlist[1];
1498 GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1);
1499 hostlist->quality = quality;
1500 hostlist->time_creation.abs_value_us = created;
1501 hostlist->time_last_usage.abs_value_us = last_used;
1503 ;
1506 "Added hostlist entry with URI `%s' \n",
1507 hostlist->hostlist_uri);
1508 GNUNET_free (uri);
1509 uri = NULL;
1510 counter++;
1511 if (counter >= MAX_NUMBER_HOSTLISTS)
1512 break;
1513 }
1514 }
1515
1517 _ ("%u hostlist URIs loaded from file\n"),
1518 counter);
1520 gettext_noop ("# hostlist URIs read from file"),
1521 counter,
1522 GNUNET_YES);
1524 gettext_noop ("# advertised hostlist URIs"),
1526 GNUNET_NO);
1527
1528 GNUNET_free (uri);
1529 emsg = NULL;
1530 (void) GNUNET_BIO_read_close (rh, &emsg);
1531 if (emsg != NULL)
1532 GNUNET_free (emsg);
1534}
1535
1536
1542static void
1544{
1545 char *filename;
1546 struct Hostlist *pos;
1547 struct GNUNET_BIO_WriteHandle *wh;
1548 int ok;
1549 uint32_t counter;
1550
1552 "HOSTLIST",
1553 "HOSTLISTFILE",
1554 &filename))
1555 {
1557 "hostlist",
1558 "HOSTLISTFILE");
1559 return;
1560 }
1562 {
1564 return;
1565 }
1567 if (NULL == wh)
1568 {
1570 _ (
1571 "Could not open file `%s' for writing to save hostlists: %s\n"),
1572 filename,
1573 strerror (errno));
1575 return;
1576 }
1578 _ ("Writing %u hostlist URIs to `%s'\n"),
1580 filename);
1581 /* add code to write hostlists to file using bio */
1582 ok = GNUNET_YES;
1583 counter = 0;
1584 while (NULL != (pos = linked_list_head))
1585 {
1586 if (GNUNET_YES == shutdown)
1587 {
1590 }
1591 if (GNUNET_YES == ok)
1592 {
1593 struct GNUNET_BIO_WriteSpec ws[] = {
1594 GNUNET_BIO_write_spec_string ("hostlist uri", pos->hostlist_uri),
1595 GNUNET_BIO_write_spec_int32 ("times used",
1596 (int32_t *) &pos->times_used),
1597 GNUNET_BIO_write_spec_int64 ("quality", (int64_t *) &pos->quality),
1599 "last usage",
1600 (int64_t *) &pos->time_last_usage.abs_value_us),
1602 "creation time",
1603 (int64_t *) &pos->time_creation.abs_value_us),
1604 GNUNET_BIO_write_spec_int32 ("hellos count",
1605 (int32_t *) &pos->hello_count),
1607 };
1609 {
1611 _ ("Error writing hostlist URIs to file `%s'\n"),
1612 filename);
1613 ok = GNUNET_NO;
1614 }
1615 }
1616
1617 if (GNUNET_YES == shutdown)
1618 GNUNET_free (pos);
1619 counter++;
1620 if (counter >= MAX_NUMBER_HOSTLISTS)
1621 break;
1622 }
1624 gettext_noop ("# hostlist URIs written to file"),
1625 counter,
1626 GNUNET_YES);
1627
1628 if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1630 _ ("Error writing hostlist URIs to file `%s'\n"),
1631 filename);
1633}
1634
1635
1647int
1653 int learn)
1654{
1655 char *filename;
1656 char *proxytype_str;
1657 int result;
1658
1659 GNUNET_assert (NULL != st);
1660 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
1661 {
1662 GNUNET_break (0);
1663 return GNUNET_SYSERR;
1664 }
1665 cfg = c;
1666 stats = st;
1667
1668 /* Read proxy configuration */
1670 if (GNUNET_OK ==
1671 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy))
1672 {
1673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy);
1674 /* proxy username */
1676 "HOSTLIST",
1677 "PROXY_USERNAME",
1679 {
1681 "Found proxy username name: `%s'\n",
1683 }
1684
1685 /* proxy password */
1687 "HOSTLIST",
1688 "PROXY_PASSWORD",
1690 {
1692 "Found proxy password name: `%s'\n",
1694 }
1695
1696 /* proxy type */
1698 "HOSTLIST",
1699 "PROXY_TYPE",
1700 &proxytype_str))
1701 {
1702 if (GNUNET_OK != GNUNET_STRINGS_utf8_toupper (proxytype_str,
1703 proxytype_str))
1705 "Unable to convert `%s' to UTF-8 uppercase\n",
1706 proxytype_str);
1707 proxy_type = CURLPROXY_HTTP;
1708 if (0 == strcmp (proxytype_str, "HTTP"))
1709 proxy_type = CURLPROXY_HTTP;
1710 else if (0 == strcmp (proxytype_str, "HTTP_1_0"))
1711 proxy_type = CURLPROXY_HTTP_1_0;
1712 else if (0 == strcmp (proxytype_str, "SOCKS4"))
1713 proxy_type = CURLPROXY_SOCKS4;
1714 else if (0 == strcmp (proxytype_str, "SOCKS5"))
1715 proxy_type = CURLPROXY_SOCKS5;
1716 else if (0 == strcmp (proxytype_str, "SOCKS4A"))
1717 proxy_type = CURLPROXY_SOCKS4A;
1718 else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME"))
1719 proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1720 else
1721 {
1722 GNUNET_log (
1724 _ (
1725 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n")
1726 ,
1727 proxytype_str);
1728 GNUNET_free (proxytype_str);
1730 proxy = NULL;
1732 proxy_username = NULL;
1734 proxy_password = NULL;
1735
1736 return GNUNET_SYSERR;
1737 }
1738 }
1739 GNUNET_free (proxytype_str);
1740 }
1741
1742 stat_learning = learn;
1743 *ch = &handler_connect;
1744 *dh = &handler_disconnect;
1745 linked_list_head = NULL;
1746 linked_list_tail = NULL;
1750
1752 {
1753 *msgh = &handler_advertisement;
1755 _ ("Learning is enabled on this peer\n"));
1758 "Hostlists will be saved to file again in %s\n",
1760 GNUNET_YES));
1763 NULL);
1764 }
1765 else
1766 {
1768 _ ("Learning is not enabled on this peer\n"));
1769 *msgh = NULL;
1771 "HOSTLIST",
1772 "HOSTLISTFILE",
1773 &filename))
1774 {
1776 {
1777 result = remove (filename);
1778 if (0 == result)
1779 GNUNET_log (
1781 _ (
1782 "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1783 filename);
1784 else
1786 "remove",
1787 filename);
1788 }
1789 }
1791 }
1793 "Loading stats value on hostlist download frequency\n");
1795 "hostlist",
1796 gettext_noop (
1797 "# milliseconds between hostlist downloads"),
1798 &primary_task,
1799 &process_stat,
1800 NULL);
1801 if (NULL == sget)
1802 {
1804 "Statistics request failed, scheduling hostlist download\n");
1806 }
1807 else
1808 {
1811 NULL);
1812 }
1813 return GNUNET_OK;
1814}
1815
1816
1820void
1822{
1823 struct StoreHelloEntry *pos;
1824
1825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
1826 while (NULL != (pos = she_head))
1827 {
1830 GNUNET_free (pos);
1831 }
1832 if (NULL != sget)
1833 {
1835 sget = NULL;
1836 }
1837 stats = NULL;
1840 if (NULL != ti_saving_task)
1841 {
1843 ti_saving_task = NULL;
1844 }
1845 if (NULL != ti_download_dispatcher_task)
1846 {
1849 }
1850 if (NULL != ti_testing_intervall_task)
1851 {
1854 }
1855 if (NULL != ti_download)
1856 {
1858 ti_download = NULL;
1859 update_hostlist ();
1860 clean_up ();
1861 }
1862 if (NULL != ti_check_download)
1863 {
1865 ti_check_download = NULL;
1866 curl_global_cleanup ();
1867 }
1869 proxy = NULL;
1871 proxy_username = NULL;
1873 proxy_password = NULL;
1874 if (NULL != peerstore)
1875 {
1877 peerstore = NULL;
1878 }
1879 cfg = NULL;
1880}
1881
1882
1883/* end of gnunet-daemon-hostlist_client.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define gettext_noop(String)
Definition: gettext.h:74
static int once
Global to mark if we've run the initialization.
Definition: gnsrecord.c:65
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
common internal definitions for hostlist daemon
#define MAX_URL_LEN
How long can hostlist URLs be?
#define MAX_BYTES_PER_HOSTLISTS
How many bytes do we download at most from a hostlist server?
static void task_download_dispatcher(void *cls)
static unsigned int stat_download_successful
Value saying if hostlist download was successful.
static struct GNUNET_TIME_Absolute end_time
At what time MUST the current hostlist request be done?
#define SAVING_INTERVAL
Time interval hostlists are saved to disk.
static char * proxy
Proxy hostname or ip we are using (can be NULL).
static uint64_t checked_add(uint64_t val1, uint64_t val2)
Add val2 to val1 with overflow check.
#define HOSTLIST_SUCCESSFUL_HELLO
Value added for each valid HELLO received during a hostlist download.
static void handler_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a given peer disconnects.
static int process_stat(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
We've received the previous delay value from statistics.
static void task_check(void *cls)
Task that checks if we should try to download a hostlist.
#define MAX_NUMBER_HOSTLISTS
Maximum number of hostlist that are saved.
static int stat_download_in_progress
Value controlling if a hostlist download is running at the moment.
static void task_hostlist_saving(void *cls)
Task that writes hostlist entries to a file on a regular base.
static int stat_learning
Set if we are allowed to learn new hostlists and use them.
static struct GNUNET_TIME_Relative hostlist_delay
Amount of time we wait between hostlist downloads.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
#define HOSTLIST_FAILED_DOWNLOAD
Value subtracted each time a hostlist download fails.
static void handler_advertisement(const char *uri)
Method called whenever an advertisement message arrives.
static unsigned int stat_use_bootstrap
Value saying if a preconfigured bootstrap server is used.
int GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, GNUNET_CORE_ConnectEventHandler *ch, GNUNET_CORE_DisconnectEventHandler *dh, GNUNET_HOSTLIST_UriHandler *msgh, int learn)
Start downloading hostlists from hostlist servers as necessary.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
static int stat_testing_allowed
Value controlling if a hostlist testing is allowed at the moment.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void insert_hostlist()
Method to insert a hostlist into the datastore.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to the PEERSTORE service.
static size_t download_pos
Number of bytes valid in 'download_buffer'.
static CURL * curl
Current CURL handle.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
static char * current_url
Current URL that we are using.
static char * proxy_password
Proxy password we are using (can be NULL).
static struct StoreHelloEntry * she_head
Head of the linkd list to store the store context for hellos.
static void stat_timeout_task(void *cls)
Continuation called by the statistics code once we go the stat.
static unsigned int linked_list_size
Size of the linked list used to store hostlists.
static struct GNUNET_STATISTICS_GetHandle * sget
Handle for our statistics GET operation.
#define CURL_EASY_SETOPT(c, a, b)
static struct StoreHelloEntry * she_tail
Tail of the linkd list to store the store context for hellos.
#define WAITING_INTERVAL
Time interval for download dispatcher before a download is re-scheduled.
static void load_hostlist_file()
Method to load persistent hostlist file during hostlist client startup.
static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task
ID of the task controlling the locking between two hostlist tests.
static unsigned int stat_connection_count
Number of active connections (according to core service).
static int linked_list_contains(const char *uri)
Method to check if a URI is in hostlist linked list.
static CURLM * multi
Current multi-CURL handle.
#define HOSTLIST_INITIAL
Defines concerning the hostlist quality metric.
static size_t callback_download(void *ptr, size_t size, size_t nmemb, void *ctx)
Process downloaded bits by calling callback on each HELLO.
static void shc_cont(void *cls, int success)
#define TESTING_INTERVAL
Time interval between two hostlist tests.
#define MIN_CONNECTIONS
Number of connections that we must have to NOT download hostlists anymore.
static void update_hostlist()
Method updating hostlist statistics.
static int stat_bogus_url
Set to GNUNET_YES if the current URL had some problems.
static void task_download(void *cls)
Task that is run when we are ready to receive more data from the hostlist server.
static struct Hostlist * hostlist_to_test
Head of the linked list used to store hostlists.
static void download_hostlist()
Main function that will download a hostlist and process its data.
void GNUNET_HOSTLIST_client_stop()
Stop downloading hostlists from hostlist servers as necessary.
static unsigned int stat_hellos_obtained
Value saying how many valid HELLO messages were obtained during download.
static struct Hostlist * linked_list_tail
Tail of the linked list used to store hostlists.
static struct GNUNET_SCHEDULER_Task * ti_download
ID of the task downloading the hostlist.
static struct Hostlist * current_hostlist
Current hostlist used for downloading.
static struct GNUNET_SCHEDULER_Task * ti_check_download
ID of the task, checking if hostlist download should take plate.
static char * download_get_url()
Method deciding if a preconfigured or advertisied hostlist is used on a 50:50 ratio.
static struct GNUNET_SCHEDULER_Task * ti_saving_task
ID of the task saving the hostlsit in a regular interval.
static void save_hostlist_file(int shutdown)
Method to save hostlist to a file during hostlist client shutdown.
static void * handler_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
static uint32_t stat_bytes_downloaded
How many bytes did we download from the current hostlist URL?
static char * get_bootstrap_server()
Obtain a hostlist URL that we should use.
static char * proxy_username
Proxy username we are using (can be NULL).
#define HOSTLIST_SUCCESSFUL_DOWNLOAD
Value added each time a hostlist download is successful.
static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task
ID of the task called to initiate a download.
static void clean_up()
Clean up the state from the task that downloaded the hostlist and schedule the next task.
static uint64_t checked_sub(uint64_t val1, uint64_t val2)
Subtract val2 from val1 with underflow check.
static curl_proxytype proxy_type
Proxy type we are using (can be NULL).
static struct Hostlist * linked_list_get_lowest_quality()
Method returning the hostlist element with the lowest quality in the datastore.
static void task_testing_intervall_reset(void *cls)
This tasks sets hostlist testing to allowed after interval between to testings is reached.
static void primary_task(void *cls, int success)
Continuation called by the statistics code once we go the stat.
static void download_prepare()
Ask CURL for the select set and then schedule the receiving task with the scheduler.
void(* GNUNET_HOSTLIST_UriHandler)(const char *uri)
Function that handles an advertised URI.
static struct GNUNET_FS_Handle * ctx
static char * filename
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static int result
Global testing status.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
library to make it easy to download JSON replies over HTTP
API to the peerstore service.
API to create, modify and access statistics.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
enum GNUNET_GenericReturnValue GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:556
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:508
enum GNUNET_GenericReturnValue GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition: bio.c:1106
enum GNUNET_GenericReturnValue GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string.
Definition: bio.c:330
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_string(const char *what, const char *s)
Create the specification to write a 0-terminated string.
Definition: bio.c:1199
#define GNUNET_BIO_read_spec_end()
End of specifications marker.
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int32(const char *what, int32_t *i)
Create the specification to read an (u)int32_t.
Definition: bio.c:999
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
enum GNUNET_GenericReturnValue GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1357
enum GNUNET_GenericReturnValue GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:162
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int32(const char *what, int32_t *i)
Create the specification to write an (u)int32_t.
Definition: bio.c:1244
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int64(const char *what, int64_t *i)
Create the specification to read an (u)int64_t.
Definition: bio.c:1043
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:114
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int64(const char *what, int64_t *i)
Create the specification to write an (u)int64_t.
Definition: bio.c:1289
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
void(* GNUNET_CORE_DisconnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
Method called whenever a peer disconnects.
void *(* GNUNET_CORE_ConnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:483
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:583
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MIN(a, b)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_BULK
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1187
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1041
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1171
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
void GNUNET_PEERSTORE_hello_add_cancel(struct GNUNET_PEERSTORE_StoreHelloContext *huc)
Cancel the request to add a hello.
struct GNUNET_PEERSTORE_StoreHelloContext * GNUNET_PEERSTORE_hello_add(struct GNUNET_PEERSTORE_Handle *h, const struct GNUNET_MessageHeader *msg, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Add hello to peerstore.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1834
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1303
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1276
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
struct GNUNET_STATISTICS_GetHandle * GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Callback cont, GNUNET_STATISTICS_Iterator proc, void *cls)
Get statistic from the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:481
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:344
#define GNUNET_TIME_UNIT_HOURS
One hour.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:579
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:486
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define max(x, y)
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Handle for buffered reading.
Definition: bio.c:69
Structure specifying a reading operation on an IO handle.
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
Handle for buffered writing.
Definition: bio.c:466
Structure specifying a writing operation on an IO handle.
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
collection of IO descriptors
Handle to the PEERSTORE service.
Definition: peerstore_api.c:44
Context for a add hello uri request.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:135
Linked list of things we still need to do.
Handle for the service.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
A single hostlist obtained by hostlist advertisements.
struct GNUNET_TIME_Absolute time_last_usage
Last time the hostlist was obtained.
uint64_t quality
Value describing the quality of the hostlist, the bigger the better but (should) never < 0 used for d...
struct Hostlist * prev
previous entry, used to manage entries in a double linked list
uint32_t hello_count
Number of HELLO messages obtained during last download.
struct GNUNET_TIME_Absolute time_creation
Time the hostlist advertisement was received and the entry was created.
uint32_t times_used
Number of times the hostlist was successfully obtained.
struct Hostlist * next
next entry, used to manage entries in a double linked list
const char * hostlist_uri
URI where hostlist can be obtained.
Context for a add hello uri request.
struct GNUNET_PEERSTORE_StoreHelloContext * sc
Store hello ctx.
struct StoreHelloEntry * prev
Kept (also) in a DLL.
struct StoreHelloEntry * next
Kept (also) in a DLL.