GNUnet  0.10.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 637 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().

642 {
643  unsigned long long port;
644  char *hostname;
645  char *ipv4;
646  char *ipv6;
647  size_t size;
648  struct in_addr i4;
649  struct in6_addr i6;
650  struct sockaddr_in v4;
651  struct sockaddr_in6 v6;
652  const struct sockaddr *sa4;
653  const struct sockaddr *sa6;
654 
655  advertising = advertise;
656  if (!advertising)
657  {
659  "Advertising not enabled on this hostlist server\n");
660  }
661  else
662  {
664  "Advertising enabled on this hostlist server\n");
665  }
666  cfg = c;
667  stats = st;
669  if (NULL == peerinfo)
670  {
672  _("Could not access PEERINFO service. Exiting.\n"));
673  return GNUNET_SYSERR;
674  }
676  "HOSTLIST",
677  "HTTPPORT",
678  &port))
679  return GNUNET_SYSERR;
680  if ((0 == port) || (port > UINT16_MAX))
681  {
683  _("Invalid port number %llu. Exiting.\n"),
684  port);
685  return GNUNET_SYSERR;
686  }
687 
688  if (GNUNET_SYSERR ==
690  "HOSTLIST",
691  "EXTERNAL_DNS_NAME",
692  &hostname))
693  hostname = GNUNET_RESOLVER_local_fqdn_get();
695  _("Hostlist service starts on %s:%llu\n"),
696  hostname,
697  port);
698  if (NULL != hostname)
699  {
700  size = strlen(hostname);
701  if (size + 15 > MAX_URL_LEN)
702  {
703  GNUNET_break(0);
704  }
705  else
706  {
708  "http://%s:%u/",
709  hostname,
710  (unsigned int)port);
712  _("Address to obtain hostlist: `%s'\n"),
713  hostlist_uri);
714  }
715  GNUNET_free(hostname);
716  }
717 
718  if (GNUNET_CONFIGURATION_have_value(cfg, "HOSTLIST", "BINDTOIPV4"))
719  {
721  "HOSTLIST",
722  "BINDTOIP",
723  &ipv4))
724  {
725  GNUNET_log(
727  _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
728  }
729  }
730  else
731  ipv4 = NULL;
732  if (GNUNET_CONFIGURATION_have_value(cfg, "HOSTLIST", "BINDTOIPV6"))
733  {
735  "HOSTLIST",
736  "BINDTOIP",
737  &ipv6))
738  {
739  GNUNET_log(
741  _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
742  }
743  }
744  else
745  ipv6 = NULL;
746  sa4 = NULL;
747  if (NULL != ipv4)
748  {
749  if (1 == inet_pton(AF_INET, ipv4, &i4))
750  {
751  memset(&v4, 0, sizeof(v4));
752  v4.sin_family = AF_INET;
753  v4.sin_addr = i4;
754  v4.sin_port = htons(port);
755 #if HAVE_SOCKADDR_IN_SIN_LEN
756  v4.sin_len = sizeof(v4);
757 #endif
758  sa4 = (const struct sockaddr *)&v4;
759  }
760  else
762  _(
763  "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
764  ipv4);
765  GNUNET_free(ipv4);
766  }
767  sa6 = NULL;
768  if (NULL != ipv6)
769  {
770  if (1 == inet_pton(AF_INET6, ipv6, &i6))
771  {
772  memset(&v6, 0, sizeof(v6));
773  v6.sin6_family = AF_INET6;
774  v6.sin6_addr = i6;
775  v6.sin6_port = htons(port);
776 #if HAVE_SOCKADDR_IN_SIN_LEN
777  v6.sin6_len = sizeof(v6);
778 #endif
779  sa6 = (const struct sockaddr *)&v6;
780  }
781  else
783  _(
784  "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
785  ipv6);
786  GNUNET_free(ipv6);
787  }
788 
789  daemon_handle_v6 = MHD_start_daemon(MHD_USE_IPv6 | MHD_USE_DEBUG,
790  (uint16_t)port,
792  NULL,
794  NULL,
795  MHD_OPTION_CONNECTION_LIMIT,
796  (unsigned int)128,
797  MHD_OPTION_PER_IP_CONNECTION_LIMIT,
798  (unsigned int)32,
799  MHD_OPTION_CONNECTION_TIMEOUT,
800  (unsigned int)16,
801  MHD_OPTION_CONNECTION_MEMORY_LIMIT,
802  (size_t)(16 * 1024),
803  MHD_OPTION_SOCK_ADDR,
804  sa6,
805  MHD_OPTION_END);
806  daemon_handle_v4 = MHD_start_daemon(MHD_NO_FLAG | MHD_USE_DEBUG,
807  (uint16_t)port,
809  NULL,
811  NULL,
812  MHD_OPTION_CONNECTION_LIMIT,
813  (unsigned int)128,
814  MHD_OPTION_PER_IP_CONNECTION_LIMIT,
815  (unsigned int)32,
816  MHD_OPTION_CONNECTION_TIMEOUT,
817  (unsigned int)16,
818  MHD_OPTION_CONNECTION_MEMORY_LIMIT,
819  (size_t)(16 * 1024),
820  MHD_OPTION_SOCK_ADDR,
821  sa4,
822  MHD_OPTION_END);
823 
824  if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
825  {
827  _("Could not start hostlist HTTP server on port %u\n"),
828  (unsigned short)port);
829  return GNUNET_SYSERR;
830  }
831 
832  core = co;
833  *server_ch = &connect_handler;
834  if (NULL != daemon_handle_v4)
836  if (NULL != daemon_handle_v6)
839  return GNUNET_OK;
840 }
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:128
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:66
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 847 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().

848 {
849  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
850  if (NULL != hostlist_task_v6)
851  {
853  hostlist_task_v6 = NULL;
854  }
855  if (NULL != hostlist_task_v4)
856  {
858  hostlist_task_v4 = NULL;
859  }
860  if (NULL != daemon_handle_v4)
861  {
862  MHD_stop_daemon(daemon_handle_v4);
863  daemon_handle_v4 = NULL;
864  }
865  if (NULL != daemon_handle_v6)
866  {
867  MHD_stop_daemon(daemon_handle_v6);
868  daemon_handle_v6 = NULL;
869  }
870  if (NULL != response)
871  {
872  MHD_destroy_response(response);
873  response = NULL;
874  }
875  if (NULL != notify)
876  {
878  notify = NULL;
879  }
880  if (NULL != builder)
881  {
882  if (NULL != builder->pitr)
883  {
885  builder->pitr = NULL;
886  }
889  builder = NULL;
890  }
891  if (NULL != peerinfo)
892  {
894  peerinfo = NULL;
895  }
896  cfg = NULL;
897  stats = NULL;
898  core = NULL;
899 }
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:519
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:154
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:956
Here is the call graph for this function:
Here is the caller graph for this function: