2 This file is part of GNUnet.
3 (C) 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 fs/perf_gnunet_service_fs_p2p.c
23 * @brief profile P2P routing using simple publish + download operation
24 * @author Christian Grothoff
27 #include "fs_test_lib.h"
28 #include "gnunet_testing_lib.h"
30 #define VERBOSE GNUNET_NO
33 * File-size we use for testing.
35 #define FILESIZE (1024 * 1024 * 1)
38 * How long until we give up on transmitting the message?
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3)
46 static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
48 static struct GNUNET_SCHEDULER_Handle *sched;
52 static struct GNUNET_TIME_Absolute start_time;
56 const struct GNUNET_SCHEDULER_TaskContext *tc)
58 GNUNET_FS_TEST_daemons_stop (sched,
65 * Master context for 'stat_run'.
69 struct GNUNET_STATISTICS_Handle *stat;
76 const char *subsystem;
81 * Statistics we print out.
83 static struct StatValues stats[] =
85 { "fs", "queries forwarded"},
86 { "fs", "replies received and matched"},
87 { "core", "bytes decrypted"},
88 { "core", "bytes encrypted"},
89 { "transport", "bytes received via TCP"},
90 { "transport", "bytes transmitted via TCP"},
91 { "datacache", "bytes stored"},
92 { "dht", "DHT ROUTE Requests Seen"},
93 { "dht", "DHT ROUTE Requests Forwarded"},
99 * Callback function to process statistic values.
102 * @param subsystem name of subsystem that created the statistic
103 * @param name the name of the datum
104 * @param value the current value
105 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
106 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
109 print_stat (void *cls,
110 const char *subsystem,
115 struct StatMaster *sm = cls;
117 "Peer %3u: %8s/%40s = %llu\n",
121 (unsigned long long) value);
126 * Function that gathers stats from all daemons.
130 const struct GNUNET_SCHEDULER_TaskContext *tc);
133 * Function called when GET operation on stats is done.
139 struct StatMaster *sm = cls;
140 GNUNET_break (GNUNET_OK == success);
142 GNUNET_SCHEDULER_add_now (sched, &stat_run, sm);
146 * Function that gathers stats from all daemons.
150 const struct GNUNET_SCHEDULER_TaskContext *tc)
152 struct StatMaster *sm = cls;
154 if (stats[sm->value].name != NULL)
156 GNUNET_STATISTICS_get (sm->stat,
157 stats[sm->value].subsystem,
158 stats[sm->value].name,
159 GNUNET_TIME_UNIT_FOREVER_REL,
164 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
167 if (sm->daemon == NUM_DAEMONS)
170 GNUNET_SCHEDULER_add_now (sched, &do_stop, NULL);
173 sm->stat = GNUNET_STATISTICS_create (sched, "<driver>",
174 GNUNET_FS_TEST_get_configuration (daemons,
176 GNUNET_SCHEDULER_add_now (sched, &stat_run, sm);
181 do_report (void *cls,
182 const struct GNUNET_SCHEDULER_TaskContext *tc)
184 struct GNUNET_TIME_Relative del;
186 struct StatMaster *sm;
188 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
190 del = GNUNET_TIME_absolute_get_duration (start_time);
193 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.value);
195 "Download speed was %s/s\n",
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
199 "Finished download, shutting down\n",
200 (unsigned long long) FILESIZE);
201 sm = GNUNET_malloc (sizeof (struct StatMaster));
202 sm->stat = GNUNET_STATISTICS_create (sched, "<driver>",
203 GNUNET_FS_TEST_get_configuration (daemons,
205 GNUNET_SCHEDULER_add_now (sched, &stat_run, sm);
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Timeout during download, shutting down with error\n");
212 GNUNET_SCHEDULER_add_now (sched, &do_stop, NULL);
218 do_download (void *cls,
219 const struct GNUNET_FS_Uri *uri)
223 GNUNET_FS_TEST_daemons_stop (sched,
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
227 "Timeout during upload attempt, shutting down with error\n");
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
232 "Downloading %llu bytes\n",
233 (unsigned long long) FILESIZE);
234 start_time = GNUNET_TIME_absolute_get ();
235 GNUNET_FS_TEST_download (sched,
245 do_publish (void *cls,
250 GNUNET_FS_TEST_daemons_stop (sched,
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
254 "Error trying to connect: %s\n",
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Publishing %llu bytes\n",
261 (unsigned long long) FILESIZE);
262 GNUNET_FS_TEST_publish (sched,
263 daemons[NUM_DAEMONS-1],
265 1, GNUNET_NO, FILESIZE, SEED,
272 do_connect (void *cls,
273 const struct GNUNET_SCHEDULER_TaskContext *tc)
275 struct GNUNET_TESTING_PeerGroup *pg;
277 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
279 "Daemons started, will now try to connect them\n");
280 pg = GNUNET_FS_TEST_get_group (daemons);
281 GNUNET_break ( (NUM_DAEMONS - 1) * 2
282 == (GNUNET_TESTING_create_topology (pg,
283 GNUNET_TESTING_TOPOLOGY_LINE,
284 GNUNET_TESTING_TOPOLOGY_NONE,
286 GNUNET_TESTING_connect_topology (pg,
287 GNUNET_TESTING_TOPOLOGY_LINE,
288 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
297 struct GNUNET_SCHEDULER_Handle *s,
300 const struct GNUNET_CONFIGURATION_Handle *cfg)
303 GNUNET_FS_TEST_daemons_start (sched,
304 "fs_test_lib_data.conf",
314 main (int argc, char *argv[])
316 char *const argvx[] = {
317 "perf-gnunet-service-fs-p2p",
319 "fs_test_lib_data.conf",
325 struct GNUNET_GETOPT_CommandLineOption options[] = {
326 GNUNET_GETOPT_OPTION_END
329 GNUNET_DISK_directory_remove ("/tmp/gnunet-perf-fs-lib/");
330 GNUNET_log_setup ("perf_gnunet_service_fs_p2p",
337 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
338 argvx, "perf-gnunet-service-fs-p2p",
339 "nohelp", options, &run, NULL);
340 GNUNET_DISK_directory_remove ("/tmp/gnunet-perf-fs-lib/");
344 /* end of perf_gnunet_service_fs_p2p.c */