GNUnet 0.21.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 statics 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 struct GNUNET_BIO_ReadSpec rs[] = {
1481 GNUNET_BIO_read_spec_int32 ("times used", (int32_t *) &times_used),
1482 GNUNET_BIO_read_spec_int64 ("quality", (int64_t *) &quality),
1483 GNUNET_BIO_read_spec_int64 ("last used", (int64_t *) &last_used),
1484 GNUNET_BIO_read_spec_int64 ("created", (int64_t *) &created),
1485 GNUNET_BIO_read_spec_int32 ("hellos returned",
1486 (int32_t *) &hellos_returned),
1488 };
1489 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) &&
1490 (NULL != uri) &&
1492 {
1493 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1);
1494 hostlist->hello_count = hellos_returned;
1495 hostlist->hostlist_uri = (const char *) &hostlist[1];
1496 GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1);
1497 hostlist->quality = quality;
1498 hostlist->time_creation.abs_value_us = created;
1499 hostlist->time_last_usage.abs_value_us = last_used;
1503 "Added hostlist entry with URI `%s' \n",
1504 hostlist->hostlist_uri);
1505 GNUNET_free (uri);
1506 uri = NULL;
1507 counter++;
1508 if (counter >= MAX_NUMBER_HOSTLISTS)
1509 break;
1510 }
1511
1513 _ ("%u hostlist URIs loaded from file\n"),
1514 counter);
1516 gettext_noop ("# hostlist URIs read from file"),
1517 counter,
1518 GNUNET_YES);
1520 gettext_noop ("# advertised hostlist URIs"),
1522 GNUNET_NO);
1523
1524 GNUNET_free (uri);
1525 emsg = NULL;
1526 (void) GNUNET_BIO_read_close (rh, &emsg);
1527 if (emsg != NULL)
1528 GNUNET_free (emsg);
1530}
1531
1532
1538static void
1540{
1541 char *filename;
1542 struct Hostlist *pos;
1543 struct GNUNET_BIO_WriteHandle *wh;
1544 int ok;
1545 uint32_t counter;
1546
1548 "HOSTLIST",
1549 "HOSTLISTFILE",
1550 &filename))
1551 {
1553 "hostlist",
1554 "HOSTLISTFILE");
1555 return;
1556 }
1558 {
1560 return;
1561 }
1563 if (NULL == wh)
1564 {
1566 _ (
1567 "Could not open file `%s' for writing to save hostlists: %s\n"),
1568 filename,
1569 strerror (errno));
1571 return;
1572 }
1574 _ ("Writing %u hostlist URIs to `%s'\n"),
1576 filename);
1577 /* add code to write hostlists to file using bio */
1578 ok = GNUNET_YES;
1579 counter = 0;
1580 while (NULL != (pos = linked_list_head))
1581 {
1582 if (GNUNET_YES == shutdown)
1583 {
1586 }
1587 if (GNUNET_YES == ok)
1588 {
1589 struct GNUNET_BIO_WriteSpec ws[] = {
1590 GNUNET_BIO_write_spec_string ("hostlist uri", pos->hostlist_uri),
1591 GNUNET_BIO_write_spec_int32 ("times used",
1592 (int32_t *) &pos->times_used),
1593 GNUNET_BIO_write_spec_int64 ("quality", (int64_t *) &pos->quality),
1595 "last usage",
1596 (int64_t *) &pos->time_last_usage.abs_value_us),
1598 "creation time",
1599 (int64_t *) &pos->time_creation.abs_value_us),
1600 GNUNET_BIO_write_spec_int32 ("hellos count",
1601 (int32_t *) &pos->hello_count),
1603 };
1605 {
1607 _ ("Error writing hostlist URIs to file `%s'\n"),
1608 filename);
1609 ok = GNUNET_NO;
1610 }
1611 }
1612
1613 if (GNUNET_YES == shutdown)
1614 GNUNET_free (pos);
1615 counter++;
1616 if (counter >= MAX_NUMBER_HOSTLISTS)
1617 break;
1618 }
1620 gettext_noop ("# hostlist URIs written to file"),
1621 counter,
1622 GNUNET_YES);
1623
1624 if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1626 _ ("Error writing hostlist URIs to file `%s'\n"),
1627 filename);
1629}
1630
1631
1643int
1649 int learn)
1650{
1651 char *filename;
1652 char *proxytype_str;
1653 int result;
1654
1655 GNUNET_assert (NULL != st);
1656 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
1657 {
1658 GNUNET_break (0);
1659 return GNUNET_SYSERR;
1660 }
1661 cfg = c;
1662 stats = st;
1663
1664 /* Read proxy configuration */
1666 if (GNUNET_OK ==
1667 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy))
1668 {
1669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy);
1670 /* proxy username */
1672 "HOSTLIST",
1673 "PROXY_USERNAME",
1675 {
1677 "Found proxy username name: `%s'\n",
1679 }
1680
1681 /* proxy password */
1683 "HOSTLIST",
1684 "PROXY_PASSWORD",
1686 {
1688 "Found proxy password name: `%s'\n",
1690 }
1691
1692 /* proxy type */
1694 "HOSTLIST",
1695 "PROXY_TYPE",
1696 &proxytype_str))
1697 {
1698 if (GNUNET_OK != GNUNET_STRINGS_utf8_toupper (proxytype_str,
1699 proxytype_str))
1701 "Unable to convert `%s' to UTF-8 uppercase\n",
1702 proxytype_str);
1703 proxy_type = CURLPROXY_HTTP;
1704 if (0 == strcmp (proxytype_str, "HTTP"))
1705 proxy_type = CURLPROXY_HTTP;
1706 else if (0 == strcmp (proxytype_str, "HTTP_1_0"))
1707 proxy_type = CURLPROXY_HTTP_1_0;
1708 else if (0 == strcmp (proxytype_str, "SOCKS4"))
1709 proxy_type = CURLPROXY_SOCKS4;
1710 else if (0 == strcmp (proxytype_str, "SOCKS5"))
1711 proxy_type = CURLPROXY_SOCKS5;
1712 else if (0 == strcmp (proxytype_str, "SOCKS4A"))
1713 proxy_type = CURLPROXY_SOCKS4A;
1714 else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME"))
1715 proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1716 else
1717 {
1718 GNUNET_log (
1720 _ (
1721 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
1722 proxytype_str);
1723 GNUNET_free (proxytype_str);
1725 proxy = NULL;
1727 proxy_username = NULL;
1729 proxy_password = NULL;
1730
1731 return GNUNET_SYSERR;
1732 }
1733 }
1734 GNUNET_free (proxytype_str);
1735 }
1736
1737 stat_learning = learn;
1738 *ch = &handler_connect;
1739 *dh = &handler_disconnect;
1740 linked_list_head = NULL;
1741 linked_list_tail = NULL;
1745
1747 {
1748 *msgh = &handler_advertisement;
1750 _ ("Learning is enabled on this peer\n"));
1753 "Hostlists will be saved to file again in %s\n",
1755 GNUNET_YES));
1758 NULL);
1759 }
1760 else
1761 {
1763 _ ("Learning is not enabled on this peer\n"));
1764 *msgh = NULL;
1766 "HOSTLIST",
1767 "HOSTLISTFILE",
1768 &filename))
1769 {
1771 {
1772 result = remove (filename);
1773 if (0 == result)
1774 GNUNET_log (
1776 _ (
1777 "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1778 filename);
1779 else
1781 "remove",
1782 filename);
1783 }
1784 }
1786 }
1788 "Loading stats value on hostlist download frequency\n");
1790 "hostlist",
1791 gettext_noop (
1792 "# milliseconds between hostlist downloads"),
1793 &primary_task,
1794 &process_stat,
1795 NULL);
1796 if (NULL == sget)
1797 {
1799 "Statistics request failed, scheduling hostlist download\n");
1801 }
1802 else
1803 {
1806 NULL);
1807 }
1808 return GNUNET_OK;
1809}
1810
1811
1815void
1817{
1818 struct StoreHelloEntry *pos;
1819
1820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
1821 while (NULL != (pos = she_head))
1822 {
1825 GNUNET_free (pos);
1826 }
1827 if (NULL != sget)
1828 {
1830 sget = NULL;
1831 }
1832 stats = NULL;
1835 if (NULL != ti_saving_task)
1836 {
1838 ti_saving_task = NULL;
1839 }
1840 if (NULL != ti_download_dispatcher_task)
1841 {
1844 }
1845 if (NULL != ti_testing_intervall_task)
1846 {
1849 }
1850 if (NULL != ti_download)
1851 {
1853 ti_download = NULL;
1854 update_hostlist ();
1855 clean_up ();
1856 }
1857 if (NULL != ti_check_download)
1858 {
1860 ti_check_download = NULL;
1861 curl_global_cleanup ();
1862 }
1864 proxy = NULL;
1866 proxy_username = NULL;
1868 proxy_password = NULL;
1869 if (NULL != peerstore)
1870 {
1872 peerstore = NULL;
1873 }
1874 cfg = NULL;
1875}
1876
1877
1878/* 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:70
static int once
Global to mark if we've run the initialization.
Definition: gnsrecord.c:67
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
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:1108
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:1201
#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:1001
#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:1359
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:1246
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:1045
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:1291
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:482
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
#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)
@ 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:1186
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:1040
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1170
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:1836
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
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:1305
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:1278
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:472
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:343
#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:405
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:570
#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:484
#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.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
collection of IO descriptors
Handle to the PEERSTORE service.
Definition: peerstore_api.c:46
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:136
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.