GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-daemon-hostlist_client.c File Reference

hostlist support. More...

#include "platform.h"
#include "gnunet-daemon-hostlist_client.h"
#include "gnunet_hello_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_service.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet-daemon-hostlist.h"
#include "gnunet_curl_lib.h"
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...
 

Macros

#define MIN_CONNECTIONS   4
 Number of connections that we must have to NOT download hostlists anymore. More...
 
#define MAX_NUMBER_HOSTLISTS   30
 Maximum number of hostlist that are saved. More...
 
#define SAVING_INTERVAL   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
 Time interval hostlists are saved to disk. More...
 
#define TESTING_INTERVAL   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
 Time interval between two hostlist tests. More...
 
#define WAITING_INTERVAL   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 Time interval for download dispatcher before a download is re-scheduled. More...
 
#define HOSTLIST_INITIAL   10000
 Defines concerning the hostlist quality metric. More...
 
#define HOSTLIST_FAILED_DOWNLOAD   100
 Value subtracted each time a hostlist download fails. More...
 
#define HOSTLIST_SUCCESSFUL_DOWNLOAD   100
 Value added each time a hostlist download is successful. More...
 
#define HOSTLIST_SUCCESSFUL_HELLO   1
 Value added for each valid HELLO recived during a hostlist download. More...
 
#define CURL_EASY_SETOPT(c, a, b)   do { ret = curl_easy_setopt (c, a, b); if (CURLE_OK != ret) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: `%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror (ret)); } while (0)
 

Functions

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

Variables

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

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 42 of file gnunet-daemon-hostlist_client.c.

Referenced by task_check().

◆ MAX_NUMBER_HOSTLISTS

#define MAX_NUMBER_HOSTLISTS   30

Maximum number of hostlist that are saved.

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

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

◆ SAVING_INTERVAL

#define SAVING_INTERVAL   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)

Time interval hostlists are saved to disk.

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

Referenced by GNUNET_HOSTLIST_client_start(), and task_hostlist_saving().

◆ TESTING_INTERVAL

#define TESTING_INTERVAL   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)

Time interval between two hostlist tests.

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

Referenced by handler_advertisement().

◆ 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.

Referenced by task_download_dispatcher().

◆ HOSTLIST_INITIAL

#define HOSTLIST_INITIAL   10000

Defines concerning the hostlist quality metric.

Initial quality of a new created hostlist

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

Referenced by handler_advertisement().

◆ HOSTLIST_FAILED_DOWNLOAD

#define HOSTLIST_FAILED_DOWNLOAD   100

Value subtracted each time a hostlist download fails.

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

Referenced by update_hostlist().

◆ HOSTLIST_SUCCESSFUL_DOWNLOAD

#define HOSTLIST_SUCCESSFUL_DOWNLOAD   100

Value added each time a hostlist download is successful.

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

Referenced by update_hostlist().

◆ HOSTLIST_SUCCESSFUL_HELLO

#define HOSTLIST_SUCCESSFUL_HELLO   1

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

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

Referenced by update_hostlist().

◆ CURL_EASY_SETOPT

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

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

Referenced by download_hostlist().

Function Documentation

◆ 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 324 of file gnunet-daemon-hostlist_client.c.

References _, current_url, download_pos, gettext_noop, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_HELLO_size(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MIN, GNUNET_NO, GNUNET_PEERINFO_add_peer(), GNUNET_STATISTICS_update(), GNUNET_YES, msg, GNUNET_MessageHeader::size, stat_bogus_url, stat_bytes_downloaded, and stat_hellos_obtained.

Referenced by download_hostlist().

328 {
329  static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1];
330  const char *cbuf = ptr;
331  const struct GNUNET_MessageHeader *msg;
332  size_t total;
333  size_t cpy;
334  size_t left;
335  uint16_t msize;
336 
337  total = size * nmemb;
338  stat_bytes_downloaded += total;
339  if ((total == 0) || (stat_bogus_url))
340  {
341  return total; /* ok, no data or bogus data */
342  }
343 
346  ("# bytes downloaded from hostlist servers"),
347  (int64_t) total, GNUNET_NO);
348  left = total;
349  while ((left > 0) || (download_pos > 0))
350  {
351  cpy = GNUNET_MIN (left, GNUNET_MAX_MESSAGE_SIZE - 1 - download_pos);
352  GNUNET_memcpy (&download_buffer[download_pos], cbuf, cpy);
353  cbuf += cpy;
354  download_pos += cpy;
355  left -= cpy;
356  if (download_pos < sizeof (struct GNUNET_MessageHeader))
357  {
358  GNUNET_assert (0 == left);
359  break;
360  }
361  msg = (const struct GNUNET_MessageHeader *) download_buffer;
362  msize = ntohs (msg->size);
363  if (msize < sizeof (struct GNUNET_MessageHeader))
364  {
367  ("# invalid HELLOs downloaded from hostlist servers"),
368  1, GNUNET_NO);
370  _("Invalid `%s' message received from hostlist at `%s'\n"),
371  "HELLO", current_url);
373  stat_bogus_url = 1;
374  return total;
375  }
376  if (download_pos < msize)
377  {
378  GNUNET_assert (left == 0);
379  break;
380  }
381  if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) msg) == msize)
382  {
384  "Received valid `%s' message from hostlist server.\n",
385  "HELLO");
388  ("# valid HELLOs downloaded from hostlist servers"),
389  1, GNUNET_NO);
392  (const struct GNUNET_HELLO_Message *) msg,
393  NULL,
394  NULL);
395  }
396  else
397  {
400  ("# invalid HELLOs downloaded from hostlist servers"),
401  1, GNUNET_NO);
403  _("Invalid `%s' message received from hostlist at `%s'\n"),
404  "HELLO", current_url);
407  return total;
408  }
409  memmove (download_buffer,
410  &download_buffer[msize],
411  download_pos - msize);
412  download_pos -= msize;
413  }
414  return total;
415 }
A HELLO message is used to exchange information about transports with other peers.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
static size_t download_pos
Number of bytes valid in &#39;download_buffer&#39;.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
static char * current_url
Current URL that we are using.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
static int stat_bogus_url
Set to GNUNET_YES if the current URL had some problems.
struct GNUNET_MQ_Envelope * GNUNET_PEERINFO_add_peer(struct GNUNET_PEERINFO_Handle *h, const struct GNUNET_HELLO_Message *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Add a host to the persistent list.
Definition: peerinfo_api.c:557
static unsigned int size
Size of the "table".
Definition: peer.c:67
static unsigned int stat_hellos_obtained
Value saying how many valid HELLO messages were obtained during download.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
#define GNUNET_log(kind,...)
static uint32_t stat_bytes_downloaded
How many bytes did we download from the current hostlist URL?
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:649
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
#define gettext_noop(String)
Definition: gettext.h:69
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 424 of file gnunet-daemon-hostlist_client.c.

References 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().

425 {
426  char *servers;
427  char *ret;
428  size_t urls;
429  size_t pos;
430 
431  if (GNUNET_OK !=
432  GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "SERVERS",
433  &servers))
434  {
436  "hostlist", "SERVERS");
437  return NULL;
438  }
439 
440  urls = 0;
441  if (strlen (servers) > 0)
442  {
443  urls++;
444  pos = strlen (servers) - 1;
445  while (pos > 0)
446  {
447  if (servers[pos] == ' ')
448  urls++;
449  pos--;
450  }
451  }
452  if (urls == 0)
453  {
455  "hostlist", "SERVERS");
456  GNUNET_free (servers);
457  return NULL;
458  }
459 
461  pos = strlen (servers) - 1;
462  while (pos > 0)
463  {
464  if (servers[pos] == ' ')
465  {
466  urls--;
467  servers[pos] = '\0';
468  }
469  if (urls == 0)
470  {
471  pos++;
472  break;
473  }
474  pos--;
475  }
476  ret = GNUNET_strdup (&servers[pos]);
477  GNUNET_free (servers);
478  return ret;
479 }
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
int 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.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_free(ptr)
Wrapper around free.
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 487 of file gnunet-daemon-hostlist_client.c.

