GNUnet debian-0.24.3-29-g453fda2cf
 
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 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 "platform.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_constants.h"
34
43#define DEFAULT_MAX_QUEUE_LENGTH 8000
44
48#define COMMUNICATOR_ADDRESS_PREFIX "unix"
49
53#define COMMUNICATOR_CONFIG_SECTION "communicator-unix"
54
58#ifndef DARWIN
59#define UNIX_MTU UINT16_MAX
60#else
61#define UNIX_MTU 2048
62#endif
63
65
81
83
84
88struct Queue
89{
93 struct Queue *next;
94
98 struct Queue *prev;
99
104
108 struct sockaddr_un *address;
109
113 socklen_t address_len;
114
120
124 struct GNUNET_MQ_Handle *mq;
125
130
134 unsigned long long bytes_in_queue;
135
140
145};
146
151
156
161
165static unsigned long long delivering_messages;
166
170static unsigned long long max_queue_length;
171
176
181
186
190static struct Queue *queue_head;
191
195static struct Queue *queue_tail;
196
201
206
207
215static void
217{
218 struct GNUNET_MQ_Handle *mq;
219
221 "Disconnecting queue for peer `%s'\n",
222 GNUNET_i2s (&queue->target));
223 if (0 != queue->bytes_in_queue)
224 {
226 queue->bytes_in_queue = 0;
227 }
228 if (NULL != (mq = queue->mq))
229 {
230 queue->mq = NULL;
232 }
234 GNUNET_YES ==
237 "# queues active",
239 GNUNET_NO);
240 if (NULL != queue->timeout_task)
241 {
242 GNUNET_SCHEDULER_cancel (queue->timeout_task);
243 queue->timeout_task = NULL;
244 }
245 GNUNET_free (queue->address);
247}
248
249
255static void
256queue_timeout (void *cls)
257{
258 struct Queue *queue = cls;
259 struct GNUNET_TIME_Relative left;
260
261 queue->timeout_task = NULL;
263 if (0 != left.rel_value_us)
264 {
265 /* not actually our turn yet, but let's at least update
266 the monitor, it may think we're about to die ... */
267 queue->timeout_task =
269 return;
270 }
272 "Queue %p was idle for %s, disconnecting\n",
273 queue,
276 GNUNET_YES));
278}
279
280
288static void
295
296
305static struct sockaddr_un *
306unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
307{
308 struct sockaddr_un *un;
309 size_t slen;
310
311 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
312 un = GNUNET_new (struct sockaddr_un);
313 un->sun_family = AF_UNIX;
314 slen = strlen (unixpath);
315 if (slen >= sizeof(un->sun_path))
316 slen = sizeof(un->sun_path) - 1;
317 GNUNET_memcpy (un->sun_path, unixpath, slen);
318 un->sun_path[slen] = '\0';
319 slen = sizeof(struct sockaddr_un);
320#if HAVE_SOCKADDR_UN_SUN_LEN
321 un->sun_len = (u_char) slen;
322#endif
323 (*sock_len) = slen;
324 if ('@' == un->sun_path[0])
325 un->sun_path[0] = '\0';
326 return un;
327}
328
329
334{
338 struct Queue *res;
339
343 const struct sockaddr_un *un;
344
348 socklen_t un_len;
349};
350
351
360static int
361lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
362{
363 struct LookupCtx *lctx = cls;
364 struct Queue *queue = value;
365
366 if ((queue->address_len == lctx->un_len) &&
367 (0 == memcmp (lctx->un, queue->address, queue->address_len)))
368 {
369 lctx->res = queue;
370 return GNUNET_NO;
371 }
372 return GNUNET_YES;
373}
374
375
383static struct Queue *
385 const struct sockaddr_un *un,
386 socklen_t un_len)
387{
388 struct LookupCtx lctx;
389
390 lctx.un = un;
391 lctx.un_len = un_len;
392 lctx.res = NULL;
394 peer,
396 &lctx);
397 return lctx.res;
398}
399
400
407static void
409{
410 struct Queue *queue = queue_tail;
411 const struct GNUNET_MessageHeader *msg = &queue->msg->header;
412 size_t msg_size = ntohs (msg->size);
413 ssize_t sent;
414
415 /* take queue of the ready list */
416 write_task = NULL;
417resend:
418 /* Send the data */
420 msg,
421 msg_size,
422 (const struct sockaddr *) queue->address,
423 queue->address_len);
425 "UNIX transmitted message to %s (%d/%u: %s)\n",
426 GNUNET_i2s (&queue->target),
427 (int) sent,
428 (unsigned int) msg_size,
429 (sent < 0) ? strerror (errno) : "ok");
430 if (-1 != sent)
431 {
433 if (NULL != queue_head)
435 unix_sock,
437 NULL);
438
439 /* send 'msg' */
440 GNUNET_free (queue->msg);
441 queue->msg = NULL;
444 "# bytes sent",
445 (long long) sent,
446 GNUNET_NO);
448 return; /* all good */
449 }
451 "# network transmission failures",
452 1,
453 GNUNET_NO);
455 unix_sock,
457 NULL);
458 switch (errno)
459 {
460 case EAGAIN:
461 case ENOBUFS:
462 /* We should retry later... */
464 return;
465
466 case EMSGSIZE: {
467 socklen_t size = 0;
468 socklen_t len = sizeof(size);
469
471 SOL_SOCKET,
472 SO_SNDBUF,
473 &size,
474 &len);
475 if (size > ntohs (msg->size))
476 {
477 /* Buffer is bigger than message: error, no retry
478 * This should never happen!*/
479 GNUNET_break (0);
480 return;
481 }
482 GNUNET_log (
484 "Trying to increase socket buffer size from %u to %u for message size %u\n",
485 (unsigned int) size,
486 (unsigned int) ((msg_size / 1000) + 2) * 1000,
487 (unsigned int) msg_size);
488 size = ((msg_size / 1000) + 2) * 1000;
490 SOL_SOCKET,
491 SO_SNDBUF,
492 &size,
493 sizeof(size)))
494 goto resend; /* Increased buffer size, retry sending */
495 /* Ok, then just try very modest increase */
496 size = msg_size;
498 SOL_SOCKET,
499 SO_SNDBUF,
500 &size,
501 sizeof(size)))
502 goto resend; /* Increased buffer size, retry sending */
503 /* Could not increase buffer size: error, no retry */
505 return;
506 }
507
508 default:
510 return;
511 }
512}
513
514
523static void
525 const struct GNUNET_MessageHeader *msg,
526 void *impl_state)
527{
528 struct Queue *queue = impl_state;
529 size_t msize = ntohs (msg->size);
530
531 GNUNET_assert (mq == queue->mq);
532 GNUNET_assert (NULL == queue->msg);
533 // Convert to UNIXMessage
534 queue->msg = GNUNET_malloc (msize + sizeof (struct UNIXMessage));
535 queue->msg->header.size = htons (msize + sizeof (struct UNIXMessage));
536 queue->msg->sender = my_identity;
537 memcpy (&queue->msg[1], msg, msize);
539 GNUNET_assert (NULL != unix_sock);
540 if (NULL == write_task)
542 unix_sock,
544 NULL);
545}
546
547
556static void
557mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
558{
559 struct Queue *queue = impl_state;
560
561 if (mq == queue->mq)
562 {
563 queue->mq = NULL;
565 }
566}
567
568
575static void
576mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
577{
578 struct Queue *queue = impl_state;
579
580 GNUNET_assert (NULL != queue->msg);
581 queue->msg = NULL;
583 GNUNET_assert (NULL != write_task);
584 if (NULL == queue_head)
585 {
587 write_task = NULL;
588 }
589}
590
591
601static void
602mq_error (void *cls, enum GNUNET_MQ_Error error)
603{
604 struct Queue *queue = cls;
605
607 "UNIX MQ error in queue to %s: %d\n",
608 GNUNET_i2s (&queue->target),
609 (int) error);
611}
612
613
624static struct Queue *
627 const struct sockaddr_un *un,
628 socklen_t un_len)
629{
630 struct Queue *queue;
631
632 queue = GNUNET_new (struct Queue);
633 queue->target = *target;
634 queue->address = GNUNET_memdup (un, un_len);
635 queue->address_len = un_len;
637 queue_map,
638 &queue->target,
639 queue,
642 "# queues active",
644 GNUNET_NO);
645 queue->timeout =
647 queue->timeout_task =
650 queue);
652 &mq_destroy,
653 &mq_cancel,
654 queue,
655 NULL,
656 &mq_error,
657 queue);
658 {
659 char *foreign_addr;
660
661 if ('\0' == un->sun_path[0])
662 GNUNET_asprintf (&foreign_addr,
663 "%s-@%s",
665 &un->sun_path[1]);
666 else
667 GNUNET_asprintf (&foreign_addr,
668 "%s-%s",
670 un->sun_path);
672 &queue->target,
673 foreign_addr,
674 UNIX_MTU - sizeof (struct
677 0,
679 cs,
680 queue->mq);
681 GNUNET_free (foreign_addr);
682 }
683 return queue;
684}
685
686
694static void
695select_read_cb (void *cls);
696
697
705static void
706receive_complete_cb (void *cls, int success)
707{
708 (void) cls;
710 if (GNUNET_OK != success)
712 "# transport transmission failures",
713 1,
714 GNUNET_NO);
715 if ((NULL == read_task) && (delivering_messages < max_queue_length) &&
716 (NULL != unix_sock))
718 unix_sock,
720 NULL);
721}
722
723
731static void
732select_read_cb (void *cls)
733{
734 char buf[65536] GNUNET_ALIGN;
735 struct Queue *queue;
736 const struct UNIXMessage *msg;
737 struct sockaddr_un un;
738 socklen_t addrlen;
739 ssize_t ret;
740 uint16_t msize;
741
742 GNUNET_assert (NULL != unix_sock);
744 unix_sock,
746 NULL);
747 addrlen = sizeof(un);
748 memset (&un, 0, sizeof(un));
750 buf,
751 sizeof(buf),
752 (struct sockaddr *) &un,
753 &addrlen);
754 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno)))
755 return;
756 if (-1 == ret)
757 {
759 return;
760 }
762 "Read %d bytes from socket %s\n",
763 (int) ret,
764 un.sun_path);
765 GNUNET_assert (AF_UNIX == (un.sun_family));
766 msg = (struct UNIXMessage *) buf;
767 msize = ntohs (msg->header.size);
768 if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
769 {
771 "Wrong message size: %d bytes\n",
772 msize);
773 GNUNET_break_op (0);
774 return;
775 }
776 queue = lookup_queue (&msg->sender, &un, addrlen);
777 if (NULL == queue)
778 queue =
779 setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
780 else
782 if (NULL == queue)
783 {
784 GNUNET_log (
786 _ (
787 "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
788 return;
789 }
790
791 {
792 uint16_t tsize = msize - sizeof(struct UNIXMessage);
793
794 const struct GNUNET_MessageHeader *currhdr;
795 struct GNUNET_MessageHeader al_hdr;
796
797 currhdr = (const struct GNUNET_MessageHeader *) &msg[1];
798 /* ensure aligned access */
799 memcpy (&al_hdr, currhdr, sizeof(al_hdr));
800 if ((tsize < sizeof(struct GNUNET_MessageHeader)) ||
801 (tsize != ntohs (al_hdr.size)))
802 {
803 GNUNET_break_op (0);
804 return;
805 }
807 &msg->sender,
808 currhdr,
811 NULL);
812 if (GNUNET_SYSERR == ret)
813 {
815 "Transport not up!\n");
816 return; /* transport not up */
817 }
818 if (GNUNET_NO == ret)
819 {
821 "Error sending message to transport\n");
822 return;
823 }
825 }
827 {
829 "Back pressure %llu\n", delivering_messages);
830
831 /* we should try to apply 'back pressure' */
833 read_task = NULL;
834 }
835}
836
837
855static int
856mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
857{
858 struct Queue *queue;
859 const char *path;
860 struct sockaddr_un *un;
861 socklen_t un_len;
862
863 (void) cls;
864 if (0 != strncmp (address,
866 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
867 {
868 GNUNET_break_op (0);
869 return GNUNET_SYSERR;
870 }
871 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
872 un = unix_address_to_sockaddr (path, &un_len);
873 queue = lookup_queue (peer, un, un_len);
874 if (NULL != queue)
875 {
877 "Address `%s' for %s ignored, queue exists\n",
878 path,
879 GNUNET_i2s (peer));
880 GNUNET_free (un);
881 return GNUNET_OK;
882 }
883 queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len);
884 GNUNET_free (un);
885 if (NULL == queue)
886 {
888 "Failed to setup queue to %s at `%s'\n",
889 GNUNET_i2s (peer),
890 path);
891 return GNUNET_NO;
892 }
893 return GNUNET_OK;
894}
895
896
905static int
907 const struct GNUNET_PeerIdentity *target,
908 void *value)
909{
910 struct Queue *queue = value;
911
912 (void) cls;
913 (void) target;
915 return GNUNET_OK;
916}
917
918
924static void
925do_shutdown (void *cls)
926{
927 if (NULL != read_task)
928 {
930 read_task = NULL;
931 }
932 if (NULL != write_task)
933 {
935 write_task = NULL;
936 }
937 if (NULL != unix_sock)
938 {
940 unix_sock = NULL;
941 }
944 if (NULL != ai)
945 {
947 ai = NULL;
948 }
949 if (NULL != ch)
950 {
952 ch = NULL;
953 }
954 if (NULL != stats)
955 {
957 stats = NULL;
958 }
959}
960
961
973static void
974enc_notify_cb (void *cls,
975 const struct GNUNET_PeerIdentity *sender,
976 const struct GNUNET_MessageHeader *msg)
977{
978 (void) cls;
979 (void) sender;
980 (void) msg;
981 GNUNET_break_op (0);
982}
983
984
993static void
994run (void *cls,
995 char *const *args,
996 const char *cfgfile,
997 const struct GNUNET_CONFIGURATION_Handle *cfg)
998{
999 char *unix_socket_path;
1000 struct sockaddr_un *un;
1001 socklen_t un_len;
1002 char *my_addr;
1004
1005 (void) cls;
1007
1009 if (NULL == my_private_key)
1010 {
1011 GNUNET_log (
1013 _ (
1014 "UNIX communicator is lacking key configuration settings. Exiting.\n"));
1016 return;
1017 }
1019
1020 if (GNUNET_OK !=
1023 "UNIXPATH",
1024 &unix_socket_path))
1025 {
1028 "UNIXPATH");
1029 return;
1030 }
1031 if (GNUNET_OK !=
1034 "MAX_QUEUE_LENGTH",
1037
1038 un = unix_address_to_sockaddr (unix_socket_path, &un_len);
1039 if (NULL == un)
1040 {
1042 "Failed to setup UNIX domain socket address with path `%s'\n",
1043 unix_socket_path);
1044 GNUNET_free (unix_socket_path);
1045 return;
1046 }
1047 unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1048 if (NULL == unix_sock)
1049 {
1051 GNUNET_free (un);
1052 GNUNET_free (unix_socket_path);
1053 return;
1054 }
1055 if (('\0' != un->sun_path[0]) &&
1057 {
1059 _ ("Cannot create path to `%s'\n"),
1060 un->sun_path);
1062 unix_sock = NULL;
1063 GNUNET_free (un);
1064 GNUNET_free (unix_socket_path);
1065 return;
1066 }
1068 (const struct sockaddr *) un,
1069 un_len))
1070 {
1071 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
1073 unix_sock = NULL;
1074 GNUNET_free (un);
1075 GNUNET_free (unix_socket_path);
1076 return;
1077 }
1078 GNUNET_free (un);
1079 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
1080 stats = GNUNET_STATISTICS_create ("C-UNIX", cfg);
1083 unix_sock,
1085 NULL);
1091 &mq_init,
1092 NULL,
1094 NULL,
1095 NULL);
1096 if (NULL == ch)
1097 {
1098 GNUNET_break (0);
1100 GNUNET_free (unix_socket_path);
1101 return;
1102 }
1103 GNUNET_asprintf (&my_addr,
1104 "%s-%s",
1106 unix_socket_path);
1107 GNUNET_free (unix_socket_path);
1109 my_addr,
1112 GNUNET_free (my_addr);
1113}
1114
1115
1123int
1124main (int argc, char *const *argv)
1125{
1126 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1128 };
1129 int ret;
1130
1131 ret = (GNUNET_OK ==
1133 argc,
1134 argv,
1135 "gnunet-communicator-unix",
1136 _ ("GNUnet UNIX domain socket communicator"),
1137 options,
1138 &run,
1139 NULL))
1140 ? 0
1141 : 1;
1142 return ret;
1143}
1144
1145
1146#if defined(__linux__) && defined(__GLIBC__)
1147#include <malloc.h>
1148
1149void __attribute__ ((constructor))
1150GNUNET_TRANSPORT_communicator_unix_memory_init (void);
1151
1155void __attribute__ ((constructor))
1156GNUNET_TRANSPORT_communicator_unix_memory_init (void)
1157{
1158 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1159 mallopt (M_TOP_PAD, 1 * 1024);
1160 malloc_trim (0);
1161}
1162
1163
1164#endif
1165
1166/* 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 struct GNUNET_PeerIdentity my_identity
My Peer Identity.
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 char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Own private key.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
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?
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition crypto_ecc.c:201
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:633
#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:627
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:688
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition network.c:833
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:806
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:772
@ 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:567
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:1511
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:1582
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:1339
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
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:1277
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:599
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.
Private ECC key encoded for transmission.
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
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Definition scheduler.c:136
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)