GNUnet 0.22.1
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
170
174 const char *config_section;
175
179 const char *addr_prefix;
180
186
191
198
203
208
212 unsigned long long max_queue_length;
213
217 uint64_t fc_gen;
218
223 uint32_t aid_gen;
224
228 uint32_t queue_gen;
229
234};
235
236
242{
247
252
257
261 char *address;
262
267
272
277
282
286 uint32_t queue_id;
287
291 uint32_t mtu;
292
296 uint64_t q_len;
300 uint32_t priority;
301};
302
303
309{
314
319
324
328 char *address;
329
335
340 uint32_t aid;
341
346};
347
348
354static void
356
357
364static void
366{
367 struct GNUNET_MQ_Envelope *env;
369
370 if (NULL == ai->ch->mq)
371 return;
373 strlen (ai->address) + 1,
376 aam->nt = htonl ((uint32_t) ai->nt);
377 memcpy (&aam[1], ai->address, strlen (ai->address) + 1);
379}
380
381
388static void
390{
391 struct GNUNET_MQ_Envelope *env;
393
394 if (NULL == ai->ch->mq)
395 return;
397 dam->aid = htonl (ai->aid);
399}
400
401
408static void
410{
411 struct GNUNET_MQ_Envelope *env;
413
414 if (NULL == qh->ch->mq)
415 return;
417 "Sending `GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP` message\n");
419 strlen (qh->address) + 1,
421 aqm->qid = htonl (qh->queue_id);
422 aqm->receiver = qh->peer;
423 aqm->nt = htonl ((uint32_t) qh->nt);
424 aqm->mtu = htonl (qh->mtu);
425 aqm->q_len = GNUNET_htonll (qh->q_len);
426 aqm->priority = htonl (qh->priority);
427 aqm->cs = htonl ((uint32_t) qh->cs);
428 memcpy (&aqm[1], qh->address, strlen (qh->address) + 1);
429 GNUNET_MQ_send (qh->ch->mq, env);
430}
431
432
439static void
441{
442 struct GNUNET_MQ_Envelope *env;
444
445 if (NULL == qh->ch->mq)
446 return;
448 uqm->qid = htonl (qh->queue_id);
449 uqm->receiver = qh->peer;
450 uqm->nt = htonl ((uint32_t) qh->nt);
451 uqm->mtu = htonl (qh->mtu);
452 uqm->q_len = GNUNET_htonll (qh->q_len);
453 uqm->priority = htonl (qh->priority);
454 uqm->cs = htonl ((uint32_t) qh->cs);
455 GNUNET_MQ_send (qh->ch->mq, env);
456}
457
458
465static void
467{
468 struct GNUNET_MQ_Envelope *env;
470
471 if (NULL == qh->ch->mq)
472 return;
474 dqm->qid = htonl (qh->queue_id);
475 dqm->receiver = qh->peer;
476 GNUNET_MQ_send (qh->ch->mq, env);
477}
478
479
488static void
490{
491 struct FlowControl *fcn;
492 struct AckPending *apn;
493
494 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn)
495 {
496 fcn = fc->next;
497 GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
498 fc->cb (fc->cb_cls, GNUNET_SYSERR);
499 GNUNET_free (fc);
500 }
501 for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn)
502 {
503 apn = ap->next;
504 GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
505 GNUNET_free (ap);
506 }
507 if (NULL == ch->mq)
508 return;
510 ch->mq = NULL;
511}
512
513
517static void
518error_handler (void *cls, enum GNUNET_MQ_Error error)
519{
521
523 "MQ failure %d, reconnecting to transport service.\n",
524 error);
525 disconnect (ch);
526 /* TODO: maybe do this with exponential backoff/delay */
527 reconnect (ch);
528}
529
530
538static void
540 void *cls,
541 const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack)
542{
544
545 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next)
546 {
547 if ((fc->id == incoming_ack->fc_id) &&
548 (0 == memcmp (&fc->sender,
549 &incoming_ack->sender,
550 sizeof(struct GNUNET_PeerIdentity))))
551 {
553 "Done with message with flow control id %" PRIu64
554 " for sender %s from sender %s\n",
555 incoming_ack->fc_id,
556 GNUNET_i2s (&fc->sender),
557 GNUNET_i2s (&incoming_ack->sender));
558 GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
559 fc->cb (fc->cb_cls, GNUNET_OK);
560 GNUNET_free (fc);
561 return;
562 }
563 }
565 "Message with flow control id %" PRIu64
566 " from sender %s not found\n",
567 incoming_ack->fc_id,
568 GNUNET_i2s (&incoming_ack->sender));
569 GNUNET_break (0);
570 disconnect (ch);
571 /* TODO: maybe do this with exponential backoff/delay */
572 reconnect (ch);
573}
574
575
584static int
586{
587 (void) cls;
589 return GNUNET_OK;
590}
591
592
599static void
601{
603 const char *addr = (const char *) &cq[1];
605 struct GNUNET_MQ_Envelope *env;
606 int ret = ch->mq_init (ch->mq_init_cls, &cq->receiver, addr);
607
608 if (GNUNET_NO == ret)
609 {
611 "Address `%s' is already (being) connected to.\n",
612 addr);
614 }
615 else if (GNUNET_SYSERR == ret)
616 {
618 "Address `%s' invalid for this communicator\n",
619 addr);
621 }
622 else
623 {
625 }
626 cqr->request_id = cq->request_id;
628}
629
630
639static int
640check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
641{
642 (void) cls;
644 return GNUNET_OK;
645}
646
647
657static void
659 int status,
660 const struct GNUNET_PeerIdentity *receiver,
661 uint64_t mid,
662 uint32_t qid)
663{
664 struct GNUNET_MQ_Envelope *env;
666
668 ack->status = htonl (status);
669 ack->mid = mid;
670 ack->qid = qid;
671 ack->receiver = *receiver;
673}
674
675
682static void
683send_ack_cb (void *cls)
684{
685 struct AckPending *ap = cls;
686
687 GNUNET_assert (NULL != ap);
688 GNUNET_assert (NULL != ap->ch->ap_head);
690 send_ack (ap->ch, GNUNET_OK, &ap->receiver, ap->mid, ap->qid);
691 GNUNET_free (ap);
692}
693
694
701static void
703{
705 const struct GNUNET_MessageHeader *mh;
706 struct GNUNET_MQ_Envelope *env;
707 struct AckPending *ap;
709
710 for (qh = ch->queue_head; NULL != qh; qh = qh->next)
711 if ((qh->queue_id == ntohl (smt->qid)) &&
712 (0 == memcmp (&qh->peer,
713 &smt->receiver,
714 sizeof(struct GNUNET_PeerIdentity))))
715 break;
716 if (NULL == qh)
717 {
718 /* queue is already gone, tell transport this one failed */
720 "Transmission failed, queue no longer exists.\n");
721 send_ack (ch, GNUNET_NO, &smt->receiver, smt->mid, smt->qid);
722 return;
723 }
724 ap = GNUNET_new (struct AckPending);
725 ap->ch = ch;
726 ap->receiver = smt->receiver;
727 ap->mid = smt->mid;
728 ap->qid = smt->qid;
729 GNUNET_CONTAINER_DLL_insert (ch->ap_head, ch->ap_tail, ap);
730 mh = (const struct GNUNET_MessageHeader *) &smt[1];
733 GNUNET_MQ_send (qh->mq, env);
734}
735
736
745static int
747 void *cls,
749{
750 (void) cls;
752 return GNUNET_OK;
753}
754
755
762static void
764 void *cls,
766{
768 if (NULL != ch->notify_cb)
769 ch->notify_cb (ch->notify_cb_cls,
770 &bi->pid,
771 (const struct GNUNET_MessageHeader *) &bi[1]);
772 else
773 GNUNET_log (
775 _ ("Dropped backchanel message: handler not provided by communicator\n"));
776}
777
778
779static int
781 const struct GNUNET_TRANSPORT_StartBurst *sb)
782{
783 const char *addr_str = (const char *) &sb[1];
784 (void) cls;
785
787 "check_start_burst %s %lu\n",
788 addr_str,
789 strlen (addr_str));
791 return GNUNET_OK;
792}
793
794
795static void
797 const struct GNUNET_TRANSPORT_StartBurst *sb)
798{
800 const char *addr = (const char *) &sb[1];
802
804 "Calling communicator to start burst to %s is %s rtt %lu\n",
805 addr,
806 NULL == sb ? "not possible" : "possible",
807 (unsigned long) rtt.rel_value_us);
808
809 if (NULL != ch->sb)
810 ch->sb (addr, GNUNET_TIME_relative_ntoh (sb->rtt), (struct
812 sb->pid);
813}
814
815
821static void
823{
825 { GNUNET_MQ_hd_fixed_size (incoming_ack,
828 ch),
829 GNUNET_MQ_hd_var_size (create_queue,
832 ch),
833 GNUNET_MQ_hd_var_size (send_msg,
836 ch),
838 backchannel_incoming,
841 ch),
846 ch),
849 struct GNUNET_MQ_Envelope *env;
850
851 ch->mq =
852 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
853 if (NULL == ch->mq)
854 return;
856 strlen (ch->addr_prefix) + 1,
858 if (NULL != ch->sb)
859 {
860 cam->can_burst = htonl (GNUNET_YES);
861 }
862 cam->cc = htonl ((uint32_t) ch->cc);
863 memcpy (&cam[1], ch->addr_prefix, strlen (ch->addr_prefix) + 1);
865 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
866 ai = ai->next)
868 for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh;
869 qh = qh->next)
870 send_add_queue (qh);
871}
872
873
876 const struct GNUNET_CONFIGURATION_Handle *cfg,
877 const char *config_section,
878 const char *addr_prefix,
881 void *mq_init_cls,
883 void *notify_cb_cls,
885{
887
889 ch->cfg = cfg;
890 ch->config_section = config_section;
891 ch->addr_prefix = addr_prefix;
892 ch->mq_init = mq_init;
893 ch->mq_init_cls = mq_init_cls;
894 ch->notify_cb = notify_cb;
895 ch->notify_cb_cls = notify_cb_cls;
896 ch->cc = cc;
897 ch->sb = sb;
898 reconnect (ch);
899 if (GNUNET_OK !=
902 "MAX_QUEUE_LENGTH",
903 &ch->max_queue_length))
904 ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
905 if (NULL == ch->mq)
906 {
907 GNUNET_free (ch);
908 return NULL;
909 }
910 return ch;
911}
912
913
919void
922{
923 disconnect (ch);
924 while (NULL != ch->ai_head)
925 {
926 GNUNET_break (0); /* communicator forgot to remove address, warn! */
928 }
929 GNUNET_free (ch);
930}
931
932
933/* ************************* Receiving *************************** */
934
935
936int
939 const struct GNUNET_PeerIdentity *sender,
940 const struct GNUNET_MessageHeader *msg,
941 struct GNUNET_TIME_Relative expected_addr_validity,
943 void *cb_cls)
944{
945 struct GNUNET_MQ_Envelope *env;
947 uint16_t msize;
948
949
951 "communicator receive\n");
952
953 if (NULL == ch->mq)
954 return GNUNET_SYSERR;
955 if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length))
956 {
957 GNUNET_log (
959 "Dropping message: transport is too slow, queue length %llu exceeded\n",
960 ch->max_queue_length);
961 return GNUNET_NO;
962 }
963
964 msize = ntohs (msg->size);
965 env =
967 if (NULL == env)
968 {
969 GNUNET_break (0);
970 return GNUNET_SYSERR;
971 }
973 GNUNET_TIME_relative_hton (expected_addr_validity);
974 im->sender = *sender;
975 // FIXME: this is expensive, would be better if we would
976 // re-design the API to allow us to create the envelope first,
977 // and then have the application fill in the body so we do
978 // not have to memcpy()
979 memcpy (&im[1], msg, msize);
980 im->fc_on = htonl (GNUNET_NO);
981 if (NULL != cb)
982 {
983 struct FlowControl *fc;
984
985 im->fc_on = htonl (GNUNET_YES);
986 im->fc_id = ch->fc_gen++;
987 fc = GNUNET_new (struct FlowControl);
988 fc->sender = *sender;
989 fc->id = im->fc_id;
990 fc->cb = cb;
991 fc->cb_cls = cb_cls;
992 GNUNET_CONTAINER_DLL_insert (ch->fc_head, ch->fc_tail, fc);
994 "Created flow control id %" PRIu64 " for sender %s\n",
995 fc->id,
996 GNUNET_i2s (&fc->sender));
997 }
999 return GNUNET_OK;
1000}
1001
1002
1003/* ************************* Discovery *************************** */
1004
1005
1009 const struct GNUNET_PeerIdentity *peer,
1010 const char *address,
1011 uint32_t mtu,
1012 uint64_t q_len,
1013 uint32_t priority,
1016 struct GNUNET_MQ_Handle *mq)
1017{
1019
1020 // Do not notify the service if there is no initial capacity.
1021 GNUNET_assert (0 < q_len);
1022
1024 qh->ch = ch;
1025 qh->peer = *peer;
1027 qh->nt = nt;
1028 qh->mtu = mtu;
1029 qh->q_len = q_len;
1030 qh->priority = priority;
1031 qh->cs = cs;
1032 qh->mq = mq;
1033 qh->queue_id = ch->queue_gen++;
1034 GNUNET_CONTAINER_DLL_insert (ch->queue_head, ch->queue_tail, qh);
1035 send_add_queue (qh);
1036 return qh;
1037}
1038
1039
1040void
1043 const struct GNUNET_TRANSPORT_QueueHandle *u_qh,
1044 uint64_t q_len,
1045 uint32_t priority)
1046{
1048
1049 for (qh = ch->queue_head; NULL != qh; qh = qh->next)
1050 {
1051 if (u_qh == qh)
1052 break;
1053 }
1054 GNUNET_assert (NULL != qh);
1055 qh->q_len = q_len;
1056 qh->priority = priority;
1057 send_update_queue (qh);
1058}
1059
1060
1067void
1069{
1071
1072 send_del_queue (qh);
1073 GNUNET_CONTAINER_DLL_remove (ch->queue_head, ch->queue_tail, qh);
1074 GNUNET_MQ_destroy (qh->mq);
1075 GNUNET_free (qh->address);
1076 GNUNET_free (qh);
1077}
1078
1079
1092 const char *address,
1095{
1097
1099 ai->ch = ch;
1101 ai->nt = nt;
1103 ai->aid = ch->aid_gen++;
1104 GNUNET_CONTAINER_DLL_insert (ch->ai_head, ch->ai_tail, ai);
1106 return ai;
1107}
1108
1109
1116void
1119{
1121
1123 GNUNET_CONTAINER_DLL_remove (ch->ai_head, ch->ai_tail, ai);
1125 GNUNET_free (ai);
1126 ai = NULL;
1127}
1128
1129
1135void
1138{
1139 struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head;
1140 while (NULL != ai)
1141 {
1142 struct GNUNET_TRANSPORT_AddressIdentifier *ai_next = ai->next;
1144 ai = ai_next;
1145 }
1146}
1147
1148
1149/* ************************* Backchannel *************************** */
1150
1151
1152void
1155 const struct GNUNET_PeerIdentity *pid,
1156 const char *comm,
1157 const struct GNUNET_MessageHeader *header)
1158{
1159 struct GNUNET_MQ_Envelope *env;
1161 size_t slen = strlen (comm) + 1;
1162 uint16_t mlen = ntohs (header->size);
1163
1164 GNUNET_assert (mlen + slen + sizeof(*cb) < UINT16_MAX);
1165 env =
1167 slen + mlen,
1169 ;
1170 cb->pid = *pid;
1171 memcpy (&cb[1], header, mlen);
1172 memcpy (((char *) &cb[1]) + mlen, comm, slen);
1173 GNUNET_MQ_send (ch->mq, env);
1174}
1175
1176
1177/* ************************* Burst *************************** */
1178
1179void
1182 *ch)
1183{
1184 struct GNUNET_MQ_Envelope *env;
1186
1188 GNUNET_MQ_send (ch->mq, env);
1189}
1190
1191
1192/* 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:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
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 void start_burst(const char *addr, struct GNUNET_TIME_Relative rtt, struct GNUNET_PeerIdentity *pid)
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.
void(* GNUNET_TRANSPORT_StartBurstNotify)(const char *address, struct GNUNET_TIME_Relative rtt, struct GNUNET_PeerIdentity *peer)
Function to start burst, if request by transport service.
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_burst_finished(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
The communicator tells the transport service that it finished the burst.
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 (...
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_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, 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.
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:1060
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_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_BURST_FINISHED
Burst message we send to another peer for hole punching.
#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_START_BURST
Burst message we send to another peer for hole punching.
#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_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:630
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:620
#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.
uint64_t rel_value_us
The actual value.
Add address to the list.
Definition: transport.h:287
struct GNUNET_TIME_RelativeNBO expiration
When does the address expire?
Definition: transport.h:301
uint32_t nt
An enum GNUNET_NetworkType in NBO.
Definition: transport.h:306
Add queue to the transport.
Definition: transport.h:401
uint32_t nt
An enum GNUNET_NetworkType in NBO.
Definition: transport.h:420
uint32_t mtu
Maximum transmission unit, in NBO.
Definition: transport.h:425
uint64_t q_len
Queue length, in NBO.
Definition: transport.h:431
uint32_t priority
Priority of the queue in relation to other queues.
Definition: transport.h:436
uint32_t qid
Queue identifier (used to identify the queue).
Definition: transport.h:410
struct GNUNET_PeerIdentity receiver
Receiver that can be addressed via the queue.
Definition: transport.h:415
uint32_t cs
An enum GNUNET_TRANSPORT_ConnectionStatus in NBO.
Definition: transport.h:441
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
uint32_t can_burst
The communicator can do burst msgs.
Definition: transport.h:277
Message from transport to communicator passing along a backchannel message from the given peer pid.
Definition: transport.h:655
struct GNUNET_PeerIdentity pid
Origin peer.
Definition: transport.h:670
Message from communicator to transport service asking for transmission of a backchannel message with ...
Definition: transport.h:626
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL.
Definition: transport.h:630
struct GNUNET_PeerIdentity pid
Target peer.
Definition: transport.h:640
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).
GNUNET_TRANSPORT_StartBurstNotify sb
Function to start a burst, requested by the transport service.
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:545
uint32_t request_id
Unique ID for the request.
Definition: transport.h:555
Transport tells communicator that it wants a new queue.
Definition: transport.h:521
uint32_t request_id
Unique ID for the request.
Definition: transport.h:530
struct GNUNET_PeerIdentity receiver
Receiver that can be addressed via the queue.
Definition: transport.h:535
Remove address from the list.
Definition: transport.h:316
uint32_t aid
Address identifier.
Definition: transport.h:325
Remove queue, it is no longer available.
Definition: transport.h:499
struct GNUNET_PeerIdentity receiver
Receiver that can be addressed via the queue.
Definition: transport.h:513
uint32_t qid
Address identifier.
Definition: transport.h:508
Transport informs us about being done with an incoming message.
Definition: transport.h:374
struct GNUNET_PeerIdentity sender
Sender identifier of the original message.
Definition: transport.h:393
uint64_t fc_id
Which message is being ACKed?
Definition: transport.h:388
Inform transport about an incoming message.
Definition: transport.h:333
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:353
struct GNUNET_PeerIdentity sender
Sender identifier.
Definition: transport.h:358
uint32_t fc_on
Do we use flow control or not?
Definition: transport.h:342
uint64_t fc_id
64-bit number to identify the matching ACK.
Definition: transport.h:347
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:592
uint32_t status
Success (GNUNET_OK), failure (GNUNET_SYSERR).
Definition: transport.h:601
uint64_t mid
Message ID of the original message.
Definition: transport.h:606
uint32_t qid
Queue ID for the queue which was used to send the message.
Definition: transport.h:611
struct GNUNET_PeerIdentity receiver
Receiver identifier.
Definition: transport.h:616
Inform communicator about transport's desire to send a message.
Definition: transport.h:563
uint32_t qid
Which queue should we use?
Definition: transport.h:572
uint64_t mid
Message ID, used for flow control.
Definition: transport.h:577
struct GNUNET_PeerIdentity receiver
Receiver identifier.
Definition: transport.h:582
Message from transport to communicator to start a burst.
Definition: transport.h:680
struct GNUNET_TIME_RelativeNBO rtt
Definition: transport.h:691
struct GNUNET_PeerIdentity pid
Target peer.
Definition: transport.h:689
struct GNUNET_PeerIdentity receiver
Receiver that can be addressed via the queue.
Definition: transport.h:465
uint32_t cs
An enum GNUNET_TRANSPORT_ConnectionStatus in NBO.
Definition: transport.h:491
uint32_t nt
An enum GNUNET_NetworkType in NBO.
Definition: transport.h:470
uint32_t priority
Priority of the queue in relation to other queues.
Definition: transport.h:486
uint32_t mtu
Maximum transmission unit, in NBO.
Definition: transport.h:475
uint64_t q_len
Queue length, in NBO.
Definition: transport.h:481
uint32_t qid
Queue identifier (used to identify the queue).
Definition: transport.h:460
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 int check_start_burst(void *cls, const struct GNUNET_TRANSPORT_StartBurst *sb)
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 handle_start_burst(void *cls, const struct GNUNET_TRANSPORT_StartBurst *sb)
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.