References 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().

488 {
489  uint32_t index;
490  unsigned int counter;
491  struct Hostlist *pos;
492 
493  if (GNUNET_NO == stat_learning)
494  {
496  "Using preconfigured bootstrap server\n");
497  current_hostlist = NULL;
498  return get_bootstrap_server ();
499  }
500 
501  if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test))
502  {
504  "Testing new advertised hostlist if it is obtainable\n");
507  }
508 
510  {
512  "Using preconfigured bootstrap server\n");
513  current_hostlist = NULL;
514  return get_bootstrap_server ();
515  }
516  index =
518  counter = 0;
519  pos = linked_list_head;
520  while (counter < index)
521  {
522  pos = pos->next;
523  counter++;
524  }
525  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using learned hostlist `%s'\n",
526  pos->hostlist_uri);
527  current_hostlist = pos;
528  return GNUNET_strdup (pos->hostlist_uri);
529 }
static int stat_learning
Set if we are allowed to learn new hostlists and use them.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct Hostlist * next
next entry, used to manage entries in a double linked list
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
const char * hostlist_uri
URI where hostlist can be obtained.
static unsigned int stat_use_bootstrap
Value saying if a preconfigured bootstrap server is used.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
static struct Hostlist * current_hostlist
Current hostlist used for downloading.
static char * get_bootstrap_server()
Obtain a hostlist URL that we should use.
static unsigned int linked_list_size
Size of the linke list used to store hostlists.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
A single hostlist obtained by hostlist advertisements.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
static struct Hostlist * hostlist_to_test
Head of the linked list used to store hostlists.
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 1422 of file gnunet-daemon-hostlist_client.c.

References _, GNUNET_TIME_Absolute::abs_value_us, filename, gettext_noop, GNUNET_BIO_write_close(), GNUNET_BIO_write_int32(), GNUNET_BIO_write_int64(), GNUNET_BIO_write_open(), GNUNET_BIO_write_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_size, MAX_NUMBER_HOSTLISTS, ok, Hostlist::quality, STRERROR, Hostlist::time_creation, Hostlist::time_last_usage, Hostlist::times_used, and wh.

Referenced by GNUNET_HOSTLIST_client_stop(), and task_hostlist_saving().

1423 {
1424  char *filename;
1425  struct Hostlist *pos;
1426  struct GNUNET_BIO_WriteHandle *wh;
1427  int ok;
1428  uint32_t counter;
1429 
1430  if (GNUNET_OK !=
1431  GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE",
1432  &filename))
1433  {
1435  "hostlist", "HOSTLISTFILE");
1436  return;
1437  }
1439  {
1440  GNUNET_free (filename);
1441  return;
1442  }
1443  wh = GNUNET_BIO_write_open (filename);
1444  if (NULL == wh)
1445  {
1447  _("Could not open file `%s' for writing to save hostlists: %s\n"),
1448  filename,
1449  STRERROR (errno));
1450  GNUNET_free (filename);
1451  return;
1452  }
1454  _("Writing %u hostlist URIs to `%s'\n"),
1455  linked_list_size, filename);
1456  /* add code to write hostlists to file using bio */
1457  ok = GNUNET_YES;
1458  counter = 0;
1459  while (NULL != (pos = linked_list_head))
1460  {
1461  if (GNUNET_YES == shutdown)
1462  {
1464  linked_list_size--;
1465  }
1466  if (GNUNET_YES == ok)
1467  {
1468  if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pos->hostlist_uri)) ||
1469  (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->times_used)) ||
1470  (GNUNET_OK != GNUNET_BIO_write_int64 (wh, pos->quality)) ||
1471  (GNUNET_OK !=
1473  (GNUNET_OK !=
1476  {
1478  _("Error writing hostlist URIs to file `%s'\n"), filename);
1479  ok = GNUNET_NO;
1480  }
1481  }
1482 
1483  if (GNUNET_YES == shutdown)
1484  GNUNET_free (pos);
1485  counter++;
1486  if (counter >= MAX_NUMBER_HOSTLISTS)
1487  break;
1488  }
1490  gettext_noop ("# hostlist URIs written to file"),
1491  counter, GNUNET_YES);
1492 
1493  if (GNUNET_OK != GNUNET_BIO_write_close (wh))
1495  _("Error writing hostlist URIs to file `%s'\n"), filename);
1496  GNUNET_free (filename);
1497 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_TIME_Absolute time_last_usage
Last time the hostlist was obtained.
struct GNUNET_TIME_Absolute time_creation
Time the hostlist advertisement was recieved and the entry was created.
uint64_t quality
Value describing the quality of the hostlist, the bigger the better but (should) never < 0 used for d...
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
Write a string to a file.
Definition: bio.c:547
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:623
#define STRERROR(i)
Definition: plibc.h:676
static int ok
Return value from &#39;main&#39; (0 == success)
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint64_t abs_value_us
The actual value.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
uint32_t hello_count
Number of HELLO messages obtained during last download.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static char * filename
const char * hostlist_uri
URI where hostlist can be obtained.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
Handle for buffered writing.
Definition: bio.c:399
static struct Hostlist * linked_list_tail
Tail of the linked list used to store hostlists.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static unsigned int linked_list_size
Size of the linke list used to store hostlists.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:457
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:430
uint32_t times_used
Number of times the hostlist was successfully obtained.
#define GNUNET_log(kind,...)
int 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.
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:605
#define MAX_NUMBER_HOSTLISTS
Maximum number of hostlist that are saved.
#define GNUNET_YES
Definition: gnunet_common.h:80
A single hostlist obtained by hostlist advertisements.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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 552 of file gnunet-daemon-hostlist_client.c.

Referenced by update_hostlist().

554 {
555  static uint64_t temp;
556  static uint64_t maxv;
557 
558  maxv = 0;
559  maxv--;
560 
561  temp = val1 + val2;
562  if (temp < val1)
563  return maxv;
564  return temp;
565 }
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 576 of file gnunet-daemon-hostlist_client.c.

