aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/perf_peerinfo_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo/perf_peerinfo_api.c')
-rwxr-xr-xsrc/peerinfo/perf_peerinfo_api.c217
1 files changed, 217 insertions, 0 deletions
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c
new file mode 100755
index 000000000..1c0df0332
--- /dev/null
+++ b/src/peerinfo/perf_peerinfo_api.c
@@ -0,0 +1,217 @@
1/*
2 This file is part of GNUnet.
3 (C) 2004, 2009 Christian Grothoff (and other contributing authors)
4
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.
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 General Public License for more details.
14
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.
19*/
20
21/**
22 * @file peerinfo/test_peerinfo_hammer.c
23 * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service
24 * @author Nathan Evans
25 */
26
27#include "platform.h"
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"
34#include "peerinfo.h"
35
36#define START_SERVICE 1
37
38#define NUM_REQUESTS 5000
39
40static struct GNUNET_SCHEDULER_Handle *sched;
41
42static const struct GNUNET_CONFIGURATION_Handle *cfg;
43
44static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS];
45
46static struct GNUNET_PEERINFO_Handle *h;
47
48static unsigned int numpeers;
49
50static int
51check_it (void *cls,
52 const char *tname,
53 struct GNUNET_TIME_Absolute expiration,
54 const void *addr, uint16_t addrlen)
55{
56 if (addrlen > 0)
57 {
58#if DEBUG
59 fprintf (stderr,
60 "name: %s, addr: %s\n",
61 tname,
62 (const char*) addr);
63#endif
64 }
65 return GNUNET_OK;
66}
67
68
69static size_t
70address_generator (void *cls, size_t max, void *buf)
71{
72 size_t *agc = cls;
73 size_t ret;
74 char *address;
75
76 if (*agc == 0)
77 return 0;
78
79 GNUNET_asprintf(&address, "Address%d", *agc);
80
81 ret = GNUNET_HELLO_add_address ("peerinfotest",
82 GNUNET_TIME_relative_to_absolute
83 (GNUNET_TIME_UNIT_HOURS), address, strlen(address) + 1,
84 buf, max);
85 *agc = 0;
86 return ret;
87}
88
89
90static void
91add_peer (size_t i)
92{
93 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
94 struct GNUNET_PeerIdentity pid;
95 struct GNUNET_HELLO_Message *h2;
96 size_t agc;
97
98 agc = 2;
99 memset (&pkey, i, sizeof (pkey));
100 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
101 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &i);
102 GNUNET_PEERINFO_add_peer (h, h2);
103 GNUNET_free (h2);
104}
105
106
107static void
108process (void *cls,
109 const struct GNUNET_PeerIdentity *peer,
110 const struct GNUNET_HELLO_Message *hello)
111{
112 if (peer == NULL)
113 {
114#if DEBUG
115 fprintf(stderr, "Process received NULL response\n");
116#endif
117 }
118 else
119 {
120#if DEBUG
121 fprintf(stderr, "Processed a peer\n");
122#endif
123 numpeers++;
124 if (0 && (hello != NULL))
125 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL);
126
127 }
128}
129
130
131static void
132run (void *cls,
133 struct GNUNET_SCHEDULER_Handle *s,
134 char *const *args,
135 const char *cfgfile,
136 const struct GNUNET_CONFIGURATION_Handle *c)
137{
138 size_t i;
139 sched = s;
140 cfg = c;
141 h = GNUNET_PEERINFO_connect (sched, cfg);
142
143 for (i = 0; i < NUM_REQUESTS; i++)
144 {
145 add_peer (i);
146 ic[i] = GNUNET_PEERINFO_iterate (h,
147 NULL,
148 GNUNET_TIME_relative_multiply
149 (GNUNET_TIME_UNIT_SECONDS, 30),
150 &process, cls);
151 }
152 fprintf (stderr,
153 "Issued %u requests\n",
154 NUM_REQUESTS);
155}
156
157static int
158check ()
159{
160 int ok = 3;
161 char *const argv[] = { "test-peerinfo-hammer",
162 "-c",
163 "test_peerinfo_api_data.conf",
164#if DEBUG_PEERINFO
165 "-L", "DEBUG",
166#endif
167 NULL
168 };
169#if START_SERVICE
170 pid_t pid;
171 struct GNUNET_GETOPT_CommandLineOption options[] = {
172 GNUNET_GETOPT_OPTION_END
173 };
174 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo",
175 "gnunet-service-peerinfo",
176#if DEBUG_PEERINFO
177 "-L", "DEBUG",
178#endif
179 "-c", "test_peerinfo_api_data.conf", NULL);
180#endif
181 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
182 argv, "test-peerinfo-api", "nohelp",
183 options, &run, &ok);
184 fprintf (stderr,
185 "Processed %u/%u peers\n",
186 numpeers,
187 NUM_REQUESTS);
188#if START_SERVICE
189 if (0 != PLIBC_KILL (pid, SIGTERM))
190 {
191 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
192 ok = 1;
193 }
194 GNUNET_OS_process_wait(pid);
195#endif
196 return ok;
197}
198
199
200int
201main (int argc, char *argv[])
202{
203 int ret = 0;
204
205 GNUNET_log_setup ("test_peerinfo_api",
206#if DEBUG_PEERINFO
207 "DEBUG",
208#else
209 "WARNING",
210#endif
211 NULL);
212 ret = check ();
213 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo");
214 return ret;
215}
216
217/* end of test_peerinfo_hammer.c */