GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
gnunet-daemon-hostlist_client.c File Reference

hostlist support. More...

Include dependency graph for gnunet-daemon-hostlist_client.c:

Go to the source code of this file.

Data Structures

struct  Hostlist
 A single hostlist obtained by hostlist advertisements. More...
 
struct  StoreHelloEntry
 Context for a add hello uri request. More...
 

Macros

#define MIN_CONNECTIONS   4
 Number of connections that we must have to NOT download hostlists anymore.
 
#define MAX_NUMBER_HOSTLISTS   30
 Maximum number of hostlist that are saved.
 
#define SAVING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
 Time interval hostlists are saved to disk.
 
#define TESTING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
 Time interval between two hostlist tests.
 
#define WAITING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 Time interval for download dispatcher before a download is re-scheduled.
 
#define HOSTLIST_INITIAL   10000
 Defines concerning the hostlist quality metric.
 
#define HOSTLIST_FAILED_DOWNLOAD   100
 Value subtracted each time a hostlist download fails.
 
#define HOSTLIST_SUCCESSFUL_DOWNLOAD   100
 Value added each time a hostlist download is successful.
 
#define HOSTLIST_SUCCESSFUL_HELLO   1
 Value added for each valid HELLO received during a hostlist download.
 
#define CURL_EASY_SETOPT(c, a, b)
 

Functions

static void shc_cont (void *cls, int success)
 
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 char * get_bootstrap_server ()
 Obtain a hostlist URL that we should use.
 
static char * download_get_url ()
 Method deciding if a preconfigured or advertisied hostlist is used on a 50:50 ratio.
 
static void save_hostlist_file (int shutdown)
 Method to save hostlist to a file during hostlist client shutdown.
 
static uint64_t checked_add (uint64_t val1, uint64_t val2)
 Add val2 to val1 with overflow check.
 
static uint64_t checked_sub (uint64_t val1, uint64_t val2)
 Subtract val2 from val1 with underflow check.
 
static int linked_list_contains (const char *uri)
 Method to check if a URI is in hostlist linked list.
 
static struct Hostlistlinked_list_get_lowest_quality ()
 Method returning the hostlist element with the lowest quality in the datastore.
 
static void insert_hostlist ()
 Method to insert a hostlist into the datastore.
 
static void update_hostlist ()
 Method updating hostlist statistics.
 
static void clean_up ()
 Clean up the state from the task that downloaded the hostlist and schedule the next task.
 
static void task_download (void *cls)
 Task that is run when we are ready to receive more data from the hostlist server.
 
static void download_prepare ()
 Ask CURL for the select set and then schedule the receiving task with the scheduler.
 
static void download_hostlist ()
 Main function that will download a hostlist and process its data.
 
static void task_download_dispatcher (void *cls)
 
static void task_check (void *cls)
 Task that checks if we should try to download a hostlist.
 
static void task_testing_intervall_reset (void *cls)
 This tasks sets hostlist testing to allowed after interval between to testings is reached.
 
static void task_hostlist_saving (void *cls)
 Task that writes hostlist entries to a file on a regular base.
 
static void * handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
 Method called whenever a given peer connects.
 
static void handler_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 Method called whenever a given peer disconnects.
 
static void handler_advertisement (const char *uri)
 Method called whenever an advertisement message arrives.
 
static void primary_task (void *cls, int success)
 Continuation called by the statistics code once we go the stat.
 
static void stat_timeout_task (void *cls)
 Continuation called by the statistics code once we go the stat.
 
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 load_hostlist_file ()
 Method to load persistent hostlist file during hostlist client startup.
 
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.
 
void GNUNET_HOSTLIST_client_stop ()
 Stop downloading hostlists from hostlist servers as necessary.
 

Variables

static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration.
 
static struct GNUNET_STATISTICS_Handlestats
 Statistics handle.
 
static char * proxy
 Proxy hostname or ip we are using (can be NULL).
 
static char * proxy_username
 Proxy username we are using (can be NULL).
 
static char * proxy_password
 Proxy password we are using (can be NULL).
 
static curl_proxytype proxy_type
 Proxy type we are using (can be NULL).
 
static size_t download_pos
 Number of bytes valid in 'download_buffer'.
 
static char * current_url
 Current URL that we are using.
 
static CURL * curl
 Current CURL handle.
 
static CURLM * multi
 Current multi-CURL handle.
 
static uint32_t stat_bytes_downloaded
 How many bytes did we download from the current hostlist URL?
 
static struct GNUNET_TIME_Relative hostlist_delay
 Amount of time we wait between hostlist downloads.
 
static struct GNUNET_SCHEDULER_Taskti_check_download
 ID of the task, checking if hostlist download should take plate.
 
static struct GNUNET_SCHEDULER_Taskti_download
 ID of the task downloading the hostlist.
 
static struct GNUNET_SCHEDULER_Taskti_saving_task
 ID of the task saving the hostlsit in a regular interval.
 
static struct GNUNET_SCHEDULER_Taskti_download_dispatcher_task
 ID of the task called to initiate a download.
 
static struct GNUNET_SCHEDULER_Taskti_testing_intervall_task
 ID of the task controlling the locking between two hostlist tests.
 
static struct GNUNET_TIME_Absolute end_time
 At what time MUST the current hostlist request be done?
 
static struct StoreHelloEntryshe_head
 Head of the linkd list to store the store context for hellos.
 
static struct StoreHelloEntryshe_tail
 Tail of the linkd list to store the store context for hellos.
 
static struct Hostlistlinked_list_head
 Head of the linked list used to store hostlists.
 
static struct Hostlistlinked_list_tail
 Tail of the linked list used to store hostlists.
 
static struct Hostlistcurrent_hostlist
 Current hostlist used for downloading.
 
static unsigned int linked_list_size
 Size of the linked list used to store hostlists.
 
static struct Hostlisthostlist_to_test
 Head of the linked list used to store hostlists.
 
static struct GNUNET_STATISTICS_GetHandlesget
 Handle for our statistics GET operation.
 
static int stat_bogus_url
 Set to GNUNET_YES if the current URL had some problems.
 
static int stat_testing_hostlist
 Value controlling if a hostlist is tested at the moment.
 
static int stat_testing_allowed
 Value controlling if a hostlist testing is allowed at the moment.
 
static int stat_download_in_progress
 Value controlling if a hostlist download is running at the moment.
 
static unsigned int stat_use_bootstrap
 Value saying if a preconfigured bootstrap server is used.
 
static int stat_learning
 Set if we are allowed to learn new hostlists and use them.
 
static unsigned int stat_download_successful
 Value saying if hostlist download was successful.
 
static unsigned int stat_hellos_obtained
 Value saying how many valid HELLO messages were obtained during download.
 
static unsigned int stat_connection_count
 Number of active connections (according to core service).
 
static struct GNUNET_PEERSTORE_Handlepeerstore
 Handle to the PEERSTORE service.
 

Detailed Description

hostlist support.

Downloads HELLOs via HTTP.

Author
Christian Grothoff
Matthias Wachs

Definition in file gnunet-daemon-hostlist_client.c.

Macro Definition Documentation

◆ MIN_CONNECTIONS

#define MIN_CONNECTIONS   4

Number of connections that we must have to NOT download hostlists anymore.

Definition at line 40 of file gnunet-daemon-hostlist_client.c.

◆ MAX_NUMBER_HOSTLISTS

#define MAX_NUMBER_HOSTLISTS   30

Maximum number of hostlist that are saved.

Definition at line 45 of file gnunet-daemon-hostlist_client.c.

◆ SAVING_INTERVAL

#define SAVING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)

Time interval hostlists are saved to disk.

Definition at line 50 of file gnunet-daemon-hostlist_client.c.

