GNUnet 0.28.1-dev.5-1-gae1c02d74
 
Loading...
Searching...
No Matches
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.
 
void GNUNET_HOSTLIST_server_stop (void)
 Stop server offering our hostlist.
 

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 870 of file gnunet-daemon-hostlist_server.c.

875{
876 unsigned long long port;
877 char *hostname;
878 char *ipv4;
879 char *ipv6;
880 size_t size;
881 struct in_addr i4;
882 struct in6_addr i6;
883 struct sockaddr_in v4;
884 struct sockaddr_in6 v6;
885 const struct sockaddr *sa4;
886 const struct sockaddr *sa6;
887
888 /* Keys are copied: #process_notify() puts the identity of a borrowed
889 PEERSTORE record, which does not outlive the callback. */
891 advertising = advertise;
892 if (! advertising)
893 {
895 "Advertising not enabled on this hostlist server\n");
896 }
897 else
898 {
900 "Advertising enabled on this hostlist server\n");
901 }
902 cfg = c;
903 stats = st;
905 if (NULL == peerstore)
906 {
908 _ ("Could not access PEERSTORE service. Exiting.\n"));
909 return GNUNET_SYSERR;
910 }
912 "HOSTLIST",
913 "HTTPPORT",
914 &port))
915 return GNUNET_SYSERR;
916 if ((0 == port) || (port > UINT16_MAX))
917 {
919 _ ("Invalid port number %llu. Exiting.\n"),
920 port);
921 return GNUNET_SYSERR;
922 }
923
924 if (GNUNET_SYSERR ==
926 "HOSTLIST",
927 "EXTERNAL_DNS_NAME",
928 &hostname))
929 hostname = GNUNET_RESOLVER_local_fqdn_get ();
931 _ ("Hostlist service starts on %s:%llu\n"),
932 hostname,
933 port);
934 if (NULL != hostname)
935 {
936 size = strlen (hostname);
937 if (size + 15 > MAX_URL_LEN)
938 {
939 GNUNET_break (0);
940 }
941 else
942 {
944 "http://%s:%u/",
945 hostname,
946 (unsigned int) port);
948 _ ("Address to obtain hostlist: `%s'\n"),
950 }
951 GNUNET_free (hostname);
952 }
953
954 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
955 {
957 "HOSTLIST",
958 "BINDTOIP",
959 &ipv4))
960 {
961 GNUNET_log (
963 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
964 }
965 }
966 else
967 ipv4 = NULL;
968 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
969 {
971 "HOSTLIST",
972 "BINDTOIP",
973 &ipv6))
974 {
975 GNUNET_log (
977 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
978 }
979 }
980 else
981 ipv6 = NULL;
982 sa4 = NULL;
983 if (NULL != ipv4)
984 {
985 if (1 == inet_pton (AF_INET, ipv4, &i4))
986 {
987 memset (&v4, 0, sizeof(v4));
988 v4.sin_family = AF_INET;
989 v4.sin_addr = i4;
990 v4.sin_port = htons (port);
991#if HAVE_SOCKADDR_IN_SIN_LEN
992 v4.sin_len = sizeof(v4);
993#endif
994 sa4 = (const struct sockaddr *) &v4;
995 }
996 else
998 _ (
999 "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
1000 ipv4);
1001 GNUNET_free (ipv4);
1002 }
1003 sa6 = NULL;
1004 if (NULL != ipv6)
1005 {
1006 if (1 == inet_pton (AF_INET6, ipv6, &i6))
1007 {
1008 memset (&v6, 0, sizeof(v6));
1009 v6.sin6_family = AF_INET6;
1010 v6.sin6_addr = i6;
1011 v6.sin6_port = htons (port);
1012#if HAVE_SOCKADDR_IN_SIN_LEN
1013 v6.sin6_len = sizeof(v6);
1014#endif
1015 sa6 = (const struct sockaddr *) &v6;
1016 }
1017 else
1019 _ (
1020 "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
1021 ipv6);
1022 GNUNET_free (ipv6);
1023 }
1024
1025 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
1026 (uint16_t) port,
1028 NULL,
1030 NULL,
1031 MHD_OPTION_CONNECTION_LIMIT,
1032 (unsigned int) 128,
1033 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
1034 (unsigned int) 32,
1035 MHD_OPTION_CONNECTION_TIMEOUT,
1036 (unsigned int) 16,
1037 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
1038 (size_t) (16 * 1024),
1039 MHD_OPTION_SOCK_ADDR,
1040 sa6,
1041 MHD_OPTION_END);
1042 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
1043 (uint16_t) port,
1045 NULL,
1047 NULL,
1048 MHD_OPTION_CONNECTION_LIMIT,
1049 (unsigned int) 128,
1050 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
1051 (unsigned int) 32,
1052 MHD_OPTION_CONNECTION_TIMEOUT,
1053 (unsigned int) 16,
1054 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
1055 (size_t) (16 * 1024),
1056 MHD_OPTION_SOCK_ADDR,
1057 sa4,
1058 MHD_OPTION_END);
1059
1060 if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
1061 {
1063 _ ("Could not start hostlist HTTP server on port %u\n"),
1064 (unsigned short) port);
1065 return GNUNET_SYSERR;
1066 }
1067
1068 core = co;
1070 if (NULL != daemon_handle_v4)
1072 if (NULL != daemon_handle_v6)
1077 NULL);
1078 return GNUNET_OK;
1079}
static uint16_t port
Port number.
Definition gnunet-bcd.c:146
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 void * connect_handler(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 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 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_NO
@ 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:1283
#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:179

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_NO, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_RESOLVER_local_fqdn_get(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TIME_UNIT_MINUTES, 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 1086 of file gnunet-daemon-hostlist_server.c.

1087{
1088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
1089 if (NULL != rebuild_task)
1090 {
1092 rebuild_task = NULL;
1093 }
1094 if (NULL != hostlist_task_v6)
1095 {
1097 hostlist_task_v6 = NULL;
1098 }
1099 if (NULL != hostlist_task_v4)
1100 {
1102 hostlist_task_v4 = NULL;
1103 }
1104 if (NULL != daemon_handle_v4)
1105 {
1106 MHD_stop_daemon (daemon_handle_v4);
1107 daemon_handle_v4 = NULL;
1108 }
1109 if (NULL != daemon_handle_v6)
1110 {
1111 MHD_stop_daemon (daemon_handle_v6);
1112 daemon_handle_v6 = NULL;
1113 }
1114 if (NULL != response)
1115 {
1116 MHD_destroy_response (response);
1117 response = NULL;
1118 }
1119 if (NULL != response_json)
1120 {
1121 MHD_destroy_response (response_json);
1122 response_json = NULL;
1123 }
1124 if (NULL != peerstore_notify)
1125 {
1127 peerstore_notify = NULL;
1128 }
1129 else if (NULL != peerstore_notify_task)
1130 {
1132 }
1133 if (NULL != builder)
1134 {
1137 builder = NULL;
1138 }
1139 if (NULL != hellos)
1140 {
1142 &free_hello,
1143 NULL);
1145 hellos = NULL;
1146 }
1147 if (NULL != peerstore)
1148 {
1150 peerstore = NULL;
1151 }
1152 cfg = NULL;
1153 stats = NULL;
1154 core = NULL;
1155}
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.
static enum GNUNET_GenericReturnValue free_hello(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Free one HELLO of hellos.
static struct GNUNET_SCHEDULER_Task * rebuild_task
Task that rebuilds our response from hellos, or NULL if no rebuild is pending.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
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:986
char * data
Place where we accumulate all of the HELLO messages.

References builder, cfg, core, daemon_handle_v4, daemon_handle_v6, HostSet::data, free_hello(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_PEERSTORE_disconnect(), GNUNET_PEERSTORE_monitor_stop(), GNUNET_SCHEDULER_cancel(), hellos, hostlist_task_v4, hostlist_task_v6, peerstore, peerstore_notify, peerstore_notify_task, rebuild_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: