GNUnet 0.26.2
 
Loading...
Searching...
No Matches
gnunet-daemon-hostlist_client.h File Reference

hostlist support. More...

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.
 

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

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

1656{
1657 char *filename;
1658 char *proxytype_str;
1659 int result;
1660
1661 GNUNET_assert (NULL != st);
1662 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
1663 {
1664 GNUNET_break (0);
1665 return GNUNET_SYSERR;
1666 }
1667 cfg = c;
1668 stats = st;
1669
1670 /* Read proxy configuration */
1672 if (GNUNET_OK ==
1674 "HOSTLIST",
1675 "PROXY",
1676 &proxy))
1677 {
1679 "Found proxy host: `%s'\n",
1680 proxy);
1681 /* proxy username */
1682 if (GNUNET_OK ==
1684 "HOSTLIST",
1685 "PROXY_USERNAME",
1687 {
1689 "Found proxy username name: `%s'\n",
1691 }
1692
1693 /* proxy password */
1694 if (GNUNET_OK ==
1696 "HOSTLIST",
1697 "PROXY_PASSWORD",
1699 {
1701 "Found proxy password name: `%s'\n",
1703 }
1704
1705 /* proxy type */
1706 if (GNUNET_OK ==
1708 "HOSTLIST",
1709 "PROXY_TYPE",
1710 &proxytype_str))
1711 {
1712 char *pstr;
1713
1714 pstr = GNUNET_STRINGS_utf8_toupper (proxytype_str);
1716 "Unable to convert `%s' to UTF-8 uppercase\n",
1717 proxytype_str);
1718 GNUNET_free (proxytype_str);
1719 proxy_type = CURLPROXY_HTTP;
1720 if (0 == strcmp (pstr, "HTTP"))
1721 proxy_type = CURLPROXY_HTTP;
1722 else if (0 == strcmp (pstr, "HTTP_1_0"))
1723 proxy_type = CURLPROXY_HTTP_1_0;
1724 else if (0 == strcmp (pstr, "SOCKS4"))
1725 proxy_type = CURLPROXY_SOCKS4;
1726 else if (0 == strcmp (pstr, "SOCKS5"))
1727 proxy_type = CURLPROXY_SOCKS5;
1728 else if (0 == strcmp (pstr, "SOCKS4A"))
1729 proxy_type = CURLPROXY_SOCKS4A;
1730 else if (0 == strcmp (pstr, "SOCKS5_HOSTNAME"))
1731 proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1732 else
1733 {
1734 GNUNET_log (
1736 _ (
1737 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n")
1738 ,
1739 pstr);
1740 GNUNET_free (pstr);
1742 proxy = NULL;
1744 proxy_username = NULL;
1746 proxy_password = NULL;
1747
1748 return GNUNET_SYSERR;
1749 }
1750 GNUNET_free (pstr);
1751 }
1752 }
1753
1754 stat_learning = learn;
1755 *ch = &handler_connect;
1756 *dh = &handler_disconnect;
1757 linked_list_head = NULL;
1758 linked_list_tail = NULL;
1762
1764 {
1765 *msgh = &handler_advertisement;
1767 _ ("Learning is enabled on this peer\n"));
1770 "Hostlists will be saved to file again in %s\n",
1772 GNUNET_YES));
1775 NULL);
1776 }
1777 else
1778 {
1780 _ ("Learning is not enabled on this peer\n"));
1781 *msgh = NULL;
1783 "HOSTLIST",
1784 "HOSTLISTFILE",
1785 &filename))
1786 {
1788 {
1789 result = remove (filename);
1790 if (0 == result)
1791 GNUNET_log (
1793 _ (
1794 "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
1795 filename);
1796 else
1798 "remove",
1799 filename);
1800 }
1801 }
1803 }
1805 "Loading stats value on hostlist download frequency\n");
1807 "hostlist",
1808 gettext_noop (
1809 "# milliseconds between hostlist downloads"),
1810 &primary_task,
1811 &process_stat,
1812 NULL);
1813 if (NULL == sget)
1814 {
1816 "Statistics request failed, scheduling hostlist download\n");
1818 }
1819 else
1820 {
1823 NULL);
1824 }
1825 return GNUNET_OK;
1826}
#define gettext_noop(String)
Definition gettext.h:74
static struct GNUNET_CADET_Channel * ch
Channel handle.
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
#define SAVING_INTERVAL
Time interval hostlists are saved to disk.
static char * proxy
Proxy hostname or ip we are using (can be NULL).
static void handler_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a given peer disconnects.
static int process_stat(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
We've received the previous delay value from statistics.
static void task_check(void *cls)
Task that checks if we should try to download a hostlist.
static void task_hostlist_saving(void *cls)
Task that writes hostlist entries to a file on a regular base.
static int stat_learning
Set if we are allowed to learn new hostlists and use them.
static struct Hostlist * linked_list_head
Head of the linked list used to store hostlists.
static void handler_advertisement(const char *uri)
Method called whenever an advertisement message arrives.
static unsigned int stat_use_bootstrap
Value saying if a preconfigured bootstrap server is used.
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
static int stat_testing_allowed
Value controlling if a hostlist testing is allowed at the moment.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to the PEERSTORE service.
static int stat_testing_hostlist
Value controlling if a hostlist is tested at the moment.
static char * proxy_password
Proxy password we are using (can be NULL).
static struct GNUNET_STATISTICS_GetHandle * sget
Handle for our statistics GET operation.
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, enum GNUNET_CORE_PeerClass class)
Method called whenever a given peer connects.
static struct Hostlist * linked_list_tail
Tail of the linked list used to store hostlists.
static struct GNUNET_SCHEDULER_Task * ti_check_download
ID of the task, checking if hostlist download should take plate.
static struct GNUNET_SCHEDULER_Task * ti_saving_task
ID of the task saving the hostlsit in a regular interval.
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).
static void primary_task(void *cls, int success)
Continuation called by the statistics code once we go the stat.
static char * filename
static int result
Global testing status.
static struct GNUNET_SCHEDULER_Task * stat_timeout_task
Task to timeout stat GET.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition disk.c:533
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1304
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1277
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.
char * GNUNET_STRINGS_utf8_toupper(const char *input)
Convert the utf-8 input string to upper case.
Definition strings.c:500
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:604
#define GNUNET_TIME_UNIT_MINUTES
One minute.
#define _(String)
GNU gettext support macro.
Definition platform.h:179

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

