GNUnet 0.22.1
gnunet-daemon-hostlist_client.c File Reference

hostlist support. More...

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

Go to the source code of this file.

Data Structures

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

Macros

#define MIN_CONNECTIONS   4
 Number of connections that we must have to NOT download hostlists anymore. 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 received during a hostlist download. More...
 
#define CURL_EASY_SETOPT(c, a, b)
 

Functions

static void shc_cont (void *cls, int success)
 
static size_t callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
 Process downloaded bits by calling callback on each HELLO. 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 interval 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 interval. 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 StoreHelloEntryshe_head
 Head of the linkd list to store the store context for hellos. More...
 
static struct StoreHelloEntryshe_tail
 Tail of the linkd list to store the store context for hellos. 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 linked 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_PEERSTORE_Handlepeerstore
 Handle to the PEERSTORE 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 40 of file gnunet-daemon-hostlist_client.c.

◆ MAX_NUMBER_HOSTLISTS

#define MAX_NUMBER_HOSTLISTS   30

Maximum number of hostlist that are saved.

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

◆ SAVING_INTERVAL

#define SAVING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)

Time interval hostlists are saved to disk.

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

◆ TESTING_INTERVAL

#define TESTING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)

Time interval between two hostlist tests.

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

◆ WAITING_INTERVAL

#define WAITING_INTERVAL    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)

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

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

◆ HOSTLIST_INITIAL

#define HOSTLIST_INITIAL   10000

Defines concerning the hostlist quality metric.

Initial quality of a new created hostlist

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

◆ HOSTLIST_FAILED_DOWNLOAD

#define HOSTLIST_FAILED_DOWNLOAD   100

Value subtracted each time a hostlist download fails.

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

◆ HOSTLIST_SUCCESSFUL_DOWNLOAD

#define HOSTLIST_SUCCESSFUL_DOWNLOAD   100

Value added each time a hostlist download is successful.

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

◆ HOSTLIST_SUCCESSFUL_HELLO

#define HOSTLIST_SUCCESSFUL_HELLO   1

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

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

◆ CURL_EASY_SETOPT

#define CURL_EASY_SETOPT (   c,
  a,
 
)
Value:
do \
{ \
ret = curl_easy_setopt (c, a, b); \
if (CURLE_OK != ret) \
_ ("%s failed at %s:%d: `%s'\n"), \
"curl_easy_setopt", \
__FILE__, \
__LINE__, \
curl_easy_strerror (ret)); \
} while (0)
static int ret
Final status code.
Definition: gnunet-arm.c:93
@ GNUNET_ERROR_TYPE_WARNING
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

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

Function Documentation

◆ shc_cont()

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

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

345{
346 struct StoreHelloEntry *she = cls;
347
348 she->sc = NULL;
349 if (GNUNET_YES == success)
351 "Hostlist entry stored successfully!\n");
352 else
354 "Error storing hostlist entry!\n");
356 GNUNET_free (she);
357}
static struct StoreHelloEntry * she_head
Head of the linkd list to store the store context for hellos.
static struct StoreHelloEntry * she_tail
Tail of the linkd list to store the store context for hellos.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
Context for a add hello uri request.
struct GNUNET_PEERSTORE_StoreHelloContext * sc
Store hello ctx.

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

Referenced by callback_download().

Here is the caller graph for this function:

◆ callback_download()

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

Process downloaded bits by calling callback on each HELLO.

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

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

371{
372 static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1];
373 struct StoreHelloEntry *she;
374 const char *cbuf = ptr;
375 const struct GNUNET_MessageHeader *msg;
376 size_t total;
377 size_t cpy;
378 size_t left;
379 uint16_t msize;
380
381 total = size * nmemb;
382 stat_bytes_downloaded += total;
383 if ((total == 0) || (stat_bogus_url))
384 {
385 return total; /* ok, no data or bogus data */
386 }
387
390 "# bytes downloaded from hostlist servers"),
391 (int64_t) total,
392 GNUNET_NO);
393 left = total;
394 while ((left > 0) || (download_pos > 0))
395 {
397 GNUNET_memcpy (&download_buffer[download_pos], cbuf, cpy);
398 cbuf += cpy;
399 download_pos += cpy;
400 left -= cpy;
401 if (download_pos < sizeof(struct GNUNET_MessageHeader))
402 {
403 GNUNET_assert (0 == left);
404 break;
405 }
406 msg = (const struct GNUNET_MessageHeader *) download_buffer;
407 msize = ntohs (msg->size);
408 if (msize < sizeof(struct GNUNET_MessageHeader))
409 {
411 stats,
412 gettext_noop ("# invalid HELLOs downloaded from hostlist servers"),
413 1,
414 GNUNET_NO);
416 _ ("Invalid `%s' message received from hostlist at `%s'\n"),
417 "HELLO",
420 stat_bogus_url = 1;
421 return total;
422 }
423 if (download_pos < msize)
424 {
425 GNUNET_assert (left == 0);
426 break;
427 }
429 "Received valid `%s' message from hostlist server.\n",
430 "HELLO");
432 stats,
433 gettext_noop ("# valid HELLOs downloaded from hostlist servers"),
434 1,
435 GNUNET_NO);
437 she = GNUNET_new (struct StoreHelloEntry);
439 msg,
440 shc_cont,
441 she);
442 if (NULL != she->sc)
443 {
445 }
446 else
447 GNUNET_free (she);
448 memmove (download_buffer, &download_buffer[msize], download_pos - msize);
449 download_pos -= msize;
450 }
451 return total;
452}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define gettext_noop(String)
Definition: gettext.h:74
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to the PEERSTORE service.
static size_t download_pos
Number of bytes valid in 'download_buffer'.
static char * current_url
Current URL that we are using.
static void shc_cont(void *cls, int success)
static int stat_bogus_url
Set to GNUNET_YES if the current URL had some problems.
static unsigned int stat_hellos_obtained
Value saying how many valid HELLO messages were obtained during download.
static uint32_t stat_bytes_downloaded
How many bytes did we download from the current hostlist URL?
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MIN(a, b)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_PEERSTORE_StoreHelloContext * GNUNET_PEERSTORE_hello_add(struct GNUNET_PEERSTORE_Handle *h, const struct GNUNET_MessageHeader *msg, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Add hello to peerstore.
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 unsigned int size
Size of the "table".
Definition: peer.c:68
Header for all communications.

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

Referenced by download_hostlist().

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

◆ get_bootstrap_server()

static char * get_bootstrap_server ( )
static

Obtain a hostlist URL that we should use.

Returns
NULL if there is no URL available

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

462{
463 char *servers;
464 char *ret;
465 size_t urls;
466 size_t pos;
467
469 "HOSTLIST",
470 "SERVERS",
471 &servers))
472 {
474 "hostlist",
475 "SERVERS");
476 return NULL;
477 }
478
479 urls = 0;
480 if (strlen (servers) > 0)
481 {
482 urls++;
483 pos = strlen (servers) - 1;
484 while (pos > 0)
485 {
486 if (servers[pos] == ' ')
487 urls++;
488 pos--;
489 }
490 }
491 if (urls == 0)
492 {
494 "hostlist",
495 "SERVERS");
496 GNUNET_free (servers);
497 return NULL;
498 }
499
501 pos = strlen (servers) - 1;
502 while (pos > 0)
503 {
504 if (servers[pos] == ' ')
505 {
506 urls--;
507 servers[pos] = '\0';
508 }
509 if (urls == 0)
510 {
511 pos++;
512 break;
513 }
514 pos--;
515 }
516 ret = GNUNET_strdup (&servers[pos]);
517 GNUNET_free (servers);
518 return ret;
519}
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_OK
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

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

Referenced by download_get_url().

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

◆ download_get_url()

static char * download_get_url ( )
static

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

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

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

528{
529 uint32_t index;
530 unsigned int counter;
531 struct Hostlist *pos;
532
534 {
536 "Using preconfigured bootstrap server\n");
537 current_hostlist = NULL;
538 return get_bootstrap_server ();
539 }
540
542 {
544 "Testing new advertised hostlist if it is obtainable\n");
547 }
548
550 {
552 "Using preconfigured bootstrap server\n");
553 current_hostlist = NULL;
554 return get_bootstrap_server ();
555 }
556 index =
558 counter = 0;
559 pos = linked_list_head;
560 while (counter < index)
561 {
562 pos = pos->next;
563 counter++;
564 }
566 "Using learned hostlist `%s'\n",
567 pos->hostlist_uri);
568 current_hostlist = pos;
569 return GNUNET_strdup (pos->hostlist_uri);
570}
static int stat_learning
Set if we are allowed to learn new hostlists and use them.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
static unsigned int stat_use_bootstrap
Value saying if a preconfigured bootstrap server is used.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
static unsigned int linked_list_size
Size of the linked list used to store hostlists.
static struct Hostlist * hostlist_to_test
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.
A single hostlist obtained by hostlist advertisements.
struct Hostlist * next
next entry, used to manage entries in a double linked list
const char * hostlist_uri
URI where hostlist can be obtained.

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

Referenced by download_hostlist().

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

◆ save_hostlist_file()

static void save_hostlist_file ( int  shutdown)
static

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

Method to save persistent hostlist file during hostlist client shutdown.

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

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

1544{
1545 char *filename;
1546 struct Hostlist *pos;
1547 struct GNUNET_BIO_WriteHandle *wh;
1548 int ok;
1549 uint32_t counter;
1550
1552 "HOSTLIST",
1553 "HOSTLISTFILE",
1554 &filename))
1555 {
1557 "hostlist",
1558 "HOSTLISTFILE");
1559 return;
1560 }
1562 {
1564 return;
1565 }
1567 if (NULL == wh)
1568 {
1570 _ (
1571 "Could not open file `%s' for writing to save hostlists: %s\n"),
1572 filename,
1573 strerror (errno));
1575 return;
1576 }
1578 _ ("Writing %u hostlist URIs to `%s'\n"),
1580 filename);
1581 /* add code to write hostlists to file using bio */
1582 ok = GNUNET_YES;
1583 counter = 0;
1584 while (NULL != (pos = linked_list_head))
1585 {
1586 if (GNUNET_YES == shutdown)
1587 {
1590 }
1591 if (GNUNET_YES == ok)
1592 {
1593 struct GNUNET_BIO_WriteSpec ws[] = {
1594 GNUNET_BIO_write_spec_string ("hostlist uri", pos->hostlist_uri),
1595 GNUNET_BIO_write_spec_int32 ("times used",
1596 (int32_t *) &pos->times_used),
1597 GNUNET_BIO_write_spec_int64 ("quality", (int64_t *) &pos->quality),
1599 "last usage",
1600 (int64_t *) &pos->time_last_usage.abs_value_us),
1602 "creation time",
1603 (int64_t *) &pos->time_creation.abs_value_us),
1604 GNUNET_BIO_write_spec_int32 ("hellos count",
1605 (int32_t *) &pos->hello_count),
1607 };
1609 {
1611 _ ("Error writing hostlist URIs to file `%s'\n"),
1612 filename);
1613 ok = GNUNET_NO;
1614 }
1615 }
1616
1617 if (GNUNET_YES == shutdown)
1618 GNUNET_free (pos);
1619 counter++;
1620 if (counter >= MAX_NUMBER_HOSTLISTS)
1621 break;
1622 }
1624 gettext_noop ("# hostlist URIs written to file"),
1625 counter,
1626 GNUNET_YES);
1627
1628 if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
1630 _ ("Error writing hostlist URIs to file `%s'\n"),
1631 filename);
1633}
#define MAX_NUMBER_HOSTLISTS
Maximum number of hostlist that are saved.
static struct Hostlist * linked_list_tail
Tail of the linked list used to store hostlists.
static char * filename
enum GNUNET_GenericReturnValue GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:556
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:508
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_string(const char *what, const char *s)
Create the specification to write a 0-terminated string.
Definition: bio.c:1199
#define GNUNET_BIO_write_spec_end()
End of specifications marker.
enum GNUNET_GenericReturnValue GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1357
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int32(const char *what, int32_t *i)
Create the specification to write an (u)int32_t.
Definition: bio.c:1244
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int64(const char *what, int64_t *i)
Create the specification to write an (u)int64_t.
Definition: bio.c:1289
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:583
@ GNUNET_SYSERR
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
Handle for buffered writing.
Definition: bio.c:466
Structure specifying a writing operation on an IO handle.
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
uint64_t abs_value_us
The actual value.
struct GNUNET_TIME_Absolute time_last_usage
Last time the hostlist was obtained.
uint64_t quality
Value describing the quality of the hostlist, the bigger the better but (should) never < 0 used for d...
uint32_t hello_count
Number of HELLO messages obtained during last download.
struct GNUNET_TIME_Absolute time_creation
Time the hostlist advertisement was received and the entry was created.
uint32_t times_used
Number of times the hostlist was successfully obtained.

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

Referenced by GNUNET_HOSTLIST_client_stop(), and task_hostlist_saving().

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

◆ checked_add()

static uint64_t checked_add ( uint64_t  val1,
uint64_t  val2 
)
static

Add val2 to val1 with overflow check.

Parameters
val1value 1
val2value 2
Returns
result

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

605{
606 static uint64_t temp;
607 static uint64_t maxv;
608
609 maxv = 0;
610 maxv--;
611
612 temp = val1 + val2;
613 if (temp < val1)
614 return maxv;
615 return temp;
616}

Referenced by update_hostlist().

Here is the caller graph for this function:

◆ checked_sub()

static uint64_t checked_sub ( uint64_t  val1,
uint64_t  val2 
)
static

Subtract val2 from val1 with underflow check.

Parameters
val1value 1
val2value 2
Returns
result

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

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

Referenced by update_hostlist().

Here is the caller graph for this function:

◆ linked_list_contains()

static int linked_list_contains ( const char *  uri)
static

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

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

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

643{
644 struct Hostlist *pos;
645
646 pos = linked_list_head;
647 while (pos != NULL)
648 {
649 if (0 == strcmp (pos->hostlist_uri, uri))
650 return GNUNET_YES;
651 pos = pos->next;
652 }
653 return GNUNET_NO;
654}
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...

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

Referenced by handler_advertisement().

Here is the caller graph for this function:

◆ linked_list_get_lowest_quality()

static struct Hostlist * linked_list_get_lowest_quality ( )
static

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

Returns
hostlist with lowest quality

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

663{
664 struct Hostlist *pos;
665 struct Hostlist *lowest;
666
667 if (linked_list_size == 0)
668 return NULL;
669 lowest = linked_list_head;
670 pos = linked_list_head->next;
671 while (pos != NULL)
672 {
673 if (pos->quality < lowest->quality)
674 lowest = pos;
675 pos = pos->next;
676 }
677 return lowest;
678}

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

Referenced by insert_hostlist().

Here is the caller graph for this function:

◆ insert_hostlist()

static void insert_hostlist ( )
static

Method to insert a hostlist into the datastore.

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

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

688{
689 struct Hostlist *lowest_quality;
690
692 {
693 /* No free entries available, replace existing entry */
694 lowest_quality = linked_list_get_lowest_quality ();
695 GNUNET_assert (lowest_quality != NULL);
696 GNUNET_log (
698 "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n",
699 lowest_quality->hostlist_uri,
700 (unsigned long long) lowest_quality->quality);
703 lowest_quality);
705 GNUNET_free (lowest_quality);
706 }
712 gettext_noop ("# advertised hostlist URIs"),
714 GNUNET_NO);
716}
static struct Hostlist * linked_list_get_lowest_quality()
Method returning the hostlist element with the lowest quality in the datastore.

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

Referenced by task_download().

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

◆ update_hostlist()

static void update_hostlist ( )
static

Method updating hostlist statistics.

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

724{
725 char *stat;
726
727 if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) ||
729 {
731 "Updating hostlist statistics for URI `%s'\n",
739 {
743 GNUNET_asprintf (&stat,
744 gettext_noop ("# advertised URI `%s' downloaded"),
746
748 GNUNET_free (stat);
749 }
750 else
753 }
754 current_hostlist = NULL;
755 /* Alternating the usage of preconfigured and learned hostlists */
756
758 return;
759
761 {
764 else
766 }
767 else
769}
static unsigned int stat_download_successful
Value saying if hostlist download was successful.
static uint64_t checked_add(uint64_t val1, uint64_t val2)
Add val2 to val1 with overflow check.
#define HOSTLIST_SUCCESSFUL_HELLO
Value added for each valid HELLO received during a hostlist download.
#define HOSTLIST_FAILED_DOWNLOAD
Value subtracted each time a hostlist download fails.
#define HOSTLIST_SUCCESSFUL_DOWNLOAD
Value added each time a hostlist download is successful.
static uint64_t checked_sub(uint64_t val1, uint64_t val2)
Subtract val2 from val1 with underflow check.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111

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

Referenced by GNUNET_HOSTLIST_client_stop(), and task_download().

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

◆ clean_up()

static void clean_up ( )
static

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

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

778{
779 CURLMcode mret;
780
783 {
784 GNUNET_log (
786 _ (
787 "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"),
789 }
790
792 {
794 }
795 if (NULL != hostlist_to_test)
796 {
798 hostlist_to_test = NULL;
799 }
800
801 if (NULL != multi)
802 {
803 mret = curl_multi_remove_handle (multi, curl);
804 if (mret != CURLM_OK)
805 {
807 _ ("%s failed at %s:%d: `%s'\n"),
808 "curl_multi_remove_handle",
809 __FILE__,
810 __LINE__,
811 curl_multi_strerror (mret));
812 }
813 mret = curl_multi_cleanup (multi);
814 if (mret != CURLM_OK)
816 _ ("%s failed at %s:%d: `%s'\n"),
817 "curl_multi_cleanup",
818 __FILE__,
819 __LINE__,
820 curl_multi_strerror (mret));
821 multi = NULL;
822 }
823 if (NULL != curl)
824 {
825 curl_easy_cleanup (curl);
826 curl = NULL;
827 }
829 current_url = NULL;
832}
static int stat_download_in_progress
Value controlling if a hostlist download is running at the moment.
static CURL * curl
Current CURL handle.
static CURLM * multi
Current multi-CURL handle.
@ GNUNET_ERROR_TYPE_ERROR

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

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

Here is the caller graph for this function:

◆ task_download()

static void task_download ( void *  cls)
static

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

Parameters
clsclosure, unused

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

912{
913 int running;
914 struct CURLMsg *msg;
915 CURLMcode mret;
916
917 ti_download = NULL;
918 if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
919 {
921 _ ("Timeout trying to download hostlist from `%s'\n"),
924 clean_up ();
925 return;
926 }
928 "Ready for processing hostlist client request\n");
929 do
930 {
931 running = 0;
933 {
935 _ (
936 "Download limit of %u bytes exceeded, stopping download\n"),
938 clean_up ();
939 return;
940 }
941 mret = curl_multi_perform (multi, &running);
942 if (running == 0)
943 {
944 do
945 {
946 msg = curl_multi_info_read (multi, &running);
947 GNUNET_break (msg != NULL);
948 if (msg == NULL)
949 break;
950 switch (msg->msg)
951 {
952 case CURLMSG_DONE:
953 if ((msg->data.result != CURLE_OK) &&
954 (msg->data.result != CURLE_GOT_NOTHING))
956 _ ("Download of hostlist from `%s' failed: `%s'\n"),
958 curl_easy_strerror (msg->data.result));
959 else
960 {
962 _ ("Download of hostlist `%s' completed.\n"),
967 {
968 GNUNET_log (
970 _ ("Adding successfully tested hostlist `%s' datastore.\n"),
973 hostlist_to_test = NULL;
975 }
976 }
977 clean_up ();
978 return;
979
980 default:
981 break;
982 }
983 }
984 while ((running > 0));
985 }
986 }
987 while (mret == CURLM_CALL_MULTI_PERFORM);
988
989 if (mret != CURLM_OK)
990 {
992 _ ("%s failed at %s:%d: `%s'\n"),
993 "curl_multi_perform",
994 __FILE__,
995 __LINE__,
996 curl_multi_strerror (mret));
997 clean_up ();
998 }
1000}
#define MAX_BYTES_PER_HOSTLISTS
How many bytes do we download at most from a hostlist server?
static struct GNUNET_TIME_Absolute end_time
At what time MUST the current hostlist request be done?
static void insert_hostlist()
Method to insert a hostlist into the datastore.
static void update_hostlist()
Method updating hostlist statistics.
static struct GNUNET_SCHEDULER_Task * ti_download
ID of the task downloading the hostlist.
static void clean_up()
Clean up the state from the task that downloaded the hostlist and schedule the next task.
static void download_prepare()
Ask CURL for the select set and then schedule the receiving task with the scheduler.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:406

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

Referenced by download_prepare().

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

◆ download_prepare()

static void download_prepare ( )
static

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

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

851{
852 CURLMcode mret;
853 fd_set rs;
854 fd_set ws;
855 fd_set es;
856 int max;
857 struct GNUNET_NETWORK_FDSet *grs;
858 struct GNUNET_NETWORK_FDSet *gws;
859 long timeout;
860 struct GNUNET_TIME_Relative rtime;
861
862 max = -1;
863 FD_ZERO (&rs);
864 FD_ZERO (&ws);
865 FD_ZERO (&es);
866 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
867 if (mret != CURLM_OK)
868 {
870 _ ("%s failed at %s:%d: `%s'\n"),
871 "curl_multi_fdset",
872 __FILE__,
873 __LINE__,
874 curl_multi_strerror (mret));
875 clean_up ();
876 return;
877 }
878 mret = curl_multi_timeout (multi, &timeout);
879 if (mret != CURLM_OK)
880 {
882 _ ("%s failed at %s:%d: `%s'\n"),
883 "curl_multi_timeout",
884 __FILE__,
885 __LINE__,
886 curl_multi_strerror (mret));
887 clean_up ();
888 return;
889 }
898 "Scheduling task for hostlist download using cURL\n");
900 rtime,
901 grs,
902 gws,
904 multi);
907}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
static void task_download(void *cls)
Task that is run when we are ready to receive more data from the hostlist server.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1187
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1041
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1171
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1834
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:344
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:486
#define max(x, y)
collection of IO descriptors
Time for relative time used by GNUnet, in microseconds.

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

Referenced by download_hostlist(), and task_download().

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

◆ download_hostlist()

static void download_hostlist ( )
static

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

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

