GNUnet  0.11.x
Functions
gnunet-daemon-hostlist_server.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_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 638 of file gnunet-daemon-hostlist_server.c.

References _, accept_policy_callback(), access_handler_callback(), advertising, connect_handler(), 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_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_PEERINFO_connect(), GNUNET_PEERINFO_notify(), GNUNET_RESOLVER_local_fqdn_get(), GNUNET_SYSERR, hostlist_uri, hostname, ipv4, ipv6, MAX_URL_LEN, port, prepare_daemon(), process_notify(), HostSet::size, and st.

Referenced by run().

643 {
644  unsigned long long port;
645  char *hostname;
646  char *ipv4;
647  char *ipv6;
648  size_t size;
649  struct in_addr i4;
650  struct in6_addr i6;
651  struct sockaddr_in v4;
652  struct sockaddr_in6 v6;
653  const struct sockaddr *sa4;
654  const struct sockaddr *sa6;
655 
656  advertising = advertise;
657  if (! advertising)
658  {
660  "Advertising not enabled on this hostlist server\n");
661  }
662  else
663  {
665  "Advertising enabled on this hostlist server\n");
666  }
667  cfg = c;
668  stats = st;
670  if (NULL == peerinfo)
671  {
673  _ ("Could not access PEERINFO service. Exiting.\n"));
674  return GNUNET_SYSERR;
675  }
677  "HOSTLIST",
678  "HTTPPORT",
679  &port))
680  return GNUNET_SYSERR;
681  if ((0 == port) || (port > UINT16_MAX))
682  {
684  _ ("Invalid port number %llu. Exiting.\n"),
685  port);
686  return GNUNET_SYSERR;
687  }
688 
689  if (GNUNET_SYSERR ==
691  "HOSTLIST",
692  "EXTERNAL_DNS_NAME",
693  &hostname))
694  hostname = GNUNET_RESOLVER_local_fqdn_get ();
696  _ ("Hostlist service starts on %s:%llu\n"),
697  hostname,
698  port);
699  if (NULL != hostname)
700  {
701  size = strlen (hostname);
702  if (size + 15 > MAX_URL_LEN)
703  {
704  GNUNET_break (0);
705  }
706  else
707  {
709  "http://%s:%u/",
710  hostname,
711  (unsigned int) port);
713  _ ("Address to obtain hostlist: `%s'\n"),
714  hostlist_uri);
715  }
716  GNUNET_free (hostname);
717  }
718 
719  if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
720  {
722  "HOSTLIST",
723  "BINDTOIP",
724  &ipv4))
725  {
726  GNUNET_log (
728  _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
729  }
730  }
731  else
732  ipv4 = NULL;
733  if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
734  {
736  "HOSTLIST",
737  "BINDTOIP",
738  &ipv6))
739  {
740  GNUNET_log (
742  _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
743  }
744  }
745  else
746  ipv6 = NULL;
747  sa4 = NULL;
748  if (NULL != ipv4)
749  {
750  if (1 == inet_pton (AF_INET, ipv4, &i4))
751  {
752  memset (&v4, 0, sizeof(v4));
753  v4.sin_family = AF_INET;
754  v4.sin_addr = i4;
755  v4.sin_port = htons (port);
756 #if HAVE_SOCKADDR_IN_SIN_LEN
757  v4.sin_len = sizeof(v4);
758 #endif
759  sa4 = (const struct sockaddr *) &v4;
760  }
761  else
763  _ (
764  "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
765  ipv4);
766  GNUNET_free (ipv4);
767  }
768  sa6 = NULL;
769  if (NULL != ipv6)
770  {
771  if (1 == inet_pton (AF_INET6, ipv6, &i6))
772  {
773  memset (&v6, 0, sizeof(v6));
774  v6.sin6_family = AF_INET6;
775  v6.sin6_addr = i6;
776  v6.sin6_port = htons (port);
777 #if HAVE_SOCKADDR_IN_SIN_LEN
778  v6.sin6_len = sizeof(v6);
779 #endif
780  sa6 = (const struct sockaddr *) &v6;
781  }
782  else
784  _ (
785  "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
786  ipv6);
787  GNUNET_free (ipv6);
788  }
789 
790  daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
791  (uint16_t) port,
793  NULL,
795  NULL,
796  MHD_OPTION_CONNECTION_LIMIT,
797  (unsigned int) 128,
798  MHD_OPTION_PER_IP_CONNECTION_LIMIT,
799  (unsigned int) 32,
800  MHD_OPTION_CONNECTION_TIMEOUT,
801  (unsigned int) 16,
802  MHD_OPTION_CONNECTION_MEMORY_LIMIT,
803  (size_t) (16 * 1024),
804  MHD_OPTION_SOCK_ADDR,
805  sa6,
806  MHD_OPTION_END);
807  daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
808  (uint16_t) port,
810  NULL,
812  NULL,
813  MHD_OPTION_CONNECTION_LIMIT,
814  (unsigned int) 128,
815  MHD_OPTION_PER_IP_CONNECTION_LIMIT,
816  (unsigned int) 32,
817  MHD_OPTION_CONNECTION_TIMEOUT,
818  (unsigned int) 16,
819  MHD_OPTION_CONNECTION_MEMORY_LIMIT,
820  (size_t) (16 * 1024),
821  MHD_OPTION_SOCK_ADDR,
822  sa4,
823  MHD_OPTION_END);
824 
825  if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
826  {
828  _ ("Could not start hostlist HTTP server on port %u\n"),
829  (unsigned short) port);
830  return GNUNET_SYSERR;
831  }
832 
833  core = co;
834  *server_ch = &connect_handler;
835  if (NULL != daemon_handle_v4)
837  if (NULL != daemon_handle_v6)
840  return GNUNET_OK;
841 }
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.
#define MAX_URL_LEN
How long can hostlist URLs be?
int 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.
struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Definition: peerinfo_api.c:130
static struct GNUNET_STATISTICS_Handle * stats
For keeping statistics.
static int ipv4
Option -4: IPv4 requested.
Definition: gnunet-vpn.c:61
static void * connect_handler(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 char * hostlist_uri
Buffer for the hostlist address.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void process_notify(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
PEERINFO calls this function to let us know about a possible peer that we might want to connect to...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_PEERINFO_NotifyContext * GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, int include_friend_only, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method whenever our known information about peers changes.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_SCHEDULER_Task * hostlist_task_v6
Our primary task for IPv6.
static int advertising
Set if we are allowed to advertise our hostlist to others.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct GNUNET_SCHEDULER_Task * hostlist_task_v4
Our primary task for IPv4.
int 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.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we've connected to it).
char * GNUNET_RESOLVER_local_fqdn_get(void)
Get local fully qualified domain name.
static struct GNUNET_PEERINFO_Handle * peerinfo
Handle for accessing peerinfo service.
static int 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 int accept_policy_callback(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Hostlist access policy (very permissive, allows everything).
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.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
static struct MHD_Daemon * daemon_handle_v6
Handle to the HTTP server as provided by libmicrohttpd for IPv6.
static char * hostname
Our hostname; we give this to all the peers we start.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
#define GNUNET_log(kind,...)
static struct GNUNET_CORE_Handle * core
Handle to the core service (NULL until we've connected to it).
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static struct MHD_Daemon * daemon_handle_v4
Handle to the HTTP server as provided by libmicrohttpd for IPv4.
#define GNUNET_free(ptr)
Wrapper around free.
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:66
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 848 of file gnunet-daemon-hostlist_server.c.

References daemon_handle_v4, daemon_handle_v6, HostSet::data, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_log, GNUNET_PEERINFO_disconnect(), GNUNET_PEERINFO_iterate_cancel(), GNUNET_PEERINFO_notify_cancel(), GNUNET_SCHEDULER_cancel(), HostSet::pitr, and response.

Referenced by cleaning_task().

849 {
850  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
851  if (NULL != hostlist_task_v6)
852  {
854  hostlist_task_v6 = NULL;
855  }
856  if (NULL != hostlist_task_v4)
857  {
859  hostlist_task_v4 = NULL;
860  }
861  if (NULL != daemon_handle_v4)
862  {
863  MHD_stop_daemon (daemon_handle_v4);
864  daemon_handle_v4 = NULL;
865  }
866  if (NULL != daemon_handle_v6)
867  {
868  MHD_stop_daemon (daemon_handle_v6);
869  daemon_handle_v6 = NULL;
870  }
871  if (NULL != response)
872  {
873  MHD_destroy_response (response);
874  response = NULL;
875  }
876  if (NULL != notify)
877  {
879  notify = NULL;
880  }
881  if (NULL != builder)
882  {
883  if (NULL != builder->pitr)
884  {
886  builder->pitr = NULL;
887  }
890  builder = NULL;
891  }
892  if (NULL != peerinfo)
893  {
895  peerinfo = NULL;
896  }
897  cfg = NULL;
898  stats = NULL;
899  core = NULL;
900 }
static struct GNUNET_STATISTICS_Handle * stats
For keeping statistics.
struct GNUNET_PEERINFO_IteratorContext * pitr
Iterator used to build data (NULL when done).
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static struct GNUNET_SCHEDULER_Task * hostlist_task_v6
Our primary task for IPv6.
void GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic)
Cancel an iteration over peer information.
Definition: peerinfo_api.c:520
static struct GNUNET_SCHEDULER_Task * hostlist_task_v4
Our primary task for IPv4.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we've connected to it).
static struct GNUNET_PEERINFO_Handle * peerinfo
Handle for accessing peerinfo service.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct MHD_Daemon * daemon_handle_v6
Handle to the HTTP server as provided by libmicrohttpd for IPv6.
#define GNUNET_log(kind,...)
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
Definition: peerinfo_api.c:156
static struct MHD_Response * response
Our canonical response.
char * data
Place where we accumulate all of the HELLO messages.
static struct GNUNET_CORE_Handle * core
Handle to the core service (NULL until we've connected to it).
static struct MHD_Daemon * daemon_handle_v4
Handle to the HTTP server as provided by libmicrohttpd for IPv4.
static struct HostSet * builder
NULL if we are not currenlty iterating over peer information.
#define GNUNET_free(ptr)
Wrapper around free.
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: