GNUnet  0.10.x
gnunet-daemon-hostlist_server.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2008, 2009, 2010, 2014, 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 
28 #include "platform.h"
29 #include <microhttpd.h>
31 #include "gnunet_hello_lib.h"
33 #include "gnunet-daemon-hostlist.h"
35 
36 
41 #define GNUNET_ADV_TIMEOUT \
42  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
43 
44 
48 static struct MHD_Daemon *daemon_handle_v6;
49 
53 static struct MHD_Daemon *daemon_handle_v4;
54 
58 static const struct GNUNET_CONFIGURATION_Handle *cfg;
59 
64 
68 static struct GNUNET_CORE_Handle *core;
69 
74 
79 
84 
88 static struct MHD_Response *response;
89 
94 
98 static int advertising;
99 
103 static char *hostlist_uri;
104 
105 
109 struct HostSet
110 {
115 
119  char *data;
120 
124  unsigned int size;
125 };
126 
127 
131 static struct HostSet *builder;
132 
133 
140 static void
141 add_cors_headers (struct MHD_Response *response)
142 {
143  MHD_add_response_header (response, "Access-Control-Allow-Origin", "*");
144  MHD_add_response_header (response,
145  "Access-Control-Allow-Methods",
146  "GET, OPTIONS");
147  MHD_add_response_header (response, "Access-Control-Max-Age", "86400");
148 }
149 
150 
154 static void
156 {
157  if (NULL != response)
158  MHD_destroy_response (response);
160  "Creating hostlist response with %u bytes\n",
161  (unsigned int) builder->size);
162  response = MHD_create_response_from_buffer (builder->size,
163  builder->data,
164  MHD_RESPMEM_MUST_FREE);
166  if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6))
167  {
168  MHD_destroy_response (response);
169  response = NULL;
170  }
171  GNUNET_STATISTICS_set (stats,
172  gettext_noop ("bytes in hostlist"),
173  builder->size,
174  GNUNET_YES);
175  GNUNET_free (builder);
176  builder = NULL;
177 }
178 
179 
188 static int
189 check_has_addr (void *cls,
190  const struct GNUNET_HELLO_Address *address,
192 {
193  int *arg = cls;
194 
195  if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
196  {
198  gettext_noop ("expired addresses encountered"),
199  1,
200  GNUNET_YES);
201  return GNUNET_YES; /* ignore this address */
202  }
203  *arg = GNUNET_YES;
204  return GNUNET_SYSERR;
205 }
206 
207 
217 static void
218 host_processor (void *cls,
219  const struct GNUNET_PeerIdentity *peer,
220  const struct GNUNET_HELLO_Message *hello,
221  const char *err_msg)
222 {
223  size_t old;
224  size_t s;
225  int has_addr;
226 
227  if (NULL != err_msg)
228  {
229  GNUNET_assert (NULL == peer);
230  builder->pitr = NULL;
231  GNUNET_free_non_null (builder->data);
232  GNUNET_free (builder);
233  builder = NULL;
235  _ ("Error in communication with PEERINFO service: %s\n"),
236  err_msg);
237  return;
238  }
239  if (NULL == peer)
240  {
241  builder->pitr = NULL;
242  finish_response ();
243  return;
244  }
245  if (NULL == hello)
246  return;
247  has_addr = GNUNET_NO;
249  if (GNUNET_NO == has_addr)
250  {
252  "HELLO for peer `%4s' has no address, not suitable for hostlist!\n",
253  GNUNET_i2s (peer));
255  gettext_noop (
256  "HELLOs without addresses encountered (ignored)"),
257  1,
258  GNUNET_NO);
259  return;
260  }
261  old = builder->size;
262  s = GNUNET_HELLO_size (hello);
264  "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
265  (unsigned int) s,
266  "HELLO",
267  GNUNET_i2s (peer));
268  if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
269  (old + s >= MAX_BYTES_PER_HOSTLISTS))
270  {
271  /* too large, skip! */
273  gettext_noop (
274  "bytes not included in hostlist (size limit)"),
275  s,
276  GNUNET_NO);
277  return;
278  }
280  "Adding peer `%s' to hostlist (%u bytes)\n",
281  GNUNET_i2s (peer),
282  (unsigned int) s);
283  GNUNET_array_grow (builder->data, builder->size, old + s);
284  GNUNET_memcpy (&builder->data[old], hello, s);
285 }
286 
287 
297 static int
299  const struct sockaddr *addr,
300  socklen_t addrlen)
301 {
302  if (NULL == response)
303  {
304  GNUNET_log (
306  "Received request for hostlist, but I am not yet ready; rejecting!\n");
307  return MHD_NO;
308  }
309  return MHD_YES; /* accept all */
310 }
311 
312 
348 static int
350  struct MHD_Connection *connection,
351  const char *url,
352  const char *method,
353  const char *version,
354  const char *upload_data,
355  size_t *upload_data_size,
356  void **con_cls)
357 {
358  static int dummy;
359 
360  /* CORS pre-flight request */
361  if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
362  {
363  struct MHD_Response *options_response;
364  int rc;
365 
366  options_response =
367  MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT);
368  add_cors_headers (options_response);
369  rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
370  MHD_destroy_response (options_response);
371  return rc;
372  }
373  if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
374  {
376  _ ("Refusing `%s' request to hostlist server\n"),
377  method);
379  gettext_noop (
380  "hostlist requests refused (not HTTP GET)"),
381  1,
382  GNUNET_YES);
383  return MHD_NO;
384  }
385  if (NULL == *con_cls)
386  {
387  (*con_cls) = &dummy;
388  return MHD_YES;
389  }
390  if (0 != *upload_data_size)
391  {
393  _ ("Refusing `%s' request with %llu bytes of upload data\n"),
394  method,
395  (unsigned long long) *upload_data_size);
397  gettext_noop (
398  "hostlist requests refused (upload data)"),
399  1,
400  GNUNET_YES);
401  return MHD_NO; /* do not support upload data */
402  }
403  if (NULL == response)
404  {
405  GNUNET_log (
407  _ (
408  "Could not handle hostlist request since I do not have a response yet\n"));
410  gettext_noop (
411  "hostlist requests refused (not ready)"),
412  1,
413  GNUNET_YES);
414  return MHD_NO; /* internal error, no response yet */
415  }
417  _ ("Received request for our hostlist\n"));
419  gettext_noop ("hostlist requests processed"),
420  1,
421  GNUNET_YES);
422  return MHD_queue_response (connection, MHD_HTTP_OK, response);
423 }
424 
425 
435 static void
437 {
438  static uint64_t hostlist_adv_count;
439  size_t uri_size; /* Including \0 termination! */
440  struct GNUNET_MessageHeader *header;
441  struct GNUNET_MQ_Envelope *env;
442 
443  uri_size = strlen (hostlist_uri) + 1;
444  env = GNUNET_MQ_msg_extra (header,
445  uri_size,
447  GNUNET_memcpy (&header[1], hostlist_uri, uri_size);
451  GNUNET_MQ_send (mq, env);
453  "Sent advertisement message: Copied %u bytes into buffer!\n",
454  (unsigned int) uri_size);
455  hostlist_adv_count++;
457  " # Sent advertisement message: %llu\n",
458  (unsigned long long) hostlist_adv_count);
460  gettext_noop ("# hostlist advertisements send"),
461  1,
462  GNUNET_NO);
463 }
464 
465 
474 static void *
475 connect_handler (void *cls,
476  const struct GNUNET_PeerIdentity *peer,
477  struct GNUNET_MQ_Handle *mq)
478 {
479  size_t size;
480 
481  if (! advertising)
482  return NULL;
483  if (NULL == hostlist_uri)
484  return NULL;
485  size = strlen (hostlist_uri) + 1;
486  if (size + sizeof (struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE)
487  {
488  GNUNET_break (0);
489  return NULL;
490  }
491  size += sizeof (struct GNUNET_MessageHeader);
492  if (NULL == core)
493  {
494  GNUNET_break (0);
495  return NULL;
496  }
497  GNUNET_log (
499  "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n",
500  (unsigned int) size,
501  GNUNET_i2s (peer));
502  adv_transmit (mq);
503  return NULL;
504 }
505 
506 
516 static void
517 process_notify (void *cls,
518  const struct GNUNET_PeerIdentity *peer,
519  const struct GNUNET_HELLO_Message *hello,
520  const char *err_msg)
521 {
523  "Peerinfo is notifying us to rebuild our hostlist\n");
524  if (NULL != err_msg)
526  _ ("Error in communication with PEERINFO service: %s\n"),
527  err_msg);
528  if (NULL != builder)
529  {
530  /* restart re-build already in progress ... */
531  if (NULL != builder->pitr)
532  {
534  builder->pitr = NULL;
535  }
536  GNUNET_free_non_null (builder->data);
537  builder->size = 0;
538  builder->data = NULL;
539  }
540  else
541  {
542  builder = GNUNET_new (struct HostSet);
543  }
544  GNUNET_assert (NULL != peerinfo);
545  builder->pitr =
546  GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, &host_processor, NULL);
547 }
548 
549 
554 static struct GNUNET_SCHEDULER_Task *
555 prepare_daemon (struct MHD_Daemon *daemon_handle);
556 
557 
564 static void
565 run_daemon (void *cls)
566 {
567  struct MHD_Daemon *daemon_handle = cls;
568 
569  if (daemon_handle == daemon_handle_v4)
570  hostlist_task_v4 = NULL;
571  else
572  hostlist_task_v6 = NULL;
573  GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
574  if (daemon_handle == daemon_handle_v4)
575  hostlist_task_v4 = prepare_daemon (daemon_handle);
576  else
577  hostlist_task_v6 = prepare_daemon (daemon_handle);
578 }
579 
580 
587 static struct GNUNET_SCHEDULER_Task *
588 prepare_daemon (struct MHD_Daemon *daemon_handle)
589 {
590  struct GNUNET_SCHEDULER_Task *ret;
591  fd_set rs;
592  fd_set ws;
593  fd_set es;
594  struct GNUNET_NETWORK_FDSet *wrs;
595  struct GNUNET_NETWORK_FDSet *wws;
596  int max;
597  MHD_UNSIGNED_LONG_LONG timeout;
598  int haveto;
599  struct GNUNET_TIME_Relative tv;
600 
601  FD_ZERO (&rs);
602  FD_ZERO (&ws);
603  FD_ZERO (&es);
606  max = -1;
607  GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
608  haveto = MHD_get_timeout (daemon_handle, &timeout);
609  if (haveto == MHD_YES)
610  tv.rel_value_us = (uint64_t) timeout * 1000LL;
611  else
613  GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
614  GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
616  tv,
617  wrs,
618  wws,
619  &run_daemon,
620  daemon_handle);
623  return ret;
624 }
625 
626 
637 int
640  struct GNUNET_CORE_Handle *co,
642  int advertise)
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;
669  peerinfo = GNUNET_PEERINFO_connect (cfg);
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)
836  hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
837  if (NULL != daemon_handle_v6)
838  hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
839  notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL);
840  return GNUNET_OK;
841 }
842 
843 
847 void
849 {
850  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
851  if (NULL != hostlist_task_v6)
852  {
853  GNUNET_SCHEDULER_cancel (hostlist_task_v6);
854  hostlist_task_v6 = NULL;
855  }
856  if (NULL != hostlist_task_v4)
857  {
858  GNUNET_SCHEDULER_cancel (hostlist_task_v4);
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  }
888  GNUNET_free_non_null (builder->data);
889  GNUNET_free (builder);
890  builder = NULL;
891  }
892  if (NULL != peerinfo)
893  {
894  GNUNET_PEERINFO_disconnect (peerinfo);
895  peerinfo = NULL;
896  }
897  cfg = NULL;
898  stats = NULL;
899  core = NULL;
900 }
901 
902 /* end of gnunet-daemon-hostlist_server.c */
static struct MHD_Daemon * daemon_handle
Handle to the HTTP server as provided by libmicrohttpd.
Definition: gnunet-bcd.c:44
static int check_has_addr(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Set cls to GNUNET_YES (we have an address!).
common internal definitions for hostlist daemon
static struct GNUNET_SCHEDULER_Task * prepare_daemon(struct MHD_Daemon *daemon_handle)
Function that queries MHD&#39;s select sets and starts the task waiting for them.
#define MAX_URL_LEN
How long can hostlist URLs be?
#define MAX_BYTES_PER_HOSTLISTS
How many bytes do we download at most from a hostlist server?
Run with high priority (important requests).
Handle to the peerinfo service.
Definition: peerinfo_api.c:86
A HELLO message is used to exchange information about transports with other peers.
static void adv_transmit(struct GNUNET_MQ_Handle *mq)
Handler called by CORE when CORE is ready to transmit message.
static char * expiration
Credential TTL.
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.
uint64_t rel_value_us
The actual value.
static struct in_addr dummy
Target "dummy" address.
Context for the core service connection.
Definition: core_api.c:78
struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Definition: peerinfo_api.c:133
Context for the info handler.
static struct GNUNET_STATISTICS_Handle * stats
For keeping statistics.
struct GNUNET_PEERINFO_IteratorContext * pitr
Iterator used to build data (NULL when done).
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.
static int ipv4
Option -4: IPv4 requested.
Definition: gnunet-vpn.c:61
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
void GNUNET_MQ_env_set_options(struct GNUNET_MQ_Envelope *env, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific options for this envelope.
Definition: mq.c:1005
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:81
static char * hostlist_uri
Buffer for the hostlist address.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static int ret
Final status code.
Definition: gnunet-arm.c:89
Handle for the service.
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...
Context for an iteration request.
Definition: peerinfo_api.c:37
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1308
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.
void *(* GNUNET_CORE_ConnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_SCHEDULER_Task * hostlist_task_v6
Our primary task for IPv6.
struct GNUNET_PEERINFO_IteratorContext * GNUNET_PEERINFO_iterate(struct GNUNET_PEERINFO_Handle *h, int include_friend_only, const struct GNUNET_PeerIdentity *peer, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method for each known matching host.
Definition: peerinfo_api.c:491
Context for host_processor().
static int advertising
Set if we are allowed to advertise our hostlist to others.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
void GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic)
Cancel an iteration over peer information.
Definition: peerinfo_api.c:524
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
#define GNUNET_memcpy(dst, src, n)
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:254
static void finish_response()
Function that assembles our response.
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&#39;ve connected to it).
char * GNUNET_RESOLVER_local_fqdn_get(void)
Get local fully qualified domain name.
unsigned int size
Number of bytes in data.
static void add_cors_headers(struct MHD_Response *response)
Add headers to a request indicating that we allow Cross-Origin Resource Sharing.
static struct GNUNET_PEERINFO_Handle * peerinfo
Handle for accessing peerinfo service.
collection of IO descriptors
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.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1829
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
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.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct MHD_Daemon * daemon_handle_v6
Handle to the HTTP server as provided by libmicrohttpd for IPv6.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
Handle to a message queue.
Definition: mq.c:85
The identity of the host (wraps the signing key of the peer).
static void host_processor(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
Callback that processes each of the known HELLOs for the hostlist response construction.
static char * hostname
Our hostname; we give this to all the peers we start.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
configuration data
Definition: configuration.c:85
void GNUNET_HOSTLIST_server_stop()
Stop server offering our hostlist.
An address for communicating with a peer.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static int inet_pton(int af, const char *cp, struct in_addr *buf)
Convert IPv4 address from text to binary form.
#define GNUNET_log(kind,...)
#define GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT
Further X-VINE DHT messages continued from 880.
Entry in list of pending tasks.
Definition: scheduler.c:134
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:649
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
Definition: peerinfo_api.c:159
static struct MHD_Response * response
Our canonical response.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
static void run_daemon(void *cls)
Call MHD to process pending requests and then go back and schedule the next run.
Flag to indicate that CORKing is acceptable.
Header for all communications.
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
char * data
Place where we accumulate all of the HELLO messages.
Flag to indicate that unreliable delivery is acceptable.
static struct GNUNET_CORE_Handle * core
Handle to the core service (NULL until we&#39;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.
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static struct HostSet * builder
NULL if we are not currenlty iterating over peer information.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:66
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965