93{
97 struct Hostlist *prev;
98
102 struct Hostlist *next;
103
107 const char *hostlist_uri;
108
117 uint64_t quality;
118
122 struct GNUNET_TIME_Absolute time_creation;
123
127 struct GNUNET_TIME_Absolute time_last_usage;
128
132 uint32_t hello_count;
133
137 uint32_t times_used;
138};
139
143struct StoreHelloEntry
144{
148 struct StoreHelloEntry *prev;
149
153 struct StoreHelloEntry *next;
154
159};
160
164static const struct GNUNET_CONFIGURATION_Handle *cfg;
165
169static struct GNUNET_STATISTICS_Handle *stats;
170
174static char *proxy;
175
179static char *proxy_username;
180
184static char *proxy_password;
185
189static curl_proxytype proxy_type;
190
194static size_t download_pos;
195
199static char *current_url;
200
204static CURL *curl;
205
209static CURLM *multi;
210
214static uint32_t stat_bytes_downloaded;
215
220
225
230
235
240
245
249static struct GNUNET_TIME_Absolute end_time;
250
254static struct StoreHelloEntry *she_head;
255
259static struct StoreHelloEntry *she_tail;
260
264static struct Hostlist *linked_list_head;
265
269static struct Hostlist *linked_list_tail;
270
274static struct Hostlist *current_hostlist;
275
279static unsigned int linked_list_size;
280
284static struct Hostlist *hostlist_to_test;
285
289static struct GNUNET_STATISTICS_GetHandle *sget;
290
294static int stat_bogus_url;
295
299static int stat_testing_hostlist;
300
304static int stat_testing_allowed;
305
310
314static unsigned int stat_use_bootstrap;
315
319static int stat_learning;
320
324static unsigned int stat_download_successful;
325
329static unsigned int stat_hellos_obtained;
330
334static unsigned int stat_connection_count;
335
340
341
342static void
343shc_cont (void *cls, int success)
344{
345 struct StoreHelloEntry *she = cls;
346
347 she->sc = NULL;
348 if (GNUNET_YES == success)
350 "Hostlist entry stored successfully!\n");
351 else
353 "Error storing hostlist entry!\n");
355 GNUNET_free (she);
356}
357
358
368static size_t
369callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
370{
371 static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1];
372 struct StoreHelloEntry *she;
373 const char *cbuf = ptr;
374 const struct GNUNET_MessageHeader *msg;
375 size_t total;
376 size_t cpy;
377 size_t left;
378 uint16_t msize;
379
380 total = size * nmemb;
381 stat_bytes_downloaded += total;
382 if ((total == 0) || (stat_bogus_url))
383 {
384 return total; /* ok, no data or bogus data */
385 }
386
389 "# bytes downloaded from hostlist servers"),
390 (int64_t) total,
391 GNUNET_NO);
392 left = total;
393 while ((left > 0) || (download_pos > 0))
394 {
396 GNUNET_memcpy (&download_buffer[download_pos], cbuf, cpy);
397 cbuf += cpy;
398 download_pos += cpy;
399 left -= cpy;
400 if (download_pos < sizeof(struct GNUNET_MessageHeader))
401 {
402 GNUNET_assert (0 == left);
403 break;
404 }
405 msg = (const struct GNUNET_MessageHeader *) download_buffer;
406 msize = ntohs (msg->size);
407 if (msize < sizeof(struct GNUNET_MessageHeader))
408 {
410 stats,
411 gettext_noop ("# invalid HELLOs downloaded from hostlist servers"),
412 1,
413 GNUNET_NO);
415 _ ("Invalid `%s' message received from hostlist at `%s'\n"),
416 "HELLO",
419 stat_bogus_url = 1;
420 return total;
421 }
422 if (download_pos < msize)
423 {
424 GNUNET_assert (left == 0);
425 break;
426 }
428 "Received valid `%s' message from hostlist server.\n",
429 "HELLO");
431 stats,
432 gettext_noop ("# valid HELLOs downloaded from hostlist servers"),
433 1,
434 GNUNET_NO);
436 she = GNUNET_new (struct StoreHelloEntry);
438 msg,
439 shc_cont,
440 she);
441 if (NULL != she->sc)
442 {
444 }
445 else
446 GNUNET_free (she);
447 memmove (download_buffer, &download_buffer[msize], download_pos - msize);
448 download_pos -= msize;
449 }
450 return total;
451}
452
453
459static char *
461{
462 char *servers;
463 char *ret;
464 size_t urls;
465 size_t pos;
466
468 "HOSTLIST",
469 "SERVERS",
470 &servers))
471 {
473 "hostlist",
474 "SERVERS");
475 return NULL;
476 }
477
478 urls = 0;
479 if (strlen (servers) > 0)
480 {
481 urls++;
482 pos = strlen (servers) - 1;
483 while (pos > 0)
484 {
485 if (servers[pos] == ' ')
486 urls++;
487 pos--;
488 }
489 }
490 if (urls == 0)
491 {
493 "hostlist",
494 "SERVERS");
495 GNUNET_free (servers);
496 return NULL;
497 }
498
500 pos = strlen (servers) - 1;
501 while (pos > 0)
502 {
503 if (servers[pos] == ' ')
504 {
505 urls--;
506 servers[pos] = '\0';
507 }
508 if (urls == 0)
509 {
510 pos++;
511 break;
512 }
513 pos--;
514 }
515 ret = GNUNET_strdup (&servers[pos]);
516 GNUNET_free (servers);
517 return ret;
518}
519
520
525static char *
527{
528 uint32_t index;
529 unsigned int counter;
530 struct Hostlist *pos;
531
533 {
535 "Using preconfigured bootstrap server\n");
536 current_hostlist = NULL;
537 return get_bootstrap_server ();
538 }
539
541 {
543 "Testing new advertised hostlist if it is obtainable\n");
546 }
547
549 {
551 "Using preconfigured bootstrap server\n");
552 current_hostlist = NULL;
553 return get_bootstrap_server ();
554 }
555 index =
557 counter = 0;
558 pos = linked_list_head;
559 while (counter < index)
560 {
561 pos = pos->next;
562 counter++;
563 }
565 "Using learned hostlist `%s'\n",
566 pos->hostlist_uri);
567 current_hostlist = pos;
568 return GNUNET_strdup (pos->hostlist_uri);
569}
570
571
572#define CURL_EASY_SETOPT(c, a, b) \
573 do \
574 { \
575 ret = curl_easy_setopt (c, a, b); \
576 if (CURLE_OK != ret) \
577 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
578 _ ("%s failed at %s:%d: `%s'\n"), \
579 "curl_easy_setopt", \
580 __FILE__, \
581 __LINE__, \
582 curl_easy_strerror (ret)); \
583 } while (0)
584
585
591static void
592save_hostlist_file (int shutdown);
593
594
602static uint64_t
603checked_add (uint64_t val1, uint64_t val2)
604{
605 static uint64_t temp;
606 static uint64_t maxv;
607
608 maxv = 0;
609 maxv--;
610
611 temp = val1 + val2;
612 if (temp < val1)
613 return maxv;
614 return temp;
615}
616
617
625static uint64_t
626checked_sub (uint64_t val1, uint64_t val2)
627{
628 if (val1 <= val2)
629 return 0;
630 return(val1 - val2);
631}
632
633
640static int
641linked_list_contains (const char *uri)
642{
643 struct Hostlist *pos;
644
645 pos = linked_list_head;
646 while (pos != NULL)
647 {
648 if (0 == strcmp (pos->hostlist_uri, uri))
649 return GNUNET_YES;
650 pos = pos->next;
651 }
652 return GNUNET_NO;
653}
654
655
660static struct Hostlist *
662{
663 struct Hostlist *pos;
664 struct Hostlist *lowest;
665
666 if (linked_list_size == 0)
667 return NULL;
668 lowest = linked_list_head;
669 pos = linked_list_head->next;
670 while (pos != NULL)
671 {
672 if (pos->quality < lowest->quality)
673 lowest = pos;
674 pos = pos->next;
675 }
676 return lowest;
677}
678
679
685static void
687{
688 struct Hostlist *lowest_quality;
689
691 {
692 /* No free entries available, replace existing entry */
693 lowest_quality = linked_list_get_lowest_quality ();
694 GNUNET_assert (lowest_quality != NULL);
695 GNUNET_log (
697 "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n",
698 lowest_quality->hostlist_uri,
699 (unsigned long long) lowest_quality->quality);
702 lowest_quality);
704 GNUNET_free (lowest_quality);
705 }
711 gettext_noop ("# advertised hostlist URIs"),
713 GNUNET_NO);
715}
716
717
721static void
723{
724 char *stat;
725
726 if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) ||
728 {
730 "Updating hostlist statistics for URI `%s'\n",
738 {
742 GNUNET_asprintf (&stat,
743 gettext_noop ("# advertised URI `%s' downloaded"),
745
747 GNUNET_free (stat);
748 }
749 else
752 }
753 current_hostlist = NULL;
754 /* Alternating the usage of preconfigured and learned hostlists */
755
757 return;
758
760 {
763 else
765 }
766 else
768}
769
770
775static void
776clean_up ()
777{
778 CURLMcode mret;
779
782 {
783 GNUNET_log (
785 _ (
786 "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"),
788 }
789
791 {
793 }
794 if (NULL != hostlist_to_test)
795 {
797 hostlist_to_test = NULL;
798 }
799
800 if (NULL != multi)
801 {
802 mret = curl_multi_remove_handle (multi, curl);
803 if (mret != CURLM_OK)
804 {
806 _ ("%s failed at %s:%d: `%s'\n"),
807 "curl_multi_remove_handle",
808 __FILE__,
809 __LINE__,
810 curl_multi_strerror (mret));
811 }
812 mret = curl_multi_cleanup (multi);
813 if (mret != CURLM_OK)
815 _ ("%s failed at %s:%d: `%s'\n"),
816 "curl_multi_cleanup",
817 __FILE__,
818 __LINE__,
819 curl_multi_strerror (mret));
820 multi = NULL;
821 }
822 if (NULL != curl)
823 {
824 curl_easy_cleanup (curl);
825 curl = NULL;
826 }
828 current_url = NULL;
831}
832
833
840static void
841task_download (void *cls);
842
843
848static void
850{
851 CURLMcode mret;
852 fd_set rs;
853 fd_set ws;
854 fd_set es;
855 int max;
856 struct GNUNET_NETWORK_FDSet *grs;
857 struct GNUNET_NETWORK_FDSet *gws;
858 long timeout;
859 struct GNUNET_TIME_Relative rtime;
860
861 max = -1;
862 FD_ZERO (&rs);
863 FD_ZERO (&ws);
864 FD_ZERO (&es);
865 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
866 if (mret != CURLM_OK)
867 {
869 _ ("%s failed at %s:%d: `%s'\n"),
870 "curl_multi_fdset",
871 __FILE__,
872 __LINE__,
873 curl_multi_strerror (mret));
874 clean_up ();
875 return;
876 }
877 mret = curl_multi_timeout (multi, &timeout);
878 if (mret != CURLM_OK)
879 {
881 _ ("%s failed at %s:%d: `%s'\n"),
882 "curl_multi_timeout",
883 __FILE__,
884 __LINE__,
885 curl_multi_strerror (mret));
886 clean_up ();
887 return;
888 }
897 "Scheduling task for hostlist download using cURL\n");
899 rtime,
900 grs,
901 gws,
903 multi);
906}
907
908
909static void
910task_download (void *cls)
911{
912 int running;
913 struct CURLMsg *msg;
914 CURLMcode mret;
915
916 ti_download = NULL;
917 if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
918 {
920 _ ("Timeout trying to download hostlist from `%s'\n"),
923 clean_up ();
924 return;
925 }
927 "Ready for processing hostlist client request\n");
928 do
929 {
930 running = 0;
932 {
934 _ (
935 "Download limit of %u bytes exceeded, stopping download\n"),
937 clean_up ();
938 return;
939 }
940 mret = curl_multi_perform (multi, &running);
941 if (running == 0)
942 {
943 do
944 {
945 msg = curl_multi_info_read (multi, &running);
946 GNUNET_break (msg != NULL);
947 if (msg == NULL)
948 break;
949 switch (msg->msg)
950 {
951 case CURLMSG_DONE:
952 if ((msg->data.result != CURLE_OK) &&
953 (msg->data.result != CURLE_GOT_NOTHING))
955 _ ("Download of hostlist from `%s' failed: `%s'\n"),
957 curl_easy_strerror (msg->data.result));
958 else
959 {
961 _ ("Download of hostlist `%s' completed.\n"),
966 {
967 GNUNET_log (
969 _ ("Adding successfully tested hostlist `%s' datastore.\n"),
972 hostlist_to_test = NULL;
974 }
975 }
976 clean_up ();
977 return;
978
979 default:
980 break;
981 }
982 }
983 while ((running > 0));
984 }
985 }
986 while (mret == CURLM_CALL_MULTI_PERFORM);
987
988 if (mret != CURLM_OK)
989 {
991 _ ("%s failed at %s:%d: `%s'\n"),
992 "curl_multi_perform",
993 __FILE__,
994 __LINE__,
995 curl_multi_strerror (mret));
996 clean_up ();
997 }
999}
1000
1001
1006static void
1008{
1009 CURLcode ret;
1010 CURLMcode mret;
1011
1012
1014 if (current_url == NULL)
1015 return;
1016 curl = curl_easy_init ();
1017 multi = NULL;
1018 if (curl == NULL)
1019 {
1020 GNUNET_break (0);
1021 clean_up ();
1022 return;
1023 }
1025 _ ("Bootstrapping using hostlist at `%s'.\n"),
1026 current_url);
1027
1032
1034 gettext_noop ("# hostlist downloads initiated"),
1035 1,
1036 GNUNET_NO);
1037 if (NULL != proxy)
1038 {
1039 CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy);
1040 CURL_EASY_SETOPT (curl, CURLOPT_PROXYTYPE, proxy_type);
1041 if (NULL != proxy_username)
1042 CURL_EASY_SETOPT (curl, CURLOPT_PROXYUSERNAME, proxy_username);
1043 if (NULL != proxy_password)
1044 CURL_EASY_SETOPT (curl, CURLOPT_PROXYPASSWORD, proxy_password);
1045 }
1046 download_pos = 0;
1047 stat_bogus_url = 0;
1048 CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download);
1049 if (ret != CURLE_OK)
1050 {
1051 clean_up ();
1052 return;
1053 }
1054 CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL);
1055 if (ret != CURLE_OK)
1056 {
1057 clean_up ();
1058 return;
1059 }
1060 CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
1061#ifdef CURLOPT_REDIR_PROTOCOLS_STR
1062 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1063 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl,
1064 CURLOPT_REDIR_PROTOCOLS_STR,
1065 "https"));
1066 else
1067 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl,
1068 CURLOPT_REDIR_PROTOCOLS_STR,
1069 "http,https"));
1070#else
1071#ifdef CURLOPT_REDIR_PROTOCOLS
1072 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1073 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS,
1074 CURLPROTO_HTTPS));
1075 else
1076 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS,
1077 CURLPROTO_HTTP
1078 | CURLPROTO_HTTPS));
1079#endif
1080#endif
1081#ifdef CURLOPT_PROTOCOLS_STR
1082 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1083 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR,
1084 "https"));
1085 else
1086 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR,
1087 "http,https"));
1088#else
1089#ifdef CURLOPT_PROTOCOLS
1090 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1091 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS,
1092 CURLPROTO_HTTPS));
1093 else
1094 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS,
1095 CURLPROTO_HTTP
1096 | CURLPROTO_HTTPS));
1097#endif
1098#endif
1099 CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
1100 /* no need to abort if the above failed */
1101 CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url);
1102 if (ret != CURLE_OK)
1103 {
1104 clean_up ();
1105 return;
1106 }
1107 CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1);
1108#if 0
1109 CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1);
1110#endif
1111 CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE);
1112 if (0 == strncmp (current_url, "http", 4))
1113 CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet");
1114 CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L);
1115 CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L);
1116 multi = curl_multi_init ();
1117 if (multi == NULL)
1118 {
1119 GNUNET_break (0);
1120 /* clean_up (); */
1121 return;
1122 }
1123 mret = curl_multi_add_handle (multi, curl);
1124 if (mret != CURLM_OK)
1125 {
1127 _ ("%s failed at %s:%d: `%s'\n"),
1128 "curl_multi_add_handle",
1129 __FILE__,
1130 __LINE__,
1131 curl_multi_strerror (mret));
1132 mret = curl_multi_cleanup (multi);
1133 if (mret != CURLM_OK)
1135 _ ("%s failed at %s:%d: `%s'\n"),
1136 "curl_multi_cleanup",
1137 __FILE__,
1138 __LINE__,
1139 curl_multi_strerror (mret));
1140 multi = NULL;
1141 clean_up ();
1142 return;
1143 }
1146}
1147
1148
1149static void
1150task_download_dispatcher (void *cls)
1151{
1153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
1155 {
1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n");
1158 }
1159 else
1160 {
1162 "Download in progress, have to wait...\n");
1166 NULL);
1167 }
1168}
1169
1170
1176static void
1177task_check (void *cls)
1178{
1179 static int once;
1180 struct GNUNET_TIME_Relative delay;
1181
1182 ti_check_download = NULL;
1183 if (stats == NULL)
1184 {
1185 curl_global_cleanup ();
1186 return; /* in shutdown */
1187 }
1192
1193 delay = hostlist_delay;
1196 else
1199 GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count))
1202 (1 + stat_connection_count));
1204 gettext_noop (
1205 "# milliseconds between hostlist downloads"),
1207 GNUNET_YES);
1208 if (0 == once)
1209 {
1210 delay = GNUNET_TIME_UNIT_ZERO;
1211 once = 1;
1212 }
1213 GNUNET_log (
1215 _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
1220}
1221
1222
1228static void
1230{
1234 "Testing new hostlist advertisements is allowed again\n");
1235}
1236
1237
1243static void
1244task_hostlist_saving (void *cls)
1245{
1246 ti_saving_task = NULL;
1248
1250 "Hostlists will be saved to file again in %s\n",
1252 GNUNET_YES));
1255}
1256
1257
1266static void *
1267handler_connect (void *cls,
1268 const struct GNUNET_PeerIdentity *peer,
1269 struct GNUNET_MQ_Handle *mq,
1270 enum GNUNET_CORE_PeerClass class)
1271{
1275 gettext_noop ("# active connections"),
1276 1,
1277 GNUNET_NO);
1278 return NULL;
1279}
1280
1281
1288static void
1289handler_disconnect (void *cls,
1290 const struct GNUNET_PeerIdentity *peer,
1291 void *internal_cls)
1292{
1296 gettext_noop ("# active connections"),
1297 -1,
1298 GNUNET_NO);
1299}
1300
1301
1307static void
1308handler_advertisement (const char *uri)
1309{
1310 size_t uri_size;
1311 struct Hostlist *hostlist;
1312
1313 uri_size = strlen (uri) + 1;
1315 "Hostlist client received advertisement containing URI `%s'\n",
1316 uri);
1318 {
1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri);
1320 return;
1321 }
1322
1324 {
1325 GNUNET_log (
1327 "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
1328 return;
1329 }
1331 {
1332 GNUNET_log (
1334 "Currently not accepting new advertisements: we are already testing a hostlist\n");
1335 return;
1336 }
1337
1338 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + uri_size);
1339 hostlist->hostlist_uri = (const char *) &hostlist[1];
1340 GNUNET_memcpy (&hostlist[1], uri, uri_size);
1342 hostlist->quality = HOSTLIST_INITIAL;
1343 hostlist_to_test = hostlist;
1344
1350 NULL);
1351
1353 "Testing new hostlist advertisements is locked for the next %s\n",
1355 GNUNET_YES));
1356
1359}
1360
1361
1370static void
1371primary_task (void *cls, int success)
1372{
1373 if (NULL != ti_check_download)
1374 {
1376 ti_check_download = NULL;
1377 }
1378 sget = NULL;
1379 GNUNET_assert (NULL != stats);
1381 "Statistics request done, scheduling hostlist download\n");
1383}
1384
1385
1392static void
1393stat_timeout_task (void *cls)
1394{
1396 sget = NULL;
1398}
1399
1400
1410static int
1411process_stat (void *cls,
1412 const char *subsystem,
1413 const char *name,
1414 uint64_t value,
1415 int is_persistent)
1416{
1419 "Initial time between hostlist downloads is %s\n",
1421 GNUNET_YES));
1422 return GNUNET_OK;
1423}
1424
1425
1429static void
1431{
1432 char *filename;
1433 char *uri;
1434 char *emsg;
1435 struct Hostlist *hostlist;
1436 uint32_t times_used;
1437 uint32_t hellos_returned;
1438 uint64_t quality;
1439 uint64_t last_used;
1440 uint64_t created;
1441 uint32_t counter;
1442 struct GNUNET_BIO_ReadHandle *rh;
1443
1444 uri = NULL;
1446 "HOSTLIST",
1447 "HOSTLISTFILE",
1448 &filename))
1449 {
1451 "hostlist",
1452 "HOSTLISTFILE");
1453 return;
1454 }
1455
1457 _ ("Loading saved hostlist entries from file `%s' \n"),
1458 filename);
1460 {
1462 _ ("Hostlist file `%s' does not exist\n"),
1463 filename);
1465 return;
1466 }
1467
1469 if (NULL == rh)
1470 {
1472 _ (
1473 "Could not open file `%s' for reading to load hostlists: %s\n"),
1474 filename,
1475 strerror (errno));
1477 return;
1478 }
1479
1480 counter = 0;
1481 {
1482 struct GNUNET_BIO_ReadSpec rs[] = {
1483 GNUNET_BIO_read_spec_int32 ("times used", (int32_t *) &times_used),
1484 GNUNET_BIO_read_spec_int64 ("quality", (int64_t *) &quality),
1485 GNUNET_BIO_read_spec_int64 ("last used", (int64_t *) &last_used),
1486 GNUNET_BIO_read_spec_int64 ("created", (int64_t *) &created),
1487 GNUNET_BIO_read_spec_int32 ("hellos returned",
1488 (int32_t *) &hellos_returned),
1490 };
1491 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN))
1492 &&
1493 (NULL != uri) &&
1495 {
1496 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1);
1497 hostlist->hello_count = hellos_returned;
1498 hostlist->hostlist_uri = (const char *) &hostlist[1];
1499 GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1);
1500 hostlist->quality = quality;
1501 hostlist->time_creation.abs_value_us = created;
1502 hostlist->time_last_usage.abs_value_us = last_used;
1504 ;
1507 "Added hostlist entry with URI `%s' \n",
1508 hostlist->hostlist_uri);
1509 GNUNET_free (uri);
1510 uri = NULL;
1511 counter++;
1512 if (counter >= MAX_NUMBER_HOSTLISTS)
1513 break;
1514 }
1515 }
1516
1518 _ ("%u hostlist URIs loaded from file\n"),
1519 counter);
1521 gettext_noop ("# hostlist URIs read from file"),
1522 counter,
1523 GNUNET_YES);
1525 gettext_noop ("# advertised hostlist URIs"),
1527 GNUNET_NO);
1528
1529 GNUNET_free (uri);
1530 emsg = NULL;
1531 (void) GNUNET_BIO_read_close (rh, &emsg);
1532 if (emsg != NULL)
1533 GNUNET_free (emsg);
1535}
1536
1537
1543static void
1544save_hostlist_file (int shutdown)
1545{
1546 char *filename;
1547 struct Hostlist *pos;
1548 struct GNUNET_BIO_WriteHandle *wh;
1549 int ok;
1550 uint32_t counter;
1551
1553 "HOSTLIST",
1554 "HOSTLISTFILE",
1555 &filename))
1556 {
1558 "hostlist",
1559 "HOSTLISTFILE");
1560 return;
1561 }
1563 {
1565 return;
1566 }
1568 if (NULL == wh)
1569 {
1571 _ (
1572 "Could not open file `%s' for writing to save hostlists: %s\n"),
1573 filename,
1574 strerror (errno));
1576 return;
1577 }
1579 _ ("Writing %u hostlist URIs to `%s'\n"),
1581 filename);
1582 /* add code to write hostlists to file using bio */
1583 ok = GNUNET_YES;
1584 counter = 0;
1585 while (NULL != (pos = linked_list_head))
1586 {
1587 if (GNUNET_YES == shutdown)
1588 {
1591 }
1592 if (GNUNET_YES == ok)
1593 {
1594 struct GNUNET_BIO_WriteSpec ws[] = {
1595 GNUNET_BIO_write_spec_string ("hostlist uri", pos->hostlist_uri),
1596 GNUNET_BIO_write_spec_int32 ("times used",
1597 (int32_t *) &pos->times_used),
1598 GNUNET_BIO_write_spec_int64 ("quality", (int64_t *) &pos->quality),
1600 "last usage",
1601 (int64_t *) &pos->time_last_usage.abs_value_us),
1603 "creation time",
1604 (int64_t *) &pos->time_creation.abs_value_us),
1605 GNUNET_BIO_write_spec_int32 ("hellos count",
1606 (int32_t *) &pos->hello_count),
1608 };
1610 {
1612 _ ("Error writing hostlist URIs to file `%s'\n"),
1613 filename);
1614 ok = GNUNET_NO;
1615 }
1616 }
1617
1618 if (GNUNET_YES == shutdown)
1619 GNUNET_free (pos);
1620 counter++;
1621 if (counter >= MAX_NUMBER_HOSTLISTS)
1622 break;
1623 }
1625 gettext_noop ("# hostlist URIs written to file"),
1626 counter,
1627 GNUNET_YES);
1628
1629 if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1631 _ ("Error writing hostlist URIs to file `%s'\n"),
1632 filename);
1634}
1635
1636
1648int
1654 int learn)
1655{
1656 char *filename;
1657 char *proxytype_str;
1658 int result;
1659
1660 GNUNET_assert (NULL != st);
1661 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
1662 {
1663 GNUNET_break (0);
1664 return GNUNET_SYSERR;
1665 }
1666 cfg = c;
1667 stats = st;
1668
1669 /* Read proxy configuration */
1671 if (GNUNET_OK ==
1672 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy))
1673 {
1674 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy);
1675 /* proxy username */
1677 "HOSTLIST",
1678 "PROXY_USERNAME",
1680 {
1682 "Found proxy username name: `%s'\n",
1684 }
1685
1686 /* proxy password */
1688 "HOSTLIST",
1689 "PROXY_PASSWORD",
1691 {
1693 "Found proxy password name: `%s'\n",
1695 }
1696
1697 /* proxy type */
1699 "HOSTLIST",
1700 "PROXY_TYPE",
1701 &proxytype_str))
1702 {
1703 if (GNUNET_OK != GNUNET_STRINGS_utf8_toupper (proxytype_str,
1704 proxytype_str))
1706 "Unable to convert `%s' to UTF-8 uppercase\n",
1707 proxytype_str);
1708 proxy_type = CURLPROXY_HTTP;
1709 if (0 == strcmp (proxytype_str, "HTTP"))
1710 proxy_type = CURLPROXY_HTTP;
1711 else if (0 == strcmp (proxytype_str, "HTTP_1_0"))
1712 proxy_type = CURLPROXY_HTTP_1_0;
1713 else if (0 == strcmp (proxytype_str, "SOCKS4"))
1714 proxy_type = CURLPROXY_SOCKS4;
1715 else if (0 == strcmp (proxytype_str, "SOCKS5"))
1716 proxy_type = CURLPROXY_SOCKS5;
1717 else if (0 == strcmp (proxytype_str, "SOCKS4A"))
1718 proxy_type = CURLPROXY_SOCKS4A;
1719 else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME"))
1720 proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1721 else
1722 {
1723 GNUNET_log (
1725 _ (
1726 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n")
1727 ,
1728 proxytype_str);
1729 GNUNET_free (proxytype_str);
1731 proxy = NULL;
1733 proxy_username = NULL;
1735 proxy_password = NULL;
1736
1737 return GNUNET_SYSERR;
1738 }
1739 }
1740 GNUNET_free (proxytype_str);
1741 }
1742
1743 stat_learning = learn;
1744 *ch = &handler_connect;
1745 *dh = &handler_disconnect;
1746 linked_list_head = NULL;
1747 linked_list_tail = NULL;
1751
1753 {
1754 *msgh = &handler_advertisement;
1756 _ ("Learning is enabled on this peer\n"));
1759 "Hostlists will be saved to file again in %s\n",
1761 GNUNET_YES));
1764 NULL);
1765 }
1766 else
1767 {
1769 _ ("Learning is not enabled on this peer\n"));
1770 *msgh = NULL;
1772 "HOSTLIST",
1773 "HOSTLISTFILE",
1774 &filename))
1775 {
1777 {
1778 result = remove (filename);
1779 if (0 == result)
1780 GNUNET_log (
1782 _ (
1783 "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1784 filename);
1785 else
1787 "remove",
1788 filename);
1789 }
1790 }
1792 }
1794 "Loading stats value on hostlist download frequency\n");
1796 "hostlist",
1797 gettext_noop (
1798 "# milliseconds between hostlist downloads"),
1799 &primary_task,
1800 &process_stat,
1801 NULL);
1802 if (NULL == sget)
1803 {
1805 "Statistics request failed, scheduling hostlist download\n");
1807 }
1808 else
1809 {
1812 NULL);
1813 }
1814 return GNUNET_OK;
1815}
1816
1817
1821void
1823{
1824 struct StoreHelloEntry *pos;
1825
1826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
1827 while (NULL != (pos = she_head))
1828 {
1831 GNUNET_free (pos);
1832 }
1833 if (NULL != sget)
1834 {
1836 sget = NULL;
1837 }
1838 stats = NULL;
1841 if (NULL != ti_saving_task)
1842 {
1844 ti_saving_task = NULL;
1845 }
1846 if (NULL != ti_download_dispatcher_task)
1847 {
1850 }
1851 if (NULL != ti_testing_intervall_task)
1852 {
1855 }
1856 if (NULL != ti_download)
1857 {
1859 ti_download = NULL;
1860 update_hostlist ();
1861 clean_up ();
1862 }
1863 if (NULL != ti_check_download)
1864 {
1866 ti_check_download = NULL;
1867 curl_global_cleanup ();
1868 }
1870 proxy = NULL;
1872 proxy_username = NULL;
1874 proxy_password = NULL;
1875 if (NULL != peerstore)
1876 {
1878 peerstore = NULL;
1879 }
1880 cfg = NULL;
1881}
1882
1883
1884/* end of gnunet-daemon-hostlist_client.c */
struct GNUNET_MessageHeader * msg
Definition 005.c:2
#define gettext_noop(String)
Definition gettext.h:74
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.
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
#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 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.
static void * handler_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
Method called whenever a given peer connects.
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 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 char * hostlist_uri
Buffer for the hostlist address.
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 int once
Option -i.
Definition gnunet-pils.c:39
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 struct GNUNET_SCHEDULER_Task * stat_timeout_task
Task to timeout stat GET.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
#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.
GNUNET_CORE_PeerClass
The peer class gives a hint about the capabilities of a peer.
void *(* GNUNET_CORE_ConnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
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:533
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:633
#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:1185
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:1169
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:1835
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
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:1304
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:1277
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:497
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:599
#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:179
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
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.
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.

◆ TESTING_INTERVAL

#define TESTING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)

Time interval between two hostlist tests.

Definition at line 56 of file gnunet-daemon-hostlist_client.c.

◆ WAITING_INTERVAL

#define WAITING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)

Time interval for download dispatcher before a download is re-scheduled.

Definition at line 62 of file gnunet-daemon-hostlist_client.c.

◆ HOSTLIST_INITIAL

#define HOSTLIST_INITIAL   10000

Defines concerning the hostlist quality metric.

Initial quality of a new created hostlist

Definition at line 72 of file gnunet-daemon-hostlist_client.c.

◆ HOSTLIST_FAILED_DOWNLOAD

#define HOSTLIST_FAILED_DOWNLOAD   100

Value subtracted each time a hostlist download fails.

Definition at line 77 of file gnunet-daemon-hostlist_client.c.

◆ HOSTLIST_SUCCESSFUL_DOWNLOAD

#define HOSTLIST_SUCCESSFUL_DOWNLOAD   100

Value added each time a hostlist download is successful.

Definition at line 82 of file gnunet-daemon-hostlist_client.c.

◆ HOSTLIST_SUCCESSFUL_HELLO

#define HOSTLIST_SUCCESSFUL_HELLO   1

Value added for each valid HELLO received during a hostlist download.

Definition at line 87 of file gnunet-daemon-hostlist_client.c.

◆ CURL_EASY_SETOPT

#define CURL_EASY_SETOPT (   c,
  a,
 
)
Value:
do \
{ \
ret = curl_easy_setopt (c, a, b); \
if (CURLE_OK != ret) \
_ ("%s failed at %s:%d: `%s'\n"), \
"curl_easy_setopt", \
__FILE__, \
__LINE__, \
curl_easy_strerror (ret)); \
} while (0)

Definition at line 573 of file gnunet-daemon-hostlist_client.c.

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)

Function Documentation

◆ shc_cont()

static void shc_cont ( void *  cls,
int  success 
)
static

Definition at line 344 of file gnunet-daemon-hostlist_client.c.

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}

References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_YES, StoreHelloEntry::sc, she_head, and she_tail.

Referenced by callback_download().

Here is the caller graph for this function:

◆ callback_download()

static size_t callback_download ( void *  ptr,
size_t  size,
size_t  nmemb,
void *  ctx 
)
static

Process downloaded bits by calling callback on each HELLO.

Parameters
ptrbuffer with downloaded data
sizesize of a record
nmembnumber of records downloaded
ctxunused
Returns
number of bytes that were processed (always size*nmemb)

Definition at line 370 of file gnunet-daemon-hostlist_client.c.

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}

References _, current_url, download_pos, gettext_noop, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MIN, GNUNET_new, GNUNET_NO, GNUNET_PEERSTORE_hello_add(), GNUNET_STATISTICS_update(), msg, peerstore, StoreHelloEntry::sc, shc_cont(), she_head, she_tail, GNUNET_MessageHeader::size, size, stat_bogus_url, stat_bytes_downloaded, stat_hellos_obtained, and stats.

Referenced by download_hostlist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_bootstrap_server()

