Start server offering our hostlist.
739{
740 unsigned long long port;
741 char *hostname;
745 struct in_addr i4;
746 struct in6_addr i6;
747 struct sockaddr_in v4;
748 struct sockaddr_in6 v6;
749 const struct sockaddr *sa4;
750 const struct sockaddr *sa6;
751
755 {
757 "Advertising not enabled on this hostlist server\n");
758 }
759 else
760 {
762 "Advertising enabled on this hostlist server\n");
763 }
768 {
770 _ (
"Could not access PEERSTORE service. Exiting.\n"));
772 }
774 "HOSTLIST",
775 "HTTPPORT",
778 if ((0 ==
port) || (
port > UINT16_MAX))
779 {
781 _ (
"Invalid port number %llu. Exiting.\n"),
784 }
785
788 "HOSTLIST",
789 "EXTERNAL_DNS_NAME",
790 &hostname))
793 _ (
"Hostlist service starts on %s:%llu\n"),
794 hostname,
796 if (NULL != hostname)
797 {
798 size = strlen (hostname);
800 {
802 }
803 else
804 {
806 "http://%s:%u/",
807 hostname,
808 (
unsigned int)
port);
810 _ (
"Address to obtain hostlist: `%s'\n"),
812 }
814 }
815
817 {
819 "HOSTLIST",
820 "BINDTOIP",
822 {
825 _ (
"BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
826 }
827 }
828 else
831 {
833 "HOSTLIST",
834 "BINDTOIP",
836 {
839 _ (
"BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
840 }
841 }
842 else
844 sa4 = NULL;
846 {
847 if (1 == inet_pton (AF_INET,
ipv4, &i4))
848 {
849 memset (&v4, 0, sizeof(v4));
850 v4.sin_family = AF_INET;
851 v4.sin_addr = i4;
852 v4.sin_port = htons (
port);
853#if HAVE_SOCKADDR_IN_SIN_LEN
854 v4.sin_len = sizeof(v4);
855#endif
856 sa4 = (const struct sockaddr *) &v4;
857 }
858 else
861 "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
864 }
865 sa6 = NULL;
867 {
868 if (1 == inet_pton (AF_INET6,
ipv6, &i6))
869 {
870 memset (&v6, 0, sizeof(v6));
871 v6.sin6_family = AF_INET6;
872 v6.sin6_addr = i6;
873 v6.sin6_port = htons (
port);
874#if HAVE_SOCKADDR_IN_SIN_LEN
875 v6.sin6_len = sizeof(v6);
876#endif
877 sa6 = (const struct sockaddr *) &v6;
878 }
879 else
882 "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
885 }
886
890 NULL,
892 NULL,
893 MHD_OPTION_CONNECTION_LIMIT,
894 (unsigned int) 128,
895 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
896 (unsigned int) 32,
897 MHD_OPTION_CONNECTION_TIMEOUT,
898 (unsigned int) 16,
899 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
900 (size_t) (16 * 1024),
901 MHD_OPTION_SOCK_ADDR,
902 sa6,
903 MHD_OPTION_END);
907 NULL,
909 NULL,
910 MHD_OPTION_CONNECTION_LIMIT,
911 (unsigned int) 128,
912 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
913 (unsigned int) 32,
914 MHD_OPTION_CONNECTION_TIMEOUT,
915 (unsigned int) 16,
916 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
917 (size_t) (16 * 1024),
918 MHD_OPTION_SOCK_ADDR,
919 sa4,
920 MHD_OPTION_END);
921
923 {
925 _ (
"Could not start hostlist HTTP server on port %u\n"),
926 (
unsigned short)
port);
928 }
929
939 NULL);
941}
static uint16_t port
Port number.
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.
static int ipv6
Option -6: IPv6 requested.
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,...)
#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
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.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
static unsigned int size
Size of the "table".