1834{
1835 struct StoreHelloEntry *pos;
1836
1837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
1838 while (NULL != (pos = she_head))
1839 {
1842 GNUNET_free (pos);
1843 }
1844 if (NULL != sget)
1845 {
1847 sget = NULL;
1848 }
1849 stats = NULL;
1852 if (NULL != ti_saving_task)
1853 {
1855 ti_saving_task = NULL;
1856 }
1857 if (NULL != ti_download_dispatcher_task)
1858 {
1861 }
1862 if (NULL != ti_testing_intervall_task)
1863 {
1866 }
1867 if (NULL != ti_download)
1868 {
1870 ti_download = NULL;
1871 update_hostlist ();
1872 clean_up ();
1873 }
1874 if (NULL != ti_check_download)
1875 {
1877 ti_check_download = NULL;
1878 curl_global_cleanup ();
1879 }
1881 proxy = NULL;
1883 proxy_username = NULL;
1885 proxy_password = NULL;
1886 if (NULL != peerstore)
1887 {
1889 peerstore = NULL;
1890 }
1891 cfg = NULL;
1892}
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.
static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task
ID of the task controlling the locking between two hostlist tests.
static void update_hostlist()
Method updating hostlist statistics.
static struct GNUNET_SCHEDULER_Task * ti_download
ID of the task downloading the hostlist.
static void save_hostlist_file(int shutdown)
Method to save hostlist to a file during hostlist client shutdown.
static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task
ID of the task called to initiate a download.
static void clean_up()
Clean up the state from the task that downloaded the hostlist and schedule the next task.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
Context for a add hello uri request.
struct GNUNET_PEERSTORE_StoreHelloContext * sc
Store hello ctx.

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: