GNUnet  0.20.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 639 of file gnunet-daemon-hostlist_server.c.

644 {
645  unsigned long long port;
646  char *hostname;
647  char *ipv4;
648  char *ipv6;
649  size_t size;
650  struct in_addr i4;
651  struct in6_addr i6;
652  struct sockaddr_in v4;
653  struct sockaddr_in6 v6;
654  const struct sockaddr *sa4;
655  const struct sockaddr *sa6;
656 
657  advertising = advertise;
658  if (! advertising)
659  {
661  "Advertising not enabled on this hostlist server\n");
662  }
663  else
664  {
666  "Advertising enabled on this hostlist server\n");
667  }
668  cfg = c;
669  stats = st;
671  if (NULL == peerinfo)
672  {
674  _ ("Could not access PEERINFO service. Exiting.\n"));
675  return GNUNET_SYSERR;
676  }
678  "HOSTLIST",
679  "HTTPPORT",
680  &port))
681  return GNUNET_SYSERR;
682  if ((0 == port) || (port > UINT16_MAX))
683  {
685  _ ("Invalid port number %llu. Exiting.\n"),
686  port);
687  return GNUNET_SYSERR;
688  }
689 
690  if (GNUNET_SYSERR ==
692  "HOSTLIST",
693  "EXTERNAL_DNS_NAME",
694  &hostname))
697  _ ("Hostlist service starts on %s:%llu\n"),
698  hostname,
699  port);
700  if (NULL != hostname)
701  {
702  size = strlen (hostname);
703  if (size + 15 > MAX_URL_LEN)
704  {
705  GNUNET_break (0);
706  }
707  else
708  {
710  "http://%s:%u/",
711  hostname,
712  (unsigned int) port);
714  _ ("Address to obtain hostlist: `%s'\n"),
715  hostlist_uri);
716  }
718  }
719 
720  if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
721  {
723  "HOSTLIST",
724  "BINDTOIP",
725  &ipv4))
726  {
727  GNUNET_log (
729  _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
730  }
731  }
732  else
733  ipv4 = NULL;
734  if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
735  {
737  "HOSTLIST",
738  "BINDTOIP",
739  &ipv6))
740  {
741  GNUNET_log (
743  _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
744  }
745  }
746  else
747  ipv6 = NULL;
748  sa4 = NULL;
749  if (NULL != ipv4)
750  {
751  if (1 == inet_pton (AF_INET, ipv4, &i4))
752  {
753  memset (&v4, 0, sizeof(v4));
754  v4.sin_family = AF_INET;
755  v4.sin_addr = i4;
756  v4.sin_port = htons (port);
757 #if HAVE_SOCKADDR_IN_SIN_LEN
758  v4.sin_len = sizeof(v4);
759 #endif
760  sa4 = (const struct sockaddr *) &v4;
761  }
762  else
764  _ (
765  "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
766  ipv4);
767  GNUNET_free (ipv4);
768  }
769  sa6 = NULL;
770  if (NULL != ipv6)
771  {
772  if (1 == inet_pton (AF_INET6, ipv6, &i6))
773  {
774  memset (&v6, 0, sizeof(v6));
775  v6.sin6_family = AF_INET6;
776  v6.sin6_addr = i6;
777  v6.sin6_port = htons (port);
778 #if HAVE_SOCKADDR_IN_SIN_LEN
779  v6.sin6_len = sizeof(v6);
780 #endif
781  sa6 = (const struct sockaddr *) &v6;
782  }
783  else
785  _ (
786  "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
787  ipv6);
788  GNUNET_free (ipv6);
789  }
790 
791  daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
792  (uint16_t) port,
794  NULL,
796  NULL,
797  MHD_OPTION_CONNECTION_LIMIT,
798  (unsigned int) 128,
799  MHD_OPTION_PER_IP_CONNECTION_LIMIT,
800  (unsigned int) 32,
801  MHD_OPTION_CONNECTION_TIMEOUT,
802  (unsigned int) 16,
803  MHD_OPTION_CONNECTION_MEMORY_LIMIT,
804  (size_t) (16 * 1024),
805  MHD_OPTION_SOCK_ADDR,
806  sa6,
807  MHD_OPTION_END);
808  daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
809  (uint16_t) port,
811  NULL,
813  NULL,
814  MHD_OPTION_CONNECTION_LIMIT,
815  (unsigned int) 128,
816  MHD_OPTION_PER_IP_CONNECTION_LIMIT,
817  (unsigned int) 32,
818  MHD_OPTION_CONNECTION_TIMEOUT,
819  (unsigned int) 16,
820  MHD_OPTION_CONNECTION_MEMORY_LIMIT,
821  (size_t) (16 * 1024),
822  MHD_OPTION_SOCK_ADDR,
823  sa4,
824  MHD_OPTION_END);
825 
826  if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
827  {
829  _ ("Could not start hostlist HTTP server on port %u\n"),
830  (unsigned short) port);
831  return GNUNET_SYSERR;
832  }
833 
834  core = co;
836  if (NULL != daemon_handle_v4)
838  if (NULL != daemon_handle_v6)
841  return GNUNET_OK;
842 }
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 void * connect_handler(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
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 struct GNUNET_STATISTICS_Handle * stats
For keeping statistics.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_SCHEDULER_Task * hostlist_task_v6
Our primary task for IPv6.
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.
static struct GNUNET_PEERINFO_Handle * peerinfo
Handle for accessing peerinfo 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 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 struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we've connected to it).
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 char * hostname
Our hostname; we give this to all the peers we start.
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.
#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_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.
struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Definition: peerinfo_api.c:123
char * GNUNET_RESOLVER_local_fqdn_get(void)
Get local fully qualified domain name.
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_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_task_v4, hostlist_task_v6, hostlist_uri, hostname, ipv4, ipv6, MAX_URL_LEN, notify, peerinfo, port, prepare_daemon(), process_notify(), server_ch, size, st, 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 849 of file gnunet-daemon-hostlist_server.c.

850 {
851  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
852  if (NULL != hostlist_task_v6)
853  {
855  hostlist_task_v6 = NULL;
856  }
857  if (NULL != hostlist_task_v4)
858  {
860  hostlist_task_v4 = NULL;
861  }
862  if (NULL != daemon_handle_v4)
863  {
864  MHD_stop_daemon (daemon_handle_v4);
865  daemon_handle_v4 = NULL;
866  }
867  if (NULL != daemon_handle_v6)
868  {
869  MHD_stop_daemon (daemon_handle_v6);
870  daemon_handle_v6 = NULL;
871  }
872  if (NULL != response)
873  {
874  MHD_destroy_response (response);
875  response = NULL;
876  }
877  if (NULL != notify)
878  {
880  notify = NULL;
881  }
882  if (NULL != builder)
883  {
884  if (NULL != builder->pitr)
885  {
887  builder->pitr = NULL;
888  }
891  builder = NULL;
892  }
893  if (NULL != peerinfo)
894  {
896  peerinfo = NULL;
897  }
898  cfg = NULL;
899  stats = NULL;
900  core = NULL;
901 }
static struct MHD_Response * response
Our canonical response.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
void GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic)
Cancel an iteration over peer information.
Definition: peerinfo_api.c:497
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
Definition: peerinfo_api.c:149
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_PEERINFO_IteratorContext * pitr
Iterator used to build data (NULL when done).
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_PEERINFO_disconnect(), GNUNET_PEERINFO_iterate_cancel(), GNUNET_PEERINFO_notify_cancel(), GNUNET_SCHEDULER_cancel(), hostlist_task_v4, hostlist_task_v6, notify, peerinfo, HostSet::pitr, response, and stats.

Referenced by cleaning_task().

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