1009{
1010 CURLcode ret;
1011 CURLMcode mret;
1012
1013
1015 if (current_url == NULL)
1016 return;
1017 curl = curl_easy_init ();
1018 multi = NULL;
1019 if (curl == NULL)
1020 {
1021 GNUNET_break (0);
1022 clean_up ();
1023 return;
1024 }
1026 _ ("Bootstrapping using hostlist at `%s'.\n"),
1027 current_url);
1028
1033
1035 gettext_noop ("# hostlist downloads initiated"),
1036 1,
1037 GNUNET_NO);
1038 if (NULL != proxy)
1039 {
1040 CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy);
1041 CURL_EASY_SETOPT (curl, CURLOPT_PROXYTYPE, proxy_type);
1042 if (NULL != proxy_username)
1043 CURL_EASY_SETOPT (curl, CURLOPT_PROXYUSERNAME, proxy_username);
1044 if (NULL != proxy_password)
1045 CURL_EASY_SETOPT (curl, CURLOPT_PROXYPASSWORD, proxy_password);
1046 }
1047 download_pos = 0;
1048 stat_bogus_url = 0;
1049 CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download);
1050 if (ret != CURLE_OK)
1051 {
1052 clean_up ();
1053 return;
1054 }
1055 CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL);
1056 if (ret != CURLE_OK)
1057 {
1058 clean_up ();
1059 return;
1060 }
1061 CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
1062#ifdef CURLOPT_REDIR_PROTOCOLS_STR
1063 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1064 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl,
1065 CURLOPT_REDIR_PROTOCOLS_STR,
1066 "https"));
1067 else
1068 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl,
1069 CURLOPT_REDIR_PROTOCOLS_STR,
1070 "http,https"));
1071#else
1072#ifdef CURLOPT_REDIR_PROTOCOLS
1073 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1074 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS,
1075 CURLPROTO_HTTPS));
1076 else
1077 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS,
1078 CURLPROTO_HTTP
1079 | CURLPROTO_HTTPS));
1080#endif
1081#endif
1082#ifdef CURLOPT_PROTOCOLS_STR
1083 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1084 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR,
1085 "https"));
1086 else
1087 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS_STR,
1088 "http,https"));
1089#else
1090#ifdef CURLOPT_PROTOCOLS
1091 if (0 == strncasecmp (current_url, "https://", strlen ("https://")))
1092 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS,
1093 CURLPROTO_HTTPS));
1094 else
1095 GNUNET_assert (CURLE_OK == curl_easy_setopt (curl, CURLOPT_PROTOCOLS,
1096 CURLPROTO_HTTP
1097 | CURLPROTO_HTTPS));
1098#endif
1099#endif
1100 CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
1101 /* no need to abort if the above failed */
1102 CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url);
1103 if (ret != CURLE_OK)
1104 {
1105 clean_up ();
1106 return;
1107 }
1108 CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1);
1109#if 0
1110 CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1);
1111#endif
1112 CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE);
1113 if (0 == strncmp (current_url, "http", 4))
1114 CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet");
1115 CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L);
1116 CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L);
1117 multi = curl_multi_init ();
1118 if (multi == NULL)
1119 {
1120 GNUNET_break (0);
1121 /* clean_up (); */
1122 return;
1123 }
1124 mret = curl_multi_add_handle (multi, curl);
1125 if (mret != CURLM_OK)
1126 {
1128 _ ("%s failed at %s:%d: `%s'\n"),
1129 "curl_multi_add_handle",
1130 __FILE__,
1131 __LINE__,
1132 curl_multi_strerror (mret));
1133 mret = curl_multi_cleanup (multi);
1134 if (mret != CURLM_OK)
1136 _ ("%s failed at %s:%d: `%s'\n"),
1137 "curl_multi_cleanup",
1138 __FILE__,
1139 __LINE__,
1140 curl_multi_strerror (mret));
1141 multi = NULL;
1142 clean_up ();
1143 return;
1144 }
1147}
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).
#define CURL_EASY_SETOPT(c, a, b)
static size_t callback_download(void *ptr, size_t size, size_t nmemb, void *ctx)
Process downloaded bits by calling callback on each HELLO.
static char * download_get_url()
Method deciding if a preconfigured or advertisied hostlist is used on a 50:50 ratio.
static char * proxy_username
Proxy username we are using (can be NULL).
static curl_proxytype proxy_type
Proxy type we are using (can be NULL).
@ GNUNET_ERROR_TYPE_BULK
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316

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

Referenced by task_download_dispatcher().

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

◆ task_download_dispatcher()

static void task_download_dispatcher ( void *  cls)
static

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

1152{
1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
1156 {
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n");
1159 }
1160 else
1161 {
1163 "Download in progress, have to wait...\n");
1167 NULL);
1168 }
1169}
static void task_download_dispatcher(void *cls)
#define WAITING_INTERVAL
Time interval for download dispatcher before a download is re-scheduled.
static void download_hostlist()
Main function that will download a hostlist and process its data.
static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task
ID of the task called to initiate a download.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1276

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

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

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

◆ task_check()

static void task_check ( void *  cls)
static

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

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

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

1179{
1180 static int once;
1181 struct GNUNET_TIME_Relative delay;
1182
1183 ti_check_download = NULL;
1184 if (stats == NULL)
1185 {
1186 curl_global_cleanup ();
1187 return; /* in shutdown */
1188 }
1193
1194 delay = hostlist_delay;
1197 else
1200 GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count))
1203 (1 + stat_connection_count));
1205 gettext_noop (
1206 "# milliseconds between hostlist downloads"),
1208 GNUNET_YES);
1209 if (0 == once)
1210 {
1211 delay = GNUNET_TIME_UNIT_ZERO;
1212 once = 1;
1213 }
1214 GNUNET_log (
1216 _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
1221}
static int once
Global to mark if we've run the initialization.
Definition: gnsrecord.c:65
static void task_check(void *cls)
Task that checks if we should try to download a hostlist.
static struct GNUNET_TIME_Relative hostlist_delay
Amount of time we wait between hostlist downloads.
static unsigned int stat_connection_count
Number of active connections (according to core service).
#define MIN_CONNECTIONS
Number of connections that we must have to NOT download hostlists anymore.
static struct GNUNET_SCHEDULER_Task * ti_check_download
ID of the task, checking if hostlist download should take plate.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1303
#define GNUNET_TIME_UNIT_HOURS
One hour.
#define GNUNET_TIME_UNIT_SECONDS
One second.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:579
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
uint64_t rel_value_us
The actual value.

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

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

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

◆ task_testing_intervall_reset()

static void task_testing_intervall_reset ( void *  cls)
static

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

Parameters
clsclosure

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

1231{
1235 "Testing new hostlist advertisements is allowed again\n");
1236}
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.

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

Referenced by handler_advertisement().

Here is the caller graph for this function:

◆ task_hostlist_saving()

static void task_hostlist_saving ( void *  cls)
static

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

Parameters
clsclosure

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

1246{
1247 ti_saving_task = NULL;
1249
1251 "Hostlists will be saved to file again in %s\n",
1253 GNUNET_YES));
1256}
#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.
static struct GNUNET_SCHEDULER_Task * ti_saving_task
ID of the task saving the hostlsit in a regular interval.
static void save_hostlist_file(int shutdown)
Method to save hostlist to a file during hostlist client shutdown.

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

Referenced by GNUNET_HOSTLIST_client_start(), and task_hostlist_saving().

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

◆ handler_connect()

static void * handler_connect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
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 1267 of file gnunet-daemon-hostlist_client.c.

1270{
1274 gettext_noop ("# active connections"),
1275 1,
1276 GNUNET_NO);
1277 return NULL;
1278}

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

Referenced by GNUNET_HOSTLIST_client_start().

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

◆ handler_disconnect()

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

Method called whenever a given peer disconnects.

Parameters
clsclosure
peerpeer identity this notification is about

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

1291{
1295 gettext_noop ("# active connections"),
1296 -1,
1297 GNUNET_NO);
1298}

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

Referenced by GNUNET_HOSTLIST_client_start().

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

◆ handler_advertisement()

static void handler_advertisement ( const char *  uri)
static

Method called whenever an advertisement message arrives.

Parameters
urithe advertised URI

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

1308{
1309 size_t uri_size;
1310 struct Hostlist *hostlist;
1311
1312 uri_size = strlen (uri) + 1;
1314 "Hostlist client received advertisement containing URI `%s'\n",
1315 uri);
1317 {
1318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri);
1319 return;
1320 }
1321
1323 {
1324 GNUNET_log (
1326 "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
1327 return;
1328 }
1330 {
1331 GNUNET_log (
1333 "Currently not accepting new advertisements: we are already testing a hostlist\n");
1334 return;
1335 }
1336
1337 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + uri_size);
1338 hostlist->hostlist_uri = (const char *) &hostlist[1];
1339 GNUNET_memcpy (&hostlist[1], uri, uri_size);
1341 hostlist->quality = HOSTLIST_INITIAL;
1342 hostlist_to_test = hostlist;
1343
1349 NULL);
1350
1352 "Testing new hostlist advertisements is locked for the next %s\n",
1354 GNUNET_YES));
1355
1358}
static int linked_list_contains(const char *uri)
Method to check if a URI is in hostlist linked list.
#define HOSTLIST_INITIAL
Defines concerning the hostlist quality metric.
#define TESTING_INTERVAL
Time interval between two hostlist tests.
static void task_testing_intervall_reset(void *cls)
This tasks sets hostlist testing to allowed after interval between to testings is reached.
#define GNUNET_malloc(size)
Wrapper around malloc.

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

Referenced by GNUNET_HOSTLIST_client_start().

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

◆ primary_task()

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

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

Initiates hostlist download scheduling.

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

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

1371{
1372 if (NULL != ti_check_download)
1373 {
1375 ti_check_download = NULL;
1376 }
1377 sget = NULL;
1378 GNUNET_assert (NULL != stats);
1380 "Statistics request done, scheduling hostlist download\n");
1382}
static struct GNUNET_STATISTICS_GetHandle * sget
Handle for our statistics GET operation.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979

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

Referenced by GNUNET_HOSTLIST_client_start().

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

◆ stat_timeout_task()

static void stat_timeout_task ( void *  cls)
static

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

Initiates hostlist download scheduling.

Parameters
clsclosure

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

1393{
1395 sget = NULL;
1397}
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.

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

Referenced by GNUNET_HOSTLIST_client_start().

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

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

1415{
1418 "Initial time between hostlist downloads is %s\n",
1420 GNUNET_YES));
1421 return GNUNET_OK;
1422}
static char * value
Value of the record to add/remove.

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

Referenced by GNUNET_HOSTLIST_client_start().

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

◆ load_hostlist_file()

static void load_hostlist_file ( )
static

Method to load persistent hostlist file during hostlist client startup.

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

1430{
1431 char *filename;
1432 char *uri;
1433 char *emsg;
1434 struct Hostlist *hostlist;
1435 uint32_t times_used;
1436 uint32_t hellos_returned;
1437 uint64_t quality;
1438 uint64_t last_used;
1439 uint64_t created;
1440 uint32_t counter;
1441 struct GNUNET_BIO_ReadHandle *rh;
1442
1443 uri = NULL;
1445 "HOSTLIST",
1446 "HOSTLISTFILE",
1447 &filename))
1448 {
1450 "hostlist",
1451 "HOSTLISTFILE");
1452 return;
1453 }
1454
1456 _ ("Loading saved hostlist entries from file `%s' \n"),
1457 filename);
1459 {
1461 _ ("Hostlist file `%s' does not exist\n"),
1462 filename);
1464 return;
1465 }
1466
1468 if (NULL == rh)
1469 {
1471 _ (
1472 "Could not open file `%s' for reading to load hostlists: %s\n"),
1473 filename,
1474 strerror (errno));
1476 return;
1477 }
1478
1479 counter = 0;
1480 {
1481 struct GNUNET_BIO_ReadSpec rs[] = {
1482 GNUNET_BIO_read_spec_int32 ("times used", (int32_t *) &times_used),
1483 GNUNET_BIO_read_spec_int64 ("quality", (int64_t *) &quality),
1484 GNUNET_BIO_read_spec_int64 ("last used", (int64_t *) &last_used),
1485 GNUNET_BIO_read_spec_int64 ("created", (int64_t *) &created),
1486 GNUNET_BIO_read_spec_int32 ("hellos returned",
1487 (int32_t *) &hellos_returned),
1489 };
1490 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN))
1491 &&
1492 (NULL != uri) &&
1494 {
1495 hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1);
1496 hostlist->hello_count = hellos_returned;
1497 hostlist->hostlist_uri = (const char *) &hostlist[1];
1498 GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1);
1499 hostlist->quality = quality;
1500 hostlist->time_creation.abs_value_us = created;
1501 hostlist->time_last_usage.abs_value_us = last_used;
1503 ;
1506 "Added hostlist entry with URI `%s' \n",
1507 hostlist->hostlist_uri);
1508 GNUNET_free (uri);
1509 uri = NULL;
1510 counter++;
1511 if (counter >= MAX_NUMBER_HOSTLISTS)
1512 break;
1513 }
1514 }
1515
1517 _ ("%u hostlist URIs loaded from file\n"),
1518 counter);
1520 gettext_noop ("# hostlist URIs read from file"),
1521 counter,
1522 GNUNET_YES);
1524 gettext_noop ("# advertised hostlist URIs"),
1526 GNUNET_NO);
1527
1528 GNUNET_free (uri);
1529 emsg = NULL;
1530 (void) GNUNET_BIO_read_close (rh, &emsg);
1531 if (emsg != NULL)
1532 GNUNET_free (emsg);
1534}
#define MAX_URL_LEN
How long can hostlist URLs be?
enum GNUNET_GenericReturnValue GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition: bio.c:1106
enum GNUNET_GenericReturnValue GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string.
Definition: bio.c:330
#define GNUNET_BIO_read_spec_end()
End of specifications marker.
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int32(const char *what, int32_t *i)
Create the specification to read an (u)int32_t.
Definition: bio.c:999
enum GNUNET_GenericReturnValue GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:162
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int64(const char *what, int64_t *i)
Create the specification to read an (u)int64_t.
Definition: bio.c:1043
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:114
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:483
Handle for buffered reading.
Definition: bio.c:69
Structure specifying a reading operation on an IO handle.
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.

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

Referenced by GNUNET_HOSTLIST_client_start().

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

◆ GNUNET_HOSTLIST_client_start()

int GNUNET_HOSTLIST_client_start ( const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_STATISTICS_Handle st,
GNUNET_CORE_ConnectEventHandler ch,
GNUNET_CORE_DisconnectEventHandler dh,
GNUNET_HOSTLIST_UriHandler msgh,
int  learn 
)

Start downloading hostlists from hostlist servers as necessary.

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

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

1654{
1655 char *filename;
1656 char *proxytype_str;
1657 int result;
1658
1659 GNUNET_assert (NULL != st);
1660 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
1661 {
1662 GNUNET_break (0);
1663 return GNUNET_SYSERR;
1664 }
1665 cfg = c;
1666 stats = st;
1667
1668 /* Read proxy configuration */
1670 if (GNUNET_OK ==
1671 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy))
1672 {
1673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy);
1674 /* proxy username */
1676 "HOSTLIST",
1677 "PROXY_USERNAME",
1679 {
1681 "Found proxy username name: `%s'\n",
1683 }
1684
1685 /* proxy password */
1687 "HOSTLIST",
1688 "PROXY_PASSWORD",
1690 {
1692 "Found proxy password name: `%s'\n",
1694 }
1695
1696 /* proxy type */
1698 "HOSTLIST",
1699 "PROXY_TYPE",
1700 &proxytype_str))
1701 {
1702 if (GNUNET_OK != GNUNET_STRINGS_utf8_toupper (proxytype_str,
1703 proxytype_str))
1705 "Unable to convert `%s' to UTF-8 uppercase\n",
1706 proxytype_str);
1707 proxy_type = CURLPROXY_HTTP;
1708 if (0 == strcmp (proxytype_str, "HTTP"))
1709 proxy_type = CURLPROXY_HTTP;
1710 else if (0 == strcmp (proxytype_str, "HTTP_1_0"))
1711 proxy_type = CURLPROXY_HTTP_1_0;
1712 else if (0 == strcmp (proxytype_str, "SOCKS4"))
1713 proxy_type = CURLPROXY_SOCKS4;
1714 else if (0 == strcmp (proxytype_str, "SOCKS5"))
1715 proxy_type = CURLPROXY_SOCKS5;
1716 else if (0 == strcmp (proxytype_str, "SOCKS4A"))
1717 proxy_type = CURLPROXY_SOCKS4A;
1718 else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME"))
1719 proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1720 else
1721 {
1722 GNUNET_log (
1724 _ (
1725 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n")
1726 ,
1727 proxytype_str);
1728 GNUNET_free (proxytype_str);
1730 proxy = NULL;
1732 proxy_username = NULL;
1734 proxy_password = NULL;
1735
1736 return GNUNET_SYSERR;
1737 }
1738 }
1739 GNUNET_free (proxytype_str);
1740 }
1741
1742 stat_learning = learn;
1743 *ch = &handler_connect;
1744 *dh = &handler_disconnect;
1745 linked_list_head = NULL;
1746 linked_list_tail = NULL;
1750
1752 {
1753 *msgh = &handler_advertisement;
1755 _ ("Learning is enabled on this peer\n"));
1758 "Hostlists will be saved to file again in %s\n",
1760 GNUNET_YES));
1763 NULL);
1764 }
1765 else
1766 {
1768 _ ("Learning is not enabled on this peer\n"));
1769 *msgh = NULL;
1771 "HOSTLIST",
1772 "HOSTLISTFILE",
1773 &filename))
1774 {
1776 {
1777 result = remove (filename);
1778 if (0 == result)
1779 GNUNET_log (
1781 _ (
1782 "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1783 filename);
1784 else
1786 "remove",
1787 filename);
1788 }
1789 }
1791 }
1793 "Loading stats value on hostlist download frequency\n");
1795 "hostlist",
1796 gettext_noop (
1797 "# milliseconds between hostlist downloads"),
1798 &primary_task,
1799 &process_stat,
1800 NULL);
1801 if (NULL == sget)
1802 {
1804 "Statistics request failed, scheduling hostlist download\n");
1806 }
1807 else
1808 {
1811 NULL);
1812 }
1813 return GNUNET_OK;
1814}
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static void handler_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a given peer disconnects.
static int process_stat(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
We've received the previous delay value from statistics.
static void handler_advertisement(const char *uri)
Method called whenever an advertisement message arrives.
static void stat_timeout_task(void *cls)
Continuation called by the statistics code once we go the stat.
static void load_hostlist_file()
Method to load persistent hostlist file during hostlist client startup.
static void * handler_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
static void primary_task(void *cls, int success)
Continuation called by the statistics code once we go the stat.
static int result
Global testing status.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
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.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:481

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

Referenced by run().

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

◆ GNUNET_HOSTLIST_client_stop()

void GNUNET_HOSTLIST_client_stop ( void  )

Stop downloading hostlists from hostlist servers as necessary.

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

1822{
1823 struct StoreHelloEntry *pos;
1824
1825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
1826 while (NULL != (pos = she_head))
1827 {
1830 GNUNET_free (pos);
1831 }
1832 if (NULL != sget)
1833 {
1835 sget = NULL;
1836 }
1837 stats = NULL;
1840 if (NULL != ti_saving_task)
1841 {
1843 ti_saving_task = NULL;
1844 }
1845 if (NULL != ti_download_dispatcher_task)
1846 {
1849 }
1850 if (NULL != ti_testing_intervall_task)
1851 {
1854 }
1855 if (NULL != ti_download)
1856 {
1858 ti_download = NULL;
1859 update_hostlist ();
1860 clean_up ();
1861 }
1862 if (NULL != ti_check_download)
1863 {
1865 ti_check_download = NULL;
1866 curl_global_cleanup ();
1867 }
1869 proxy = NULL;
1871 proxy_username = NULL;
1873 proxy_password = NULL;
1874 if (NULL != peerstore)
1875 {
1877 peerstore = NULL;
1878 }
1879 cfg = NULL;
1880}
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
void GNUNET_PEERSTORE_hello_add_cancel(struct GNUNET_PEERSTORE_StoreHelloContext *huc)
Cancel the request to add a hello.

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

Referenced by cleaning_task().

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

Variable Documentation

◆ cfg

◆ stats

◆ proxy

char* proxy
static

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

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

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

◆ proxy_username

char* proxy_username
static

Proxy username we are using (can be NULL).

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

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

◆ proxy_password

char* proxy_password
static

Proxy password we are using (can be NULL).

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

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

◆ proxy_type

curl_proxytype proxy_type
static

Proxy type we are using (can be NULL).

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

Referenced by download_hostlist(), and GNUNET_HOSTLIST_client_start().

◆ download_pos

size_t download_pos
static

Number of bytes valid in 'download_buffer'.

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

Referenced by callback_download(), and download_hostlist().

◆ current_url

char* current_url
static

Current URL that we are using.

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

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

◆ curl

CURL* curl
static

Current CURL handle.

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

Referenced by clean_up(), and download_hostlist().

◆ multi

CURLM* multi
static

Current multi-CURL handle.

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

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

◆ stat_bytes_downloaded

uint32_t stat_bytes_downloaded
static

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

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

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

◆ hostlist_delay

struct GNUNET_TIME_Relative hostlist_delay
static

Amount of time we wait between hostlist downloads.

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

Referenced by process_stat(), and task_check().

◆ ti_check_download

struct GNUNET_SCHEDULER_Task* ti_check_download
static

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

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

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

◆ ti_download

struct GNUNET_SCHEDULER_Task* ti_download
static

ID of the task downloading the hostlist.

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

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

◆ ti_saving_task

struct GNUNET_SCHEDULER_Task* ti_saving_task
static

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

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

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

◆ ti_download_dispatcher_task

struct GNUNET_SCHEDULER_Task* ti_download_dispatcher_task
static

ID of the task called to initiate a download.

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

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

◆ ti_testing_intervall_task

struct GNUNET_SCHEDULER_Task* ti_testing_intervall_task
static

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

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

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

◆ end_time

struct GNUNET_TIME_Absolute end_time
static

At what time MUST the current hostlist request be done?

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

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

◆ she_head

struct StoreHelloEntry* she_head
static

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

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

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

◆ she_tail

struct StoreHelloEntry* she_tail
static

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

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

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

◆ linked_list_head

struct Hostlist* linked_list_head
static

◆ linked_list_tail

struct Hostlist* linked_list_tail
static

Tail of the linked list used to store hostlists.

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

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

◆ current_hostlist

struct Hostlist* current_hostlist
static

Current hostlist used for downloading.

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

Referenced by download_get_url(), and update_hostlist().

◆ linked_list_size

unsigned int linked_list_size
static

Size of the linked list used to store hostlists.

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

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

◆ hostlist_to_test

struct Hostlist* hostlist_to_test
static

Head of the linked list used to store hostlists.

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

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

◆ sget

struct GNUNET_STATISTICS_GetHandle* sget
static

Handle for our statistics GET operation.

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

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

◆ stat_bogus_url

int stat_bogus_url
static

Set to GNUNET_YES if the current URL had some problems.

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

Referenced by callback_download(), and download_hostlist().

◆ stat_testing_hostlist

int stat_testing_hostlist
static

Value controlling if a hostlist is tested at the moment.

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

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

◆ stat_testing_allowed

int stat_testing_allowed
static

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

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

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

◆ stat_download_in_progress

int stat_download_in_progress
static

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

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

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

◆ stat_use_bootstrap

unsigned int stat_use_bootstrap
static

Value saying if a preconfigured bootstrap server is used.

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

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

◆ stat_learning

int stat_learning
static

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

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

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

◆ stat_download_successful

unsigned int stat_download_successful
static

Value saying if hostlist download was successful.

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

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

◆ stat_hellos_obtained

unsigned int stat_hellos_obtained
static

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

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

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

◆ stat_connection_count

unsigned int stat_connection_count
static

Number of active connections (according to core service).

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

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

◆ peerstore

struct GNUNET_PEERSTORE_Handle* peerstore
static

Handle to the PEERSTORE service.

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

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