GNUnet 0.21.2
transport_api2_communication.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 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
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_protocols.h"
30#include "transport.h"
31
32
38#define DEFAULT_MAX_QUEUE_LENGTH 16
39
40
45{
50
55
60
64 void *cb_cls;
65
70
74 uint64_t id;
75};
76
77
83{
88
93
98
103
107 uint64_t mid;
108
112 uint32_t qid;
113};
114
115
120{
125
130
135
140
145
150
155
160
165
169 const char *config_section;
170
174 const char *addr_prefix;
175
181
186
193
198
203
207 unsigned long long max_queue_length;
208
212 uint64_t fc_gen;
213
218 uint32_t aid_gen;
219
223 uint32_t queue_gen;
224
229};
230
231
237{
242
247
252
256 char *address;
257
262
267
272
277
281 uint32_t queue_id;
282
286 uint32_t mtu;
287
291 uint64_t q_len;
295 uint32_t priority;
296};
297
298
304{
309
314
319
323 char *address;
324
330
335 uint32_t aid;
336
341};
342
343
349static void
351
352
359static void
361{
362 struct GNUNET_MQ_Envelope *env;
364
365 if (NULL == ai->ch->mq)
366 return;
368 strlen (ai->address) + 1,
371 aam->nt = htonl ((uint32_t) ai->nt);
372 memcpy (&aam[1], ai->address, strlen (ai->address) + 1);
374}
375
376
383static void
385{
386 struct GNUNET_MQ_Envelope *env;
388
389 if (NULL == ai->ch->mq)
390 return;
392 dam->aid = htonl (ai->aid);
394}
395
396
403static void
405{
406 struct GNUNET_MQ_Envelope *env;
408
409 if (NULL == qh->ch->mq)
410 return;
412 "Sending `GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP` message\n");
414 strlen (qh->address) + 1,
416 aqm->qid = htonl (qh->queue_id);
417 aqm->receiver = qh->peer;
418 aqm->nt = htonl ((uint32_t) qh->nt);
419 aqm->mtu = htonl (qh->mtu);
420 aqm->q_len = GNUNET_htonll (qh->q_len);
421 aqm->priority = htonl (qh->priority);
422 aqm->cs = htonl ((uint32_t) qh->cs);
423 memcpy (&aqm[1], qh->address, strlen (qh->address) + 1);
424 GNUNET_MQ_send (qh->ch->mq, env);
425}
426
427
434static void
436{
437 struct GNUNET_MQ_Envelope *env;
439
440 if (NULL == qh->ch->mq)
441 return;
443 uqm->qid = htonl (qh->queue_id);
444 uqm->receiver = qh->peer;
445 uqm->nt = htonl ((uint32_t) qh->nt);
446 uqm->mtu = htonl (qh->mtu);
447 uqm->q_len = GNUNET_htonll (qh->q_len);
448 uqm->priority = htonl (qh->priority);
449 uqm->cs = htonl ((uint32_t) qh->cs);
450 GNUNET_MQ_send (qh->ch->mq, env);
451}
452
453
460static void
462{
463 struct GNUNET_MQ_Envelope *env;
465
466 if (NULL == qh->ch->mq)
467 return;
469 dqm->qid = htonl (qh->queue_id);
470 dqm->receiver = qh->peer;
471 GNUNET_MQ_send (qh->ch->mq, env);
472}
473
474
483static void
485{
486 struct FlowControl *fcn;
487 struct AckPending *apn;
488
489 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn)
490 {
491 fcn = fc->next;
492 GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
493 fc->cb (fc->cb_cls, GNUNET_SYSERR);
494 GNUNET_free (fc);
495 }
496 for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn)
497 {
498 apn = ap->next;
499 GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
500 GNUNET_free (ap);
501 }
502 if (NULL == ch->mq)
503 return;
505 ch->mq = NULL;
506}
507
508
512static void
513error_handler (void *cls, enum GNUNET_MQ_Error error)
514{
516
518 "MQ failure %d, reconnecting to transport service.\n",
519 error);
520 disconnect (ch);
521 /* TODO: maybe do this with exponential backoff/delay */
522 reconnect (ch);
523}
524
525
533static void
535 void *cls,
536 const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack)
537{
539
540 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next)
541 {
542 if ((fc->id == incoming_ack->fc_id) &&
543 (0 == memcmp (&fc->sender,
544 &incoming_ack->sender,
545 sizeof(struct GNUNET_PeerIdentity))))
546 {
548 "Done with message with flow control id %" PRIu64
549 " for sender %s from sender %s\n",
550 incoming_ack->fc_id,
551 GNUNET_i2s (&fc->sender),
552 GNUNET_i2s (&incoming_ack->sender));
553 GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
554 fc->cb (fc->cb_cls, GNUNET_OK);
555 GNUNET_free (fc);
556 return;
557 }
558 }
560 "Message with flow control id %" PRIu64
561 " from sender %s not found\n",
562 incoming_ack->fc_id,
563 GNUNET_i2s (&incoming_ack->sender));
564 GNUNET_break (0);
565 disconnect (ch);
566 /* TODO: maybe do this with exponential backoff/delay */
567 reconnect (ch);
568}
569
570
579static int
581{
582 (void) cls;
584 return GNUNET_OK;
585}
586
587
594static void
596{
598 const char *addr = (const char *) &cq[1];
600 struct GNUNET_MQ_Envelope *env;
601 int ret = ch->mq_init (ch->mq_init_cls, &cq->receiver, addr);
602
603 if (GNUNET_NO == ret)
604 {
606 "Address `%s' is already (being) connected to.\n",
607 addr);
609 }
610 else if (GNUNET_SYSERR == ret)
611 {
613 "Address `%s' invalid for this communicator\n",
614 addr);
616 }
617 else
618 {
620 }
621 cqr->request_id = cq->request_id;
623}
624
625
634static int
635check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
636{
637 (void) cls;
639 return GNUNET_OK;
640}
641
642
652static void
654 int status,
655 const struct GNUNET_PeerIdentity *receiver,
656 uint64_t mid,
657 uint32_t qid)
658{
659 struct GNUNET_MQ_Envelope *env;
661
663 ack->status = htonl (status);
664 ack->mid = mid;
665 ack->qid = qid;
666 ack->receiver = *receiver;
668}
669
670
677static void
678send_ack_cb (void *cls)
679{
680 struct AckPending *ap = cls;
682
683 if (NULL != ch->ap_head && NULL != ap)
684 GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
685 if (NULL != ap)
686 {
687 send_ack (ch, GNUNET_OK, &ap->receiver, ap->mid, ap->qid);
688 GNUNET_free (ap);
689 }
690}
691
692
699static void
701{
703 const struct GNUNET_MessageHeader *mh;
704 struct GNUNET_MQ_Envelope *env;
705 struct AckPending *ap;
707
708 for (qh = ch->queue_head; NULL != qh; qh = qh->next)
709 if ((qh->queue_id == ntohl (smt->qid)) &&
710 (0 == memcmp (&qh->peer,
711 &smt->receiver,
712 sizeof(struct GNUNET_PeerIdentity))))
713 break;
714 if (NULL == qh)
715 {
716 /* queue is already gone, tell transport this one failed */
718 "Transmission failed, queue no longer exists.\n");
719 send_ack (ch, GNUNET_NO, &smt->receiver, smt->mid, smt->qid);
720 return;
721 }
722 ap = GNUNET_new (struct AckPending);
723 ap->ch = ch;
724 ap->receiver = smt->receiver;
725 ap->mid = smt->mid;
726 ap->qid = smt->qid;
727 GNUNET_CONTAINER_DLL_insert (ch->ap_head, ch->ap_tail, ap);
728 mh = (const struct GNUNET_MessageHeader *) &smt[1];
731 GNUNET_MQ_send (qh->mq, env);
732}
733
734
743static int
745 void *cls,
747{
748 (void) cls;
750 return GNUNET_OK;
751}
752
753
760static void
762 void *cls,
764{
766 if (NULL != ch->notify_cb)
767 ch->notify_cb (ch->notify_cb_cls,
768 &bi->pid,
769 (const struct GNUNET_MessageHeader *) &bi[1]);
770 else
771 GNUNET_log (
773 _ ("Dropped backchanel message: handler not provided by communicator\n"));
774}
775
776
782static void
784{
786 { GNUNET_MQ_hd_fixed_size (incoming_ack,
789 ch),
790 GNUNET_MQ_hd_var_size (create_queue,
793 ch),
794 GNUNET_MQ_hd_var_size (send_msg,
797 ch),
799 backchannel_incoming,
802 ch),
805 struct GNUNET_MQ_Envelope *env;
806
807 ch->mq =
808 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
809 if (NULL == ch->mq)
810 return;
812 strlen (ch->addr_prefix) + 1,
814 cam->cc = htonl ((uint32_t) ch->cc);
815 memcpy (&cam[1], ch->addr_prefix, strlen (ch->addr_prefix) + 1);
817 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
818 ai = ai->next)
820 for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh;
821 qh = qh->next)
822 send_add_queue (qh);
823}
824
825
828 const struct GNUNET_CONFIGURATION_Handle *cfg,
829 const char *config_section,
830 const char *addr_prefix,
833 void *mq_init_cls,
835 void *notify_cb_cls)
836{
838
840 ch->cfg = cfg;
841 ch->config_section = config_section;
842 ch->addr_prefix = addr_prefix;
843 ch->mq_init = mq_init;
844 ch->mq_init_cls = mq_init_cls;
845 ch->notify_cb = notify_cb;
846 ch->notify_cb_cls = notify_cb_cls;
847 ch->cc = cc;
848 reconnect (ch);
849 if (GNUNET_OK !=
852 "MAX_QUEUE_LENGTH",
853 &ch->max_queue_length))
854 ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
855 if (NULL == ch->mq)
856 {
857 GNUNET_free (ch);
858 return NULL;
859 }
860 return ch;
861}
862
863
869void
872{
873 disconnect (ch);
874 while (NULL != ch->ai_head)
875 {
876 GNUNET_break (0); /* communicator forgot to remove address, warn! */
878 }
879 GNUNET_free (ch);
880}
881
882
883/* ************************* Receiving *************************** */
884
885
886int
889 const struct GNUNET_PeerIdentity *sender,
890 const struct GNUNET_MessageHeader *msg,
891 struct GNUNET_TIME_Relative expected_addr_validity,
893 void *cb_cls)
894{
895 struct GNUNET_MQ_Envelope *env;
897 uint16_t msize;
898
899
901 "communicator receive\n");
902
903 if (NULL == ch->mq)
904 return GNUNET_SYSERR;
905 if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length))
906 {
907 GNUNET_log (
909 "Dropping message: transport is too slow, queue length %llu exceeded\n",
910 ch->max_queue_length);
911 return GNUNET_NO;
912 }
913
914 msize = ntohs (msg->size);
915 env =
917 if (NULL == env)
918 {
919 GNUNET_break (0);
920 return GNUNET_SYSERR;
921 }
923 GNUNET_TIME_relative_hton (expected_addr_validity);
924 im->sender = *sender;
925 // FIXME: this is expensive, would be better if we would
926 // re-design the API to allow us to create the envelope first,
927 // and then have the application fill in the body so we do
928 // not have to memcpy()
929 memcpy (&im[1], msg, msize);
930 im->fc_on = htonl (GNUNET_NO);
931 if (NULL != cb)
932 {
933 struct FlowControl *fc;
934
935 im->fc_on = htonl (GNUNET_YES);
936 im->fc_id = ch->fc_gen++;
937 fc = GNUNET_new (struct FlowControl);
938 fc->sender = *sender;
939 fc->id = im->fc_id;
940 fc->cb = cb;
941 fc->cb_cls = cb_cls;
942 GNUNET_CONTAINER_DLL_insert (ch->fc_head, ch->fc_tail, fc);
944 "Created flow control id %" PRIu64 " for sender %s\n",
945 fc->id,
946 GNUNET_i2s (&fc->sender));
947 }
949 return GNUNET_OK;
950}
951
952
953/* ************************* Discovery *************************** */
954
955
959 const struct GNUNET_PeerIdentity *peer,
960 const char *address,
961 uint32_t mtu,
962 uint64_t q_len,
963 uint32_t priority,
966 struct GNUNET_MQ_Handle *mq)
967{
969
970 // Do not notify the service if there is no initial capacity.
971 GNUNET_assert (0 < q_len);
972
974 qh->ch = ch;
975 qh->peer = *peer;
977 qh->nt = nt;
978 qh->mtu = mtu;
979 qh->q_len = q_len;
980 qh->priority = priority;
981 qh->cs = cs;
982 qh->mq = mq;
983 qh->queue_id = ch->queue_gen++;
984 GNUNET_CONTAINER_DLL_insert (ch->queue_head, ch->queue_tail, qh);
985 send_add_queue (qh);
986 return qh;
987}
988
989
990void
993 const struct GNUNET_TRANSPORT_QueueHandle *u_qh,
994 uint64_t q_len,
995 uint32_t priority)
996{
998
999 for (qh = ch->queue_head; NULL != qh; qh = qh->next)
1000 {
1001 if (u_qh == qh)
1002 break;
1003 }
1004 GNUNET_assert (NULL != qh);
1005 qh->q_len = q_len;
1006 qh->priority = priority;
1007 send_update_queue (qh);
1008}
1009
1010
1017void
1019{
1021
1022 send_del_queue (qh);
1023 GNUNET_CONTAINER_DLL_remove (ch->queue_head, ch->queue_tail, qh);
1024 GNUNET_MQ_destroy (qh->mq);
1025 GNUNET_free (qh->address);
1026 GNUNET_free (qh);
1027}
1028
1029
1042 const char *address,
1045{
1047
1049 ai->ch = ch;
1051 ai->nt = nt;
1053 ai->aid = ch->aid_gen++;
1054 GNUNET_CONTAINER_DLL_insert (ch->ai_head, ch->ai_tail, ai);
1056 return ai;
1057}
1058
1059
1066void
1069{
1071
1073 GNUNET_CONTAINER_DLL_remove (ch->ai_head, ch->ai_tail, ai);
1075 GNUNET_free (ai);
1076 ai = NULL;
1077}
1078
1079
1085void
1088{
1089 struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head;
1090 while (NULL != ai)
1091 {
1092 struct GNUNET_TRANSPORT_AddressIdentifier *ai_next = ai->next;
1094 ai = ai_next;
1095 }
1096}
1097
1098
1099/* ************************* Backchannel *************************** */
1100
1101
1102void
1105 const struct GNUNET_PeerIdentity *pid,
1106 const char *comm,
1107 const struct GNUNET_MessageHeader *header)
1108{
1109 struct GNUNET_MQ_Envelope *env;
1111 size_t slen = strlen (comm) + 1;
1112 uint16_t mlen = ntohs (header->size);
1113
1114 GNUNET_assert (mlen + slen + sizeof(*cb) < UINT16_MAX);
1115 env =
1117 slen + mlen,
1119 cb->pid = *pid;
1120 memcpy (&cb[1], header, mlen);
1121 memcpy (((char *) &cb[1]) + mlen, comm, slen);
1122 GNUNET_MQ_send (ch->mq, env);
1123}
1124
1125
1126/* end of transport_api2_communication.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
static void notify_cb(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received a backchannel message for this communicator (...
static int mq_init(void *cls, const struct GNUNET_PeerIdentity *peer_id, const char *address)
Function called by the transport service to initialize a message queue given address information abou...
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static char * address
GNS address for this phone.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:39
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Constants for network protocols.
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 *ch, 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.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
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...
GNUNET_TRANSPORT_CommunicatorCharacteristics
What characteristics does this communicator have?
void GNUNET_TRANSPORT_communicator_mq_update(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_TRANSPORT_QueueHandle *u_qh, uint64_t q_len, uint32_t priority)
Notify transport service that an MQ was updated.
void GNUNET_TRANSPORT_communicator_notify(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *pid, const char *comm, const struct GNUNET_MessageHeader *header)
The communicator asks the transport service to route a message via a different path to another commun...
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
void(* GNUNET_TRANSPORT_CommunicatorNotify)(void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
Function called when the transport service has received a backchannel message for this communicator (...
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, 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)
Connect to the transport service.
int(* GNUNET_TRANSPORT_CommunicatorMqInit)(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...
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
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.
void GNUNET_TRANSPORT_communicator_address_remove_all(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Notify transport service that this communicator no longer provides all its addresses for this peer.
void(* GNUNET_TRANSPORT_MessageCompletedCallback)(void *cls, int success)
Function called to notify communicator that we have received and processed the message.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
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_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_log(kind,...)
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
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
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
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:550
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:293
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#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
#define GNUNET_MQ_check_boxed_message(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:655
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:44
#define GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK
transport acknowledges processing an incoming message
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN
inform transport that a queue was torn down
#define GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR
Message sent to indicate to the transport which address prefix is supported by a communicator.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL
Response from communicator: address bogus, will not try to create queue.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE
transport tells communicator it wants a queue
#define GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL
Tell transport that it should assist with exchanging a message between communicators.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG
inform transport about an incoming message
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK
Response from communicator: will try to create queue.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING
Transport signalling incoming backchannel message to a communicator.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK
communicator tells transports that message was sent
#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS
inform transport to add an address of this peer
#define GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS
inform transport to delete an address of this peer
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG
transport tells communicator it wants to transmit
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP
inform transport that a queue was setup to talk to some peer
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE
inform transport that a queue was updated
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:618
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
Definition: socks.c:330
Information we track per message to tell the transport about success or failures.
struct AckPending * next
Kept in a DLL.
uint64_t mid
More-or-less unique ID for the message.
struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Communicator this entry belongs to.
struct AckPending * prev
Kept in a DLL.
struct GNUNET_PeerIdentity receiver
Which peer is this about?
uint32_t qid
Queue ID of the queue which will be used for the message.
Information we track per packet to enable flow control.
struct FlowControl * prev
Kept in a DLL.
GNUNET_TRANSPORT_MessageCompletedCallback cb
Function to call once the message was processed.
struct GNUNET_PeerIdentity sender
Which peer is this about?
struct FlowControl * next
Kept in a DLL.
uint64_t id
More-or-less unique ID for the message.
void * cb_cls
Closure for cb.
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition: cadet.h:142
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Time for relative time used by GNUnet, in microseconds.
Add address to the list.
Definition: transport.h:282
struct GNUNET_TIME_RelativeNBO expiration
When does the address expire?
Definition: transport.h:296
uint32_t nt
An enum GNUNET_NetworkType in NBO.
Definition: transport.h:301
Add queue to the transport.
Definition: transport.h:396
uint32_t nt
An enum GNUNET_NetworkType in NBO.
Definition: transport.h:415
uint32_t mtu
Maximum transmission unit, in NBO.
Definition: transport.h:420
uint64_t q_len
Queue length, in NBO.
Definition: transport.h:426
uint32_t priority
Priority of the queue in relation to other queues.
Definition: transport.h:431
uint32_t qid
Queue identifier (used to identify the queue).
Definition: transport.h:405
struct GNUNET_PeerIdentity receiver
Receiver that can be addressed via the queue.
Definition: transport.h:410
uint32_t cs
An enum GNUNET_TRANSPORT_ConnectionStatus in NBO.
Definition: transport.h:436
Internal representation of an address a communicator is currently providing for the transport service...
struct GNUNET_TRANSPORT_AddressIdentifier * next
Kept in a DLL.
struct GNUNET_TIME_Relative expiration
When does the address expire? (Expected lifetime of the address.)
enum GNUNET_NetworkType nt
Network type for the address.
struct GNUNET_TRANSPORT_AddressIdentifier * prev
Kept in a DLL.
uint32_t aid
Internal UUID for the address used in communication with the transport service.
struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Transport handle where the address was added.
uint32_t cc
NBO encoding of enum GNUNET_TRANSPORT_CommunicatorCharacteristics
Definition: transport.h:272
Message from transport to communicator passing along a backchannel message from the given peer pid.
Definition: transport.h:650
struct GNUNET_PeerIdentity pid
Origin peer.
Definition: transport.h:665
Message from communicator to transport service asking for transmission of a backchannel message with ...
Definition: transport.h:621
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL.
Definition: transport.h:625
struct GNUNET_PeerIdentity pid
Target peer.
Definition: transport.h:635
Opaque handle to the transport service for communicators.
struct GNUNET_TRANSPORT_AddressIdentifier * ai_head
Head of DLL of addresses this communicator offers to the transport service.
struct AckPending * ap_head
DLL of messages awaiting transmission confirmation (ack).
struct GNUNET_TRANSPORT_QueueHandle * queue_tail
DLL of queues we offer.
enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc
Characteristics of the communicator.
GNUNET_TRANSPORT_CommunicatorMqInit mq_init
Function to call when the transport service wants us to initiate a communication channel with another...
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.
struct FlowControl * fc_tail
DLL of messages awaiting flow control confirmation (ack).
uint32_t queue_gen
Queue identifier generator.
const char * addr_prefix
Address prefix to use.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct FlowControl * fc_head
DLL of messages awaiting flow control confirmation (ack).
GNUNET_TRANSPORT_CommunicatorNotify notify_cb
Function to call when the transport service receives messages for a communicator (i....
struct AckPending * ap_tail
DLL of messages awaiting transmission confirmation (ack).
struct GNUNET_TRANSPORT_AddressIdentifier * ai_tail
Tail of DLL of addresses this communicator offers to the transport service.
struct GNUNET_TRANSPORT_QueueHandle * queue_head
DLL of queues we offer.
uint64_t fc_gen
Flow-control identifier generator.
const char * config_section
Config section to use.
unsigned long long max_queue_length
Maximum permissible queue length.
uint32_t aid_gen
Internal UUID for the address used in communication with the transport service.
Communicator tells transport how queue creation went down.
Definition: transport.h:540
uint32_t request_id
Unique ID for the request.
Definition: transport.h:550
Transport tells communicator that it wants a new queue.
Definition: transport.h:516
uint32_t request_id
Unique ID for the request.
Definition: transport.h:525
struct GNUNET_PeerIdentity receiver
Receiver that can be addressed via the queue.
Definition: transport.h:530
Remove address from the list.
Definition: transport.h:311
uint32_t aid
Address identifier.
Definition: transport.h:320
Remove queue, it is no longer available.
Definition: transport.h:494
struct GNUNET_PeerIdentity receiver
Receiver that can be addressed via the queue.
Definition: transport.h:508
uint32_t qid
Address identifier.
Definition: transport.h:503
Transport informs us about being done with an incoming message.
Definition: transport.h:369
struct GNUNET_PeerIdentity sender
Sender identifier of the original message.
Definition: transport.h:388
uint64_t fc_id
Which message is being ACKed?
Definition: transport.h:383
Inform transport about an incoming message.
Definition: transport.h:328
struct GNUNET_TIME_RelativeNBO expected_address_validity
How long does the communicator believe the address on which the message was received to remain valid?
Definition: transport.h:348
struct GNUNET_PeerIdentity sender
Sender identifier.
Definition: transport.h:353
uint32_t fc_on
Do we use flow control or not?
Definition: transport.h:337
uint64_t fc_id
64-bit number to identify the matching ACK.
Definition: transport.h:342
Handle returned to identify the internal data structure the transport API has created to manage a mes...
enum GNUNET_TRANSPORT_ConnectionStatus cs
Communication status of the queue.
struct GNUNET_MQ_Handle * mq
The queue itself.
struct GNUNET_TRANSPORT_QueueHandle * next
Kept in a DLL.
struct GNUNET_TRANSPORT_QueueHandle * prev
Kept in a DLL.
uint32_t queue_id
ID for this queue when talking to the transport service.
uint32_t mtu
Maximum transmission unit for the queue.
char * address
Address used by the communication queue.
enum GNUNET_NetworkType nt
Network type of the communication queue.
struct GNUNET_PeerIdentity peer
Which peer we can communciate with.
struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Handle this queue belongs to.
Inform transport that message was sent.
Definition: transport.h:587
uint32_t status
Success (GNUNET_OK), failure (GNUNET_SYSERR).
Definition: transport.h:596
uint64_t mid
Message ID of the original message.
Definition: transport.h:601
uint32_t qid
Queue ID for the queue which was used to send the message.
Definition: transport.h:606
struct GNUNET_PeerIdentity receiver
Receiver identifier.
Definition: transport.h:611
Inform communicator about transport's desire to send a message.
Definition: transport.h:558
uint32_t qid
Which queue should we use?
Definition: transport.h:567
uint64_t mid
Message ID, used for flow control.
Definition: transport.h:572
struct GNUNET_PeerIdentity receiver
Receiver identifier.
Definition: transport.h:577
struct GNUNET_PeerIdentity receiver
Receiver that can be addressed via the queue.
Definition: transport.h:460
uint32_t cs
An enum GNUNET_TRANSPORT_ConnectionStatus in NBO.
Definition: transport.h:486
uint32_t nt
An enum GNUNET_NetworkType in NBO.
Definition: transport.h:465
uint32_t priority
Priority of the queue in relation to other queues.
Definition: transport.h:481
uint32_t mtu
Maximum transmission unit, in NBO.
Definition: transport.h:470
uint64_t q_len
Queue length, in NBO.
Definition: transport.h:476
uint32_t qid
Queue identifier (used to identify the queue).
Definition: transport.h:455
common internal definitions for transport service
static void handle_incoming_ack(void *cls, const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack)
Transport service acknowledged a message we gave it (with flow control enabled).
static void reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
(re)connect our communicator to the transport service
static void handle_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
Transport service wants us to create a queue.
static void handle_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
Transport service wants us to send a message.
static void send_ack(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, int status, const struct GNUNET_PeerIdentity *receiver, uint64_t mid, uint32_t qid)
Notify transport service about status of a message with mid sent to receiver.
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on MQ errors.
static void send_add_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Send message to the transport service about address ai being now available.
static void send_add_queue(struct GNUNET_TRANSPORT_QueueHandle *qh)
Send message to the transport service about queue qh being now available.
static void disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
static void send_ack_cb(void *cls)
Message queue transmission by communicator was successful, notify transport service.
static int check_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
Transport service wants us to send a message.
static void send_del_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Send message to the transport service about address ai being no longer available.
static void handle_backchannel_incoming(void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
Transport service gives us backchannel message.
static int check_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
Transport service wants us to create a queue.
static int check_backchannel_incoming(void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
Transport service gives us backchannel message.
#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 send_del_queue(struct GNUNET_TRANSPORT_QueueHandle *qh)
Send message to the transport service about queue qh being no longer available.
static void send_update_queue(struct GNUNET_TRANSPORT_QueueHandle *qh)
Send message to the transport service about queue qh updated.