GNUnet  0.17.6
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"
37 #include "testing_cmds.h"
38 
39 #define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
40 
41 #define CONNECT_ADDRESS_TEMPLATE "%s-192.168.15.%u"
42 
43 #define ROUTER_CONNECT_ADDRESS_TEMPLATE "%s-92.68.150.%u"
44 
45 #define KNOWN_CONNECT_ADDRESS_TEMPLATE "%s-92.68.151.%u"
46 
47 #define PREFIX_TCP "tcp"
48 
49 #define PREFIX_UDP "udp"
50 
57 #define LOW_PORT 12000
58 
64 #define HIGH_PORT 56000
65 
66 
68 {
69  struct SharedService *ss;
70 
71  char *cfg_fn;
72 
74 
75  char *unix_sock;
76 
77  char *port_str;
78 
79  unsigned int n_refs;
80 };
81 
82 struct SharedService
83 {
84  char *sname;
85 
87 
89 
90  unsigned int n_peers;
91 
92  unsigned int share;
93 
94  unsigned int n_instances;
95 };
96 
97 
103 {
108  char *tmppath;
109 
114  char *trusted_ip;
115 
119  char *hostname;
120 
125 
130 
132 
133  unsigned int n_shared_services;
134 
143  uint32_t reserved_ports[65536 / 32];
144 
153  uint32_t path_counter;
154 
158  uint32_t total_hostkeys;
159 
163  uint16_t lowport;
164 
168  uint16_t highport;
169 };
170 
171 
176 {
181 
185  char *cfgfile;
186 
193  char *main_binary;
194  char *args;
195 
201 
206 
211 
216 
220  void *cb_cls;
221 
227 
229 
235  uint16_t *ports;
236 
240  unsigned int nports;
241 
245  uint32_t key_number;
246 };
247 
248 
256 static int
258 {
259  uint64_t fs;
260  char *data_dir;
261  char *filename;
262  struct GNUNET_DISK_FileHandle *fd;
263 
264  GNUNET_assert (NULL == system->hostkeys_data);
266  GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
267  GNUNET_free (data_dir);
268 
270  {
272  _ ("Hostkeys file not found: %s\n"),
273  filename);
275  return GNUNET_SYSERR;
276  }
277  /* Check hostkey file size, read entire thing into memory */
278  if (GNUNET_OK !=
280  fs = 0;
281  if (0 == fs)
282  {
284  return GNUNET_SYSERR; /* File is empty */
285  }
286  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
287  {
289  _ ("Incorrect hostkey file format: %s\n"),
290  filename);
292  return GNUNET_SYSERR;
293  }
297  if (NULL == fd)
298  {
301  return GNUNET_SYSERR;
302  }
304  system->hostkeys_data =
307  if (NULL == system->hostkeys_data)
308  return GNUNET_SYSERR;
310  return GNUNET_OK;
311 }
312 
313 
319 static void
321 {
322  GNUNET_break (NULL != system->hostkeys_data);
323  system->hostkeys_data = NULL;
324  GNUNET_DISK_file_unmap (system->map);
325  system->map = NULL;
326  system->hostkeys_data = NULL;
327  system->total_hostkeys = 0;
328 }
329 
330 
339 static void
340 cfg_copy_iterator (void *cls,
341  const char *section,
342  const char *option,
343  const char *value)
344 {
345  struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
346 
347  GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value);
348 }
349 
350 
372 struct GNUNET_TESTING_System *
374  const char *testdir,
375  const char *trusted_ip,
376  const char *hostname,
378  uint16_t lowport,
379  uint16_t highport)
380 {
381  struct GNUNET_TESTING_System *system;
382  struct GNUNET_TESTING_SharedService tss;
383  struct SharedService *ss;
384  unsigned int cnt;
385 
386  GNUNET_assert (NULL != testdir);
387  system = GNUNET_new (struct GNUNET_TESTING_System);
388  if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX)))
389  system->tmppath = GNUNET_DISK_mkdtemp (testdir);
390  else
391  system->tmppath = GNUNET_strdup (system->tmppath);
392  system->lowport = lowport;
393  system->highport = highport;
394  if (NULL == system->tmppath)
395  {
396  GNUNET_free (system);
397  return NULL;
398  }
399  if (NULL != trusted_ip)
400  system->trusted_ip = GNUNET_strdup (trusted_ip);
401  if (NULL != hostname)
402  system->hostname = GNUNET_strdup (hostname);
403  if (GNUNET_OK != hostkeys_load (system))
404  {
406  return NULL;
407  }
408  if (NULL == shared_services)
409  return system;
410  for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
411  {
412  tss = shared_services[cnt];
413  ss = GNUNET_new (struct SharedService);
414  ss->sname = GNUNET_strdup (tss.service);
417  ss->sname,
419  ss->cfg);
421  "TESTING",
423  ss->cfg);
425  "PATHS",
427  ss->cfg);
428  ss->share = tss.share;
430  system->n_shared_services,
431  ss);
432  }
433  return system;
434 }
435 
436 
457 struct GNUNET_TESTING_System *
459  const char *testdir,
460  const char *trusted_ip,
461  const char *hostname,
463 {
465  trusted_ip,
466  hostname,
468  LOW_PORT,
469  HIGH_PORT);
470 }
471 
472 
473 static void
475 {
476  if (NULL != i->cfg_fn)
477  {
478  (void) unlink (i->cfg_fn);
479  GNUNET_free (i->cfg_fn);
480  }
481  GNUNET_free (i->unix_sock);
482  GNUNET_free (i->port_str);
483  GNUNET_break (NULL == i->proc);
484  GNUNET_break (0 == i->n_refs);
485  GNUNET_free (i);
486 }
487 
488 
489 static int
491 {
492  char *binary;
493  char *libexec_binary;
494 
495  GNUNET_assert (NULL == i->proc);
496  GNUNET_assert (NULL != i->cfg_fn);
497  (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
498  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
499  GNUNET_free (binary);
501  NULL,
502  NULL,
503  NULL,
504  libexec_binary,
505  libexec_binary,
506  "-c",
507  i->cfg_fn,
508  NULL);
509  GNUNET_free (libexec_binary);
510  if (NULL == i->proc)
511  return GNUNET_SYSERR;
512  return GNUNET_OK;
513 }
514 
515 
516 static void
518 {
519  GNUNET_break (0 == i->n_refs);
522  "Killing shared service instance (%s) failed\n",
523  i->ss->sname);
524  (void) GNUNET_OS_process_wait (i->proc);
526  i->proc = NULL;
527 }
528 
529 
537 void
539  int remove_paths)
540 {
541  struct SharedService *ss;
542  struct SharedServiceInstance *i;
543  unsigned int ss_cnt;
544  unsigned int i_cnt;
545 
546  if (NULL != system->hostkeys_data)
547  hostkeys_unload (system);
548  for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
549  {
550  ss = system->shared_services[ss_cnt];
551  for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
552  {
553  i = ss->instances[i_cnt];
554  if (NULL != i->proc)
557  }
560  GNUNET_free (ss->sname);
561  GNUNET_free (ss);
562  }
563  GNUNET_free (system->shared_services);
564  if (GNUNET_YES == remove_paths)
566  GNUNET_free (system->tmppath);
567  GNUNET_free (system->trusted_ip);
568  GNUNET_free (system->hostname);
569  GNUNET_free (system);
570 }
571 
572 
579 uint16_t
581 {
582  struct GNUNET_NETWORK_Handle *socket;
583  struct addrinfo hint;
584  struct addrinfo *ret;
585  struct addrinfo *ai;
586  uint32_t *port_buckets;
587  char *open_port_str;
588  int bind_status;
589  uint32_t xor_image;
590  uint16_t index;
591  uint16_t open_port;
592  uint16_t pos;
593 
594  /*
595  FIXME: Instead of using getaddrinfo we should try to determine the port
596  status by the following heurestics.
597 
598  On systems which support both IPv4 and IPv6, only ports open on both
599  address families are considered open.
600  On system with either IPv4 or IPv6. A port is considered open if it's
601  open in the respective address family
602  */hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
603  hint.ai_socktype = 0;
604  hint.ai_protocol = 0;
605  hint.ai_addrlen = 0;
606  hint.ai_addr = NULL;
607  hint.ai_canonname = NULL;
608  hint.ai_next = NULL;
609  hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
610  port_buckets = system->reserved_ports;
611  for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
612  index++)
613  {
614  xor_image = (UINT32_MAX ^ port_buckets[index]);
615  if (0 == xor_image) /* Ports in the bucket are full */
616  continue;
617  pos = system->lowport % 32;
618  while (pos < 32)
619  {
620  if (0 == ((xor_image >> pos) & 1U))
621  {
622  pos++;
623  continue;
624  }
625  open_port = (index * 32) + pos;
626  if (open_port >= system->highport)
627  return 0;
628  GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
629  ret = NULL;
630  GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
631  GNUNET_free (open_port_str);
632  bind_status = GNUNET_NO;
633  for (ai = ret; NULL != ai; ai = ai->ai_next)
634  {
635  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
636  if (NULL == socket)
637  continue;
638  bind_status =
639  GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
641  if (GNUNET_OK != bind_status)
642  break;
643  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
644  if (NULL == socket)
645  continue;
646  bind_status =
647  GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
649  if (GNUNET_OK != bind_status)
650  break;
651  }
652  port_buckets[index] |= (1U << pos); /* Set the port bit */
653  freeaddrinfo (ret);
654  if (GNUNET_OK == bind_status)
655  {
657  "Found a free port %u\n",
658  (unsigned int) open_port);
659  return open_port;
660  }
661  pos++;
662  }
663  }
664  return 0;
665 }
666 
667 
675 void
677  uint16_t port)
678 {
679  uint32_t *port_buckets;
680  uint16_t bucket;
681  uint16_t pos;
682 
683  port_buckets = system->reserved_ports;
684  bucket = port / 32;
685  pos = port % 32;
686  LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
687  if (0 == (port_buckets[bucket] & (1U << pos)))
688  {
689  GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
690  return;
691  }
692  port_buckets[bucket] &= ~(1U << pos);
693 }
694 
695 
715  uint32_t key_number,
716  struct GNUNET_PeerIdentity *id)
717 {
718  struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
719 
720  if ((NULL == id) || (NULL == system->hostkeys_data))
721  return NULL;
722  if (key_number >= system->total_hostkeys)
723  {
725  _ ("Key number %u does not exist\n"),
726  key_number);
727  return NULL;
728  }
729  private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
730  GNUNET_memcpy (private_key,
731  system->hostkeys_data
732  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
734  GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key);
735  return private_key;
736 }
737 
738 
743 struct UpdateContext
744 {
749 
754 
758  char *gnunet_home;
759 
765  uint16_t *ports;
766 
770  unsigned int nports;
771 
775  int status;
776 };
777 
778 
789 static void
790 update_config (void *cls,
791  const char *section,
792  const char *option,
793  const char *value)
794 {
795  struct UpdateContext *uc = cls;
796  unsigned int ival;
797  char cval[12];
798  char uval[PATH_MAX];
799  char *single_variable;
800  char *per_host_variable;
801  unsigned long long num_per_host;
802  uint16_t new_port;
803 
804  if (GNUNET_OK != uc->status)
805  return;
806  if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
807  (0 == strcmp (option, "HOSTNAME"))))
808  return;
809  GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
810  GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
811  if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
812  {
813  if ((ival != 0) &&
815  "testing",
816  single_variable)))
817  {
818  new_port = GNUNET_TESTING_reserve_port (uc->system);
819  if (0 == new_port)
820  {
821  uc->status = GNUNET_SYSERR;
822  GNUNET_free (single_variable);
823  GNUNET_free (per_host_variable);
824  return;
825  }
826  GNUNET_snprintf (cval, sizeof(cval), "%u", new_port);
827  value = cval;
828  GNUNET_array_append (uc->ports, uc->nports, new_port);
829  }
830  else if ((ival != 0) &&
831  (GNUNET_YES ==
833  "testing",
834  single_variable)) &&
836  "testing",
837  per_host_variable,
838  &num_per_host))
839  {
840  /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
841  /* ival + ctx->fdnum % num_per_host); */
842  /* value = cval; */
843  GNUNET_break (0); /* FIXME */
844  }
845  }
846  if (0 == strcmp (option, "UNIXPATH"))
847  {
849  "testing",
850  single_variable))
851  {
852  GNUNET_snprintf (uval,
853  sizeof(uval),
854  "%s/%s.sock",
855  uc->gnunet_home,
856  section);
857  value = uval;
858  }
859  else if ((GNUNET_YES ==
861  "testing",
862  per_host_variable,
863  &num_per_host)) &&
864  (num_per_host > 0))
865  {
866  GNUNET_break (0); /* FIXME */
867  }
868  }
869  if (0 == strcmp (option, "HOSTNAME"))
870  {
871  value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
872  }
873  GNUNET_free (single_variable);
874  GNUNET_free (per_host_variable);
875  GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
876 }
877 
878 
886 static void
887 update_config_sections (void *cls, const char *section)
888 {
889  struct UpdateContext *uc = cls;
890  char **ikeys;
891  char *val;
892  char *ptr;
893  char *orig_allowed_hosts;
894  char *allowed_hosts;
895  char *ACCEPT_FROM_key;
896  uint16_t ikeys_cnt;
897  uint16_t key;
898 
899  ikeys_cnt = 0;
900  val = NULL;
901  /* Ignore certain options from sections. See
902  https://gnunet.org/bugs/view.php?id=2476 */
903  if (GNUNET_YES ==
904  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
905  {
908  section,
909  "TESTING_IGNORE_KEYS",
910  &val));
911  ptr = val;
912  for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
913  ptr++;
914  if (0 == ikeys_cnt)
915  GNUNET_break (0);
916  else
917  {
918  ikeys = GNUNET_malloc ((sizeof(char *)) * ikeys_cnt);
919  ptr = val;
920  for (key = 0; key < ikeys_cnt; key++)
921  {
922  ikeys[key] = ptr;
923  ptr = strstr (ptr, ";");
924  GNUNET_assert (NULL != ptr); /* worked just before... */
925  *ptr = '\0';
926  ptr++;
927  }
928  }
929  }
930  if (0 != ikeys_cnt)
931  {
932  for (key = 0; key < ikeys_cnt; key++)
933  {
934  if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
935  break;
936  }
937  if ((key == ikeys_cnt) &&
938  (GNUNET_YES ==
939  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
940  {
942  section,
943  "PORT",
944  &ptr))
945  {
947  section,
948  "ADVERTISED_PORT",
949  ptr);
950  GNUNET_free (ptr);
951  }
952  }
953  for (key = 0; key < ikeys_cnt; key++)
954  {
955  if (NULL != strstr (ikeys[key], "ACCEPT_FROM"))
956  {
957  GNUNET_free (ikeys);
958  GNUNET_free (val);
959  return;
960  }
961  }
962  GNUNET_free (ikeys);
963  }
964  GNUNET_free (val);
965  ACCEPT_FROM_key = "ACCEPT_FROM";
966  if ((NULL != uc->system->trusted_ip) &&
967  (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
968  ACCEPT_FROM_key = "ACCEPT_FROM6";
970  section,
971  ACCEPT_FROM_key,
972  &orig_allowed_hosts))
973  {
974  orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
975  }
976  if (NULL == uc->system->trusted_ip)
977  allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
978  else
979  GNUNET_asprintf (&allowed_hosts,
980  "%s%s;",
981  orig_allowed_hosts,
982  uc->system->trusted_ip);
983  GNUNET_free (orig_allowed_hosts);
985  section,
986  ACCEPT_FROM_key,
987  allowed_hosts);
988  GNUNET_free (allowed_hosts);
989 }
990 
991 
992 static struct SharedServiceInstance *
994  struct SharedService *ss,
996 {
997  struct SharedServiceInstance *i;
998  struct GNUNET_CONFIGURATION_Handle *temp;
999  char *gnunet_home;
1000  uint32_t port;
1001 
1002  ss->n_peers++;
1003  if (((0 == ss->share) && (NULL == ss->instances)) ||
1004  ((0 != ss->share) &&
1005  (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
1006  {
1007  i = GNUNET_new (struct SharedServiceInstance);
1008  i->ss = ss;
1009  (void) GNUNET_asprintf (&gnunet_home,
1010  "%s/shared/%s/%u",
1011  system->tmppath,
1012  ss->sname,
1013  ss->n_instances);
1014  (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
1015  port = GNUNET_TESTING_reserve_port (system);
1016  if (0 == port)
1017  {
1018  GNUNET_free (gnunet_home);
1020  return NULL;
1021  }
1023  temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1024  (void) GNUNET_asprintf (&i->port_str, "%u", port);
1025  (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1027  "PATHS",
1028  "GNUNET_HOME",
1029  gnunet_home);
1030  GNUNET_free (gnunet_home);
1032  ss->sname,
1033  "UNIXPATH",
1034  i->unix_sock);
1036  ss->sname,
1037  "PORT",
1038  i->port_str);
1040  {
1043  return NULL;
1044  }
1046  }
1047  else
1048  {
1049  GNUNET_assert (NULL != ss->instances);
1050  GNUNET_assert (0 < ss->n_instances);
1051  i = ss->instances[ss->n_instances - 1];
1052  }
1054  ss->sname,
1056  cfg);
1058  ss->sname,
1059  "UNIXPATH",
1060  i->unix_sock);
1062  return i;
1063 }
1064 
1065 
1085 static int
1088  uint16_t **ports,
1089  unsigned int *nports)
1090 {
1091  struct UpdateContext uc;
1092  char *default_config;
1093 
1094  uc.system = system;
1095  uc.cfg = cfg;
1096  uc.status = GNUNET_OK;
1097  uc.ports = NULL;
1098  uc.nports = 0;
1099  GNUNET_asprintf (&uc.gnunet_home,
1100  "%s/%u",
1101  system->tmppath,
1102  system->path_counter++);
1103  GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1105  "PATHS",
1106  "DEFAULTCONFIG",
1107  default_config);
1108  GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
1109  GNUNET_free (default_config);
1111  "PATHS",
1112  "GNUNET_HOME",
1113  uc.gnunet_home);
1114  /* make PORTs and UNIXPATHs unique */
1116  /* allow connections to services from system trusted_ip host */
1118  /* enable loopback-based connections between peers */
1119  GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
1120  GNUNET_free (uc.gnunet_home);
1121  if ((NULL != ports) && (NULL != nports))
1122  {
1123  *ports = uc.ports;
1124  *nports = uc.nports;
1125  }
1126  else
1127  GNUNET_free (uc.ports);
1128  return uc.status;
1129 }
1130 
1131 
1148 int
1151 {
1152  return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1153 }
1154 
1155 
1169 struct GNUNET_TESTING_Peer *
1172  uint32_t key_number,
1173  struct GNUNET_PeerIdentity *id,
1174  char **emsg)
1175 {
1176  struct GNUNET_TESTING_Peer *peer;
1177  struct GNUNET_DISK_FileHandle *fd;
1178  char *hostkey_filename;
1179  char *config_filename;
1180  char *libexec_binary;
1181  char *emsg_;
1183  uint16_t *ports;
1184  struct SharedService *ss;
1185  struct SharedServiceInstance **ss_instances;
1186  unsigned int cnt;
1187  unsigned int nports;
1188 
1189  ports = NULL;
1190  nports = 0;
1191  ss_instances = NULL;
1192  if (NULL != emsg)
1193  *emsg = NULL;
1194  if (key_number >= system->total_hostkeys)
1195  {
1196  GNUNET_asprintf (
1197  &emsg_,
1198  _ (
1199  "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1200  (unsigned int) system->total_hostkeys);
1201  goto err_ret;
1202  }
1203  pk = NULL;
1204  if ((NULL != id) &&
1205  (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1206  {
1207  GNUNET_asprintf (&emsg_,
1208  _ ("Failed to initialize hostkey for peer %u\n"),
1209  (unsigned int) key_number);
1210  goto err_ret;
1211  }
1212  if (NULL != pk)
1213  GNUNET_free (pk);
1214  if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1215  {
1216  GNUNET_asprintf (
1217  &emsg_,
1218  _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
1219  goto err_ret;
1220  }
1221  /* Remove sections for shared services */
1222  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1223  {
1224  ss = system->shared_services[cnt];
1226  }
1227  if (GNUNET_OK !=
1228  GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
1229  {
1230  GNUNET_asprintf (&emsg_,
1231  _ ("Failed to create configuration for peer "
1232  "(not enough free ports?)\n"));
1233  goto err_ret;
1234  }
1237  "PEER",
1238  "PRIVATE_KEY",
1239  &hostkey_filename));
1240  fd = GNUNET_DISK_file_open (hostkey_filename,
1244  if (NULL == fd)
1245  {
1246  GNUNET_asprintf (&emsg_,
1247  _ ("Cannot open hostkey file `%s': %s\n"),
1248  hostkey_filename,
1249  strerror (errno));
1250  GNUNET_free (hostkey_filename);
1251  goto err_ret;
1252  }
1253  GNUNET_free (hostkey_filename);
1256  system->hostkeys_data
1257  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1259  {
1260  GNUNET_asprintf (&emsg_,
1261  _ ("Failed to write hostkey file for peer %u: %s\n"),
1262  (unsigned int) key_number,
1263  strerror (errno));
1265  goto err_ret;
1266  }
1268  ss_instances = GNUNET_malloc (sizeof(struct SharedServiceInstance *)
1269  * system->n_shared_services);
1270  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1271  {
1272  ss = system->shared_services[cnt];
1273  ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1274  if (NULL == ss_instances[cnt])
1275  {
1276  emsg_ = GNUNET_strdup ("FIXME");
1277  goto err_ret;
1278  }
1279  }
1282  "PATHS",
1283  "DEFAULTCONFIG",
1284  &config_filename));
1285  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1286  {
1287  GNUNET_asprintf (&emsg_,
1288  _ (
1289  "Failed to write configuration file `%s' for peer %u: %s\n"),
1290  config_filename,
1291  (unsigned int) key_number,
1292  strerror (errno));
1293  GNUNET_free (config_filename);
1294  goto err_ret;
1295  }
1296  peer = GNUNET_new (struct GNUNET_TESTING_Peer);
1297  peer->ss_instances = ss_instances;
1298  peer->cfgfile = config_filename; /* Free in peer_destroy */
1300  libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1301  if (GNUNET_SYSERR ==
1303  "arm",
1304  "PREFIX",
1305  &peer->main_binary))
1306  {
1307  /* No prefix */
1308  GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1309  peer->args = GNUNET_strdup ("");
1310  }
1311  else
1312  {
1313  peer->args = GNUNET_strdup (libexec_binary);
1314  }
1315  peer->system = system;
1316  peer->key_number = key_number;
1317  GNUNET_free (libexec_binary);
1318  peer->ports = ports; /* Free in peer_destroy */
1319  peer->nports = nports;
1320  return peer;
1321 
1322 err_ret:
1323  GNUNET_free (ss_instances);
1324  GNUNET_free (ports);
1325  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1326  if (NULL != emsg)
1327  *emsg = emsg_;
1328  else
1329  GNUNET_free (emsg_);
1330  return NULL;
1331 }
1332 
1333 
1340 void
1342  struct GNUNET_PeerIdentity *id)
1343 {
1344  if (NULL != peer->id)
1345  {
1346  GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1347  return;
1348  }
1349  peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1350  GNUNET_free_nz (
1351  GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
1352  GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1353 }
1354 
1355 
1362 int
1364 {
1365  struct SharedServiceInstance *i;
1366  unsigned int cnt;
1367 
1368  if (NULL != peer->main_process)
1369  {
1370  GNUNET_break (0);
1371  return GNUNET_SYSERR;
1372  }
1373  GNUNET_assert (NULL != peer->cfgfile);
1374  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1375  {
1376  i = peer->ss_instances[cnt];
1377  if ((0 == i->n_refs) &&
1379  return GNUNET_SYSERR;
1380  i->n_refs++;
1381  }
1382  peer->main_binary =
1383  GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary);
1384  peer->main_process =
1386  NULL,
1387  peer->main_binary,
1388  peer->args,
1389  "-c",
1390  peer->cfgfile,
1391  NULL);
1392  if (NULL == peer->main_process)
1393  {
1395  _ ("Failed to start `%s': %s\n"),
1396  peer->main_binary,
1397  strerror (errno));
1398  return GNUNET_SYSERR;
1399  }
1400  return GNUNET_OK;
1401 }
1402 
1403 
1411 int
1413 {
1414  struct SharedServiceInstance *i;
1415  unsigned int cnt;
1416 
1417  if (NULL == peer->main_process)
1418  {
1419  GNUNET_break (0);
1420  return GNUNET_SYSERR;
1421  }
1422  if (0 != GNUNET_OS_process_kill (peer->main_process, GNUNET_TERM_SIG))
1423  return GNUNET_SYSERR;
1424  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1425  {
1426  i = peer->ss_instances[cnt];
1427  GNUNET_assert (0 != i->n_refs);
1428  i->n_refs--;
1429  if (0 == i->n_refs)
1431  }
1432  return GNUNET_OK;
1433 }
1434 
1435 
1443 int
1445 {
1446  int ret;
1447 
1448  if (NULL == peer->main_process)
1449  {
1450  GNUNET_break (0);
1451  return GNUNET_SYSERR;
1452  }
1453  ret = GNUNET_OS_process_wait (peer->main_process);
1454  GNUNET_OS_process_destroy (peer->main_process);
1455  peer->main_process = NULL;
1456  return ret;
1457 }
1458 
1459 
1466 int
1468 {
1470  return GNUNET_SYSERR;
1472  return GNUNET_SYSERR;
1473  return GNUNET_OK;
1474 }
1475 
1476 
1484 static void
1485 disconn_status (void *cls, int connected)
1486 {
1487  struct GNUNET_TESTING_Peer *peer = cls;
1488 
1489  if (GNUNET_SYSERR == connected)
1490  {
1491  peer->cb (peer->cb_cls, peer, connected);
1492  return;
1493  }
1494  if (GNUNET_YES == connected)
1495  {
1497  return;
1498  }
1501  peer->ah = NULL;
1502  peer->cb (peer->cb_cls, peer, GNUNET_YES);
1503 }
1504 
1505 
1517 int
1520  void *cb_cls)
1521 {
1522  if (NULL == peer->main_process)
1523  return GNUNET_SYSERR;
1525  if (NULL == peer->ah)
1526  return GNUNET_SYSERR;
1527  peer->cb = cb;
1528  peer->cb_cls = cb_cls;
1529  return GNUNET_OK;
1530 }
1531 
1532 
1542 void
1544 {
1545  GNUNET_assert (NULL != peer->ah);
1547  peer->ah = NULL;
1548 }
1549 
1550 
1558 void
1560 {
1561  unsigned int cnt;
1562 
1563  if (NULL != peer->main_process)
1565  if (NULL != peer->ah)
1567  GNUNET_free (peer->cfgfile);
1568  if (NULL != peer->cfg)
1570  GNUNET_free (peer->main_binary);
1571  GNUNET_free (peer->args);
1572  GNUNET_free (peer->id);
1573  GNUNET_free (peer->ss_instances);
1574  if (NULL != peer->ports)
1575  {
1576  for (cnt = 0; cnt < peer->nports; cnt++)
1577  GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]);
1578  GNUNET_free (peer->ports);
1579  }
1580  GNUNET_free (peer);
1581 }
1582 
1583 
1600 int
1601 GNUNET_TESTING_peer_run (const char *testdir,
1602  const char *cfgfilename,
1604  void *tm_cls)
1605 {
1606  return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
1607 }
1608 
1609 
1614 {
1619 
1624 
1629 
1633  void *tm_cls;
1634 };
1635 
1636 
1642 static void
1643 service_run_main (void *cls)
1644 {
1645  struct ServiceContext *sc = cls;
1646 
1647  sc->tm (sc->tm_cls, sc->cfg, sc->peer);
1648 }
1649 
1650 
1672 int
1673 GNUNET_TESTING_service_run (const char *testdir,
1674  const char *service_name,
1675  const char *cfgfilename,
1677  void *tm_cls)
1678 {
1679  struct ServiceContext sc;
1680  struct GNUNET_TESTING_System *system;
1681  struct GNUNET_TESTING_Peer *peer;
1683  char *binary;
1684  char *libexec_binary;
1685 
1686  GNUNET_log_setup (testdir, "WARNING", NULL);
1687  system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1688  if (NULL == system)
1689  return 1;
1691  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1692  {
1694  _ ("Failed to load configuration from %s\n"),
1695  cfgfilename);
1698  return 1;
1699  }
1700  peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
1701  if (NULL == peer)
1702  {
1704  hostkeys_unload (system);
1706  return 1;
1707  }
1708  GNUNET_free (peer->main_binary);
1709  GNUNET_free (peer->args);
1710  GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1711  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1712  if (GNUNET_SYSERR ==
1714  service_name,
1715  "PREFIX",
1716  &peer->main_binary))
1717  {
1718  /* No prefix */
1719  GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1720  peer->args = GNUNET_strdup ("");
1721  }
1722  else
1723  peer->args = GNUNET_strdup (libexec_binary);
1724 
1725  GNUNET_free (libexec_binary);
1726  GNUNET_free (binary);
1728  {
1732  return 1;
1733  }
1734  sc.cfg = cfg;
1735  sc.tm = tm;
1736  sc.tm_cls = tm_cls;
1737  sc.peer = peer;
1738  GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1739  if ((NULL != peer->main_process) &&
1741  {
1745  return 1;
1746  }
1750  return 0;
1751 }
1752 
1753 
1767 char *
1769 {
1770  size_t slen = strlen (argv0) + 1;
1771  char sbuf[slen];
1772  char *ret;
1773  char *dot;
1774 
1775  GNUNET_memcpy (sbuf, argv0, slen);
1776  ret = strrchr (sbuf, '_');
1777  if (NULL == ret)
1778  return NULL;
1779  ret++; /* skip underscore */
1780  dot = strchr (ret, '.');
1781  if (NULL != dot)
1782  *dot = '\0';
1783  return GNUNET_strdup (ret);
1784 }
1785 
1786 
1787 static unsigned int
1789 {
1790  char *copy;
1791  size_t slen;
1792  char *token;
1793  unsigned int ret;
1794  char *rest = NULL;
1795 
1796  slen = strlen (line) + 1;
1797  copy = malloc (slen);
1798  memcpy (copy, line, slen);
1799  token = strtok_r (copy, ":", &rest);
1800  token = strtok_r (NULL, ":", &rest);
1801  GNUNET_assert (1 == sscanf (token, "%u", &ret));
1802  GNUNET_free (copy);
1803  return ret;
1804 }
1805 
1806 
1807 static char *
1808 get_key (char *line)
1809 {
1810  char *copy;
1811  size_t slen;
1812  char *token;
1813  char *ret;
1814  char *rest = NULL;
1815 
1816  slen = strlen (line) + 1;
1817  copy = malloc (slen);
1818  memcpy (copy, line, slen);
1819  token = strtok_r (copy, ":", &rest);
1820  ret = malloc (2);
1821  memcpy (ret, token, 2);
1822  GNUNET_free (copy);
1823  return ret;
1824 }
1825 
1826 
1827 static char *
1829 {
1830  char *copy;
1831  size_t slen, slen_token;
1832  char *token;
1833  char *ret;
1834  char *rest = NULL;
1835 
1836  slen = strlen (line) + 1;
1837  copy = malloc (slen);
1838  memcpy (copy, line, slen);
1839  token = strtok_r (copy, ":", &rest);
1840  token = strtok_r (NULL, ":", &rest);
1842  "first token %s\n",
1843  token);
1844  slen_token = strlen (token);
1845  ret = malloc (slen_token + 1);
1846  memcpy (ret, token, slen_token + 1);
1847  GNUNET_free (copy);
1848  return ret;
1849 }
1850 
1851 
1852 static unsigned int
1854 {
1855  char *copy;
1856  size_t slen;
1857  char *token;
1858  unsigned int ret;
1859  char *rest = NULL;
1860 
1861  slen = strlen (line) + 1;
1862  copy = malloc (slen);
1863  memcpy (copy, line, slen);
1864  token = strtok_r (copy, ":", &rest);
1865  token = strtok_r (NULL, ":", &rest);
1866  token = strtok_r (NULL, ":", &rest);
1867  GNUNET_assert (1 == sscanf (token, "%u", &ret));
1868  GNUNET_free (copy);
1869  return ret;
1870 }
1871 
1872 
1873 static char *
1874 get_value (char *key, char *line)
1875 {
1876  char *copy;
1877  size_t slen, slen_token;
1878  char *token;
1879  char *token2;
1880  char *temp;
1881  char *rest = NULL;
1882  char *ret;
1883 
1884  slen = strlen (line) + 1;
1885  copy = malloc (slen);
1886  memcpy (copy, line, slen);
1887  temp = strstr (copy, key);
1888  if (NULL == temp)
1889  return NULL;
1890  token = strtok_r (temp, ":", &rest);
1891  token = strtok_r (NULL, ":", &rest);
1892  token2 = strtok_r (token, "}", &rest);
1893  slen_token = strlen (token2);
1894  ret = malloc (slen_token + 1);
1895  memcpy (ret, token2, slen_token + 1);
1896  GNUNET_free (copy);
1897  return ret;
1898 }
1899 
1900 
1901 static struct GNUNET_TESTING_NodeConnection *
1903 {
1904  struct GNUNET_TESTING_NodeConnection *node_connection;
1905  char *copy;
1906  size_t slen;
1907  char *token;
1908  char *token2;
1909  unsigned int node_n;
1910  unsigned int namespace_n;
1911  char *rest = NULL;
1912  char *rest2 = NULL;
1914 
1915  node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection);
1916  node_connection->node = node;
1917 
1918  slen = strlen (line) + 1;
1919  copy = malloc (slen);
1920  memcpy (copy, line, slen);
1921  token = strtok_r (copy, ":", &rest);
1922  if (0 == strcmp ("{K", token))
1923  {
1924  node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE;
1925  token = strtok_r (NULL, ":", &rest);
1926  GNUNET_assert (1 == sscanf (token, "%u", &node_n));
1928  "node_n %u\n",
1929  node_n);
1930  node_connection->node_n = node_n;
1931  node_connection->namespace_n = 0;
1932  }
1933  else if (0 == strcmp ("{P", token))
1934  {
1935  node_connection->node_type = GNUNET_TESTING_SUBNET_NODE;
1936  token = strtok_r (NULL, ":", &rest);
1937  sscanf (token, "%u", &namespace_n);
1938  node_connection->namespace_n = namespace_n;
1939  token = strtok_r (NULL, ":", &rest);
1940  sscanf (token, "%u", &node_n);
1941  node_connection->node_n = node_n;
1943  "node_n %u namespace_n %u node->node_n %u node->namespace_n %u\n",
1944  node_n,
1945  namespace_n,
1946  node->node_n,
1947  node->namespace_n);
1948  }
1949  while (NULL != (token = strtok_r (NULL, ":", &rest)))
1950  {
1952  token2 = strtok_r (token, "}", &rest2);
1953  if (NULL != token2)
1954  {
1955  slen = strlen (token2) + 1;
1956  prefix->address_prefix = malloc (slen);
1957  memcpy (prefix->address_prefix, token2, slen);
1958  }
1959  else
1960  {
1961  slen = strlen (token) + 1;
1962  prefix->address_prefix = malloc (slen);
1963  memcpy (prefix->address_prefix, token, slen);
1964  }
1965 
1967  "address_prefix %s\n",
1968  prefix->address_prefix);
1969 
1971  node_connection->address_prefixes_tail,
1972  prefix);
1974  "address_prefix %s\n",
1975  prefix->address_prefix);
1976  }
1977 
1978  GNUNET_free (copy);
1979  return node_connection;
1980 }
1981 
1982 
1983 static void
1985 {
1986  char *value, *value2;
1987  char *temp;
1988  char *copy;
1989  size_t slen;
1990  char *rest = NULL;
1991  char *rest2 = NULL;
1992  struct GNUNET_TESTING_NodeConnection *node_connection;
1993 
1994 
1995  temp = strstr (line, "connect");
1996  if (NULL != temp)
1997  {
1998  slen = strlen (temp) + 1;
1999  copy = GNUNET_malloc (slen);
2000  memcpy (copy, temp, slen);
2001  strtok_r (copy, ":", &rest);
2002  value = strtok_r (rest, "|", &rest2);
2003 
2004  while (NULL != value)
2005  {
2007  "node_connections value %s\n",
2008  value);
2009  node_connection = get_connect_value (value, node);
2012  node_connection);
2013  value2 = strstr (value, "}}");
2014  if (NULL != value2)
2015  break;
2016  value = strtok_r (NULL, "|", &rest2);
2017 
2018  }
2019  GNUNET_free (copy);
2020  }
2021 }
2022 
2023 
2024 static int
2025 log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2026 {
2027  struct GNUNET_TESTING_NetjailNode *node = value;
2028  struct GNUNET_TESTING_NodeConnection *pos_connection;
2029  struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2030 
2032  "plugin: %s space: %u node: %u global: %u\n",
2033  node->plugin,
2034  node->namespace_n,
2035  node->node_n,
2036  node->is_global);
2037 
2038  for (pos_connection = node->node_connections_head; NULL != pos_connection;
2039  pos_connection = pos_connection->next)
2040  {
2041 
2043  "namespace_n: %u node_n: %u node_type: %u\n",
2044  pos_connection->namespace_n,
2045  pos_connection->node_n,
2046  pos_connection->node_type);
2047 
2048  for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
2049  pos_prefix =
2050  pos_prefix->next)
2051  {
2053  "prefix: %s\n",
2054  pos_prefix->address_prefix);
2055  }
2056  }
2057  return GNUNET_YES;
2058 }
2059 
2060 
2061 static int
2062 log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2063 {
2064  struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2065 
2066  GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
2067  return GNUNET_YES;
2068 }
2069 
2070 
2071 static int
2073 {
2075  "plugin: %s spaces: %u nodes: %u known: %u\n",
2076  topology->plugin,
2077  topology->namespaces_n,
2078  topology->nodes_m,
2079  topology->nodes_x);
2080 
2082  log_namespaces, NULL);
2084  NULL);
2085  return GNUNET_YES;
2086 }
2087 
2088 
2097 GNUNET_TESTING_get_connections (unsigned int num, struct
2099 {
2100  struct GNUNET_TESTING_NetjailNode *node;
2101  struct GNUNET_ShortHashCode *hkey;
2102  struct GNUNET_HashCode hc;
2103  struct GNUNET_TESTING_NetjailNamespace *namespace;
2104  unsigned int namespace_n, node_m;
2106 
2108  "gaga 1\n");
2109  log_topo (topology);
2111  "gaga 2\n");
2112  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2114  "num: %u \n",
2115  num);
2116  if (topology->nodes_x >= num)
2117  {
2118 
2119  GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
2120  memcpy (hkey,
2121  &hc,
2122  sizeof (*hkey));
2124  hkey);
2125  if (NULL != node)
2127  }
2128  else
2129  {
2130  namespace_n = (unsigned int) ceil ((double) (num - topology->nodes_x)
2131  / topology->nodes_m);
2133  "ceil num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
2134  num,
2135  topology->nodes_x,
2136  topology->nodes_m,
2137  namespace_n);
2138  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2139  GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
2140  memcpy (hkey,
2141  &hc,
2142  sizeof (*hkey));
2143  namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
2144  hkey);
2145  if (NULL == namespace)
2146  return NULL;
2147  node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
2148  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2149  GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
2150  memcpy (hkey,
2151  &hc,
2152  sizeof (*hkey));
2153  node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
2154  hkey);
2155  if (NULL != node)
2157  }
2158 
2159  GNUNET_free (hkey);
2160  return node_connections;
2161 }
2162 
2163 
2171 struct GNUNET_PeerIdentity *
2172 GNUNET_TESTING_get_pub_key (unsigned int num,
2173  const struct GNUNET_TESTING_System *tl_system)
2174 {
2176  struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
2178  struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
2180 
2181  priv_key = GNUNET_TESTING_hostkey_get (tl_system,
2182  num,
2183  peer);
2184 
2186  pub_key);
2187  peer->public_key = *pub_key;
2188  GNUNET_free (priv_key);
2189  GNUNET_free (pub_key);
2190  return peer;
2191 }
2192 
2193 
2194 int
2195 free_nodes_cb (void *cls,
2196  const struct GNUNET_ShortHashCode *key,
2197  void *value)
2198 {
2199  (void) cls;
2200  struct GNUNET_TESTING_NetjailNode *node = value;
2201  struct GNUNET_TESTING_NodeConnection *pos_connection;
2202  struct GNUNET_TESTING_NodeConnection *tmp_connection;
2203  struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2204  struct GNUNET_TESTING_AddressPrefix *tmp_prefix;
2205 
2206  pos_connection = node->node_connections_head;
2207 
2208  while (NULL != pos_connection->next)
2209  {
2210  pos_prefix = pos_connection->address_prefixes_head;
2211  while (NULL != pos_prefix->next)
2212  {
2213  tmp_prefix = pos_prefix->next;
2214  GNUNET_free (pos_prefix);
2215  pos_prefix = tmp_prefix;
2216  }
2217  tmp_connection = pos_connection->next;
2218  GNUNET_free (pos_connection);
2219  pos_connection = tmp_connection;
2220  }
2221  GNUNET_free (node->plugin);
2222  GNUNET_free (node);
2223  return GNUNET_OK;
2224 }
2225 
2226 
2227 int
2229  const struct GNUNET_ShortHashCode *key,
2230  void *value)
2231 {
2232  (void) cls;
2233  struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2234 
2235  GNUNET_free (namespace->router);
2237  NULL);
2238  return GNUNET_OK;
2239 
2240 }
2241 
2242 
2248 void
2250 {
2252  free_namespaces_cb, NULL);
2255  NULL);
2257  GNUNET_free (topology->plugin);
2259 }
2260 
2261 
2262 unsigned int
2264  struct GNUNET_TESTING_NodeConnection *node_connection,
2266 {
2267  unsigned int n, m, num;
2268 
2269  n = node_connection->namespace_n;
2270  m = node_connection->node_n;
2271 
2272  if (0 == n)
2273  num = m;
2274  else
2275  num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
2276 
2277  return num;
2278 }
2279 
2280 
2288 char *
2290  char *prefix)
2291 {
2292  struct GNUNET_TESTING_NetjailNode *node;
2293  char *addr;
2294  char *template;
2295  unsigned int node_n;
2296 
2298  "node_n: %u\n",
2299  connection->node_n);
2300 
2301  node = connection->node;
2302  if (connection->namespace_n == node->namespace_n)
2303  {
2304  template = CONNECT_ADDRESS_TEMPLATE;
2305  node_n = connection->node_n;
2306  }
2307  else if (0 == connection->namespace_n)
2308  {
2309  template = KNOWN_CONNECT_ADDRESS_TEMPLATE;
2310  node_n = connection->node_n;
2311  }
2312  else if (1 == connection->node_n)
2313  {
2315  node_n = connection->namespace_n;
2316  }
2317  else
2318  {
2319  return NULL;
2320  }
2321 
2322  if (0 == strcmp (PREFIX_TCP, prefix))
2323  {
2324 
2325  GNUNET_asprintf (&addr,
2326  template,
2327  prefix,
2328  node_n);
2329  }
2330  else if (0 == strcmp (PREFIX_UDP, prefix))
2331  {
2332  GNUNET_asprintf (&addr,
2333  template,
2334  prefix,
2335  node_n);
2336  }
2337  else
2338  {
2339  GNUNET_assert (0);
2340  }
2341 
2342  return addr;
2343 }
2344 
2345 
2352 struct GNUNET_MessageHeader *
2354 {
2355  struct GNUNET_CMDS_LOCAL_FINISHED *reply;
2356  size_t msg_length;
2357 
2359  "Local test exits with status %d\n",
2360  rv);
2361  msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
2362  reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
2364  reply->header.size = htons ((uint16_t) msg_length);
2365  reply->result = htons (rv);
2366 
2367  return (struct GNUNET_MessageHeader *) reply;
2368 }
2369 
2370 
2379 {
2380  char *token;
2381  char *key = NULL;
2382  unsigned int out;
2383  char *rest = NULL;
2384  char *value = NULL;
2385  char *value2;
2386  int ret;
2387  struct GNUNET_TESTING_NetjailTopology *topo;
2388  struct GNUNET_TESTING_NetjailNode *node;
2389  struct GNUNET_TESTING_NetjailRouter *router;
2390  struct GNUNET_TESTING_NetjailNamespace *namespace;
2391  struct GNUNET_ShortHashCode *hkey;
2392  struct GNUNET_HashCode hc;
2393 
2394  token = strtok_r (data, "\n", &rest);
2396  topo->map_namespaces =
2398  topo->map_globals =
2400 
2401  while (NULL != token)
2402  {
2403  if (NULL != key)
2404  free (key);
2405  key = get_key (token);
2407  "In the loop with token: %s beginning with %s\n",
2408  token,
2409  key);
2410  if (0 == strcmp (key, "M"))
2411  {
2413  "Get first Value for M.\n");
2414  out = get_first_value (token);
2416  "M: %u\n",
2417  out);
2418  topo->nodes_m = out;
2419  }
2420  else if (0 == strcmp (key, "N"))
2421  {
2423  "Get first Value for N.\n");
2424  out = get_first_value (token);
2426  "N: %u\n",
2427  out);
2428  topo->namespaces_n = out;
2429  }
2430  else if (0 == strcmp (key, "X"))
2431  {
2433  "Get first Value for X.\n");
2434  out = get_first_value (token);
2436  "X: %u\n",
2437  out);
2438  topo->nodes_x = out;
2439  }
2440  else if (0 == strcmp (key, "AC"))
2441  {
2443  "Get first Value for AC.\n");
2444  out = get_first_value (token);
2446  "AC: %u\n",
2447  out);
2448  topo->additional_connects = out;
2449  }
2450  else if (0 == strcmp (key, "T"))
2451  {
2453  "Get first string value for T.\n");
2454  value = get_first_string_value (token);
2456  "value: %s\n",
2457  value);
2458  topo->plugin = value;
2459  }
2460  else if (0 == strcmp (key, "K"))
2461  {
2462  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2463  node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2464 
2466  "Get first Value for K.\n");
2467  out = get_first_value (token);
2469  "K: %u\n",
2470  out);
2471  node->node_n = out;
2472  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2473  memcpy (hkey,
2474  &hc,
2475  sizeof (*hkey));
2476  node->is_global = GNUNET_YES;
2477 
2479  topo->map_globals,
2480  hkey))
2481  GNUNET_break (0);
2482  else
2484  hkey,
2485  node,
2488  "Get value for key value on K.\n");
2489  value = get_value ("plugin", token);
2491  "value: %s\n",
2492  value);
2493  node->plugin = value;
2494  node_connections (token, node);
2495  }
2496  else if (0 == strcmp (key, "R"))
2497  {
2498  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2499  router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter);
2500  node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2501 
2503  "Get first Value for R.\n");
2504  out = get_first_value (token);
2506  "R: %u\n",
2507  out);
2508  node->node_n = out;
2509  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2510  memcpy (hkey,
2511  &hc,
2512  sizeof (*hkey));
2514  "Get value for key tcp_port on R.\n");
2515  value = get_value ("tcp_port", token);
2517  "tcp_port: %s\n",
2518  value);
2519  ret = sscanf (value, "%u", &(router->tcp_port));
2520 
2521  GNUNET_break (0 != ret && 1 >= router->tcp_port);
2522 
2524  "Get value for key udp_port on R.\n");
2525  value2 = get_value ("udp_port", token);
2526  ret = sscanf (value2, "%u", &(router->udp_port));
2527  GNUNET_break (0 != ret && 1 >= router->udp_port);
2529  "udp_port: %s\n",
2530  value2);
2531 
2533  topo->map_namespaces,
2534  hkey))
2535  {
2537  hkey);
2538  }
2539  else
2540  {
2541  namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2542  namespace->namespace_n = out;
2543  namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
2545  hkey,
2546  namespace,
2548  }
2549  namespace->router = router;
2550 
2551  }
2552  else if (0 == strcmp (key, "P"))
2553  {
2554  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2555  node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2556 
2558  "Get first Value for P.\n");
2559  out = get_first_value (token);
2561  "P: %u\n",
2562  out);
2563  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2564  memcpy (hkey,
2565  &hc,
2566  sizeof (*hkey));
2567 
2569  topo->map_namespaces,
2570  hkey))
2571  {
2573  hkey);
2574  }
2575  else
2576  {
2577  namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2578  namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
2579  namespace->namespace_n = out;
2581  hkey,
2582  namespace,
2584  }
2586  "Get second Value for P.\n");
2587  out = get_second_value (token);
2589  "P: %u\n",
2590  out);
2591  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2592  memcpy (hkey,
2593  &hc,
2594  sizeof (*hkey));
2596  namespace->nodes,
2597  hkey))
2598  {
2599  GNUNET_break (0);
2600  }
2601  else
2602  {
2603  node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2604  GNUNET_CONTAINER_multishortmap_put (namespace->nodes,
2605  hkey,
2606  node,
2609  "Get value for key plugin on P.\n");
2610  value = get_value ("plugin", token);
2612  "plugin: %s\n",
2613  value);
2614  node->plugin = value;
2615  node->node_n = out;
2616  node->namespace_n = namespace->namespace_n;
2617  }
2618  node_connections (token, node);
2619  }
2620  token = strtok_r (NULL, "\n", &rest);
2621  if (NULL != token)
2623  "Next token %s\n",
2624  token);
2625  }
2626  if (NULL != key)
2627  GNUNET_free (key);
2628  /*if (NULL != value)
2629  GNUNET_free (value);*/
2630 
2631  return topo;
2632 }
2633 
2634 
2643 {
2644  uint64_t fs;
2645  char *data;
2646  struct GNUNET_TESTING_NetjailTopology *topo;
2647 
2649  {
2651  _ ("Topology file %s not found\n"),
2652  filename);
2653  return NULL;
2654  }
2655  if (GNUNET_OK !=
2657  {
2659  _ ("Topology file %s has no data\n"),
2660  filename);
2661  return NULL;
2662  }
2663  data = GNUNET_malloc (fs + 1);
2664  if (fs != GNUNET_DISK_fn_read (filename, data, fs))
2665  {
2667  _ ("Topology file %s cannot be read\n"),
2668  filename);
2669  GNUNET_free (data);
2670  return NULL;
2671  }
2672 
2674  "file length %lu\n",
2675  fs);
2676  data[fs] = '\0';
2677 
2679 
2680  GNUNET_free (data);
2681 
2682  return topo;
2683 }
2684 
2685 
2686 /* end of testing.c */
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
char * getenv()
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:58
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
struct GNUNET_HashCode key
The key used in the DHT.
static char * filename
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
uint32_t data
The data value.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:84
static char * hostname
Our hostname; we give this to all the peers we start.
static struct GNUNET_FS_UnindexContext * uc
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
Convenience API for writing testcases for GNUnet.
@ GNUNET_TESTING_SUBNET_NODE
Node in a subnet.
@ GNUNET_TESTING_GLOBAL_NODE
Global known node.
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:577
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition: arm_api.c:602
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.
enum GNUNET_GenericReturnValue 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.
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
enum GNUNET_GenericReturnValue 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".
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...
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
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:197
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:1235
enum GNUNET_GenericReturnValue 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:482
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:686
enum GNUNET_GenericReturnValue 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:222
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:1378
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1085
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:340
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1409
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:664
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_MAP_TYPE_READ
Read-only memory map.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multishortmap_contains(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:855
enum GNUNET_GenericReturnValue 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:439
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 ...
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:672
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:741
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:981
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:280
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,...
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:217
@ GNUNET_OS_INHERIT_STD_OUT_AND_ERR
When these flags are set, the child process will inherit stdout and stderr of the parent.
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:705
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1467
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:458
#define GNUNET_TESTING_PREFIX
The environmental variable, if set, that dictates where testing should place generated peer configura...
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:373
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:1170
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.
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:714
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:1601
void(* GNUNET_TESTING_TestMain)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer)
Signature of the 'main' function for a (single-peer) testcase that is run using GNUNET_TESTING_peer_r...
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:538
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 'arm') and run a test u...
Definition: testing.c:1673
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1363
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a TCP or UDP port for a peer.
Definition: testing.c:580
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:676
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1543
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:1518
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:1149
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:1768
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer's main process.
Definition: testing.c:1412
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1559
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1444
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:1341
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
#define AI_NUMERICSERV
AI_NUMERICSERV not defined in windows.
Definition: platform.h:218
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:233
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:240
Handle for interacting with ARM.
Definition: arm_api.c:103
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED.
Definition: testing_cmds.h:85
enum GNUNET_GenericReturnValue result
Definition: testing_cmds.h:87
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.
Handle for a memory-mapping operation.
Definition: disk.c:1359
A 512-bit hashcode.
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
handle to a socket
Definition: network.c:53
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
Protocol address prefix für a connection between nodes.
struct GNUNET_TESTING_AddressPrefix * next
Pointer to the next prefix in the DLL.
char * address_prefix
The address prefix.
unsigned int namespace_n
The number of the subnet.
Node in the netjail topology.
unsigned int namespace_n
The number of the subnet this node is running in.
struct GNUNET_TESTING_NodeConnection * node_connections_head
Head of the DLL with the connections which shall be established to other nodes.
unsigned int is_global
Flag indicating if this node is a global known node.
char * plugin
Plugin for the test case to be run on this node.
unsigned int node_n
The number of this node in the subnet.
struct GNUNET_TESTING_NodeConnection * node_connections_tail
Tail of the DLL with the connections which shall be established to other nodes.
API for writing an interpreter to test GNUnet components.
unsigned int tcp_port
Will tcp be forwarded?
unsigned int udp_port
Will udp be forwarded?
struct GNUNET_CONTAINER_MultiShortmap * map_globals
Hash map containing the global known nodes which are not natted.
char * plugin
Default plugin for the test case to be run on nodes.
unsigned int nodes_m
Number of nodes per subnet.
unsigned int nodes_x
Number of global known nodes.
unsigned int namespaces_n
Number of subnets.
struct GNUNET_CONTAINER_MultiShortmap * map_namespaces
Hash map containing the subnets (for natted nodes) of the topology.
unsigned int additional_connects
Additional connects we do expect, beside the connects which are configured in the topology.
struct GNUNET_TESTING_AddressPrefix * address_prefixes_tail
Tail of the DLL with the address prefixes for the protocolls this node is reachable.
enum GNUNET_TESTING_NODE_TYPE node_type
The type of the node this connection points to.
struct GNUNET_TESTING_NodeConnection * next
Pointer to the next connection in the DLL.
unsigned int node_n
The number of the node this connection points to.
struct GNUNET_TESTING_NetjailNode * node
The node which establish the connection.
unsigned int namespace_n
The number of the subnet of the node this connection points to.
struct GNUNET_TESTING_AddressPrefix * address_prefixes_head
Head of the DLL with the address prefixes for the protocolls this node is reachable.
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:176
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:180
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running.
Definition: testing.c:200
unsigned int nports
The number of ports in the above array.
Definition: testing.c:240
char * main_binary
Binary to be executed during 'GNUNET_TESTING_peer_start'.
Definition: testing.c:193
struct GNUNET_CONFIGURATION_Handle * cfg
The config of the peer.
Definition: testing.c:210
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:235
struct SharedServiceInstance ** ss_instances
Definition: testing.c:228
struct GNUNET_PeerIdentity * id
The cached identity of this peer.
Definition: testing.c:226
struct GNUNET_ARM_Handle * ah
The handle to the peer's ARM service.
Definition: testing.c:205
uint32_t key_number
The keynumber of this peer's hostkey.
Definition: testing.c:245
void * cb_cls
The closure for the above callback.
Definition: testing.c:220
char * cfgfile
Path to the configuration file for this peer.
Definition: testing.c:185
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:215
Specification of a service that is to be shared among peers.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration template for the service.
unsigned int share
The number of peers which share an instance of the service.
const char * service
The name of the service.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:103
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:168
char * trusted_ip
The trusted ip.
Definition: testing.c:114
char * tmppath
Prefix (e.g.
Definition: testing.c:108
uint32_t total_hostkeys
The number of hostkeys.
Definition: testing.c:158
unsigned int n_shared_services
Definition: testing.c:133
char * hostname
our hostname
Definition: testing.c:119
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
Definition: testing.c:143
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:124
uint32_t path_counter
Counter we use to make service home paths unique on this system; the full path consists of the tmppat...
Definition: testing.c:153
struct SharedService ** shared_services
Definition: testing.c:131
struct GNUNET_DISK_MapHandle * map
memory map for hostkeys_data.
Definition: testing.c:129
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:163
Structure for holding service data.
Definition: testing.c:1614
struct GNUNET_TESTING_Peer * peer
The peer in which the service is run.
Definition: testing.c:1628
void * tm_cls
Closure for the above callback.
Definition: testing.c:1633
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer in which the service is run.
Definition: testing.c:1618
GNUNET_TESTING_TestMain tm
Callback to signal service startup.
Definition: testing.c:1623
unsigned int n_refs
Definition: testing.c:79
struct SharedService * ss
Definition: testing.c:69
struct GNUNET_OS_Process * proc
Definition: testing.c:73
The structure for identifying a shared service.
unsigned int share
Definition: testing.c:92
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:88
unsigned int n_instances
Definition: testing.c:94
struct SharedServiceInstance ** instances
Definition: testing.c:86
unsigned int n_peers
Definition: testing.c:90
char * sname
Definition: testing.c:84
Closure for update_rel_sum() and update_abs_sum().
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:765
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:748
char * gnunet_home
The customized service home path for this peer.
Definition: testing.c:758
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration we are building.
Definition: testing.c:753
unsigned int nports
The number of ports in the above array.
Definition: testing.c:770
int status
build status - to signal error while building a configuration
Definition: testing.c:775
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int free_nodes_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
Definition: testing.c:2195
static char * get_value(char *key, char *line)
Definition: testing.c:1874
static void disconn_status(void *cls, int connected)
Function called whenever we connect to or disconnect from ARM.
Definition: testing.c:1485
struct GNUNET_MessageHeader * GNUNET_TESTING_send_local_test_finished_msg(enum GNUNET_GenericReturnValue rv)
Create a GNUNET_CMDS_LOCAL_FINISHED message.
Definition: testing.c:2353
static int start_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:490
static void service_run_main(void *cls)
Callback to be called when SCHEDULER has been started.
Definition: testing.c:1643
char * GNUNET_TESTING_get_address(struct GNUNET_TESTING_NodeConnection *connection, char *prefix)
Get the address for a specific communicator from a connection.
Definition: testing.c:2289
#define HIGH_PORT
Highest port used for GNUnet testing.
Definition: testing.c:64
static void node_connections(char *line, struct GNUNET_TESTING_NetjailNode *node)
Definition: testing.c:1984
static void hostkeys_unload(struct GNUNET_TESTING_System *system)
Function to remove the loaded hostkeys.
Definition: testing.c:320
#define PREFIX_TCP
Definition: testing.c:47
struct GNUNET_TESTING_NetjailTopology * GNUNET_TESTING_get_topo_from_string(char *data)
Parse the topology data.
Definition: testing.c:2378
struct GNUNET_PeerIdentity * GNUNET_TESTING_get_pub_key(unsigned int num, const struct GNUNET_TESTING_System *tl_system)
Retrieve the public key from the test system with the unique node id.
Definition: testing.c:2172
static unsigned int get_second_value(char *line)
Definition: testing.c:1853
int free_namespaces_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
Definition: testing.c:2228
static void cleanup_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:474
static unsigned int get_first_value(char *line)
Definition: testing.c:1788
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:790
static struct SharedServiceInstance * associate_shared_service(struct GNUNET_TESTING_System *system, struct SharedService *ss, struct GNUNET_CONFIGURATION_Handle *cfg)
Definition: testing.c:993
struct GNUNET_TESTING_NodeConnection * GNUNET_TESTING_get_connections(unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology)
Get the connections to other nodes for a specific node.
Definition: testing.c:2097
static char * get_key(char *line)
Definition: testing.c:1808
static void stop_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:517
static int log_topo(struct GNUNET_TESTING_NetjailTopology *topology)
Definition: testing.c:2072
static char * get_first_string_value(char *line)
Definition: testing.c:1828
static struct GNUNET_TESTING_NodeConnection * get_connect_value(char *line, struct GNUNET_TESTING_NetjailNode *node)
Definition: testing.c:1902
unsigned int GNUNET_TESTING_calculate_num(struct GNUNET_TESTING_NodeConnection *node_connection, struct GNUNET_TESTING_NetjailTopology *topology)
Calculate the unique id identifying a node from a given connection.
Definition: testing.c:2263
#define LOG(kind,...)
Definition: testing.c:39
static void update_config_sections(void *cls, const char *section)
Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of 'trusted_hosts' in all sec...
Definition: testing.c:887
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:1086
#define CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:41
#define PREFIX_UDP
Definition: testing.c:49
struct GNUNET_TESTING_NetjailTopology * GNUNET_TESTING_get_topo_from_file(const char *filename)
Getting the topology from file.
Definition: testing.c:2642
#define LOW_PORT
Lowest port used for GNUnet testing.
Definition: testing.c:57
static void cfg_copy_iterator(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:340
static int log_nodes(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
Definition: testing.c:2025
#define KNOWN_CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:45
void GNUNET_TESTING_free_topology(struct GNUNET_TESTING_NetjailTopology *topology)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
Definition: testing.c:2249
#define ROUTER_CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:43
static int log_namespaces(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
Definition: testing.c:2062
static int hostkeys_load(struct GNUNET_TESTING_System *system)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:257
Message formats for communication between testing cmds helper and testcase plugins.