GNUnet 0.22.0
gnunet-daemon-hostlist_server.h File Reference

hostlist support. More...

Include dependency graph for gnunet-daemon-hostlist_server.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, struct GNUNET_CORE_Handle *core, GNUNET_CORE_ConnectEventHandler *server_ch, int advertise)
 Start server offering our hostlist. More...
 
void GNUNET_HOSTLIST_server_stop (void)
 Stop server offering our hostlist. More...
 

Detailed Description

hostlist support.

Downloads HELLOs via HTTP.

Author
Christian Grothoff

Definition in file gnunet-daemon-hostlist_server.h.

Function Documentation

◆ GNUNET_HOSTLIST_server_start()

int GNUNET_HOSTLIST_server_start ( const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_STATISTICS_Handle st,
struct GNUNET_CORE_Handle co,
GNUNET_CORE_ConnectEventHandler server_ch,
int  advertise 
)

Start server offering our hostlist.

Parameters
cconfiguration to use
ststatistics handle to use
cocore handle to use
[out]server_chset to handler for CORE connect events
advertiseGNUNET_YES if we should advertise our hostlist
Returns
GNUNET_OK on success

Definition at line 718 of file gnunet-daemon-hostlist_server.c.

723{
724 unsigned long long port;
725 char *hostname;
726 char *ipv4;
727 char *ipv6;
728 size_t size;
729 struct in_addr i4;
730 struct in6_addr i6;
731 struct sockaddr_in v4;
732 struct sockaddr_in6 v6;
733 const struct sockaddr *sa4;
734 const struct sockaddr *sa6;
735
737 advertising = advertise;
738 if (! advertising)
739 {
741 "Advertising not enabled on this hostlist server\n");
742 }
743 else
744 {
746 "Advertising enabled on this hostlist server\n");
747 }
748 cfg = c;
749 stats = st;
751 if (NULL == peerstore)
752 {
754 _ ("Could not access PEERSTORE service. Exiting.\n"));
755 return GNUNET_SYSERR;
756 }
758 "HOSTLIST",
759 "HTTPPORT",
760 &port))
761 return GNUNET_SYSERR;
762 if ((0 == port) || (port > UINT16_MAX))
763 {
765 _ ("Invalid port number %llu. Exiting.\n"),
766 port);
767 return GNUNET_SYSERR;
768 }
769
770 if (GNUNET_SYSERR ==
772 "HOSTLIST",
773 "EXTERNAL_DNS_NAME",
774 &hostname))
775 hostname = GNUNET_RESOLVER_local_fqdn_get ();
777 _ ("Hostlist service starts on %s:%llu\n"),
778 hostname,
779 port);
780 if (NULL != hostname)
781 {
782 size = strlen (hostname);
783 if (size + 15 > MAX_URL_LEN)
784 {
785 GNUNET_break (0);
786 }
787 else
788 {
790 "http://%s:%u/",
791 hostname,
792 (unsigned int) port);
794 _ ("Address to obtain hostlist: `%s'\n"),
796 }
797 GNUNET_free (hostname);
798 }
799
800 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
801 {
803 "HOSTLIST",
804 "BINDTOIP",
805 &ipv4))
806 {
807 GNUNET_log (
809 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
810 }
811 }
812 else
813 ipv4 = NULL;
814 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
815 {
817 "HOSTLIST",
818 "BINDTOIP",
819 &ipv6))
820 {
821 GNUNET_log (
823 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
824 }
825 }
826 else
827 ipv6 = NULL;
828 sa4 = NULL;
829 if (NULL != ipv4)
830 {
831 if (1 == inet_pton (AF_INET, ipv4, &i4))
832 {
833 memset (&v4, 0, sizeof(v4));
834 v4.sin_family = AF_INET;
835 v4.sin_addr = i4;
836 v4.sin_port = htons (port);
837#if HAVE_SOCKADDR_IN_SIN_LEN
838 v4.sin_len = sizeof(v4);
839#endif
840 sa4 = (const struct sockaddr *) &v4;
841 }
842 else
844 _ (
845 "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
846 ipv4);
848 }
849 sa6 = NULL;
850 if (NULL != ipv6)
851 {
852 if (1 == inet_pton (AF_INET6, ipv6, &i6))
853 {
854 memset (&v6, 0, sizeof(v6));
855 v6.sin6_family = AF_INET6;
856 v6.sin6_addr = i6;
857 v6.sin6_port = htons (port);
858#if HAVE_SOCKADDR_IN_SIN_LEN
859 v6.sin6_len = sizeof(v6);
860#endif
861 sa6 = (const struct sockaddr *) &v6;
862 }
863 else
865 _ (
866 "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
867 ipv6);
869 }
870
871 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
872 (uint16_t) port,
874 NULL,
876 NULL,
877 MHD_OPTION_CONNECTION_LIMIT,
878 (unsigned int) 128,
879 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
880 (unsigned int) 32,
881 MHD_OPTION_CONNECTION_TIMEOUT,
882 (unsigned int) 16,
883 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
884 (size_t) (16 * 1024),
885 MHD_OPTION_SOCK_ADDR,
886 sa6,
887 MHD_OPTION_END);
888 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
889 (uint16_t) port,
891 NULL,
893 NULL,
894 MHD_OPTION_CONNECTION_LIMIT,
895 (unsigned int) 128,
896 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
897 (unsigned int) 32,
898 MHD_OPTION_CONNECTION_TIMEOUT,
899 (unsigned int) 16,
900 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
901 (size_t) (16 * 1024),
902 MHD_OPTION_SOCK_ADDR,
903 sa4,
904 MHD_OPTION_END);
905
906 if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
907 {
909 _ ("Could not start hostlist HTTP server on port %u\n"),
910 (unsigned short) port);
911 return GNUNET_SYSERR;
912 }
913
914 core = co;
916 if (NULL != daemon_handle_v4)
918 if (NULL != daemon_handle_v6)
923 NULL);
924 return GNUNET_OK;
925}
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static GNUNET_CORE_ConnectEventHandler server_ch
Handle to hostlist server's connect handler.
#define MAX_URL_LEN
How long can hostlist URLs be?
static struct MHD_Daemon * daemon_handle_v6
Handle to the HTTP server as provided by libmicrohttpd for IPv6.
static struct MHD_Daemon * daemon_handle_v4
Handle to the HTTP server as provided by libmicrohttpd for IPv4.
static struct GNUNET_SCHEDULER_Task * hostlist_task_v4
Our primary task for IPv4.
static struct GNUNET_CORE_Handle * core
Handle to the core service (NULL until we've connected to it).
static int advertising
Set if we are allowed to advertise our hostlist to others.
static void * connect_handler(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
static struct GNUNET_STATISTICS_Handle * stats
For keeping statistics.
struct GNUNET_CONTAINER_MultiPeerMap * hellos
Map with hellos we build the hostlist with.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_SCHEDULER_Task * hostlist_task_v6
Our primary task for IPv6.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to the PEERSTORE service.
static struct GNUNET_SCHEDULER_Task * prepare_daemon(struct MHD_Daemon *daemon_handle)
Function that queries MHD's select sets and starts the task waiting for them.
static void start_notify(void *cls)
struct GNUNET_SCHEDULER_Task * peerstore_notify_task
The task to delayed start the notification process initially.
static MHD_RESULT access_handler_callback(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
Main request handler.
static char * hostlist_uri
Buffer for the hostlist address.
static MHD_RESULT accept_policy_callback(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Hostlist access policy (very permissive, allows everything).
static int ipv4
Option -4: IPv4 requested.
Definition: gnunet-vpn.c:60
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:65
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
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_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
char * GNUNET_RESOLVER_local_fqdn_get(void)
Get local fully qualified domain name.
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
#define GNUNET_TIME_UNIT_MINUTES
One minute.
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

References _, accept_policy_callback(), access_handler_callback(), advertising, cfg, connect_handler(), core, daemon_handle_v4, daemon_handle_v6, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_RESOLVER_local_fqdn_get(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, hellos, hostlist_task_v4, hostlist_task_v6, hostlist_uri, ipv4, ipv6, MAX_URL_LEN, peerstore, peerstore_notify_task, port, prepare_daemon(), server_ch, size, st, start_notify(), and stats.

Referenced by run().

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

◆ GNUNET_HOSTLIST_server_stop()

void GNUNET_HOSTLIST_server_stop ( void  )

Stop server offering our hostlist.

Definition at line 932 of file gnunet-daemon-hostlist_server.c.

933{
934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
935 if (NULL != hostlist_task_v6)
936 {
938 hostlist_task_v6 = NULL;
939 }
940 if (NULL != hostlist_task_v4)
941 {
943 hostlist_task_v4 = NULL;
944 }
945 if (NULL != daemon_handle_v4)
946 {
947 MHD_stop_daemon (daemon_handle_v4);
948 daemon_handle_v4 = NULL;
949 }
950 if (NULL != daemon_handle_v6)
951 {
952 MHD_stop_daemon (daemon_handle_v6);
953 daemon_handle_v6 = NULL;
954 }
955 if (NULL != response)
956 {
957 MHD_destroy_response (response);
958 response = NULL;
959 }
960 if (NULL != response_json)
961 {
962 MHD_destroy_response (response_json);
963 response_json = NULL;
964 }
965 if (NULL != peerstore_notify)
966 {
968 peerstore_notify = NULL;
969 }
970 else if (NULL != peerstore_notify_task)
971 {
973 }
974 if (NULL != builder)
975 {
978 builder = NULL;
979 }
980 if (NULL != peerstore)
981 {
983 peerstore = NULL;
984 }
985 cfg = NULL;
986 stats = NULL;
987 core = NULL;
988}
static struct MHD_Response * response
Our canonical response.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
static struct GNUNET_PEERSTORE_Monitor * peerstore_notify
Our peerstore notification context.
static struct MHD_Response * response_json
Our json response.
void GNUNET_PEERSTORE_monitor_stop(struct GNUNET_PEERSTORE_Monitor *zm)
Stop monitoring.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
char * data
Place where we accumulate all of the HELLO messages.

References builder, cfg, core, daemon_handle_v4, daemon_handle_v6, HostSet::data, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_PEERSTORE_disconnect(), GNUNET_PEERSTORE_monitor_stop(), GNUNET_SCHEDULER_cancel(), hostlist_task_v4, hostlist_task_v6, peerstore, peerstore_notify, peerstore_notify_task, response, response_json, and stats.

Referenced by cleaning_task().

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