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 {
70 
79 
84 
88  uint32_t qid;
89 
93  uint64_t mid;
94 
98  uint32_t nt;
99 
103  uint32_t mtu;
104 
108  uint64_t q_len;
109 
113  uint32_t priority;
114 
118  uint32_t cs;
119 
124 
129 };
130 
131 
136 {
137 };
138 
139 
149 static int
151  void *cls,
152  const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
153 {
154  uint16_t size;
155 
156  size = ntohs (msg->header.size) - sizeof(*msg);
157  if (0 == size)
158  return GNUNET_OK; /* receive-only communicator */
160  return GNUNET_OK;
161 }
162 
163 
172 static void
174  void *cls,
175  const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
176 {
177  struct MyClient *client = cls;
179  client->tc;
180  uint16_t size;
181  tc_h->c_mq = client->c_mq;
182 
183  size = ntohs (msg->header.size) - sizeof(*msg);
184  if (0 == size)
185  {
187  return; /* receive-only communicator */
188  }
189  tc_h->c_characteristics = ntohl (msg->cc);
190  tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]);
191  if (NULL != tc_h->communicator_available_cb)
192  {
193  LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n");
194  tc_h->communicator_available_cb (tc_h->cb_cls,
195  tc_h,
196  tc_h->c_characteristics,
197  tc_h->c_addr_prefix);
198  }
200  LOG (GNUNET_ERROR_TYPE_DEBUG, "finished communicator_available_cb()\n");
201 
202 }
203 
204 
212 static int
214  const struct
215  GNUNET_TRANSPORT_CommunicatorBackchannel *msg)
216 {
217  // struct TransportClient *tc = cls;
218 
219  // if (CT_COMMUNICATOR != tc->type)
220  // {
221  // GNUNET_break (0);
222  // return GNUNET_SYSERR;
223  // }
224  // GNUNET_MQ_check_boxed_message (msg);
225  return GNUNET_OK;
226 }
227 
228 
237 static void
239  const struct
240  GNUNET_TRANSPORT_CommunicatorBackchannel *
241  bc_msg)
242 {
243  struct MyClient *client = cls;
245  client->tc;
247  struct GNUNET_MessageHeader *msg;
248  msg = (struct GNUNET_MessageHeader *) &bc_msg[1];
249  uint16_t isize = ntohs (msg->size);
250  const char *target_communicator = ((const char *) msg) + isize;
251  struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *cbi;
252  struct GNUNET_MQ_Envelope *env;
253 
255  "Received backchannel message\n");
256  if (tc_h->bc_enabled != GNUNET_YES)
257  {
259  return;
260  }
261  /* Find client providing this communicator */
262  /* Finally, deliver backchannel message to communicator */
264  "Delivering backchannel message of type %u to %s\n",
265  ntohs (msg->type),
266  target_communicator);
267  other_tc_h = tc_h->bc_cb (tc_h, msg, (struct
268  GNUNET_PeerIdentity*) &bc_msg->pid);
269  env = GNUNET_MQ_msg_extra (
270  cbi,
271  isize,
273  cbi->pid = tc_h->peer_id;
274  memcpy (&cbi[1], msg, isize);
275 
276 
277  GNUNET_MQ_send (other_tc_h->c_mq, env);
279 }
280 
281 
289 static int
290 check_add_address (void *cls,
291  const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
292 {
293  // if (CT_COMMUNICATOR != tc->type)
294  // {
295  // GNUNET_break (0);
296  // return GNUNET_SYSERR;
297  // }
299  return GNUNET_OK;
300 }
301 
302 
311 static void
313  const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
314 {
315  struct MyClient *client = cls;
317  client->tc;
318  uint16_t size;
319  size = ntohs (msg->header.size) - sizeof(*msg);
320  if (0 == size)
321  return; /* receive-only communicator */
322  LOG (GNUNET_ERROR_TYPE_DEBUG, "received add address cb %u\n", size);
323  tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]);
324  if (NULL != tc_h->add_address_cb)
325  {
326  LOG (GNUNET_ERROR_TYPE_DEBUG, "calling add_address_cb()\n");
327  tc_h->add_address_cb (tc_h->cb_cls,
328  tc_h,
329  tc_h->c_address,
330  GNUNET_TIME_relative_ntoh (msg->expiration),
331  msg->aid,
332  ntohl (msg->nt));
333  }
335 }
336 
337 
345 static int
347  const struct GNUNET_TRANSPORT_IncomingMessage *msg)
348 {
349  // struct TransportClient *tc = cls;
350 
351  // if (CT_COMMUNICATOR != tc->type)
352  // {
353  // GNUNET_break (0);
354  // return GNUNET_SYSERR;
355  // }
357  return GNUNET_OK;
358 }
359 
360 
369 static void
371  const struct GNUNET_TRANSPORT_IncomingMessage *inc_msg)
372 {
373  struct MyClient *client = cls;
375  client->tc;
376  struct GNUNET_MessageHeader *msg;
377  msg = (struct GNUNET_MessageHeader *) &inc_msg[1];
378  size_t payload_len = ntohs (msg->size) - sizeof (struct
380  if (NULL != tc_h->incoming_msg_cb)
381  {
382  tc_h->incoming_msg_cb (tc_h->cb_cls,
383  tc_h,
384  (char*) &msg[1],
385  payload_len);
386  }
387  else
388  {
390  "Incoming message from communicator but no handler!\n");
391  }
392  if (GNUNET_YES == ntohl (inc_msg->fc_on))
393  {
394  /* send ACK when done to communicator for flow control! */
395  struct GNUNET_MQ_Envelope *env;
396  struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
397 
399  GNUNET_assert (NULL != env);
400  ack->reserved = htonl (0);
401  ack->fc_id = inc_msg->fc_id;
402  ack->sender = inc_msg->sender;
403  GNUNET_MQ_send (tc_h->c_mq, env);
404  }
405 
407 }
408 
409 
416 static void
418  const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
419 {
420  struct MyClient *client = cls;
422  client->tc;
423 
424  if (NULL != tc_h->queue_create_reply_cb)
425  {
426  tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_YES);
427  }
429 }
430 
431 
441 static void
443  void *cls,
444  const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
445 {
446  struct MyClient *client = cls;
448  client->tc;
449 
450  if (NULL != tc_h->queue_create_reply_cb)
451  {
452  tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_NO);
453  }
455 }
456 
457 
464 static int
466  const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
467 {
469  return GNUNET_OK;
470 }
471 
472 
481 static void
483  const struct GNUNET_TRANSPORT_AddQueueMessage *msg)
484 {
485  struct MyClient *client = cls;
487  client->tc;
489 
491  "Got queue with ID %u\n", msg->qid);
492  for (tc_queue = tc_h->queue_head; NULL != tc_queue; tc_queue = tc_queue->next)
493  {
494  if (tc_queue->qid == msg->qid)
495  break;
496  }
497  if (NULL == tc_queue)
498  {
499  tc_queue =
501  tc_queue->tc_h = tc_h;
502  tc_queue->qid = msg->qid;
503  tc_queue->peer_id = msg->receiver;
504  GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue);
505  }
506  GNUNET_assert (tc_queue->qid == msg->qid);
507  GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
508  tc_queue->nt = msg->nt;
509  tc_queue->mtu = ntohl (msg->mtu);
510  tc_queue->cs = msg->cs;
511  tc_queue->priority = ntohl (msg->priority);
512  tc_queue->q_len = GNUNET_ntohll (msg->q_len);
513  if (NULL != tc_h->add_queue_cb)
514  {
515  tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue, tc_queue->mtu);
516  }
518 }
519 
520 
529 static void
531  const struct
532  GNUNET_TRANSPORT_UpdateQueueMessage *msg)
533 {
534  struct MyClient *client = cls;
536  client->tc;
538 
540  "Received queue update message for %u with q_len %" PRIu64 "\n",
541  msg->qid, GNUNET_ntohll (msg->q_len));
542  tc_queue = tc_h->queue_head;
543  if (NULL != tc_queue)
544  {
545  while (tc_queue->qid != msg->qid)
546  {
547  tc_queue = tc_queue->next;
548  }
549  }
550  GNUNET_assert (tc_queue->qid == msg->qid);
551  GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
552  tc_queue->nt = msg->nt;
553  tc_queue->mtu = ntohl (msg->mtu);
554  tc_queue->cs = msg->cs;
555  tc_queue->priority = ntohl (msg->priority);
556  tc_queue->q_len += GNUNET_ntohll (msg->q_len);
558 }
559 
560 
566 static void
567 shutdown_service (void *cls)
568 {
569  struct GNUNET_SERVICE_Handle *h = cls;
570 
572  "Shutting down service!\n");
573 
575 }
576 
577 
587 static void *
588 connect_cb (void *cls,
590  struct GNUNET_MQ_Handle *mq)
591 {
593  struct MyClient *new_c;
594 
595  LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected to %p.\n",
596  client, tc_h);
597  new_c = GNUNET_new (struct MyClient);
598  new_c->client = client;
599  new_c->c_mq = mq;
600  new_c->tc = tc_h;
602  tc_h->client_tail,
603  new_c);
604 
605  if (NULL == tc_h->queue_head)
606  return new_c;
607  /* Iterate over queues. They are yet to be opened. Request opening. */
608  for (struct
610  tc_h->queue_head;
611  NULL != tc_queue_iter;
612  tc_queue_iter = tc_queue_iter->next)
613  {
614  if (NULL == tc_queue_iter->open_queue_env)
615  continue;
616  /* Send the previously created mq envelope to request the creation of the
617  * queue. */
618  GNUNET_MQ_send (tc_h->c_mq,
619  tc_queue_iter->open_queue_env);
620  tc_queue_iter->open_queue_env = NULL;
621  }
622  return new_c;
623 }
624 
625 
633 static void
634 disconnect_cb (void *cls,
636  void *internal_cls)
637 {
638  struct MyClient *cl = cls;
640 
641  for (cl = tc_h->client_head; NULL != cl; cl = cl->next)
642  {
643  if (cl->client != client)
644  continue;
646  tc_h->client_tail,
647  cl);
648  if (cl->c_mq == tc_h->c_mq)
649  tc_h->c_mq = NULL;
650  GNUNET_free (cl);
651  break;
652  }
653  LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n");
654 }
655 
656 
663 static void
665  const struct GNUNET_TRANSPORT_SendMessageToAck *sma)
666 {
667  struct MyClient *client = cls;
669  // NOP
670 }
671 
672 
680 static void
683 {
684  struct GNUNET_MQ_MessageHandler mh[] = {
685  GNUNET_MQ_hd_var_size (communicator_available,
687  struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
688  tc_h),
689  GNUNET_MQ_hd_var_size (communicator_backchannel,
691  struct GNUNET_TRANSPORT_CommunicatorBackchannel,
692  tc_h),
693  GNUNET_MQ_hd_var_size (add_address,
695  struct GNUNET_TRANSPORT_AddAddressMessage,
696  tc_h),
697  // GNUNET_MQ_hd_fixed_size (del_address,
698  // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
699  // struct GNUNET_TRANSPORT_DelAddressMessage,
700  // NULL),
701  GNUNET_MQ_hd_var_size (incoming_msg,
703  struct GNUNET_TRANSPORT_IncomingMessage,
704  tc_h),
705  GNUNET_MQ_hd_fixed_size (queue_create_ok,
707  struct GNUNET_TRANSPORT_CreateQueueResponse,
708  tc_h),
709  GNUNET_MQ_hd_fixed_size (queue_create_fail,
711  struct GNUNET_TRANSPORT_CreateQueueResponse,
712  tc_h),
713  GNUNET_MQ_hd_var_size (add_queue_message,
715  struct GNUNET_TRANSPORT_AddQueueMessage,
716  tc_h),
717  GNUNET_MQ_hd_fixed_size (update_queue_message,
719  struct GNUNET_TRANSPORT_UpdateQueueMessage,
720  tc_h),
721  // GNUNET_MQ_hd_fixed_size (del_queue_message,
722  // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
723  // struct GNUNET_TRANSPORT_DelQueueMessage,
724  // NULL),
725  GNUNET_MQ_hd_fixed_size (send_message_ack,
727  struct GNUNET_TRANSPORT_SendMessageToAck,
728  tc_h),
730  };
731 
732 
733  tc_h->sh = GNUNET_SERVICE_start ("transport",
734  tc_h->cfg,
735  &connect_cb,
736  &disconnect_cb,
737  tc_h,
738  mh);
739  GNUNET_assert (NULL != tc_h->sh);
740 }
741 
742 
748 static void
750 {
751  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
752  {
754  "Error shutting down process with SIGERM, trying SIGKILL\n");
755  if (0 != GNUNET_OS_process_kill (proc, SIGKILL))
756  {
758  "Error shutting down process with SIGERM and SIGKILL\n");
759  }
760  }
762 }
763 
764 static void
766 {
767  struct GNUNET_OS_Process *proc = cls;
768  shutdown_process (proc);
769 }
770 
771 static void
773 {
774  struct GNUNET_OS_Process *proc = cls;
775  shutdown_process (proc);
776 }
777 
778 
784 static void
787  const char *binary_name)
788 {
789  char *binary;
790  char *loprefix;
791  char *section_name;
792 
793  LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n");
794 
795  section_name = strchr (binary_name, '-');
796  section_name++;
797 
799  section_name,
800  "PREFIX",
801  &loprefix))
802  loprefix = GNUNET_strdup ("");
803 
804 
805  binary = GNUNET_OS_get_libexec_binary_path (binary_name);
807  NULL,
808  loprefix,
809  binary,
810  binary_name,
811  "-c",
812  tc_h->cfg_filename,
813  NULL);
814  if (NULL == tc_h->c_proc)
815  {
816  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!");
817  return;
818  }
819  LOG (GNUNET_ERROR_TYPE_INFO, "started communicator\n");
820  GNUNET_free (binary);
821 }
822 
823 
829 static void
830 shutdown_nat (void *cls)
831 {
832  struct GNUNET_OS_Process *proc = cls;
833  shutdown_process (proc);
834 }
835 
836 
842 static void
843 shutdown_resolver (void *cls)
844 {
845  struct GNUNET_OS_Process *proc = cls;
846  shutdown_process (proc);
847 }
848 
849 
850 static void
853 {
854  char *binary;
855 
856  LOG (GNUNET_ERROR_TYPE_DEBUG, "resolver_start\n");
857  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
861  NULL,
862  NULL,
863  NULL,
864  binary,
865  "gnunet-service-resolver",
866  "-c",
867  tc_h->cfg_filename,
868  NULL);
869  if (NULL == tc_h->resolver_proc)
870  {
871  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start resolver service!");
872  return;
873  }
874  LOG (GNUNET_ERROR_TYPE_INFO, "started resolver service\n");
875  GNUNET_free (binary);
876 
877 }
878 
879 
884 static void
887 {
888  char *binary;
889 
890  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-peerstore");
892  NULL,
893  NULL,
894  NULL,
895  binary,
896  "gnunet-service-peerstore",
897  "-c",
898  tc_h->cfg_filename,
899  NULL);
900  if (NULL == tc_h->ps_proc)
901  {
902  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start Peerstore!");
903  return;
904  }
905  LOG (GNUNET_ERROR_TYPE_INFO, "started Peerstore\n");
906  GNUNET_free (binary);
907 }
908 
913 static void
916 {
917  char *binary;
918 
919  LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start\n");
920  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-nat");
923  NULL,
924  NULL,
925  NULL,
926  binary,
927  "gnunet-service-nat",
928  "-c",
929  tc_h->cfg_filename,
930  NULL);
931  if (NULL == tc_h->nat_proc)
932  {
933  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start NAT!");
934  return;
935  }
936  LOG (GNUNET_ERROR_TYPE_INFO, "started NAT\n");
937  GNUNET_free (binary);
938 }
939 
940 
955  const char *service_name,
956  const char *binary_name,
957  const char *cfg_filename,
958  const struct GNUNET_PeerIdentity *peer_id,
966  void *cb_cls)
967 {
969 
971  "Starting new transport/communicator combo with config %s\n",
972  cfg_filename);
973  tc_h =
975  tc_h->cfg_filename = GNUNET_strdup (cfg_filename);
976  tc_h->cfg = GNUNET_CONFIGURATION_create ();
977  if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load (tc_h->cfg, cfg_filename)))
978  {
980  _ ("Malformed configuration file `%s', exit ...\n"),
981  cfg_filename);
982  GNUNET_free (tc_h->cfg_filename);
984  GNUNET_free (tc_h);
985  return NULL;
986  }
988  "communicator-test",
989  "BACKCHANNEL_ENABLED");
993  tc_h->add_queue_cb = add_queue_cb;
994  tc_h->incoming_msg_cb = incoming_message_cb;
995  tc_h->bc_cb = bc_cb;
996  tc_h->peer_id = *peer_id;
997  tc_h->cb_cls = cb_cls;
998 
999  /* Start communicator part of service */
1001  /* Start NAT */
1002  nat_start (tc_h);
1003  /* Start resolver service */
1004  resolver_start (tc_h);
1005  /* Start peerstore service */
1006  peerstore_start (tc_h);
1007  /* Schedule start communicator */
1008  communicator_start (tc_h,
1009  binary_name);
1010  return tc_h;
1011 }
1012 
1013 
1014 void
1017 {
1018  shutdown_communicator (tc_h->c_proc);
1019  shutdown_service (tc_h->sh);
1020  shutdown_nat (tc_h->nat_proc);
1022  shutdown_peerstore (tc_h->ps_proc);
1024  GNUNET_free (tc_h);
1025 }
1026 
1027 
1035 void
1038  const struct GNUNET_PeerIdentity *peer_id,
1039  const char *address)
1040 {
1042  static uint32_t idgen;
1043  char *prefix;
1044  struct GNUNET_TRANSPORT_CreateQueue *msg;
1045  struct GNUNET_MQ_Envelope *env;
1046  size_t alen;
1047 
1048  tc_queue =
1050  tc_queue->tc_h = tc_h;
1051  prefix = GNUNET_HELLO_address_to_prefix (address);
1052  if (NULL == prefix)
1053  {
1054  GNUNET_break (0); /* We got an invalid address!? */
1055  GNUNET_free (tc_queue);
1056  return;
1057  }
1058  GNUNET_free (prefix);
1059  alen = strlen (address) + 1;
1060  env =
1062  msg->request_id = htonl (idgen++);
1063  tc_queue->qid = msg->request_id;
1064  msg->receiver = *peer_id;
1065  tc_queue->peer_id = *peer_id;
1066  memcpy (&msg[1], address, alen);
1067  if (NULL != tc_h->c_mq)
1068  {
1070  "Sending queue create immediately\n");
1071  GNUNET_MQ_send (tc_h->c_mq, env);
1072  }
1073  else
1074  {
1075  tc_queue->open_queue_env = env;
1076  }
1077  GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue);
1078 }
1079 
1080 
1090 void
1094  void *cont_cls,
1095  const void *payload,
1096  size_t payload_size)
1097 {
1098  struct GNUNET_MessageHeader *mh;
1099  struct GNUNET_TRANSPORT_SendMessageTo *msg;
1100  struct GNUNET_MQ_Envelope *env;
1101  size_t inbox_size;
1104 
1105  tc_queue = NULL;
1106  for (tc_queue_tmp = tc_h->queue_head;
1107  NULL != tc_queue_tmp;
1108  tc_queue_tmp = tc_queue_tmp->next)
1109  {
1110  if (tc_queue_tmp->q_len <= 0)
1111  continue;
1112  if (NULL == tc_queue)
1113  {
1115  "Selecting queue with prio %u, len %" PRIu64 " and MTU %u\n",
1116  tc_queue_tmp->priority,
1117  tc_queue_tmp->q_len,
1118  tc_queue_tmp->mtu);
1119  tc_queue = tc_queue_tmp;
1120  continue;
1121  }
1122  if (tc_queue->priority < tc_queue_tmp->priority)
1123  {
1125  "Selecting queue with prio %u, len %" PRIu64 " and MTU %u\n",
1126  tc_queue_tmp->priority,
1127  tc_queue_tmp->q_len,
1128  tc_queue_tmp->mtu);
1129  tc_queue = tc_queue_tmp;
1130  }
1131  }
1132  GNUNET_assert (NULL != tc_queue);
1134  tc_queue->q_len--;
1136  "Sending message\n");
1137  inbox_size = sizeof (struct GNUNET_MessageHeader) + payload_size;
1138  env = GNUNET_MQ_msg_extra (msg,
1139  inbox_size,
1141  GNUNET_assert (NULL != env);
1142  msg->qid = htonl (tc_queue->qid);
1143  msg->mid = tc_queue->mid++;
1144  msg->receiver = tc_queue->peer_id;
1145  mh = (struct GNUNET_MessageHeader *) &msg[1];
1146  mh->size = htons (inbox_size);
1148  memcpy (&mh[1],
1149  payload,
1150  payload_size);
1151  if (NULL != cont)
1152  GNUNET_MQ_notify_sent (env,
1153  cont,
1154  cont_cls);
1155  GNUNET_MQ_send (tc_queue->tc_h->c_mq,
1156  env);
1157 }
#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.
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:747
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_OS_Process * GNUNET_OS_start_process(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:678
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.
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
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.
struct GNUNET_OS_Process * ps_proc
peerstore service process
#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:787
#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
static void peerstore_start(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
Start Peerstore.
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.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
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
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.
static char * section_name
Name of section in configuration file to use for additional options.
Definition: gnunet-nat.c:40
#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,...)
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
static void shutdown_peerstore(void *cls)
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * queue_head
Head of the DLL of queues associated with this 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.
Should a pipe be used to send signals to the child?
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.