GNUnet 0.27.0
 
Loading...
Searching...
No Matches
gnunet-communicator-unix.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2014, 2018, 2026 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
29#include "gnunet_common.h"
30#include "platform.h"
31#include "gnunet_util_lib.h"
32#include "gnunet_constants.h"
33#include "gnunet_pils_service.h"
36
45#define DEFAULT_MAX_QUEUE_LENGTH 8000
46
50#define COMMUNICATOR_ADDRESS_PREFIX "unix"
51
55#define COMMUNICATOR_CONFIG_SECTION "communicator-unix"
56
60#ifndef DARWIN
61#define UNIX_MTU UINT16_MAX
62#else
63#define UNIX_MTU 2048
64#endif
65
67
83
85
86
90struct Queue
91{
95 struct Queue *next;
96
100 struct Queue *prev;
101
106
110 struct sockaddr_un *address;
111
115 socklen_t address_len;
116
122
126 struct GNUNET_MQ_Handle *mq;
127
132
136 unsigned long long bytes_in_queue;
137
142
147};
148
153
158
163
167static unsigned long long delivering_messages;
168
172static unsigned long long max_queue_length;
173
178
183
188
192static struct Queue *queue_head;
193
197static struct Queue *queue_tail;
198
203
208
209
217static void
219{
220 struct GNUNET_MQ_Handle *mq;
221
223 "Disconnecting queue for peer `%s'\n",
224 GNUNET_i2s (&queue->target));
225 if (0 != queue->bytes_in_queue)
226 {
228 queue->bytes_in_queue = 0;
229 }
230 if (NULL != (mq = queue->mq))
231 {
232 queue->mq = NULL;
234 }
236 GNUNET_YES ==
239 "# queues active",
241 GNUNET_NO);
242 if (NULL != queue->timeout_task)
243 {
244 GNUNET_SCHEDULER_cancel (queue->timeout_task);
245 queue->timeout_task = NULL;
246 }
247 GNUNET_free (queue->address);
249}
250
251
257static void
258queue_timeout (void *cls)
259{
260 struct Queue *queue = cls;
261 struct GNUNET_TIME_Relative left;
262
263 queue->timeout_task = NULL;
265 if (0 != left.rel_value_us)
266 {
267 /* not actually our turn yet, but let's at least update
268 the monitor, it may think we're about to die ... */
269 queue->timeout_task =
271 return;
272 }
274 "Queue %p was idle for %s, disconnecting\n",
275 queue,
278 GNUNET_YES));
280}
281
282
290static void
297
298
307static struct sockaddr_un *
308unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
309{
310 struct sockaddr_un *un;
311 size_t slen;
312
313 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
314 un = GNUNET_new (struct sockaddr_un);
315 un->sun_family = AF_UNIX;
316 slen = strlen (unixpath);
317 if (slen >= sizeof(un->sun_path))
318 slen = sizeof(un->sun_path) - 1;
319 GNUNET_memcpy (un->sun_path, unixpath, slen);
320 un->sun_path[slen] = '\0';
321 slen = sizeof(struct sockaddr_un);
322#if HAVE_SOCKADDR_UN_SUN_LEN
323 un->sun_len = (u_char) slen;
324#endif
325 (*sock_len) = slen;
326 if ('@' == un->sun_path[0])
327 un->sun_path[0] = '\0';
328 return un;
329}
330
331
336{
340 struct Queue *res;
341
345 const struct sockaddr_un *un;
346
350 socklen_t un_len;
351};
352
353
362static int
363lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
364{
365 struct LookupCtx *lctx = cls;
366 struct Queue *queue = value;
367
368 if ((queue->address_len == lctx->un_len) &&
369 (0 == memcmp (lctx->un, queue->address, queue->address_len)))
370 {
371 lctx->res = queue;
372 return GNUNET_NO;
373 }
374 return GNUNET_YES;
375}
376
377
385static struct Queue *
387 const struct sockaddr_un *un,
388 socklen_t un_len)
389{
390 struct LookupCtx lctx;
391
392 lctx.un = un;
393 lctx.un_len = un_len;
394 lctx.res = NULL;
396 peer,
398 &lctx);
399 return lctx.res;
400}
401
402
409static void
411{
412 struct Queue *queue = queue_tail;
413 const struct GNUNET_MessageHeader *msg = &queue->msg->header;
414 size_t msg_size = ntohs (msg->size);
415 ssize_t sent;
416
417 /* take queue of the ready list */
418 write_task = NULL;
419resend:
420 /* Send the data */
422 msg,
423 msg_size,
424 (const struct sockaddr *) queue->address,
425 queue->address_len);
427 "UNIX transmitted message to %s (%d/%u: %s)\n",
428 GNUNET_i2s (&queue->target),
429 (int) sent,
430 (unsigned int) msg_size,
431 (sent < 0) ? strerror (errno) : "ok");
432 if (-1 != sent)
433 {
435 if (NULL != queue_head)
437 unix_sock,
439 NULL);
440
441 /* send 'msg' */
442 GNUNET_free (queue->msg);
443 queue->msg = NULL;
446 "# bytes sent",
447 (long long) sent,
448 GNUNET_NO);
450 return; /* all good */
451 }
453 "# network transmission failures",
454 1,
455 GNUNET_NO);
457 unix_sock,
459 NULL);
460 switch (errno)
461 {
462 case EAGAIN:
463 case ENOBUFS:
464 /* We should retry later... */
466 return;
467
468 case EMSGSIZE: {
469 socklen_t size = 0;
470 socklen_t len = sizeof(size);
471
473 SOL_SOCKET,
474 SO_SNDBUF,
475 &size,
476 &len);
477 if (size > ntohs (msg->size))
478 {
479 /* Buffer is bigger than message: error, no retry
480 * This should never happen!*/
481 GNUNET_break (0);
482 return;
483 }
484 GNUNET_log (
486 "Trying to increase socket buffer size from %u to %u for message size %u\n",
487 (unsigned int) size,
488 (unsigned int) ((msg_size / 1000) + 2) * 1000,
489 (unsigned int) msg_size);
490 size = ((msg_size / 1000) + 2) * 1000;
492 SOL_SOCKET,
493 SO_SNDBUF,
494 &size,
495 sizeof(size)))
496 goto resend; /* Increased buffer size, retry sending */
497 /* Ok, then just try very modest increase */
498 size = msg_size;
500 SOL_SOCKET,
501 SO_SNDBUF,
502 &size,
503 sizeof(size)))
504 goto resend; /* Increased buffer size, retry sending */
505 /* Could not increase buffer size: error, no retry */
507 return;
508 }
509
510 default:
512 return;
513 }
514}
515
516
525static void
527 const struct GNUNET_MessageHeader *msg,
528 void *impl_state)
529{
530 const struct GNUNET_PeerIdentity *my_identity;
531 struct Queue *queue = impl_state;
532 size_t msize = ntohs (msg->size);
533
536
537 GNUNET_assert (mq == queue->mq);
538 GNUNET_assert (NULL == queue->msg);
539 // Convert to UNIXMessage
540 queue->msg = GNUNET_malloc (msize + sizeof (struct UNIXMessage));
541 queue->msg->header.size = htons (msize + sizeof (struct UNIXMessage));
542 queue->msg->sender = *my_identity;
543 memcpy (&queue->msg[1], msg, msize);
545 GNUNET_assert (NULL != unix_sock);
546 if (NULL == write_task)
548 unix_sock,
550 NULL);
551}
552
553
562static void
563mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
564{
565 struct Queue *queue = impl_state;
566
567 if (mq == queue->mq)
568 {
569 queue->mq = NULL;
571 }
572}
573
574
581static void
582mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
583{
584 struct Queue *queue = impl_state;
585
586 GNUNET_assert (NULL != queue->msg);
587 queue->msg = NULL;
589 GNUNET_assert (NULL != write_task);
590 if (NULL == queue_head)
591 {
593 write_task = NULL;
594 }
595}
596
597
607static void
608mq_error (void *cls, enum GNUNET_MQ_Error error)
609{
610 struct Queue *queue = cls;
611
613 "UNIX MQ error in queue to %s: %d\n",
614 GNUNET_i2s (&queue->target),
615 (int) error);
617}
618
619
630static struct Queue *
633 const struct sockaddr_un *un,
634 socklen_t un_len)
635{
636 struct Queue *queue;
637
638 queue = GNUNET_new (struct Queue);
639 queue->target = *target;
640 queue->address = GNUNET_memdup (un, un_len);
641 queue->address_len = un_len;
643 queue_map,
644 &queue->target,
645 queue,
648 "# queues active",
650 GNUNET_NO);
651 queue->timeout =
653 queue->timeout_task =
656 queue);
658 &mq_destroy,
659 &mq_cancel,
660 queue,
661 NULL,
662 &mq_error,
663 queue);
664 {
665 char *foreign_addr;
666
667 if ('\0' == un->sun_path[0])
668 GNUNET_asprintf (&foreign_addr,
669 "%s-@%s",
671 &un->sun_path[1]);
672 else
673 GNUNET_asprintf (&foreign_addr,
674 "%s-%s",
676 un->sun_path);
678 &queue->target,
679 foreign_addr,
680 UNIX_MTU - sizeof (struct
683 0,
685 cs,
686 queue->mq);
687 GNUNET_free (foreign_addr);
688 }
689 return queue;
690}
691
692
700static void
701select_read_cb (void *cls);
702
703
711static void
712receive_complete_cb (void *cls, int success)
713{
714 (void) cls;
716 if (GNUNET_OK != success)
718 "# transport transmission failures",
719 1,
720 GNUNET_NO);
721 if ((NULL == read_task) && (delivering_messages < max_queue_length) &&
722 (NULL != unix_sock))
724 unix_sock,
726 NULL);
727}
728
729
737static void
738select_read_cb (void *cls)
739{
740 char buf[65536] GNUNET_ALIGN;
741 struct Queue *queue;
742 const struct UNIXMessage *msg;
743 struct sockaddr_un un;
744 socklen_t addrlen;
745 ssize_t ret;
746 uint16_t msize;
747
748 GNUNET_assert (NULL != unix_sock);
750 unix_sock,
752 NULL);
753 addrlen = sizeof(un);
754 memset (&un, 0, sizeof(un));
756 buf,
757 sizeof(buf),
758 (struct sockaddr *) &un,
759 &addrlen);
760 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno)))
761 return;
762 if (-1 == ret)
763 {
765 return;
766 }
768 "Read %d bytes from socket %s\n",
769 (int) ret,
770 un.sun_path);
771 GNUNET_assert (AF_UNIX == (un.sun_family));
772 msg = (struct UNIXMessage *) buf;
773 msize = ntohs (msg->header.size);
774 if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
775 {
777 "Wrong message size: %d bytes\n",
778 msize);
779 GNUNET_break_op (0);
780 return;
781 }
782 queue = lookup_queue (&msg->sender, &un, addrlen);
783 if (NULL == queue)
784 queue =
785 setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
786 else
788 if (NULL == queue)
789 {
790 GNUNET_log (
792 _ (
793 "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
794 return;
795 }
796
797 {
798 uint16_t tsize = msize - sizeof(struct UNIXMessage);
799
800 const struct GNUNET_MessageHeader *currhdr;
801 struct GNUNET_MessageHeader al_hdr;
802
803 currhdr = (const struct GNUNET_MessageHeader *) &msg[1];
804 /* ensure aligned access */
805 memcpy (&al_hdr, currhdr, sizeof(al_hdr));
806 if ((tsize < sizeof(struct GNUNET_MessageHeader)) ||
807 (tsize != ntohs (al_hdr.size)))
808 {
809 GNUNET_break_op (0);
810 return;
811 }
813 &msg->sender,
814 currhdr,
817 NULL);
818 if (GNUNET_SYSERR == ret)
819 {
821 "Transport not up!\n");
822 return; /* transport not up */
823 }
824 if (GNUNET_NO == ret)
825 {
827 "Error sending message to transport\n");
828 return;
829 }
831 }
833 {
835 "Back pressure %llu\n", delivering_messages);
836
837 /* we should try to apply 'back pressure' */
839 read_task = NULL;
840 }
841}
842
843
861static int
862mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
863{
864 struct Queue *queue;
865 const char *path;
866 struct sockaddr_un *un;
867 socklen_t un_len;
868
869 (void) cls;
870 if (0 != strncmp (address,
872 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
873 {
874 GNUNET_break_op (0);
875 return GNUNET_SYSERR;
876 }
877 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
878 un = unix_address_to_sockaddr (path, &un_len);
879 queue = lookup_queue (peer, un, un_len);
880 if (NULL != queue)
881 {
883 "Address `%s' for %s ignored, queue exists\n",
884 path,
885 GNUNET_i2s (peer));
886 GNUNET_free (un);
887 return GNUNET_OK;
888 }
889 queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len);
890 GNUNET_free (un);
891 if (NULL == queue)
892 {
894 "Failed to setup queue to %s at `%s'\n",
895 GNUNET_i2s (peer),
896 path);
897 return GNUNET_NO;
898 }
899 return GNUNET_OK;
900}
901
902
911static int
913 const struct GNUNET_PeerIdentity *target,
914 void *value)
915{
916 struct Queue *queue = value;
917
918 (void) cls;
919 (void) target;
921 return GNUNET_OK;
922}
923
924
930static void
931do_shutdown (void *cls)
932{
933 if (NULL != read_task)
934 {
936 read_task = NULL;
937 }
938 if (NULL != write_task)
939 {
941 write_task = NULL;
942 }
943 if (NULL != unix_sock)
944 {
946 unix_sock = NULL;
947 }
950 if (NULL != ai)
951 {
953 ai = NULL;
954 }
955 if (NULL != ch)
956 {
958 ch = NULL;
959 }
960 if (NULL != pils)
961 {
963 pils = NULL;
964 }
965 if (NULL != stats)
966 {
968 stats = NULL;
969 }
970}
971
972
984static void
985enc_notify_cb (void *cls,
986 const struct GNUNET_PeerIdentity *sender,
987 const struct GNUNET_MessageHeader *msg)
988{
989 (void) cls;
990 (void) sender;
991 (void) msg;
992 GNUNET_break_op (0);
993}
994
995
1004static void
1005run (void *cls,
1006 char *const *args,
1007 const char *cfgfile,
1008 const struct GNUNET_CONFIGURATION_Handle *cfg)
1009{
1010 char *unix_socket_path;
1011 struct sockaddr_un *un;
1012 socklen_t un_len;
1013 char *my_addr;
1014
1015 (void) cls;
1017
1018 pils = GNUNET_PILS_connect (cfg, NULL, NULL);
1019
1020 if (NULL == pils)
1021 {
1022 GNUNET_log (
1024 _ (
1025 "UNIX communicator is lacking PILS connection. Exiting.\n"));
1027 return;
1028 }
1029
1030 if (GNUNET_OK !=
1033 "UNIXPATH",
1034 &unix_socket_path))
1035 {
1038 "UNIXPATH");
1039 return;
1040 }
1041 if (GNUNET_OK !=
1044 "MAX_QUEUE_LENGTH",
1047
1048 un = unix_address_to_sockaddr (unix_socket_path, &un_len);
1049 if (NULL == un)
1050 {
1052 "Failed to setup UNIX domain socket address with path `%s'\n",
1053 unix_socket_path);
1054 GNUNET_free (unix_socket_path);
1055 return;
1056 }
1057 unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1058 if (NULL == unix_sock)
1059 {
1061 GNUNET_free (un);
1062 GNUNET_free (unix_socket_path);
1063 return;
1064 }
1065 if (('\0' != un->sun_path[0]) &&
1067 {
1069 _ ("Cannot create path to `%s'\n"),
1070 un->sun_path);
1072 unix_sock = NULL;
1073 GNUNET_free (un);
1074 GNUNET_free (unix_socket_path);
1075 return;
1076 }
1078 (const struct sockaddr *) un,
1079 un_len))
1080 {
1081 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
1083 unix_sock = NULL;
1084 GNUNET_free (un);
1085 GNUNET_free (unix_socket_path);
1086 return;
1087 }
1088 GNUNET_free (un);
1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
1090 stats = GNUNET_STATISTICS_create ("C-UNIX", cfg);
1093 unix_sock,
1095 NULL);
1101 &mq_init,
1102 NULL,
1104 NULL,
1105 NULL);
1106 if (NULL == ch)
1107 {
1108 GNUNET_break (0);
1110 GNUNET_free (unix_socket_path);
1111 return;
1112 }
1113 GNUNET_asprintf (&my_addr,
1114 "%s-%s",
1116 unix_socket_path);
1117 GNUNET_free (unix_socket_path);
1119 my_addr,
1122 GNUNET_free (my_addr);
1123}
1124
1125
1133int
1134main (int argc, char *const *argv)
1135{
1136 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1138 };
1139 int ret;
1140
1141 ret = (GNUNET_OK ==
1143 argc,
1144 argv,
1145 "gnunet-communicator-unix",
1146 _ ("GNUnet UNIX domain socket communicator"),
1147 options,
1148 &run,
1149 NULL))
1150 ? 0
1151 : 1;
1152 return ret;
1153}
1154
1155
1156#if defined(__linux__) && defined(__GLIBC__)
1157#include <malloc.h>
1158
1159void __attribute__ ((constructor))
1160GNUNET_TRANSPORT_communicator_unix_memory_init (void);
1161
1165void __attribute__ ((constructor))
1166GNUNET_TRANSPORT_communicator_unix_memory_init (void)
1167{
1168 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1169 mallopt (M_TOP_PAD, 1 * 1024);
1170 malloc_trim (0);
1171}
1172
1173
1174#endif
1175
1176/* end of gnunet-communicator-unix.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
struct GNUNET_MessageHeader * msg
Definition 005.c:2
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
#define UNIX_MTU
Our MTU.
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
static int get_queue_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all message queues to clean up.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static void queue_timeout(void *cls)
Queue was idle for too long, so disconnect it.
static struct GNUNET_SCHEDULER_Task * write_task
ID of write task.
static struct Queue * queue_tail
Tail of queue of messages to transmit.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void queue_destroy(struct Queue *queue)
Functions with this signature are called whenever we need to close a queue due to a disconnect or fai...
static void receive_complete_cb(void *cls, int success)
Function called when message was successfully passed to transport service.
static void enc_notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received an acknowledgement for this communicator (!...
static struct sockaddr_un * unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
Convert unix path to a struct sockaddr_un *
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
static struct GNUNET_NETWORK_Handle * unix_sock
socket that we transmit all data with
static struct GNUNET_SCHEDULER_Task * read_task
ID of read task.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static int mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
Function called by the transport service to initialize a message queue given address information abou...
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Setup communicator and launch network interactions.
static void select_write_cb(void *cls)
We have been notified that our socket is ready to write.
static struct Queue * lookup_queue(const struct GNUNET_PeerIdentity *peer, const struct sockaddr_un *un, socklen_t un_len)
Find an existing queue by address.
static unsigned long long delivering_messages
Number of messages we currently have in our queues towards the transport service.
static void select_read_cb(void *cls)
We have been notified that our socket has something to read.
static struct Queue * queue_head
Head of queue of messages to transmit.
static struct Queue * setup_queue(const struct GNUNET_PeerIdentity *target, enum GNUNET_TRANSPORT_ConnectionStatus cs, const struct sockaddr_un *un, socklen_t un_len)
Creates a new outbound queue the transport service will use to send data to another peer.
static int lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Function called to find a queue by address.
#define DEFAULT_MAX_QUEUE_LENGTH
How many messages do we keep at most in the queue to the transport service before we start to drop (d...
static void mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static void mq_send(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue.
static struct GNUNET_PILS_Handle * pils
PILS handle.
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static void queue(const char *label, uint32_t rd_count, struct GNUNET_GNSRECORD_Data *rd, const struct Zone *zone)
Add hostname to the list of requests to be made.
static char * value
Value of the record to add/remove.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:465
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:488
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
struct GNUNET_PQ_ResultSpec __attribute__
API to create, modify and access statistics.
API of the transport service towards the communicator processes.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls, GNUNET_TRANSPORT_StartBurstNotify sb)
Connect to the transport service.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
@ GNUNET_TRANSPORT_CC_RELIABLE
Transmission is reliabile (with ACKs), e.g.
@ GNUNET_TRANSPORT_CS_INBOUND
this is an inbound connection (communicator initiated)
@ GNUNET_TRANSPORT_CS_OUTBOUND
this is an outbound connection (transport initiated)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
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.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
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).
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_log(kind,...)
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ 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_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.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition mq.c:482
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition mq.c:437
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition mq.c:700
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname, void *optval, socklen_t *optlen)
Get socket options.
Definition network.c:626
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition network.c:508
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
Definition network.c:687
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition network.c:832
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition network.c:439
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition network.c:805
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition network.c:771
@ GNUNET_NT_LOOPBACK
Loopback (same host).
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition scheduler.c:1517
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition scheduler.c:1588
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1345
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
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:1283
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
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.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition strings.c:604
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
static unsigned int size
Size of the "table".
Definition peer.c:68
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Internal representation of the hash map.
Definition of a command line option.
Handle to a message queue.
Definition mq.c:87
Header for all communications.
handle to a socket
Definition network.c:53
A handle for the PILS service.
Definition pils_api.c:82
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition scheduler.c:141
Handle for the service.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Internal representation of an address a communicator is currently providing for the transport service...
Opaque handle to the transport service for communicators.
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.
Handle returned to identify the internal data structure the transport API has created to manage a mes...
Closure to lookup_queue_it().
socklen_t un_len
Number of bytes in un.
const struct sockaddr_un * un
Address we are looking for.
struct Queue * res
Location to store the queue, if found.
Handle for a queue.
struct UNIXMessage * msg
Message currently scheduled for transmission, non-NULL if and only if this queue is in the queue_head...
struct GNUNET_TRANSPORT_QueueHandle * qh
handle for this queue with the ch.
socklen_t address_len
Length of the address.
struct GNUNET_MQ_Handle * mq
Message queue we are providing for the ch.
unsigned long long bytes_in_queue
Number of bytes we currently have in our write queue.
struct sockaddr_un * address
Address of the other peer.
struct GNUNET_SCHEDULER_Task * timeout_task
Queue timeout task.
struct GNUNET_TIME_Absolute timeout
Timeout for this queue.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct Queue * next
Queues with pending messages (!) are kept in a DLL.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.
struct Queue * prev
Queues with pending messages (!) are kept in a DLL.
UNIX Message-Packet header.
struct GNUNET_MessageHeader header
Message header.
struct GNUNET_PeerIdentity sender
What is the identity of the sender (GNUNET_hash of public key)