GNUnet  0.19.5
testbed_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2008--2013 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 
29 #include "platform.h"
30 #include "gnunet_testbed_service.h"
31 #include "gnunet_core_service.h"
32 #include "gnunet_constants.h"
34 #include "gnunet_hello_lib.h"
35 #include <zlib.h>
36 
37 #include "testbed.h"
38 #include "testbed_api.h"
39 #include "testbed_api_hosts.h"
40 #include "testbed_api_peers.h"
41 #include "testbed_api_operations.h"
42 #include "testbed_api_sd.h"
43 
47 #define LOG(kind, ...) GNUNET_log_from (kind, "testbed-api", __VA_ARGS__)
48 
52 #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
53 
57 #define TIME_REL_SECS(sec) \
58  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
59 
60 
64 #define TIMEOUT_REL TIME_REL_SECS (1)
65 
66 
71 {
76 
80  void *cc_cls;
81 };
82 
83 
88 {
92  uint32_t slave_id;
93 };
94 
95 
100 {
105 
109  uint32_t host_id;
110 };
111 
112 
117 {
122 
126  void *cb_cls;
127 };
128 
129 
134 {
139 
144 
149 };
150 
151 
156 
161 
162 
168 static void
170 {
171  struct ExpireOperationEntry *entry;
172 
173  entry = GNUNET_new (struct ExpireOperationEntry);
174  entry->op = op;
176 }
177 
178 
190 static int
192 {
193  struct ExpireOperationEntry *entry;
194  struct ExpireOperationEntry *entry2;
195  int found;
196 
197  found = GNUNET_NO;
198  entry = exop_head;
199  while (NULL != entry)
200  {
201  if (op == entry->op)
202  {
203  found = GNUNET_YES;
204  break;
205  }
206  entry = entry->next;
207  }
208  if (GNUNET_NO == found)
209  return GNUNET_NO;
210  /* Truncate the tail */
211  while (NULL != entry)
212  {
213  entry2 = entry->next;
215  GNUNET_free (entry);
216  entry = entry2;
217  }
218  return GNUNET_YES;
219 }
220 
221 
226 {
231 
235  uint64_t id;
236 };
237 
238 
248 static int
249 opc_search_iterator (void *cls, uint32_t key, void *value)
250 {
251  struct SearchContext *sc = cls;
252  struct OperationContext *opc = value;
253 
254  GNUNET_assert (NULL != opc);
255  GNUNET_assert (NULL == sc->opc);
256  if (opc->id != sc->id)
257  return GNUNET_YES;
258  sc->opc = opc;
259  return GNUNET_NO;
260 }
261 
262 
271 static struct OperationContext *
272 find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id)
273 {
274  struct SearchContext sc;
275 
276  sc.id = id;
277  sc.opc = NULL;
278  GNUNET_assert (NULL != c->opc_map);
279  if (GNUNET_SYSERR !=
281  (uint32_t) id,
283  &sc))
284  return NULL;
285  return sc.opc;
286 }
287 
288 
297 void
299  struct OperationContext *opc)
300 {
301  if (NULL == c->opc_map)
304  c->opc_map,
305  (uint32_t) opc->id,
306  opc,
308 }
309 
310 
318 void
320  struct OperationContext *opc)
321 {
322  GNUNET_assert (NULL != c->opc_map);
325  (uint32_t) opc->id,
326  opc));
328  (NULL != c->opcq_empty_cb))
330 }
331 
332 
340 static int
343 {
344  const char *emsg;
345  uint16_t msg_size;
346 
347  msg_size = ntohs (msg->header.size) - sizeof(*msg);
348  if (0 == msg_size)
349  return GNUNET_OK;
350  /* We have an error message */
351  emsg = (const char *) &msg[1];
352  if ('\0' != emsg[msg_size - 1])
353  {
354  GNUNET_break (0);
355  return GNUNET_SYSERR;
356  }
357  return GNUNET_OK;
358 }
359 
360 
368 static void
371 {
372  struct GNUNET_TESTBED_Controller *c = cls;
374  const char *emsg;
375  uint16_t msg_size;
376 
377  if (NULL == rh)
378  return;
379  if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
380  {
381  LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n",
383  ntohl (msg->host_id));
384  return;
385  }
386  c->rh = NULL;
387  msg_size = ntohs (msg->header.size) - sizeof(*msg);
388  if (0 == msg_size)
389  {
390  LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id));
392  rh->cc (rh->cc_cls, NULL);
393  GNUNET_free (rh);
394  return;
395  }
396  /* We have an error message */
397  emsg = (const char *) &msg[1];
399  _ ("Adding host %u failed with error: %s\n"),
400  ntohl (msg->host_id),
401  emsg);
402  rh->cc (rh->cc_cls, emsg);
403  GNUNET_free (rh);
404 }
405 
406 
414 static void
416  struct OperationContext *opc,
417  const struct GNUNET_MessageHeader *msg)
418 {
419  struct GNUNET_TESTBED_Controller *c = cls;
420  struct ForwardedOperationData *fo_data;
421 
422  fo_data = opc->data;
423  if (NULL != fo_data->cc)
424  fo_data->cc (fo_data->cc_cls, msg);
426  GNUNET_free (fo_data);
427  GNUNET_free (opc);
428 }
429 
430 
438 static void
440  void *cls,
442 {
443  struct GNUNET_TESTBED_Controller *c = cls;
444  struct OperationContext *opc;
446  void *op_comp_cb_cls;
447  struct GNUNET_TESTBED_EventInformation event;
448  uint64_t op_id;
449 
450  op_id = GNUNET_ntohll (msg->operation_id);
451  LOG_DEBUG ("Operation %llu successful\n",
452  (unsigned long long) op_id);
453  if (NULL == (opc = find_opc (c, op_id)))
454  {
455  LOG_DEBUG ("Operation not found\n");
456  return;
457  }
459  event.op = opc->op;
460  event.op_cls = opc->op_cls;
461  event.details.operation_finished.emsg = NULL;
462  event.details.operation_finished.generic = NULL;
463  op_comp_cb = NULL;
464  op_comp_cb_cls = NULL;
465  switch (opc->type)
466  {
467  case OP_FORWARDED: {
469  opc,
470  (const struct
472  return;
473  }
474  break;
475 
476  case OP_PEER_DESTROY: {
477  struct GNUNET_TESTBED_Peer *peer;
478 
479  peer = opc->data;
481  GNUNET_free (peer);
482  opc->data = NULL;
483  // PEERDESTROYDATA
484  }
485  break;
486 
487  case OP_SHUTDOWN_PEERS: {
488  struct ShutdownPeersData *data;
489 
490  data = opc->data;
491  op_comp_cb = data->cb;
492  op_comp_cb_cls = data->cb_cls;
493  GNUNET_free (data);
494  opc->data = NULL;
496  }
497  break;
498 
499  case OP_MANAGE_SERVICE: {
500  struct ManageServiceData *data;
501 
502  GNUNET_assert (NULL != (data = opc->data));
503  op_comp_cb = data->cb;
504  op_comp_cb_cls = data->cb_cls;
505  GNUNET_free (data);
506  opc->data = NULL;
507  }
508  break;
509 
510  case OP_PEER_RECONFIGURE:
511  break;
512 
513  default:
514  GNUNET_assert (0);
515  }
516  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
517  opc->state = OPC_STATE_FINISHED;
518  exop_insert (event.op);
519  if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
520  {
521  if (NULL != c->cc)
522  c->cc (c->cc_cls, &event);
523  if (GNUNET_NO == exop_check (event.op))
524  return;
525  }
526  else
527  LOG_DEBUG ("Not calling callback\n");
528  if (NULL != op_comp_cb)
529  op_comp_cb (op_comp_cb_cls, event.op, NULL);
530  /* You could have marked the operation as done by now */
531  GNUNET_break (GNUNET_NO == exop_check (event.op));
532 }
533 
534 
542 static void
544  void *cls,
546 {
547  struct GNUNET_TESTBED_Controller *c = cls;
548  struct OperationContext *opc;
549  struct PeerCreateData *data;
550  struct GNUNET_TESTBED_Peer *peer;
553  void *cb_cls;
554  uint64_t op_id;
555 
557  ntohs (msg->header.size));
558  op_id = GNUNET_ntohll (msg->operation_id);
559  if (NULL == (opc = find_opc (c, op_id)))
560  {
561  LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n");
562  return;
563  }
564  if (OP_FORWARDED == opc->type)
565  {
567  opc,
568  (const struct GNUNET_MessageHeader *) msg);
569  return;
570  }
572  GNUNET_assert (NULL != opc->data);
573  data = opc->data;
574  GNUNET_assert (NULL != data->peer);
575  peer = data->peer;
576  GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
579  cb = data->cb;
580  cb_cls = data->cls;
581  op = opc->op;
582  GNUNET_free (opc->data);
583  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
584  opc->state = OPC_STATE_FINISHED;
585  exop_insert (op);
586  if (NULL != cb)
587  cb (cb_cls, peer, NULL);
588  /* You could have marked the operation as done by now */
590 }
591 
592 
600 static void
602 {
603  struct GNUNET_TESTBED_Controller *c = cls;
604  struct OperationContext *opc;
605  struct GNUNET_TESTBED_Peer *peer;
606  struct PeerEventData *data;
608  void *pcc_cls;
609  struct GNUNET_TESTBED_EventInformation event;
610  uint64_t op_id;
611  uint64_t mask;
612 
614  ntohs (msg->header.size));
615  op_id = GNUNET_ntohll (msg->operation_id);
616  if (NULL == (opc = find_opc (c, op_id)))
617  {
618  LOG_DEBUG ("Operation not found\n");
619  return;
620  }
621  if (OP_FORWARDED == opc->type)
622  {
624  opc,
625  (const struct GNUNET_MessageHeader *) msg);
626  return;
627  }
628  GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type));
629  data = opc->data;
630  GNUNET_assert (NULL != data);
631  peer = data->peer;
632  GNUNET_assert (NULL != peer);
633  event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
634  event.op = opc->op;
635  event.op_cls = opc->op_cls;
636  switch (event.type)
637  {
640  event.details.peer_start.host = peer->host;
641  event.details.peer_start.peer = peer;
642  break;
643 
646  event.details.peer_stop.peer = peer;
647  break;
648 
649  default:
650  GNUNET_assert (0); /* We should never reach this state */
651  }
652  pcc = data->pcc;
653  pcc_cls = data->pcc_cls;
654  GNUNET_free (data);
655  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
656  opc->state = OPC_STATE_FINISHED;
657  exop_insert (event.op);
658  mask = 1LL << GNUNET_TESTBED_ET_PEER_START;
659  mask |= 1LL << GNUNET_TESTBED_ET_PEER_STOP;
660  if (0 != (mask & c->event_mask))
661  {
662  if (NULL != c->cc)
663  c->cc (c->cc_cls, &event);
664  if (GNUNET_NO == exop_check (event.op))
665  return;
666  }
667  if (NULL != pcc)
668  pcc (pcc_cls, NULL);
669  /* You could have marked the operation as done by now */
670  GNUNET_break (GNUNET_NO == exop_check (event.op));
671 }
672 
673 
681 static void
684 {
685  struct GNUNET_TESTBED_Controller *c = cls;
686  struct OperationContext *opc;
687  struct OverlayConnectData *data;
689  void *cb_cls;
690  struct GNUNET_TESTBED_EventInformation event;
691  uint64_t op_id;
692  uint64_t mask;
693 
694  op_id = GNUNET_ntohll (msg->operation_id);
695  if (NULL == (opc = find_opc (c, op_id)))
696  {
697  LOG_DEBUG ("Operation not found\n");
698  return;
699  }
700  if (OP_FORWARDED == opc->type)
701  {
703  opc,
704  (const struct GNUNET_MessageHeader *) msg);
705  return;
706  }
708  GNUNET_assert (NULL != (data = opc->data));
709  GNUNET_assert ((ntohl (msg->peer1) == data->p1->unique_id) &&
710  (ntohl (msg->peer2) == data->p2->unique_id));
711  event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
712  event.op = opc->op;
713  event.op_cls = opc->op_cls;
714  switch (event.type)
715  {
717  event.details.peer_connect.peer1 = data->p1;
718  event.details.peer_connect.peer2 = data->p2;
719  break;
720 
722  GNUNET_assert (0); /* FIXME: implement */
723  break;
724 
725  default:
726  GNUNET_assert (0); /* Should never reach here */
727  break;
728  }
729  cb = data->cb;
730  cb_cls = data->cb_cls;
731  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
732  opc->state = OPC_STATE_FINISHED;
733  exop_insert (event.op);
734  mask = 1LL << GNUNET_TESTBED_ET_CONNECT;
735  mask |= 1LL << GNUNET_TESTBED_ET_DISCONNECT;
736  if (0 != (mask & c->event_mask))
737  {
738  if (NULL != c->cc)
739  c->cc (c->cc_cls, &event);
740  if (GNUNET_NO == exop_check (event.op))
741  return;
742  }
743  if (NULL != cb)
744  cb (cb_cls, opc->op, NULL);
745  /* You could have marked the operation as done by now */
746  GNUNET_break (GNUNET_NO == exop_check (event.op));
747 }
748 
749 
757 static int
759  void *cls,
761 {
762  /* anything goes? */
763  return GNUNET_OK;
764 }
765 
766 
774 static void
776  void *cls,
778 {
779  struct GNUNET_TESTBED_Controller *c = cls;
780  struct OperationContext *opc;
781  struct GNUNET_TESTBED_Peer *peer;
782  struct PeerInfoData *data;
783  struct GNUNET_TESTBED_PeerInformation *pinfo;
785  void *cb_cls;
786  uint64_t op_id;
787 
788  op_id = GNUNET_ntohll (msg->operation_id);
789  if (NULL == (opc = find_opc (c, op_id)))
790  {
791  LOG_DEBUG ("Operation not found\n");
792  return;
793  }
794  if (OP_FORWARDED == opc->type)
795  {
796  handle_forwarded_operation_msg (c, opc, &msg->header);
797  return;
798  }
799  data = opc->data;
800  GNUNET_assert (NULL != data);
801  peer = data->peer;
802  GNUNET_assert (NULL != peer);
803  GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
805  pinfo->pit = data->pit;
806  cb = data->cb;
807  cb_cls = data->cb_cls;
808  GNUNET_assert (NULL != cb);
809  GNUNET_free (data);
810  opc->data = NULL;
811  switch (pinfo->pit)
812  {
814  pinfo->result.id = GNUNET_new (struct GNUNET_PeerIdentity);
815  GNUNET_memcpy (pinfo->result.id,
816  &msg->peer_identity,
817  sizeof(struct GNUNET_PeerIdentity));
818  break;
819 
821  pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */
823  break;
824 
826  GNUNET_assert (0); /* never reach here */
827  break;
828  }
829  opc->data = pinfo;
830  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
831  opc->state = OPC_STATE_FINISHED;
832  cb (cb_cls, opc->op, pinfo, NULL);
833  /* We dont check whether the operation is marked as done here as the
834  operation contains data (cfg/identify) which will be freed at a later point
835  */
836 }
837 
838 
847 static int
849  void *cls,
851 {
852  /* we accept anything as a valid error message */
853  return GNUNET_OK;
854 }
855 
856 
864 static void
866  void *cls,
868 {
869  struct GNUNET_TESTBED_Controller *c = cls;
870  struct OperationContext *opc;
871  const char *emsg;
872  uint64_t op_id;
873  uint64_t mask;
874  struct GNUNET_TESTBED_EventInformation event;
875 
876  op_id = GNUNET_ntohll (msg->operation_id);
877  if (NULL == (opc = find_opc (c, op_id)))
878  {
879  LOG_DEBUG ("Operation not found\n");
880  return;
881  }
882  if (OP_FORWARDED == opc->type)
883  {
885  opc,
886  (const struct GNUNET_MessageHeader *) msg);
887  return;
888  }
889  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
890  opc->state = OPC_STATE_FINISHED;
892  if (NULL == emsg)
893  emsg = "Unknown error";
894  if (OP_PEER_INFO == opc->type)
895  {
896  struct PeerInfoData *data;
897 
898  data = opc->data;
899  if (NULL != data->cb)
900  data->cb (data->cb_cls, opc->op, NULL, emsg);
901  GNUNET_free (data);
902  return; /* We do not call controller callback for peer info */
903  }
905  event.op = opc->op;
906  event.op_cls = opc->op_cls;
907  event.details.operation_finished.emsg = emsg;
908  event.details.operation_finished.generic = NULL;
909  mask = (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
910  if ((0 != (mask & c->event_mask)) && (NULL != c->cc))
911  {
912  exop_insert (event.op);
913  c->cc (c->cc_cls, &event);
914  if (GNUNET_NO == exop_check (event.op))
915  return;
916  }
917  switch (opc->type)
918  {
919  case OP_PEER_CREATE: {
920  struct PeerCreateData *data;
921 
922  data = opc->data;
923  GNUNET_free (data->peer);
924  if (NULL != data->cb)
925  data->cb (data->cls, NULL, emsg);
926  GNUNET_free (data);
927  }
928  break;
929 
930  case OP_PEER_START:
931  case OP_PEER_STOP: {
932  struct PeerEventData *data;
933 
934  data = opc->data;
935  if (NULL != data->pcc)
936  data->pcc (data->pcc_cls, emsg);
937  GNUNET_free (data);
938  }
939  break;
940 
941  case OP_PEER_DESTROY:
942  break;
943 
944  case OP_PEER_INFO:
945  GNUNET_assert (0);
946 
947  case OP_OVERLAY_CONNECT: {
948  struct OverlayConnectData *data;
949 
950  data = opc->data;
952  if (NULL != data->cb)
953  data->cb (data->cb_cls, opc->op, emsg);
954  }
955  break;
956 
957  case OP_FORWARDED:
958  GNUNET_assert (0);
959 
960  case OP_LINK_CONTROLLERS: /* No secondary callback */
961  break;
962 
963  case OP_SHUTDOWN_PEERS: {
964  struct ShutdownPeersData *data;
965 
966  data = opc->data;
967  GNUNET_free (data); /* FIXME: Decide whether we call data->op_cb */
968  opc->data = NULL;
969  }
970  break;
971 
972  case OP_MANAGE_SERVICE: {
973  struct ManageServiceData *data = opc->data;
975  void *cb_cls;
976 
977  GNUNET_assert (NULL != data);
978  cb = data->cb;
979  cb_cls = data->cb_cls;
980  GNUNET_free (data);
981  opc->data = NULL;
982  exop_insert (event.op);
983  if (NULL != cb)
984  cb (cb_cls, opc->op, emsg);
985  /* You could have marked the operation as done by now */
986  GNUNET_break (GNUNET_NO == exop_check (event.op));
987  }
988  break;
989 
990  default:
991  GNUNET_break (0);
992  }
993 }
994 
995 
1005 {
1007  uint16_t msize;
1008 
1009  msize = sizeof(struct GNUNET_TESTBED_SlaveGetConfigurationMessage);
1010  msg = GNUNET_malloc (msize);
1011  msg->header.size = htons (msize);
1012  msg->header.type =
1014  msg->operation_id = GNUNET_htonll (op_id);
1015  msg->slave_id = htonl (slave_id);
1016  return msg;
1017 }
1018 
1019 
1027 static int
1029  const struct GNUNET_TESTBED_SlaveConfiguration *msg)
1030 {
1031  /* anything goes? */
1032  return GNUNET_OK;
1033 }
1034 
1035 
1043 static void
1045  const struct GNUNET_TESTBED_SlaveConfiguration *msg)
1046 {
1047  struct GNUNET_TESTBED_Controller *c = cls;
1048  struct OperationContext *opc;
1049  uint64_t op_id;
1050  uint64_t mask;
1051  struct GNUNET_TESTBED_EventInformation event;
1052 
1053  op_id = GNUNET_ntohll (msg->operation_id);
1054  if (NULL == (opc = find_opc (c, op_id)))
1055  {
1056  LOG_DEBUG ("Operation not found\n");
1057  return;
1058  }
1059  if (OP_GET_SLAVE_CONFIG != opc->type)
1060  {
1061  GNUNET_break (0);
1062  return;
1063  }
1064  opc->state = OPC_STATE_FINISHED;
1065  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1067  if ((0 != (mask & c->event_mask)) && (NULL != c->cc))
1068  {
1069  opc->data = GNUNET_TESTBED_extract_config_ (&msg->header);
1071  event.op = opc->op;
1072  event.op_cls = opc->op_cls;
1073  event.details.operation_finished.generic = opc->data;
1074  event.details.operation_finished.emsg = NULL;
1075  c->cc (c->cc_cls, &event);
1076  }
1077 }
1078 
1079 
1088 static int
1090  void *cls,
1092 {
1093  /* actual check to be implemented */
1094  return GNUNET_OK;
1095 }
1096 
1097 
1105 static void
1107  void *cls,
1109 {
1110  struct GNUNET_TESTBED_Controller *c = cls;
1111  struct OperationContext *opc;
1112  struct ControllerLinkData *data;
1114  struct GNUNET_TESTBED_Host *host;
1115  char *emsg;
1116  uint64_t op_id;
1117  struct GNUNET_TESTBED_EventInformation event;
1118 
1119  op_id = GNUNET_ntohll (msg->operation_id);
1120  if (NULL == (opc = find_opc (c, op_id)))
1121  {
1122  LOG_DEBUG ("Operation not found\n");
1123  return;
1124  }
1125  if (OP_FORWARDED == opc->type)
1126  {
1128  opc,
1129  (const struct GNUNET_MessageHeader *) msg);
1130  return;
1131  }
1132  if (OP_LINK_CONTROLLERS != opc->type)
1133  {
1134  GNUNET_break (0);
1135  return;
1136  }
1137  GNUNET_assert (NULL != (data = opc->data));
1139  GNUNET_assert (NULL != host);
1140  GNUNET_free (data);
1141  opc->data = NULL;
1142  opc->state = OPC_STATE_FINISHED;
1143  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1145  event.op = opc->op;
1146  event.op_cls = opc->op_cls;
1147  event.details.operation_finished.emsg = NULL;
1148  event.details.operation_finished.generic = NULL;
1149  emsg = NULL;
1150  cfg = NULL;
1151  if (GNUNET_NO == ntohs (msg->success))
1152  {
1153  emsg =
1154  GNUNET_malloc (ntohs (msg->header.size)
1155  - sizeof(struct GNUNET_TESTBED_ControllerLinkResponse)
1156  + 1);
1158  &msg[1],
1159  ntohs (msg->header.size)
1160  - sizeof(struct GNUNET_TESTBED_ControllerLinkResponse));
1161  event.details.operation_finished.emsg = emsg;
1162  }
1163  else
1164  {
1165  if (0 != ntohs (msg->config_size))
1166  {
1168  (const struct GNUNET_MessageHeader *) msg);
1169  GNUNET_assert (NULL != cfg);
1171  }
1172  }
1173  if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
1174  {
1175  if (NULL != c->cc)
1176  c->cc (c->cc_cls, &event);
1177  }
1178  else
1179  LOG_DEBUG ("Not calling callback\n");
1180  if (NULL != cfg)
1182  GNUNET_free (emsg);
1183 }
1184 
1185 
1195 static int
1197  const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
1198 {
1199  uint16_t msize;
1200  uint16_t name_len;
1201  int status;
1202  const char *name;
1203  size_t emsg_len;
1204 
1205  msize = ntohs (msg->header.size);
1206  name = msg->data;
1207  name_len = ntohs (msg->name_len);
1208 
1209  if (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize)
1210  {
1211  GNUNET_break_op (0);
1212  return GNUNET_SYSERR;
1213  }
1214  if ('\0' != name[name_len])
1215  {
1216  GNUNET_break_op (0);
1217  return GNUNET_SYSERR;
1218  }
1219  status = ntohs (msg->status);
1221  {
1222  emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg)
1223  + name_len + 1); /* +1!? */
1224  if (0 == emsg_len)
1225  {
1226  GNUNET_break_op (0);
1227  return GNUNET_SYSERR;
1228  }
1229  }
1230  return GNUNET_OK;
1231 }
1232 
1233 
1241 static void
1243  const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
1244 {
1245  struct GNUNET_TESTBED_Controller *c = cls;
1246  struct GNUNET_TESTBED_Barrier *barrier;
1247  char *emsg;
1248  const char *name;
1249  struct GNUNET_HashCode key;
1250  size_t emsg_len;
1251  int status;
1252  uint16_t msize;
1253  uint16_t name_len;
1254 
1255  emsg = NULL;
1256  barrier = NULL;
1257  msize = ntohs (msg->header.size);
1258  if (msize <= sizeof(struct GNUNET_TESTBED_BarrierStatusMsg))
1259  {
1260  GNUNET_break_op (0);
1261  goto cleanup;
1262  }
1263  name = msg->data;
1264  name_len = ntohs (msg->name_len);
1265  if (name_len >= // name_len is strlen(barrier_name)
1266  (msize - ((sizeof msg->header) + sizeof(msg->status))))
1267  {
1268  GNUNET_break_op (0);
1269  goto cleanup;
1270  }
1271  if ('\0' != name[name_len])
1272  {
1273  GNUNET_break_op (0);
1274  goto cleanup;
1275  }
1276  LOG_DEBUG ("Received BARRIER_STATUS msg\n");
1277  status = ntohs (msg->status);
1279  {
1280  status = -1;
1281  // unlike name_len, emsg_len includes the trailing zero
1282  emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg)
1283  + (name_len + 1));
1284  if (0 == emsg_len)
1285  {
1286  GNUNET_break_op (0);
1287  goto cleanup;
1288  }
1289  if ('\0' != (msg->data[(name_len + 1) + (emsg_len - 1)]))
1290  {
1291  GNUNET_break_op (0);
1292  goto cleanup;
1293  }
1294  emsg = GNUNET_malloc (emsg_len);
1295  GNUNET_memcpy (emsg, msg->data + name_len + 1, emsg_len);
1296  }
1297  if (NULL == c->barrier_map)
1298  {
1299  GNUNET_break_op (0);
1300  goto cleanup;
1301  }
1304  if (NULL == barrier)
1305  {
1306  GNUNET_break_op (0);
1307  goto cleanup;
1308  }
1309  GNUNET_assert (NULL != barrier->cb);
1310  if ((GNUNET_YES == barrier->echo) &&
1313  barrier->cb (barrier->cls, name, barrier, status, emsg);
1315  return; /* just initialised; skip cleanup */
1316 
1317 cleanup:
1318  GNUNET_free (emsg);if ((NULL != barrier) && (GNUNET_YES == barrier->echo))
1326 }
1327 
1328 
1335 void
1337  struct GNUNET_MessageHeader *msg)
1338 {
1339  struct GNUNET_MQ_Envelope *env;
1340  struct GNUNET_MessageHeader *m2;
1341  uint16_t type;
1342  uint16_t size;
1343 
1344  type = ntohs (msg->type);
1345  size = ntohs (msg->size);
1348  env = GNUNET_MQ_msg_extra (m2, size - sizeof(*m2), type);
1349  GNUNET_memcpy (m2, msg, size);
1350  GNUNET_free (msg);
1351  GNUNET_MQ_send (controller->mq, env);
1352 }
1353 
1354 
1369 struct OperationContext *
1371  struct GNUNET_TESTBED_Controller *controller,
1372  uint64_t operation_id,
1373  const struct GNUNET_MessageHeader *msg,
1375  void *cc_cls)
1376 {
1377  struct OperationContext *opc;
1378  struct ForwardedOperationData *data;
1379  struct GNUNET_MQ_Envelope *env;
1380  struct GNUNET_MessageHeader *m2;
1381  uint16_t type = ntohs (msg->type);
1382  uint16_t size = ntohs (msg->size);
1383 
1384  env = GNUNET_MQ_msg_extra (m2, size - sizeof(*m2), type);
1385  GNUNET_memcpy (m2, msg, size);
1386  GNUNET_MQ_send (controller->mq, env);
1388  data->cc = cc;
1389  data->cc_cls = cc_cls;
1390  opc = GNUNET_new (struct OperationContext);
1391  opc->c = controller;
1392  opc->type = OP_FORWARDED;
1393  opc->data = data;
1394  opc->id = operation_id;
1395  GNUNET_TESTBED_insert_opc_ (controller, opc);
1396  return opc;
1397 }
1398 
1399 
1406 void
1408 {
1409  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1410  GNUNET_free (opc->data);
1411  GNUNET_free (opc);
1412 }
1413 
1414 
1421 static void
1423 {
1424  struct OperationContext *opc = cls;
1425  struct ControllerLinkData *data;
1427 
1428  GNUNET_assert (NULL != opc->data);
1429  data = opc->data;
1430  msg = data->msg;
1431  data->msg = NULL;
1432  opc->state = OPC_STATE_STARTED;
1433  GNUNET_TESTBED_insert_opc_ (opc->c, opc);
1434  GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
1435 }
1436 
1437 
1443 static void
1445 {
1446  struct OperationContext *opc = cls;
1447  struct ControllerLinkData *data;
1448 
1449  data = opc->data;
1450  switch (opc->state)
1451  {
1452  case OPC_STATE_INIT:
1453  GNUNET_free (data->msg);
1454  break;
1455 
1456  case OPC_STATE_STARTED:
1457  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1458  break;
1459 
1460  case OPC_STATE_FINISHED:
1461  break;
1462  }
1463  GNUNET_free (data);
1464  GNUNET_free (opc);
1465 }
1466 
1467 
1473 static void
1475 {
1476  struct OperationContext *opc = cls;
1477  struct GetSlaveConfigData *data = opc->data;
1479 
1480  GNUNET_assert (NULL != data);
1482  GNUNET_free (opc->data);
1483  data = NULL;
1484  opc->data = NULL;
1485  GNUNET_TESTBED_insert_opc_ (opc->c, opc);
1486  GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
1487  opc->state = OPC_STATE_STARTED;
1488 }
1489 
1490 
1496 static void
1498 {
1499  struct OperationContext *opc = cls;
1500 
1501  switch (opc->state)
1502  {
1503  case OPC_STATE_INIT:
1504  GNUNET_free (opc->data);
1505  break;
1506 
1507  case OPC_STATE_STARTED:
1508  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1509  break;
1510 
1511  case OPC_STATE_FINISHED:
1512  if (NULL != opc->data)
1514  break;
1515  }
1516  GNUNET_free (opc);
1517 }
1518 
1519 
1528 static void
1529 mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
1530 {
1531  /* struct GNUNET_TESTBED_Controller *c = cls; */
1532 
1533  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Encountered MQ error: %d\n", error);
1534  /* now what? */
1535  GNUNET_SCHEDULER_shutdown (); /* seems most reasonable */
1536 }
1537 
1538 
1556  uint64_t event_mask,
1558  void *cc_cls)
1559 {
1560  struct GNUNET_TESTBED_Controller *controller =
1563  { GNUNET_MQ_hd_var_size (add_host_confirm,
1566  controller),
1567  GNUNET_MQ_hd_fixed_size (peer_conevent,
1570  controller),
1571  GNUNET_MQ_hd_fixed_size (opsuccess,
1573  struct
1575  controller),
1576  GNUNET_MQ_hd_var_size (op_fail_event,
1579  controller),
1580  GNUNET_MQ_hd_fixed_size (peer_create_success,
1582  struct
1584  controller),
1585  GNUNET_MQ_hd_fixed_size (peer_event,
1588  controller),
1589  GNUNET_MQ_hd_var_size (peer_config,
1591  struct
1593  controller),
1594  GNUNET_MQ_hd_var_size (slave_config,
1597  controller),
1598  GNUNET_MQ_hd_var_size (link_controllers_result,
1601  controller),
1602  GNUNET_MQ_hd_var_size (barrier_status,
1605  controller),
1606  GNUNET_MQ_handler_end () };
1608  struct GNUNET_MQ_Envelope *env;
1609  const struct GNUNET_CONFIGURATION_Handle *cfg;
1610  const char *controller_hostname;
1611  unsigned long long max_parallel_operations;
1612  unsigned long long max_parallel_service_connections;
1613  unsigned long long max_parallel_topology_config_operations;
1614  size_t slen;
1615 
1616  GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
1617  if (GNUNET_OK !=
1619  "testbed",
1620  "MAX_PARALLEL_OPERATIONS",
1621  &max_parallel_operations))
1622  {
1623  GNUNET_break (0);
1624  GNUNET_free (controller);
1625  return NULL;
1626  }
1627  if (GNUNET_OK !=
1629  "testbed",
1630  "MAX_PARALLEL_SERVICE_CONNECTIONS",
1631  &max_parallel_service_connections))
1632  {
1633  GNUNET_break (0);
1634  GNUNET_free (controller);
1635  return NULL;
1636  }
1638  cfg,
1639  "testbed",
1640  "MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS",
1641  &max_parallel_topology_config_operations))
1642  {
1643  GNUNET_break (0);
1644  GNUNET_free (controller);
1645  return NULL;
1646  }
1647  controller->cc = cc;
1648  controller->cc_cls = cc_cls;
1649  controller->event_mask = event_mask;
1650  controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
1651  controller->mq = GNUNET_CLIENT_connect (controller->cfg,
1652  "testbed",
1653  handlers,
1655  controller);
1656  if (NULL == controller->mq)
1657  {
1658  GNUNET_break (0);
1660  return NULL;
1661  }
1662  GNUNET_TESTBED_mark_host_registered_at_ (host, controller);
1663  controller->host = host;
1664  controller->opq_parallel_operations =
1666  (unsigned int)
1667  max_parallel_operations);
1668  controller->opq_parallel_service_connections =
1670  (unsigned int)
1671  max_parallel_service_connections);
1675  (unsigned int) max_parallel_topology_config_operations);
1676  controller_hostname = GNUNET_TESTBED_host_get_hostname (host);
1677  if (NULL == controller_hostname)
1678  controller_hostname = "127.0.0.1";
1679  slen = strlen (controller_hostname) + 1;
1681  msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1682  msg->event_mask = GNUNET_htonll (controller->event_mask);
1683  GNUNET_memcpy (&msg[1], controller_hostname, slen);
1684  GNUNET_MQ_send (controller->mq, env);
1685  return controller;
1686 }
1687 
1688 
1698 static int
1699 opc_free_iterator (void *cls, uint32_t key, void *value)
1700 {
1701  struct GNUNET_CONTAINER_MultiHashMap32 *map = cls;
1702  struct OperationContext *opc = value;
1703 
1704  GNUNET_assert (NULL != opc);
1705  GNUNET_break (0);
1708  GNUNET_free (opc);
1709  return GNUNET_YES;
1710 }
1711 
1712 
1720 void
1722 {
1723  if (NULL != c->mq)
1724  {
1725  GNUNET_MQ_destroy (c->mq);
1726  c->mq = NULL;
1727  }
1728  if (NULL != c->host)
1735  if (NULL != c->opc_map)
1736  {
1740  c->opc_map));
1743  }
1744  GNUNET_free (c);
1745 }
1746 
1747 
1757 size_t
1759  size_t size,
1760  char **xconfig)
1761 {
1762  size_t xsize;
1763 
1764  xsize = compressBound ((uLong) size);
1765  *xconfig = GNUNET_malloc (xsize);
1766  GNUNET_assert (Z_OK == compress2 ((Bytef *) *xconfig,
1767  (uLongf *) &xsize,
1768  (const Bytef *) config,
1769  (uLongf) size,
1770  Z_BEST_SPEED));
1771  return xsize;
1772 }
1773 
1774 
1784 char *
1786  size_t *size,
1787  size_t *xsize)
1788 {
1789  char *config;
1790  char *xconfig;
1791  size_t size_;
1792  size_t xsize_;
1793 
1795  xsize_ = GNUNET_TESTBED_compress_config_ (config, size_, &xconfig);
1796  GNUNET_free (config);
1797  *size = size_;
1798  *xsize = xsize_;
1799  return xconfig;
1800 }
1801 
1802 
1831 struct GNUNET_TESTBED_Operation *
1833  struct GNUNET_TESTBED_Controller *master,
1834  struct GNUNET_TESTBED_Host *delegated_host,
1835  struct GNUNET_TESTBED_Host *slave_host,
1836  int is_subordinate)
1837 {
1838  struct OperationContext *opc;
1840  struct ControllerLinkData *data;
1841  uint32_t slave_host_id;
1842  uint32_t delegated_host_id;
1843  uint16_t msg_size;
1844 
1846  GNUNET_TESTBED_is_host_registered_ (delegated_host, master));
1847  slave_host_id = GNUNET_TESTBED_host_get_id_ (
1848  (NULL != slave_host) ? slave_host : master->host);
1849  delegated_host_id = GNUNET_TESTBED_host_get_id_ (delegated_host);
1850  if ((NULL != slave_host) && (0 != slave_host_id))
1852  GNUNET_TESTBED_is_host_registered_ (slave_host, master));
1853  msg_size = sizeof(struct GNUNET_TESTBED_ControllerLinkRequest);
1854  msg = GNUNET_malloc (msg_size);
1856  msg->header.size = htons (msg_size);
1857  msg->delegated_host_id = htonl (delegated_host_id);
1858  msg->slave_host_id = htonl (slave_host_id);
1859  msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0;
1860  data = GNUNET_new (struct ControllerLinkData);
1861  data->msg = msg;
1862  data->host_id = delegated_host_id;
1863  opc = GNUNET_new (struct OperationContext);
1864  opc->c = master;
1865  opc->data = data;
1866  opc->type = OP_LINK_CONTROLLERS;
1867  opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
1868  opc->state = OPC_STATE_INIT;
1869  opc->op_cls = op_cls;
1870  msg->operation_id = GNUNET_htonll (opc->id);
1875  opc->op);
1877  return opc->op;
1878 }
1879 
1880 
1893 struct GNUNET_TESTBED_Operation *
1895  struct GNUNET_TESTBED_Controller *master,
1896  uint32_t slave_host_id)
1897 {
1898  struct OperationContext *opc;
1899  struct GetSlaveConfigData *data;
1900 
1901  data = GNUNET_new (struct GetSlaveConfigData);
1902  data->slave_id = slave_host_id;
1903  opc = GNUNET_new (struct OperationContext);
1904  opc->state = OPC_STATE_INIT;
1905  opc->c = master;
1906  opc->id = GNUNET_TESTBED_get_next_op_id (master);
1907  opc->type = OP_GET_SLAVE_CONFIG;
1908  opc->data = data;
1909  opc->op_cls = op_cls;
1914  opc->op);
1916  return opc->op;
1917 }
1918 
1919 
1920 struct GNUNET_TESTBED_Operation *
1922  struct GNUNET_TESTBED_Controller *master,
1923  struct GNUNET_TESTBED_Host *slave_host)
1924 {
1925  if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_ (slave_host, master))
1926  return NULL;
1927  return GNUNET_TESTBED_get_slave_config_ (op_cls,
1928  master,
1930  slave_host));
1931 }
1932 
1933 
1934 void
1936  struct GNUNET_TESTBED_Controller *controller,
1937  const char *filename)
1938 {
1939  GNUNET_break (0);
1940 }
1941 
1942 
1958  const char *trusted_ip,
1959  const char *hostname,
1960  const struct GNUNET_CONFIGURATION_Handle *cfg)
1961 {
1963  char *config;
1964  char *xconfig;
1965  size_t config_size;
1966  size_t xconfig_size;
1967  uint16_t trusted_ip_len;
1968  uint16_t hostname_len;
1969  uint16_t msg_size;
1970 
1972  GNUNET_assert (NULL != config);
1973  xconfig_size =
1975  GNUNET_free (config);
1976  trusted_ip_len = strlen (trusted_ip);
1977  hostname_len = (NULL == hostname) ? 0 : strlen (hostname);
1978  msg_size = xconfig_size + trusted_ip_len + 1
1979  + sizeof(struct GNUNET_TESTBED_HelperInit);
1980  msg_size += hostname_len;
1981  msg = GNUNET_realloc (xconfig, msg_size);
1982  (void) memmove (((void *) &msg[1]) + trusted_ip_len + 1 + hostname_len,
1983  msg,
1984  xconfig_size);
1985  msg->header.size = htons (msg_size);
1987  msg->trusted_ip_size = htons (trusted_ip_len);
1988  msg->hostname_size = htons (hostname_len);
1989  msg->config_size = htons (config_size);
1990  (void) strcpy ((char *) &msg[1], trusted_ip);
1991  if (0 != hostname_len)
1992  GNUNET_memcpy ((char *) &msg[1] + trusted_ip_len + 1,
1993  hostname,
1994  hostname_len);
1995  return msg;
1996 }
1997 
1998 
2020 void
2022 {
2023  (void) exop_check (operation);
2025 }
2026 
2027 
2044 {
2046  Bytef *data;
2047  const Bytef *xdata;
2048  uLong data_len;
2049  uLong xdata_len;
2050  int ret;
2051 
2052  switch (ntohs (msg->type))
2053  {
2056 
2057  imsg =
2059  data_len = (uLong) ntohs (imsg->config_size);
2060  xdata_len =
2061  ntohs (imsg->header.size)
2063  xdata = (const Bytef *) &imsg[1];
2064  }
2065  break;
2066 
2068  const struct GNUNET_TESTBED_SlaveConfiguration *imsg;
2069 
2070  imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *) msg;
2071  data_len = (uLong) ntohs (imsg->config_size);
2072  xdata_len = ntohs (imsg->header.size)
2073  - sizeof(struct GNUNET_TESTBED_SlaveConfiguration);
2074  xdata = (const Bytef *) &imsg[1];
2075  }
2076  break;
2077 
2079  const struct GNUNET_TESTBED_AddHostMessage *imsg;
2080  uint16_t osize;
2081 
2082  imsg = (const struct GNUNET_TESTBED_AddHostMessage *) msg;
2083  data_len = (uLong) ntohs (imsg->config_size);
2084  osize = sizeof(struct GNUNET_TESTBED_AddHostMessage)
2085  + ntohs (imsg->username_length) + ntohs (imsg->hostname_length);
2086  xdata_len = ntohs (imsg->header.size) - osize;
2087  xdata = (const Bytef *) ((const void *) imsg + osize);
2088  }
2089  break;
2090 
2092  const struct GNUNET_TESTBED_ControllerLinkResponse *imsg;
2093 
2094  imsg = (const struct GNUNET_TESTBED_ControllerLinkResponse *) msg;
2095  data_len = ntohs (imsg->config_size);
2096  xdata_len = ntohs (imsg->header.size)
2097  - sizeof(const struct GNUNET_TESTBED_ControllerLinkResponse);
2098  xdata = (const Bytef *) &imsg[1];
2099  }
2100  break;
2101 
2103  const struct GNUNET_TESTBED_PeerCreateMessage *imsg;
2104 
2105  imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *) msg;
2106  data_len = ntohs (imsg->config_size);
2107  xdata_len = ntohs (imsg->header.size)
2108  - sizeof(struct GNUNET_TESTBED_PeerCreateMessage);
2109  xdata = (const Bytef *) &imsg[1];
2110  }
2111  break;
2112 
2114  const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg;
2115 
2116  imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) msg;
2117  data_len = ntohs (imsg->config_size);
2118  xdata_len = ntohs (imsg->header.size)
2119  - sizeof(struct GNUNET_TESTBED_PeerReconfigureMessage);
2120  xdata = (const Bytef *) &imsg[1];
2121  }
2122  break;
2123 
2124  default:
2125  GNUNET_assert (0);
2126  }
2127  data = GNUNET_malloc (data_len);
2128  if (Z_OK != (ret = uncompress (data, &data_len, xdata, xdata_len)))
2129  {
2130  GNUNET_free (data);
2131  GNUNET_break_op (0); /* Un-compression failure */
2132  return NULL;
2133  }
2136  (const char *) data,
2137  (size_t) data_len,
2138  NULL))
2139  {
2140  GNUNET_free (data);
2141  GNUNET_break_op (0); /* De-serialization failure */
2142  return NULL;
2143  }
2144  GNUNET_free (data);
2145  return cfg;
2146 }
2147 
2148 
2149 const char *
2152 {
2153  uint16_t msize;
2154  const char *emsg;
2155 
2156  msize = ntohs (msg->header.size);
2157  if (sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage) >= msize)
2158  return NULL;
2159  msize -= sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage);
2160  emsg = (const char *) &msg[1];
2161  if ('\0' != emsg[msize - 1])
2162  {
2163  GNUNET_break (0);
2164  return NULL;
2165  }
2166  return emsg;
2167 }
2168 
2169 
2177 uint64_t
2179 {
2180  uint64_t op_id;
2181 
2182  op_id = (uint64_t) GNUNET_TESTBED_host_get_id_ (controller->host);
2183  op_id = op_id << 32;
2184  op_id |= (uint64_t) controller->operation_counter++;
2185  return op_id;
2186 }
2187 
2188 
2194 static void
2196 {
2197  struct OperationContext *opc = cls;
2198  struct GNUNET_MQ_Envelope *env;
2200 
2201  opc->state = OPC_STATE_STARTED;
2203  msg->operation_id = GNUNET_htonll (opc->id);
2204  GNUNET_TESTBED_insert_opc_ (opc->c, opc);
2205  GNUNET_MQ_send (opc->c->mq, env);
2206 }
2207 
2208 
2214 static void
2216 {
2217  struct OperationContext *opc = cls;
2218 
2219  switch (opc->state)
2220  {
2221  case OPC_STATE_STARTED:
2222  GNUNET_TESTBED_remove_opc_ (opc->c, opc);
2223 
2224  /* no break; continue */
2225  case OPC_STATE_INIT:
2226  GNUNET_free (opc->data);
2227  break;
2228 
2229  case OPC_STATE_FINISHED:
2230  break;
2231  }
2232  GNUNET_free (opc);
2233 }
2234 
2235 
2251 struct GNUNET_TESTBED_Operation *
2253  void *op_cls,
2255  void *cb_cls)
2256 {
2257  struct OperationContext *opc;
2258  struct ShutdownPeersData *data;
2259 
2261  return NULL;
2262  data = GNUNET_new (struct ShutdownPeersData);
2263  data->cb = cb;
2264  data->cb_cls = cb_cls;
2265  opc = GNUNET_new (struct OperationContext);
2266  opc->c = c;
2267  opc->op_cls = op_cls;
2268  opc->data = data;
2269  opc->id = GNUNET_TESTBED_get_next_op_id (c);
2270  opc->type = OP_SHUTDOWN_PEERS;
2271  opc->state = OPC_STATE_INIT;
2276  opc->op);
2278  return opc->op;
2279 }
2280 
2281 
2290 uint32_t
2292 {
2293  return peer->unique_id;
2294 }
2295 
2296 
2303 void
2305 {
2306  struct GNUNET_TESTBED_Controller *c = barrier->c;
2307 
2308  GNUNET_assert (NULL != c->barrier_map); /* No barriers present */
2311  &barrier->key,
2312  barrier));
2313  GNUNET_free (barrier->name);
2314  GNUNET_free (barrier);
2316  {
2318  c->barrier_map = NULL;
2319  }
2320 }
2321 
2322 
2323 struct GNUNET_TESTBED_Barrier *
2325  const char *name,
2326  unsigned int quorum,
2328  void *cls,
2329  int echo)
2330 {
2332  struct GNUNET_MQ_Envelope *env;
2333  struct GNUNET_TESTBED_Barrier *barrier;
2334  struct GNUNET_HashCode key;
2335  size_t name_len;
2336 
2337  GNUNET_assert (quorum <= 100);
2338  GNUNET_assert (NULL != cb);
2339  name_len = strlen (name);
2340  GNUNET_assert (0 < name_len);
2341  GNUNET_CRYPTO_hash (name, name_len, &key);
2342  if (NULL == controller->barrier_map)
2343  controller->barrier_map =
2345  if (GNUNET_YES ==
2347  {
2348  GNUNET_break (0);
2349  return NULL;
2350  }
2351  LOG_DEBUG ("Initialising barrier `%s'\n", name);
2352  barrier = GNUNET_new (struct GNUNET_TESTBED_Barrier);
2353  barrier->c = controller;
2354  barrier->name = GNUNET_strdup (name);
2355  barrier->cb = cb;
2356  barrier->cls = cls;
2357  barrier->echo = echo;
2358  GNUNET_memcpy (&barrier->key, &key, sizeof(struct GNUNET_HashCode));
2361  controller->barrier_map,
2362  &barrier->key,
2363  barrier,
2365 
2367  name_len,
2369  msg->quorum = (uint8_t) quorum;
2370  GNUNET_memcpy (msg->name, barrier->name, name_len);
2371  GNUNET_MQ_send (barrier->c->mq, env);
2372  return barrier;
2373 }
2374 
2375 
2390 struct GNUNET_TESTBED_Barrier *
2392  const char *name,
2393  unsigned int quorum,
2395  void *cb_cls)
2396 {
2397  return GNUNET_TESTBED_barrier_init_ (controller,
2398  name,
2399  quorum,
2400  cb,
2401  cb_cls,
2402  GNUNET_YES);
2403 }
2404 
2405 
2411 void
2413 {
2414  struct GNUNET_MQ_Envelope *env;
2416  size_t slen;
2417 
2418  slen = strlen (barrier->name);
2419  env =
2421  GNUNET_memcpy (msg->name, barrier->name, slen);
2422  GNUNET_MQ_send (barrier->c->mq, env);
2424 }
2425 
2426 
2427 /* end of testbed_api.c */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static int echo
Request echo service.
Definition: gnunet-cadet.c:67
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
struct GNUNET_HashCode key
The key used in the DHT.
static char * filename
uint32_t data
The data value.
uint16_t status
See PRISM_STATUS_*-constants.
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
static char * hostname
Our hostname; we give this to all the peers we start.
static const struct GNUNET_CONFIGURATION_Handle * config
uint64_t event_mask
Global event mask for all testbed events.
Core service; the main API for encrypted P2P communications.
Helper library for handling HELLOs.
API for writing tests and creating large-scale emulation testbeds for GNUnet.
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
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
int GNUNET_CONTAINER_multihashmap32_get_multiple(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, GNUNET_CONTAINER_MultiHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_remove(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
unsigned int GNUNET_CONTAINER_multihashmap32_size(const struct GNUNET_CONTAINER_MultiHashMap32 *map)
Get the number of key-value pairs in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MultiHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#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_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
#define GNUNET_free(ptr)
Wrapper around free.
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_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_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_MessageCallback)(void *cls, const struct GNUNET_MessageHeader *msg)
Called when a message has been received.
#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
#define GNUNET_MESSAGE_TYPE_TESTBED_INIT
Initial message from a client to a testing control service.
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT
Message to initialise a barrier.
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL
Message to cancel a barrier.
#define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT
Message to signal the result of GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS request.
#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT
Message for peer events.
#define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST
Message to add host.
#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS
Message to signal successful peer creation.
#define GNUNET_MESSAGE_TYPE_TESTBED_MAX
Not really a message, but for careful checks on the testbed messages; Should always be the maximum an...
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS
Message for signalling status of a barrier.
#define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS
Message to signal that a add host succeeded.
#define GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION
Message which contains the configuration of slave controller.
#define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS
Message to link delegated controller to slave controller.
#define GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS
Message to signal a generic operation has been successful.
#define GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION
Message to request configuration of a slave controller.
#define GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER
Message to reconfigure a peer.
#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER
Message to create a peer at a host.
#define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT
Message for operation events.
#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION
Message containing the peer's information.
#define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS
A controller receiving this message floods it to its directly-connected sub-controllers and then stop...
#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT
Message for peer connect events.
#define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT
The initialization message towards gnunet-testbed-helper.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
void(* GNUNET_TESTBED_ControllerCallback)(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Signature of the event handler function called by the respective event controller.
struct GNUNET_TESTBED_Barrier * GNUNET_TESTBED_barrier_init(struct GNUNET_TESTBED_Controller *controller, const char *name, unsigned int quorum, GNUNET_TESTBED_barrier_status_cb cb, void *cb_cls)
Initialise a barrier and call the given callback when the required percentage of peers (quorum) reach...
Definition: testbed_api.c:2391
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2021
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_get_slave_config(void *op_cls, struct GNUNET_TESTBED_Controller *master, struct GNUNET_TESTBED_Host *slave_host)
Function to acquire the configuration of a running slave controller.
Definition: testbed_api.c:1921
void(* GNUNET_TESTBED_barrier_status_cb)(void *cls, const char *name, struct GNUNET_TESTBED_Barrier *barrier, enum GNUNET_TESTBED_BarrierStatus status, const char *emsg)
Functions of this type are to be given as callback argument to GNUNET_TESTBED_barrier_init().
void(* GNUNET_TESTBED_PeerChurnCallback)(void *cls, const char *emsg)
Functions of this signature are called when a peer has been successfully started or stopped.
void(* GNUNET_TESTBED_OperationCompletionCallback)(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
Callback to be called when an operation is completed.
void(* GNUNET_TESTBED_PeerCreateCallback)(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
Functions of this signature are called when a peer has been successfully created.
void GNUNET_TESTBED_controller_disconnect(struct GNUNET_TESTBED_Controller *c)
Stop the given controller (also will terminate all peers and controllers dependent on this controller...
Definition: testbed_api.c:1721
void GNUNET_TESTBED_overlay_write_topology_to_file(struct GNUNET_TESTBED_Controller *controller, const char *filename)
Ask the testbed controller to write the current overlay topology to a file.
Definition: testbed_api.c:1935
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_shutdown_peers(struct GNUNET_TESTBED_Controller *c, void *op_cls, GNUNET_TESTBED_OperationCompletionCallback cb, void *cb_cls)
Stops and destroys all peers.
Definition: testbed_api.c:2252
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_controller_link(void *op_cls, struct GNUNET_TESTBED_Controller *master, struct GNUNET_TESTBED_Host *delegated_host, struct GNUNET_TESTBED_Host *slave_host, int is_subordinate)
Create a link from slave controller to delegated controller.
Definition: testbed_api.c:1832
uint32_t GNUNET_TESTBED_get_index(const struct GNUNET_TESTBED_Peer *peer)
Return the index of the peer inside of the total peer array, aka.
Definition: testbed_api.c:2291
void(* GNUNET_TESTBED_PeerInfoCallback)(void *cb_cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg)
Callback to be called when the requested peer information is available The peer information in the ca...
GNUNET_TESTBED_EventType
Enumeration with (at most 64) possible event types that can be monitored using the testbed framework.
struct GNUNET_TESTBED_Controller * GNUNET_TESTBED_controller_connect(struct GNUNET_TESTBED_Host *host, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls)
Start a controller process using the given configuration at the given host.
Definition: testbed_api.c:1555
const char * GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host)
Obtain the host's hostname.
void GNUNET_TESTBED_barrier_cancel(struct GNUNET_TESTBED_Barrier *barrier)
Cancel a barrier.
Definition: testbed_api.c:2412
@ GNUNET_TESTBED_PIT_CONFIGURATION
What configuration is the peer using? Returns a 'const struct GNUNET_CONFIGURATION_Handle *'.
@ GNUNET_TESTBED_PIT_IDENTITY
What is the identity of the peer? Returns a 'const struct GNUNET_PeerIdentity *'.
@ GNUNET_TESTBED_PIT_GENERIC
Special value (not valid for requesting information) that is used in the event struct if a 'generic' ...
@ GNUNET_TESTBED_ET_CONNECT
A connection between two peers was established.
@ GNUNET_TESTBED_ET_OPERATION_FINISHED
A requested testbed operation has been completed.
@ GNUNET_TESTBED_ET_PEER_START
A peer has been started.
@ GNUNET_TESTBED_ET_DISCONNECT
A connection between two peers was torn down.
@ GNUNET_TESTBED_ET_PEER_STOP
A peer has been stopped.
@ GNUNET_TESTBED_BARRIERSTATUS_CROSSED
Barrier is crossed.
@ GNUNET_TESTBED_BARRIERSTATUS_ERROR
Error status.
@ GNUNET_TESTBED_BARRIERSTATUS_INITIALISED
Barrier initialised successfully.
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
const char * name
Context data for controller link operations.
Definition: testbed_api.c:100
struct GNUNET_TESTBED_ControllerLinkRequest * msg
The controller link message.
Definition: testbed_api.c:104
uint32_t host_id
The id of the host which is hosting the controller to be linked.
Definition: testbed_api.c:109
An entry in the stack for keeping operations which are about to expire.
Definition: testbed_api.c:134
struct ExpireOperationEntry * next
DLL head; new entries are to be inserted here.
Definition: testbed_api.c:138
struct ExpireOperationEntry * prev
DLL tail; entries are deleted from here.
Definition: testbed_api.c:143
const struct GNUNET_TESTBED_Operation * op
The operation.
Definition: testbed_api.c:148
Context data for forwarded Operation.
Definition: testbed_api.c:71
void * cc_cls
The closure for the above callback.
Definition: testbed_api.c:80
GNUNET_MQ_MessageCallback cc
The callback to call when reply is available.
Definition: testbed_api.c:75
Internal representation of the hash map.
A 512-bit hashcode.
Message handler for a specific message type.
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
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).
Notify the service about a host that we intend to use.
Definition: testbed.h:65
uint16_t username_length
Number of bytes in the user name that follows; 0 to use no user name; otherwise 'strlen (username)',...
Definition: testbed.h:86
uint16_t hostname_length
Number of bytes in the host name (excluding 0-termination) that follows the user name; cannot be 0.
Definition: testbed.h:92
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST.
Definition: testbed.h:69
uint16_t config_size
The length of the uncompressed configuration.
Definition: testbed.h:97
Message to cancel a barrier.
Definition: testbed.h:805
Message to initialise a barrier.
Definition: testbed.h:783
Message for signalling status changes of a barrier.
Definition: testbed.h:822
uint16_t name_len
strlen of the barrier name
Definition: testbed.h:836
Handle for barrier.
Definition: testbed_api.h:278
GNUNET_TESTBED_barrier_status_cb cb
The continuation callback to call when we have a status update on this.
Definition: testbed_api.h:297
struct GNUNET_TESTBED_Controller * c
The controller handle given while initialising this barrier.
Definition: testbed_api.h:287
struct GNUNET_HashCode key
hashcode identifying this barrier in the hashmap
Definition: testbed_api.h:282
char * name
The name of the barrier.
Definition: testbed_api.h:292
int echo
Should the barrier crossed status message be echoed back to the controller?
Definition: testbed_api.h:307
void * cls
the closure for the above callback
Definition: testbed_api.h:302
Event notification from a controller to a client.
Definition: testbed.h:476
Client notifies controller that it should delegate requests for a particular client to a particular s...
Definition: testbed.h:137
uint32_t slave_host_id
Which host is responsible for managing the delegation? NBO.
Definition: testbed.h:156
uint32_t delegated_host_id
For which host should requests be delegated? NBO.
Definition: testbed.h:146
uint8_t is_subordinate
Set to 1 if the receiving controller is the master controller for the slave host (and thus responsibl...
Definition: testbed.h:162
Response message for ControllerLinkRequest message.
Definition: testbed.h:170
uint16_t config_size
The size of the compressed configuration.
Definition: testbed.h:180
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT.
Definition: testbed.h:174
Handle to interact with a GNUnet testbed controller.
Definition: testbed_api.h:194
uint32_t operation_counter
The operation id counter.
Definition: testbed_api.h:270
void * opcq_empty_cls
Closure for the above task.
Definition: testbed_api.h:239
uint64_t event_mask
The controller event mask.
Definition: testbed_api.h:265
struct GNUNET_CONTAINER_MultiHashMap32 * opc_map
The map of active operation contexts.
Definition: testbed_api.h:229
void * cc_cls
The closure for controller callback.
Definition: testbed_api.h:208
struct OperationQueue * opq_parallel_topology_config_operations
Operation queue for simultaneous topology configuration operations.
Definition: testbed_api.h:254
struct OperationQueue * opq_parallel_service_connections
Operation queue for simultaneous service connections.
Definition: testbed_api.h:249
struct GNUNET_MQ_Handle * mq
The message queue to the controller service.
Definition: testbed_api.h:218
TESTBED_opcq_empty_cb opcq_empty_cb
If this callback is not NULL, schedule it as a task when opc_map gets empty.
Definition: testbed_api.h:234
struct GNUNET_TESTBED_Host * host
The host where the controller is running.
Definition: testbed_api.h:198
GNUNET_TESTBED_ControllerCallback cc
The controller callback.
Definition: testbed_api.h:203
struct GNUNET_TESTBED_HostRegistrationHandle * rh
The host registration handle; NULL if no current registration requests are present.
Definition: testbed_api.h:224
struct OperationQueue * opq_parallel_operations
Operation queue for simultaneous operations.
Definition: testbed_api.h:244
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration to use while connecting to controller.
Definition: testbed_api.h:213
struct GNUNET_CONTAINER_MultiHashMap * barrier_map
handle for hashtable of barrier handles, values are of type struct GNUNET_TESTBED_Barrier.
Definition: testbed_api.h:260
Argument to GNUNET_TESTBED_ControllerCallback with details about the event.
enum GNUNET_TESTBED_EventType type
Type of the event.
struct GNUNET_TESTBED_Operation * op
Handle for the corresponding operation that generated this event.
const char * emsg
Error message for the operation, NULL on success.
struct GNUNET_TESTBED_Host * host
Handle for the host where the peer was started.
Event notification from a controller to a client for a generic operational success where the operatio...
Definition: testbed.h:558
Initialization message for gnunet-helper-testbed to start testbed service.
uint16_t config_size
The size of the uncompressed configuration.
Confirmation from the service that adding a host worked (or failed).
Definition: testbed.h:115
handle for host registration
struct GNUNET_TESTBED_Host * host
The host being registered.
struct GNUNET_TESTBED_Controller * c
The controller at which this host is being registered.
GNUNET_TESTBED_HostRegistrationCompletion cc
The Registration completion callback.
void * cc_cls
The closure for above callback.
Opaque handle to a host running experiments managed by the testing framework.
Initial message from a client to a testing control service.
Definition: testbed.h:37
Event notification from a controller to a client.
Definition: testbed.h:509
Opaque handle to an abstract operation to be executed by the testing framework.
void * cb_cls
Closure for callbacks.
Peer configuration and identity reply from controller to a client.
Definition: testbed.h:604
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION.
Definition: testbed.h:608
uint16_t config_size
The size of configuration when uncompressed.
Definition: testbed.h:628
Message sent from client to testing service to create (configure, but not start) a peer.
Definition: testbed.h:205
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER.
Definition: testbed.h:209
uint16_t config_size
Size of the uncompressed configuration.
Definition: testbed.h:229
Event notification from a controller to a client.
Definition: testbed.h:534
Event notification from a controller to a client.
Definition: testbed.h:443
Data returned from GNUNET_TESTBED_peer_get_information.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer.
union GNUNET_TESTBED_PeerInformation::@49 result
The result of the get information operation; Choose according to the pit.
enum GNUNET_TESTBED_PeerInformationType pit
Peer information type; captures which of the types in the 'op_result' is actually in use.
struct GNUNET_PeerIdentity * id
The identity of the peer.
Message sent from client to testing service to reconfigure a (stopped) a peer.
Definition: testbed.h:241
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER.
Definition: testbed.h:245
uint16_t config_size
The length of the serialized configuration when uncompressed.
Definition: testbed.h:260
A peer controlled by the testing framework.
enum PeerState state
Peer's state.
uint32_t unique_id
Globally unique ID of the peer.
struct GNUNET_TESTBED_Host * host
Which host does this peer run on?
Shutdown peers message.
Definition: testbed.h:689
Reply to GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION message.
Definition: testbed.h:660
uint16_t config_size
The size of the configuration when uncompressed.
Definition: testbed.h:679
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION.
Definition: testbed.h:664
Message to request configuration of a slave controller.
Definition: testbed.h:638
uint32_t slave_id
The id of the slave host.
Definition: testbed.h:647
Context data for get slave config operations.
Definition: testbed_api.c:88
uint32_t slave_id
The id of the slave controller.
Definition: testbed_api.c:92
GNUNET_TESTBED_OperationCompletionCallback cb
Context information for GNUNET_TESTBED_Operation.
Definition: testbed_api.h:137
void * op_cls
The operation closure.
Definition: testbed_api.h:151
enum OperationContextState state
The state of the operation.
Definition: testbed_api.h:171
enum OperationType type
The type of operation.
Definition: testbed_api.h:166
uint64_t id
The id of the operation.
Definition: testbed_api.h:161
struct GNUNET_TESTBED_Operation * op
The operation.
Definition: testbed_api.h:146
struct GNUNET_TESTBED_Controller * c
The controller to which this operation context belongs to.
Definition: testbed_api.h:141
void * data
Data relevant to the operation.
Definition: testbed_api.h:156
Data structure for OperationType OP_OVERLAY_CONNECT.
void * cb_cls
The closure for the above callback.
GNUNET_TESTBED_OperationCompletionCallback cb
The operation completion callback to call once this operation is done.
Data for the OperationType OP_PEER_CREATE.
Data for OperationType OP_PEER_START and OP_PEER_STOP.
GNUNET_TESTBED_PeerChurnCallback pcc
The Peer churn callback to call when this operation is completed.
void * pcc_cls
Closure for the above callback.
Data for the OperationType OP_PEER_INFO.
Context information to be used while searching for operation contexts.
Definition: testbed_api.c:226
uint64_t id
The id of the operation context we are searching for.
Definition: testbed_api.c:235
struct OperationContext * opc
The result of the search.
Definition: testbed_api.c:230
Date context for OP_SHUTDOWN_PEERS operations.
Definition: testbed_api.c:117
void * cb_cls
The closure for the above callback.
Definition: testbed_api.c:126
GNUNET_TESTBED_OperationCompletionCallback cb
The operation completion callback to call.
Definition: testbed_api.c:121
IPC messages between testing API and service ("controller")
static struct ExpireOperationEntry * exop_head
DLL head for list of operations marked for expiry.
Definition: testbed_api.c:155
void GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller, struct GNUNET_MessageHeader *msg)
Queues a message in send queue for sending to the service.
Definition: testbed_api.c:1336
static void handle_peer_conevent(void *cls, const struct GNUNET_TESTBED_ConnectionEventMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT message from controller (testbed service)
Definition: testbed_api.c:682
static void handle_link_controllers_result(void *cls, const struct GNUNET_TESTBED_ControllerLinkResponse *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT message from controller (testbed serv...
Definition: testbed_api.c:1106
static void handle_op_fail_event(void *cls, const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT message from controller (testbed service...
Definition: testbed_api.c:865
static void handle_opsuccess(void *cls, const struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS message from controller (testbed service)
Definition: testbed_api.c:439
static void handle_barrier_status(void *cls, const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages.
Definition: testbed_api.c:1242
static void handle_forwarded_operation_msg(void *cls, struct OperationContext *opc, const struct GNUNET_MessageHeader *msg)
Handler for forwarded operations.
Definition: testbed_api.c:415
struct GNUNET_TESTBED_HelperInit * GNUNET_TESTBED_create_helper_init_msg_(const char *trusted_ip, const char *hostname, const struct GNUNET_CONFIGURATION_Handle *cfg)
Creates a helper initialization message.
Definition: testbed_api.c:1957
static void handle_add_host_confirm(void *cls, const struct GNUNET_TESTBED_HostConfirmedMessage *msg)
Handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from controller (testbed service)
Definition: testbed_api.c:369
struct GNUNET_TESTBED_Barrier * GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller, const char *name, unsigned int quorum, GNUNET_TESTBED_barrier_status_cb cb, void *cls, int echo)
Initialise a barrier and call the given callback when the required percentage of peers (quorum) reach...
Definition: testbed_api.c:2324
void GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c, struct OperationContext *opc)
Removes the given operation context from the operation context map of the given controller.
Definition: testbed_api.c:319
static int exop_check(const struct GNUNET_TESTBED_Operation *const op)
Checks if an operation is present in the list of operations marked for expiry.
Definition: testbed_api.c:191
static int check_op_fail_event(void *cls, const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
Validate GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT message from controller (testbed service)
Definition: testbed_api.c:848
static int opc_search_iterator(void *cls, uint32_t key, void *value)
Search iterator for searching an operation context.
Definition: testbed_api.c:249
static void opstart_shutdown_peers(void *cls)
Function called when a shutdown peers operation is ready.
Definition: testbed_api.c:2195
static struct ExpireOperationEntry * exop_tail
DLL tail for list of operation marked for expiry.
Definition: testbed_api.c:160
static int check_link_controllers_result(void *cls, const struct GNUNET_TESTBED_ControllerLinkResponse *msg)
Check GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT message from controller (testbed service)
Definition: testbed_api.c:1089
#define LOG_DEBUG(...)
Debug logging.
Definition: testbed_api.c:52
char * GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size, size_t *xsize)
Function to serialize and compress using zlib a configuration through a configuration handle.
Definition: testbed_api.c:1785
static int check_barrier_status(void *cls, const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
Validate GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS message.
Definition: testbed_api.c:1196
const char * GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
Checks the integrity of the OpeationFailureEventMessage and if good returns the error message it cont...
Definition: testbed_api.c:2150
static void handle_peer_create_success(void *cls, const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS message from controller (testbed service)
Definition: testbed_api.c:543
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: testbed_api.c:1529
void GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier)
Remove a barrier and it was the last one in the barrier hash map, destroy the hash map.
Definition: testbed_api.c:2304
static void handle_slave_config(void *cls, const struct GNUNET_TESTBED_SlaveConfiguration *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION message from controller (testbed service)
Definition: testbed_api.c:1044
void GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc)
Function to cancel an operation created by simply forwarding an operation message.
Definition: testbed_api.c:1407
static void oprelease_shutdown_peers(void *cls)
Callback which will be called when shutdown peers operation is released.
Definition: testbed_api.c:2215
uint64_t GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller)
Function to return the operation id for a controller.
Definition: testbed_api.c:2178
static void opstart_link_controllers(void *cls)
Function to call to start a link-controllers type operation once all queues the operation is part of ...
Definition: testbed_api.c:1422
static void oprelease_link_controllers(void *cls)
Callback which will be called when link-controllers type operation is released.
Definition: testbed_api.c:1444
static void opstart_get_slave_config(void *cls)
Function to be called when get slave config operation is ready.
Definition: testbed_api.c:1474
static struct OperationContext * find_opc(const struct GNUNET_TESTBED_Controller *c, const uint64_t id)
Returns the operation context with the given id if found in the Operation context queues of the contr...
Definition: testbed_api.c:272
static int check_peer_config(void *cls, const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
Validate GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION message from controller (testbed service)
Definition: testbed_api.c:758
struct GNUNET_CONFIGURATION_Handle * GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg)
Generates configuration by uncompressing configuration in given message.
Definition: testbed_api.c:2043
struct OperationContext * GNUNET_TESTBED_forward_operation_msg_(struct GNUNET_TESTBED_Controller *controller, uint64_t operation_id, const struct GNUNET_MessageHeader *msg, GNUNET_MQ_MessageCallback cc, void *cc_cls)
Sends the given message as an operation.
Definition: testbed_api.c:1370
static void handle_peer_event(void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT message from controller (testbed service)
Definition: testbed_api.c:601
static int check_slave_config(void *cls, const struct GNUNET_TESTBED_SlaveConfiguration *msg)
Validate #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_INFORMATION message from controller (testbed service)
Definition: testbed_api.c:1028
#define LOG(kind,...)
Generic logging shorthand.
Definition: testbed_api.c:47
static void exop_insert(struct GNUNET_TESTBED_Operation *op)
Inserts an operation into the list of operations marked for expiry.
Definition: testbed_api.c:169
static int opc_free_iterator(void *cls, uint32_t key, void *value)
Iterator to free opc map entries.
Definition: testbed_api.c:1699
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_get_slave_config_(void *op_cls, struct GNUNET_TESTBED_Controller *master, uint32_t slave_host_id)
Like GNUNET_TESTBED_get_slave_config(), however without the host registration check.
Definition: testbed_api.c:1894
static void handle_peer_config(void *cls, const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION message from controller (testbed service)
Definition: testbed_api.c:775
static void oprelease_get_slave_config(void *cls)
Function to be called when get slave config operation is cancelled or finished.
Definition: testbed_api.c:1497
static struct GNUNET_TESTBED_SlaveGetConfigurationMessage * GNUNET_TESTBED_generate_slavegetconfig_msg_(uint64_t op_id, uint32_t slave_id)
Function to build GET_SLAVE_CONFIG message.
Definition: testbed_api.c:1004
static int check_add_host_confirm(void *cls, const struct GNUNET_TESTBED_HostConfirmedMessage *msg)
Check #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message is well-formed.
Definition: testbed_api.c:341
void GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c, struct OperationContext *opc)
Inserts the given operation context into the operation context map of the given controller.
Definition: testbed_api.c:298
size_t GNUNET_TESTBED_compress_config_(const char *config, size_t size, char **xconfig)
Compresses given configuration using zlib compress.
Definition: testbed_api.c:1758
Interface for functions internally exported from testbed_api.c.
@ OP_GET_SLAVE_CONFIG
Get slave config operation.
Definition: testbed_api.h:94
@ OP_PEER_RECONFIGURE
Reconfigure a peer.
Definition: testbed_api.h:74
@ OP_FORWARDED
Forwarded operation.
Definition: testbed_api.h:84
@ OP_PEER_START
Peer start operation.
Definition: testbed_api.h:54
@ OP_PEER_INFO
Get peer information operation.
Definition: testbed_api.h:69
@ OP_SHUTDOWN_PEERS
Stop and destroy all peers.
Definition: testbed_api.h:99
@ OP_MANAGE_SERVICE
Start/stop service at a peer.
Definition: testbed_api.h:104
@ OP_PEER_DESTROY
Peer destroy operation.
Definition: testbed_api.h:64
@ OP_OVERLAY_CONNECT
Overlay connection operation.
Definition: testbed_api.h:79
@ OP_LINK_CONTROLLERS
Link controllers operation.
Definition: testbed_api.h:89
@ OP_PEER_STOP
Peer stop operation.
Definition: testbed_api.h:59
@ OP_PEER_CREATE
Peer create operation.
Definition: testbed_api.h:49
@ OPC_STATE_INIT
The initial state where the associated operation has just been created and is waiting in the operatio...
Definition: testbed_api.h:117
@ OPC_STATE_STARTED
The operation has been started.
Definition: testbed_api.h:123
@ OPC_STATE_FINISHED
The operation has finished.
Definition: testbed_api.h:129
void GNUNET_TESTBED_mark_host_registered_at_(struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller)
Marks a host as registered with a controller.
void GNUNET_TESTBED_deregister_host_at_(struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller)
Unmarks a host registered at a controller.
int GNUNET_TESTBED_is_host_registered_(const struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller)
Checks whether a host has been registered.
void GNUNET_TESTBED_host_replace_cfg_(struct GNUNET_TESTBED_Host *host, const struct GNUNET_CONFIGURATION_Handle *new_cfg)
Function to replace host's configuration.
const struct GNUNET_CONFIGURATION_Handle * GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host)
Obtain the host's configuration template.
struct GNUNET_TESTBED_Host * GNUNET_TESTBED_host_lookup_by_id_(uint32_t id)
Lookup a host by ID.
uint32_t GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host)
Obtain a host's unique global ID.
internal API to access the 'hosts' subsystem
void GNUNET_TESTBED_operation_mark_failed(struct GNUNET_TESTBED_Operation *op)
Marks an operation as failed.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, OperationRelease release)
Create an 'operation' to be performed.
void GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op)
An operation is 'done' (was cancelled or finished); remove it from the queues and release associated ...
struct OperationQueue * GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type, unsigned int max_active)
Create an operation queue.
void GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op)
Add an operation to a queue.
void GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue)
Destroys an operation queue.
void GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op)
Marks the given operation as waiting on the queues.
internal API to access the 'operations' subsystem
@ OPERATION_QUEUE_TYPE_FIXED
Operation queue which permits a fixed maximum number of operations to be active at any time.
void GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer)
Removes a peer from the peer list.
void GNUNET_TESTBED_cleanup_peers_(void)
Frees all peers.
void GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer)
Adds a peer to the peer list.
internal API to access the 'peers' subsystem
@ TESTBED_PS_STOPPED
The peer is stopped.
@ TESTBED_PS_CREATED
The peer has been created.
@ TESTBED_PS_STARTED
The peer is running.
functions to calculate standard deviation
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.