Referenced by update_hostlist().

578 {
579  if (val1 <= val2)
580  return 0;
581  return (val1 - val2);
582 }
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 592 of file gnunet-daemon-hostlist_client.c.

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

Referenced by handler_advertisement().

593 {
594  struct Hostlist *pos;
595 
596  pos = linked_list_head;
597  while (pos != NULL)
598  {
599  if (0 == strcmp (pos->hostlist_uri, uri))
600  return GNUNET_YES;
601  pos = pos->next;
602  }
603  return GNUNET_NO;
604 }
#define GNUNET_NO
Definition: gnunet_common.h:81
struct Hostlist * next
next entry, used to manage entries in a double linked list
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
const char * hostlist_uri
URI where hostlist can be obtained.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
#define GNUNET_YES
Definition: gnunet_common.h:80
A single hostlist obtained by hostlist advertisements.
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 612 of file gnunet-daemon-hostlist_client.c.

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

Referenced by insert_hostlist().

613 {
614  struct Hostlist *pos;
615  struct Hostlist *lowest;
616 
617  if (linked_list_size == 0)
618  return NULL;
619  lowest = linked_list_head;
620  pos = linked_list_head->next;
621  while (pos != NULL)
622  {
623  if (pos->quality < lowest->quality)
624  lowest = pos;
625  pos = pos->next;
626  }
627  return lowest;
628 }
uint64_t quality
Value describing the quality of the hostlist, the bigger the better but (should) never < 0 used for d...
struct Hostlist * next
next entry, used to manage entries in a double linked list
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
static unsigned int linked_list_size
Size of the linke list used to store hostlists.
A single hostlist obtained by hostlist advertisements.
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 637 of file gnunet-daemon-hostlist_client.c.

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::hostlist_uri, linked_list_get_lowest_quality(), linked_list_size, MAX_NUMBER_HOSTLISTS, Hostlist::quality, and stat_testing_hostlist.

Referenced by task_download().

638 {
639  struct Hostlist *lowest_quality;
640 
642  {
643  /* No free entries available, replace existing entry */
644  lowest_quality = linked_list_get_lowest_quality ();
645  GNUNET_assert (lowest_quality != NULL);
647  "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n",
648  lowest_quality->hostlist_uri,
649  (unsigned long long) lowest_quality->quality);
651  lowest_quality);
653  GNUNET_free (lowest_quality);
654  }
658  GNUNET_STATISTICS_set (stats, gettext_noop ("# advertised hostlist URIs"),
661 }
#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.
uint64_t quality
Value describing the quality of the hostlist, the bigger the better but (should) never < 0 used for d...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
const char * hostlist_uri
URI where hostlist can be obtained.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
static struct Hostlist * linked_list_tail
Tail of the linked list used to store hostlists.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static unsigned int linked_list_size
Size of the linke list used to store hostlists.
#define GNUNET_log(kind,...)
static struct Hostlist * linked_list_get_lowest_quality()
Method returning the hostlist element with the lowest quality in the datastore.
#define MAX_NUMBER_HOSTLISTS
Maximum number of hostlist that are saved.
A single hostlist obtained by hostlist advertisements.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
static struct Hostlist * hostlist_to_test
Head of the linked list used to store hostlists.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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 668 of file gnunet-daemon-hostlist_client.c.

References checked_add(), checked_sub(), 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, Hostlist::time_last_usage, and Hostlist::times_used.

Referenced by GNUNET_HOSTLIST_client_stop(), and task_download().

669 {
670  char *stat;
671 
672  if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) ||
674  {
676  "Updating hostlist statics for URI `%s'\n",
684  {
688  GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"),
690 
692  GNUNET_free (stat);
693  }
694  else
697  }
698  current_hostlist = NULL;
699  /* Alternating the usage of preconfigured and learned hostlists */
700 
702  return;
703 
704  if (GNUNET_YES == stat_learning)
705  {
708  else
710  }
711  else
713 }
struct GNUNET_TIME_Absolute time_last_usage
Last time the hostlist was obtained.
static uint64_t checked_add(uint64_t val1, uint64_t val2)
Add val2 to val1 with overflow check.
uint64_t quality
Value describing the quality of the hostlist, the bigger the better but (should) never < 0 used for d...
static int stat_learning
Set if we are allowed to learn new hostlists and use them.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define HOSTLIST_SUCCESSFUL_HELLO
Value added for each valid HELLO recived during a hostlist download.
uint32_t hello_count
Number of HELLO messages obtained during last download.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static unsigned int stat_download_successful
Value saying if hostlist download was successful.
const char * hostlist_uri
URI where hostlist can be obtained.
static unsigned int stat_use_bootstrap
Value saying if a preconfigured bootstrap server is used.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static struct Hostlist * current_hostlist
Current hostlist used for downloading.
#define HOSTLIST_SUCCESSFUL_DOWNLOAD
Value added each time a hostlist download is successful.
static unsigned int stat_hellos_obtained
Value saying how many valid HELLO messages were obtained during download.
uint32_t times_used
Number of times the hostlist was successfully obtained.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
#define HOSTLIST_FAILED_DOWNLOAD
Value subtracted each time a hostlist download fails.
static uint64_t checked_sub(uint64_t val1, uint64_t val2)
Subtract val2 from val1 with underflow check.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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 721 of file gnunet-daemon-hostlist_client.c.

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

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

722 {
723  CURLMcode mret;
724 
725  if ( (stat_testing_hostlist == GNUNET_YES) &&
727  (NULL != hostlist_to_test) )
728  {
730  _
731  ("Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"),
733  }
734 
736  {
738  }
739  if (NULL != hostlist_to_test)
740  {
742  hostlist_to_test = NULL;
743  }
744 
745  if (NULL != multi)
746  {
747  mret = curl_multi_remove_handle (multi, curl);
748  if (mret != CURLM_OK)
749  {
750  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
751  "curl_multi_remove_handle", __FILE__, __LINE__,
752  curl_multi_strerror (mret));
753  }
754  mret = curl_multi_cleanup (multi);
755  if (mret != CURLM_OK)
756  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
757  "curl_multi_cleanup", __FILE__, __LINE__,
758  curl_multi_strerror (mret));
759  multi = NULL;
760  }
761  if (NULL != curl)
762  {
763  curl_easy_cleanup (curl);
764  curl = NULL;
765  }
767  current_url = NULL;
770 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static char * current_url
Current URL that we are using.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static CURLM * multi
Current multi-CURL handle.
static unsigned int stat_download_successful
Value saying if hostlist download was successful.
const char * hostlist_uri
URI where hostlist can be obtained.
static CURL * curl
Current CURL handle.
#define GNUNET_log(kind,...)
static uint32_t stat_bytes_downloaded
How many bytes did we download from the current hostlist URL?
#define GNUNET_YES
Definition: gnunet_common.h:80
static int stat_download_in_progress
Value controlling if a hostlist download is running at the moment.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
static struct Hostlist * hostlist_to_test
Head of the linked list used to store hostlists.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
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
tctask context, unused
clsclosure, unused

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

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, insert_hostlist(), MAX_BYTES_PER_HOSTLISTS, msg, multi, stat_bytes_downloaded, stat_download_successful, stat_testing_hostlist, and update_hostlist().