static char * get_bootstrap_server ( )
static

Obtain a hostlist URL that we should use.

Returns
NULL if there is no URL available

Definition at line 461 of file gnunet-daemon-hostlist_client.c.

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}

References cfg, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_strdup, and ret.

Referenced by download_get_url().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_get_url()

static char * download_get_url ( )
static

Method deciding if a preconfigured or advertisied hostlist is used on a 50:50 ratio.

Returns
uri to use, NULL if there is no URL available

Definition at line 527 of file gnunet-daemon-hostlist_client.c.

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}

References current_hostlist, get_bootstrap_server(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_strdup, GNUNET_YES, hostlist_to_test, Hostlist::hostlist_uri, linked_list_head, linked_list_size, Hostlist::next, stat_learning, stat_testing_hostlist, and stat_use_bootstrap.

Referenced by download_hostlist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_hostlist_file()

static void save_hostlist_file ( int  shutdown)
static

Method to save hostlist to a file during hostlist client shutdown.

Method to save persistent hostlist file during hostlist client shutdown.

Parameters
shutdownset if called because of shutdown, entries in linked list will be destroyed

Definition at line 1545 of file gnunet-daemon-hostlist_client.c.

1546{
1547 char *filename;
1548 struct Hostlist *pos;
1549 struct GNUNET_BIO_WriteHandle *wh;
1550 int ok;
1551 uint32_t counter;
1552
1554 "HOSTLIST",
1555 "HOSTLISTFILE",
1556 &filename))
1557 {
1559 "hostlist",
1560 "HOSTLISTFILE");
1561 return;
1562 }
1564 {
1566 return;
1567 }
1569 if (NULL == wh)
1570 {
1572 _ (
1573 "Could not open file `%s' for writing to save hostlists: %s\n"),
1574 filename,
1575 strerror (errno));
1577 return;
1578 }
1580 _ ("Writing %u hostlist URIs to `%s'\n"),
1582 filename);
1583 /* add code to write hostlists to file using bio */
1584 ok = GNUNET_YES;
1585 counter = 0;
1586 while (NULL != (pos = linked_list_head))
1587 {
1588 if (GNUNET_YES == shutdown)
1589 {
1592 }
1593 if (GNUNET_YES == ok)
1594 {
1595 struct GNUNET_BIO_WriteSpec ws[] = {
1596 GNUNET_BIO_write_spec_string ("hostlist uri", pos->hostlist_uri),
1597 GNUNET_BIO_write_spec_int32 ("times used",
1598 (int32_t *) &pos->times_used),
1599 GNUNET_BIO_write_spec_int64 ("quality", (int64_t *) &pos->quality),
1601 "last usage",
1602 (int64_t *) &pos->time_last_usage.abs_value_us),
1604 "creation time",
1605 (int64_t *) &pos->time_creation.abs_value_us),
1606 GNUNET_BIO_write_spec_int32 ("hellos count",
1607 (int32_t *) &pos->hello_count),
1609 };
1611 {
1613 _ ("Error writing hostlist URIs to file `%s'\n"),
1614 filename);
1615 ok = GNUNET_NO;
1616 }
1617 }
1618
1619 if (GNUNET_YES == shutdown)
1620 GNUNET_free (pos);
1621 counter++;
1622 if (counter >= MAX_NUMBER_HOSTLISTS)
1623 break;
1624 }
1626 gettext_noop ("# hostlist URIs written to file"),
1627 counter,
1628 GNUNET_YES);
1629
1630 if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1632 _ ("Error writing hostlist URIs to file `%s'\n"),
1633 filename);
1635}

