GNUnet 0.21.2
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
38
43#define GNUNET_ADV_TIMEOUT \
44 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
45
50
54static struct MHD_Daemon *daemon_handle_v6;
55
59static struct MHD_Daemon *daemon_handle_v4;
60
64static const struct GNUNET_CONFIGURATION_Handle *cfg;
65
70
74static struct GNUNET_CORE_Handle *core;
75
81
87
92
97
101static struct MHD_Response *response;
102
107
111static int advertising;
112
116static char *hostlist_uri;
117
118
123{
127 char *data;
128
132 unsigned int size;
133};
134
135
139static struct HostSet *builder;
140
141
148static void
149add_cors_headers (struct MHD_Response *response)
150{
151 MHD_add_response_header (response, "Access-Control-Allow-Origin", "*");
152 MHD_add_response_header (response,
153 "Access-Control-Allow-Methods",
154 "GET, OPTIONS");
155 MHD_add_response_header (response, "Access-Control-Max-Age", "86400");
156}
157
158
162static void
164{
165 if (NULL != response)
166 MHD_destroy_response (response);
168 "Creating hostlist response with %u bytes\n",
169 (unsigned int) builder->size);
170 response = MHD_create_response_from_buffer (builder->size,
171 builder->data,
172 MHD_RESPMEM_MUST_FREE);
174 if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6))
175 {
176 MHD_destroy_response (response);
177 response = NULL;
178 }
180 gettext_noop ("bytes in hostlist"),
181 builder->size,
182 GNUNET_YES);
184 builder = NULL;
185}
186
187
198host_processor (void *cls,
199 const struct GNUNET_PeerIdentity *peer,
200 void *value)
201{
202 (void) cls;
203 size_t old;
204 size_t s;
205 struct GNUNET_MessageHeader *hello = value;
206
208 "host_processor\n");
209 old = builder->size;
210 s = ntohs (hello->size);
212 "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
213 (unsigned int) s,
214 "HELLO",
215 GNUNET_i2s (peer));
216 if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
217 (old + s >= MAX_BYTES_PER_HOSTLISTS))
218 {
219 /* too large, skip! */
222 "bytes not included in hostlist (size limit)"),
223 s,
224 GNUNET_NO);
225 return GNUNET_YES;
226 }
228 "Adding peer `%s' to hostlist (%u bytes)\n",
229 GNUNET_i2s (peer),
230 (unsigned int) s);
232 GNUNET_memcpy (&builder->data[old], hello, s);
233
234 return GNUNET_YES;
235}
236
237
247static MHD_RESULT
249 const struct sockaddr *addr,
250 socklen_t addrlen)
251{
252 if (NULL == response)
253 {
254 GNUNET_log (
256 "Received request for hostlist, but I am not yet ready; rejecting!\n");
257 return MHD_NO;
258 }
259 return MHD_YES; /* accept all */
260}
261
262
298static MHD_RESULT
300 struct MHD_Connection *connection,
301 const char *url,
302 const char *method,
303 const char *version,
304 const char *upload_data,
305 size_t *upload_data_size,
306 void **con_cls)
307{
308 static int dummy;
309
310 /* CORS pre-flight request */
311 if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
312 {
313 struct MHD_Response *options_response;
314 int rc;
315
316 options_response =
317 MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT);
318 add_cors_headers (options_response);
319 rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
320 MHD_destroy_response (options_response);
321 return rc;
322 }
323 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
324 {
326 _ ("Refusing `%s' request to hostlist server\n"),
327 method);
330 "hostlist requests refused (not HTTP GET)"),
331 1,
332 GNUNET_YES);
333 return MHD_NO;
334 }
335 if (NULL == *con_cls)
336 {
337 (*con_cls) = &dummy;
338 return MHD_YES;
339 }
340 if (0 != *upload_data_size)
341 {
343 _ ("Refusing `%s' request with %llu bytes of upload data\n"),
344 method,
345 (unsigned long long) *upload_data_size);
348 "hostlist requests refused (upload data)"),
349 1,
350 GNUNET_YES);
351 return MHD_NO; /* do not support upload data */
352 }
353 if (NULL == response)
354 {
355 GNUNET_log (
357 _ (
358 "Could not handle hostlist request since I do not have a response yet\n"));
361 "hostlist requests refused (not ready)"),
362 1,
363 GNUNET_YES);
364 return MHD_NO; /* internal error, no response yet */
365 }
367 _ ("Received request for our hostlist\n"));
369 gettext_noop ("hostlist requests processed"),
370 1,
371 GNUNET_YES);
372 return MHD_queue_response (connection, MHD_HTTP_OK, response);
373}
374
375
385static void
387{
388 static uint64_t hostlist_adv_count;
389 size_t uri_size; /* Including \0 termination! */
390 struct GNUNET_MessageHeader *header;
391 struct GNUNET_MQ_Envelope *env;
392
393 uri_size = strlen (hostlist_uri) + 1;
394 env = GNUNET_MQ_msg_extra (header,
395 uri_size,
397 GNUNET_memcpy (&header[1], hostlist_uri, uri_size);
403 "Sent advertisement message: Copied %u bytes into buffer!\n",
404 (unsigned int) uri_size);
405 hostlist_adv_count++;
407 " # Sent advertisement message: %llu\n",
408 (unsigned long long) hostlist_adv_count);
410 gettext_noop ("# hostlist advertisements send"),
411 1,
412 GNUNET_NO);
413}
414
415
424static void *
426 const struct GNUNET_PeerIdentity *peer,
427 struct GNUNET_MQ_Handle *mq)
428{
429 size_t size;
430
431 if (! advertising)
432 return NULL;
433 if (NULL == hostlist_uri)
434 return NULL;
435 size = strlen (hostlist_uri) + 1;
436 if (size + sizeof(struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE)
437 {
438 GNUNET_break (0);
439 return NULL;
440 }
441 size += sizeof(struct GNUNET_MessageHeader);
442 if (NULL == core)
443 {
444 GNUNET_break (0);
445 return NULL;
446 }
447 GNUNET_log (
449 "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n",
450 (unsigned int) size,
451 GNUNET_i2s (peer));
453 return NULL;
454}
455
456
466static void
467process_notify (void *cls,
468 const struct GNUNET_PEERSTORE_Record *record,
469 const char *err_msg)
470{
471 unsigned int map_size;
472 struct GNUNET_MessageHeader *hello_cpy;
473 struct GNUNET_PeerIdentity *peer_cpy;
474 struct GNUNET_MessageHeader *hello;
475
478 "Peerstore is notifying us to rebuild our hostlist map size %u\n",
479 map_size);
480 if (NULL != err_msg)
481 {
483 _ ("Error in communication with PEERSTORE service: %s\n"),
484 err_msg);
485 return;
486 }
487 hello = record->value;
488 if (NULL != builder)
489 {
491 builder->size = 0;
492 builder->data = NULL;
493 }
494 else
495 {
496 builder = GNUNET_new (struct HostSet);
497 }
498
499 peer_cpy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
500 GNUNET_memcpy (peer_cpy, &record->peer, sizeof (struct GNUNET_PeerIdentity));
501 hello_cpy = GNUNET_malloc (ntohs (hello->size));
502 GNUNET_memcpy (hello_cpy, hello, ntohs (hello->size));
505 peer_cpy,
506 (struct
508 hello_cpy,
512 NULL))
516 "1 Peerstore is notifying us to rebuild our hostlist map size %u peer %s\n",
517 map_size,
518 GNUNET_i2s (&record->peer));
520}
521
522
527static struct GNUNET_SCHEDULER_Task *
528prepare_daemon (struct MHD_Daemon *daemon_handle);
529
530
537static void
538run_daemon (void *cls)
539{
540 struct MHD_Daemon *daemon_handle = cls;
541
542 if (daemon_handle == daemon_handle_v4)
543 hostlist_task_v4 = NULL;
544 else
545 hostlist_task_v6 = NULL;
546 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
547 if (daemon_handle == daemon_handle_v4)
548 hostlist_task_v4 = prepare_daemon (daemon_handle);
549 else
550 hostlist_task_v6 = prepare_daemon (daemon_handle);
551}
552
553
560static struct GNUNET_SCHEDULER_Task *
561prepare_daemon (struct MHD_Daemon *daemon_handle)
562{
564 fd_set rs;
565 fd_set ws;
566 fd_set es;
567 struct GNUNET_NETWORK_FDSet *wrs;
568 struct GNUNET_NETWORK_FDSet *wws;
569 int max;
570 MHD_UNSIGNED_LONG_LONG timeout;
571 int haveto;
572 struct GNUNET_TIME_Relative tv;
573
574 FD_ZERO (&rs);
575 FD_ZERO (&ws);
576 FD_ZERO (&es);
579 max = -1;
580 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
581 haveto = MHD_get_timeout (daemon_handle, &timeout);
582 if (haveto == MHD_YES)
583 tv.rel_value_us = (uint64_t) timeout * 1000LL;
584 else
589 tv,
590 wrs,
591 wws,
592 &run_daemon,
593 daemon_handle);
596 return ret;
597}
598
599
600static void
601error_cb (void *cls)
602{
604 "Error in PEERSTORE monitoring\n");
605}
606
607
608static void
609sync_cb (void *cls)
610{
612 "Done with initial PEERSTORE iteration during monitoring\n");
613}
614
615
616static void
617start_notify (void *cls)
618{
619 (void) cls;
620
622 "Starting to process new hellos to add to hostlist.\n");
625 "peerstore",
626 NULL,
628 &error_cb,
629 NULL,
630 &sync_cb,
631 NULL,
632 &process_notify, NULL);
633}
634
635
646int
649 struct GNUNET_CORE_Handle *co,
651 int advertise)
652{
653 unsigned long long port;
654 char *hostname;
655 char *ipv4;
656 char *ipv6;
657 size_t size;
658 struct in_addr i4;
659 struct in6_addr i6;
660 struct sockaddr_in v4;
661 struct sockaddr_in6 v6;
662 const struct sockaddr *sa4;
663 const struct sockaddr *sa6;
664
666 advertising = advertise;
667 if (! advertising)
668 {
670 "Advertising not enabled on this hostlist server\n");
671 }
672 else
673 {
675 "Advertising enabled on this hostlist server\n");
676 }
677 cfg = c;
678 stats = st;
680 if (NULL == peerstore)
681 {
683 _ ("Could not access PEERSTORE service. Exiting.\n"));
684 return GNUNET_SYSERR;
685 }
687 "HOSTLIST",
688 "HTTPPORT",
689 &port))
690 return GNUNET_SYSERR;
691 if ((0 == port) || (port > UINT16_MAX))
692 {
694 _ ("Invalid port number %llu. Exiting.\n"),
695 port);
696 return GNUNET_SYSERR;
697 }
698
699 if (GNUNET_SYSERR ==
701 "HOSTLIST",
702 "EXTERNAL_DNS_NAME",
703 &hostname))
704 hostname = GNUNET_RESOLVER_local_fqdn_get ();
706 _ ("Hostlist service starts on %s:%llu\n"),
707 hostname,
708 port);
709 if (NULL != hostname)
710 {
711 size = strlen (hostname);
712 if (size + 15 > MAX_URL_LEN)
713 {
714 GNUNET_break (0);
715 }
716 else
717 {
719 "http://%s:%u/",
720 hostname,
721 (unsigned int) port);
723 _ ("Address to obtain hostlist: `%s'\n"),
725 }
726 GNUNET_free (hostname);
727 }
728
729 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
730 {
732 "HOSTLIST",
733 "BINDTOIP",
734 &ipv4))
735 {
736 GNUNET_log (
738 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
739 }
740 }
741 else
742 ipv4 = NULL;
743 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
744 {
746 "HOSTLIST",
747 "BINDTOIP",
748 &ipv6))
749 {
750 GNUNET_log (
752 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
753 }
754 }
755 else
756 ipv6 = NULL;
757 sa4 = NULL;
758 if (NULL != ipv4)
759 {
760 if (1 == inet_pton (AF_INET, ipv4, &i4))
761 {
762 memset (&v4, 0, sizeof(v4));
763 v4.sin_family = AF_INET;
764 v4.sin_addr = i4;
765 v4.sin_port = htons (port);
766#if HAVE_SOCKADDR_IN_SIN_LEN
767 v4.sin_len = sizeof(v4);
768#endif
769 sa4 = (const struct sockaddr *) &v4;
770 }
771 else
773 _ (
774 "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
775 ipv4);
777 }
778 sa6 = NULL;
779 if (NULL != ipv6)
780 {
781 if (1 == inet_pton (AF_INET6, ipv6, &i6))
782 {
783 memset (&v6, 0, sizeof(v6));
784 v6.sin6_family = AF_INET6;
785 v6.sin6_addr = i6;
786 v6.sin6_port = htons (port);
787#if HAVE_SOCKADDR_IN_SIN_LEN
788 v6.sin6_len = sizeof(v6);
789#endif
790 sa6 = (const struct sockaddr *) &v6;
791 }
792 else
794 _ (
795 "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
796 ipv6);
798 }
799
800 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
801 (uint16_t) port,
803 NULL,
805 NULL,
806 MHD_OPTION_CONNECTION_LIMIT,
807 (unsigned int) 128,
808 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
809 (unsigned int) 32,
810 MHD_OPTION_CONNECTION_TIMEOUT,
811 (unsigned int) 16,
812 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
813 (size_t) (16 * 1024),
814 MHD_OPTION_SOCK_ADDR,
815 sa6,
816 MHD_OPTION_END);
817 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
818 (uint16_t) port,
820 NULL,
822 NULL,
823 MHD_OPTION_CONNECTION_LIMIT,
824 (unsigned int) 128,
825 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
826 (unsigned int) 32,
827 MHD_OPTION_CONNECTION_TIMEOUT,
828 (unsigned int) 16,
829 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
830 (size_t) (16 * 1024),
831 MHD_OPTION_SOCK_ADDR,
832 sa4,
833 MHD_OPTION_END);
834
835 if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
836 {
838 _ ("Could not start hostlist HTTP server on port %u\n"),
839 (unsigned short) port);
840 return GNUNET_SYSERR;
841 }
842
843 core = co;
845 if (NULL != daemon_handle_v4)
847 if (NULL != daemon_handle_v6)
852 NULL);
853 return GNUNET_OK;
854}
855
856
860void
862{
863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
864 if (NULL != hostlist_task_v6)
865 {
867 hostlist_task_v6 = NULL;
868 }
869 if (NULL != hostlist_task_v4)
870 {
872 hostlist_task_v4 = NULL;
873 }
874 if (NULL != daemon_handle_v4)
875 {
876 MHD_stop_daemon (daemon_handle_v4);
877 daemon_handle_v4 = NULL;
878 }
879 if (NULL != daemon_handle_v6)
880 {
881 MHD_stop_daemon (daemon_handle_v6);
882 daemon_handle_v6 = NULL;
883 }
884 if (NULL != response)
885 {
886 MHD_destroy_response (response);
887 response = NULL;
888 }
889 if (NULL != peerstore_notify)
890 {
892 peerstore_notify = NULL;
893 }
894 else if (NULL != peerstore_notify_task)
895 {
897 }
898 if (NULL != builder)
899 {
902 builder = NULL;
903 }
904 if (NULL != peerstore)
905 {
907 peerstore = NULL;
908 }
909 cfg = NULL;
910 stats = NULL;
911 core = NULL;
912}
913
914
915/* 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:94
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
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 *response)
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 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 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 intially.
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 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).
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.
#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:830
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:304
#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:1186
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:1040
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1170
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:1836
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
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:1278
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
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:136
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.