Referenced by clean_up(), and download_prepare().

850 {
851  int running;
852  struct CURLMsg *msg;
853  CURLMcode mret;
854 
855  ti_download = NULL;
856  if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
857  {
859  _("Timeout trying to download hostlist from `%s'\n"),
860  current_url);
861  update_hostlist ();
862  clean_up ();
863  return;
864  }
866  "Ready for processing hostlist client request\n");
867  do
868  {
869  running = 0;
871  {
873  _("Download limit of %u bytes exceeded, stopping download\n"),
875  clean_up ();
876  return;
877  }
878  mret = curl_multi_perform (multi, &running);
879  if (running == 0)
880  {
881  do
882  {
883  msg = curl_multi_info_read (multi, &running);
884  GNUNET_break (msg != NULL);
885  if (msg == NULL)
886  break;
887  switch (msg->msg)
888  {
889  case CURLMSG_DONE:
890  if ((msg->data.result != CURLE_OK) &&
891  (msg->data.result != CURLE_GOT_NOTHING))
893  _("Download of hostlist from `%s' failed: `%s'\n"),
894  current_url,
895  curl_easy_strerror (msg->data.result));
896  else
897  {
899  _("Download of hostlist `%s' completed.\n"),
900  current_url);
902  update_hostlist ();
904  {
906  _
907  ("Adding successfully tested hostlist `%s' datastore.\n"),
908  current_url);
909  insert_hostlist ();
910  hostlist_to_test = NULL;
912  }
913  }
914  clean_up ();
915  return;
916  default:
917  break;
918  }
919 
920  }
921  while ((running > 0));
922  }
923  }
924  while (mret == CURLM_CALL_MULTI_PERFORM);
925 
926  if (mret != CURLM_OK)
927  {
928  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%s failed at %s:%d: `%s'\n"),
929  "curl_multi_perform", __FILE__, __LINE__,
930  curl_multi_strerror (mret));
931  clean_up ();
932  }
933  download_prepare ();
934 }
#define MAX_BYTES_PER_HOSTLISTS
How many bytes do we download at most from a hostlist server?
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_TIME_Absolute end_time
At what time MUST the current hostlist request be done?
static struct GNUNET_SCHEDULER_Task * ti_download
ID of the task downloading the hostlist.
#define GNUNET_NO
Definition: gnunet_common.h:81
static void update_hostlist()
Method updating hostlist statistics.
static char * current_url
Current URL that we are using.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void insert_hostlist()
Method to insert a hostlist into the datastore.
static CURLM * multi
Current multi-CURL handle.
static unsigned int stat_download_successful
Value saying if hostlist download was successful.
static void download_prepare()
Ask CURL for the select set and then schedule the receiving task with the scheduler.
static void clean_up()
Clean up the state from the task that downloaded the hostlist and schedule the next task...
#define GNUNET_log(kind,...)
static uint32_t stat_bytes_downloaded
How many bytes did we download from the current hostlist URL?
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:331
#define GNUNET_YES
Definition: gnunet_common.h:80
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
static struct Hostlist * hostlist_to_test
Head of the linked list used to store hostlists.
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 789 of file gnunet-daemon-hostlist_client.c.

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, multi, task_download(), and timeout.

Referenced by download_hostlist(), and task_download().

790 {
791  CURLMcode mret;
792  fd_set rs;
793  fd_set ws;
794  fd_set es;
795  int max;
796  struct GNUNET_NETWORK_FDSet *grs;
797  struct GNUNET_NETWORK_FDSet *gws;
798  long timeout;
799  struct GNUNET_TIME_Relative rtime;
800 
801  max = -1;
802  FD_ZERO (&rs);
803  FD_ZERO (&ws);
804  FD_ZERO (&es);
805  mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
806  if (mret != CURLM_OK)
807  {
808  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
809  "curl_multi_fdset", __FILE__, __LINE__,
810  curl_multi_strerror (mret));
811  clean_up ();
812  return;
813  }
814  mret = curl_multi_timeout (multi, &timeout);
815  if (mret != CURLM_OK)
816  {
817  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
818  "curl_multi_timeout", __FILE__, __LINE__,
819  curl_multi_strerror (mret));
820  clean_up ();
821  return;
822  }
823  rtime =
826  (GNUNET_TIME_UNIT_MILLISECONDS, timeout));
829  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
830  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
832  "Scheduling task for hostlist download using cURL\n");
833  ti_download =
835  rtime, grs, gws,
836  &task_download, multi);
839 }
static void task_download(void *cls)
Task that is run when we are ready to receive more data from the hostlist server. ...
static struct GNUNET_TIME_Absolute end_time
At what time MUST the current hostlist request be done?
static struct GNUNET_SCHEDULER_Task * ti_download
ID of the task downloading the hostlist.
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:1308
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
static CURLM * multi
Current multi-CURL handle.
collection of IO descriptors
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:1829
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:439
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
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:271
static void clean_up()
Clean up the state from the task that downloaded the hostlist and schedule the next task...
#define GNUNET_log(kind,...)
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:331
Run with the default priority (normal P2P operations).
Time for relative time used by GNUnet, in microseconds.
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 942 of file gnunet-daemon-hostlist_client.c.

References _, callback_download(), clean_up(), curl, CURL_EASY_SETOPT, current_url, download_get_url(), download_pos, download_prepare(), end_time, gettext_noop, 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, and stat_hellos_obtained.

Referenced by task_download_dispatcher().

943 {
944  CURLcode ret;
945  CURLMcode mret;
946 
947 
949  if (current_url == NULL)
950  return;
951  curl = curl_easy_init ();
952  multi = NULL;
953  if (curl == NULL)
954  {
955  GNUNET_break (0);
956  clean_up ();
957  return;
958  }
960  _("Bootstrapping using hostlist at `%s'.\n"), current_url);
961 
966 
968  gettext_noop ("# hostlist downloads initiated"), 1,
969  GNUNET_NO);
970  if (NULL != proxy)
971  {
972  CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy);
973  CURL_EASY_SETOPT (curl, CURLOPT_PROXYTYPE, proxy_type);
974  if (NULL != proxy_username)
975  CURL_EASY_SETOPT (curl, CURLOPT_PROXYUSERNAME, proxy_username);
976  if (NULL != proxy_password)
977  CURL_EASY_SETOPT (curl, CURLOPT_PROXYPASSWORD, proxy_password);
978  }
979  download_pos = 0;
980  stat_bogus_url = 0;
981  CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download);
982  if (ret != CURLE_OK)
983  {
984  clean_up ();
985  return;
986  }
987  CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL);
988  if (ret != CURLE_OK)
989  {
990  clean_up ();
991  return;
992  }
993  CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
994  CURL_EASY_SETOPT (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
995  CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
996  CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
997  /* no need to abort if the above failed */
998  CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url);
999  if (ret != CURLE_OK)
1000  {
1001  clean_up ();
1002  return;
1003  }
1004  CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1);
1005 #if 0
1006  CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1);
1007 #endif
1008  CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE);
1009  if (0 == strncmp (current_url, "http", 4))
1010  CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet");
1011  CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L);
1012  CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L);
1013  multi = curl_multi_init ();
1014  if (multi == NULL)
1015  {
1016  GNUNET_break (0);
1017  /* clean_up (); */
1018  return;
1019  }
1020  mret = curl_multi_add_handle (multi, curl);
1021  if (mret != CURLM_OK)
1022  {
1023  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
1024  "curl_multi_add_handle", __FILE__, __LINE__,
1025  curl_multi_strerror (mret));
1026  mret = curl_multi_cleanup (multi);
1027  if (mret != CURLM_OK)
1028  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
1029  "curl_multi_cleanup", __FILE__, __LINE__,
1030  curl_multi_strerror (mret));
1031  multi = NULL;
1032  clean_up ();
1033  return;
1034  }
1036  download_prepare ();
1037 }
static struct GNUNET_TIME_Absolute end_time
At what time MUST the current hostlist request be done?
#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:245
static curl_proxytype proxy_type
Proxy type we are using (can be NULL).
#define GNUNET_NO
Definition: gnunet_common.h:81
static size_t download_pos
Number of bytes valid in &#39;download_buffer&#39;.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static char * proxy_username
Proxy username we are using (can be NULL).
static int ret
Final status code.
Definition: gnunet-arm.c:89
static char * current_url
Current URL that we are using.
static char * proxy
Proxy hostname or ip we are using (can be NULL).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define CURL_EASY_SETOPT(c, a, b)
static char * proxy_password
Proxy password we are using (can be NULL).
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static CURLM * multi
Current multi-CURL handle.
static unsigned int stat_download_successful
Value saying if hostlist download was successful.
static int stat_bogus_url
Set to GNUNET_YES if the current URL had some problems.
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 CURL * curl
Current CURL handle.
static unsigned int stat_hellos_obtained
Value saying how many valid HELLO messages were obtained during download.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
static void download_prepare()
Ask CURL for the select set and then schedule the receiving task with the scheduler.
static void clean_up()
Clean up the state from the task that downloaded the hostlist and schedule the next task...
#define GNUNET_log(kind,...)
static uint32_t stat_bytes_downloaded
How many bytes did we download from the current hostlist URL?
static char * download_get_url()
Method deciding if a preconfigured or advertisied hostlist is used on a 50:50 ratio.
#define GNUNET_YES
Definition: gnunet_common.h:80
static int stat_download_in_progress
Value controlling if a hostlist download is running at the moment.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
#define gettext_noop(String)
Definition: gettext.h:69
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 1041 of file gnunet-daemon-hostlist_client.c.

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