References _, GNUNET_TIME_Absolute::abs_value_us, cfg, filename, gettext_noop, GNUNET_BIO_write_close(), GNUNET_BIO_write_open_file(), GNUNET_BIO_write_spec_commit(), GNUNET_BIO_write_spec_end, GNUNET_BIO_write_spec_int32(), GNUNET_BIO_write_spec_int64(), GNUNET_BIO_write_spec_string(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_YES, Hostlist::hello_count, Hostlist::hostlist_uri, linked_list_head, linked_list_size, linked_list_tail, MAX_NUMBER_HOSTLISTS, Hostlist::quality, stats, Hostlist::time_creation, Hostlist::time_last_usage, Hostlist::times_used, and GNUNET_BIO_WriteSpec::wh.

Referenced by GNUNET_HOSTLIST_client_stop(), and task_hostlist_saving().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checked_add()

static uint64_t checked_add ( uint64_t  val1,
uint64_t  val2 
)
static

Add val2 to val1 with overflow check.

Parameters
val1value 1
val2value 2
Returns
result

Definition at line 604 of file gnunet-daemon-hostlist_client.c.

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}

Referenced by update_hostlist().

Here is the caller graph for this function:

◆ checked_sub()

static uint64_t checked_sub ( uint64_t  val1,
uint64_t  val2 
)
static

Subtract val2 from val1 with underflow check.

Parameters
val1value 1
val2value 2
Returns
result

Definition at line 627 of file gnunet-daemon-hostlist_client.c.

628{
629 if (val1 <= val2)
630 return 0;
631 return(val1 - val2);
632}

Referenced by update_hostlist().

Here is the caller graph for this function:

◆ linked_list_contains()

static int linked_list_contains ( const char *  uri)
static

Method to check if a URI is in hostlist linked list.

Parameters
uriuri to check
Returns
GNUNET_YES if existing in linked list, GNUNET_NO if not

Definition at line 642 of file gnunet-daemon-hostlist_client.c.

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}

References GNUNET_NO, GNUNET_YES, Hostlist::hostlist_uri, linked_list_head, Hostlist::next, and uri.

Referenced by handler_advertisement().

Here is the caller graph for this function:

◆ linked_list_get_lowest_quality()

static struct Hostlist * linked_list_get_lowest_quality ( )
static

Method returning the hostlist element with the lowest quality in the datastore.

Returns
hostlist with lowest quality

Definition at line 662 of file gnunet-daemon-hostlist_client.c.

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}

References linked_list_head, linked_list_size, Hostlist::next, and Hostlist::quality.

Referenced by insert_hostlist().

Here is the caller graph for this function:

◆ insert_hostlist()

static void insert_hostlist ( )
static

Method to insert a hostlist into the datastore.

If datastore contains maximum number of elements, the elements with lowest quality is dismissed

Definition at line 687 of file gnunet-daemon-hostlist_client.c.

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}

References gettext_noop, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_set(), hostlist_to_test, Hostlist::hostlist_uri, linked_list_get_lowest_quality(), linked_list_head, linked_list_size, linked_list_tail, MAX_NUMBER_HOSTLISTS, Hostlist::quality, stat_testing_hostlist, and stats.

Referenced by task_download().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_hostlist()

static void update_hostlist ( )
static

Method updating hostlist statistics.

Definition at line 723 of file gnunet-daemon-hostlist_client.c.

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}

