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 
46 #define LOW_PORT 12000
47 
53 #define HIGH_PORT 56000
54 
55 
57 {
58  struct SharedService *ss;
59 
60  char *cfg_fn;
61 
63 
64  char *unix_sock;
65 
66  char *port_str;
67 
68  unsigned int n_refs;
69 };
70 
71 struct SharedService
72 {
73  char *sname;
74 
76 
78 
79  unsigned int n_peers;
80 
81  unsigned int share;
82 
83  unsigned int n_instances;
84 };
85 
86 
92 {
97  char *tmppath;
98 
103  char *trusted_ip;
104 
108  char *hostname;
109 
114 
119 
121 
122  unsigned int n_shared_services;
123 
132  uint32_t reserved_ports[65536 / 32];
133 
142  uint32_t path_counter;
143 
147  uint32_t total_hostkeys;
148 
152  uint16_t lowport;
153 
157  uint16_t highport;
158 };
159 
160 
165 {
170 
174  char *cfgfile;
175 
182  char *main_binary;
183  char *args;
184 
190 
195 
200 
205 
209  void *cb_cls;
210 
216 
218 
224  uint16_t *ports;
225 
229  unsigned int nports;
230 
234  uint32_t key_number;
235 };
236 
237 
245 static int
247 {
248  uint64_t fs;
249  char *data_dir;
250  char *filename;
251  struct GNUNET_DISK_FileHandle *fd;
252 
253  GNUNET_assert (NULL == system->hostkeys_data);
255  GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
256  GNUNET_free (data_dir);
257 
258  if (GNUNET_YES != GNUNET_DISK_file_test (filename))
259  {
261  _ ("Hostkeys file not found: %s\n"),
262  filename);
263  GNUNET_free (filename);
264  return GNUNET_SYSERR;
265  }
266  /* Check hostkey file size, read entire thing into memory */
267  if (GNUNET_OK !=
268  GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
269  fs = 0;
270  if (0 == fs)
271  {
272  GNUNET_free (filename);
273  return GNUNET_SYSERR; /* File is empty */
274  }
275  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
276  {
278  _ ("Incorrect hostkey file format: %s\n"),
279  filename);
280  GNUNET_free (filename);
281  return GNUNET_SYSERR;
282  }
283  fd = GNUNET_DISK_file_open (filename,
286  if (NULL == fd)
287  {
289  GNUNET_free (filename);
290  return GNUNET_SYSERR;
291  }
292  GNUNET_free (filename);
293  system->hostkeys_data =
296  if (NULL == system->hostkeys_data)
297  return GNUNET_SYSERR;
299  return GNUNET_OK;
300 }
301 
302 
308 static void
310 {
311  GNUNET_break (NULL != system->hostkeys_data);
312  system->hostkeys_data = NULL;
313  GNUNET_DISK_file_unmap (system->map);
314  system->map = NULL;
315  system->hostkeys_data = NULL;
316  system->total_hostkeys = 0;
317 }
318 
319 
328 static void
329 cfg_copy_iterator (void *cls,
330  const char *section,
331  const char *option,
332  const char *value)
333 {
334  struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
335 
336  GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value);
337 }
338 
339 
361 struct GNUNET_TESTING_System *
363  const char *testdir,
364  const char *trusted_ip,
365  const char *hostname,
367  uint16_t lowport,
368  uint16_t highport)
369 {
370  struct GNUNET_TESTING_System *system;
371  struct GNUNET_TESTING_SharedService tss;
372  struct SharedService *ss;
373  unsigned int cnt;
374 
375  GNUNET_assert (NULL != testdir);
376  system = GNUNET_new (struct GNUNET_TESTING_System);
377  if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX)))
378  system->tmppath = GNUNET_DISK_mkdtemp (testdir);
379  else
380  system->tmppath = GNUNET_strdup (system->tmppath);
381  system->lowport = lowport;
382  system->highport = highport;
383  if (NULL == system->tmppath)
384  {
385  GNUNET_free (system);
386  return NULL;
387  }
388  if (NULL != trusted_ip)
389  system->trusted_ip = GNUNET_strdup (trusted_ip);
390  if (NULL != hostname)
391  system->hostname = GNUNET_strdup (hostname);
392  if (GNUNET_OK != hostkeys_load (system))
393  {
395  return NULL;
396  }
397  if (NULL == shared_services)
398  return system;
399  for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
400  {
401  tss = shared_services[cnt];
402  ss = GNUNET_new (struct SharedService);
403  ss->sname = GNUNET_strdup (tss.service);
406  ss->sname,
408  ss->cfg);
410  "TESTING",
412  ss->cfg);
414  "PATHS",
416  ss->cfg);
417  ss->share = tss.share;
419  system->n_shared_services,
420  ss);
421  }
422  return system;
423 }
424 
425 
446 struct GNUNET_TESTING_System *
448  const char *testdir,
449  const char *trusted_ip,
450  const char *hostname,
452 {
454  trusted_ip,
455  hostname,
456  shared_services,
457  LOW_PORT,
458  HIGH_PORT);
459 }
460 
461 
462 static void
464 {
465  if (NULL != i->cfg_fn)
466  {
467  (void) unlink (i->cfg_fn);
468  GNUNET_free (i->cfg_fn);
469  }
470  GNUNET_free (i->unix_sock);
471  GNUNET_free (i->port_str);
472  GNUNET_break (NULL == i->proc);
473  GNUNET_break (0 == i->n_refs);
474  GNUNET_free (i);
475 }
476 
477 
478 static int
480 {
481  char *binary;
482  char *libexec_binary;
483 
484  GNUNET_assert (NULL == i->proc);
485  GNUNET_assert (NULL != i->cfg_fn);
486  (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
487  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
488  GNUNET_free (binary);
490  NULL,
491  NULL,
492  NULL,
493  libexec_binary,
494  libexec_binary,
495  "-c",
496  i->cfg_fn,
497  NULL);
498  GNUNET_free (libexec_binary);
499  if (NULL == i->proc)
500  return GNUNET_SYSERR;
501  return GNUNET_OK;
502 }
503 
504 
505 static void
507 {
508  GNUNET_break (0 == i->n_refs);
511  "Killing shared service instance (%s) failed\n",
512  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  }
547  GNUNET_free (ss->instances);
549  GNUNET_free (ss->sname);
550  GNUNET_free (ss);
551  }
552  GNUNET_free (system->shared_services);
553  if (GNUNET_YES == remove_paths)
555  GNUNET_free (system->tmppath);
556  GNUNET_free (system->trusted_ip);
557  GNUNET_free (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  */hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
592  hint.ai_socktype = 0;
593  hint.ai_protocol = 0;
594  hint.ai_addrlen = 0;
595  hint.ai_addr = NULL;
596  hint.ai_canonname = NULL;
597  hint.ai_next = NULL;
598  hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
599  port_buckets = system->reserved_ports;
600  for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
601  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 =
628  GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
630  if (GNUNET_OK != bind_status)
631  break;
632  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
633  if (NULL == socket)
634  continue;
635  bind_status =
636  GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
638  if (GNUNET_OK != bind_status)
639  break;
640  }
641  port_buckets[index] |= (1U << pos); /* Set the port bit */
642  freeaddrinfo (ret);
643  if (GNUNET_OK == bind_status)
644  {
646  "Found a free port %u\n",
647  (unsigned int) open_port);
648  return open_port;
649  }
650  pos++;
651  }
652  }
653  return 0;
654 }
655 
656 
664 void
666  uint16_t port)
667 {
668  uint32_t *port_buckets;
669  uint16_t bucket;
670  uint16_t pos;
671 
672  port_buckets = system->reserved_ports;
673  bucket = port / 32;
674  pos = port % 32;
675  LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
676  if (0 == (port_buckets[bucket] & (1U << pos)))
677  {
678  GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
679  return;
680  }
681  port_buckets[bucket] &= ~(1U << pos);
682 }
683 
684 
704  uint32_t key_number,
705  struct GNUNET_PeerIdentity *id)
706 {
707  struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
708 
709  if ((NULL == id) || (NULL == system->hostkeys_data))
710  return NULL;
711  if (key_number >= system->total_hostkeys)
712  {
714  _ ("Key number %u does not exist\n"),
715  key_number);
716  return NULL;
717  }
718  private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
719  GNUNET_memcpy (private_key,
720  system->hostkeys_data
721  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
722  GNUNET_TESTING_HOSTKEYFILESIZE);
724  return private_key;
725 }
726 
727 
732 struct UpdateContext
733 {
738 
743 
747  char *gnunet_home;
748 
754  uint16_t *ports;
755 
759  unsigned int nports;
760 
764  int status;
765 };
766 
767 
778 static void
779 update_config (void *cls,
780  const char *section,
781  const char *option,
782  const char *value)
783 {
784  struct UpdateContext *uc = cls;
785  unsigned int ival;
786  char cval[12];
787  char uval[PATH_MAX];
788  char *single_variable;
789  char *per_host_variable;
790  unsigned long long num_per_host;
791  uint16_t new_port;
792 
793  if (GNUNET_OK != uc->status)
794  return;
795  if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
796  (0 == strcmp (option, "HOSTNAME"))))
797  return;
798  GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
799  GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
800  if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
801  {
802  if ((ival != 0) &&
804  "testing",
805  single_variable)))
806  {
807  new_port = GNUNET_TESTING_reserve_port (uc->system);
808  if (0 == new_port)
809  {
810  uc->status = GNUNET_SYSERR;
811  GNUNET_free (single_variable);
812  GNUNET_free (per_host_variable);
813  return;
814  }
815  GNUNET_snprintf (cval, sizeof(cval), "%u", new_port);
816  value = cval;
817  GNUNET_array_append (uc->ports, uc->nports, new_port);
818  }
819  else if ((ival != 0) &&
820  (GNUNET_YES ==
822  "testing",
823  single_variable)) &&
825  "testing",
826  per_host_variable,
827  &num_per_host))
828  {
829  /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
830  /* ival + ctx->fdnum % num_per_host); */
831  /* value = cval; */
832  GNUNET_break (0); /* FIXME */
833  }
834  }
835  if (0 == strcmp (option, "UNIXPATH"))
836  {
838  "testing",
839  single_variable))
840  {
841  GNUNET_snprintf (uval,
842  sizeof(uval),
843  "%s/%s.sock",
844  uc->gnunet_home,
845  section);
846  value = uval;
847  }
848  else if ((GNUNET_YES ==
850  "testing",
851  per_host_variable,
852  &num_per_host)) &&
853  (num_per_host > 0))
854  {
855  GNUNET_break (0); /* FIXME */
856  }
857  }
858  if (0 == strcmp (option, "HOSTNAME"))
859  {
860  value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
861  }
862  GNUNET_free (single_variable);
863  GNUNET_free (per_host_variable);
864  GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
865 }
866 
867 
875 static void
876 update_config_sections (void *cls, 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 ==
893  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
894  {
897  section,
898  "TESTING_IGNORE_KEYS",
899  &val));
900  ptr = val;
901  for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
902  ptr++;
903  if (0 == ikeys_cnt)
904  GNUNET_break (0);
905  else
906  {
907  ikeys = GNUNET_malloc ((sizeof(char *)) * ikeys_cnt);
908  ptr = val;
909  for (key = 0; key < ikeys_cnt; key++)
910  {
911  ikeys[key] = ptr;
912  ptr = strstr (ptr, ";");
913  GNUNET_assert (NULL != ptr); /* worked just before... */
914  *ptr = '\0';
915  ptr++;
916  }
917  }
918  }
919  if (0 != ikeys_cnt)
920  {
921  for (key = 0; key < ikeys_cnt; key++)
922  {
923  if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
924  break;
925  }
926  if ((key == ikeys_cnt) &&
927  (GNUNET_YES ==
928  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
929  {
931  section,
932  "PORT",
933  &ptr))
934  {
936  section,
937  "ADVERTISED_PORT",
938  ptr);
939  GNUNET_free (ptr);
940  }
941  }
942  for (key = 0; key < ikeys_cnt; key++)
943  {
944  if (NULL != strstr (ikeys[key], "ACCEPT_FROM"))
945  {
946  GNUNET_free (ikeys);
947  GNUNET_free (val);
948  return;
949  }
950  }
951  GNUNET_free (ikeys);
952  }
953  GNUNET_free (val);
954  ACCEPT_FROM_key = "ACCEPT_FROM";
955  if ((NULL != uc->system->trusted_ip) &&
956  (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
957  ACCEPT_FROM_key = "ACCEPT_FROM6";
959  section,
960  ACCEPT_FROM_key,
961  &orig_allowed_hosts))
962  {
963  orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
964  }
965  if (NULL == uc->system->trusted_ip)
966  allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
967  else
968  GNUNET_asprintf (&allowed_hosts,
969  "%s%s;",
970  orig_allowed_hosts,
971  uc->system->trusted_ip);
972  GNUNET_free (orig_allowed_hosts);
974  section,
975  ACCEPT_FROM_key,
976  allowed_hosts);
977  GNUNET_free (allowed_hosts);
978 }
979 
980 
981 static struct SharedServiceInstance *
983  struct SharedService *ss,
985 {
986  struct SharedServiceInstance *i;
987  struct GNUNET_CONFIGURATION_Handle *temp;
988  char *gnunet_home;
989  uint32_t port;
990 
991  ss->n_peers++;
992  if (((0 == ss->share) && (NULL == ss->instances)) ||
993  ((0 != ss->share) &&
994  (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
995  {
996  i = GNUNET_new (struct SharedServiceInstance);
997  i->ss = ss;
998  (void) GNUNET_asprintf (&gnunet_home,
999  "%s/shared/%s/%u",
1000  system->tmppath,
1001  ss->sname,
1002  ss->n_instances);
1003  (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
1004  port = GNUNET_TESTING_reserve_port (system);
1005  if (0 == port)
1006  {
1007  GNUNET_free (gnunet_home);
1009  return NULL;
1010  }
1012  temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1013  (void) GNUNET_asprintf (&i->port_str, "%u", port);
1014  (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1016  "PATHS",
1017  "GNUNET_HOME",
1018  gnunet_home);
1019  GNUNET_free (gnunet_home);
1021  ss->sname,
1022  "UNIXPATH",
1023  i->unix_sock);
1025  ss->sname,
1026  "PORT",
1027  i->port_str);
1029  {
1032  return NULL;
1033  }
1035  }
1036  else
1037  {
1038  GNUNET_assert (NULL != ss->instances);
1039  GNUNET_assert (0 < ss->n_instances);
1040  i = ss->instances[ss->n_instances - 1];
1041  }
1043  ss->sname,
1045  cfg);
1047  ss->sname,
1048  "UNIXPATH",
1049  i->unix_sock);
1050  GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1051  return i;
1052 }
1053 
1054 
1074 static int
1077  uint16_t **ports,
1078  unsigned int *nports)
1079 {
1080  struct UpdateContext uc;
1081  char *default_config;
1082 
1083  uc.system = system;
1084  uc.cfg = cfg;
1085  uc.status = GNUNET_OK;
1086  uc.ports = NULL;
1087  uc.nports = 0;
1089  "%s/%u",
1090  system->tmppath,
1091  system->path_counter++);
1092  GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1094  "PATHS",
1095  "DEFAULTCONFIG",
1096  default_config);
1097  GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
1098  GNUNET_free (default_config);
1100  "PATHS",
1101  "GNUNET_HOME",
1102  uc.gnunet_home);
1103  /* make PORTs and UNIXPATHs unique */
1105  /* allow connections to services from system trusted_ip host */
1107  /* enable loopback-based connections between peers */
1108  GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
1109  GNUNET_free (uc.gnunet_home);
1110  if ((NULL != ports) && (NULL != nports))
1111  {
1112  *ports = uc.ports;
1113  *nports = uc.nports;
1114  }
1115  else
1116  GNUNET_free (uc.ports);
1117  return uc.status;
1118 }
1119 
1120 
1137 int
1140 {
1141  return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1142 }
1143 
1144 
1158 struct GNUNET_TESTING_Peer *
1161  uint32_t key_number,
1162  struct GNUNET_PeerIdentity *id,
1163  char **emsg)
1164 {
1165  struct GNUNET_TESTING_Peer *peer;
1166  struct GNUNET_DISK_FileHandle *fd;
1167  char *hostkey_filename;
1168  char *config_filename;
1169  char *libexec_binary;
1170  char *emsg_;
1172  uint16_t *ports;
1173  struct SharedService *ss;
1174  struct SharedServiceInstance **ss_instances;
1175  unsigned int cnt;
1176  unsigned int nports;
1177 
1178  ports = NULL;
1179  nports = 0;
1180  ss_instances = NULL;
1181  if (NULL != emsg)
1182  *emsg = NULL;
1183  if (key_number >= system->total_hostkeys)
1184  {
1185  GNUNET_asprintf (
1186  &emsg_,
1187  _ (
1188  "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1189  (unsigned int) system->total_hostkeys);
1190  goto err_ret;
1191  }
1192  pk = NULL;
1193  if ((NULL != id) &&
1194  (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1195  {
1196  GNUNET_asprintf (&emsg_,
1197  _ ("Failed to initialize hostkey for peer %u\n"),
1198  (unsigned int) key_number);
1199  goto err_ret;
1200  }
1201  if (NULL != pk)
1202  GNUNET_free (pk);
1203  if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1204  {
1205  GNUNET_asprintf (
1206  &emsg_,
1207  _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
1208  goto err_ret;
1209  }
1210  /* Remove sections for shared services */
1211  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1212  {
1213  ss = system->shared_services[cnt];
1215  }
1216  if (GNUNET_OK !=
1217  GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
1218  {
1219  GNUNET_asprintf (&emsg_,
1220  _ ("Failed to create configuration for peer "
1221  "(not enough free ports?)\n"));
1222  goto err_ret;
1223  }
1226  "PEER",
1227  "PRIVATE_KEY",
1228  &hostkey_filename));
1229  fd = GNUNET_DISK_file_open (hostkey_filename,
1233  if (NULL == fd)
1234  {
1235  GNUNET_asprintf (&emsg_,
1236  _ ("Cannot open hostkey file `%s': %s\n"),
1237  hostkey_filename,
1238  strerror (errno));
1239  GNUNET_free (hostkey_filename);
1240  goto err_ret;
1241  }
1242  GNUNET_free (hostkey_filename);
1245  system->hostkeys_data
1246  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1247  GNUNET_TESTING_HOSTKEYFILESIZE))
1248  {
1249  GNUNET_asprintf (&emsg_,
1250  _ ("Failed to write hostkey file for peer %u: %s\n"),
1251  (unsigned int) key_number,
1252  strerror (errno));
1254  goto err_ret;
1255  }
1257  ss_instances = GNUNET_malloc (sizeof(struct SharedServiceInstance *)
1258  * system->n_shared_services);
1259  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1260  {
1261  ss = system->shared_services[cnt];
1262  ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1263  if (NULL == ss_instances[cnt])
1264  {
1265  emsg_ = GNUNET_strdup ("FIXME");
1266  goto err_ret;
1267  }
1268  }
1271  "PATHS",
1272  "DEFAULTCONFIG",
1273  &config_filename));
1274  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1275  {
1276  GNUNET_asprintf (&emsg_,
1277  _ (
1278  "Failed to write configuration file `%s' for peer %u: %s\n"),
1279  config_filename,
1280  (unsigned int) key_number,
1281  strerror (errno));
1282  GNUNET_free (config_filename);
1283  goto err_ret;
1284  }
1285  peer = GNUNET_new (struct GNUNET_TESTING_Peer);
1286  peer->ss_instances = ss_instances;
1287  peer->cfgfile = config_filename; /* Free in peer_destroy */
1288  peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1289  libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1290  if (GNUNET_SYSERR ==
1292  "arm",
1293  "PREFIX",
1294  &peer->main_binary))
1295  {
1296  /* No prefix */
1297  GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1298  peer->args = GNUNET_strdup ("");
1299  }
1300  else
1301  {
1302  peer->args = GNUNET_strdup (libexec_binary);
1303  }
1304  peer->system = system;
1305  peer->key_number = key_number;
1306  GNUNET_free (libexec_binary);
1307  peer->ports = ports; /* Free in peer_destroy */
1308  peer->nports = nports;
1309  return peer;
1310 
1311 err_ret:
1312  GNUNET_free (ss_instances);
1313  GNUNET_free (ports);
1314  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1315  if (NULL != emsg)
1316  *emsg = emsg_;
1317  else
1318  GNUNET_free (emsg_);
1319  return NULL;
1320 }
1321 
1322 
1329 void
1331  struct GNUNET_PeerIdentity *id)
1332 {
1333  if (NULL != peer->id)
1334  {
1335  GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1336  return;
1337  }
1338  peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1339  GNUNET_free_nz (
1340  GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
1341  GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1342 }
1343 
1344 
1351 int
1353 {
1354  struct SharedServiceInstance *i;
1355  unsigned int cnt;
1356 
1357  if (NULL != peer->main_process)
1358  {
1359  GNUNET_break (0);
1360  return GNUNET_SYSERR;
1361  }
1362  GNUNET_assert (NULL != peer->cfgfile);
1363  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1364  {
1365  i = peer->ss_instances[cnt];
1366  if ((0 == i->n_refs) &&
1368  return GNUNET_SYSERR;
1369  i->n_refs++;
1370  }
1371  peer->main_binary =
1373  peer->main_process =
1375  NULL,
1376  peer->main_binary,
1377  peer->args,
1378  "-c",
1379  peer->cfgfile,
1380  NULL);
1381  if (NULL == peer->main_process)
1382  {
1384  _ ("Failed to start `%s': %s\n"),
1385  peer->main_binary,
1386  strerror (errno));
1387  return GNUNET_SYSERR;
1388  }
1389  return GNUNET_OK;
1390 }
1391 
1392 
1400 int
1402 {
1403  struct SharedServiceInstance *i;
1404  unsigned int cnt;
1405 
1406  if (NULL == peer->main_process)
1407  {
1408  GNUNET_break (0);
1409  return GNUNET_SYSERR;
1410  }
1412  return GNUNET_SYSERR;
1413  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1414  {
1415  i = peer->ss_instances[cnt];
1416  GNUNET_assert (0 != i->n_refs);
1417  i->n_refs--;
1418  if (0 == i->n_refs)
1420  }
1421  return GNUNET_OK;
1422 }
1423 
1424 
1432 int
1434 {
1435  int ret;
1436 
1437  if (NULL == peer->main_process)
1438  {
1439  GNUNET_break (0);
1440  return GNUNET_SYSERR;
1441  }
1442  ret = GNUNET_OS_process_wait (peer->main_process);
1444  peer->main_process = NULL;
1445  return ret;
1446 }
1447 
1448 
1455 int
1457 {
1459  return GNUNET_SYSERR;
1461  return GNUNET_SYSERR;
1462  return GNUNET_OK;
1463 }
1464 
1465 
1473 static void
1474 disconn_status (void *cls, int connected)
1475 {
1476  struct GNUNET_TESTING_Peer *peer = cls;
1477 
1478  if (GNUNET_SYSERR == connected)
1479  {
1480  peer->cb (peer->cb_cls, peer, connected);
1481  return;
1482  }
1483  if (GNUNET_YES == connected)
1484  {
1486  return;
1487  }
1489  GNUNET_ARM_disconnect (peer->ah);
1490  peer->ah = NULL;
1491  peer->cb (peer->cb_cls, peer, GNUNET_YES);
1492 }
1493 
1494 
1506 int
1509  void *cb_cls)
1510 {
1511  if (NULL == peer->main_process)
1512  return GNUNET_SYSERR;
1513  peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer);
1514  if (NULL == peer->ah)
1515  return GNUNET_SYSERR;
1516  peer->cb = cb;
1517  peer->cb_cls = cb_cls;
1518  return GNUNET_OK;
1519 }
1520 
1521 
1531 void
1533 {
1534  GNUNET_assert (NULL != peer->ah);
1535  GNUNET_ARM_disconnect (peer->ah);
1536  peer->ah = NULL;
1537 }
1538 
1539 
1547 void
1549 {
1550  unsigned int cnt;
1551 
1552  if (NULL != peer->main_process)
1553  GNUNET_TESTING_peer_stop (peer);
1554  if (NULL != peer->ah)
1555  GNUNET_ARM_disconnect (peer->ah);
1556  GNUNET_free (peer->cfgfile);
1557  if (NULL != peer->cfg)
1559  GNUNET_free (peer->main_binary);
1560  GNUNET_free (peer->args);
1561  GNUNET_free (peer->id);
1562  GNUNET_free (peer->ss_instances);
1563  if (NULL != peer->ports)
1564  {
1565  for (cnt = 0; cnt < peer->nports; cnt++)
1566  GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]);
1567  GNUNET_free (peer->ports);
1568  }
1569  GNUNET_free (peer);
1570 }
1571 
1572 
1589 int
1590 GNUNET_TESTING_peer_run (const char *testdir,
1591  const char *cfgfilename,
1593  void *tm_cls)
1594 {
1595  return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
1596 }
1597 
1598 
1603 {
1608 
1613 
1618 
1622  void *tm_cls;
1623 };
1624 
1625 
1631 static void
1632 service_run_main (void *cls)
1633 {
1634  struct ServiceContext *sc = cls;
1635 
1636  sc->tm (sc->tm_cls, sc->cfg, sc->peer);
1637 }
1638 
1639 
1661 int
1662 GNUNET_TESTING_service_run (const char *testdir,
1663  const char *service_name,
1664  const char *cfgfilename,
1666  void *tm_cls)
1667 {
1668  struct ServiceContext sc;
1669  struct GNUNET_TESTING_System *system;
1670  struct GNUNET_TESTING_Peer *peer;
1672  char *binary;
1673  char *libexec_binary;
1674 
1675  GNUNET_log_setup (testdir, "WARNING", NULL);
1676  system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1677  if (NULL == system)
1678  return 1;
1679  cfg = GNUNET_CONFIGURATION_create ();
1680  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1681  {
1683  _ ("Failed to load configuration from %s\n"),
1684  cfgfilename);
1687  return 1;
1688  }
1689  peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
1690  if (NULL == peer)
1691  {
1693  hostkeys_unload (system);
1695  return 1;
1696  }
1697  GNUNET_free (peer->main_binary);
1698  GNUNET_free (peer->args);
1699  GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1700  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1701  if (GNUNET_SYSERR ==
1703  service_name,
1704  "PREFIX",
1705  &peer->main_binary))
1706  {
1707  /* No prefix */
1708  GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1709  peer->args = GNUNET_strdup ("");
1710  }
1711  else
1712  peer->args = GNUNET_strdup (libexec_binary);
1713 
1714  GNUNET_free (libexec_binary);
1715  GNUNET_free (binary);
1716  if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
1717  {
1721  return 1;
1722  }
1723  sc.cfg = cfg;
1724  sc.tm = tm;
1725  sc.tm_cls = tm_cls;
1726  sc.peer = peer;
1727  GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1728  if ((NULL != peer->main_process) &&
1729  (GNUNET_OK != GNUNET_TESTING_peer_stop (peer)))
1730  {
1734  return 1;
1735  }
1739  return 0;
1740 }
1741 
1742 
1756 char *
1758 {
1759  size_t slen = strlen (argv0) + 1;
1760  char sbuf[slen];
1761  char *ret;
1762  char *dot;
1763 
1764  GNUNET_memcpy (sbuf, argv0, slen);
1765  ret = strrchr (sbuf, '_');
1766  if (NULL == ret)
1767  return NULL;
1768  ret++; /* skip underscore */
1769  dot = strchr (ret, '.');
1770  if (NULL != dot)
1771  *dot = '\0';
1772  return GNUNET_strdup (ret);
1773 }
1774 
1775 
1776 /* end of testing.c */
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration we are building.
Definition: testing.c:742
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:779
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.
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:747
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:1507
Create file if it doesn&#39;t exist.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer in which the service is run.
Definition: testing.c:1607
struct GNUNET_OS_Process * GNUNET_OS_start_process(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:678
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:77
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1280
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
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
The structure for identifying a shared service.
#define AI_NUMERICSERV
AI_NUMERICSERV not defined in windows.
Definition: platform.h:231
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:463
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:229
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:152
char * gnunet_home
The customized service home path for this peer.
Definition: testing.c:747
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:1352
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:164
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:1590
struct GNUNET_ARM_Handle * ah
The handle to the peer&#39;s ARM service.
Definition: testing.c:194
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:754
unsigned int n_instances
Definition: testing.c:83
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
Definition: testing.c:132
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:703
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.
#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:1375
unsigned int share
Definition: testing.c:81
struct GNUNET_OS_Process * proc
Definition: testing.c:62
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:246
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:479
unsigned int n_shared_services
Definition: testing.c:122
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:720
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_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:1474
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:224
void * tm_cls
Closure for the above callback.
Definition: testing.c:1622
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:982
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1456
#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:1138
#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:147
char * main_binary
Binary to be executed during &#39;GNUNET_TESTING_peer_start&#39;.
Definition: testing.c:182
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:1159
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * section
Name of the section.
Definition: gnunet-config.c:33
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
Structure for holding service data.
Definition: testing.c:1602
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1401
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:142
unsigned int n_peers
Definition: testing.c:79
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:1662
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1028
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:169
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:209
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:199
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:253
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:174
char * sname
Definition: testing.c:73
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:759
#define HIGH_PORT
Highest port used for GNUnet testing.
Definition: testing.c:53
When these flags are set, the child process will inherit stdout and stderr of the parent...
Definition: gnunet_os_lib.h:97
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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:447
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:527
#define GNUNET_free_nz(ptr)
Wrapper around free.
unsigned int n_refs
Definition: testing.c:68
GNUNET_TESTING_TestMain tm
Callback to signal service startup.
Definition: testing.c:1612
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
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:1412
struct SharedService ** shared_services
Definition: testing.c:120
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:91
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define LOW_PORT
Lowest port used for GNUnet testing.
Definition: testing.c:46
struct SharedService * ss
Definition: testing.c:58
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:193
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:189
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1532
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:362
static void hostkeys_unload(struct GNUNET_TESTING_System *system)
Function to remove the loaded hostkeys.
Definition: testing.c:309
Private ECC key encoded for transmission.
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:1757
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:157
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:329
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:983
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
configuration data
Definition: configuration.c:84
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static void stop_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:506
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:876
struct GNUNET_TESTING_Peer * peer
The peer in which the service is run.
Definition: testing.c:1617
struct SharedServiceInstance ** instances
Definition: testing.c:75
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:118
#define GNUNET_log(kind,...)
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:113
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:1330
handle to a socket
Definition: network.c:52
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:234
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:1075
char * hostname
our hostname
Definition: testing.c:108
int fd
File handle on Unix-like systems.
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:737
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:204
struct GNUNET_PeerIdentity * id
The cached identity of this peer.
Definition: testing.c:215
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
struct SharedServiceInstance ** ss_instances
Definition: testing.c:217
char * tmppath
Prefix (i.e.
Definition: testing.c:97
int status
build status - to signal error while building a configuration
Definition: testing.c:764
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:246
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:1203
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1548
static void service_run_main(void *cls)
Callback to be called when SCHEDULER has been started.
Definition: testing.c:1632
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:665
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:1347
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:1433
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:103
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.