Referenced by handler_advertisement(), and task_check().

1042 {
1044  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
1046  {
1047  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n");
1048  download_hostlist ();
1049  }
1050  else
1051  {
1053  "Download in progess, have to wait...\n");
1056  &task_download_dispatcher, NULL);
1057  }
1058 }
#define WAITING_INTERVAL
Time interval for download dispatcher before a download is re-scheduled.
static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task
ID of the task called to initiate a download.
#define GNUNET_NO
Definition: gnunet_common.h:81
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:1246
static void task_download_dispatcher(void *cls)
static void download_hostlist()
Main function that will download a hostlist and process its data.
#define GNUNET_log(kind,...)
static int stat_download_in_progress
Value controlling if a hostlist download is running at the moment.
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 1067 of file gnunet-daemon-hostlist_client.c.

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, and task_download_dispatcher().

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

1068 {
1069  static int once;
1070  struct GNUNET_TIME_Relative delay;
1071 
1072  ti_check_download = NULL;
1073  if (stats == NULL)
1074  {
1075  curl_global_cleanup ();
1076  return; /* in shutdown */
1077  }
1079  (NULL == ti_download_dispatcher_task) )
1082 
1084  if (0 == hostlist_delay.rel_value_us)
1086  else
1089  GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count))
1090  hostlist_delay =
1092  (1 + stat_connection_count));
1094  gettext_noop
1095  ("# milliseconds between hostlist downloads"),
1096  hostlist_delay.rel_value_us / 1000LL,
1097  GNUNET_YES);
1098  if (0 == once)
1099  {
1101  once = 1;
1102  }
1104  _("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
1107  ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
1108  &task_check, NULL);
1109 }
#define GNUNET_TIME_UNIT_HOURS
One hour.
uint64_t rel_value_us
The actual value.
static unsigned int stat_connection_count
Number of active connections (according to core service).
static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task
ID of the task called to initiate a download.
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
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:1246
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:1273
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:727
static int once
Global to mark if we&#39;ve run the initialization.
Definition: gnsrecord.c:68
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:439
static void task_download_dispatcher(void *cls)
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static void task_check(void *cls)
Task that checks if we should try to download a hostlist.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
static struct GNUNET_SCHEDULER_Task * ti_check_download
ID of the task, checking if hostlist download should take plate.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
#define MIN_CONNECTIONS
Number of connections that we must have to NOT download hostlists anymore.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
static struct GNUNET_TIME_Relative hostlist_delay
Amount of time we wait between hostlist downloads.
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
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 intervall between to testings is reached.

Parameters
clsclosure

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

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, and stat_testing_allowed.

Referenced by handler_advertisement().

1119 {
1123  "Testing new hostlist advertisements is allowed again\n");
1124 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int stat_testing_allowed
Value controlling if a hostlist testing is allowed at the moment.
static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task
ID of the task controlling the locking between two hostlist tests.
#define GNUNET_log(kind,...)
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 1133 of file gnunet-daemon-hostlist_client.c.

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

Referenced by GNUNET_HOSTLIST_client_start().

1134 {
1135  ti_saving_task = NULL;
1137 
1139  "Hostlists will be saved to file again in %s\n",
1141  ti_saving_task =
1144  NULL);
1145 }
static struct GNUNET_SCHEDULER_Task * ti_saving_task
ID of the task saving the hostlsit in a regular intervall.
#define GNUNET_NO
Definition: gnunet_common.h:81
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:1246
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:727
static void save_hostlist_file(int shutdown)
Method to save hostlist to a file during hostlist client shutdown.
#define GNUNET_log(kind,...)
#define SAVING_INTERVAL
Time interval hostlists are saved to disk.
static void task_hostlist_saving(void *cls)
Task that writes hostlist entries to a file on a regular base.
#define GNUNET_YES
Definition: gnunet_common.h:80
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 
)
static

Method called whenever a given peer connects.

Parameters
clsclosure
peerpeer identity this notification is about
mqmessage queue for transmissions to peer

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

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

Referenced by GNUNET_HOSTLIST_client_start().

1159 {
1160  GNUNET_assert (stat_connection_count < UINT_MAX);
1163  gettext_noop ("# active connections"),
1164  1,
1165  GNUNET_NO);
1166  return NULL;
1167 }
static unsigned int stat_connection_count
Number of active connections (according to core service).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
#define gettext_noop(String)
Definition: gettext.h:69
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 1177 of file gnunet-daemon-hostlist_client.c.

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

