GNUnet  0.10.x
testing.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2008, 2009, 2012 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 
32 #include "platform.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_arm_service.h"
35 #include "gnunet_testing_lib.h"
36 
37 #define LOG(kind,...) \
38  GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
39 
40 
44 #if WINDOWS
45 #define PIPE_CONTROL GNUNET_YES
46 #else
47 #define PIPE_CONTROL GNUNET_NO
48 #endif
49 
50 
57 #define LOW_PORT 12000
58 
64 #define HIGH_PORT 56000
65 
66 
68 {
69  struct SharedService *ss;
70 
71  char *cfg_fn;
72 
74 
75  char *unix_sock;
76 
77  char *port_str;
78 
79  unsigned int n_refs;
80 };
81 
82 struct SharedService
83 {
84  char *sname;
85 
87 
89 
90  unsigned int n_peers;
91 
92  unsigned int share;
93 
94  unsigned int n_instances;
95 };
96 
97 
103 {
108  char *tmppath;
109 
114  char *trusted_ip;
115 
119  char *hostname;
120 
125 
130 
132 
133  unsigned int n_shared_services;
134 
143  uint32_t reserved_ports[65536 / 32];
144 
153  uint32_t path_counter;
154 
158  uint32_t total_hostkeys;
159 
163  uint16_t lowport;
164 
168  uint16_t highport;
169 };
170 
171 
176 {
181 
185  char *cfgfile;
186 
193  char *main_binary;
194  char *args;
195 
201 
206 
211 
216 
220  void *cb_cls;
221 
227 
229 
235  uint16_t *ports;
236 
240  unsigned int nports;
241 
245  uint32_t key_number;
246 };
247 
248 
256 static int
258 {
259  uint64_t fs;
260  char *data_dir;
261  char *filename;
262  struct GNUNET_DISK_FileHandle *fd;
263 
264  GNUNET_assert (NULL == system->hostkeys_data);
266  GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
267  GNUNET_free (data_dir);
268 
269  if (GNUNET_YES != GNUNET_DISK_file_test (filename))
270  {
272  _("Hostkeys file not found: %s\n"), filename);
273  GNUNET_free (filename);
274  return GNUNET_SYSERR;
275  }
276  /* Check hostkey file size, read entire thing into memory */
277  if (GNUNET_OK !=
278  GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
279  fs = 0;
280  if (0 == fs)
281  {
282  GNUNET_free (filename);
283  return GNUNET_SYSERR; /* File is empty */
284  }
285  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
286  {
288  _("Incorrect hostkey file format: %s\n"), filename);
289  GNUNET_free (filename);
290  return GNUNET_SYSERR;
291  }
294  if (NULL == fd)
295  {
297  GNUNET_free (filename);
298  return GNUNET_SYSERR;
299  }
300  GNUNET_free (filename);
301  system->hostkeys_data = GNUNET_DISK_file_map (fd,
302  &system->map,
304  fs);
306  if (NULL == system->hostkeys_data)
307  return GNUNET_SYSERR;
309  return GNUNET_OK;
310 }
311 
312 
318 static void
320 {
321  GNUNET_break (NULL != system->hostkeys_data);
322  system->hostkeys_data = NULL;
323  GNUNET_DISK_file_unmap (system->map);
324  system->map = NULL;
325  system->hostkeys_data = NULL;
326  system->total_hostkeys = 0;
327 }
328 
329 
338 static void
339 cfg_copy_iterator (void *cls, const char *section,
340  const char *option, const char *value)
341 {
342  struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
343 
344  GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value);
345 }
346 
347 
369 struct GNUNET_TESTING_System *
371  const char *trusted_ip,
372  const char *hostname,
373  const struct
376  uint16_t lowport,
377  uint16_t highport)
378 {
379  struct GNUNET_TESTING_System *system;
380  struct GNUNET_TESTING_SharedService tss;
381  struct SharedService *ss;
382  unsigned int cnt;
383 
384  GNUNET_assert (NULL != testdir);
385  system = GNUNET_new (struct GNUNET_TESTING_System);
386  if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX)))
387  system->tmppath = GNUNET_DISK_mkdtemp (testdir);
388  else
389  system->tmppath = GNUNET_strdup (system->tmppath);
390  system->lowport = lowport;
391  system->highport = highport;
392  if (NULL == system->tmppath)
393  {
394  GNUNET_free (system);
395  return NULL;
396  }
397  if (NULL != trusted_ip)
398  system->trusted_ip = GNUNET_strdup (trusted_ip);
399  if (NULL != hostname)
400  system->hostname = GNUNET_strdup (hostname);
401  if (GNUNET_OK != hostkeys_load (system))
402  {
404  return NULL;
405  }
406  if (NULL == shared_services)
407  return system;
408  for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
409  {
410  tss = shared_services[cnt];
411  ss = GNUNET_new (struct SharedService);
412  ss->sname = GNUNET_strdup (tss.service);
415  &cfg_copy_iterator, ss->cfg);
417  &cfg_copy_iterator, ss->cfg);
419  &cfg_copy_iterator, ss->cfg);
420  ss->share = tss.share;
422  ss);
423  }
424  return system;
425 }
426 
427 
448 struct GNUNET_TESTING_System *
449 GNUNET_TESTING_system_create (const char *testdir,
450  const char *trusted_ip,
451  const char *hostname,
452  const struct GNUNET_TESTING_SharedService *
454 {
456  trusted_ip,
457  hostname,
458  shared_services,
459  LOW_PORT,
460  HIGH_PORT);
461 }
462 
463 
464 static void
466 {
467  if (NULL != i->cfg_fn)
468  {
469  (void) unlink (i->cfg_fn);
470  GNUNET_free (i->cfg_fn);
471  }
474  GNUNET_break (NULL == i->proc);
475  GNUNET_break (0 == i->n_refs);
476  GNUNET_free (i);
477 }
478 
479 
480 static int
482 {
483  char *binary;
484  char *libexec_binary;
485 
486  GNUNET_assert (NULL == i->proc);
487  GNUNET_assert (NULL != i->cfg_fn);
488  (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
489  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
490  GNUNET_free (binary);
493  NULL, NULL, NULL,
494  libexec_binary,
495  libexec_binary,
496  "-c",
497  i->cfg_fn,
498  NULL);
499  GNUNET_free (libexec_binary);
500  if (NULL == i->proc)
501  return GNUNET_SYSERR;
502  return GNUNET_OK;
503 }
504 
505 
506 static void
508 {
509  GNUNET_break (0 == i->n_refs);
512  "Killing shared service instance (%s) failed\n", i->ss->sname);
513  (void) GNUNET_OS_process_wait (i->proc);
515  i->proc = NULL;
516 }
517 
518 
526 void
528  int remove_paths)
529 {
530  struct SharedService *ss;
531  struct SharedServiceInstance *i;
532  unsigned int ss_cnt;
533  unsigned int i_cnt;
534 
535  if (NULL != system->hostkeys_data)
536  hostkeys_unload (system);
537  for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
538  {
539  ss = system->shared_services[ss_cnt];
540  for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
541  {
542  i = ss->instances[i_cnt];
543  if (NULL != i->proc)
546  }
549  GNUNET_free (ss->sname);
550  GNUNET_free (ss);
551  }
553  if (GNUNET_YES == remove_paths)
555  GNUNET_free (system->tmppath);
557  GNUNET_free_non_null (system->hostname);
558  GNUNET_free (system);
559 }
560 
561 
568 uint16_t
570 {
571  struct GNUNET_NETWORK_Handle *socket;
572  struct addrinfo hint;
573  struct addrinfo *ret;
574  struct addrinfo *ai;
575  uint32_t *port_buckets;
576  char *open_port_str;
577  int bind_status;
578  uint32_t xor_image;
579  uint16_t index;
580  uint16_t open_port;
581  uint16_t pos;
582 
583  /*
584  FIXME: Instead of using getaddrinfo we should try to determine the port
585  status by the following heurestics.
586 
587  On systems which support both IPv4 and IPv6, only ports open on both
588  address families are considered open.
589  On system with either IPv4 or IPv6. A port is considered open if it's
590  open in the respective address family
591  */
592  hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
593  hint.ai_socktype = 0;
594  hint.ai_protocol = 0;
595  hint.ai_addrlen = 0;
596  hint.ai_addr = NULL;
597  hint.ai_canonname = NULL;
598  hint.ai_next = NULL;
599  hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
600  port_buckets = system->reserved_ports;
601  for (index = (system->lowport / 32) + 1; index < (system->highport / 32); index++)
602  {
603  xor_image = (UINT32_MAX ^ port_buckets[index]);
604  if (0 == xor_image) /* Ports in the bucket are full */
605  continue;
606  pos = system->lowport % 32;
607  while (pos < 32)
608  {
609  if (0 == ((xor_image >> pos) & 1U))
610  {
611  pos++;
612  continue;
613  }
614  open_port = (index * 32) + pos;
615  if (open_port >= system->highport)
616  return 0;
617  GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
618  ret = NULL;
619  GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
620  GNUNET_free (open_port_str);
621  bind_status = GNUNET_NO;
622  for (ai = ret; NULL != ai; ai = ai->ai_next)
623  {
624  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
625  if (NULL == socket)
626  continue;
627  bind_status = GNUNET_NETWORK_socket_bind (socket,
628  ai->ai_addr,
629  ai->ai_addrlen);
631  if (GNUNET_OK != bind_status)
632  break;
633  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
634  if (NULL == socket)
635  continue;
636  bind_status = GNUNET_NETWORK_socket_bind (socket,
637  ai->ai_addr,
638  ai->ai_addrlen);
640  if (GNUNET_OK != bind_status)
641  break;
642  }
643  port_buckets[index] |= (1U << pos); /* Set the port bit */
644  freeaddrinfo (ret);
645  if (GNUNET_OK == bind_status)
646  {
648  "Found a free port %u\n", (unsigned int) open_port);
649  return open_port;
650  }
651  pos++;
652  }
653  }
654  return 0;
655 }
656 
657 
665 void
667  uint16_t port)
668 {
669  uint32_t *port_buckets;
670  uint16_t bucket;
671  uint16_t pos;
672 
673  port_buckets = system->reserved_ports;
674  bucket = port / 32;
675  pos = port % 32;
676  LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
677  if (0 == (port_buckets[bucket] & (1U << pos)))
678  {
679  GNUNET_break(0); /* Port was not reserved by us using reserve_port() */
680  return;
681  }
682  port_buckets[bucket] &= ~(1U << pos);
683 }
684 
685 
705  uint32_t key_number,
706  struct GNUNET_PeerIdentity *id)
707 {
708  struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
709 
710  if ((NULL == id) || (NULL == system->hostkeys_data))
711  return NULL;
712  if (key_number >= system->total_hostkeys)
713  {
715  _("Key number %u does not exist\n"),
716  key_number);
717  return NULL;
718  }
719  private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
720  GNUNET_memcpy (private_key,
721  system->hostkeys_data +
722  (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
723  GNUNET_TESTING_HOSTKEYFILESIZE);
725  &id->public_key);
726  return private_key;
727 }
728 
729 
734 struct UpdateContext
735 {
740 
745 
749  char *gnunet_home;
750 
756  uint16_t *ports;
757 
761  unsigned int nports;
762 
766  int status;
767 };
768 
769 
780 static void
781 update_config (void *cls,
782  const char *section,
783  const char *option,
784  const char *value)
785 {
786  struct UpdateContext *uc = cls;
787  unsigned int ival;
788  char cval[12];
789  char uval[PATH_MAX];
790  char *single_variable;
791  char *per_host_variable;
792  unsigned long long num_per_host;
793  uint16_t new_port;
794 
795  if (GNUNET_OK != uc->status)
796  return;
797  if (! ((0 == strcmp (option, "PORT"))
798  || (0 == strcmp (option, "UNIXPATH"))
799  || (0 == strcmp (option, "HOSTNAME"))))
800  return;
801  GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
802  GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
803  if ((0 == strcmp (option, "PORT")) && (1 == SSCANF (value, "%u", &ival)))
804  {
805  if ((ival != 0) &&
806  (GNUNET_YES !=
808  single_variable)))
809  {
810  new_port = GNUNET_TESTING_reserve_port (uc->system);
811  if (0 == new_port)
812  {
813  uc->status = GNUNET_SYSERR;
814  GNUNET_free (single_variable);
815  GNUNET_free (per_host_variable);
816  return;
817  }
818  GNUNET_snprintf (cval, sizeof (cval), "%u", new_port);
819  value = cval;
820  GNUNET_array_append (uc->ports, uc->nports, new_port);
821  }
822  else if ((ival != 0) &&
823  (GNUNET_YES ==
825  single_variable)) &&
827  per_host_variable,
828  &num_per_host))
829  {
830  /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
831  /* ival + ctx->fdnum % num_per_host); */
832  /* value = cval; */
833  GNUNET_break (0); /* FIXME */
834  }
835  }
836  if (0 == strcmp (option, "UNIXPATH"))
837  {
838  if (GNUNET_YES !=
840  single_variable))
841  {
842  GNUNET_snprintf (uval,
843  sizeof (uval),
844  "%s/%s.sock",
845  uc->gnunet_home, section);
846  value = uval;
847  }
848  else if ((GNUNET_YES ==
850  per_host_variable,
851  &num_per_host)) &&
852  (num_per_host > 0))
853  {
854  GNUNET_break(0); /* FIXME */
855  }
856  }
857  if (0 == strcmp (option, "HOSTNAME"))
858  {
859  value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
860  }
861  GNUNET_free (single_variable);
862  GNUNET_free (per_host_variable);
863  GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
864 }
865 
866 
874 static void
876  const char *section)
877 {
878  struct UpdateContext *uc = cls;
879  char **ikeys;
880  char *val;
881  char *ptr;
882  char *orig_allowed_hosts;
883  char *allowed_hosts;
884  char *ACCEPT_FROM_key;
885  uint16_t ikeys_cnt;
886  uint16_t key;
887 
888  ikeys_cnt = 0;
889  val = NULL;
890  /* Ignore certain options from sections. See
891  https://gnunet.org/bugs/view.php?id=2476 */
892  if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section,
893  "TESTING_IGNORE_KEYS"))
894  {
896  (GNUNET_YES ==
898  "TESTING_IGNORE_KEYS", &val));
899  ptr = val;
900  for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
901  ptr++;
902  if (0 == ikeys_cnt)
903  GNUNET_break (0);
904  else
905  {
906  ikeys = GNUNET_malloc ((sizeof (char *)) * ikeys_cnt);
907  ptr = val;
908  for (key = 0; key < ikeys_cnt; key++)
909  {
910  ikeys[key] = ptr;
911  ptr = strstr (ptr, ";");
912  GNUNET_assert (NULL != ptr); /* worked just before... */
913  *ptr = '\0';
914  ptr++;
915  }
916  }
917  }
918  if (0 != ikeys_cnt)
919  {
920  for (key = 0; key < ikeys_cnt; key++)
921  {
922  if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
923  break;
924  }
925  if ((key == ikeys_cnt) &&
927  "ADVERTISED_PORT")))
928  {
929  if (GNUNET_OK ==
930  GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, "PORT", &ptr))
931  {
933  "ADVERTISED_PORT", ptr);
934  GNUNET_free (ptr);
935  }
936  }
937  for (key = 0; key < ikeys_cnt; key++)
938  {
939  if (NULL != strstr (ikeys[key], "ACCEPT_FROM"))
940  {
941  GNUNET_free (ikeys);
942  GNUNET_free (val);
943  return;
944  }
945  }
946  GNUNET_free (ikeys);
947  }
948  GNUNET_free_non_null (val);
949  ACCEPT_FROM_key = "ACCEPT_FROM";
950  if ((NULL != uc->system->trusted_ip) &&
951  (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
952  ACCEPT_FROM_key = "ACCEPT_FROM6";
953  if (GNUNET_OK !=
954  GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, ACCEPT_FROM_key,
955  &orig_allowed_hosts))
956  {
957  orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
958  }
959  if (NULL == uc->system->trusted_ip)
960  allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
961  else
962  GNUNET_asprintf (&allowed_hosts, "%s%s;", orig_allowed_hosts,
963  uc->system->trusted_ip);
964  GNUNET_free (orig_allowed_hosts);
965  GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, ACCEPT_FROM_key,
966  allowed_hosts);
967  GNUNET_free (allowed_hosts);
968 }
969 
970 
971 static struct SharedServiceInstance *
973  struct SharedService *ss,
975 {
976  struct SharedServiceInstance *i;
977  struct GNUNET_CONFIGURATION_Handle *temp;
978  char *gnunet_home;
979  uint32_t port;
980 
981  ss->n_peers++;
982  if ( ((0 == ss->share) && (NULL == ss->instances))
983  ||
984  ( (0 != ss->share)
985  && (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)) ) )
986  {
987  i = GNUNET_new (struct SharedServiceInstance);
988  i->ss = ss;
989  (void) GNUNET_asprintf (&gnunet_home, "%s/shared/%s/%u",
990  system->tmppath, ss->sname, ss->n_instances);
991  (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
992  port = GNUNET_TESTING_reserve_port (system);
993  if (0 == port)
994  {
995  GNUNET_free (gnunet_home);
997  return NULL;
998  }
1000  temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1001  (void) GNUNET_asprintf (&i->port_str, "%u", port);
1002  (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1003  GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "GNUNET_HOME",
1004  gnunet_home);
1005  GNUNET_free (gnunet_home);
1006  GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH",
1007  i->unix_sock);
1008  GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT",
1009  i->port_str);
1011  {
1014  return NULL;
1015  }
1017  }
1018  else
1019  {
1020  GNUNET_assert (NULL != ss->instances);
1021  GNUNET_assert (0 < ss->n_instances);
1022  i = ss->instances[ss->n_instances - 1];
1023  }
1025  &cfg_copy_iterator, cfg);
1026  GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "UNIXPATH",
1027  i->unix_sock);
1028  GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1029  return i;
1030 }
1031 
1032 
1052 static int
1055  uint16_t **ports,
1056  unsigned int *nports)
1057 {
1058  struct UpdateContext uc;
1059  char *default_config;
1060 
1061  uc.system = system;
1062  uc.cfg = cfg;
1063  uc.status = GNUNET_OK;
1064  uc.ports = NULL;
1065  uc.nports = 0;
1066  GNUNET_asprintf (&uc.gnunet_home, "%s/%u", system->tmppath,
1067  system->path_counter++);
1068  GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1069  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
1070  default_config);
1071  GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG",
1072  default_config);
1073  GNUNET_free (default_config);
1074  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "GNUNET_HOME",
1075  uc.gnunet_home);
1076  /* make PORTs and UNIXPATHs unique */
1078  /* allow connections to services from system trusted_ip host */
1080  /* enable loopback-based connections between peers */
1082  "nat",
1083  "USE_LOCALADDR", "YES");
1084  GNUNET_free (uc.gnunet_home);
1085  if ((NULL != ports) && (NULL != nports))
1086  {
1087  *ports = uc.ports;
1088  *nports = uc.nports;
1089  }
1090  else
1092  return uc.status;
1093 }
1094 
1095 
1112 int
1115 {
1116  return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1117 }
1118 
1119 
1133 struct GNUNET_TESTING_Peer *
1136  uint32_t key_number,
1137  struct GNUNET_PeerIdentity *id,
1138  char **emsg)
1139 {
1140  struct GNUNET_TESTING_Peer *peer;
1141  struct GNUNET_DISK_FileHandle *fd;
1142  char *hostkey_filename;
1143  char *config_filename;
1144  char *libexec_binary;
1145  char *emsg_;
1147  uint16_t *ports;
1148  struct SharedService *ss;
1149  struct SharedServiceInstance **ss_instances;
1150  unsigned int cnt;
1151  unsigned int nports;
1152 
1153  ports = NULL;
1154  nports = 0;
1155  ss_instances = NULL;
1156  if (NULL != emsg)
1157  *emsg = NULL;
1158  if (key_number >= system->total_hostkeys)
1159  {
1160  GNUNET_asprintf (&emsg_,
1161  _("You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1162  (unsigned int) system->total_hostkeys);
1163  goto err_ret;
1164  }
1165  pk = NULL;
1166  if ((NULL != id) &&
1167  (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1168  {
1169  GNUNET_asprintf (&emsg_,
1170  _("Failed to initialize hostkey for peer %u\n"),
1171  (unsigned int) key_number);
1172  goto err_ret;
1173  }
1174  if (NULL != pk)
1175  GNUNET_free (pk);
1176  if (GNUNET_NO ==
1177  GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1178  {
1179  GNUNET_asprintf (&emsg_,
1180  _("PRIVATE_KEY option in PEER section missing in configuration\n"));
1181  goto err_ret;
1182  }
1183  /* Remove sections for shared services */
1184  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1185  {
1186  ss = system->shared_services[cnt];
1188  }
1189  if (GNUNET_OK != GNUNET_TESTING_configuration_create_ (system, cfg,
1190  &ports, &nports))
1191  {
1192  GNUNET_asprintf (&emsg_,
1193  _("Failed to create configuration for peer "
1194  "(not enough free ports?)\n"));
1195  goto err_ret;
1196  }
1199  "PRIVATE_KEY",
1200  &hostkey_filename));
1201  fd = GNUNET_DISK_file_open (hostkey_filename,
1205  if (NULL == fd)
1206  {
1207  GNUNET_asprintf (&emsg_, _("Cannot open hostkey file `%s': %s\n"),
1208  hostkey_filename, STRERROR (errno));
1209  GNUNET_free (hostkey_filename);
1210  goto err_ret;
1211  }
1212  GNUNET_free (hostkey_filename);
1215  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1216  GNUNET_TESTING_HOSTKEYFILESIZE))
1217  {
1218  GNUNET_asprintf (&emsg_,
1219  _("Failed to write hostkey file for peer %u: %s\n"),
1220  (unsigned int) key_number,
1221  STRERROR (errno));
1223  goto err_ret;
1224  }
1226  ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *)
1227  * system->n_shared_services);
1228  for (cnt=0; cnt < system->n_shared_services; cnt++)
1229  {
1230  ss = system->shared_services[cnt];
1231  ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1232  if (NULL == ss_instances[cnt])
1233  {
1234  emsg_ = GNUNET_strdup ("FIXME");
1235  goto err_ret;
1236  }
1237  }
1240  (cfg, "PATHS", "DEFAULTCONFIG", &config_filename));
1241  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1242  {
1243  GNUNET_asprintf (&emsg_,
1244  _("Failed to write configuration file `%s' for peer %u: %s\n"),
1245  config_filename,
1246  (unsigned int) key_number,
1247  STRERROR (errno));
1248  GNUNET_free (config_filename);
1249  goto err_ret;
1250  }
1251  peer = GNUNET_new (struct GNUNET_TESTING_Peer);
1252  peer->ss_instances = ss_instances;
1253  peer->cfgfile = config_filename; /* Free in peer_destroy */
1254  peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1255  libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1256  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary))
1257  {
1258  /* No prefix */
1259  GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary);
1260  peer->args = GNUNET_strdup ("");
1261  }
1262  else
1263  {
1264  peer->args = GNUNET_strdup (libexec_binary);
1265  }
1266  peer->system = system;
1267  peer->key_number = key_number;
1268  GNUNET_free (libexec_binary);
1269  peer->ports = ports; /* Free in peer_destroy */
1270  peer->nports = nports;
1271  return peer;
1272 
1273  err_ret:
1274  GNUNET_free_non_null (ss_instances);
1275  GNUNET_free_non_null (ports);
1276  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1277  if (NULL != emsg)
1278  *emsg = emsg_;
1279  else
1280  GNUNET_free (emsg_);
1281  return NULL;
1282 }
1283 
1284 
1291 void
1293  struct GNUNET_PeerIdentity *id)
1294 {
1295  if (NULL != peer->id)
1296  {
1297  GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity));
1298  return;
1299  }
1300  peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1302  peer->key_number,
1303  peer->id));
1304  GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity));
1305 }
1306 
1307 
1314 int
1316 {
1317  struct SharedServiceInstance *i;
1318  unsigned int cnt;
1319 
1320  if (NULL != peer->main_process)
1321  {
1322  GNUNET_break (0);
1323  return GNUNET_SYSERR;
1324  }
1325  GNUNET_assert (NULL != peer->cfgfile);
1326  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1327  {
1328  i = peer->ss_instances[cnt];
1329  if ((0 == i->n_refs)
1331  return GNUNET_SYSERR;
1332  i->n_refs++;
1333  }
1337  NULL,
1338  peer->main_binary,
1339  peer->args,
1340  "-c",
1341  peer->cfgfile,
1342  NULL);
1343  if (NULL == peer->main_process)
1344  {
1346  _("Failed to start `%s': %s\n"),
1347  peer->main_binary,
1348  STRERROR (errno));
1349  return GNUNET_SYSERR;
1350  }
1351  return GNUNET_OK;
1352 }
1353 
1354 
1362 int
1364 {
1365  struct SharedServiceInstance *i;
1366  unsigned int cnt;
1367 
1368  if (NULL == peer->main_process)
1369  {
1370  GNUNET_break (0);
1371  return GNUNET_SYSERR;
1372  }
1374  return GNUNET_SYSERR;
1375  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1376  {
1377  i = peer->ss_instances[cnt];
1378  GNUNET_assert (0 != i->n_refs);
1379  i->n_refs--;
1380  if (0 == i->n_refs)
1382  }
1383  return GNUNET_OK;
1384 }
1385 
1386 
1394 int
1396 {
1397  int ret;
1398 
1399  if (NULL == peer->main_process)
1400  {
1401  GNUNET_break (0);
1402  return GNUNET_SYSERR;
1403  }
1404  ret = GNUNET_OS_process_wait (peer->main_process);
1406  peer->main_process = NULL;
1407  return ret;
1408 }
1409 
1410 
1417 int
1419 {
1421  return GNUNET_SYSERR;
1423  return GNUNET_SYSERR;
1424  return GNUNET_OK;
1425 }
1426 
1427 
1435 static void
1436 disconn_status (void *cls,
1437  int connected)
1438 {
1439  struct GNUNET_TESTING_Peer *peer = cls;
1440 
1441  if (GNUNET_SYSERR == connected)
1442  {
1443  peer->cb (peer->cb_cls, peer, connected);
1444  return;
1445  }
1446  if (GNUNET_YES == connected)
1447  {
1449  return;
1450  }
1452  GNUNET_ARM_disconnect (peer->ah);
1453  peer->ah = NULL;
1454  peer->cb (peer->cb_cls, peer, GNUNET_YES);
1455 }
1456 
1457 
1469 int
1472  void *cb_cls)
1473 {
1474  if (NULL == peer->main_process)
1475  return GNUNET_SYSERR;
1476  peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer);
1477  if (NULL == peer->ah)
1478  return GNUNET_SYSERR;
1479  peer->cb = cb;
1480  peer->cb_cls = cb_cls;
1481  return GNUNET_OK;
1482 }
1483 
1484 
1494 void
1496 {
1497  GNUNET_assert (NULL != peer->ah);
1498  GNUNET_ARM_disconnect (peer->ah);
1499  peer->ah = NULL;
1500 }
1501 
1502 
1510 void
1512 {
1513  unsigned int cnt;
1514 
1515  if (NULL != peer->main_process)
1516  GNUNET_TESTING_peer_stop (peer);
1517  if (NULL != peer->ah)
1518  GNUNET_ARM_disconnect (peer->ah);
1519  GNUNET_free (peer->cfgfile);
1520  if (NULL != peer->cfg)
1522  GNUNET_free (peer->main_binary);
1523  GNUNET_free (peer->args);
1524  GNUNET_free_non_null (peer->id);
1526  if (NULL != peer->ports)
1527  {
1528  for (cnt = 0; cnt < peer->nports; cnt++)
1529  GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]);
1530  GNUNET_free (peer->ports);
1531  }
1532  GNUNET_free (peer);
1533 }
1534 
1535 
1552 int
1553 GNUNET_TESTING_peer_run (const char *testdir,
1554  const char *cfgfilename,
1556  void *tm_cls)
1557 {
1558  return GNUNET_TESTING_service_run (testdir, "arm",
1559  cfgfilename, tm, tm_cls);
1560 }
1561 
1562 
1567 {
1572 
1577 
1582 
1586  void *tm_cls;
1587 };
1588 
1589 
1595 static void
1596 service_run_main (void *cls)
1597 {
1598  struct ServiceContext *sc = cls;
1599 
1600  sc->tm (sc->tm_cls, sc->cfg, sc->peer);
1601 }
1602 
1603 
1625 int
1626 GNUNET_TESTING_service_run (const char *testdir,
1627  const char *service_name,
1628  const char *cfgfilename,
1630  void *tm_cls)
1631 {
1632  struct ServiceContext sc;
1633  struct GNUNET_TESTING_System *system;
1634  struct GNUNET_TESTING_Peer *peer;
1636  char *binary;
1637  char *libexec_binary;
1638 
1639  GNUNET_log_setup (testdir,
1640  "WARNING",
1641  NULL);
1642  system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1643  if (NULL == system)
1644  return 1;
1645  cfg = GNUNET_CONFIGURATION_create ();
1646  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1647  {
1649  _("Failed to load configuration from %s\n"), cfgfilename);
1652  return 1;
1653  }
1654  peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
1655  if (NULL == peer)
1656  {
1658  hostkeys_unload (system);
1660  return 1;
1661  }
1662  GNUNET_free (peer->main_binary);
1663  GNUNET_free (peer->args);
1664  GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1665  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1666  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, service_name, "PREFIX", &peer->main_binary))
1667  {
1668  /* No prefix */
1669  GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary);
1670  peer->args = GNUNET_strdup ("");
1671  }
1672  else
1673  peer->args = GNUNET_strdup (libexec_binary);
1674 
1675  GNUNET_free (libexec_binary);
1676  GNUNET_free (binary);
1677  if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
1678  {
1682  return 1;
1683  }
1684  sc.cfg = cfg;
1685  sc.tm = tm;
1686  sc.tm_cls = tm_cls;
1687  sc.peer = peer;
1688  GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1689  if ((NULL != peer->main_process) &&
1690  (GNUNET_OK != GNUNET_TESTING_peer_stop (peer)))
1691  {
1695  return 1;
1696  }
1700  return 0;
1701 }
1702 
1703 
1717 char *
1719 {
1720  size_t slen = strlen (argv0) + 1;
1721  char sbuf[slen];
1722  char *ret;
1723  char *dot;
1724 
1725  GNUNET_memcpy (sbuf, argv0, slen);
1726  ret = strrchr (sbuf, '_');
1727  if (NULL == ret)
1728  return NULL;
1729  ret++; /* skip underscore */
1730  dot = strchr (ret, '.');
1731  if (NULL != dot)
1732  *dot = '\0';
1733  return GNUNET_strdup (ret);
1734 }
1735 
1736 
1737 /* end of testing.c */
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration we are building.
Definition: testing.c:744
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:781
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:669
Open the file for reading.
int GNUNET_TESTING_peer_stop_async(struct GNUNET_TESTING_Peer *peer, GNUNET_TESTING_PeerStopCallback cb, void *cb_cls)
Stop a peer asynchronously using ARM API.
Definition: testing.c:1470
Create file if it doesn&#39;t exist.
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer in which the service is run.
Definition: testing.c:1571
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:88
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
Closure for update_rel_sum() and update_abs_sum().
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.
The structure for identifying a shared service.
#define AI_NUMERICSERV
AI_NUMERICSERV not defined in windows.
Definition: platform.h:261
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
static void cleanup_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:465
int GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
unsigned int nports
The number of ports in the above array.
Definition: testing.c:240
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:163
char * gnunet_home
The customized service home path for this peer.
Definition: testing.c:749
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
Specification of a service that is to be shared among peers.
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1315
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:175
#define PIPE_CONTROL
We need pipe control only on WINDOWS.
Definition: testing.c:47
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
int GNUNET_TESTING_peer_run(const char *testdir, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls)
Start a single peer and run a test using the testing library.
Definition: testing.c:1553
struct GNUNET_ARM_Handle * ah
The handle to the peer&#39;s ARM service.
Definition: testing.c:205
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:756
unsigned int n_instances
Definition: testing.c:94
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
Definition: testing.c:143
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:704
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_OS_Process * GNUNET_OS_start_process(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:1400
#define LOG(kind,...)
Definition: testing.c:37
#define STRERROR(i)
Definition: plibc.h:676
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:2020
unsigned int share
Definition: testing.c:92
struct GNUNET_OS_Process * proc
Definition: testing.c:73
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(int pipe_control, unsigned int std_inheritance, const SOCKTYPE *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:1474
int GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:522
static struct GNUNET_FS_UnindexContext * uc
static int hostkeys_load(struct GNUNET_TESTING_System *system)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:257
Nobody is allowed to do anything to the file.
static int start_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:481
unsigned int n_shared_services
Definition: testing.c:133
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:716
Handle for interacting with ARM.
Definition: arm_api.c:97
#define GNUNET_TESTING_PREFIX
The environmental variable, if set, that dictates where testing should place generated peer configura...
#define GNUNET_NO
Definition: gnunet_common.h:81
#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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void disconn_status(void *cls, int connected)
Function called whenever we connect to or disconnect from ARM.
Definition: testing.c:1436
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:235
void * tm_cls
Closure for the above callback.
Definition: testing.c:1586
static int ret
Final status code.
Definition: gnunet-arm.c:89
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition: arm_api.c:507
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct SharedServiceInstance * associate_shared_service(struct GNUNET_TESTING_System *system, struct SharedService *ss, struct GNUNET_CONFIGURATION_Handle *cfg)
Definition: testing.c:972
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1418
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
int GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testing.c:1113
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint32_t total_hostkeys
The number of hostkeys.
Definition: testing.c:158
char * main_binary
Binary to be executed during &#39;GNUNET_TESTING_peer_start&#39;.
Definition: testing.c:193
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
struct GNUNET_TESTING_Peer * GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t key_number, struct GNUNET_PeerIdentity *id, char **emsg)
Configure a GNUnet peer.
Definition: testing.c:1134
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * section
Name of the section.
Definition: gnunet-config.c:33
Structure for holding service data.
Definition: testing.c:1566
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1363
uint32_t path_counter
Counter we use to make service home paths unique on this system; the full path consists of the tmppat...
Definition: testing.c:153
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
unsigned int n_peers
Definition: testing.c:90
#define GNUNET_memcpy(dst, src, n)
static char * value
Value of the record to add/remove.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:1049
int GNUNET_TESTING_service_run(const char *testdir, const char *service_name, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls)
Start a single service (no ARM, except of course if the given service name is &#39;arm&#39;) and run a test u...
Definition: testing.c:1626
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1359
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:180
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation directory.
Read-only memory map.
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
void * cb_cls
The closure for the above callback.
Definition: testing.c:220
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static char * option
Name of the option.
Definition: gnunet-config.c:38
static char * filename
struct GNUNET_CONFIGURATION_Handle * cfg
The config of the peer.
Definition: testing.c:210
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:289
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
struct GNUNET_ARM_Handle * GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ARM_ConnectionStatusCallback conn_status, void *conn_status_cls)
Set up a context for communicating with ARM, then start connecting to the ARM service using that cont...
Definition: arm_api.c:482
char * cfgfile
Path to the configuration file for this peer.
Definition: testing.c:185
char * sname
Definition: testing.c:84
unsigned int share
The number of peers which share an instance of the service.
unsigned int nports
The number of ports in the above array.
Definition: testing.c:761
#define HIGH_PORT
Highest port used for GNUnet testing.
Definition: testing.c:64
When these flags are set, the child process will inherit stdout and stderr of the parent...
Definition: gnunet_os_lib.h:98
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
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
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:527
unsigned int n_refs
Definition: testing.c:79
GNUNET_TESTING_TestMain tm
Callback to signal service startup.
Definition: testing.c:1576
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:2100
struct SharedService ** shared_services
Definition: testing.c:131
Open the file for writing.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:530
const char * service
The name of the service.
char * getenv()
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:102
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define LOW_PORT
Lowest port used for GNUnet testing.
Definition: testing.c:57
struct SharedService * ss
Definition: testing.c:69
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
int GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:289
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:272
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running...
Definition: testing.c:200
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1495
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create_with_portrange(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services, uint16_t lowport, uint16_t highport)
Create a system handle.
Definition: testing.c:370
static void hostkeys_unload(struct GNUNET_TESTING_System *system)
Function to remove the loaded hostkeys.
Definition: testing.c:319
Private ECC key encoded for transmission.
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
char * GNUNET_TESTING_get_testname_from_underscore(const char *argv0)
Sometimes we use the binary name to determine which specific test to run.
Definition: testing.c:1718
The identity of the host (wraps the signing key of the peer).
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:168
static char * hostname
Our hostname; we give this to all the peers we start.
static void cfg_copy_iterator(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:339
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1762
#define SSCANF
Definition: plibc.h:691
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
configuration data
Definition: configuration.c:85
static void stop_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:507
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration template for the service.
static void update_config_sections(void *cls, const char *section)
Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of &#39;trusted_hosts&#39; in all sec...
Definition: testing.c:875
struct GNUNET_TESTING_Peer * peer
The peer in which the service is run.
Definition: testing.c:1581
struct SharedServiceInstance ** instances
Definition: testing.c:86
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Section_Iterator iter, void *iter_cls)
Iterate over all sections in the configuration.
struct GNUNET_DISK_MapHandle * map
memory map for hostkeys_data.
Definition: testing.c:129
#define GNUNET_log(kind,...)
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:124
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a TCP or UDP port for a peer.
Definition: testing.c:569
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.
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
void GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer, struct GNUNET_PeerIdentity *id)
Obtain the peer identity from a peer handle.
Definition: testing.c:1292
handle to a socket
Definition: network.c:46
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:245
static int GNUNET_TESTING_configuration_create_(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t **ports, unsigned int *nports)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testing.c:1053
char * hostname
our hostname
Definition: testing.c:119
#define GNUNET_YES
Definition: gnunet_common.h:80
int fd
File handle on other OSes.
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:739
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:215
struct GNUNET_PeerIdentity * id
The cached identity of this peer.
Definition: testing.c:226
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
struct SharedServiceInstance ** ss_instances
Definition: testing.c:228
char * tmppath
Prefix (i.e.
Definition: testing.c:108
int status
build status - to signal error while building a configuration
Definition: testing.c:766
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:282
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1673
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1511
static void service_run_main(void *cls)
Callback to be called when SCHEDULER has been started.
Definition: testing.c:1596
void GNUNET_TESTING_release_port(struct GNUNET_TESTING_System *system, uint16_t port)
Release reservation of a TCP or UDP port for a peer (used during GNUNET_TESTING_peer_destroy()).
Definition: testing.c:666
Handle used to access files (and pipes).
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
void(* GNUNET_TESTING_TestMain)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer)
Signature of the &#39;main&#39; function for a (single-peer) testcase that is run using GNUNET_TESTING_peer_r...
#define GNUNET_malloc(size)
Wrapper around malloc.
Handle for a memory-mapping operation.
Definition: disk.c:1985
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1395
struct GNUNET_CRYPTO_EddsaPublicKey public_key
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:1037
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:251
char * trusted_ip
The trusted ip.
Definition: testing.c:114
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.