GNUnet  0.10.x
testing.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2008, 2009, 2012 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
32 #include "platform.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_arm_service.h"
35 #include "gnunet_testing_lib.h"
36 
37 #define LOG(kind, ...) 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  struct SharedService *ss;
64 
65  char *cfg_fn;
66 
68 
69  char *unix_sock;
70 
71  char *port_str;
72 
73  unsigned int n_refs;
74 };
75 
76 struct SharedService {
77  char *sname;
78 
80 
82 
83  unsigned int n_peers;
84 
85  unsigned int share;
86 
87  unsigned int n_instances;
88 };
89 
90 
100  char *tmppath;
101 
106  char *trusted_ip;
107 
111  char *hostname;
112 
117 
122 
124 
125  unsigned int n_shared_services;
126 
135  uint32_t reserved_ports[65536 / 32];
136 
145  uint32_t path_counter;
146 
150  uint32_t total_hostkeys;
151 
155  uint16_t lowport;
156 
160  uint16_t highport;
161 };
162 
163 
172 
176  char *cfgfile;
177 
184  char *main_binary;
185  char *args;
186 
192 
197 
202 
207 
211  void *cb_cls;
212 
218 
220 
226  uint16_t *ports;
227 
231  unsigned int nports;
232 
236  uint32_t key_number;
237 };
238 
239 
247 static int
249 {
250  uint64_t fs;
251  char *data_dir;
252  char *filename;
253  struct GNUNET_DISK_FileHandle *fd;
254 
255  GNUNET_assert(NULL == system->hostkeys_data);
257  GNUNET_asprintf(&filename, "%s/testing_hostkeys.ecc", data_dir);
258  GNUNET_free(data_dir);
259 
260  if (GNUNET_YES != GNUNET_DISK_file_test(filename))
261  {
263  _("Hostkeys file not found: %s\n"),
264  filename);
265  GNUNET_free(filename);
266  return GNUNET_SYSERR;
267  }
268  /* Check hostkey file size, read entire thing into memory */
269  if (GNUNET_OK !=
271  fs = 0;
272  if (0 == fs)
273  {
274  GNUNET_free(filename);
275  return GNUNET_SYSERR; /* File is empty */
276  }
277  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
278  {
280  _("Incorrect hostkey file format: %s\n"),
281  filename);
282  GNUNET_free(filename);
283  return GNUNET_SYSERR;
284  }
285  fd = GNUNET_DISK_file_open(filename,
288  if (NULL == fd)
289  {
291  GNUNET_free(filename);
292  return GNUNET_SYSERR;
293  }
294  GNUNET_free(filename);
295  system->hostkeys_data =
298  if (NULL == system->hostkeys_data)
299  return GNUNET_SYSERR;
301  return GNUNET_OK;
302 }
303 
304 
310 static void
312 {
313  GNUNET_break(NULL != system->hostkeys_data);
314  system->hostkeys_data = NULL;
315  GNUNET_DISK_file_unmap(system->map);
316  system->map = NULL;
317  system->hostkeys_data = NULL;
318  system->total_hostkeys = 0;
319 }
320 
321 
330 static void
332  const char *section,
333  const char *option,
334  const char *value)
335 {
336  struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
337 
338  GNUNET_CONFIGURATION_set_value_string(cfg2, section, option, value);
339 }
340 
341 
363 struct GNUNET_TESTING_System *
365  const char *testdir,
366  const char *trusted_ip,
367  const char *hostname,
369  uint16_t lowport,
370  uint16_t highport)
371 {
372  struct GNUNET_TESTING_System *system;
373  struct GNUNET_TESTING_SharedService tss;
374  struct SharedService *ss;
375  unsigned int cnt;
376 
377  GNUNET_assert(NULL != testdir);
378  system = GNUNET_new(struct GNUNET_TESTING_System);
379  if (NULL == (system->tmppath = getenv(GNUNET_TESTING_PREFIX)))
380  system->tmppath = GNUNET_DISK_mkdtemp(testdir);
381  else
382  system->tmppath = GNUNET_strdup(system->tmppath);
383  system->lowport = lowport;
384  system->highport = highport;
385  if (NULL == system->tmppath)
386  {
387  GNUNET_free(system);
388  return NULL;
389  }
390  if (NULL != trusted_ip)
391  system->trusted_ip = GNUNET_strdup(trusted_ip);
392  if (NULL != hostname)
393  system->hostname = GNUNET_strdup(hostname);
394  if (GNUNET_OK != hostkeys_load(system))
395  {
397  return NULL;
398  }
399  if (NULL == shared_services)
400  return system;
401  for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
402  {
403  tss = shared_services[cnt];
404  ss = GNUNET_new(struct SharedService);
405  ss->sname = GNUNET_strdup(tss.service);
408  ss->sname,
410  ss->cfg);
412  "TESTING",
414  ss->cfg);
416  "PATHS",
418  ss->cfg);
419  ss->share = tss.share;
421  system->n_shared_services,
422  ss);
423  }
424  return system;
425 }
426 
427 
448 struct GNUNET_TESTING_System *
450  const char *testdir,
451  const char *trusted_ip,
452  const char *hostname,
454 {
456  trusted_ip,
457  hostname,
458  shared_services,
459  LOW_PORT,
460  HIGH_PORT);
461 }
462 
463 
464 static void
466 {
467  if (NULL != i->cfg_fn)
468  {
469  (void)unlink(i->cfg_fn);
470  GNUNET_free(i->cfg_fn);
471  }
474  GNUNET_break(NULL == i->proc);
475  GNUNET_break(0 == i->n_refs);
476  GNUNET_free(i);
477 }
478 
479 
480 static int
482 {
483  char *binary;
484  char *libexec_binary;
485 
486  GNUNET_assert(NULL == i->proc);
487  GNUNET_assert(NULL != i->cfg_fn);
488  (void)GNUNET_asprintf(&binary, "gnunet-service-%s", i->ss->sname);
489  libexec_binary = GNUNET_OS_get_libexec_binary_path(binary);
490  GNUNET_free(binary);
493  NULL,
494  NULL,
495  NULL,
496  libexec_binary,
497  libexec_binary,
498  "-c",
499  i->cfg_fn,
500  NULL);
501  GNUNET_free(libexec_binary);
502  if (NULL == i->proc)
503  return GNUNET_SYSERR;
504  return GNUNET_OK;
505 }
506 
507 
508 static void
510 {
511  GNUNET_break(0 == i->n_refs);
514  "Killing shared service instance (%s) failed\n",
515  i->ss->sname);
516  (void)GNUNET_OS_process_wait(i->proc);
518  i->proc = NULL;
519 }
520 
521 
529 void
531  int remove_paths)
532 {
533  struct SharedService *ss;
534  struct SharedServiceInstance *i;
535  unsigned int ss_cnt;
536  unsigned int i_cnt;
537 
538  if (NULL != system->hostkeys_data)
539  hostkeys_unload(system);
540  for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
541  {
542  ss = system->shared_services[ss_cnt];
543  for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
544  {
545  i = ss->instances[i_cnt];
546  if (NULL != i->proc)
549  }
552  GNUNET_free(ss->sname);
553  GNUNET_free(ss);
554  }
556  if (GNUNET_YES == remove_paths)
558  GNUNET_free(system->tmppath);
561  GNUNET_free(system);
562 }
563 
564 
571 uint16_t
573 {
574  struct GNUNET_NETWORK_Handle *socket;
575  struct addrinfo hint;
576  struct addrinfo *ret;
577  struct addrinfo *ai;
578  uint32_t *port_buckets;
579  char *open_port_str;
580  int bind_status;
581  uint32_t xor_image;
582  uint16_t index;
583  uint16_t open_port;
584  uint16_t pos;
585 
586  /*
587  FIXME: Instead of using getaddrinfo we should try to determine the port
588  status by the following heurestics.
589 
590  On systems which support both IPv4 and IPv6, only ports open on both
591  address families are considered open.
592  On system with either IPv4 or IPv6. A port is considered open if it's
593  open in the respective address family
594  */
595  hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
596  hint.ai_socktype = 0;
597  hint.ai_protocol = 0;
598  hint.ai_addrlen = 0;
599  hint.ai_addr = NULL;
600  hint.ai_canonname = NULL;
601  hint.ai_next = NULL;
602  hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
603  port_buckets = system->reserved_ports;
604  for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
605  index++)
606  {
607  xor_image = (UINT32_MAX ^ port_buckets[index]);
608  if (0 == xor_image) /* Ports in the bucket are full */
609  continue;
610  pos = system->lowport % 32;
611  while (pos < 32)
612  {
613  if (0 == ((xor_image >> pos) & 1U))
614  {
615  pos++;
616  continue;
617  }
618  open_port = (index * 32) + pos;
619  if (open_port >= system->highport)
620  return 0;
621  GNUNET_asprintf(&open_port_str, "%u", (unsigned int)open_port);
622  ret = NULL;
623  GNUNET_assert(0 == getaddrinfo(NULL, open_port_str, &hint, &ret));
624  GNUNET_free(open_port_str);
625  bind_status = GNUNET_NO;
626  for (ai = ret; NULL != ai; ai = ai->ai_next)
627  {
628  socket = GNUNET_NETWORK_socket_create(ai->ai_family, SOCK_STREAM, 0);
629  if (NULL == socket)
630  continue;
631  bind_status =
632  GNUNET_NETWORK_socket_bind(socket, ai->ai_addr, ai->ai_addrlen);
634  if (GNUNET_OK != bind_status)
635  break;
636  socket = GNUNET_NETWORK_socket_create(ai->ai_family, SOCK_DGRAM, 0);
637  if (NULL == socket)
638  continue;
639  bind_status =
640  GNUNET_NETWORK_socket_bind(socket, ai->ai_addr, ai->ai_addrlen);
642  if (GNUNET_OK != bind_status)
643  break;
644  }
645  port_buckets[index] |= (1U << pos); /* Set the port bit */
646  freeaddrinfo(ret);
647  if (GNUNET_OK == bind_status)
648  {
650  "Found a free port %u\n",
651  (unsigned int)open_port);
652  return open_port;
653  }
654  pos++;
655  }
656  }
657  return 0;
658 }
659 
660 
668 void
670  uint16_t port)
671 {
672  uint32_t *port_buckets;
673  uint16_t bucket;
674  uint16_t pos;
675 
676  port_buckets = system->reserved_ports;
677  bucket = port / 32;
678  pos = port % 32;
679  LOG(GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
680  if (0 == (port_buckets[bucket] & (1U << pos)))
681  {
682  GNUNET_break(0); /* Port was not reserved by us using reserve_port() */
683  return;
684  }
685  port_buckets[bucket] &= ~(1U << pos);
686 }
687 
688 
708  uint32_t key_number,
709  struct GNUNET_PeerIdentity *id)
710 {
711  struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
712 
713  if ((NULL == id) || (NULL == system->hostkeys_data))
714  return NULL;
715  if (key_number >= system->total_hostkeys)
716  {
718  _("Key number %u does not exist\n"),
719  key_number);
720  return NULL;
721  }
722  private_key = GNUNET_new(struct GNUNET_CRYPTO_EddsaPrivateKey);
723  GNUNET_memcpy(private_key,
724  system->hostkeys_data +
725  (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
726  GNUNET_TESTING_HOSTKEYFILESIZE);
728  return private_key;
729 }
730 
731 
736 struct UpdateContext {
741 
746 
750  char *gnunet_home;
751 
757  uint16_t *ports;
758 
762  unsigned int nports;
763 
767  int status;
768 };
769 
770 
781 static void
782 update_config(void *cls,
783  const char *section,
784  const char *option,
785  const char *value)
786 {
787  struct UpdateContext *uc = cls;
788  unsigned int ival;
789  char cval[12];
790  char uval[PATH_MAX];
791  char *single_variable;
792  char *per_host_variable;
793  unsigned long long num_per_host;
794  uint16_t new_port;
795 
796  if (GNUNET_OK != uc->status)
797  return;
798  if (!((0 == strcmp(option, "PORT")) || (0 == strcmp(option, "UNIXPATH")) ||
799  (0 == strcmp(option, "HOSTNAME"))))
800  return;
801  GNUNET_asprintf(&single_variable, "single_%s_per_host", section);
802  GNUNET_asprintf(&per_host_variable, "num_%s_per_host", section);
803  if ((0 == strcmp(option, "PORT")) && (1 == sscanf(value, "%u", &ival)))
804  {
805  if ((ival != 0) &&
807  "testing",
808  single_variable)))
809  {
810  new_port = GNUNET_TESTING_reserve_port(uc->system);
811  if (0 == new_port)
812  {
813  uc->status = GNUNET_SYSERR;
814  GNUNET_free(single_variable);
815  GNUNET_free(per_host_variable);
816  return;
817  }
818  GNUNET_snprintf(cval, sizeof(cval), "%u", new_port);
819  value = cval;
820  GNUNET_array_append(uc->ports, uc->nports, new_port);
821  }
822  else if ((ival != 0) &&
823  (GNUNET_YES ==
825  "testing",
826  single_variable)) &&
828  "testing",
829  per_host_variable,
830  &num_per_host))
831  {
832  /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
833  /* ival + ctx->fdnum % num_per_host); */
834  /* value = cval; */
835  GNUNET_break(0); /* FIXME */
836  }
837  }
838  if (0 == strcmp(option, "UNIXPATH"))
839  {
841  "testing",
842  single_variable))
843  {
844  GNUNET_snprintf(uval,
845  sizeof(uval),
846  "%s/%s.sock",
847  uc->gnunet_home,
848  section);
849  value = uval;
850  }
851  else if ((GNUNET_YES ==
853  "testing",
854  per_host_variable,
855  &num_per_host)) &&
856  (num_per_host > 0))
857  {
858  GNUNET_break(0); /* FIXME */
859  }
860  }
861  if (0 == strcmp(option, "HOSTNAME"))
862  {
863  value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
864  }
865  GNUNET_free(single_variable);
866  GNUNET_free(per_host_variable);
867  GNUNET_CONFIGURATION_set_value_string(uc->cfg, section, option, value);
868 }
869 
870 
878 static void
879 update_config_sections(void *cls, const char *section)
880 {
881  struct UpdateContext *uc = cls;
882  char **ikeys;
883  char *val;
884  char *ptr;
885  char *orig_allowed_hosts;
886  char *allowed_hosts;
887  char *ACCEPT_FROM_key;
888  uint16_t ikeys_cnt;
889  uint16_t key;
890 
891  ikeys_cnt = 0;
892  val = NULL;
893  /* Ignore certain options from sections. See
894  https://gnunet.org/bugs/view.php?id=2476 */
895  if (GNUNET_YES ==
896  GNUNET_CONFIGURATION_have_value(uc->cfg, section, "TESTING_IGNORE_KEYS"))
897  {
900  section,
901  "TESTING_IGNORE_KEYS",
902  &val));
903  ptr = val;
904  for (ikeys_cnt = 0; NULL != (ptr = strstr(ptr, ";")); ikeys_cnt++)
905  ptr++;
906  if (0 == ikeys_cnt)
907  GNUNET_break(0);
908  else
909  {
910  ikeys = GNUNET_malloc((sizeof(char *)) * ikeys_cnt);
911  ptr = val;
912  for (key = 0; key < ikeys_cnt; key++)
913  {
914  ikeys[key] = ptr;
915  ptr = strstr(ptr, ";");
916  GNUNET_assert(NULL != ptr); /* worked just before... */
917  *ptr = '\0';
918  ptr++;
919  }
920  }
921  }
922  if (0 != ikeys_cnt)
923  {
924  for (key = 0; key < ikeys_cnt; key++)
925  {
926  if (NULL != strstr(ikeys[key], "ADVERTISED_PORT"))
927  break;
928  }
929  if ((key == ikeys_cnt) &&
930  (GNUNET_YES ==
931  GNUNET_CONFIGURATION_have_value(uc->cfg, section, "ADVERTISED_PORT")))
932  {
934  section,
935  "PORT",
936  &ptr))
937  {
939  section,
940  "ADVERTISED_PORT",
941  ptr);
942  GNUNET_free(ptr);
943  }
944  }
945  for (key = 0; key < ikeys_cnt; key++)
946  {
947  if (NULL != strstr(ikeys[key], "ACCEPT_FROM"))
948  {
949  GNUNET_free(ikeys);
950  GNUNET_free(val);
951  return;
952  }
953  }
954  GNUNET_free(ikeys);
955  }
957  ACCEPT_FROM_key = "ACCEPT_FROM";
958  if ((NULL != uc->system->trusted_ip) &&
959  (NULL != strstr(uc->system->trusted_ip, ":"))) /* IPv6 in use */
960  ACCEPT_FROM_key = "ACCEPT_FROM6";
962  section,
963  ACCEPT_FROM_key,
964  &orig_allowed_hosts))
965  {
966  orig_allowed_hosts = GNUNET_strdup("127.0.0.1;");
967  }
968  if (NULL == uc->system->trusted_ip)
969  allowed_hosts = GNUNET_strdup(orig_allowed_hosts);
970  else
971  GNUNET_asprintf(&allowed_hosts,
972  "%s%s;",
973  orig_allowed_hosts,
974  uc->system->trusted_ip);
975  GNUNET_free(orig_allowed_hosts);
977  section,
978  ACCEPT_FROM_key,
979  allowed_hosts);
980  GNUNET_free(allowed_hosts);
981 }
982 
983 
984 static struct SharedServiceInstance *
986  struct SharedService *ss,
988 {
989  struct SharedServiceInstance *i;
990  struct GNUNET_CONFIGURATION_Handle *temp;
991  char *gnunet_home;
992  uint32_t port;
993 
994  ss->n_peers++;
995  if (((0 == ss->share) && (NULL == ss->instances)) ||
996  ((0 != ss->share) &&
997  (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
998  {
999  i = GNUNET_new(struct SharedServiceInstance);
1000  i->ss = ss;
1001  (void)GNUNET_asprintf(&gnunet_home,
1002  "%s/shared/%s/%u",
1003  system->tmppath,
1004  ss->sname,
1005  ss->n_instances);
1006  (void)GNUNET_asprintf(&i->unix_sock, "%s/sock", gnunet_home);
1007  port = GNUNET_TESTING_reserve_port(system);
1008  if (0 == port)
1009  {
1010  GNUNET_free(gnunet_home);
1012  return NULL;
1013  }
1015  temp = GNUNET_CONFIGURATION_dup(ss->cfg);
1016  (void)GNUNET_asprintf(&i->port_str, "%u", port);
1017  (void)GNUNET_asprintf(&i->cfg_fn, "%s/config", gnunet_home);
1019  "PATHS",
1020  "GNUNET_HOME",
1021  gnunet_home);
1022  GNUNET_free(gnunet_home);
1024  ss->sname,
1025  "UNIXPATH",
1026  i->unix_sock);
1028  ss->sname,
1029  "PORT",
1030  i->port_str);
1032  {
1035  return NULL;
1036  }
1038  }
1039  else
1040  {
1041  GNUNET_assert(NULL != ss->instances);
1042  GNUNET_assert(0 < ss->n_instances);
1043  i = ss->instances[ss->n_instances - 1];
1044  }
1046  ss->sname,
1048  cfg);
1050  ss->sname,
1051  "UNIXPATH",
1052  i->unix_sock);
1054  return i;
1055 }
1056 
1057 
1077 static int
1080  uint16_t **ports,
1081  unsigned int *nports)
1082 {
1083  struct UpdateContext uc;
1084  char *default_config;
1085 
1086  uc.system = system;
1087  uc.cfg = cfg;
1088  uc.status = GNUNET_OK;
1089  uc.ports = NULL;
1090  uc.nports = 0;
1092  "%s/%u",
1093  system->tmppath,
1094  system->path_counter++);
1095  GNUNET_asprintf(&default_config, "%s/config", uc.gnunet_home);
1097  "PATHS",
1098  "DEFAULTCONFIG",
1099  default_config);
1100  GNUNET_CONFIGURATION_set_value_string(cfg, "arm", "CONFIG", default_config);
1101  GNUNET_free(default_config);
1103  "PATHS",
1104  "GNUNET_HOME",
1105  uc.gnunet_home);
1106  /* make PORTs and UNIXPATHs unique */
1108  /* allow connections to services from system trusted_ip host */
1110  /* enable loopback-based connections between peers */
1111  GNUNET_CONFIGURATION_set_value_string(cfg, "nat", "USE_LOCALADDR", "YES");
1113  if ((NULL != ports) && (NULL != nports))
1114  {
1115  *ports = uc.ports;
1116  *nports = uc.nports;
1117  }
1118  else
1120  return uc.status;
1121 }
1122 
1123 
1140 int
1143 {
1144  return GNUNET_TESTING_configuration_create_(system, cfg, NULL, NULL);
1145 }
1146 
1147 
1161 struct GNUNET_TESTING_Peer *
1164  uint32_t key_number,
1165  struct GNUNET_PeerIdentity *id,
1166  char **emsg)
1167 {
1168  struct GNUNET_TESTING_Peer *peer;
1169  struct GNUNET_DISK_FileHandle *fd;
1170  char *hostkey_filename;
1171  char *config_filename;
1172  char *libexec_binary;
1173  char *emsg_;
1175  uint16_t *ports;
1176  struct SharedService *ss;
1177  struct SharedServiceInstance **ss_instances;
1178  unsigned int cnt;
1179  unsigned int nports;
1180 
1181  ports = NULL;
1182  nports = 0;
1183  ss_instances = NULL;
1184  if (NULL != emsg)
1185  *emsg = NULL;
1186  if (key_number >= system->total_hostkeys)
1187  {
1189  &emsg_,
1190  _(
1191  "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1192  (unsigned int)system->total_hostkeys);
1193  goto err_ret;
1194  }
1195  pk = NULL;
1196  if ((NULL != id) &&
1197  (NULL == (pk = GNUNET_TESTING_hostkey_get(system, key_number, id))))
1198  {
1199  GNUNET_asprintf(&emsg_,
1200  _("Failed to initialize hostkey for peer %u\n"),
1201  (unsigned int)key_number);
1202  goto err_ret;
1203  }
1204  if (NULL != pk)
1205  GNUNET_free(pk);
1206  if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, "PEER", "PRIVATE_KEY"))
1207  {
1209  &emsg_,
1210  _("PRIVATE_KEY option in PEER section missing in configuration\n"));
1211  goto err_ret;
1212  }
1213  /* Remove sections for shared services */
1214  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1215  {
1216  ss = system->shared_services[cnt];
1218  }
1219  if (GNUNET_OK !=
1220  GNUNET_TESTING_configuration_create_(system, cfg, &ports, &nports))
1221  {
1222  GNUNET_asprintf(&emsg_,
1223  _("Failed to create configuration for peer "
1224  "(not enough free ports?)\n"));
1225  goto err_ret;
1226  }
1229  "PEER",
1230  "PRIVATE_KEY",
1231  &hostkey_filename));
1232  fd = GNUNET_DISK_file_open(hostkey_filename,
1236  if (NULL == fd)
1237  {
1238  GNUNET_asprintf(&emsg_,
1239  _("Cannot open hostkey file `%s': %s\n"),
1240  hostkey_filename,
1241  strerror(errno));
1242  GNUNET_free(hostkey_filename);
1243  goto err_ret;
1244  }
1245  GNUNET_free(hostkey_filename);
1248  system->hostkeys_data +
1249  (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1250  GNUNET_TESTING_HOSTKEYFILESIZE))
1251  {
1252  GNUNET_asprintf(&emsg_,
1253  _("Failed to write hostkey file for peer %u: %s\n"),
1254  (unsigned int)key_number,
1255  strerror(errno));
1257  goto err_ret;
1258  }
1260  ss_instances = GNUNET_malloc(sizeof(struct SharedServiceInstance *) *
1261  system->n_shared_services);
1262  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1263  {
1264  ss = system->shared_services[cnt];
1265  ss_instances[cnt] = associate_shared_service(system, ss, cfg);
1266  if (NULL == ss_instances[cnt])
1267  {
1268  emsg_ = GNUNET_strdup("FIXME");
1269  goto err_ret;
1270  }
1271  }
1274  "PATHS",
1275  "DEFAULTCONFIG",
1276  &config_filename));
1277  if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config_filename))
1278  {
1279  GNUNET_asprintf(&emsg_,
1280  _(
1281  "Failed to write configuration file `%s' for peer %u: %s\n"),
1282  config_filename,
1283  (unsigned int)key_number,
1284  strerror(errno));
1285  GNUNET_free(config_filename);
1286  goto err_ret;
1287  }
1288  peer = GNUNET_new(struct GNUNET_TESTING_Peer);
1289  peer->ss_instances = ss_instances;
1290  peer->cfgfile = config_filename; /* Free in peer_destroy */
1291  peer->cfg = GNUNET_CONFIGURATION_dup(cfg);
1292  libexec_binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm");
1293  if (GNUNET_SYSERR ==
1295  "arm",
1296  "PREFIX",
1297  &peer->main_binary))
1298  {
1299  /* No prefix */
1300  GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary);
1301  peer->args = GNUNET_strdup("");
1302  }
1303  else
1304  {
1305  peer->args = GNUNET_strdup(libexec_binary);
1306  }
1307  peer->system = system;
1308  peer->key_number = key_number;
1309  GNUNET_free(libexec_binary);
1310  peer->ports = ports; /* Free in peer_destroy */
1311  peer->nports = nports;
1312  return peer;
1313 
1314 err_ret:
1315  GNUNET_free_non_null(ss_instances);
1316  GNUNET_free_non_null(ports);
1317  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1318  if (NULL != emsg)
1319  *emsg = emsg_;
1320  else
1321  GNUNET_free(emsg_);
1322  return NULL;
1323 }
1324 
1325 
1332 void
1334  struct GNUNET_PeerIdentity *id)
1335 {
1336  if (NULL != peer->id)
1337  {
1338  GNUNET_memcpy(id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1339  return;
1340  }
1341  peer->id = GNUNET_new(struct GNUNET_PeerIdentity);
1342  GNUNET_free(
1343  GNUNET_TESTING_hostkey_get(peer->system, peer->key_number, peer->id));
1344  GNUNET_memcpy(id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1345 }
1346 
1347 
1354 int
1356 {
1357  struct SharedServiceInstance *i;
1358  unsigned int cnt;
1359 
1360  if (NULL != peer->main_process)
1361  {
1362  GNUNET_break(0);
1363  return GNUNET_SYSERR;
1364  }
1365  GNUNET_assert(NULL != peer->cfgfile);
1366  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1367  {
1368  i = peer->ss_instances[cnt];
1369  if ((0 == i->n_refs) &&
1371  return GNUNET_SYSERR;
1372  i->n_refs++;
1373  }
1374  peer->main_binary =
1376  peer->main_process =
1379  NULL,
1380  peer->main_binary,
1381  peer->args,
1382  "-c",
1383  peer->cfgfile,
1384  NULL);
1385  if (NULL == peer->main_process)
1386  {
1388  _("Failed to start `%s': %s\n"),
1389  peer->main_binary,
1390  strerror(errno));
1391  return GNUNET_SYSERR;
1392  }
1393  return GNUNET_OK;
1394 }
1395 
1396 
1404 int
1406 {
1407  struct SharedServiceInstance *i;
1408  unsigned int cnt;
1409 
1410  if (NULL == peer->main_process)
1411  {
1412  GNUNET_break(0);
1413  return GNUNET_SYSERR;
1414  }
1416  return GNUNET_SYSERR;
1417  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1418  {
1419  i = peer->ss_instances[cnt];
1420  GNUNET_assert(0 != i->n_refs);
1421  i->n_refs--;
1422  if (0 == i->n_refs)
1424  }
1425  return GNUNET_OK;
1426 }
1427 
1428 
1436 int
1438 {
1439  int ret;
1440 
1441  if (NULL == peer->main_process)
1442  {
1443  GNUNET_break(0);
1444  return GNUNET_SYSERR;
1445  }
1446  ret = GNUNET_OS_process_wait(peer->main_process);
1448  peer->main_process = NULL;
1449  return ret;
1450 }
1451 
1452 
1459 int
1461 {
1463  return GNUNET_SYSERR;
1465  return GNUNET_SYSERR;
1466  return GNUNET_OK;
1467 }
1468 
1469 
1477 static void
1478 disconn_status(void *cls, int connected)
1479 {
1480  struct GNUNET_TESTING_Peer *peer = cls;
1481 
1482  if (GNUNET_SYSERR == connected)
1483  {
1484  peer->cb(peer->cb_cls, peer, connected);
1485  return;
1486  }
1487  if (GNUNET_YES == connected)
1488  {
1490  return;
1491  }
1493  GNUNET_ARM_disconnect(peer->ah);
1494  peer->ah = NULL;
1495  peer->cb(peer->cb_cls, peer, GNUNET_YES);
1496 }
1497 
1498 
1510 int
1513  void *cb_cls)
1514 {
1515  if (NULL == peer->main_process)
1516  return GNUNET_SYSERR;
1517  peer->ah = GNUNET_ARM_connect(peer->cfg, &disconn_status, peer);
1518  if (NULL == peer->ah)
1519  return GNUNET_SYSERR;
1520  peer->cb = cb;
1521  peer->cb_cls = cb_cls;
1522  return GNUNET_OK;
1523 }
1524 
1525 
1535 void
1537 {
1538  GNUNET_assert(NULL != peer->ah);
1539  GNUNET_ARM_disconnect(peer->ah);
1540  peer->ah = NULL;
1541 }
1542 
1543 
1551 void
1553 {
1554  unsigned int cnt;
1555 
1556  if (NULL != peer->main_process)
1558  if (NULL != peer->ah)
1559  GNUNET_ARM_disconnect(peer->ah);
1560  GNUNET_free(peer->cfgfile);
1561  if (NULL != peer->cfg)
1563  GNUNET_free(peer->main_binary);
1564  GNUNET_free(peer->args);
1565  GNUNET_free_non_null(peer->id);
1567  if (NULL != peer->ports)
1568  {
1569  for (cnt = 0; cnt < peer->nports; cnt++)
1570  GNUNET_TESTING_release_port(peer->system, peer->ports[cnt]);
1571  GNUNET_free(peer->ports);
1572  }
1573  GNUNET_free(peer);
1574 }
1575 
1576 
1593 int
1594 GNUNET_TESTING_peer_run(const char *testdir,
1595  const char *cfgfilename,
1597  void *tm_cls)
1598 {
1599  return GNUNET_TESTING_service_run(testdir, "arm", cfgfilename, tm, tm_cls);
1600 }
1601 
1602 
1611 
1616 
1621 
1625  void *tm_cls;
1626 };
1627 
1628 
1634 static void
1636 {
1637  struct ServiceContext *sc = cls;
1638 
1639  sc->tm(sc->tm_cls, sc->cfg, sc->peer);
1640 }
1641 
1642 
1664 int
1665 GNUNET_TESTING_service_run(const char *testdir,
1666  const char *service_name,
1667  const char *cfgfilename,
1669  void *tm_cls)
1670 {
1671  struct ServiceContext sc;
1672  struct GNUNET_TESTING_System *system;
1673  struct GNUNET_TESTING_Peer *peer;
1675  char *binary;
1676  char *libexec_binary;
1677 
1678  GNUNET_log_setup(testdir, "WARNING", NULL);
1679  system = GNUNET_TESTING_system_create(testdir, "127.0.0.1", NULL, NULL);
1680  if (NULL == system)
1681  return 1;
1683  if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfgfilename))
1684  {
1686  _("Failed to load configuration from %s\n"),
1687  cfgfilename);
1690  return 1;
1691  }
1692  peer = GNUNET_TESTING_peer_configure(system, cfg, 0, NULL, NULL);
1693  if (NULL == peer)
1694  {
1696  hostkeys_unload(system);
1698  return 1;
1699  }
1700  GNUNET_free(peer->main_binary);
1701  GNUNET_free(peer->args);
1702  GNUNET_asprintf(&binary, "gnunet-service-%s", service_name);
1703  libexec_binary = GNUNET_OS_get_libexec_binary_path(binary);
1704  if (GNUNET_SYSERR ==
1706  service_name,
1707  "PREFIX",
1708  &peer->main_binary))
1709  {
1710  /* No prefix */
1711  GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary);
1712  peer->args = GNUNET_strdup("");
1713  }
1714  else
1715  peer->args = GNUNET_strdup(libexec_binary);
1716 
1717  GNUNET_free(libexec_binary);
1718  GNUNET_free(binary);
1719  if (GNUNET_OK != GNUNET_TESTING_peer_start(peer))
1720  {
1724  return 1;
1725  }
1726  sc.cfg = cfg;
1727  sc.tm = tm;
1728  sc.tm_cls = tm_cls;
1729  sc.peer = peer;
1730  GNUNET_SCHEDULER_run(&service_run_main, &sc); /* Scheduler loop */
1731  if ((NULL != peer->main_process) &&
1733  {
1737  return 1;
1738  }
1742  return 0;
1743 }
1744 
1745 
1759 char *
1761 {
1762  size_t slen = strlen(argv0) + 1;
1763  char sbuf[slen];
1764  char *ret;
1765  char *dot;
1766 
1767  GNUNET_memcpy(sbuf, argv0, slen);
1768  ret = strrchr(sbuf, '_');
1769  if (NULL == ret)
1770  return NULL;
1771  ret++; /* skip underscore */
1772  dot = strchr(ret, '.');
1773  if (NULL != dot)
1774  *dot = '\0';
1775  return GNUNET_strdup(ret);
1776 }
1777 
1778 
1779 /* end of testing.c */
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration we are building.
Definition: testing.c:745
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:782
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:541
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:1511
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:1610
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:81
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1339
Closure for update_rel_sum() and update_abs_sum().
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
The structure for identifying a shared service.
#define AI_NUMERICSERV
AI_NUMERICSERV not defined in windows.
Definition: platform.h:226
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
static void cleanup_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:465
int GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
unsigned int nports
The number of ports in the above array.
Definition: testing.c:231
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:155
char * gnunet_home
The customized service home path for this peer.
Definition: testing.c:750
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:286
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:1355
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:167
#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:1594
struct GNUNET_ARM_Handle * ah
The handle to the peer&#39;s ARM service.
Definition: testing.c:196
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:757
unsigned int n_instances
Definition: testing.c:87
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
Definition: testing.c:135
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:707
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:1433
unsigned int share
Definition: testing.c:85
struct GNUNET_OS_Process * proc
Definition: testing.c:67
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(int pipe_control, unsigned int std_inheritance, const SOCKTYPE *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:762
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:474
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:248
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:481
unsigned int n_shared_services
Definition: testing.c:125
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:707
Handle for interacting with ARM.
Definition: arm_api.c:96
#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:1478
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:226
void * tm_cls
Closure for the above callback.
Definition: testing.c:1625
static int ret
Final status code.
Definition: gnunet-arm.c:89
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition: arm_api.c:505
#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:985
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1460
#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:1141
#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:150
char * main_binary
Binary to be executed during &#39;GNUNET_TESTING_peer_start&#39;.
Definition: testing.c:184
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:1162
#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:1606
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1405
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:145
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
unsigned int n_peers
Definition: testing.c:83
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:817
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:1665
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1026
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:171
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:211
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:201
#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:480
char * cfgfile
Path to the configuration file for this peer.
Definition: testing.c:176
char * sname
Definition: testing.c:77
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:762
#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:96
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
Create a system handle.
Definition: testing.c:449
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:530
unsigned int n_refs
Definition: testing.c:73
GNUNET_TESTING_TestMain tm
Callback to signal service startup.
Definition: testing.c:1615
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:1469
struct SharedService ** shared_services
Definition: testing.c:123
Open the file for writing.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:406
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:95
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:63
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:254
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:272
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running...
Definition: testing.c:191
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1536
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:364
static void hostkeys_unload(struct GNUNET_TESTING_System *system)
Function to remove the loaded hostkeys.
Definition: testing.c:311
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:1760
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:160
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:331
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:83
static void stop_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:509
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:879
struct GNUNET_TESTING_Peer * peer
The peer in which the service is run.
Definition: testing.c:1620
struct SharedServiceInstance ** instances
Definition: testing.c:79
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:121
#define GNUNET_log(kind,...)
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:116
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a TCP or UDP port for a peer.
Definition: testing.c:572
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:1333
handle to a socket
Definition: network.c:46
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:236
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:1078
char * hostname
our hostname
Definition: testing.c:111
#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:740
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:206
struct GNUNET_PeerIdentity * id
The cached identity of this peer.
Definition: testing.c:217
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
struct SharedServiceInstance ** ss_instances
Definition: testing.c:219
char * tmppath
Prefix (i.e.
Definition: testing.c:100
int status
build status - to signal error while building a configuration
Definition: testing.c:767
#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:1262
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1552
static void service_run_main(void *cls)
Callback to be called when SCHEDULER has been started.
Definition: testing.c:1635
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:669
Handle used to access files (and pipes).
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:548
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:1406
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:1437
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:900
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:224
char * trusted_ip
The trusted ip.
Definition: testing.c:106
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.