References checked_add(), checked_sub(), current_hostlist, gettext_noop, GNUNET_asprintf(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_YES, Hostlist::hello_count, HOSTLIST_FAILED_DOWNLOAD, HOSTLIST_SUCCESSFUL_DOWNLOAD, HOSTLIST_SUCCESSFUL_HELLO, Hostlist::hostlist_uri, Hostlist::quality, stat_download_successful, stat_hellos_obtained, stat_learning, stat_testing_hostlist, stat_use_bootstrap, stats, Hostlist::time_last_usage, and Hostlist::times_used.

Referenced by GNUNET_HOSTLIST_client_stop(), and task_download().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_up()

static void clean_up ( )
static

Clean up the state from the task that downloaded the hostlist and schedule the next task.

Definition at line 777 of file gnunet-daemon-hostlist_client.c.

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}

References _, curl, current_url, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_YES, hostlist_to_test, Hostlist::hostlist_uri, multi, stat_bytes_downloaded, stat_download_in_progress, stat_download_successful, and stat_testing_hostlist.

Referenced by download_hostlist(), download_prepare(), GNUNET_HOSTLIST_client_stop(), and task_download().

Here is the caller graph for this function:

◆ task_download()

static void task_download ( void *  cls)
static

Task that is run when we are ready to receive more data from the hostlist server.

Parameters
clsclosure, unused

Definition at line 911 of file gnunet-daemon-hostlist_client.c.

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}

References _, clean_up(), current_url, download_prepare(), end_time, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, hostlist_to_test, insert_hostlist(), MAX_BYTES_PER_HOSTLISTS, msg, multi, stat_bytes_downloaded, stat_download_successful, stat_testing_hostlist, ti_download, and update_hostlist().

Referenced by download_prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_prepare()

static void download_prepare ( )
static

Ask CURL for the select set and then schedule the receiving task with the scheduler.

Definition at line 850 of file gnunet-daemon-hostlist_client.c.

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}

References _, clean_up(), end_time, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NETWORK_fdset_copy_native(), GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_min(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MILLISECONDS, max, multi, task_download(), ti_download, and timeout.

Referenced by download_hostlist(), and task_download().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_hostlist()

static void download_hostlist ( )
static

Main function that will download a hostlist and process its data.

Definition at line 1008 of file gnunet-daemon-hostlist_client.c.

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}

References _, callback_download(), clean_up(), curl, CURL_EASY_SETOPT, current_url, download_get_url(), download_pos, download_prepare(), end_time, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, multi, proxy, proxy_password, proxy_type, proxy_username, ret, stat_bogus_url, stat_bytes_downloaded, stat_download_in_progress, stat_download_successful, stat_hellos_obtained, and stats.

Referenced by task_download_dispatcher().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_download_dispatcher()

static void task_download_dispatcher ( void *  cls)
static

Definition at line 1151 of file gnunet-daemon-hostlist_client.c.

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}

References download_hostlist(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), stat_download_in_progress, task_download_dispatcher(), ti_download_dispatcher_task, and WAITING_INTERVAL.

Referenced by handler_advertisement(), task_check(), and task_download_dispatcher().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_check()

static void task_check ( void *  cls)
static

Task that checks if we should try to download a hostlist.

If so, we initiate the download, otherwise we schedule this task again for a later time.

Definition at line 1178 of file gnunet-daemon-hostlist_client.c.

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}

References _, gettext_noop, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_set(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_HOURS, GNUNET_TIME_UNIT_SECONDS, GNUNET_TIME_UNIT_ZERO, GNUNET_YES, hostlist_delay, MIN_CONNECTIONS, once, GNUNET_TIME_Relative::rel_value_us, stat_connection_count, stats, task_check(), task_download_dispatcher(), ti_check_download, and ti_download_dispatcher_task.

Referenced by GNUNET_HOSTLIST_client_start(), primary_task(), stat_timeout_task(), and task_check().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_testing_intervall_reset()

static void task_testing_intervall_reset ( void *  cls)
static

This tasks sets hostlist testing to allowed after interval between to testings is reached.

Parameters
clsclosure

Definition at line 1230 of file gnunet-daemon-hostlist_client.c.

1231{
1235 "Testing new hostlist advertisements is allowed again\n");
1236}

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, stat_testing_allowed, and ti_testing_intervall_task.

Referenced by handler_advertisement().

Here is the caller graph for this function:

◆ task_hostlist_saving()

static void task_hostlist_saving ( void *  cls)
static

Task that writes hostlist entries to a file on a regular base.

Parameters
clsclosure

Definition at line 1245 of file gnunet-daemon-hostlist_client.c.

1246{
1247 ti_saving_task = NULL;
1249
1251 "Hostlists will be saved to file again in %s\n",
1253 GNUNET_YES));
1256}

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, save_hostlist_file(), SAVING_INTERVAL, task_hostlist_saving(), and ti_saving_task.

Referenced by GNUNET_HOSTLIST_client_start(), and task_hostlist_saving().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handler_connect()

static void * handler_connect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq,
enum GNUNET_CORE_PeerClass  class 
)
static

Method called whenever a given peer connects.

Parameters
clsclosure
peerpeer identity this notification is about
mqmessage queue for transmissions to peer
classclass of the connecting peer

Definition at line 1268 of file gnunet-daemon-hostlist_client.c.

1272{
1276 gettext_noop ("# active connections"),
1277 1,
1278 GNUNET_NO);
1279 return NULL;
1280}

References gettext_noop, GNUNET_assert, GNUNET_NO, GNUNET_STATISTICS_update(), stat_connection_count, and stats.

Referenced by GNUNET_HOSTLIST_client_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handler_disconnect()

static void handler_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  internal_cls 
)
static

Method called whenever a given peer disconnects.

Parameters
clsclosure
peerpeer identity this notification is about

Definition at line 1290 of file gnunet-daemon-hostlist_client.c.

1293{
1297 gettext_noop ("# active connections"),
1298 -1,
1299 GNUNET_NO);
1300}

References gettext_noop, GNUNET_assert, GNUNET_NO, GNUNET_STATISTICS_update(), stat_connection_count, and stats.

Referenced by GNUNET_HOSTLIST_client_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handler_advertisement()

static void handler_advertisement ( const char *  uri)
static

Method called whenever an advertisement message arrives.

Parameters
urithe advertised URI

Definition at line 1309 of file gnunet-daemon-hostlist_client.c.

1310{
1311 size_t uri_size;
1312 struct Hostlist *hostlist;
1313
1314 uri_size = strlen (uri) + 1;
1316 "Hostlist client received advertisement containing URI `%s'\n",
1317 uri);
1319 {
1320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri);
1321 return;
1322 }
1323
1325 {
1326 GNUNET_log (
1328 "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
1329 return;
1330 }
1332 {
1333 GNUNET_log (
1335 "Currently not accepting new advertisements: we are already testing a hostlist\n");
1336 return;
1337 }
1338
1339 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + uri_size);
1340 hostlist->hostlist_uri = (const char *) &hostlist[1];
1341 GNUNET_memcpy (&hostlist[1], uri, uri_size);
1343 hostlist->quality = HOSTLIST_INITIAL;
1344 hostlist_to_test = hostlist;
1345
1351 NULL);
1352
1354 "Testing new hostlist advertisements is locked for the next %s\n",
1356 GNUNET_YES));
1357
1360}

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_YES, HOSTLIST_INITIAL, hostlist_to_test, Hostlist::hostlist_uri, linked_list_contains(), Hostlist::quality, stat_testing_allowed, stat_testing_hostlist, task_download_dispatcher(), task_testing_intervall_reset(), TESTING_INTERVAL, ti_download_dispatcher_task, ti_testing_intervall_task, Hostlist::time_creation, and uri.

Referenced by GNUNET_HOSTLIST_client_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ primary_task()

static void primary_task ( void *  cls,
int  success 
)
static

Continuation called by the statistics code once we go the stat.

Initiates hostlist download scheduling.

Parameters
clsclosure
successGNUNET_OK if statistics were successfully obtained, GNUNET_SYSERR if not.

Definition at line 1372 of file gnunet-daemon-hostlist_client.c.

1373{
1374 if (NULL != ti_check_download)
1375 {
1377 ti_check_download = NULL;
1378 }
1379 sget = NULL;
1380 GNUNET_assert (NULL != stats);
1382 "Statistics request done, scheduling hostlist download\n");
1384}

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), sget, stats, task_check(), and ti_check_download.

Referenced by GNUNET_HOSTLIST_client_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stat_timeout_task()

static void stat_timeout_task ( void *  cls)
static

Continuation called by the statistics code once we go the stat.

Initiates hostlist download scheduling.

Parameters
clsclosure

Definition at line 1394 of file gnunet-daemon-hostlist_client.c.

References GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_get_cancel(), sget, task_check(), and ti_check_download.

Here is the call graph for this function:

◆ process_stat()

static int process_stat ( void *  cls,
const char *  subsystem,
const char *  name,
uint64_t  value,
int  is_persistent 
)
static

We've received the previous delay value from statistics.

Remember it.

Parameters
clsNULL, unused
subsystemshould be "hostlist", unused
namewill be "milliseconds between hostlist downloads", unused
valueprevious delay value, in milliseconds (!)
is_persistentunused, will be GNUNET_YES

Definition at line 1412 of file gnunet-daemon-hostlist_client.c.

1417{
1420 "Initial time between hostlist downloads is %s\n",
1422 GNUNET_YES));
1423 return GNUNET_OK;
1424}

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, hostlist_delay, GNUNET_TIME_Relative::rel_value_us, and value.

Referenced by GNUNET_HOSTLIST_client_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_hostlist_file()

static void load_hostlist_file ( )
static

Method to load persistent hostlist file during hostlist client startup.

Definition at line 1431 of file gnunet-daemon-hostlist_client.c.

