GNUnet  0.11.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, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
38 
39 
43 #define PIPE_CONTROL GNUNET_NO
44 
45 
52 #define LOW_PORT 12000
53 
59 #define HIGH_PORT 56000
60 
61 
63 {
64  struct SharedService *ss;
65 
66  char *cfg_fn;
67 
69 
70  char *unix_sock;
71 
72  char *port_str;
73 
74  unsigned int n_refs;
75 };
76 
77 struct SharedService
78 {
79  char *sname;
80 
82 
84 
85  unsigned int n_peers;
86 
87  unsigned int share;
88 
89  unsigned int n_instances;
90 };
91 
92 
98 {
103  char *tmppath;
104 
109  char *trusted_ip;
110 
114  char *hostname;
115 
120 
125 
127 
128  unsigned int n_shared_services;
129 
138  uint32_t reserved_ports[65536 / 32];
139 
148  uint32_t path_counter;
149 
153  uint32_t total_hostkeys;
154 
158  uint16_t lowport;
159 
163  uint16_t highport;
164 };
165 
166 
171 {
176 
180  char *cfgfile;
181 
188  char *main_binary;
189  char *args;
190 
196 
201 
206 
211 
215  void *cb_cls;
216 
222 
224 
230  uint16_t *ports;
231 
235  unsigned int nports;
236 
240  uint32_t key_number;
241 };
242 
243 
251 static int
253 {
254  uint64_t fs;
255  char *data_dir;
256  char *filename;
257  struct GNUNET_DISK_FileHandle *fd;
258 
259  GNUNET_assert (NULL == system->hostkeys_data);
261  GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
262  GNUNET_free (data_dir);
263 
264  if (GNUNET_YES != GNUNET_DISK_file_test (filename))
265  {
267  _ ("Hostkeys file not found: %s\n"),
268  filename);
269  GNUNET_free (filename);
270  return GNUNET_SYSERR;
271  }
272  /* Check hostkey file size, read entire thing into memory */
273  if (GNUNET_OK !=
274  GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
275  fs = 0;
276  if (0 == fs)
277  {
278  GNUNET_free (filename);
279  return GNUNET_SYSERR; /* File is empty */
280  }
281  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
282  {
284  _ ("Incorrect hostkey file format: %s\n"),
285  filename);
286  GNUNET_free (filename);
287  return GNUNET_SYSERR;
288  }
289  fd = GNUNET_DISK_file_open (filename,
292  if (NULL == fd)
293  {
295  GNUNET_free (filename);
296  return GNUNET_SYSERR;
297  }
298  GNUNET_free (filename);
299  system->hostkeys_data =
302  if (NULL == system->hostkeys_data)
303  return GNUNET_SYSERR;
305  return GNUNET_OK;
306 }
307 
308 
314 static void
316 {
317  GNUNET_break (NULL != system->hostkeys_data);
318  system->hostkeys_data = NULL;
319  GNUNET_DISK_file_unmap (system->map);
320  system->map = NULL;
321  system->hostkeys_data = NULL;
322  system->total_hostkeys = 0;
323 }
324 
325 
334 static void
335 cfg_copy_iterator (void *cls,
336  const char *section,
337  const char *option,
338  const char *value)
339 {
340  struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
341 
342  GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value);
343 }
344 
345 
367 struct GNUNET_TESTING_System *
369  const char *testdir,
370  const char *trusted_ip,
371  const char *hostname,
373  uint16_t lowport,
374  uint16_t highport)
375 {
376  struct GNUNET_TESTING_System *system;
377  struct GNUNET_TESTING_SharedService tss;
378  struct SharedService *ss;
379  unsigned int cnt;
380 
381  GNUNET_assert (NULL != testdir);
382  system = GNUNET_new (struct GNUNET_TESTING_System);
383  if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX)))
384  system->tmppath = GNUNET_DISK_mkdtemp (testdir);
385  else
386  system->tmppath = GNUNET_strdup (system->tmppath);
387  system->lowport = lowport;
388  system->highport = highport;
389  if (NULL == system->tmppath)
390  {
391  GNUNET_free (system);
392  return NULL;
393  }
394  if (NULL != trusted_ip)
395  system->trusted_ip = GNUNET_strdup (trusted_ip);
396  if (NULL != hostname)
397  system->hostname = GNUNET_strdup (hostname);
398  if (GNUNET_OK != hostkeys_load (system))
399  {
401  return NULL;
402  }
403  if (NULL == shared_services)
404  return system;
405  for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
406  {
407  tss = shared_services[cnt];
408  ss = GNUNET_new (struct SharedService);
409  ss->sname = GNUNET_strdup (tss.service);
412  ss->sname,
414  ss->cfg);
416  "TESTING",
418  ss->cfg);
420  "PATHS",
422  ss->cfg);
423  ss->share = tss.share;
425  system->n_shared_services,
426  ss);
427  }
428  return system;
429 }
430 
431 
452 struct GNUNET_TESTING_System *
454  const char *testdir,
455  const char *trusted_ip,
456  const char *hostname,
458 {
460  trusted_ip,
461  hostname,
462  shared_services,
463  LOW_PORT,
464  HIGH_PORT);
465 }
466 
467 
468 static void
470 {
471  if (NULL != i->cfg_fn)
472  {
473  (void) unlink (i->cfg_fn);
474  GNUNET_free (i->cfg_fn);
475  }
478  GNUNET_break (NULL == i->proc);
479  GNUNET_break (0 == i->n_refs);
480  GNUNET_free (i);
481 }
482 
483 
484 static int
486 {
487  char *binary;
488  char *libexec_binary;
489 
490  GNUNET_assert (NULL == i->proc);
491  GNUNET_assert (NULL != i->cfg_fn);
492  (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
493  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
494  GNUNET_free (binary);
497  NULL,
498  NULL,
499  NULL,
500  libexec_binary,
501  libexec_binary,
502  "-c",
503  i->cfg_fn,
504  NULL);
505  GNUNET_free (libexec_binary);
506  if (NULL == i->proc)
507  return GNUNET_SYSERR;
508  return GNUNET_OK;
509 }
510 
511 
512 static void
514 {
515  GNUNET_break (0 == i->n_refs);
518  "Killing shared service instance (%s) failed\n",
519  i->ss->sname);
520  (void) GNUNET_OS_process_wait (i->proc);
522  i->proc = NULL;
523 }
524 
525 
533 void
535  int remove_paths)
536 {
537  struct SharedService *ss;
538  struct SharedServiceInstance *i;
539  unsigned int ss_cnt;
540  unsigned int i_cnt;
541 
542  if (NULL != system->hostkeys_data)
543  hostkeys_unload (system);
544  for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
545  {
546  ss = system->shared_services[ss_cnt];
547  for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
548  {
549  i = ss->instances[i_cnt];
550  if (NULL != i->proc)
553  }
556  GNUNET_free (ss->sname);
557  GNUNET_free (ss);
558  }
560  if (GNUNET_YES == remove_paths)
562  GNUNET_free (system->tmppath);
564  GNUNET_free_non_null (system->hostname);
565  GNUNET_free (system);
566 }
567 
568 
575 uint16_t
577 {
578  struct GNUNET_NETWORK_Handle *socket;
579  struct addrinfo hint;
580  struct addrinfo *ret;
581  struct addrinfo *ai;
582  uint32_t *port_buckets;
583  char *open_port_str;
584  int bind_status;
585  uint32_t xor_image;
586  uint16_t index;
587  uint16_t open_port;
588  uint16_t pos;
589 
590  /*
591  FIXME: Instead of using getaddrinfo we should try to determine the port
592  status by the following heurestics.
593 
594  On systems which support both IPv4 and IPv6, only ports open on both
595  address families are considered open.
596  On system with either IPv4 or IPv6. A port is considered open if it's
597  open in the respective address family
598  */hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
599  hint.ai_socktype = 0;
600  hint.ai_protocol = 0;
601  hint.ai_addrlen = 0;
602  hint.ai_addr = NULL;
603  hint.ai_canonname = NULL;
604  hint.ai_next = NULL;
605  hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
606  port_buckets = system->reserved_ports;
607  for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
608  index++)
609  {
610  xor_image = (UINT32_MAX ^ port_buckets[index]);
611  if (0 == xor_image) /* Ports in the bucket are full */
612  continue;
613  pos = system->lowport % 32;
614  while (pos < 32)
615  {
616  if (0 == ((xor_image >> pos) & 1U))
617  {
618  pos++;
619  continue;
620  }
621  open_port = (index * 32) + pos;
622  if (open_port >= system->highport)
623  return 0;
624  GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
625  ret = NULL;
626  GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
627  GNUNET_free (open_port_str);
628  bind_status = GNUNET_NO;
629  for (ai = ret; NULL != ai; ai = ai->ai_next)
630  {
631  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
632  if (NULL == socket)
633  continue;
634  bind_status =
635  GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
637  if (GNUNET_OK != bind_status)
638  break;
639  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
640  if (NULL == socket)
641  continue;
642  bind_status =
643  GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
645  if (GNUNET_OK != bind_status)
646  break;
647  }
648  port_buckets[index] |= (1U << pos); /* Set the port bit */
649  freeaddrinfo (ret);
650  if (GNUNET_OK == bind_status)
651  {
653  "Found a free port %u\n",
654  (unsigned int) open_port);
655  return open_port;
656  }
657  pos++;
658  }
659  }
660  return 0;
661 }
662 
663 
671 void
673  uint16_t port)
674 {
675  uint32_t *port_buckets;
676  uint16_t bucket;
677  uint16_t pos;
678 
679  port_buckets = system->reserved_ports;
680  bucket = port / 32;
681  pos = port % 32;
682  LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
683  if (0 == (port_buckets[bucket] & (1U << pos)))
684  {
685  GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
686  return;
687  }
688  port_buckets[bucket] &= ~(1U << pos);
689 }
690 
691 
711  uint32_t key_number,
712  struct GNUNET_PeerIdentity *id)
713 {
714  struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
715 
716  if ((NULL == id) || (NULL == system->hostkeys_data))
717  return NULL;
718  if (key_number >= system->total_hostkeys)
719  {
721  _ ("Key number %u does not exist\n"),
722  key_number);
723  return NULL;
724  }
725  private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
726  GNUNET_memcpy (private_key,
727  system->hostkeys_data
728  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
729  GNUNET_TESTING_HOSTKEYFILESIZE);
731  return private_key;
732 }
733 
734 
739 struct UpdateContext
740 {
745 
750 
754  char *gnunet_home;
755 
761  uint16_t *ports;
762 
766  unsigned int nports;
767 
771  int status;
772 };
773 
774 
785 static void
786 update_config (void *cls,
787  const char *section,
788  const char *option,
789  const char *value)
790 {
791  struct UpdateContext *uc = cls;
792  unsigned int ival;
793  char cval[12];
794  char uval[PATH_MAX];
795  char *single_variable;
796  char *per_host_variable;
797  unsigned long long num_per_host;
798  uint16_t new_port;
799 
800  if (GNUNET_OK != uc->status)
801  return;
802  if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
803  (0 == strcmp (option, "HOSTNAME"))))
804  return;
805  GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
806  GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
807  if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
808  {
809  if ((ival != 0) &&
811  "testing",
812  single_variable)))
813  {
814  new_port = GNUNET_TESTING_reserve_port (uc->system);
815  if (0 == new_port)
816  {
817  uc->status = GNUNET_SYSERR;
818  GNUNET_free (single_variable);
819  GNUNET_free (per_host_variable);
820  return;
821  }
822  GNUNET_snprintf (cval, sizeof(cval), "%u", new_port);
823  value = cval;
824  GNUNET_array_append (uc->ports, uc->nports, new_port);
825  }
826  else if ((ival != 0) &&
827  (GNUNET_YES ==
829  "testing",
830  single_variable)) &&
832  "testing",
833  per_host_variable,
834  &num_per_host))
835  {
836  /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
837  /* ival + ctx->fdnum % num_per_host); */
838  /* value = cval; */
839  GNUNET_break (0); /* FIXME */
840  }
841  }
842  if (0 == strcmp (option, "UNIXPATH"))
843  {
845  "testing",
846  single_variable))
847  {
848  GNUNET_snprintf (uval,
849  sizeof(uval),
850  "%s/%s.sock",
851  uc->gnunet_home,
852  section);
853  value = uval;
854  }
855  else if ((GNUNET_YES ==
857  "testing",
858  per_host_variable,
859  &num_per_host)) &&
860  (num_per_host > 0))
861  {
862  GNUNET_break (0); /* FIXME */
863  }
864  }
865  if (0 == strcmp (option, "HOSTNAME"))
866  {
867  value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
868  }
869  GNUNET_free (single_variable);
870  GNUNET_free (per_host_variable);
871  GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
872 }
873 
874 
882 static void
883 update_config_sections (void *cls, const char *section)
884 {
885  struct UpdateContext *uc = cls;
886  char **ikeys;
887  char *val;
888  char *ptr;
889  char *orig_allowed_hosts;
890  char *allowed_hosts;
891  char *ACCEPT_FROM_key;
892  uint16_t ikeys_cnt;
893  uint16_t key;
894 
895  ikeys_cnt = 0;
896  val = NULL;
897  /* Ignore certain options from sections. See
898  https://gnunet.org/bugs/view.php?id=2476 */
899  if (GNUNET_YES ==
900  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
901  {
904  section,
905  "TESTING_IGNORE_KEYS",
906  &val));
907  ptr = val;
908  for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
909  ptr++;
910  if (0 == ikeys_cnt)
911  GNUNET_break (0);
912  else
913  {
914  ikeys = GNUNET_malloc ((sizeof(char *)) * ikeys_cnt);
915  ptr = val;
916  for (key = 0; key < ikeys_cnt; key++)
917  {
918  ikeys[key] = ptr;
919  ptr = strstr (ptr, ";");
920  GNUNET_assert (NULL != ptr); /* worked just before... */
921  *ptr = '\0';
922  ptr++;
923  }
924  }
925  }
926  if (0 != ikeys_cnt)
927  {
928  for (key = 0; key < ikeys_cnt; key++)
929  {
930  if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
931  break;
932  }
933  if ((key == ikeys_cnt) &&
934  (GNUNET_YES ==
935  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
936  {
938  section,
939  "PORT",
940  &ptr))
941  {
943  section,
944  "ADVERTISED_PORT",
945  ptr);
946  GNUNET_free (ptr);
947  }
948  }
949  for (key = 0; key < ikeys_cnt; key++)
950  {
951  if (NULL != strstr (ikeys[key], "ACCEPT_FROM"))
952  {
953  GNUNET_free (ikeys);
954  GNUNET_free (val);
955  return;
956  }
957  }
958  GNUNET_free (ikeys);
959  }
960  GNUNET_free_non_null (val);
961  ACCEPT_FROM_key = "ACCEPT_FROM";
962  if ((NULL != uc->system->trusted_ip) &&
963  (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
964  ACCEPT_FROM_key = "ACCEPT_FROM6";
966  section,
967  ACCEPT_FROM_key,
968  &orig_allowed_hosts))
969  {
970  orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
971  }
972  if (NULL == uc->system->trusted_ip)
973  allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
974  else
975  GNUNET_asprintf (&allowed_hosts,
976  "%s%s;",
977  orig_allowed_hosts,
978  uc->system->trusted_ip);
979  GNUNET_free (orig_allowed_hosts);
981  section,
982  ACCEPT_FROM_key,
983  allowed_hosts);
984  GNUNET_free (allowed_hosts);
985 }
986 
987 
988 static struct SharedServiceInstance *
990  struct SharedService *ss,
992 {
993  struct SharedServiceInstance *i;
994  struct GNUNET_CONFIGURATION_Handle *temp;
995  char *gnunet_home;
996  uint32_t port;
997 
998  ss->n_peers++;
999  if (((0 == ss->share) && (NULL == ss->instances)) ||
1000  ((0 != ss->share) &&
1001  (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
1002  {
1003  i = GNUNET_new (struct SharedServiceInstance);
1004  i->ss = ss;
1005  (void) GNUNET_asprintf (&gnunet_home,
1006  "%s/shared/%s/%u",
1007  system->tmppath,
1008  ss->sname,
1009  ss->n_instances);
1010  (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
1011  port = GNUNET_TESTING_reserve_port (system);
1012  if (0 == port)
1013  {
1014  GNUNET_free (gnunet_home);
1016  return NULL;
1017  }
1019  temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1020  (void) GNUNET_asprintf (&i->port_str, "%u", port);
1021  (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1023  "PATHS",
1024  "GNUNET_HOME",
1025  gnunet_home);
1026  GNUNET_free (gnunet_home);
1028  ss->sname,
1029  "UNIXPATH",
1030  i->unix_sock);
1032  ss->sname,
1033  "PORT",
1034  i->port_str);
1036  {
1039  return NULL;
1040  }
1042  }
1043  else
1044  {
1045  GNUNET_assert (NULL != ss->instances);
1046  GNUNET_assert (0 < ss->n_instances);
1047  i = ss->instances[ss->n_instances - 1];
1048  }
1050  ss->sname,
1052  cfg);
1054  ss->sname,
1055  "UNIXPATH",
1056  i->unix_sock);
1057  GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1058  return i;
1059 }
1060 
1061 
1081 static int
1084  uint16_t **ports,
1085  unsigned int *nports)
1086 {
1087  struct UpdateContext uc;
1088  char *default_config;
1089 
1090  uc.system = system;
1091  uc.cfg = cfg;
1092  uc.status = GNUNET_OK;
1093  uc.ports = NULL;
1094  uc.nports = 0;
1096  "%s/%u",
1097  system->tmppath,
1098  system->path_counter++);
1099  GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1101  "PATHS",
1102  "DEFAULTCONFIG",
1103  default_config);
1104  GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
1105  GNUNET_free (default_config);
1107  "PATHS",
1108  "GNUNET_HOME",
1109  uc.gnunet_home);
1110  /* make PORTs and UNIXPATHs unique */
1112  /* allow connections to services from system trusted_ip host */
1114  /* enable loopback-based connections between peers */
1115  GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
1116  GNUNET_free (uc.gnunet_home);
1117  if ((NULL != ports) && (NULL != nports))
1118  {
1119  *ports = uc.ports;
1120  *nports = uc.nports;
1121  }
1122  else
1124  return uc.status;
1125 }
1126 
1127 
1144 int
1147 {
1148  return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1149 }
1150 
1151 
1165 struct GNUNET_TESTING_Peer *
1168  uint32_t key_number,
1169  struct GNUNET_PeerIdentity *id,
1170  char **emsg)
1171 {
1172  struct GNUNET_TESTING_Peer *peer;
1173  struct GNUNET_DISK_FileHandle *fd;
1174  char *hostkey_filename;
1175  char *config_filename;
1176  char *libexec_binary;
1177  char *emsg_;
1179  uint16_t *ports;
1180  struct SharedService *ss;
1181  struct SharedServiceInstance **ss_instances;
1182  unsigned int cnt;
1183  unsigned int nports;
1184 
1185  ports = NULL;
1186  nports = 0;
1187  ss_instances = NULL;
1188  if (NULL != emsg)
1189  *emsg = NULL;
1190  if (key_number >= system->total_hostkeys)
1191  {
1192  GNUNET_asprintf (
1193  &emsg_,
1194  _ (
1195  "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1196  (unsigned int) system->total_hostkeys);
1197  goto err_ret;
1198  }
1199  pk = NULL;
1200  if ((NULL != id) &&
1201  (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1202  {
1203  GNUNET_asprintf (&emsg_,
1204  _ ("Failed to initialize hostkey for peer %u\n"),
1205  (unsigned int) key_number);
1206  goto err_ret;
1207  }
1208  if (NULL != pk)
1209  GNUNET_free (pk);
1210  if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1211  {
1212  GNUNET_asprintf (
1213  &emsg_,
1214  _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
1215  goto err_ret;
1216  }
1217  /* Remove sections for shared services */
1218  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1219  {
1220  ss = system->shared_services[cnt];
1222  }
1223  if (GNUNET_OK !=
1224  GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
1225  {
1226  GNUNET_asprintf (&emsg_,
1227  _ ("Failed to create configuration for peer "
1228  "(not enough free ports?)\n"));
1229  goto err_ret;
1230  }
1233  "PEER",
1234  "PRIVATE_KEY",
1235  &hostkey_filename));
1236  fd = GNUNET_DISK_file_open (hostkey_filename,
1240  if (NULL == fd)
1241  {
1242  GNUNET_asprintf (&emsg_,
1243  _ ("Cannot open hostkey file `%s': %s\n"),
1244  hostkey_filename,
1245  strerror (errno));
1246  GNUNET_free (hostkey_filename);
1247  goto err_ret;
1248  }
1249  GNUNET_free (hostkey_filename);
1252  system->hostkeys_data
1253  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1254  GNUNET_TESTING_HOSTKEYFILESIZE))
1255  {
1256  GNUNET_asprintf (&emsg_,
1257  _ ("Failed to write hostkey file for peer %u: %s\n"),
1258  (unsigned int) key_number,
1259  strerror (errno));
1261  goto err_ret;
1262  }
1264  ss_instances = GNUNET_malloc (sizeof(struct SharedServiceInstance *)
1265  * system->n_shared_services);
1266  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1267  {
1268  ss = system->shared_services[cnt];
1269  ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1270  if (NULL == ss_instances[cnt])
1271  {
1272  emsg_ = GNUNET_strdup ("FIXME");
1273  goto err_ret;
1274  }
1275  }
1278  "PATHS",
1279  "DEFAULTCONFIG",
1280  &config_filename));
1281  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1282  {
1283  GNUNET_asprintf (&emsg_,
1284  _ (
1285  "Failed to write configuration file `%s' for peer %u: %s\n"),
1286  config_filename,
1287  (unsigned int) key_number,
1288  strerror (errno));
1289  GNUNET_free (config_filename);
1290  goto err_ret;
1291  }
1292  peer = GNUNET_new (struct GNUNET_TESTING_Peer);
1293  peer->ss_instances = ss_instances;
1294  peer->cfgfile = config_filename; /* Free in peer_destroy */
1295  peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1296  libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1297  if (GNUNET_SYSERR ==
1299  "arm",
1300  "PREFIX",
1301  &peer->main_binary))
1302  {
1303  /* No prefix */
1304  GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1305  peer->args = GNUNET_strdup ("");
1306  }
1307  else
1308  {
1309  peer->args = GNUNET_strdup (libexec_binary);
1310  }
1311  peer->system = system;
1312  peer->key_number = key_number;
1313  GNUNET_free (libexec_binary);
1314  peer->ports = ports; /* Free in peer_destroy */
1315  peer->nports = nports;
1316  return peer;
1317 
1318 err_ret:
1319  GNUNET_free_non_null (ss_instances);
1320  GNUNET_free_non_null (ports);
1321  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1322  if (NULL != emsg)
1323  *emsg = emsg_;
1324  else
1325  GNUNET_free (emsg_);
1326  return NULL;
1327 }
1328 
1329 
1336 void
1338  struct GNUNET_PeerIdentity *id)
1339 {
1340  if (NULL != peer->id)
1341  {
1342  GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1343  return;
1344  }
1345  peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1346  GNUNET_free (
1347  GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
1348  GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1349 }
1350 
1351 
1358 int
1360 {
1361  struct SharedServiceInstance *i;
1362  unsigned int cnt;
1363 
1364  if (NULL != peer->main_process)
1365  {
1366  GNUNET_break (0);
1367  return GNUNET_SYSERR;
1368  }
1369  GNUNET_assert (NULL != peer->cfgfile);
1370  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1371  {
1372  i = peer->ss_instances[cnt];
1373  if ((0 == i->n_refs) &&
1375  return GNUNET_SYSERR;
1376  i->n_refs++;
1377  }
1378  peer->main_binary =
1380  peer->main_process =
1383  NULL,
1384  peer->main_binary,
1385  peer->args,
1386  "-c",
1387  peer->cfgfile,
1388  NULL);
1389  if (NULL == peer->main_process)
1390  {
1392  _ ("Failed to start `%s': %s\n"),
1393  peer->main_binary,
1394  strerror (errno));
1395  return GNUNET_SYSERR;
1396  }
1397  return GNUNET_OK;
1398 }
1399 
1400 
1408 int
1410 {
1411  struct SharedServiceInstance *i;
1412  unsigned int cnt;
1413 
1414  if (NULL == peer->main_process)
1415  {
1416  GNUNET_break (0);
1417  return GNUNET_SYSERR;
1418  }
1420  return GNUNET_SYSERR;
1421  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1422  {
1423  i = peer->ss_instances[cnt];
1424  GNUNET_assert (0 != i->n_refs);
1425  i->n_refs--;
1426  if (0 == i->n_refs)
1428  }
1429  return GNUNET_OK;
1430 }
1431 
1432 
1440 int
1442 {
1443  int ret;
1444 
1445  if (NULL == peer->main_process)
1446  {
1447  GNUNET_break (0);
1448  return GNUNET_SYSERR;
1449  }
1450  ret = GNUNET_OS_process_wait (peer->main_process);
1452  peer->main_process = NULL;
1453  return ret;
1454 }
1455 
1456 
1463 int
1465 {
1467  return GNUNET_SYSERR;
1469  return GNUNET_SYSERR;
1470  return GNUNET_OK;
1471 }
1472 
1473 
1481 static void
1482 disconn_status (void *cls, int connected)
1483 {
1484  struct GNUNET_TESTING_Peer *peer = cls;
1485 
1486  if (GNUNET_SYSERR == connected)
1487  {
1488  peer->cb (peer->cb_cls, peer, connected);
1489  return;
1490  }
1491  if (GNUNET_YES == connected)
1492  {
1494  return;
1495  }
1497  GNUNET_ARM_disconnect (peer->ah);
1498  peer->ah = NULL;
1499  peer->cb (peer->cb_cls, peer, GNUNET_YES);
1500 }
1501 
1502 
1514 int
1517  void *cb_cls)
1518 {
1519  if (NULL == peer->main_process)
1520  return GNUNET_SYSERR;
1521  peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer);
1522  if (NULL == peer->ah)
1523  return GNUNET_SYSERR;
1524  peer->cb = cb;
1525  peer->cb_cls = cb_cls;
1526  return GNUNET_OK;
1527 }
1528 
1529 
1539 void
1541 {
1542  GNUNET_assert (NULL != peer->ah);
1543  GNUNET_ARM_disconnect (peer->ah);
1544  peer->ah = NULL;
1545 }
1546 
1547 
1555 void
1557 {
1558  unsigned int cnt;
1559 
1560  if (NULL != peer->main_process)
1561  GNUNET_TESTING_peer_stop (peer);
1562  if (NULL != peer->ah)
1563  GNUNET_ARM_disconnect (peer->ah);
1564  GNUNET_free (peer->cfgfile);
1565  if (NULL != peer->cfg)
1567  GNUNET_free (peer->main_binary);
1568  GNUNET_free (peer->args);
1569  GNUNET_free_non_null (peer->id);
1571  if (NULL != peer->ports)
1572  {
1573  for (cnt = 0; cnt < peer->nports; cnt++)
1574  GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]);
1575  GNUNET_free (peer->ports);
1576  }
1577  GNUNET_free (peer);
1578 }
1579 
1580 
1597 int
1598 GNUNET_TESTING_peer_run (const char *testdir,
1599  const char *cfgfilename,
1601  void *tm_cls)
1602 {
1603  return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
1604 }
1605 
1606 
1611 {
1616 
1621 
1626 
1630  void *tm_cls;
1631 };
1632 
1633 
1639 static void
1640 service_run_main (void *cls)
1641 {
1642  struct ServiceContext *sc = cls;
1643 
1644  sc->tm (sc->tm_cls, sc->cfg, sc->peer);
1645 }
1646 
1647 
1669 int
1670 GNUNET_TESTING_service_run (const char *testdir,
1671  const char *service_name,
1672  const char *cfgfilename,
1674  void *tm_cls)
1675 {
1676  struct ServiceContext sc;
1677  struct GNUNET_TESTING_System *system;
1678  struct GNUNET_TESTING_Peer *peer;
1680  char *binary;
1681  char *libexec_binary;
1682 
1683  GNUNET_log_setup (testdir, "WARNING", NULL);
1684  system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1685  if (NULL == system)
1686  return 1;
1687  cfg = GNUNET_CONFIGURATION_create ();
1688  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1689  {
1691  _ ("Failed to load configuration from %s\n"),
1692  cfgfilename);
1695  return 1;
1696  }
1697  peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
1698  if (NULL == peer)
1699  {
1701  hostkeys_unload (system);
1703  return 1;
1704  }
1705  GNUNET_free (peer->main_binary);
1706  GNUNET_free (peer->args);
1707  GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1708  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1709  if (GNUNET_SYSERR ==
1711  service_name,
1712  "PREFIX",
1713  &peer->main_binary))
1714  {
1715  /* No prefix */
1716  GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1717  peer->args = GNUNET_strdup ("");
1718  }
1719  else
1720  peer->args = GNUNET_strdup (libexec_binary);
1721 
1722  GNUNET_free (libexec_binary);
1723  GNUNET_free (binary);
1724  if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
1725  {
1729  return 1;
1730  }
1731  sc.cfg = cfg;
1732  sc.tm = tm;
1733  sc.tm_cls = tm_cls;
1734  sc.peer = peer;
1735  GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1736  if ((NULL != peer->main_process) &&
1737  (GNUNET_OK != GNUNET_TESTING_peer_stop (peer)))
1738  {
1742  return 1;
1743  }
1747  return 0;
1748 }
1749 
1750 
1764 char *
1766 {
1767  size_t slen = strlen (argv0) + 1;
1768  char sbuf[slen];
1769  char *ret;
1770  char *dot;
1771 
1772  GNUNET_memcpy (sbuf, argv0, slen);
1773  ret = strrchr (sbuf, '_');
1774  if (NULL == ret)
1775  return NULL;
1776  ret++; /* skip underscore */
1777  dot = strchr (ret, '.');
1778  if (NULL != dot)
1779  *dot = '\0';
1780  return GNUNET_strdup (ret);
1781 }
1782 
1783 
1784 /* end of testing.c */
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration we are building.
Definition: testing.c:749
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:786
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:544
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:1515
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:1615
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:83
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
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.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
The structure for identifying a shared service.
#define AI_NUMERICSERV
AI_NUMERICSERV not defined in windows.
Definition: platform.h:227
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:469
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:235
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:158
char * gnunet_home
The customized service home path for this peer.
Definition: testing.c:754
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:287
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:1359
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:170
#define PIPE_CONTROL
We need pipe control only on WINDOWS.
Definition: testing.c:43
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:1598
struct GNUNET_ARM_Handle * ah
The handle to the peer&#39;s ARM service.
Definition: testing.c:200
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:761
unsigned int n_instances
Definition: testing.c:89
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
Definition: testing.c:138
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:710
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:687
#define LOG(kind,...)
Definition: testing.c:37
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:1440
unsigned int share
Definition: testing.c:87
struct GNUNET_OS_Process * proc
Definition: testing.c:68
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:485
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:252
Nobody is allowed to do anything to the file.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int start_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:485
unsigned int n_shared_services
Definition: testing.c:128
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:717
Handle for interacting with ARM.
Definition: arm_api.c:102
#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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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:1482
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:230
void * tm_cls
Closure for the above callback.
Definition: testing.c:1630
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition: arm_api.c:604
#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:989
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1464
#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:1145
#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:153
char * main_binary
Binary to be executed during &#39;GNUNET_TESTING_peer_start&#39;.
Definition: testing.c:188
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:1166
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * section
Name of the section.
Definition: gnunet-config.c:33
Structure for holding service data.
Definition: testing.c:1610
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1409
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:148
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
unsigned int n_peers
Definition: testing.c:85
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:820
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:1670
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1029
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:175
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:215
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:205
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:249
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:579
char * cfgfile
Path to the configuration file for this peer.
Definition: testing.c:180
char * sname
Definition: testing.c:79
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:766
#define HIGH_PORT
Highest port used for GNUnet testing.
Definition: testing.c:59
When these flags are set, the child process will inherit stdout and stderr of the parent...
Definition: gnunet_os_lib.h:97
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.
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:453
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:534
unsigned int n_refs
Definition: testing.c:74
GNUNET_TESTING_TestMain tm
Callback to signal service startup.
Definition: testing.c:1620
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:76
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:1477
struct SharedService ** shared_services
Definition: testing.c:126
Open the file for writing.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:409
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:97
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define LOW_PORT
Lowest port used for GNUnet testing.
Definition: testing.c:52
struct SharedService * ss
Definition: testing.c:64
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:257
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:270
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:195
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1540
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:368
static void hostkeys_unload(struct GNUNET_TESTING_System *system)
Function to remove the loaded hostkeys.
Definition: testing.c:315
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:1765
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:163
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:335
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1000
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
configuration data
Definition: configuration.c:85
static void stop_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:513
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration template for the service.
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(int pipe_control, unsigned int std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:762
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:883
struct GNUNET_TESTING_Peer * peer
The peer in which the service is run.
Definition: testing.c:1625
struct SharedServiceInstance ** instances
Definition: testing.c:81
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:124
#define GNUNET_log(kind,...)
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:119
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a TCP or UDP port for a peer.
Definition: testing.c:576
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:1337
handle to a socket
Definition: network.c:52
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:240
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:1082
char * hostname
our hostname
Definition: testing.c:114
#define GNUNET_YES
Definition: gnunet_common.h:77
int fd
File handle on Unix-like systems.
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:744
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:210
struct GNUNET_PeerIdentity * id
The cached identity of this peer.
Definition: testing.c:221
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
struct SharedServiceInstance ** ss_instances
Definition: testing.c:223
char * tmppath
Prefix (i.e.
Definition: testing.c:103
int status
build status - to signal error while building a configuration
Definition: testing.c:771
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:242
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:1268
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1556
static void service_run_main(void *cls)
Callback to be called when SCHEDULER has been started.
Definition: testing.c:1640
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:672
Handle used to access files (and pipes).
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
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:1412
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:1441
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:912
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:225
char * trusted_ip
The trusted ip.
Definition: testing.c:109
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.