GNUnet  0.10.x
gnunet-service-testbed.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2008--2013, 2016 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 "gnunet-service-testbed.h"
30 
31 /***********/
32 /* Globals */
33 /***********/
34 
39 
44 
49 
54 
59 
64 
69 
73 unsigned int GST_host_list_size;
74 
78 unsigned int GST_peer_list_size;
79 
80 
81 /***********************************/
82 /* Local definitions and variables */
83 /***********************************/
84 
88 static char *hostname;
89 
90 
98 static int
100 {
101  uint32_t host_id;
102 
103  host_id = GNUNET_TESTBED_host_get_id_ (host);
104  if (GST_host_list_size <= host_id)
105  GST_array_grow_large_enough (GST_host_list, GST_host_list_size, host_id);
106  if (NULL != GST_host_list[host_id])
107  {
108  LOG_DEBUG ("A host with id: %u already exists\n", host_id);
109  return GNUNET_SYSERR;
110  }
111  GST_host_list[host_id] = host;
112  return GNUNET_OK;
113 }
114 
115 
123 void
125  uint64_t operation_id,
126  const char *emsg)
127 {
128  struct GNUNET_MQ_Envelope *env;
130  uint16_t emsg_len;
131 
132  emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
133  env = GNUNET_MQ_msg_extra (msg,
134  emsg_len,
137  msg->operation_id = GNUNET_htonll (operation_id);
138  GNUNET_memcpy (&msg[1],
139  emsg,
140  emsg_len);
142  env);
143 }
144 
145 
152 void
154  uint64_t operation_id)
155 {
156  struct GNUNET_MQ_Envelope *env;
158 
159  env = GNUNET_MQ_msg (msg,
161  msg->operation_id = GNUNET_htonll (operation_id);
164  env);
165 }
166 
167 
174 static void
175 hr_completion (void *cls,
176  const char *emsg);
177 
178 
185 static void
186 register_next_host (struct Slave *slave)
187 {
188  struct HostRegistration *hr;
189 
190  hr = slave->hr_dll_head;
191  GNUNET_assert (NULL != hr);
192  GNUNET_assert (NULL == slave->rhandle);
193  LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n",
195  GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
196  slave->rhandle
198  hr->host,
200  slave);
201 }
202 
203 
210 static void
211 hr_completion (void *cls,
212  const char *emsg)
213 {
214  struct Slave *slave = cls;
215  struct HostRegistration *hr;
216 
217  slave->rhandle = NULL;
218  hr = slave->hr_dll_head;
219  GNUNET_assert (NULL != hr);
221  "Registering host %u at %u successful\n",
223  GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
225  slave->hr_dll_tail,
226  hr);
227  if (NULL != hr->cb)
228  hr->cb (hr->cb_cls,
229  emsg);
230  GNUNET_free (hr);
231  if (NULL != slave->hr_dll_head)
232  register_next_host (slave);
233 }
234 
235 
245 void
248  void *cb_cls,
249  struct GNUNET_TESTBED_Host *host)
250 {
251  struct HostRegistration *hr;
252  int call_register;
253 
255  "Queueing host registration for host %u at %u\n",
257  GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
258  hr = GNUNET_new (struct HostRegistration);
259  hr->cb = cb;
260  hr->cb_cls = cb_cls;
261  hr->host = host;
262  call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO;
264  slave->hr_dll_tail,
265  hr);
266  if (GNUNET_YES == call_register)
267  register_next_host (slave);
268 }
269 
270 
277 void
279  const struct GNUNET_MessageHeader *msg)
280 {
281  struct ForwardedOperationContext *fopc = cls;
282  struct GNUNET_MQ_Envelope *env;
283 
284  LOG_DEBUG ("Relaying message with type: %u, size: %u\n",
285  ntohs (msg->type),
286  ntohs (msg->size));
287  env = GNUNET_MQ_msg_copy (msg);
289  env);
291  GNUNET_CONTAINER_DLL_remove (fopcq_head,
292  fopcq_tail,
293  fopc);
294  GNUNET_free (fopc);
295 }
296 
297 
303 void
305 {
306  struct ForwardedOperationContext *fopc = cls;
307 
308  fopc->timeout_task = NULL;
311  "A forwarded operation has timed out\n");
313  fopc->operation_id,
314  "A forwarded operation has timed out");
315  GNUNET_CONTAINER_DLL_remove (fopcq_head,
316  fopcq_tail,
317  fopc);
318  GNUNET_free (fopc);
319 }
320 
321 
331 static struct GNUNET_TESTING_SharedService *
332 parse_shared_services (char *ss_str,
334 {
336  struct GNUNET_TESTING_SharedService *slist;
337  char service[256];
338  char *arg;
339  unsigned int n;
340 #define GROW_SS \
341  do { \
342  GNUNET_array_grow (slist, n, n+1); \
343  GNUNET_memcpy (&slist[n - 1], &ss, \
344  sizeof (struct GNUNET_TESTING_SharedService)); \
345  } while (0)
346 
347  slist = NULL;
348  n = 0;
349  ss.cfg = cfg;
350  for (; NULL != (arg = strtok (ss_str, " ")); ss_str = NULL)
351  {
352  ss.service = NULL;
353  ss.share = 0;
354  if (2 != sscanf (arg, "%255[^:]:%u",
355  service,
356  &ss.share))
357  {
359  "Ignoring shared service spec: %s",
360  arg);
361  continue;
362  }
363  LOG_DEBUG ("Will be sharing %s service among %u peers\n",
364  service,
365  ss.share);
366  ss.service = GNUNET_strdup (service);
367  GROW_SS;
368  }
369  if (NULL != slist)
370  {
371  /* Add trailing NULL block */
372  (void) memset (&ss,
373  0,
374  sizeof (struct GNUNET_TESTING_SharedService));
375  GROW_SS;
376  }
377  return slist;
378 #undef GROW_SS
379 }
380 
381 
389 static int
390 check_init (void *cls,
391  const struct GNUNET_TESTBED_InitMessage *msg)
392 {
393  const char *controller_hostname;
394  uint16_t msize;
395 
396  msize = ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_InitMessage);
397  controller_hostname = (const char *) &msg[1];
398  if ('\0' != controller_hostname[msize - 1])
399  {
400  GNUNET_break (0);
401  return GNUNET_SYSERR;
402  }
403  return GNUNET_OK;
404 }
405 
406 
413 static void
414 handle_init (void *cls,
415  const struct GNUNET_TESTBED_InitMessage *msg)
416 {
417  struct GNUNET_SERVICE_Client *client = cls;
418  struct GNUNET_TESTBED_Host *host;
419  const char *controller_hostname;
420  char *ss_str;
421  struct GNUNET_TESTING_SharedService *ss;
422  unsigned int cnt;
423 
424  if (NULL != GST_context)
425  {
426  LOG_DEBUG ("We are being connected to laterally\n");
428  return;
429  }
430  controller_hostname = (const char *) &msg[1];
431  ss_str = NULL;
432  ss = NULL;
433  if (GNUNET_OK ==
435  "TESTBED",
436  "SHARED_SERVICES",
437  &ss_str))
438  {
439  ss = parse_shared_services (ss_str,
440  GST_config);
441  GNUNET_free (ss_str);
442  ss_str = NULL;
443  }
444  GST_context = GNUNET_new (struct Context);
445  GST_context->client = client;
446  GST_context->host_id = ntohl (msg->host_id);
447  GST_context->master_ip = GNUNET_strdup (controller_hostname);
448  LOG_DEBUG ("Our IP: %s\n",
449  GST_context->master_ip);
450  GST_context->system
451  = GNUNET_TESTING_system_create ("testbed",
452  GST_context->master_ip,
453  hostname,
454  ss);
455  if (NULL != ss)
456  {
457  for (cnt = 0; NULL != ss[cnt].service; cnt++)
458  {
459  ss_str = (char *) ss[cnt].service;
460  GNUNET_free (ss_str);
461  }
462  GNUNET_free (ss);
463  ss = NULL;
464  }
465  host =
467  GST_context->master_ip,
468  NULL,
469  GST_config,
470  0);
471  host_list_add (host);
472  LOG_DEBUG ("Created master context with host ID: %u\n",
473  GST_context->host_id);
475 }
476 
477 
485 static int
486 check_add_host (void *cls,
487  const struct GNUNET_TESTBED_AddHostMessage *msg)
488 {
489  uint16_t username_length;
490  uint16_t hostname_length;
491  uint16_t msize;
492 
493  msize = ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_AddHostMessage);
494  username_length = ntohs (msg->username_length);
495  hostname_length = ntohs (msg->hostname_length);
496  /* msg must contain hostname */
497  if ( (msize <= username_length) ||
498  (0 == hostname_length) )
499  {
500  GNUNET_break (0);
501  return GNUNET_SYSERR;
502  }
503  /* msg must contain configuration */
504  if (msize <= username_length + hostname_length)
505  {
506  GNUNET_break (0);
507  return GNUNET_SYSERR;
508  }
509  return GNUNET_OK;
510 }
511 
512 
519 static void
520 handle_add_host (void *cls,
521  const struct GNUNET_TESTBED_AddHostMessage *msg)
522 {
523  struct GNUNET_SERVICE_Client *client = cls;
524  struct GNUNET_TESTBED_Host *host;
526  struct GNUNET_CONFIGURATION_Handle *host_cfg;
527  char *username;
528  char *hostname;
529  char *emsg;
530  const void *ptr;
531  uint32_t host_id;
532  uint16_t username_length;
533  uint16_t hostname_length;
534  struct GNUNET_MQ_Envelope *env;
535 
536  username_length = ntohs (msg->username_length);
537  hostname_length = ntohs (msg->hostname_length);
538  username = NULL;
539  hostname = NULL;
540  ptr = &msg[1];
541  if (0 != username_length)
542  {
543  username = GNUNET_malloc (username_length + 1);
544  GNUNET_strlcpy (username, ptr, username_length + 1);
545  ptr += username_length;
546  }
547  hostname = GNUNET_malloc (hostname_length + 1);
548  GNUNET_strlcpy (hostname, ptr, hostname_length + 1);
549  if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (&msg->header)))
550  {
551  GNUNET_free_non_null (username);
552  GNUNET_free_non_null (hostname);
553  GNUNET_break_op (0);
555  return;
556  }
557  host_id = ntohl (msg->host_id);
558  LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
559  LOG_DEBUG ("-------host id: %u\n", host_id);
560  LOG_DEBUG ("-------hostname: %s\n", hostname);
561  if (NULL != username)
562  LOG_DEBUG ("-------username: %s\n", username);
563  else
564  LOG_DEBUG ("-------username: <not given>\n");
565  LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
566  host = GNUNET_TESTBED_host_create_with_id (host_id,
567  hostname,
568  username,
569  host_cfg,
570  ntohs (msg->ssh_port));
571  GNUNET_free_non_null (username);
572  GNUNET_free (hostname);
573  GNUNET_CONFIGURATION_destroy (host_cfg);
574  if (NULL == host)
575  {
576  GNUNET_break_op (0);
578  return;
579  }
580  if (GNUNET_OK != host_list_add (host))
581  {
582  /* We are unable to add a host */
583  emsg = "A host exists with given host-id";
584  LOG_DEBUG ("%s: %u",
585  emsg,
586  host_id);
588  env = GNUNET_MQ_msg_extra (reply,
589  strlen (emsg) + 1,
591  GNUNET_memcpy (&reply[1],
592  emsg,
593  strlen (emsg) + 1);
594  }
595  else
596  {
597  LOG_DEBUG ("Added host %u at %u\n",
598  host_id,
599  GST_context->host_id);
600  env = GNUNET_MQ_msg (reply,
602  }
603  reply->host_id = htonl (host_id);
605  env);
607 }
608 
609 
616 static void
619 {
620  struct GNUNET_SERVICE_Client *client = cls;
621  struct Slave *slave;
622  struct GNUNET_TESTBED_SlaveConfiguration *reply;
623  const struct GNUNET_CONFIGURATION_Handle *cfg;
624  struct GNUNET_MQ_Envelope *env;
625  char *config;
626  char *xconfig;
627  size_t config_size;
628  size_t xconfig_size;
629  uint64_t op_id;
630  uint32_t slave_id;
631 
632  slave_id = ntohl (msg->slave_id);
633  op_id = GNUNET_ntohll (msg->operation_id);
634  if ( (GST_slave_list_size <= slave_id) ||
635  (NULL == GST_slave_list[slave_id]) )
636  {
637  /* FIXME: Add forwardings for this type of message here.. */
639  op_id,
640  "Slave not found");
642  return;
643  }
644  slave = GST_slave_list[slave_id];
645  GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (GST_host_list[slave->host_id])));
646  config = GNUNET_CONFIGURATION_serialize (cfg,
647  &config_size);
648  /* FIXME: maybe we want to transmit the delta to the default here? */
649  xconfig_size = GNUNET_TESTBED_compress_config_ (config,
650  config_size,
651  &xconfig);
652  GNUNET_free (config);
653  GNUNET_assert (xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration) <= UINT16_MAX);
654  GNUNET_assert (xconfig_size <= UINT16_MAX);
655  env = GNUNET_MQ_msg_extra (reply,
656  xconfig_size,
658  reply->slave_id = msg->slave_id;
659  reply->operation_id = msg->operation_id;
660  reply->config_size = htons ((uint16_t) config_size);
661  GNUNET_memcpy (&reply[1],
662  xconfig,
663  xconfig_size);
664  GNUNET_free (xconfig);
666  env);
668 }
669 
670 
674 void
676 {
677  struct ForwardedOperationContext *fopc;
678 
679  while (NULL != (fopc = fopcq_head))
680  {
681  GNUNET_CONTAINER_DLL_remove (fopcq_head,
682  fopcq_tail,
683  fopc);
685  if (NULL != fopc->timeout_task)
687  switch (fopc->type)
688  {
689  case OP_PEER_CREATE:
690  GNUNET_free (fopc->cls);
691  break;
692  case OP_SHUTDOWN_PEERS:
693  {
694  struct HandlerContext_ShutdownPeers *hc = fopc->cls;
695 
696  GNUNET_assert (0 < hc->nslaves);
697  hc->nslaves--;
698  if (0 == hc->nslaves)
699  GNUNET_free (hc);
700  }
701  break;
702  case OP_PEER_START:
703  case OP_PEER_STOP:
704  case OP_PEER_DESTROY:
705  case OP_PEER_INFO:
706  case OP_OVERLAY_CONNECT:
707  case OP_LINK_CONTROLLERS:
708  case OP_GET_SLAVE_CONFIG:
709  case OP_MANAGE_SERVICE:
710  case OP_PEER_RECONFIGURE:
711  break;
712  case OP_FORWARDED:
713  GNUNET_assert (0);
714  };
715  GNUNET_free (fopc);
716  }
717 }
718 
719 
725 static void
726 shutdown_task (void *cls)
727 {
728  uint32_t id;
729 
730  LOG_DEBUG ("Shutting down testbed service\n");
731  /* cleanup any remaining forwarded operations */
732  GST_clear_fopcq ();
733  GST_free_lcf ();
734  GST_free_mctxq ();
735  GST_free_occq ();
736  GST_free_roccq ();
737  GST_free_nccq ();
739  GST_free_prcq ();
740  /* Clear peer list */
742  /* Clear route list */
744  /* Clear GST_slave_list */
746  /* Clear host list */
747  for (id = 0; id < GST_host_list_size; id++)
748  if (NULL != GST_host_list[id])
749  GNUNET_TESTBED_host_destroy (GST_host_list[id]);
750  GNUNET_free_non_null (GST_host_list);
751  if (NULL != GST_context)
752  {
753  GNUNET_free_non_null (GST_context->master_ip);
754  if (NULL != GST_context->system)
756  GNUNET_YES);
757  GNUNET_free (GST_context);
758  GST_context = NULL;
759  }
761  /* Free hello cache */
762  GST_cache_clear ();
764  GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
765  GST_opq_openfds = NULL;
768  GNUNET_CONFIGURATION_destroy (GST_config);
769 }
770 
771 
780 static void *
781 client_connect_cb (void *cls,
782  struct GNUNET_SERVICE_Client *client,
783  struct GNUNET_MQ_Handle *mq)
784 {
785  return client;
786 }
787 
788 
796 static void
798  struct GNUNET_SERVICE_Client *client,
799  void *app_ctx)
800 {
801  struct ForwardedOperationContext *fopc;
802  struct ForwardedOperationContext *fopcn;
803 
804  GNUNET_assert (client == app_ctx);
808  for (fopc = fopcq_head; NULL != fopc; fopc = fopcn)
809  {
810  fopcn = fopc->next;
811  if (fopc->client == client)
812  {
813  /* handle as if it were a timeout */
816  }
817  }
818  if (NULL == GST_context)
819  return;
820  if (client == GST_context->client)
821  {
823  "Master client disconnected\n");
824  GST_context->client = NULL;
825  /* should not be needed as we're terminated by failure to read
826  * from stdin, but if stdin fails for some reason, this shouldn't
827  * hurt for now --- might need to revise this later if we ever
828  * decide that master connections might be temporarily down
829  * for some reason */
830  //GNUNET_SCHEDULER_shutdown ();
831  }
832 }
833 
834 
842 static void
844  const struct GNUNET_CONFIGURATION_Handle *cfg,
846 {
847  char *logfile;
848  unsigned long long num;
849 
850  LOG_DEBUG ("Starting testbed\n");
851  if (GNUNET_OK ==
852  GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
853  &logfile))
854  {
856  GNUNET_log_setup ("testbed",
857  "DEBUG",
858  logfile));
859  GNUNET_free (logfile);
860  }
863  "TESTBED",
864  "CACHE_SIZE",
865  &num));
866  GST_cache_init ((unsigned int) num);
867  GST_connection_pool_init ((unsigned int) num);
870  "TESTBED",
871  "MAX_OPEN_FDS",
872  &num));
874  (unsigned int) num);
877  "TESTBED",
878  "OPERATION_TIMEOUT",
879  (struct GNUNET_TIME_Relative *)
880  &GST_timeout));
883  "testbed",
884  "HOSTNAME",
885  &hostname));
886  GST_config = GNUNET_CONFIGURATION_dup (cfg);
888  NULL);
889  LOG_DEBUG ("Testbed startup complete\n");
890  GST_stats_init (GST_config);
891  GST_barriers_init (GST_config);
892 }
893 
894 
899 ("testbed",
901  &testbed_run,
904  NULL,
908  NULL),
912  NULL),
913  GNUNET_MQ_hd_fixed_size (slave_get_config,
916  NULL),
917  GNUNET_MQ_hd_fixed_size (link_controllers,
920  NULL),
921  GNUNET_MQ_hd_var_size (remote_overlay_connect,
924  NULL),
925  GNUNET_MQ_hd_fixed_size (overlay_connect,
928  NULL),
929  GNUNET_MQ_hd_var_size (peer_create,
932  NULL),
933  GNUNET_MQ_hd_fixed_size (peer_destroy,
936  NULL),
937  GNUNET_MQ_hd_fixed_size (peer_start,
940  NULL),
941  GNUNET_MQ_hd_fixed_size (peer_stop,
944  NULL),
945  GNUNET_MQ_hd_fixed_size (peer_get_config,
948  NULL),
949  GNUNET_MQ_hd_var_size (manage_peer_service,
952  NULL),
953  GNUNET_MQ_hd_fixed_size (shutdown_peers,
956  NULL),
957  GNUNET_MQ_hd_var_size (peer_reconfigure,
960  NULL),
961  GNUNET_MQ_hd_var_size (barrier_init,
964  NULL),
965  GNUNET_MQ_hd_var_size (barrier_cancel,
968  NULL),
969  GNUNET_MQ_hd_var_size (barrier_status,
972  NULL),
974 
975 
976 /* end of gnunet-service-testbed.c */
struct GNUNET_SCHEDULER_Task * timeout_task
Task ID for the timeout task.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Context to hold data of peer.
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS
Message for signalling status of a barrier.
Interface for the barrier initialisation handler routine.
#define GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION
Message which contains the configuration of slave controller.
Confirmation from the service that adding a host worked (or failed).
Definition: testbed.h:117
Message to request configuration of a slave controller.
Definition: testbed.h:675
void GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, uint64_t operation_id, const char *emsg)
Send operation failure message to client.
uint16_t username_length
Number of bytes in the user name that follows; 0 to use no user name; otherwise &#39;strlen (username)&#39;...
Definition: testbed.h:88
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:653
unsigned int GST_host_list_size
The size of the host list.
#define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS
Message to link delegated controller to slave controller.
Message sent from host controller of a peer(A) to the host controller of another peer(B) to request B...
Definition: testbed.h:431
void GST_route_list_clear(void)
Cleans up the route list.
int GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
void GST_barriers_destroy()
Function to stop the barrier service.
int 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_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_INIT.
Definition: testbed.h:42
void GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client)
Notify OC subsystem that client disconnected.
Message sent from client to testing service to reconfigure a (stopped) a peer.
Definition: testbed.h:251
Message to cancel a barrier.
Definition: testbed.h:845
uint32_t slave_id
The id of the host where the slave is running.
Definition: testbed.h:708
Handle to a service.
Definition: service.c:116
#define GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION
Message to request configuration of a slave controller.
Specification of a service that is to be shared among peers.
data structures shared amongst components of TESTBED service
Message sent from client to testing service to stop a peer.
Definition: testbed.h:309
void GST_clear_fopcq()
Clears the forwarded operations queue.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2734
Message sent from client to testing service to obtain the configuration of a peer.
Definition: testbed.h:615
struct GNUNET_TESTBED_Host * GNUNET_TESTBED_host_create_with_id(uint32_t id, const char *hostname, const char *username, const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t port)
Create a host to run peers and controllers on.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
void GST_stats_destroy(void)
Shutdown the status calls module.
Shutdown peers message.
Definition: testbed.h:728
Message sent from client to testing service to destroy a (stopped) peer.
Definition: testbed.h:334
#define LOG(kind,...)
Definition: arm_api.c:33
#define GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER
Message to stop a peer at a host.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Notify the service about a host that we intend to use.
Definition: testbed.h:65
uint64_t operation_id
Operation ID.
Definition: testbed.h:713
char * master_ip
The network address of the master controller.
struct OperationContext * opc
The generated operation context.
void GST_queue_host_registration(struct Slave *slave, GNUNET_TESTBED_HostRegistrationCompletion cb, void *cb_cls, struct GNUNET_TESTBED_Host *host)
Adds a host registration&#39;s request to a slave&#39;s registration queue.
#define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS
A controller receiving this message floods it to its directly-connected sub-controllers and then stop...
static void add_host(const char *hostname, uint16_t rec_type, const void *data, size_t data_size)
Add information about a host from /etc/hosts to our cache.
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:94
uint16_t config_size
The size of the configuration when uncompressed.
Definition: testbed.h:718
Operation queue which permits a fixed maximum number of operations to be active at any time...
struct GNUNET_TESTING_System * system
The TESTING system handle for starting peers locally.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
Stop and destroy all peers.
Definition: testbed_api.h:99
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
unsigned int GST_peer_list_size
The size of the peer list.
static void register_next_host(struct Slave *slave)
Attempts to register the next host in the host registration queue.
#define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS
Message to signal that a add host succeeded.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
void(* GNUNET_TESTBED_HostRegistrationCompletion)(void *cls, const char *emsg)
Callback which will be called to after a host registration succeeded or failed.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Callback for client connect.
Structure representing a connected(directly-linked) controller.
static struct GNUNET_TESTING_SharedService * parse_shared_services(char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
Parse service sharing specification line.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_TESTBED_HostRegistrationHandle * rhandle
The current host registration handle.
Opaque handle to a host running experiments managed by the testing framework.
Event notification from a controller to a client.
Definition: testbed.h:536
Initial message from a client to a testing control service.
Definition: testbed.h:36
void GST_free_mctxq(void)
Frees the ManageServiceContext queue.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE
Message to start/stop a service of a peer.
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:2068
struct OperationQueue * GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type, unsigned int max_active)
Create an operation queue.
int32_t event_type
&#39;enum GNUNET_TESTBED_EventType&#39; (in NBO); GNUNET_TESTBED_ET_OPERATION_FINISHED.
Definition: testbed.h:548
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct OperationQueue * GST_opq_openfds
Operation queue for open file descriptors.
#define GST_array_grow_large_enough(ptr, size, accommodate_size)
Similar to GNUNET_array_grow(); however instead of calling GNUNET_array_grow() several times we call ...
void GST_forwarded_operation_reply_relay(void *cls, const struct GNUNET_MessageHeader *msg)
Callback to relay the reply msg of a forwarded operation back to the client.
void GST_forwarded_operation_timeout(void *cls)
Task to free resources when forwarded operation has been timed out.
Reconfigure a peer.
Definition: testbed_api.h:74
Message sent from client to testing service to start a peer.
Definition: testbed.h:284
#define GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS
Message to signal a generic operation has been successful.
Handle to a client that is connected to a service.
Definition: service.c:249
static void handle_add_host(void *cls, const struct GNUNET_TESTBED_AddHostMessage *msg)
Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages.
uint64_t operation_id
Operation ID of the operation that created this event.
Definition: testbed.h:606
const struct GNUNET_TIME_Relative GST_timeout
Timeout for operations which may take some time.
GNUNET_TESTBED_HostRegistrationCompletion cb
The callback to call after this registration&#39;s status is available.
static void hr_completion(void *cls, const char *emsg)
Callback which will be called after a host registration succeeded or failed.
#define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT
Message for operation events.
#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
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
Callback for client disconnect.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
Link controllers operation.
Definition: testbed_api.h:89
#define GNUNET_memcpy(dst, src, n)
uint32_t host_id
Our host id according to this context.
struct ForwardedOperationContext * fopcq_head
DLL head for forwarded operation contexts.
#define GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT
Message to request a controller to make one of its peer to connect to another peer using the containe...
uint64_t operation_id
Operation ID of the operation that created this event.
Definition: testbed.h:553
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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:1410
#define GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER
Message to reconfigure a peer.
static int check_init(void *cls, const struct GNUNET_TESTBED_InitMessage *msg)
Check GNUNET_MESSAGE_TYPE_TESTBED_INIT messages.
struct GNUNET_TESTBED_Host ** GST_host_list
Array of hosts.
enum OperationType type
The type of the operation which is forwarded.
static int host_list_add(struct GNUNET_TESTBED_Host *host)
Function to add a host to the current list of known hosts.
A DLL of host registrations to be made.
void GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg)
Function to initialise barrriers component.
Peer destroy operation.
Definition: testbed_api.h:64
struct GNUNET_SERVICE_Client * client
The client handle associated with this context.
A requested testbed operation has been completed.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
#define GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER
Message to destroy a peer.
static const struct GNUNET_CONFIGURATION_Handle * config
#define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST
Message to add host.
uint32_t GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host)
Obtain the host&#39;s unique global ID.
struct HostRegistration * hr_dll_tail
Tail of the host registration DLL.
uint32_t host_id
Unique ID for the host (in NBO).
Definition: testbed.h:128
Peer start operation.
Definition: testbed_api.h:54
void GST_cache_clear(void)
Clear cache.
const struct GNUNET_CONFIGURATION_Handle * GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host)
Obtain the host&#39;s configuration template.
void GST_cache_init(unsigned int size)
Initializes the cache.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2618
#define GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT
Message to connect peers in a overlay.
unsigned int share
The number of peers which share an instance of the service.
unsigned int nslaves
The number of slave we expect to hear from since we forwarded the GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOW...
struct HostRegistration * hr_dll_head
Head of the host registration DLL.
void * cls
Closure pointer.
Message sent from client to testing service to create (configure, but not start) a peer...
Definition: testbed.h:213
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 struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
uint64_t operation_id
Operation ID.
Definition: testbed.h:690
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
Create a system handle.
Definition: testing.c:449
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
void GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue)
Destroys an operation queue.
Interface for connection pooling subroutines.
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:527
uint32_t host_id
Unique ID for the host (in NBO).
Definition: testbed.h:76
void GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host)
Destroy a host handle.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
GUID host
Reply to GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION message.
Definition: testbed.h:698
Overlay connection operation.
Definition: testbed_api.h:79
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST.
Definition: testbed.h:71
const char * service
The name of the service.
static void testbed_run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service)
Testbed setup.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Forwarded operation.
Definition: testbed_api.h:84
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION
Message to get a peer&#39;s information.
struct GNUNET_TESTBED_Host * host
The host that has to be registered.
static char * init
Set to the name of a service to start.
Definition: gnunet-arm.c:69
static void handle_slave_get_config(void *cls, const struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg)
Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages.
uint32_t host_id
Host ID that the controller is either given (if this is the dominating client) or assumed to have (fo...
Definition: testbed.h:50
#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER
Message to create a peer at a host.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
Peer stop operation.
Definition: testbed_api.h:59
size_t GNUNET_TESTBED_compress_config_(const char *config, size_t size, char **xconfig)
Compresses given configuration using zlib compress.
Definition: testbed_api.c:1761
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
Handle to a message queue.
Definition: mq.c:85
Message sent from client to testing service to connect two peers.
Definition: testbed.h:396
Get slave config operation.
Definition: testbed_api.h:94
Start/stop service at a peer.
Definition: testbed_api.h:104
Queue of operations where we can only support a certain number of concurrent operations of a particul...
struct ForwardedOperationContext * fopcq_tail
DLL tail for forwarded operation contexts.
static char * hostname
Our hostname; we give this to all the peers we start.
void GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client)
Notify peers subsystem that client disconnected.
uint32_t host_id
The id of the host this controller is running on.
configuration data
Definition: configuration.c:85
struct GNUNET_SERVICE_Client * client
The client to which we have to reply.
struct Context * GST_context
The master context; generated with the first INIT message.
Message to start/stop services of a peer.
Definition: testbed.h:745
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration template for the service.
void GST_connection_pool_init(unsigned int size)
Initialise the connection pool.
void GST_free_prcq(void)
Cleans up the Peer reconfigure context list.
#define GNUNET_MESSAGE_TYPE_TESTBED_INIT
Initial message from a client to a testing control service.
#define GROW_SS
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
Peer create operation.
Definition: testbed_api.h:49
struct ForwardedOperationContext * next
The next pointer for DLL.
struct GNUNET_TESTBED_Controller * controller
The controller handle.
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
uint64_t operation_id
The id of the operation that has been forwarded.
void GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize logging CPU and IO statisticfs.
static void handle_init(void *cls, const struct GNUNET_TESTBED_InitMessage *msg)
Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages.
Header for all communications.
Event notification from a controller to a client for a generic operational success where the operatio...
Definition: testbed.h:589
#define GNUNET_YES
Definition: gnunet_common.h:80
Message for signalling status changes of a barrier.
Definition: testbed.h:862
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:353
void * cb_cls
The closure for the above callback.
GNUNET_SERVICE_MAIN("testbed", GNUNET_SERVICE_OPTION_NONE, &testbed_run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(init, GNUNET_MESSAGE_TYPE_TESTBED_INIT, struct GNUNET_TESTBED_InitMessage, NULL), GNUNET_MQ_hd_var_size(add_host, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, struct GNUNET_TESTBED_AddHostMessage, NULL), GNUNET_MQ_hd_fixed_size(slave_get_config, GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, struct GNUNET_TESTBED_SlaveGetConfigurationMessage, NULL), GNUNET_MQ_hd_fixed_size(link_controllers, GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, struct GNUNET_TESTBED_ControllerLinkRequest, NULL), GNUNET_MQ_hd_var_size(remote_overlay_connect, GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, struct GNUNET_TESTBED_RemoteOverlayConnectMessage, NULL), GNUNET_MQ_hd_fixed_size(overlay_connect, GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, struct GNUNET_TESTBED_OverlayConnectMessage, NULL), GNUNET_MQ_hd_var_size(peer_create, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, struct GNUNET_TESTBED_PeerCreateMessage, NULL), GNUNET_MQ_hd_fixed_size(peer_destroy, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, struct GNUNET_TESTBED_PeerDestroyMessage, NULL), GNUNET_MQ_hd_fixed_size(peer_start, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, struct GNUNET_TESTBED_PeerStartMessage, NULL), GNUNET_MQ_hd_fixed_size(peer_stop, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, struct GNUNET_TESTBED_PeerStopMessage, NULL), GNUNET_MQ_hd_fixed_size(peer_get_config, GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, struct GNUNET_TESTBED_PeerGetConfigurationMessage, NULL), GNUNET_MQ_hd_var_size(manage_peer_service, GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, struct GNUNET_TESTBED_ManagePeerServiceMessage, NULL), GNUNET_MQ_hd_fixed_size(shutdown_peers, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, struct GNUNET_TESTBED_ShutdownPeersMessage, NULL), GNUNET_MQ_hd_var_size(peer_reconfigure, GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, struct GNUNET_TESTBED_PeerReconfigureMessage, NULL), GNUNET_MQ_hd_var_size(barrier_init, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, struct GNUNET_TESTBED_BarrierInit, NULL), GNUNET_MQ_hd_var_size(barrier_cancel, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, struct GNUNET_TESTBED_BarrierCancel, NULL), GNUNET_MQ_hd_var_size(barrier_status, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, struct GNUNET_TESTBED_BarrierStatusMsg, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
void GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, uint64_t operation_id)
Function to send generic operation success message to given client.
void GST_free_lcf(void)
Cleans up the queue used for forwarding link controllers requests.
static int check_add_host(void *cls, const struct GNUNET_TESTBED_AddHostMessage *msg)
Check #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages.
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT
Message to initialise a barrier.
#define LOG_DEBUG(msg)
void GST_free_occq(void)
Clears all pending overlay connect contexts in queue.
uint32_t slave_id
The id of the slave host.
Definition: testbed.h:685
Context data for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler.
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL
Message to cancel a barrier.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
struct GNUNET_CONFIGURATION_Handle * GST_config
Our configuration.
Message to initialise a barrier.
Definition: testbed.h:823
Context information for operations forwarded to subcontrollers.
struct GNUNET_TESTBED_HostRegistrationHandle * GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller, struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_HostRegistrationCompletion cc, void *cc_cls)
Register a host with the controller.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
#define GNUNET_MESSAGE_TYPE_TESTBED_START_PEER
Message to start a peer at a host.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2533
Get peer information operation.
Definition: testbed_api.h:69
static void shutdown_task(void *cls)
Task to clean up and shutdown nicely.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_malloc(size)
Wrapper around malloc.
void GST_connection_pool_destroy()
Cleanup the connection pool.
uint16_t ssh_port
SSH port to use, 0 for default (in NBO).
Definition: testbed.h:81
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void GST_destroy_peers(void)
Stops and destroys all peers.
Client notifies controller that it should delegate requests for a particular client to a particular s...
Definition: testbed.h:141
void GST_free_roccq(void)
Clears all pending remote overlay connect contexts in queue.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
int32_t event_type
&#39;enum GNUNET_TESTBED_EventType&#39; (in NBO); GNUNET_TESTBED_ET_OPERATION_FINISHED.
Definition: testbed.h:601