Referenced by GNUNET_HOSTLIST_client_start().

1180 {
1184  gettext_noop ("# active connections"),
1185  -1,
1186  GNUNET_NO);
1187 }
static unsigned int stat_connection_count
Number of active connections (according to core service).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
#define gettext_noop(String)
Definition: gettext.h:69
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 1196 of file gnunet-daemon-hostlist_client.c.

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::hostlist_uri, linked_list_contains(), Hostlist::quality, stat_testing_allowed, stat_testing_hostlist, task_download_dispatcher(), task_testing_intervall_reset(), TESTING_INTERVAL, and Hostlist::time_creation.

Referenced by GNUNET_HOSTLIST_client_start().

1197 {
1198  size_t uri_size;
1199  struct Hostlist *hostlist;
1200 
1201  uri_size = strlen (uri) + 1;
1203  "Hostlist client recieved advertisement containing URI `%s'\n",
1204  uri);
1206  {
1208  "URI `%s' is already known\n",
1209  uri);
1210  return;
1211  }
1212 
1214  {
1216  "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
1217  return;
1218  }
1220  {
1222  "Currently not accepting new advertisements: we are already testing a hostlist\n");
1223  return;
1224  }
1225 
1226  hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size);
1227  hostlist->hostlist_uri = (const char *) &hostlist[1];
1228  GNUNET_memcpy (&hostlist[1],
1229  uri,
1230  uri_size);
1231  hostlist->time_creation = GNUNET_TIME_absolute_get ();
1232  hostlist->quality = HOSTLIST_INITIAL;
1233  hostlist_to_test = hostlist;
1234 
1240  NULL);
1241 
1243  "Testing new hostlist advertisements is locked for the next %s\n",
1245  GNUNET_YES));
1246 
1249  NULL);
1250 }
#define TESTING_INTERVAL
Time interval between two hostlist tests.
struct GNUNET_TIME_Absolute time_creation
Time the hostlist advertisement was recieved and the entry was created.
uint64_t quality
Value describing the quality of the hostlist, the bigger the better but (should) never < 0 used for d...
#define HOSTLIST_INITIAL
Defines concerning the hostlist quality metric.
static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task
ID of the task called to initiate a download.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
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:1246
#define GNUNET_memcpy(dst, src, n)
static int stat_testing_allowed
Value controlling if a hostlist testing is allowed at the moment.
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:1273
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:727
static int linked_list_contains(const char *uri)
Method to check if a URI is in hostlist linked list.
const char * hostlist_uri
URI where hostlist can be obtained.
static void task_download_dispatcher(void *cls)
static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task
ID of the task controlling the locking between two hostlist tests.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static void task_testing_intervall_reset(void *cls)
This tasks sets hostlist testing to allowed after intervall between to testings is reached...
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
A single hostlist obtained by hostlist advertisements.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
#define GNUNET_malloc(size)
Wrapper around malloc.
static struct Hostlist * hostlist_to_test
Head of the linked list used to store hostlists.
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 1262 of file gnunet-daemon-hostlist_client.c.

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

Referenced by GNUNET_HOSTLIST_client_start().

1264 {
1265  if (NULL != ti_check_download)
1266  {
1268  ti_check_download = NULL;
1269  }
1270  sget = NULL;
1271  GNUNET_assert (NULL != stats);
1273  "Statistics request done, scheduling hostlist download\n");
1275 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:1273
static void task_check(void *cls)
Task that checks if we should try to download a hostlist.
static struct GNUNET_STATISTICS_GetHandle * sget
Handle for our statistics GET operation.
static struct GNUNET_SCHEDULER_Task * ti_check_download
ID of the task, checking if hostlist download should take plate.
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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
successGNUNET_OK if statistics were successfully obtained, GNUNET_SYSERR if not.

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

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

Referenced by GNUNET_HOSTLIST_client_start().

1288 {
1290  sget = NULL;
1292  NULL);
1293 }
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
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:1273
static void task_check(void *cls)
Task that checks if we should try to download a hostlist.
static struct GNUNET_STATISTICS_GetHandle * sget
Handle for our statistics GET operation.
static struct GNUNET_SCHEDULER_Task * ti_check_download
ID of the task, checking if hostlist download should take plate.
Here is the call graph for this function:
Here is the caller 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 1306 of file gnunet-daemon-hostlist_client.c.

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

Referenced by GNUNET_HOSTLIST_client_start().

1311 {
1312  hostlist_delay.rel_value_us = value * 1000LL;
1314  "Initial time between hostlist downloads is %s\n",
1316  GNUNET_YES));
1317  return GNUNET_OK;
1318 }
uint64_t rel_value_us
The actual value.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static char * value
Value of the record to add/remove.
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:727
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_TIME_Relative hostlist_delay
Amount of time we wait between hostlist downloads.
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 1325 of file gnunet-daemon-hostlist_client.c.

References _, GNUNET_TIME_Absolute::abs_value_us, filename, gettext_noop, GNUNET_BIO_read_close(), GNUNET_BIO_read_int32, GNUNET_BIO_read_int64, GNUNET_BIO_read_open(), 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_free_non_null, 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_size, MAX_NUMBER_HOSTLISTS, MAX_URL_LEN, Hostlist::quality, STRERROR, Hostlist::time_creation, Hostlist::time_last_usage, Hostlist::times_used, and uri.

Referenced by GNUNET_HOSTLIST_client_start().

