GNUnet  0.19.4
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"
31 #include "transport.h"
32 
33 
39 #define DEFAULT_MAX_QUEUE_LENGTH 16
40 
41 
46 {
50  struct FlowControl *next;
51 
55  struct FlowControl *prev;
56 
61 
65  void *cb_cls;
66 
71 
75  uint64_t id;
76 };
77 
78 
83 struct AckPending
84 {
88  struct AckPending *next;
89 
93  struct AckPending *prev;
94 
99 
104 
108  uint64_t mid;
109 
113  uint32_t qid;
114 };
115 
116 
121 {
126 
131 
136 
141 
146 
151 
156 
161 
166 
170  const char *config_section;
171 
175  const char *addr_prefix;
176 
182 
186  void *mq_init_cls;
187 
194 
199 
204 
208  unsigned long long max_queue_length;
209 
213  uint64_t fc_gen;
214 
219  uint32_t aid_gen;
220 
224  uint32_t queue_gen;
225 
230 };
231 
232 
238 {
243 
248 
253 
257  char *address;
258 
263 
267  struct GNUNET_PeerIdentity peer;
268 
272  enum GNUNET_NetworkType nt;
273 
278 
282  uint32_t queue_id;
283 
287  uint32_t mtu;
288 
292  uint64_t q_len;
296  uint32_t priority;
297 };
298 
299 
305 {
310 
315 
320 
324  char *address;
325 
331 
336  uint32_t aid;
337 
341  enum GNUNET_NetworkType nt;
342 };
343 
344 
350 static void
352 
353 
360 static void
362 {
363  struct GNUNET_MQ_Envelope *env;
364  struct GNUNET_TRANSPORT_AddAddressMessage *aam;
365 
366  if (NULL == ai->ch->mq)
367  return;
368  env = GNUNET_MQ_msg_extra (aam,
369  strlen (ai->address) + 1,
371  aam->expiration = GNUNET_TIME_relative_hton (ai->expiration);
372  aam->nt = htonl ((uint32_t) ai->nt);
373  memcpy (&aam[1], ai->address, strlen (ai->address) + 1);
374  GNUNET_MQ_send (ai->ch->mq, env);
375 }
376 
377 
384 static void
386 {
387  struct GNUNET_MQ_Envelope *env;
388  struct GNUNET_TRANSPORT_DelAddressMessage *dam;
389 
390  if (NULL == ai->ch->mq)
391  return;
393  dam->aid = htonl (ai->aid);
394  GNUNET_MQ_send (ai->ch->mq, env);
395 }
396 
397 
404 static void
406 {
407  struct GNUNET_MQ_Envelope *env;
408  struct GNUNET_TRANSPORT_AddQueueMessage *aqm;
409 
410  if (NULL == qh->ch->mq)
411  return;
413  "Sending `GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP` message\n");
414  env = GNUNET_MQ_msg_extra (aqm,
415  strlen (qh->address) + 1,
417  aqm->qid = htonl (qh->queue_id);
418  aqm->receiver = qh->peer;
419  aqm->nt = htonl ((uint32_t) qh->nt);
420  aqm->mtu = htonl (qh->mtu);
421  aqm->q_len = GNUNET_htonll (qh->q_len);
422  aqm->priority = htonl (qh->priority);
423  aqm->cs = htonl ((uint32_t) qh->cs);
424  memcpy (&aqm[1], qh->address, strlen (qh->address) + 1);
425  GNUNET_MQ_send (qh->ch->mq, env);
426 }
427 
428 
435 static void
437 {
438  struct GNUNET_MQ_Envelope *env;
439  struct GNUNET_TRANSPORT_UpdateQueueMessage *uqm;
440 
441  if (NULL == qh->ch->mq)
442  return;
444  uqm->qid = htonl (qh->queue_id);
445  uqm->receiver = qh->peer;
446  uqm->nt = htonl ((uint32_t) qh->nt);
447  uqm->mtu = htonl (qh->mtu);
448  uqm->q_len = GNUNET_htonll (qh->q_len);
449  uqm->priority = htonl (qh->priority);
450  uqm->cs = htonl ((uint32_t) qh->cs);
451  GNUNET_MQ_send (qh->ch->mq, env);
452 }
453 
454 
461 static void
463 {
464  struct GNUNET_MQ_Envelope *env;
465  struct GNUNET_TRANSPORT_DelQueueMessage *dqm;
466 
467  if (NULL == qh->ch->mq)
468  return;
470  dqm->qid = htonl (qh->queue_id);
471  dqm->receiver = qh->peer;
472  GNUNET_MQ_send (qh->ch->mq, env);
473 }
474 
475 
484 static void
486 {
487  struct FlowControl *fcn;
488  struct AckPending *apn;
489 
490  for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn)
491  {
492  fcn = fc->next;
493  GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
494  fc->cb (fc->cb_cls, GNUNET_SYSERR);
495  GNUNET_free (fc);
496  }
497  for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn)
498  {
499  apn = ap->next;
500  GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
501  GNUNET_free (ap);
502  }
503  if (NULL == ch->mq)
504  return;
506  ch->mq = NULL;
507 }
508 
509 
513 static void
514 error_handler (void *cls, enum GNUNET_MQ_Error error)
515 {
517 
519  "MQ failure %d, reconnecting to transport service.\n",
520  error);
521  disconnect (ch);
522  /* TODO: maybe do this with exponential backoff/delay */
523  reconnect (ch);
524 }
525 
526 
534 static void
536  void *cls,
537  const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack)
538 {
540 
541  for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next)
542  {
543  if ((fc->id == incoming_ack->fc_id) &&
544  (0 == memcmp (&fc->sender,
545  &incoming_ack->sender,
546  sizeof(struct GNUNET_PeerIdentity))))
547  {
549  "Done with message with flow control id %" PRIu64
550  " for sender %s from sender %s\n",
551  incoming_ack->fc_id,
552  GNUNET_i2s (&fc->sender),
553  GNUNET_i2s (&incoming_ack->sender));
554  GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
555  fc->cb (fc->cb_cls, GNUNET_OK);
556  GNUNET_free (fc);
557  return;
558  }
559  }
561  "Message with flow control id %" PRIu64
562  " from sender %s not found\n",
563  incoming_ack->fc_id,
564  GNUNET_i2s (&incoming_ack->sender));
565  GNUNET_break (0);
566  disconnect (ch);
567  /* TODO: maybe do this with exponential backoff/delay */
568  reconnect (ch);
569 }
570 
571 
580 static int
581 check_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
582 {
583  (void) cls;
585  return GNUNET_OK;
586 }
587 
588 
595 static void
596 handle_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
597 {
599  const char *addr = (const char *) &cq[1];
600  struct GNUNET_TRANSPORT_CreateQueueResponse *cqr;
601  struct GNUNET_MQ_Envelope *env;
602 
603  if (GNUNET_OK != ch->mq_init (ch->mq_init_cls, &cq->receiver, addr))
604  {
606  "Address `%s' invalid for this communicator\n",
607  addr);
609  }
610  else
611  {
613  }
614  cqr->request_id = cq->request_id;
615  GNUNET_MQ_send (ch->mq, env);
616 }
617 
618 
627 static int
628 check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
629 {
630  (void) cls;
632  return GNUNET_OK;
633 }
634 
635 
645 static void
647  int status,
648  const struct GNUNET_PeerIdentity *receiver,
649  uint64_t mid,
650  uint32_t qid)
651 {
652  struct GNUNET_MQ_Envelope *env;
653  struct GNUNET_TRANSPORT_SendMessageToAck *ack;
654 
656  ack->status = htonl (status);
657  ack->mid = mid;
658  ack->qid = qid;
659  ack->receiver = *receiver;
660  GNUNET_MQ_send (ch->mq, env);
661 }
662 
663 
670 static void
671 send_ack_cb (void *cls)
672 {
673  struct AckPending *ap = cls;
675 
676  GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
677  send_ack (ch, GNUNET_OK, &ap->receiver, ap->mid, ap->qid);
678  GNUNET_free (ap);
679 }
680 
681 
688 static void
689 handle_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
690 {
692  const struct GNUNET_MessageHeader *mh;
693  struct GNUNET_MQ_Envelope *env;
694  struct AckPending *ap;
695  struct GNUNET_TRANSPORT_QueueHandle *qh;
696 
697  for (qh = ch->queue_head; NULL != qh; qh = qh->next)
698  if ((qh->queue_id == ntohl (smt->qid)) &&
699  (0 == memcmp (&qh->peer,
700  &smt->receiver,
701  sizeof(struct GNUNET_PeerIdentity))))
702  break;
703  if (NULL == qh)
704  {
705  /* queue is already gone, tell transport this one failed */
707  "Transmission failed, queue no longer exists.\n");
708  send_ack (ch, GNUNET_NO, &smt->receiver, smt->mid, smt->qid);
709  return;
710  }
711  ap = GNUNET_new (struct AckPending);
712  ap->ch = ch;
713  ap->receiver = smt->receiver;
714  ap->mid = smt->mid;
715  ap->qid = smt->qid;
716  GNUNET_CONTAINER_DLL_insert (ch->ap_head, ch->ap_tail, ap);
717  mh = (const struct GNUNET_MessageHeader *) &smt[1];
720  GNUNET_MQ_send (qh->mq, env);
721 }
722 
723 
732 static int
734  void *cls,
735  const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
736 {
737  (void) cls;
739  return GNUNET_OK;
740 }
741 
742 
749 static void
751  void *cls,
752  const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
753 {
755  if (NULL != ch->notify_cb)
756  ch->notify_cb (ch->notify_cb_cls,
757  &bi->pid,
758  (const struct GNUNET_MessageHeader *) &bi[1]);
759  else
760  GNUNET_log (
762  _ ("Dropped backchanel message: handler not provided by communicator\n"));
763 }
764 
765 
771 static void
773 {
775  { GNUNET_MQ_hd_fixed_size (incoming_ack,
777  struct GNUNET_TRANSPORT_IncomingMessageAck,
778  ch),
779  GNUNET_MQ_hd_var_size (create_queue,
781  struct GNUNET_TRANSPORT_CreateQueue,
782  ch),
785  struct GNUNET_TRANSPORT_SendMessageTo,
786  ch),
788  backchannel_incoming,
790  struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming,
791  ch),
793  struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam;
794  struct GNUNET_MQ_Envelope *env;
795 
796  ch->mq =
797  GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
798  if (NULL == ch->mq)
799  return;
800  env = GNUNET_MQ_msg_extra (cam,
801  strlen (ch->addr_prefix) + 1,
803  cam->cc = htonl ((uint32_t) ch->cc);
804  memcpy (&cam[1], ch->addr_prefix, strlen (ch->addr_prefix) + 1);
805  GNUNET_MQ_send (ch->mq, env);
806  for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
807  ai = ai->next)
809  for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh;
810  qh = qh->next)
811  send_add_queue (qh);
812 }
813 
814 
817  const struct GNUNET_CONFIGURATION_Handle *cfg,
818  const char *config_section,
819  const char *addr_prefix,
822  void *mq_init_cls,
824  void *notify_cb_cls)
825 {
827 
829  ch->cfg = cfg;
830  ch->config_section = config_section;
831  ch->addr_prefix = addr_prefix;
832  ch->mq_init = mq_init;
833  ch->mq_init_cls = mq_init_cls;
834  ch->notify_cb = notify_cb;
835  ch->notify_cb_cls = notify_cb_cls;
836  ch->cc = cc;
837  reconnect (ch);
838  if (GNUNET_OK !=
841  "MAX_QUEUE_LENGTH",
842  &ch->max_queue_length))
843  ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
844  if (NULL == ch->mq)
845  {
846  GNUNET_free (ch);
847  return NULL;
848  }
849  return ch;
850 }
851 
852 
858 void
861 {
862  disconnect (ch);
863  while (NULL != ch->ai_head)
864  {
865  GNUNET_break (0); /* communicator forgot to remove address, warn! */
867  }
868  GNUNET_free (ch);
869 }
870 
871 
872 /* ************************* Receiving *************************** */
873 
874 
875 int
878  const struct GNUNET_PeerIdentity *sender,
879  const struct GNUNET_MessageHeader *msg,
880  struct GNUNET_TIME_Relative expected_addr_validity,
882  void *cb_cls)
883 {
884  struct GNUNET_MQ_Envelope *env;
885  struct GNUNET_TRANSPORT_IncomingMessage *im;
886  uint16_t msize;
887 
888 
890  "communicator receive\n");
891 
892  if (NULL == ch->mq)
893  return GNUNET_SYSERR;
894  if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length))
895  {
896  GNUNET_log (
898  "Dropping message: transport is too slow, queue length %llu exceeded\n",
899  ch->max_queue_length);
900  return GNUNET_NO;
901  }
902 
903  msize = ntohs (msg->size);
904  env =
906  if (NULL == env)
907  {
908  GNUNET_break (0);
909  return GNUNET_SYSERR;
910  }
911  im->expected_address_validity =
912  GNUNET_TIME_relative_hton (expected_addr_validity);
913  im->sender = *sender;
914  // FIXME: this is expensive, would be better if we would
915  // re-design the API to allow us to create the envelope first,
916  // and then have the application fill in the body so we do
917  // not have to memcpy()
918  memcpy (&im[1], msg, msize);
919  im->fc_on = htonl (GNUNET_NO);
920  if (NULL != cb)
921  {
922  struct FlowControl *fc;
923 
924  im->fc_on = htonl (GNUNET_YES);
925  im->fc_id = ch->fc_gen++;
926  fc = GNUNET_new (struct FlowControl);
927  fc->sender = *sender;
928  fc->id = im->fc_id;
929  fc->cb = cb;
930  fc->cb_cls = cb_cls;
931  GNUNET_CONTAINER_DLL_insert (ch->fc_head, ch->fc_tail, fc);
933  "Created flow control id %" PRIu64 " for sender %s\n",
934  fc->id,
935  GNUNET_i2s (&fc->sender));
936  }
937  GNUNET_MQ_send (ch->mq, env);
938  return GNUNET_OK;
939 }
940 
941 
942 /* ************************* Discovery *************************** */
943 
944 
948  const struct GNUNET_PeerIdentity *peer,
949  const char *address,
950  uint32_t mtu,
951  uint64_t q_len,
952  uint32_t priority,
953  enum GNUNET_NetworkType nt,
955  struct GNUNET_MQ_Handle *mq)
956 {
957  struct GNUNET_TRANSPORT_QueueHandle *qh;
958 
959  // Do not notify the service if there is no intial capacity.
960  GNUNET_assert (0 < q_len);
961 
963  qh->ch = ch;
964  qh->peer = *peer;
965  qh->address = GNUNET_strdup (address);
966  qh->nt = nt;
967  qh->mtu = mtu;
968  qh->q_len = q_len;
969  qh->priority = priority;
970  qh->cs = cs;
971  qh->mq = mq;
972  qh->queue_id = ch->queue_gen++;
973  GNUNET_CONTAINER_DLL_insert (ch->queue_head, ch->queue_tail, qh);
974  send_add_queue (qh);
975  return qh;
976 }
977 
978 
979 void
982  const struct GNUNET_TRANSPORT_QueueHandle *u_qh,
983  uint64_t q_len,
984  uint32_t priority)
985 {
986  struct GNUNET_TRANSPORT_QueueHandle *qh;
987 
988  for (qh = ch->queue_head; NULL != qh; qh = qh->next)
989  {
990  if (u_qh == qh)
991  break;
992  }
993  GNUNET_assert (NULL != qh);
994  qh->q_len = q_len;
995  qh->priority = priority;
996  send_update_queue (qh);
997 }
998 
999 
1006 void
1008 {
1010 
1011  send_del_queue (qh);
1012  GNUNET_CONTAINER_DLL_remove (ch->queue_head, ch->queue_tail, qh);
1013  GNUNET_MQ_destroy (qh->mq);
1014  GNUNET_free (qh->address);
1015  GNUNET_free (qh);
1016 }
1017 
1018 
1031  const char *address,
1032  enum GNUNET_NetworkType nt,
1034 {
1036 
1038  ai->ch = ch;
1040  ai->nt = nt;
1042  ai->aid = ch->aid_gen++;
1043  GNUNET_CONTAINER_DLL_insert (ch->ai_head, ch->ai_tail, ai);
1044  send_add_address (ai);
1045  return ai;
1046 }
1047 
1048 
1055 void
1058 {
1060 
1061  send_del_address (ai);
1062  GNUNET_CONTAINER_DLL_remove (ch->ai_head, ch->ai_tail, ai);
1063  GNUNET_free (ai->address);
1064  GNUNET_free (ai);
1065  ai = NULL;
1066 }
1067 
1068 
1074 void
1077 {
1078  struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head;
1079  while (NULL != ai)
1080  {
1081  struct GNUNET_TRANSPORT_AddressIdentifier *ai_next = ai->next;
1083  ai = ai_next;
1084  }
1085 }
1086 
1087 
1088 /* ************************* Backchannel *************************** */
1089 
1090 
1091 void
1094  const struct GNUNET_PeerIdentity *pid,
1095  const char *comm,
1096  const struct GNUNET_MessageHeader *header)
1097 {
1098  struct GNUNET_MQ_Envelope *env;
1099  struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb;
1100  size_t slen = strlen (comm) + 1;
1101  uint16_t mlen = ntohs (header->size);
1102 
1103  GNUNET_assert (mlen + slen + sizeof(*cb) < UINT16_MAX);
1104  env =
1105  GNUNET_MQ_msg_extra (cb,
1106  slen + mlen,
1108  cb->pid = *pid;
1109  memcpy (&cb[1], header, mlen);
1110  memcpy (((char *) &cb[1]) + mlen, comm, slen);
1111  GNUNET_MQ_send (ch->mq, env);
1112 }
1113 
1114 
1115 /* end of transport_api2_communication.c */
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 char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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 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 struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static char * address
GNS address for this phone.
uint16_t status
See PRISM_STATUS_*-constants.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static void send_msg(void *cls)
Function called to notify a client about the socket begin ready to queue more data.
Bandwidth allocation API for the transport service.
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...
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_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.
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.
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.
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
@ 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.
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:304
#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:62
#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:77
#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:638
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:533
#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:683
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:39
#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.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).
Time for relative time used by GNUnet, in microseconds.
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.
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.
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.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
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.