1432{
1433 char *filename;
1434 char *uri;
1435 char *emsg;
1436 struct Hostlist *hostlist;
1437 uint32_t times_used;
1438 uint32_t hellos_returned;
1439 uint64_t quality;
1440 uint64_t last_used;
1441 uint64_t created;
1442 uint32_t counter;
1443 struct GNUNET_BIO_ReadHandle *rh;
1444
1445 uri = NULL;
1447 "HOSTLIST",
1448 "HOSTLISTFILE",
1449 &filename))
1450 {
1452 "hostlist",
1453 "HOSTLISTFILE");
1454 return;
1455 }
1456
1458 _ ("Loading saved hostlist entries from file `%s' \n"),
1459 filename);
1461 {
1463 _ ("Hostlist file `%s' does not exist\n"),
1464 filename);
1466 return;
1467 }
1468
1470 if (NULL == rh)
1471 {
1473 _ (
1474 "Could not open file `%s' for reading to load hostlists: %s\n"),
1475 filename,
1476 strerror (errno));
1478 return;
1479 }
1480
1481 counter = 0;
1482 {
1483 struct GNUNET_BIO_ReadSpec rs[] = {
1484 GNUNET_BIO_read_spec_int32 ("times used", (int32_t *) &times_used),
1485 GNUNET_BIO_read_spec_int64 ("quality", (int64_t *) &quality),
1486 GNUNET_BIO_read_spec_int64 ("last used", (int64_t *) &last_used),
1487 GNUNET_BIO_read_spec_int64 ("created", (int64_t *) &created),
1488 GNUNET_BIO_read_spec_int32 ("hellos returned",
1489 (int32_t *) &hellos_returned),
1491 };
1492 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN))
1493 &&
1494 (NULL != uri) &&
1496 {
1497 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1);
1498 hostlist->hello_count = hellos_returned;
1499 hostlist->hostlist_uri = (const char *) &hostlist[1];
1500 GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1);
1501 hostlist->quality = quality;
1502 hostlist->time_creation.abs_value_us = created;
1503 hostlist->time_last_usage.abs_value_us = last_used;
1505 ;
1508 "Added hostlist entry with URI `%s' \n",
1509 hostlist->hostlist_uri);
1510 GNUNET_free (uri);
1511 uri = NULL;
1512 counter++;
1513 if (counter >= MAX_NUMBER_HOSTLISTS)
1514 break;
1515 }
1516 }
1517
1519 _ ("%u hostlist URIs loaded from file\n"),
1520 counter);
1522 gettext_noop ("# hostlist URIs read from file"),
1523 counter,
1524 GNUNET_YES);
1526 gettext_noop ("# advertised hostlist URIs"),
1528 GNUNET_NO);
1529
1530 GNUNET_free (uri);
1531 emsg = NULL;
1532 (void) GNUNET_BIO_read_close (rh, &emsg);
1533 if (emsg != NULL)
1534 GNUNET_free (emsg);
1536}

References _, GNUNET_TIME_Absolute::abs_value_us, cfg, filename, gettext_noop, GNUNET_BIO_read_close(), GNUNET_BIO_read_open_file(), GNUNET_BIO_read_spec_commit(), GNUNET_BIO_read_spec_end, GNUNET_BIO_read_spec_int32(), GNUNET_BIO_read_spec_int64(), GNUNET_BIO_read_string(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_DLL_insert, GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_set(), GNUNET_YES, Hostlist::hello_count, Hostlist::hostlist_uri, linked_list_head, linked_list_size, linked_list_tail, MAX_NUMBER_HOSTLISTS, MAX_URL_LEN, Hostlist::quality, GNUNET_BIO_ReadSpec::rh, stats, Hostlist::time_creation, Hostlist::time_last_usage, Hostlist::times_used, and uri.

Referenced by GNUNET_HOSTLIST_client_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HOSTLIST_client_start()

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.

Parameters
cconfiguration to use
ststatistics handle to use
[out]chset to handler for CORE connect events
[out]dhset to handler for CORE disconnect events
[out]msghset to handler for CORE advertisement messages
learnshould we learn hostlist URLs from CORE
Returns
GNUNET_OK on success

Definition at line 1650 of file gnunet-daemon-hostlist_client.c.

1656{
1657 char *filename;
1658 char *proxytype_str;
1659 int result;
1660
1661 GNUNET_assert (NULL != st);
1662 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
1663 {
1664 GNUNET_break (0);
1665 return GNUNET_SYSERR;
1666 }
1667 cfg = c;
1668 stats = st;
1669
1670 /* Read proxy configuration */
1672 if (GNUNET_OK ==
1673 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy))
1674 {
1675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy);
1676 /* proxy username */
1678 "HOSTLIST",
1679 "PROXY_USERNAME",
1681 {
1683 "Found proxy username name: `%s'\n",
1685 }
1686
1687 /* proxy password */
1689 "HOSTLIST",
1690 "PROXY_PASSWORD",
1692 {
1694 "Found proxy password name: `%s'\n",
1696 }
1697
1698 /* proxy type */
1700 "HOSTLIST",
1701 "PROXY_TYPE",
1702 &proxytype_str))
1703 {
1704 if (GNUNET_OK != GNUNET_STRINGS_utf8_toupper (proxytype_str,
1705 proxytype_str))
1707 "Unable to convert `%s' to UTF-8 uppercase\n",
1708 proxytype_str);
1709 proxy_type = CURLPROXY_HTTP;
1710 if (0 == strcmp (proxytype_str, "HTTP"))
1711 proxy_type = CURLPROXY_HTTP;
1712 else if (0 == strcmp (proxytype_str, "HTTP_1_0"))
1713 proxy_type = CURLPROXY_HTTP_1_0;
1714 else if (0 == strcmp (proxytype_str, "SOCKS4"))
1715 proxy_type = CURLPROXY_SOCKS4;
1716 else if (0 == strcmp (proxytype_str, "SOCKS5"))
1717 proxy_type = CURLPROXY_SOCKS5;
1718 else if (0 == strcmp (proxytype_str, "SOCKS4A"))
1719 proxy_type = CURLPROXY_SOCKS4A;
1720 else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME"))
1721 proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1722 else
1723 {
1724 GNUNET_log (
1726 _ (
1727 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n")
1728 ,
1729 proxytype_str);
1730 GNUNET_free (proxytype_str);
1732 proxy = NULL;
1734 proxy_username = NULL;
1736 proxy_password = NULL;
1737
1738 return GNUNET_SYSERR;
1739 }
1740 }
1741 GNUNET_free (proxytype_str);
1742 }
1743
1744 stat_learning = learn;
1745 *ch = &handler_connect;
1746 *dh = &handler_disconnect;
1747 linked_list_head = NULL;
1748 linked_list_tail = NULL;
1752
1754 {
1755 *msgh = &handler_advertisement;
1757 _ ("Learning is enabled on this peer\n"));
1760 "Hostlists will be saved to file again in %s\n",
1762 GNUNET_YES));
1765 NULL);
1766 }
1767 else
1768 {
1770 _ ("Learning is not enabled on this peer\n"));
1771 *msgh = NULL;
1773 "HOSTLIST",
1774 "HOSTLISTFILE",
1775 &filename))
1776 {
1778 {
1779 result = remove (filename);
1780 if (0 == result)
1781 GNUNET_log (
1783 _ (
1784 "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1785 filename);
1786 else
1788 "remove",
1789 filename);
1790 }
1791 }
1793 }
1795 "Loading stats value on hostlist download frequency\n");
1797 "hostlist",
1798 gettext_noop (
1799 "# milliseconds between hostlist downloads"),
1800 &primary_task,
1801 &process_stat,
1802 NULL);
1803 if (NULL == sget)
1804 {
1806 "Statistics request failed, scheduling hostlist download\n");
1808 }
1809 else
1810 {
1813 NULL);
1814 }
1815 return GNUNET_OK;
1816}