1326 {
1327  char *filename;
1328  char *uri;
1329  char *emsg;
1330  struct Hostlist *hostlist;
1331  uint32_t times_used;
1332  uint32_t hellos_returned;
1333  uint64_t quality;
1334  uint64_t last_used;
1335  uint64_t created;
1336  uint32_t counter;
1337  struct GNUNET_BIO_ReadHandle *rh;
1338 
1339  uri = NULL;
1340  if (GNUNET_OK !=
1341  GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE",
1342  &filename))
1343  {
1345  "hostlist", "HOSTLISTFILE");
1346  return;
1347  }
1348 
1350  _("Loading saved hostlist entries from file `%s' \n"),
1351  filename);
1352  if (GNUNET_NO == GNUNET_DISK_file_test (filename))
1353  {
1355  _("Hostlist file `%s' does not exist\n"), filename);
1356  GNUNET_free (filename);
1357  return;
1358  }
1359 
1360  rh = GNUNET_BIO_read_open (filename);
1361  if (NULL == rh)
1362  {
1364  _("Could not open file `%s' for reading to load hostlists: %s\n"),
1365  filename, STRERROR (errno));
1366  GNUNET_free (filename);
1367  return;
1368  }
1369 
1370  counter = 0;
1371  while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) &&
1372  (NULL != uri) && (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &times_used))
1373  && (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
1374  (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) &&
1375  (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) &&
1376  (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)))
1377  {
1378  hostlist = GNUNET_malloc (sizeof (struct Hostlist) + strlen (uri) + 1);
1379  hostlist->hello_count = hellos_returned;
1380  hostlist->hostlist_uri = (const char *) &hostlist[1];
1381  GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1);
1382  hostlist->quality = quality;
1383  hostlist->time_creation.abs_value_us = created;
1384  hostlist->time_last_usage.abs_value_us = last_used;
1386  linked_list_size++;
1388  "Added hostlist entry eith URI `%s' \n",
1389  hostlist->hostlist_uri);
1390  GNUNET_free (uri);
1391  uri = NULL;
1392  counter++;
1393  if (counter >= MAX_NUMBER_HOSTLISTS)
1394  break;
1395  }
1396 
1398  _("%u hostlist URIs loaded from file\n"),
1399  counter);
1401  gettext_noop ("# hostlist URIs read from file"),
1402  counter, GNUNET_YES);
1404  gettext_noop ("# advertised hostlist URIs"),
1406 
1407  GNUNET_free_non_null (uri);
1408  emsg = NULL;
1409  (void) GNUNET_BIO_read_close (rh, &emsg);
1410  if (emsg != NULL)
1411  GNUNET_free (emsg);
1412  GNUNET_free (filename);
1413 }
int 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:669
struct GNUNET_TIME_Absolute time_last_usage
Last time the hostlist was obtained.
#define MAX_URL_LEN
How long can hostlist URLs be?
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_TIME_Absolute time_creation
Time the hostlist advertisement was recieved and the entry was created.
uint64_t quality
Value describing the quality of the hostlist, the bigger the better but (should) never < 0 used for d...
#define STRERROR(i)
Definition: plibc.h:676
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
uint64_t abs_value_us
The actual value.
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open file.
Definition: bio.c:119
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open(const char *fn)
Open a file for reading.
Definition: bio.c:94
uint32_t hello_count
Number of HELLO messages obtained during last download.
#define GNUNET_BIO_read_int64(h, i)
Read an (u)int64_t.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
#define GNUNET_memcpy(dst, src, n)
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static char * filename
const char * hostlist_uri
URI where hostlist can be obtained.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
static struct Hostlist * linked_list_tail
Tail of the linked list used to store hostlists.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string from a file.
Definition: bio.c:237
static unsigned int linked_list_size
Size of the linke list used to store hostlists.
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
uint32_t times_used
Number of times the hostlist was successfully obtained.
#define GNUNET_log(kind,...)
int 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.
#define MAX_NUMBER_HOSTLISTS
Maximum number of hostlist that are saved.
#define GNUNET_YES
Definition: gnunet_common.h:80
A single hostlist obtained by hostlist advertisements.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
#define GNUNET_malloc(size)
Wrapper around malloc.
Handle for buffered reading.
Definition: bio.c:53
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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 1512 of file gnunet-daemon-hostlist_client.c.

References _, 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_free, GNUNET_free_non_null, GNUNET_log, GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_PEERINFO_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(), load_hostlist_file(), primary_task(), process_stat(), proxy, proxy_password, proxy_type, proxy_username, result, SAVING_INTERVAL, st, stat_learning, stat_testing_allowed, stat_testing_hostlist, stat_timeout_task(), stat_use_bootstrap, task_check(), and task_hostlist_saving().

Referenced by run().

