2 This file is part of GNUnet.
3 (C) 2004, 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file peerinfo/test_peerinfo_hammer.c
23 * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service
24 * @author Nathan Evans
28 #include "gnunet_hello_lib.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_os_lib.h"
31 #include "gnunet_peerinfo_service.h"
32 #include "gnunet_program_lib.h"
33 #include "gnunet_time_lib.h"
37 #define START_SERVICE 1
39 #define NUM_REQUESTS 5000
41 static const struct GNUNET_CONFIGURATION_Handle *cfg;
43 static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS];
45 static struct GNUNET_PEERINFO_Handle *h;
47 static unsigned int numpeers;
50 check_it (void *cls, const char *tname, struct GNUNET_TIME_Absolute expiration,
51 const void *addr, uint16_t addrlen)
56 fprintf (stderr, "name: %s, addr: %s\n", tname, (const char *) addr);
64 address_generator (void *cls, size_t max, void *buf)
73 GNUNET_asprintf (&address, "Address%d", *agc);
76 GNUNET_HELLO_add_address ("peerinfotest",
77 GNUNET_TIME_relative_to_absolute
78 (GNUNET_TIME_UNIT_HOURS), address,
79 strlen (address) + 1, buf, max);
80 GNUNET_free (address);
89 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
90 struct GNUNET_PeerIdentity pid;
91 struct GNUNET_HELLO_Message *h2;
93 memset (&pkey, i, sizeof (pkey));
94 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
95 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &i);
96 GNUNET_PEERINFO_add_peer (h, h2);
102 process (void *cls, const struct GNUNET_PeerIdentity *peer,
103 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
108 fprintf (stderr, "Process received NULL response\n");
114 fprintf (stderr, "Processed a peer\n");
117 if (0 && (hello != NULL))
118 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL);
125 run (void *cls, char *const *args, const char *cfgfile,
126 const struct GNUNET_CONFIGURATION_Handle *c)
131 h = GNUNET_PEERINFO_connect (cfg);
132 GNUNET_assert (h != NULL);
133 for (i = 0; i < NUM_REQUESTS; i++)
137 GNUNET_PEERINFO_iterate (h, NULL,
138 GNUNET_TIME_relative_multiply
139 (GNUNET_TIME_UNIT_SECONDS, 30), &process, cls);
148 char *const argv[] = { "perf-peerinfo-api",
150 "test_peerinfo_api_data.conf",
159 struct GNUNET_OS_Process *proc;
161 struct GNUNET_GETOPT_CommandLineOption options[] = {
162 GNUNET_GETOPT_OPTION_END
165 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo",
166 "gnunet-service-peerinfo",
172 "-c", "test_peerinfo_api_data.conf", NULL);
174 GNUNET_assert (NULL != proc);
175 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
176 "perf-peerinfo-api", "nohelp", options, &run, &ok);
177 fprintf (stderr, "Received %u/%u calls before timeout\n", numpeers,
178 NUM_REQUESTS * NUM_REQUESTS / 2);
179 GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s");
181 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
183 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
186 GNUNET_OS_process_wait (proc);
187 GNUNET_OS_process_close (proc);
196 main (int argc, char *argv[])
200 GNUNET_log_setup ("perf_peerinfo_api",
208 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo");
212 /* end of perf_peerinfo_api.c */