References _, cfg, ch, filename, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_get(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_STRINGS_utf8_toupper(), GNUNET_SYSERR, GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, handler_advertisement(), handler_connect(), handler_disconnect(), linked_list_head, linked_list_tail, load_hostlist_file(), peerstore, primary_task(), process_stat(), proxy, proxy_password, proxy_type, proxy_username, result, SAVING_INTERVAL, sget, st, stat_learning, stat_testing_allowed, stat_testing_hostlist, stat_timeout_task, stat_use_bootstrap, stats, task_check(), task_hostlist_saving(), ti_check_download, and ti_saving_task.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HOSTLIST_client_stop()

void GNUNET_HOSTLIST_client_stop ( void  )

Stop downloading hostlists from hostlist servers as necessary.

Definition at line 1823 of file gnunet-daemon-hostlist_client.c.

1824{
1825 struct StoreHelloEntry *pos;
1826
1827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
1828 while (NULL != (pos = she_head))
1829 {
1832 GNUNET_free (pos);
1833 }
1834 if (NULL != sget)
1835 {
1837 sget = NULL;
1838 }
1839 stats = NULL;
1842 if (NULL != ti_saving_task)
1843 {
1845 ti_saving_task = NULL;
1846 }
1847 if (NULL != ti_download_dispatcher_task)
1848 {
1851 }
1852 if (NULL != ti_testing_intervall_task)
1853 {
1856 }
1857 if (NULL != ti_download)
1858 {
1860 ti_download = NULL;
1861 update_hostlist ();
1862 clean_up ();
1863 }
1864 if (NULL != ti_check_download)
1865 {
1867 ti_check_download = NULL;
1868 curl_global_cleanup ();
1869 }
1871 proxy = NULL;
1873 proxy_username = NULL;
1875 proxy_password = NULL;
1876 if (NULL != peerstore)
1877 {
1879 peerstore = NULL;
1880 }
1881 cfg = NULL;
1882}

References cfg, clean_up(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_PEERSTORE_disconnect(), GNUNET_PEERSTORE_hello_add_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_get_cancel(), GNUNET_YES, peerstore, proxy, proxy_password, proxy_username, save_hostlist_file(), StoreHelloEntry::sc, sget, she_head, she_tail, stat_learning, stats, ti_check_download, ti_download, ti_download_dispatcher_task, ti_saving_task, ti_testing_intervall_task, and update_hostlist().

Referenced by cleaning_task().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cfg

◆ stats

◆ proxy

char* proxy
static

Proxy hostname or ip we are using (can be NULL).

Definition at line 175 of file gnunet-daemon-hostlist_client.c.

Referenced by download_hostlist(), GNUNET_HOSTLIST_client_start(), and GNUNET_HOSTLIST_client_stop().

◆ proxy_username

char* proxy_username
static

Proxy username we are using (can be NULL).

Definition at line 180 of file gnunet-daemon-hostlist_client.c.

Referenced by download_hostlist(), GNUNET_HOSTLIST_client_start(), and GNUNET_HOSTLIST_client_stop().

◆ proxy_password

char* proxy_password
static

Proxy password we are using (can be NULL).

Definition at line 185 of file gnunet-daemon-hostlist_client.c.

Referenced by download_hostlist(), GNUNET_HOSTLIST_client_start(), and GNUNET_HOSTLIST_client_stop().

◆ proxy_type

curl_proxytype proxy_type
static

Proxy type we are using (can be NULL).

Definition at line 190 of file gnunet-daemon-hostlist_client.c.

Referenced by download_hostlist(), and GNUNET_HOSTLIST_client_start().

◆ download_pos

size_t download_pos
static

Number of bytes valid in 'download_buffer'.

Definition at line 195 of file gnunet-daemon-hostlist_client.c.

Referenced by callback_download(), and download_hostlist().

◆ current_url

char* current_url
static

Current URL that we are using.

Definition at line 200 of file gnunet-daemon-hostlist_client.c.

Referenced by callback_download(), clean_up(), download_hostlist(), and task_download().

◆ curl

CURL* curl
static

Current CURL handle.

Definition at line 205 of file gnunet-daemon-hostlist_client.c.

Referenced by clean_up(), and download_hostlist().

◆ multi

CURLM* multi
static

Current multi-CURL handle.

Definition at line 210 of file gnunet-daemon-hostlist_client.c.

Referenced by clean_up(), download_hostlist(), download_prepare(), GNUNET_CURL_init(), and task_download().

◆ stat_bytes_downloaded

uint32_t stat_bytes_downloaded
static

How many bytes did we download from the current hostlist URL?

Definition at line 215 of file gnunet-daemon-hostlist_client.c.

Referenced by callback_download(), clean_up(), download_hostlist(), and task_download().

◆ hostlist_delay

struct GNUNET_TIME_Relative hostlist_delay
static

Amount of time we wait between hostlist downloads.

Definition at line 220 of file gnunet-daemon-hostlist_client.c.

Referenced by process_stat(), and task_check().

◆ ti_check_download

struct GNUNET_SCHEDULER_Task* ti_check_download
static

ID of the task, checking if hostlist download should take plate.

Definition at line 225 of file gnunet-daemon-hostlist_client.c.

Referenced by GNUNET_HOSTLIST_client_start(), GNUNET_HOSTLIST_client_stop(), primary_task(), stat_timeout_task(), and task_check().

◆ ti_download

struct GNUNET_SCHEDULER_Task* ti_download
static

ID of the task downloading the hostlist.

Definition at line 230 of file gnunet-daemon-hostlist_client.c.

Referenced by download_prepare(), GNUNET_HOSTLIST_client_stop(), and task_download().

◆ ti_saving_task

struct GNUNET_SCHEDULER_Task* ti_saving_task
static

ID of the task saving the hostlsit in a regular interval.

Definition at line 235 of file gnunet-daemon-hostlist_client.c.

Referenced by GNUNET_HOSTLIST_client_start(), GNUNET_HOSTLIST_client_stop(), and task_hostlist_saving().

◆ ti_download_dispatcher_task

struct GNUNET_SCHEDULER_Task* ti_download_dispatcher_task
static

ID of the task called to initiate a download.

Definition at line 240 of file gnunet-daemon-hostlist_client.c.

Referenced by GNUNET_HOSTLIST_client_stop(), handler_advertisement(), task_check(), and task_download_dispatcher().

◆ ti_testing_intervall_task

struct GNUNET_SCHEDULER_Task* ti_testing_intervall_task
static

ID of the task controlling the locking between two hostlist tests.

Definition at line 245 of file gnunet-daemon-hostlist_client.c.

Referenced by GNUNET_HOSTLIST_client_stop(), handler_advertisement(), and task_testing_intervall_reset().

◆ end_time

struct GNUNET_TIME_Absolute end_time
static

At what time MUST the current hostlist request be done?

Definition at line 250 of file gnunet-daemon-hostlist_client.c.

Referenced by download_hostlist(), download_prepare(), process_job_queue(), and task_download().

◆ she_head

struct StoreHelloEntry* she_head
static

Head of the linkd list to store the store context for hellos.

Definition at line 255 of file gnunet-daemon-hostlist_client.c.

Referenced by callback_download(), GNUNET_HOSTLIST_client_stop(), and shc_cont().

◆ she_tail

struct StoreHelloEntry* she_tail
static

Tail of the linkd list to store the store context for hellos.

Definition at line 260 of file gnunet-daemon-hostlist_client.c.

Referenced by callback_download(), GNUNET_HOSTLIST_client_stop(), and shc_cont().

◆ linked_list_head

struct Hostlist* linked_list_head
static

◆ linked_list_tail

struct Hostlist* linked_list_tail
static

Tail of the linked list used to store hostlists.

Definition at line 270 of file gnunet-daemon-hostlist_client.c.

Referenced by GNUNET_HOSTLIST_client_start(), insert_hostlist(), load_hostlist_file(), and save_hostlist_file().

◆ current_hostlist

struct Hostlist* current_hostlist
static

Current hostlist used for downloading.

Definition at line 275 of file gnunet-daemon-hostlist_client.c.

Referenced by download_get_url(), and update_hostlist().

◆ linked_list_size

unsigned int linked_list_size
static

Size of the linked list used to store hostlists.

Definition at line 280 of file gnunet-daemon-hostlist_client.c.

Referenced by download_get_url(), insert_hostlist(), linked_list_get_lowest_quality(), load_hostlist_file(), and save_hostlist_file().

◆ hostlist_to_test

struct Hostlist* hostlist_to_test
static

Head of the linked list used to store hostlists.

Definition at line 285 of file gnunet-daemon-hostlist_client.c.

Referenced by clean_up(), download_get_url(), handler_advertisement(), insert_hostlist(), and task_download().

◆ sget

struct GNUNET_STATISTICS_GetHandle* sget
static

Handle for our statistics GET operation.

Definition at line 290 of file gnunet-daemon-hostlist_client.c.

Referenced by GNUNET_HOSTLIST_client_start(), GNUNET_HOSTLIST_client_stop(), primary_task(), and stat_timeout_task().

◆ stat_bogus_url

int stat_bogus_url
static

Set to GNUNET_YES if the current URL had some problems.

Definition at line 295 of file gnunet-daemon-hostlist_client.c.

Referenced by callback_download(), and download_hostlist().

◆ stat_testing_hostlist

int stat_testing_hostlist
static

Value controlling if a hostlist is tested at the moment.

Definition at line 300 of file gnunet-daemon-hostlist_client.c.

Referenced by clean_up(), download_get_url(), GNUNET_HOSTLIST_client_start(), handler_advertisement(), insert_hostlist(), task_download(), and update_hostlist().

◆ stat_testing_allowed

int stat_testing_allowed
static

Value controlling if a hostlist testing is allowed at the moment.

Definition at line 305 of file gnunet-daemon-hostlist_client.c.

Referenced by GNUNET_HOSTLIST_client_start(), handler_advertisement(), and task_testing_intervall_reset().

◆ stat_download_in_progress

int stat_download_in_progress
static

Value controlling if a hostlist download is running at the moment.

Definition at line 310 of file gnunet-daemon-hostlist_client.c.

Referenced by clean_up(), download_hostlist(), and task_download_dispatcher().

◆ stat_use_bootstrap

unsigned int stat_use_bootstrap
static

Value saying if a preconfigured bootstrap server is used.

Definition at line 315 of file gnunet-daemon-hostlist_client.c.

Referenced by download_get_url(), GNUNET_HOSTLIST_client_start(), and update_hostlist().

◆ stat_learning

int stat_learning
static

Set if we are allowed to learn new hostlists and use them.

Definition at line 320 of file gnunet-daemon-hostlist_client.c.

Referenced by download_get_url(), GNUNET_HOSTLIST_client_start(), GNUNET_HOSTLIST_client_stop(), and update_hostlist().

◆ stat_download_successful

unsigned int stat_download_successful
static

Value saying if hostlist download was successful.

Definition at line 325 of file gnunet-daemon-hostlist_client.c.

Referenced by clean_up(), download_hostlist(), task_download(), and update_hostlist().

◆ stat_hellos_obtained

unsigned int stat_hellos_obtained
static

Value saying how many valid HELLO messages were obtained during download.

Definition at line 330 of file gnunet-daemon-hostlist_client.c.

Referenced by callback_download(), download_hostlist(), and update_hostlist().

◆ stat_connection_count

unsigned int stat_connection_count
static

Number of active connections (according to core service).

Definition at line 335 of file gnunet-daemon-hostlist_client.c.

Referenced by handler_connect(), handler_disconnect(), and task_check().

◆ peerstore

struct GNUNET_PEERSTORE_Handle* peerstore
static

Handle to the PEERSTORE service.

Definition at line 340 of file gnunet-daemon-hostlist_client.c.

Referenced by callback_download(), GNUNET_HOSTLIST_client_start(), and GNUNET_HOSTLIST_client_stop().