1518 {
1519  char *filename;
1520  char *proxytype_str;
1521  int result;
1522 
1523  GNUNET_assert (NULL != st);
1524  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
1525  {
1526  GNUNET_break (0);
1527  return GNUNET_SYSERR;
1528  }
1529  cfg = c;
1530  stats = st;
1531 
1532  /* Read proxy configuration */
1534  if (GNUNET_OK ==
1536  "HOSTLIST",
1537  "PROXY",
1538  &proxy))
1539  {
1541  "Found proxy host: `%s'\n",
1542  proxy);
1543  /* proxy username */
1544  if (GNUNET_OK ==
1546  "HOSTLIST",
1547  "PROXY_USERNAME",
1548  &proxy_username))
1549  {
1551  "Found proxy username name: `%s'\n",
1552  proxy_username);
1553  }
1554 
1555  /* proxy password */
1556  if (GNUNET_OK ==
1558  "HOSTLIST",
1559  "PROXY_PASSWORD",
1560  &proxy_password))
1561  {
1563  "Found proxy password name: `%s'\n",
1564  proxy_password);
1565  }
1566 
1567  /* proxy type */
1568  if (GNUNET_OK ==
1570  "HOSTLIST",
1571  "PROXY_TYPE",
1572  &proxytype_str))
1573  {
1574  GNUNET_STRINGS_utf8_toupper (proxytype_str,
1575  proxytype_str);
1576  proxy_type = CURLPROXY_HTTP;
1577  if (0 == strcmp (proxytype_str, "HTTP"))
1578  proxy_type = CURLPROXY_HTTP;
1579  else if (0 == strcmp (proxytype_str, "HTTP_1_0"))
1580  proxy_type = CURLPROXY_HTTP_1_0;
1581  else if (0 == strcmp (proxytype_str, "SOCKS4"))
1582  proxy_type = CURLPROXY_SOCKS4;
1583  else if (0 == strcmp (proxytype_str, "SOCKS5"))
1584  proxy_type = CURLPROXY_SOCKS5;
1585  else if (0 == strcmp (proxytype_str, "SOCKS4A"))
1586  proxy_type = CURLPROXY_SOCKS4A;
1587  else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME"))
1588  proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1589  else
1590  {
1592  _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
1593  proxytype_str);
1594  GNUNET_free (proxytype_str);
1595  GNUNET_free (proxy);
1596  proxy = NULL;
1598  proxy_username = NULL;
1600  proxy_password = NULL;
1601 
1602  return GNUNET_SYSERR;
1603  }
1604  }
1605  GNUNET_free_non_null (proxytype_str);
1606  }
1607 
1608  stat_learning = learn;
1609  *ch = &handler_connect;
1610  *dh = &handler_disconnect;
1611  linked_list_head = NULL;
1612  linked_list_tail = NULL;
1616 
1617  if (GNUNET_YES == stat_learning)
1618  {
1619  *msgh = &handler_advertisement;
1621  _("Learning is enabled on this peer\n"));
1622  load_hostlist_file ();
1624  "Hostlists will be saved to file again in %s\n",
1626  GNUNET_YES));
1627  ti_saving_task =
1630  NULL);
1631  }
1632  else
1633  {
1635  _("Learning is not enabled on this peer\n"));
1636  *msgh = NULL;
1637  if (GNUNET_OK ==
1639  "HOSTLIST",
1640  "HOSTLISTFILE",
1641  &filename))
1642  {
1643  if (GNUNET_YES == GNUNET_DISK_file_test (filename))
1644  {
1645  result = remove (filename);
1646  if (0 == result)
1648  _("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1649  filename);
1650  else
1652  "remove",
1653  filename);
1654  }
1655  }
1656  GNUNET_free (filename);
1657  }
1659  "Loading stats value on hostlist download frequency\n");
1660  sget = GNUNET_STATISTICS_get (stats, "hostlist",
1661  gettext_noop
1662  ("# milliseconds between hostlist downloads"),
1663  &primary_task,
1664  &process_stat,
1665  NULL);
1666  if (NULL == sget)
1667  {
1669  "Statistics request failed, scheduling hostlist download\n");
1671  NULL);
1672  }
1673  else
1674  {
1678  NULL);
1679  }
1680  return GNUNET_OK;
1681 }
int 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:669
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Definition: peerinfo_api.c:133
static int stat_learning
Set if we are allowed to learn new hostlists and use them.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
static struct GNUNET_SCHEDULER_Task * ti_saving_task
ID of the task saving the hostlsit in a regular intervall.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void load_hostlist_file()
Method to load persistent hostlist file during hostlist client startup.
static void handler_advertisement(const char *uri)
Method called whenever an advertisement message arrives.
static curl_proxytype proxy_type
Proxy type we are using (can be NULL).
static int process_stat(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
We&#39;ve received the previous delay value from statistics.
static void * handler_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
#define GNUNET_NO
Definition: gnunet_common.h:81
static void primary_task(void *cls, int success)
Continuation called by the statistics code once we go the stat.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static char * proxy_username
Proxy username we are using (can be NULL).
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
static char * proxy
Proxy hostname or ip we are using (can be NULL).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * proxy_password
Proxy password we are using (can be NULL).
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void stat_timeout_task(void *cls)
Continuation called by the statistics code once we go the stat.
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:1246
void GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:580
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static int stat_testing_allowed
Value controlling if a hostlist testing is allowed at the moment.
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:1273
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:727
static char * filename
static int result
Global testing status.
static unsigned int stat_use_bootstrap
Value saying if a preconfigured bootstrap server is used.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
static struct Hostlist * linked_list_tail
Tail of the linked list used to store hostlists.
static void handler_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a given peer disconnects.
static void task_check(void *cls)
Task that checks if we should try to download a hostlist.
int 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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_STATISTICS_GetHandle * sget
Handle for our statistics GET operation.
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.
static struct GNUNET_SCHEDULER_Task * ti_check_download
ID of the task, checking if hostlist download should take plate.
#define GNUNET_log(kind,...)
#define SAVING_INTERVAL
Time interval hostlists are saved to disk.
int 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.
static void task_hostlist_saving(void *cls)
Task that writes hostlist entries to a file on a regular base.
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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 1688 of file gnunet-daemon-hostlist_client.c.

References clean_up(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free_non_null, GNUNET_log, GNUNET_PEERINFO_disconnect(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_get_cancel(), GNUNET_YES, proxy, proxy_password, proxy_username, save_hostlist_file(), stat_learning, and update_hostlist().

Referenced by cleaning_task().

1689 {
1691  "Hostlist client shutdown\n");
1692  if (NULL != sget)
1693  {
1695  sget = NULL;
1696  }
1697  stats = NULL;
1698  if (GNUNET_YES == stat_learning)
1700  if (NULL != ti_saving_task)
1701  {
1703  ti_saving_task = NULL;
1704  }
1705  if (NULL != ti_download_dispatcher_task)
1706  {
1709  }
1710  if (NULL != ti_testing_intervall_task)
1711  {
1714  }
1715  if (NULL != ti_download)
1716  {
1718  ti_download = NULL;
1719  update_hostlist ();
1720  clean_up ();
1721  }
1722  if (NULL != ti_check_download)
1723  {
1725  ti_check_download = NULL;
1726  curl_global_cleanup ();
1727  }
1729  proxy = NULL;
1731  proxy_username = NULL;
1733  proxy_password = NULL;
1734  if (NULL != pi)
1735  {
1737  pi = NULL;
1738  }
1739  cfg = NULL;
1740 }
static int stat_learning
Set if we are allowed to learn new hostlists and use them.
static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task
ID of the task called to initiate a download.
static struct GNUNET_SCHEDULER_Task * ti_saving_task
ID of the task saving the hostlsit in a regular intervall.
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
static struct GNUNET_SCHEDULER_Task * ti_download
ID of the task downloading the hostlist.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static void update_hostlist()
Method updating hostlist statistics.
static char * proxy_username
Proxy username we are using (can be NULL).
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
static char * proxy
Proxy hostname or ip we are using (can be NULL).
static char * proxy_password
Proxy password we are using (can be NULL).
static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task
ID of the task controlling the locking between two hostlist tests.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void save_hostlist_file(int shutdown)
Method to save hostlist to a file during hostlist client shutdown.
static void clean_up()
Clean up the state from the task that downloaded the hostlist and schedule the next task...
static struct GNUNET_STATISTICS_GetHandle * sget
Handle for our statistics GET operation.
static struct GNUNET_SCHEDULER_Task * ti_check_download
ID of the task, checking if hostlist download should take plate.
#define GNUNET_log(kind,...)
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
Definition: peerinfo_api.c:159
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

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

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Statistics handle.

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

◆ proxy

char* proxy
static

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

Definition at line 156 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 161 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 166 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 171 of file gnunet-daemon-hostlist_client.c.

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

◆ download_pos

size_t download_pos
static

Number of bytes valid in 'download_buffer'.

Definition at line 176 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 181 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 186 of file gnunet-daemon-hostlist_client.c.

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

◆ multi

CURLM* multi
static

Current multi-CURL handle.

Definition at line 191 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 196 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 201 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 206 of file gnunet-daemon-hostlist_client.c.

◆ ti_download

struct GNUNET_SCHEDULER_Task* ti_download
static

ID of the task downloading the hostlist.

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

◆ ti_saving_task

struct GNUNET_SCHEDULER_Task* ti_saving_task
static

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

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

◆ 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 221 of file gnunet-daemon-hostlist_client.c.

◆ 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 226 of file gnunet-daemon-hostlist_client.c.

◆ end_time

struct GNUNET_TIME_Absolute end_time
static

At what time MUST the current hostlist request be done?

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

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

◆ linked_list_head

struct Hostlist* linked_list_head
static

Head of the linked list used to store hostlists.

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

Referenced by download_get_url(), linked_list_contains(), and linked_list_get_lowest_quality().

◆ linked_list_tail

struct Hostlist* linked_list_tail
static

Tail of the linked list used to store hostlists.

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

◆ current_hostlist

struct Hostlist* current_hostlist
static

Current hostlist used for downloading.

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

◆ linked_list_size

unsigned int linked_list_size
static

Size of the linke list used to store hostlists.

Definition at line 251 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 256 of file gnunet-daemon-hostlist_client.c.

Referenced by download_get_url().

◆ sget

struct GNUNET_STATISTICS_GetHandle* sget
static

Handle for our statistics GET operation.

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

◆ stat_bogus_url

int stat_bogus_url
static

Set to GNUNET_YES if the current URL had some problems.

Definition at line 266 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 271 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 276 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 281 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 286 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 291 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 296 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 301 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 306 of file gnunet-daemon-hostlist_client.c.

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

◆ pi

struct GNUNET_PEERINFO_Handle* pi
static