2 This file is part of GNUnet.
3 Copyright (C) 2004, 2009, 2010, 2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU 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.
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.
17 * @file peerinfo/perf_peerinfo_api.c
18 * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service,
19 * this performance test adds up to 5000 peers with one address each and checks
20 * over how many peers it can iterate before receiving a timeout after 5 seconds
21 * @author Nathan Evans
25 #include "gnunet_hello_lib.h"
26 #include "gnunet_util_lib.h"
27 #include "gnunet_testing_lib.h"
28 #include "gnunet_peerinfo_service.h"
32 #define NUM_REQUESTS 5000
34 static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS];
36 static struct GNUNET_PEERINFO_Handle *h;
38 static unsigned int numpeers;
40 static struct GNUNET_PeerIdentity pid;
42 static struct GNUNET_SCHEDULER_Task *tt;
46 do_shutdown (void *cls)
50 GNUNET_SCHEDULER_cancel (tt);
53 for (unsigned int i = 0; i < NUM_REQUESTS; i++)
55 GNUNET_PEERINFO_iterate_cancel (ic[i]);
56 GNUNET_PEERINFO_disconnect (h);
62 do_timeout (void *cls)
65 GNUNET_SCHEDULER_shutdown ();
71 const struct GNUNET_HELLO_Address *address,
72 struct GNUNET_TIME_Absolute expiration)
79 address_generator (void *cls, size_t max, void *buf)
84 struct GNUNET_HELLO_Address address;
87 return GNUNET_SYSERR; /* Done */
89 GNUNET_asprintf (&caddress, "Address%d", *agc);
91 address.address_length = strlen (caddress) + 1;
92 address.address = caddress;
93 address.transport_name = "peerinfotest";
95 GNUNET_HELLO_add_address (&address,
96 GNUNET_TIME_relative_to_absolute
97 (GNUNET_TIME_UNIT_HOURS), buf, max);
98 GNUNET_free (caddress);
107 struct GNUNET_HELLO_Message *h2;
109 memset (&pid, i, sizeof (pid));
110 h2 = GNUNET_HELLO_create (&pid.public_key,
114 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
121 const struct GNUNET_PeerIdentity *peer,
122 const struct GNUNET_HELLO_Message *hello,
125 struct GNUNET_PEERINFO_IteratorContext **icp = cls;
133 if (0 && (NULL != hello) )
134 GNUNET_HELLO_iterate_addresses (hello,
143 const struct GNUNET_CONFIGURATION_Handle *cfg,
144 struct GNUNET_TESTING_Peer *peer)
146 h = GNUNET_PEERINFO_connect (cfg);
147 GNUNET_assert (h != NULL);
148 for (unsigned int i = 0; i < NUM_REQUESTS; i++)
151 ic[i] = GNUNET_PEERINFO_iterate (h,
157 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
161 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
170 if (0 != GNUNET_TESTING_service_run ("perf-gnunet-peerinfo",
172 "test_peerinfo_api_data.conf",
176 "Received %u/%u calls before timeout\n",
178 NUM_REQUESTS * NUM_REQUESTS / 2);
186 /* end of perf_peerinfo_api.c */