GNUnet 0.22.0
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 "gnunet_common.h"
30#include <microhttpd.h>
36#include "gnunet_mhd_compat.h"
37#include <jansson.h>
38#include <strings.h>
39
44#define GNUNET_ADV_TIMEOUT \
45 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
46
51
55static struct MHD_Daemon *daemon_handle_v6;
56
60static struct MHD_Daemon *daemon_handle_v4;
61
65static const struct GNUNET_CONFIGURATION_Handle *cfg;
66
71
75static struct GNUNET_CORE_Handle *core;
76
82
88
93
98
102static struct MHD_Response *response;
103
107static struct MHD_Response *response_json;
108
113
117static int advertising;
118
122static char *hostlist_uri;
123
124
129{
133 char *data;
134
138 unsigned int size;
139};
140
141
145static struct HostSet *builder;
146
147
154static void
155add_cors_headers (struct MHD_Response *resp)
156{
157 MHD_add_response_header (resp, "Access-Control-Allow-Origin", "*");
158 MHD_add_response_header (resp,
159 "Access-Control-Allow-Methods",
160 "GET, OPTIONS");
161 MHD_add_response_header (resp, "Access-Control-Max-Age", "86400");
162}
163
164
165static struct MHD_Response*
166build_json_response (const struct HostSet *bu)
167{
168 struct GNUNET_MessageHeader *hello;
169 struct GNUNET_HELLO_Builder *hbuilder;
170 json_t*hello_uri_j;
171 json_t*hello_array;
172 char *hello_uri;
173 char *hello_uris;
174 size_t offset = 0;
175
176 hello_uri_j = json_object ();
177 hello_array = json_array ();
178 while (offset < bu->size)
179 {
180 hello = (struct GNUNET_MessageHeader*) (bu->data + offset);
181 hbuilder = GNUNET_HELLO_builder_from_msg (hello);
182 hello_uri = GNUNET_HELLO_builder_to_url (hbuilder, NULL);
183 json_array_append_new (hello_array, json_string (hello_uri));
184 GNUNET_free (hello_uri);
185 GNUNET_HELLO_builder_free (hbuilder);
186 offset += ntohs (hello->size);
187 }
188 json_object_set_new (hello_uri_j, "hellos", hello_array);
189 hello_uris = json_dumps (hello_uri_j, JSON_INDENT (2));
190 json_decref (hello_uri_j);
191 return MHD_create_response_from_buffer (strlen (hello_uris),
192 hello_uris,
193 MHD_RESPMEM_MUST_FREE);
194}
195
196
200static void
202{
203 if (NULL != response)
204 MHD_destroy_response (response);
205 if (NULL != response_json)
206 MHD_destroy_response (response_json);
208 "Creating hostlist response with %u bytes\n",
209 (unsigned int) builder->size);
210 response = MHD_create_response_from_buffer (builder->size,
211 builder->data,
212 MHD_RESPMEM_MUST_FREE);
214 MHD_add_response_header (response_json,
215 "Content-Type",
216 "application/json");
218 if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6))
219 {
220 MHD_destroy_response (response);
221 response = NULL;
222 MHD_destroy_response (response_json);
223 response_json = NULL;
224 }
226 gettext_noop ("bytes in hostlist"),
227 builder->size,
228 GNUNET_YES);
230 builder = NULL;
231}
232
233
244host_processor (void *cls,
245 const struct GNUNET_PeerIdentity *peer,
246 void *value)
247{
248 (void) cls;
249 size_t old;
250 size_t s;
251 struct GNUNET_MessageHeader *hello = value;
252
254 "host_processor\n");
255 old = builder->size;
256 s = ntohs (hello->size);
258 "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
259 (unsigned int) s,
260 "HELLO",
261 GNUNET_i2s (peer));
262 if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
263 (old + s >= MAX_BYTES_PER_HOSTLISTS))
264 {
265 /* too large, skip! */
268 "bytes not included in hostlist (size limit)"),
269 s,
270 GNUNET_NO);
271 return GNUNET_YES;
272 }
274 "Adding peer `%s' to hostlist (%u bytes)\n",
275 GNUNET_i2s (peer),
276 (unsigned int) s);
278 GNUNET_memcpy (&builder->data[old], hello, s);
279
280 return GNUNET_YES;
281}
282
283
293static MHD_RESULT
295 const struct sockaddr *addr,
296 socklen_t addrlen)
297{
298 if (NULL == response)
299 {
300 GNUNET_log (
302 "Received request for hostlist, but I am not yet ready; rejecting!\n");
303 return MHD_NO;
304 }
305 return MHD_YES; /* accept all */
306}
307
308static int
310 enum MHD_ValueKind kind,
311 const char *key,
312 const char *value)
313{
314 enum GNUNET_GenericReturnValue *want_json = cls;
315
316 if (0 != strcasecmp(key, "Accept"))
317 return GNUNET_YES;
318 if (0 == strcasecmp (value, "application/json"))
319 *want_json = GNUNET_YES;
320 return MHD_YES;
321}
322
358static MHD_RESULT
360 struct MHD_Connection *connection,
361 const char *url,
362 const char *method,
363 const char *version,
364 const char *upload_data,
365 size_t *upload_data_size,
366 void **con_cls)
367{
368 static int dummy;
369 struct MHD_Response *selected_response;
370
371 /* CORS pre-flight request */
372 if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
373 {
374 struct MHD_Response *options_response;
375 int rc;
376
377 options_response =
378 MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT);
379 add_cors_headers (options_response);
380 rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
381 MHD_destroy_response (options_response);
382 return rc;
383 }
384 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
385 {
387 _ ("Refusing `%s' request to hostlist server\n"),
388 method);
391 "hostlist requests refused (not HTTP GET)"),
392 1,
393 GNUNET_YES);
394 return MHD_NO;
395 }
396 if (NULL == *con_cls)
397 {
398 (*con_cls) = &dummy;
399 return MHD_YES;
400 }
401 if (0 != *upload_data_size)
402 {
404 _ ("Refusing `%s' request with %llu bytes of upload data\n"),
405 method,
406 (unsigned long long) *upload_data_size);
409 "hostlist requests refused (upload data)"),
410 1,
411 GNUNET_YES);
412 return MHD_NO; /* do not support upload data */
413 }
414 selected_response = response;
415 enum GNUNET_GenericReturnValue want_json = GNUNET_NO;
416 MHD_get_connection_values (connection,
417 MHD_HEADER_KIND,
418 (MHD_KeyValueIterator) &header_iterator,
419 &want_json);
420 if (GNUNET_YES == want_json)
421 {
422 selected_response = response_json;
423 }
424 if (NULL == selected_response)
425 {
426 GNUNET_log (
428 _ (
429 "Could not handle hostlist request since I do not have a response yet\n"));
432 "hostlist requests refused (not ready)"),
433 1,
434 GNUNET_YES);
435 return MHD_NO; /* internal error, no response yet */
436 }
438 _ ("Received request for our hostlist\n"));
440 gettext_noop ("hostlist requests processed"),
441 1,
442 GNUNET_YES);
443 return MHD_queue_response (connection, MHD_HTTP_OK, selected_response);
444}
445
446
456static void
458{
459 static uint64_t hostlist_adv_count;
460 size_t uri_size; /* Including \0 termination! */
461 struct GNUNET_MessageHeader *header;
462 struct GNUNET_MQ_Envelope *env;
463
464 uri_size = strlen (hostlist_uri) + 1;
465 env = GNUNET_MQ_msg_extra (header,
466 uri_size,
468 GNUNET_memcpy (&header[1], hostlist_uri, uri_size);
474 "Sent advertisement message: Copied %u bytes into buffer!\n",
475 (unsigned int) uri_size);
476 hostlist_adv_count++;
478 " # Sent advertisement message: %llu\n",
479 (unsigned long long) hostlist_adv_count);
481 gettext_noop ("# hostlist advertisements send"),
482 1,
483 GNUNET_NO);
484}
485
486
495static void *
497 const struct GNUNET_PeerIdentity *peer,
498 struct GNUNET_MQ_Handle *mq)
499{
500 size_t size;
501
502 if (! advertising)
503 return NULL;
504 if (NULL == hostlist_uri)
505 return NULL;
506 size = strlen (hostlist_uri) + 1;
507 if (size + sizeof(struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE)
508 {
509 GNUNET_break (0);
510 return NULL;
511 }
512 size += sizeof(struct GNUNET_MessageHeader);
513 if (NULL == core)
514 {
515 GNUNET_break (0);
516 return NULL;
517 }
518 GNUNET_log (
520 "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n",
521 (unsigned int) size,
522 GNUNET_i2s (peer));
524 return NULL;
525}
526
527
537static void
538process_notify (void *cls,
539 const struct GNUNET_PEERSTORE_Record *record,
540 const char *err_msg)
541{
542 unsigned int map_size;
543 struct GNUNET_MessageHeader *hello_cpy;
544 struct GNUNET_PeerIdentity *peer_cpy;
545 struct GNUNET_MessageHeader *hello;
546
549 "Peerstore is notifying us to rebuild our hostlist map size %u\n",
550 map_size);
551 if (NULL != err_msg)
552 {
554 _ ("Error in communication with PEERSTORE service: %s\n"),
555 err_msg);
556 return;
557 }
558 hello = record->value;
559 if (NULL != builder)
560 {
562 builder->size = 0;
563 builder->data = NULL;
564 }
565 else
566 {
567 builder = GNUNET_new (struct HostSet);
568 }
569
570 peer_cpy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
571 GNUNET_memcpy (peer_cpy, &record->peer, sizeof (struct GNUNET_PeerIdentity));
572 hello_cpy = GNUNET_malloc (ntohs (hello->size));
573 GNUNET_memcpy (hello_cpy, hello, ntohs (hello->size));
576 peer_cpy,
577 (struct
579 hello_cpy,
583 NULL))
587 "1 Peerstore is notifying us to rebuild our hostlist map size %u peer %s\n",
588 map_size,
589 GNUNET_i2s (&record->peer));
591}
592
593
598static struct GNUNET_SCHEDULER_Task *
599prepare_daemon (struct MHD_Daemon *daemon_handle);
600
601
608static void
609run_daemon (void *cls)
610{
611 struct MHD_Daemon *daemon_handle = cls;
612
613 if (daemon_handle == daemon_handle_v4)
614 hostlist_task_v4 = NULL;
615 else
616 hostlist_task_v6 = NULL;
617 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
618 if (daemon_handle == daemon_handle_v4)
619 hostlist_task_v4 = prepare_daemon (daemon_handle);
620 else
621 hostlist_task_v6 = prepare_daemon (daemon_handle);
622}
623
624
631static struct GNUNET_SCHEDULER_Task *
632prepare_daemon (struct MHD_Daemon *daemon_handle)
633{
635 fd_set rs;
636 fd_set ws;
637 fd_set es;
638 struct GNUNET_NETWORK_FDSet *wrs;
639 struct GNUNET_NETWORK_FDSet *wws;
640 int max;
641 MHD_UNSIGNED_LONG_LONG timeout;
642 int haveto;
643 struct GNUNET_TIME_Relative tv;
644
645 FD_ZERO (&rs);
646 FD_ZERO (&ws);
647 FD_ZERO (&es);
650 max = -1;
651 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
652 haveto = MHD_get_timeout (daemon_handle, &timeout);
653 if (haveto == MHD_YES)
654 tv.rel_value_us = (uint64_t) timeout * 1000LL;
655 else
660 tv,
661 wrs,
662 wws,
663 &run_daemon,
664 daemon_handle);
667 return ret;
668}
669
670
671static void
672error_cb (void *cls)
673{
675 "Error in PEERSTORE monitoring\n");
676}
677
678
679static void
680sync_cb (void *cls)
681{
683 "Done with initial PEERSTORE iteration during monitoring\n");
684}
685
686
687static void
688start_notify (void *cls)
689{
690 (void) cls;
691
693 "Starting to process new hellos to add to hostlist.\n");
696 "peerstore",
697 NULL,
699 &error_cb,
700 NULL,
701 &sync_cb,
702 NULL,
703 &process_notify, NULL);
704}
705
706
717int
720 struct GNUNET_CORE_Handle *co,
722 int advertise)
723{
724 unsigned long long port;
725 char *hostname;
726 char *ipv4;
727 char *ipv6;
728 size_t size;
729 struct in_addr i4;
730 struct in6_addr i6;
731 struct sockaddr_in v4;
732 struct sockaddr_in6 v6;
733 const struct sockaddr *sa4;
734 const struct sockaddr *sa6;
735
737 advertising = advertise;
738 if (! advertising)
739 {
741 "Advertising not enabled on this hostlist server\n");
742 }
743 else
744 {
746 "Advertising enabled on this hostlist server\n");
747 }
748 cfg = c;
749 stats = st;
751 if (NULL == peerstore)
752 {
754 _ ("Could not access PEERSTORE service. Exiting.\n"));
755 return GNUNET_SYSERR;
756 }
758 "HOSTLIST",
759 "HTTPPORT",
760 &port))
761 return GNUNET_SYSERR;
762 if ((0 == port) || (port > UINT16_MAX))
763 {
765 _ ("Invalid port number %llu. Exiting.\n"),
766 port);
767 return GNUNET_SYSERR;
768 }
769
770 if (GNUNET_SYSERR ==
772 "HOSTLIST",
773 "EXTERNAL_DNS_NAME",
774 &hostname))
775 hostname = GNUNET_RESOLVER_local_fqdn_get ();
777 _ ("Hostlist service starts on %s:%llu\n"),
778 hostname,
779 port);
780 if (NULL != hostname)
781 {
782 size = strlen (hostname);
783 if (size + 15 > MAX_URL_LEN)
784 {
785 GNUNET_break (0);
786 }
787 else
788 {
790 "http://%s:%u/",
791 hostname,
792 (unsigned int) port);
794 _ ("Address to obtain hostlist: `%s'\n"),
796 }
797 GNUNET_free (hostname);
798 }
799
800 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
801 {
803 "HOSTLIST",
804 "BINDTOIP",
805 &ipv4))
806 {
807 GNUNET_log (
809 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
810 }
811 }
812 else
813 ipv4 = NULL;
814 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
815 {
817 "HOSTLIST",
818 "BINDTOIP",
819 &ipv6))
820 {
821 GNUNET_log (
823 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
824 }
825 }
826 else
827 ipv6 = NULL;
828 sa4 = NULL;
829 if (NULL != ipv4)
830 {
831 if (1 == inet_pton (AF_INET, ipv4, &i4))
832 {
833 memset (&v4, 0, sizeof(v4));
834 v4.sin_family = AF_INET;
835 v4.sin_addr = i4;
836 v4.sin_port = htons (port);
837#if HAVE_SOCKADDR_IN_SIN_LEN
838 v4.sin_len = sizeof(v4);
839#endif
840 sa4 = (const struct sockaddr *) &v4;
841 }
842 else
844 _ (
845 "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
846 ipv4);
848 }
849 sa6 = NULL;
850 if (NULL != ipv6)
851 {
852 if (1 == inet_pton (AF_INET6, ipv6, &i6))
853 {
854 memset (&v6, 0, sizeof(v6));
855 v6.sin6_family = AF_INET6;
856 v6.sin6_addr = i6;
857 v6.sin6_port = htons (port);
858#if HAVE_SOCKADDR_IN_SIN_LEN
859 v6.sin6_len = sizeof(v6);
860#endif
861 sa6 = (const struct sockaddr *) &v6;
862 }
863 else
865 _ (
866 "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
867 ipv6);
869 }
870
871 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
872 (uint16_t) port,
874 NULL,
876 NULL,
877 MHD_OPTION_CONNECTION_LIMIT,
878 (unsigned int) 128,
879 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
880 (unsigned int) 32,
881 MHD_OPTION_CONNECTION_TIMEOUT,
882 (unsigned int) 16,
883 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
884 (size_t) (16 * 1024),
885 MHD_OPTION_SOCK_ADDR,
886 sa6,
887 MHD_OPTION_END);
888 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
889 (uint16_t) port,
891 NULL,
893 NULL,
894 MHD_OPTION_CONNECTION_LIMIT,
895 (unsigned int) 128,
896 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
897 (unsigned int) 32,
898 MHD_OPTION_CONNECTION_TIMEOUT,
899 (unsigned int) 16,
900 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
901 (size_t) (16 * 1024),
902 MHD_OPTION_SOCK_ADDR,
903 sa4,
904 MHD_OPTION_END);
905
906 if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
907 {
909 _ ("Could not start hostlist HTTP server on port %u\n"),
910 (unsigned short) port);
911 return GNUNET_SYSERR;
912 }
913
914 core = co;
916 if (NULL != daemon_handle_v4)
918 if (NULL != daemon_handle_v6)
923 NULL);
924 return GNUNET_OK;
925}
926
927
931void
933{
934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
935 if (NULL != hostlist_task_v6)
936 {
938 hostlist_task_v6 = NULL;
939 }
940 if (NULL != hostlist_task_v4)
941 {
943 hostlist_task_v4 = NULL;
944 }
945 if (NULL != daemon_handle_v4)
946 {
947 MHD_stop_daemon (daemon_handle_v4);
948 daemon_handle_v4 = NULL;
949 }
950 if (NULL != daemon_handle_v6)
951 {
952 MHD_stop_daemon (daemon_handle_v6);
953 daemon_handle_v6 = NULL;
954 }
955 if (NULL != response)
956 {
957 MHD_destroy_response (response);
958 response = NULL;
959 }
960 if (NULL != response_json)
961 {
962 MHD_destroy_response (response_json);
963 response_json = NULL;
964 }
965 if (NULL != peerstore_notify)
966 {
968 peerstore_notify = NULL;
969 }
970 else if (NULL != peerstore_notify_task)
971 {
973 }
974 if (NULL != builder)
975 {
978 builder = NULL;
979 }
980 if (NULL != peerstore)
981 {
983 peerstore = NULL;
984 }
985 cfg = NULL;
986 stats = NULL;
987 core = NULL;
988}
989
990
991/* end of gnunet-daemon-hostlist_server.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define gettext_noop(String)
Definition: gettext.h:74
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static GNUNET_CORE_ConnectEventHandler server_ch
Handle to hostlist server's connect handler.
common internal definitions for hostlist daemon
#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?
static struct MHD_Daemon * daemon_handle_v6
Handle to the HTTP server as provided by libmicrohttpd for IPv6.
static struct MHD_Response * response
Our canonical response.
static void sync_cb(void *cls)
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 HostSet * builder
NULL if we are not currently iterating over peer information.
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 void add_cors_headers(struct MHD_Response *resp)
Add headers to a request indicating that we allow Cross-Origin Resource Sharing.
static struct GNUNET_PEERSTORE_Monitor * peerstore_notify
Our peerstore notification context.
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 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 MHD_Response * build_json_response(const struct HostSet *bu)
static enum GNUNET_GenericReturnValue host_processor(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Callback that processes each of the known HELLOs for the hostlist response construction.
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)
static struct MHD_Response * response_json
Our json response.
static void adv_transmit(struct GNUNET_MQ_Handle *mq)
Handler called by CORE when CORE is ready to transmit message.
struct GNUNET_SCHEDULER_Task * peerstore_notify_task
The task to delayed start the notification process initially.
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 void run_daemon(void *cls)
Call MHD to process pending requests and then go back and schedule the next run.
static int header_iterator(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
static void finish_response()
Function that assembles our response.
static void error_cb(void *cls)
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 void process_notify(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *err_msg)
PEERSTORE calls this function to let us know about a possible peer that we might want to connect to.
void GNUNET_HOSTLIST_server_stop()
Stop server offering our hostlist.
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).
struct GNUNET_HashCode key
The key used in the DHT.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * value
Value of the record to add/remove.
static int ipv4
Option -4: IPv4 requested.
Definition: gnunet-vpn.c:60
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:65
static unsigned int map_size
Command-line argument specifying desired size of the hash map with all of our pending names.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Helper library for handling HELLO URIs.
#define MHD_RESULT
API to the peerstore service.
Functions related to doing DNS lookups.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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.
void *(* GNUNET_CORE_ConnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
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).
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:388
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg into builder.
Definition: hello-uri.c:406
char * GNUNET_HELLO_builder_to_url(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Generate GNUnet HELLO URI from a builder.
Definition: hello-uri.c:703
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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:847
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:305
#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:63
@ GNUNET_MQ_PREF_CORK_ALLOWED
Flag to indicate that CORKing is acceptable.
@ GNUNET_MQ_PREF_UNRELIABLE
Flag to indicate that unreliable delivery is acceptable.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1187
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:1041
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1171
void GNUNET_PEERSTORE_monitor_stop(struct GNUNET_PEERSTORE_Monitor *zm)
Stop monitoring.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Monitor * GNUNET_PEERSTORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, int iterate_first, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Request watching a given key The monitoring can be filtered to contain only records matching peer and...
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
void GNUNET_PEERSTORE_monitor_next(struct GNUNET_PEERSTORE_Monitor *zm, uint64_t limit)
Calls the monitor processor specified in GNUNET_PEERSTORE_monitor_start for the next record(s).
#define GNUNET_PEERSTORE_HELLO_KEY
Key used for storing HELLO in the peerstore.
#define GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT
Hostlist advertisement message.
char * GNUNET_RESOLVER_local_fqdn_get(void)
Get local fully qualified domain name.
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:1834
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
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.
Definition: scheduler.c:1276
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_MINUTES
One minute.
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
#define max(x, y)
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Internal representation of the hash map.
Context for the core service connection.
Definition: core_api.c:78
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:206
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
collection of IO descriptors
Handle to the PEERSTORE service.
Definition: peerstore_api.c:44
Context for a monitor.
Single PEERSTORE record.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:135
Handle for the service.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Context for host_processor().
char * data
Place where we accumulate all of the HELLO messages.
unsigned int size
Number of bytes in data.