GNUnet  0.11.x
Typedefs | Functions
gnunet-daemon-hostlist_client.h File Reference

hostlist support. More...

#include "gnunet_core_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-daemon-hostlist_client.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* GNUNET_HOSTLIST_UriHandler) (const char *uri)
 Function that handles an advertised URI. More...
 

Functions

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 (void)
 Stop downloading hostlists from hostlist servers as necessary. More...
 

Detailed Description

hostlist support.

Downloads HELLOs via HTTP.

Author
Christian Grothoff

Definition in file gnunet-daemon-hostlist_client.h.

Typedef Documentation

◆ GNUNET_HOSTLIST_UriHandler

typedef void(* GNUNET_HOSTLIST_UriHandler) (const char *uri)

Function that handles an advertised URI.

Parameters
uri0-termianted URI of a hostlist

Definition at line 39 of file gnunet-daemon-hostlist_client.h.

Function Documentation

◆ 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 1571 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().

1577 {
1578  char *filename;
1579  char *proxytype_str;
1580  int result;
1581 
1582  GNUNET_assert (NULL != st);
1583  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
1584  {
1585  GNUNET_break (0);
1586  return GNUNET_SYSERR;
1587  }
1588  cfg = c;
1589  stats = st;
1590 
1591  /* Read proxy configuration */
1593  if (GNUNET_OK ==
1594  GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy))
1595  {
1596  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy);
1597  /* proxy username */
1599  "HOSTLIST",
1600  "PROXY_USERNAME",
1601  &proxy_username))
1602  {
1604  "Found proxy username name: `%s'\n",
1605  proxy_username);
1606  }
1607 
1608  /* proxy password */
1610  "HOSTLIST",
1611  "PROXY_PASSWORD",
1612  &proxy_password))
1613  {
1615  "Found proxy password name: `%s'\n",
1616  proxy_password);
1617  }
1618 
1619  /* proxy type */
1621  "HOSTLIST",
1622  "PROXY_TYPE",
1623  &proxytype_str))
1624  {
1625  GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str);
1626  proxy_type = CURLPROXY_HTTP;
1627  if (0 == strcmp (proxytype_str, "HTTP"))
1628  proxy_type = CURLPROXY_HTTP;
1629  else if (0 == strcmp (proxytype_str, "HTTP_1_0"))
1630  proxy_type = CURLPROXY_HTTP_1_0;
1631  else if (0 == strcmp (proxytype_str, "SOCKS4"))
1632  proxy_type = CURLPROXY_SOCKS4;
1633  else if (0 == strcmp (proxytype_str, "SOCKS5"))
1634  proxy_type = CURLPROXY_SOCKS5;
1635  else if (0 == strcmp (proxytype_str, "SOCKS4A"))
1636  proxy_type = CURLPROXY_SOCKS4A;
1637  else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME"))
1638  proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1639  else
1640  {
1641  GNUNET_log (
1643  _ (
1644  "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
1645  proxytype_str);
1646  GNUNET_free (proxytype_str);
1647  GNUNET_free (proxy);
1648  proxy = NULL;
1650  proxy_username = NULL;
1652  proxy_password = NULL;
1653 
1654  return GNUNET_SYSERR;
1655  }
1656  }
1657  GNUNET_free_non_null (proxytype_str);
1658  }
1659 
1660  stat_learning = learn;
1661  *ch = &handler_connect;
1662  *dh = &handler_disconnect;
1663  linked_list_head = NULL;
1664  linked_list_tail = NULL;
1668 
1669  if (GNUNET_YES == stat_learning)
1670  {
1671  *msgh = &handler_advertisement;
1673  _ ("Learning is enabled on this peer\n"));
1674  load_hostlist_file ();
1676  "Hostlists will be saved to file again in %s\n",
1678  GNUNET_YES));
1681  NULL);
1682  }
1683  else
1684  {
1686  _ ("Learning is not enabled on this peer\n"));
1687  *msgh = NULL;
1689  "HOSTLIST",
1690  "HOSTLISTFILE",
1691  &filename))
1692  {
1693  if (GNUNET_YES == GNUNET_DISK_file_test (filename))
1694  {
1695  result = remove (filename);
1696  if (0 == result)
1697  GNUNET_log (
1699  _ (
1700  "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1701  filename);
1702  else
1704  "remove",
1705  filename);
1706  }
1707  }
1708  GNUNET_free (filename);
1709  }
1711  "Loading stats value on hostlist download frequency\n");
1713  "hostlist",
1714  gettext_noop (
1715  "# milliseconds between hostlist downloads"),
1716  &primary_task,
1717  &process_stat,
1718  NULL);
1719  if (NULL == sget)
1720  {
1722  "Statistics request failed, scheduling hostlist download\n");
1724  }
1725  else
1726  {
1729  NULL);
1730  }
1731  return GNUNET_OK;
1732 }
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:544
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:130
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'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:78
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:75
#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:181
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:1253
void GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:578
#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...
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:1280
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:687
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:76
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:77
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 1739 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().

1740 {
1741  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
1742  if (NULL != sget)
1743  {
1745  sget = NULL;
1746  }
1747  stats = NULL;
1748  if (GNUNET_YES == stat_learning)
1750  if (NULL != ti_saving_task)
1751  {
1753  ti_saving_task = NULL;
1754  }
1755  if (NULL != ti_download_dispatcher_task)
1756  {
1759  }
1760  if (NULL != ti_testing_intervall_task)
1761  {
1764  }
1765  if (NULL != ti_download)
1766  {
1768  ti_download = NULL;
1769  update_hostlist ();
1770  clean_up ();
1771  }
1772  if (NULL != ti_check_download)
1773  {
1775  ti_check_download = NULL;
1776  curl_global_cleanup ();
1777  }
1779  proxy = NULL;
1781  proxy_username = NULL;
1783  proxy_password = NULL;
1784  if (NULL != pi)
1785  {
1787  pi = NULL;
1788  }
1789  cfg = NULL;
1790 }
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:156
#define GNUNET_YES
Definition: gnunet_common.h:77
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:966
Here is the call graph for this function:
Here is the caller graph for this function: