GNUnet  0.11.x
transport-testing2.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2019 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 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_constants.h"
31 #include "transport-testing2.h"
33 #include "gnunet_hello_lib.h"
34 #include "gnunet_signatures.h"
35 #include "transport.h"
36 #include <inttypes.h>
37 
38 #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__)
39 
40 struct MyClient
41 {
42  struct MyClient *prev;
43  struct MyClient *next;
48 
53 
58 
59 };
60 
65 {
71 
76 
81 
85  char *cfg_filename;
86 
88 
93 
99 
100 
105 
110 
115 
120 
125 
130 
134  char *c_address;
135 
140 
145 
146  /* Callbacks + Closures */
152 
157 
162 
167 
172 
177 
182 
186  void *cb_cls;
187 
192 };
193 
194 
199 {
204 
213 
218 
222  uint32_t qid;
223 
227  uint64_t mid;
228 
232  uint32_t nt;
233 
237  uint32_t mtu;
238 
242  uint64_t q_len;
243 
247  uint32_t priority;
248 
252  uint32_t cs;
253 
258 
263 };
264 
265 
270 {
271 };
272 
273 
283 static int
285  void *cls,
286  const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
287 {
288  uint16_t size;
289 
290  size = ntohs (msg->header.size) - sizeof(*msg);
291  if (0 == size)
292  return GNUNET_OK; /* receive-only communicator */
294  return GNUNET_OK;
295 }
296 
297 
306 static void
308  void *cls,
309  const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
310 {
311  struct MyClient *client = cls;
313  client->tc;
314  uint16_t size;
315  tc_h->c_mq = client->c_mq;
316 
317  size = ntohs (msg->header.size) - sizeof(*msg);
318  if (0 == size)
319  {
321  return; /* receive-only communicator */
322  }
323  tc_h->c_characteristics = ntohl (msg->cc);
324  tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]);
325  if (NULL != tc_h->communicator_available_cb)
326  {
327  LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n");
328  tc_h->communicator_available_cb (tc_h->cb_cls,
329  tc_h,
330  tc_h->c_characteristics,
331  tc_h->c_addr_prefix);
332  }
334  LOG (GNUNET_ERROR_TYPE_DEBUG, "finished communicator_available_cb()\n");
335 
336 }
337 
338 
346 static int
348  const struct
349  GNUNET_TRANSPORT_CommunicatorBackchannel *msg)
350 {
351  // struct TransportClient *tc = cls;
352 
353  // if (CT_COMMUNICATOR != tc->type)
354  // {
355  // GNUNET_break (0);
356  // return GNUNET_SYSERR;
357  // }
358  // GNUNET_MQ_check_boxed_message (msg);
359  return GNUNET_OK;
360 }
361 
362 
371 static void
373  const struct
374  GNUNET_TRANSPORT_CommunicatorBackchannel *
375  bc_msg)
376 {
377  struct MyClient *client = cls;
379  client->tc;
381  struct GNUNET_MessageHeader *msg;
382  msg = (struct GNUNET_MessageHeader *) &bc_msg[1];
383  uint16_t isize = ntohs (msg->size);
384  const char *target_communicator = ((const char *) msg) + isize;
385  struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *cbi;
386  struct GNUNET_MQ_Envelope *env;
387 
389  "Received backchannel message\n");
390  if (tc_h->bc_enabled != GNUNET_YES)
391  {
393  return;
394  }
395  /* Find client providing this communicator */
396  /* Finally, deliver backchannel message to communicator */
398  "Delivering backchannel message of type %u to %s\n",
399  ntohs (msg->type),
400  target_communicator);
401  other_tc_h = tc_h->bc_cb (tc_h, msg, (struct
402  GNUNET_PeerIdentity*) &bc_msg->pid);
403  env = GNUNET_MQ_msg_extra (
404  cbi,
405  isize,
407  cbi->pid = tc_h->peer_id;
408  memcpy (&cbi[1], msg, isize);
409 
410 
411  GNUNET_MQ_send (other_tc_h->c_mq, env);
413 }
414 
415 
423 static int
424 check_add_address (void *cls,
425  const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
426 {
427  // if (CT_COMMUNICATOR != tc->type)
428  // {
429  // GNUNET_break (0);
430  // return GNUNET_SYSERR;
431  // }
433  return GNUNET_OK;
434 }
435 
436 
445 static void
447  const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
448 {
449  struct MyClient *client = cls;
451  client->tc;
452  uint16_t size;
453  size = ntohs (msg->header.size) - sizeof(*msg);
454  if (0 == size)
455  return; /* receive-only communicator */
456  LOG (GNUNET_ERROR_TYPE_DEBUG, "received add address cb %u\n", size);
457  tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]);
458  if (NULL != tc_h->add_address_cb)
459  {
460  LOG (GNUNET_ERROR_TYPE_DEBUG, "calling add_address_cb()\n");
461  tc_h->add_address_cb (tc_h->cb_cls,
462  tc_h,
463  tc_h->c_address,
464  GNUNET_TIME_relative_ntoh (msg->expiration),
465  msg->aid,
466  ntohl (msg->nt));
467  }
469 }
470 
471 
479 static int
481  const struct GNUNET_TRANSPORT_IncomingMessage *msg)
482 {
483  // struct TransportClient *tc = cls;
484 
485  // if (CT_COMMUNICATOR != tc->type)
486  // {
487  // GNUNET_break (0);
488  // return GNUNET_SYSERR;
489  // }
491  return GNUNET_OK;
492 }
493 
494 
503 static void
505  const struct GNUNET_TRANSPORT_IncomingMessage *inc_msg)
506 {
507  struct MyClient *client = cls;
509  client->tc;
510  struct GNUNET_MessageHeader *msg;
511  msg = (struct GNUNET_MessageHeader *) &inc_msg[1];
512  size_t payload_len = ntohs (msg->size) - sizeof (struct
514  if (NULL != tc_h->incoming_msg_cb)
515  {
516  tc_h->incoming_msg_cb (tc_h->cb_cls,
517  tc_h,
518  (char*) &msg[1],
519  payload_len);
520  }
521  else
522  {
524  "Incoming message from communicator but no handler!\n");
525  }
526  if (GNUNET_YES == ntohl (inc_msg->fc_on))
527  {
528  /* send ACK when done to communicator for flow control! */
529  struct GNUNET_MQ_Envelope *env;
530  struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
531 
533  GNUNET_assert (NULL != env);
534  ack->reserved = htonl (0);
535  ack->fc_id = inc_msg->fc_id;
536  ack->sender = inc_msg->sender;
537  GNUNET_MQ_send (tc_h->c_mq, env);
538  }
539 
541 }
542 
543 
550 static void
552  const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
553 {
554  struct MyClient *client = cls;
556  client->tc;
557 
558  if (NULL != tc_h->queue_create_reply_cb)
559  {
560  tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_YES);
561  }
563 }
564 
565 
575 static void
577  void *cls,
578  const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
579 {
580  struct MyClient *client = cls;
582  client->tc;
583 
584  if (NULL != tc_h->queue_create_reply_cb)
585  {
586  tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_NO);
587  }
589 }
590 
591 
598 static int
600  const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
601 {
603  return GNUNET_OK;
604 }
605 
606 
615 static void
617  const struct GNUNET_TRANSPORT_AddQueueMessage *msg)
618 {
619  struct MyClient *client = cls;
621  client->tc;
623 
625  "Got queue with ID %u\n", msg->qid);
626  for (tc_queue = tc_h->queue_head; NULL != tc_queue; tc_queue = tc_queue->next)
627  {
628  if (tc_queue->qid == msg->qid)
629  break;
630  }
631  if (NULL == tc_queue)
632  {
633  tc_queue =
635  tc_queue->tc_h = tc_h;
636  tc_queue->qid = msg->qid;
637  tc_queue->peer_id = msg->receiver;
638  GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue);
639  }
640  GNUNET_assert (tc_queue->qid == msg->qid);
641  GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
642  tc_queue->nt = msg->nt;
643  tc_queue->mtu = ntohl (msg->mtu);
644  tc_queue->cs = msg->cs;
645  tc_queue->priority = ntohl (msg->priority);
646  tc_queue->q_len = GNUNET_ntohll (msg->q_len);
647  if (NULL != tc_h->add_queue_cb)
648  {
649  tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue, tc_queue->mtu);
650  }
652 }
653 
654 
663 static void
665  const struct
666  GNUNET_TRANSPORT_UpdateQueueMessage *msg)
667 {
668  struct MyClient *client = cls;
670  client->tc;
672 
674  "Received queue update message for %u with q_len %"PRIu64"\n",
675  msg->qid, GNUNET_ntohll(msg->q_len));
676  tc_queue = tc_h->queue_head;
677  if (NULL != tc_queue)
678  {
679  while (tc_queue->qid != msg->qid)
680  {
681  tc_queue = tc_queue->next;
682  }
683  }
684  GNUNET_assert (tc_queue->qid == msg->qid);
685  GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
686  tc_queue->nt = msg->nt;
687  tc_queue->mtu = ntohl (msg->mtu);
688  tc_queue->cs = msg->cs;
689  tc_queue->priority = ntohl (msg->priority);
690  tc_queue->q_len += GNUNET_ntohll (msg->q_len);
692 }
693 
694 
700 static void
701 shutdown_service (void *cls)
702 {
703  struct GNUNET_SERVICE_Handle *h = cls;
704 
706 }
707 
708 
718 static void *
719 connect_cb (void *cls,
721  struct GNUNET_MQ_Handle *mq)
722 {
724  struct MyClient *new_c;
725 
726  LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected to %p.\n",
727  client, tc_h);
728  new_c = GNUNET_new (struct MyClient);
729  new_c->client = client;
730  new_c->c_mq = mq;
731  new_c->tc = tc_h;
733  tc_h->client_tail,
734  new_c);
735 
736  if (NULL == tc_h->queue_head)
737  return new_c;
738  /* Iterate over queues. They are yet to be opened. Request opening. */
739  for (struct
741  tc_h->queue_head;
742  NULL != tc_queue_iter;
743  tc_queue_iter = tc_queue_iter->next)
744  {
745  if (NULL == tc_queue_iter->open_queue_env)
746  continue;
747  /* Send the previously created mq envelope to request the creation of the
748  * queue. */
749  GNUNET_MQ_send (tc_h->c_mq,
750  tc_queue_iter->open_queue_env);
751  tc_queue_iter->open_queue_env = NULL;
752  }
753  return new_c;
754 }
755 
756 
764 static void
765 disconnect_cb (void *cls,
767  void *internal_cls)
768 {
769  struct MyClient *cl = cls;
771 
772  for (cl = tc_h->client_head; NULL != cl; cl = cl->next)
773  {
774  if (cl->client != client)
775  continue;
777  tc_h->client_tail,
778  cl);
779  if (cl->c_mq == tc_h->c_mq)
780  tc_h->c_mq = NULL;
781  GNUNET_free (cl);
782  break;
783  }
784  LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n");
785 }
786 
787 
794 static void
796  const struct GNUNET_TRANSPORT_SendMessageToAck *sma)
797 {
798  struct MyClient *client = cls;
800  // NOP
801 }
802 
803 
811 static void
814 {
815  struct GNUNET_MQ_MessageHandler mh[] = {
816  GNUNET_MQ_hd_var_size (communicator_available,
818  struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
819  tc_h),
820  GNUNET_MQ_hd_var_size (communicator_backchannel,
822  struct GNUNET_TRANSPORT_CommunicatorBackchannel,
823  tc_h),
824  GNUNET_MQ_hd_var_size (add_address,
826  struct GNUNET_TRANSPORT_AddAddressMessage,
827  tc_h),
828  // GNUNET_MQ_hd_fixed_size (del_address,
829  // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
830  // struct GNUNET_TRANSPORT_DelAddressMessage,
831  // NULL),
832  GNUNET_MQ_hd_var_size (incoming_msg,
834  struct GNUNET_TRANSPORT_IncomingMessage,
835  tc_h),
836  GNUNET_MQ_hd_fixed_size (queue_create_ok,
838  struct GNUNET_TRANSPORT_CreateQueueResponse,
839  tc_h),
840  GNUNET_MQ_hd_fixed_size (queue_create_fail,
842  struct GNUNET_TRANSPORT_CreateQueueResponse,
843  tc_h),
844  GNUNET_MQ_hd_var_size (add_queue_message,
846  struct GNUNET_TRANSPORT_AddQueueMessage,
847  tc_h),
848  GNUNET_MQ_hd_fixed_size (update_queue_message,
850  struct GNUNET_TRANSPORT_UpdateQueueMessage,
851  tc_h),
852  // GNUNET_MQ_hd_fixed_size (del_queue_message,
853  // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
854  // struct GNUNET_TRANSPORT_DelQueueMessage,
855  // NULL),
856  GNUNET_MQ_hd_fixed_size (send_message_ack,
858  struct GNUNET_TRANSPORT_SendMessageToAck,
859  tc_h),
861  };
862 
863 
864  tc_h->sh = GNUNET_SERVICE_start ("transport",
865  tc_h->cfg,
866  &connect_cb,
867  &disconnect_cb,
868  tc_h,
869  mh);
870  GNUNET_assert (NULL != tc_h->sh);
871 }
872 
873 
879 static void
881 {
882  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
883  {
885  "Error shutting down process with SIGERM, trying SIGKILL\n");
886  if (0 != GNUNET_OS_process_kill (proc, SIGKILL))
887  {
889  "Error shutting down process with SIGERM and SIGKILL\n");
890  }
891  }
893 }
894 
895 
896 static void
898 {
899  struct GNUNET_OS_Process *proc = cls;
900  shutdown_process (proc);
901 }
902 
903 
909 static void
912  const char *binary_name)
913 {
914  char *binary;
915 
916  LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n");
917  binary = GNUNET_OS_get_libexec_binary_path (binary_name);
920  NULL,
921  NULL,
922  NULL,
923  binary,
924  binary_name,
925  "-c",
926  tc_h->cfg_filename,
927  NULL);
928  if (NULL == tc_h->c_proc)
929  {
930  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!");
931  return;
932  }
933  LOG (GNUNET_ERROR_TYPE_INFO, "started communicator\n");
934  GNUNET_free (binary);
935 }
936 
937 
943 static void
944 shutdown_nat (void *cls)
945 {
946  struct GNUNET_OS_Process *proc = cls;
947  shutdown_process (proc);
948 }
949 
955 static void
956 shutdown_resolver (void *cls)
957 {
958  struct GNUNET_OS_Process *proc = cls;
959  shutdown_process (proc);
960 }
961 
962 static void
965 {
966  char *binary;
967 
968  LOG (GNUNET_ERROR_TYPE_DEBUG, "resolver_start\n");
969  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
972  NULL,
973  NULL,
974  NULL,
975  binary,
976  "gnunet-service-resolver",
977  "-c",
978  tc_h->cfg_filename,
979  NULL);
980  if (NULL == tc_h->resolver_proc)
981  {
982  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start resolver service!");
983  return;
984  }
985  LOG (GNUNET_ERROR_TYPE_INFO, "started resolver service\n");
986  GNUNET_free (binary);
987 
988 }
989 
994 static void
997 {
998  char *binary;
999 
1000  LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start\n");
1001  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-nat");
1004  NULL,
1005  NULL,
1006  NULL,
1007  binary,
1008  "gnunet-service-nat",
1009  "-c",
1010  tc_h->cfg_filename,
1011  NULL);
1012  if (NULL == tc_h->nat_proc)
1013  {
1014  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start NAT!");
1015  return;
1016  }
1017  LOG (GNUNET_ERROR_TYPE_INFO, "started NAT\n");
1018  GNUNET_free (binary);
1019 }
1020 
1021 
1036  const char *service_name,
1037  const char *binary_name,
1038  const char *cfg_filename,
1039  const struct GNUNET_PeerIdentity *peer_id,
1047  void *cb_cls)
1048 {
1050 
1052  "Starting new transport/communicator combo with config %s\n",
1053  cfg_filename);
1054  tc_h =
1056  tc_h->cfg_filename = GNUNET_strdup (cfg_filename);
1057  tc_h->cfg = GNUNET_CONFIGURATION_create ();
1058  if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load (tc_h->cfg, cfg_filename)))
1059  {
1061  _ ("Malformed configuration file `%s', exit ...\n"),
1062  cfg_filename);
1063  GNUNET_free (tc_h->cfg_filename);
1065  GNUNET_free (tc_h);
1066  return NULL;
1067  }
1069  "communicator-test",
1070  "BACKCHANNEL_ENABLED");
1074  tc_h->add_queue_cb = add_queue_cb;
1075  tc_h->incoming_msg_cb = incoming_message_cb;
1076  tc_h->bc_cb = bc_cb;
1077  tc_h->peer_id = *peer_id;
1078  tc_h->cb_cls = cb_cls;
1079 
1080  /* Start communicator part of service */
1082  /* Start NAT */
1083  nat_start (tc_h);
1084  /* Start resolver service */
1085  resolver_start (tc_h);
1086  /* Schedule start communicator */
1087  communicator_start (tc_h,
1088  binary_name);
1089  return tc_h;
1090 }
1091 
1092 
1093 void
1096 {
1097  shutdown_communicator (tc_h->c_proc);
1098  shutdown_service (tc_h->sh);
1099  shutdown_nat (tc_h->nat_proc);
1102  GNUNET_free (tc_h);
1103 }
1104 
1105 
1113 void
1116  const struct GNUNET_PeerIdentity *peer_id,
1117  const char *address)
1118 {
1120  static uint32_t idgen;
1121  char *prefix;
1122  struct GNUNET_TRANSPORT_CreateQueue *msg;
1123  struct GNUNET_MQ_Envelope *env;
1124  size_t alen;
1125 
1126  tc_queue =
1128  tc_queue->tc_h = tc_h;
1129  prefix = GNUNET_HELLO_address_to_prefix (address);
1130  if (NULL == prefix)
1131  {
1132  GNUNET_break (0); /* We got an invalid address!? */
1133  GNUNET_free (tc_queue);
1134  return;
1135  }
1136  GNUNET_free (prefix);
1137  alen = strlen (address) + 1;
1138  env =
1140  msg->request_id = htonl (idgen++);
1141  tc_queue->qid = msg->request_id;
1142  msg->receiver = *peer_id;
1143  tc_queue->peer_id = *peer_id;
1144  memcpy (&msg[1], address, alen);
1145  if (NULL != tc_h->c_mq)
1146  {
1147  GNUNET_MQ_send (tc_h->c_mq, env);
1148  }
1149  else
1150  {
1151  tc_queue->open_queue_env = env;
1152  }
1153  GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue);
1154 }
1155 
1156 
1166 void
1170  void *cont_cls,
1171  const void *payload,
1172  size_t payload_size)
1173 {
1174  struct GNUNET_MessageHeader *mh;
1175  struct GNUNET_TRANSPORT_SendMessageTo *msg;
1176  struct GNUNET_MQ_Envelope *env;
1177  size_t inbox_size;
1180 
1181  tc_queue = NULL;
1182  for (tc_queue_tmp = tc_h->queue_head;
1183  NULL != tc_queue_tmp;
1184  tc_queue_tmp = tc_queue_tmp->next)
1185  {
1186  if (tc_queue_tmp->q_len <= 0)
1187  continue;
1188  if (NULL == tc_queue)
1189  {
1191  "Selecting queue with prio %u, len %" PRIu64 " and MTU %u\n",
1192  tc_queue_tmp->priority,
1193  tc_queue_tmp->q_len,
1194  tc_queue_tmp->mtu);
1195  tc_queue = tc_queue_tmp;
1196  continue;
1197  }
1198  if (tc_queue->priority < tc_queue_tmp->priority)
1199  {
1201  "Selecting queue with prio %u, len %" PRIu64 " and MTU %u\n",
1202  tc_queue_tmp->priority,
1203  tc_queue_tmp->q_len,
1204  tc_queue_tmp->mtu);
1205  tc_queue = tc_queue_tmp;
1206  }
1207  }
1208  GNUNET_assert (NULL != tc_queue);
1210  tc_queue->q_len--;
1212  "Sending message\n");
1213  inbox_size = sizeof (struct GNUNET_MessageHeader) + payload_size;
1214  env = GNUNET_MQ_msg_extra (msg,
1215  inbox_size,
1217  GNUNET_assert (NULL != env);
1218  msg->qid = htonl (tc_queue->qid);
1219  msg->mid = tc_queue->mid++;
1220  msg->receiver = tc_queue->peer_id;
1221  mh = (struct GNUNET_MessageHeader *) &msg[1];
1222  mh->size = htons (inbox_size);
1224  memcpy (&mh[1],
1225  payload,
1226  payload_size);
1227  if (NULL != cont)
1228  GNUNET_MQ_notify_sent (env,
1229  cont,
1230  cont_cls);
1231  GNUNET_MQ_send (tc_queue->tc_h->c_mq,
1232  env);
1233 }
GNUNET_TRANSPORT_CommunicatorCharacteristics
What characteristics does this communicator have?
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
functions and structures related to testing-tng
void GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * next
Next element inside a DLL.
struct GNUNET_PeerIdentity peer_id
Peer ID of the peer on the other side of the queue.
static char * cfg_filename
Name of the configuration file.
void(* GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, const char *payload, size_t payload_len)
Handle an incoming message.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG
transport tells communicator it wants to transmit
static void handle_queue_create_fail(void *cls, const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
Communicator informs that it wont try establishing requested queue.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE
transport tells communicator it wants a queue
static void nat_start(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
Start NAT.
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * tc
The TCH.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void(* GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, int will_try)
Get informed about the success of a queue request.
common internal definitions for transport service
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:287
Handle to a service.
Definition: service.c:116
struct MyClient * next
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK
Response from communicator: will try to create queue.
char * cfg_filename
File name of configuration file.
static void handle_communicator_available(void *cls, const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
Handle new communicator.
struct GNUNET_SCHEDULER_Task * ts_shutdown_task
Task that will be run on shutdown to stop and clean transport service.
static void shutdown_communicator(void *cls)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
struct GNUNET_OS_Process * GNUNET_OS_start_process(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:687
void GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, const struct GNUNET_PeerIdentity *peer_id, const char *address)
Instruct communicator to open a queue.
static void handle_incoming_msg(void *cls, const struct GNUNET_TRANSPORT_IncomingMessage *inc_msg)
Receive an incoming message.
#define GNUNET_MESSAGE_TYPE_DUMMY
Dummy messages for testing / benchmarking.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE
inform transport that a queue was updated
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_SERVICE_Handle * GNUNET_SERVICE_start(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SERVICE_ConnectHandler connect_cb, GNUNET_SERVICE_DisconnectHandler disconnect_cb, void *cls, const struct GNUNET_MQ_MessageHandler *handlers)
Low-level function to start a service if the scheduler is already running.
Definition: service.c:1875
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
struct GNUNET_MQ_Handle * c_mq
Handle to the client.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_TRANSPORT_CommunicatorCharacteristics c_characteristics
Characteristics of the communicator.
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(const char *service_name, const char *binary_name, const char *cfg_filename, const struct GNUNET_PeerIdentity *peer_id, GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb, GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb, GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb, void *cb_cls)
Start communicator part of transport service and communicator.
static void shutdown_nat(void *cls)
Task run at shutdown to kill communicator and clean up.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING
Transport signalling incoming backchannel message to a communicator.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_SERVICE_Handle * sh
Our service handle.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_MQ_check_boxed_message(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb
Callback called when a new communicator connects.
struct GNUNET_OS_Process * nat_proc
NAT process.
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static void resolver_start(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
Handle to a client that is connected to a service.
Definition: service.c:250
char * c_addr_prefix
Specifies supported addresses.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG
inform transport about an incoming message
void(* GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, size_t mtu)
Handle opening of queue.
uint32_t cs
An enum GNUNET_TRANSPORT_ConnectionStatus in NBO.
static void handle_add_address(void *cls, const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
The communicator informs about an address.
#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:52
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
static int check_add_queue_message(void *cls, const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
New queue became available.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
void * cls
Closure for mv and cb.
static int check_communicator_available(void *cls, const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
Check whether incoming msg indicating available communicator is correct.
static int check_add_address(void *cls, const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
Address of our peer added.
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:783
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK
transport acknowledges processing an incoming message
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP
inform transport that a queue was setup to talk to some peer
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *(* GNUNET_TRANSPORT_TESTING_BackchannelCallback)(void *cls, struct GNUNET_MessageHeader *msg, struct GNUNET_PeerIdentity *pid)
Function signature for callbacks that are called when new backchannel message arrived.
static void shutdown_process(struct GNUNET_OS_Process *proc)
Task run at shutdown to kill communicator and clean up.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL
Tell transport that it should assist with exchanging a message between communicators.
struct GNUNET_OS_Process * resolver_proc
resolver service process
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
struct GNUNET_SERVICE_Client * client
Handle to the client.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb
Callback called when a new communicator connects.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK
communicator tells transports that message was sent
static void handle_queue_create_ok(void *cls, const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
Communicator informs that it tries to establish requested queue.
void GNUNET_SERVICE_stop(struct GNUNET_SERVICE_Handle *srv)
Stops a service that was started with GNUNET_SERVICE_start().
Definition: service.c:1908
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:641
Message handler for a specific message type.
When these flags are set, the child process will inherit stdout and stderr of the parent...
Definition: gnunet_os_lib.h:97
static int check_incoming_msg(void *cls, const struct GNUNET_TRANSPORT_IncomingMessage *msg)
Incoming message.
static int check_communicator_backchannel(void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannel *msg)
Incoming message.
void(* GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, char *address_prefix)
Function signature for callbacks that are called when new communicators become available.
struct GNUNET_CONFIGURATION_Handle * cfg
Handle to the configuration.
static void handle_update_queue_message(void *cls, const struct GNUNET_TRANSPORT_UpdateQueueMessage *msg)
Handle new queue.
struct GNUNET_MQ_Handle * c_mq
Handle to the client.
static unsigned int size
Size of the "table".
Definition: peer.c:67
char * GNUNET_HELLO_address_to_prefix(const char *address)
Given an address as a string, extract the prefix that identifies the communicator offering transmissi...
Definition: hello-ng.c:190
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * prev
Previous element inside a DLL.
static void handle_send_message_ack(void *cls, const struct GNUNET_TRANSPORT_SendMessageToAck *sma)
Message was transmitted.
static void shutdown_resolver(void *cls)
Task run at shutdown to kill the resolver process.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb
Callback called when a new communicator connects.
static void communicator_start(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, const char *binary_name)
Start the communicator.
static unsigned long long payload
How much data are we currently storing in the database?
uint32_t nt
An enum GNUNET_NetworkType in NBO.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct MyClient * prev
struct GNUNET_SERVICE_Handle * tsh
Handle to the transport service.
Handle to a message queue.
Definition: mq.c:85
static void handle_communicator_backchannel(void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannel *bc_msg)
Receive an incoming message.
The identity of the host (wraps the signing key of the peer).
static void handle_add_queue_message(void *cls, const struct GNUNET_TRANSPORT_AddQueueMessage *msg)
Handle new queue.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
configuration data
Definition: configuration.c:84
#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.
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * queue_tail
Tail of the DLL of queues associated with this communicator.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
static void disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *internal_cls)
Callback called when Client disconnects.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS
inform transport to add an address of this peer
struct GNUNET_MQ_Envelope * open_queue_env
Envelope to a message that requests the opening of the queue.
struct GNUNET_OS_Process * c_proc
Process of the communicator.
Header for all communications.
void(* GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, const char *address, struct GNUNET_TIME_Relative expiration, uint32_t aid, enum GNUNET_NetworkType nt)
Receive information about the address of a communicator.
GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb
Callback called when a new communicator connects.
GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb
Callback called when a new communicator connects.
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:355
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * queue_head
Head of the DLL of queues associated with this communicator.
struct GNUNET_SCHEDULER_Task * c_shutdown_task
Task that will be run on shutdown to stop and clean communicator.
GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb
Backchannel callback.
static void shutdown_service(void *cls)
Shut down the service.
static void transport_communicator_start(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
Start the communicator part of the transport service.
void GNUNET_TRANSPORT_TESTING_transport_communicator_send(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls, const void *payload, size_t payload_size)
Instruct communicator to send data.
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
static char * address
GNS address for this phone.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2242
#define LOG(kind,...)
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * tc_h
Handle to the TransportCommunicator.
char * c_address
Specifies supported addresses.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
#define GNUNET_free(ptr)
Wrapper around free.
Queue of a communicator and some context.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:225
static void * connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Callback called when new Client (Communicator) connects.
Bandwidth allocation API for the transport service.