2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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_testbed_service.h"
30 #define VERBOSE GNUNET_NO
33 * File-size we use for testing.
35 #define FILESIZE (1024 * 1024 * 10)
38 * How long until we give up on transmitting the message?
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
46 static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
50 static struct GNUNET_TIME_Absolute start_time;
52 static const char *progname;
54 static struct GNUNET_TIME_Absolute start_time;
58 * Master context for 'stat_run'.
62 struct GNUNET_STATISTICS_Handle *stat;
63 struct GNUNET_TESTBED_Operation *op;
70 const char *subsystem;
75 * Statistics we print out.
77 static struct StatValues stats[] = {
78 { "fs", "# queries forwarded" },
79 { "fs", "# replies received and matched" },
80 { "fs", "# results found locally" },
81 { "fs", "# requests forwarded due to high load" },
82 { "fs", "# requests done for free (low load)" },
83 { "fs", "# requests dropped, priority insufficient" },
84 { "fs", "# requests done for a price (normal load)" },
85 { "fs", "# requests dropped by datastore (queue length limit)" },
86 { "fs", "# P2P searches received" },
87 { "fs", "# P2P searches discarded (queue length bound)" },
88 { "fs", "# replies received for local clients" },
89 { "fs", "# queries retransmitted to same target" },
90 { "core", "# bytes decrypted" },
91 { "core", "# bytes encrypted" },
92 { "core", "# discarded CORE_SEND requests" },
93 { "core", "# discarded CORE_SEND request bytes" },
94 { "core", "# discarded lower priority CORE_SEND requests" },
95 { "core", "# discarded lower priority CORE_SEND request bytes" },
96 { "transport", "# bytes received via TCP" },
97 { "transport", "# bytes transmitted via TCP" },
98 { "datacache", "# bytes stored" },
104 * Callback function to process statistic values.
107 * @param subsystem name of subsystem that created the statistic
108 * @param name the name of the datum
109 * @param value the current value
110 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
111 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
114 print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
117 struct StatMaster *sm = cls;
120 "Peer %2u: %12s/%50s = %12llu\n",
124 (unsigned long long) value);
130 * Function that gathers stats from all daemons.
134 struct GNUNET_TESTBED_Operation *op,
140 * Function called when GET operation on stats is done.
143 get_done (void *cls, int success)
145 struct StatMaster *sm = cls;
147 GNUNET_break (GNUNET_OK == success);
149 stat_run (sm, sm->op, sm->stat, NULL);
154 * Adapter function called to establish a connection to
155 * statistics service.
158 * @param cfg configuration of the peer to connect to; will be available until
159 * GNUNET_TESTBED_operation_done() is called on the operation returned
160 * from GNUNET_TESTBED_service_connect()
161 * @return service handle to return in 'op_result', NULL on error
164 statistics_connect_adapter (void *cls,
165 const struct GNUNET_CONFIGURATION_Handle *cfg)
167 return GNUNET_STATISTICS_create ("<driver>",
173 * Adapter function called to destroy a connection to
174 * statistics service.
177 * @param op_result service handle returned from the connect adapter
180 statistics_disconnect_adapter (void *cls,
183 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
188 * Function that gathers stats from all daemons.
192 struct GNUNET_TESTBED_Operation *op,
196 struct StatMaster *sm = cls;
200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
201 "Failed to statistics service: %s\n",
203 GNUNET_SCHEDULER_shutdown ();
206 sm->stat = ca_result;
208 if (stats[sm->value].name != NULL)
210 GNUNET_STATISTICS_get (sm->stat,
214 stats[sm->value].subsystem, stats[sm->value].name,
216 &get_done, &print_stat,
220 GNUNET_TESTBED_operation_done (sm->op);
223 if (NUM_DAEMONS == sm->daemon)
226 GNUNET_SCHEDULER_shutdown ();
230 GNUNET_TESTBED_service_connect (NULL,
234 &statistics_connect_adapter,
235 &statistics_disconnect_adapter,
241 do_report (void *cls)
244 struct GNUNET_TIME_Relative del;
246 struct StatMaster *sm;
250 GNUNET_DISK_directory_remove (fn);
254 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
259 "Timeout during download, shutting down with error\n");
261 GNUNET_SCHEDULER_shutdown ();
265 del = GNUNET_TIME_absolute_get_duration (start_time);
266 if (del.rel_value_us == 0)
267 del.rel_value_us = 1;
269 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE)
270 * 1000000LL / del.rel_value_us);
272 "Download speed was %s/s\n",
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
276 "Finished download, shutting down\n");
277 sm = GNUNET_new (struct StatMaster);
279 GNUNET_TESTBED_service_connect (NULL,
283 &statistics_connect_adapter,
284 &statistics_disconnect_adapter,
290 do_download (void *cls,
291 const struct GNUNET_FS_Uri *uri,
298 GNUNET_SCHEDULER_shutdown ();
299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
300 "Timeout during upload attempt, shutting down with error\n");
304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
305 (unsigned long long) FILESIZE);
306 start_time = GNUNET_TIME_absolute_get ();
307 if (NULL != strstr (progname, "dht"))
311 start_time = GNUNET_TIME_absolute_get ();
312 GNUNET_FS_TEST_download (daemons[0],
319 (NULL == fn) ? NULL : GNUNET_strdup (fn));
324 do_publish (void *cls,
325 struct GNUNET_TESTBED_RunHandle *h,
326 unsigned int num_peers,
327 struct GNUNET_TESTBED_Peer **peers,
328 unsigned int links_succeeded,
329 unsigned int links_failed)
335 GNUNET_assert (NUM_DAEMONS == num_peers);
336 for (i = 0; i < num_peers; i++)
337 daemons[i] = peers[i];
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
339 (unsigned long long) FILESIZE);
340 if (NULL != strstr (progname, "index"))
341 do_index = GNUNET_YES;
343 do_index = GNUNET_NO;
344 if (NULL != strstr (progname, "dht"))
348 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
349 do_index, FILESIZE, SEED, VERBOSE, &do_download,
355 main (int argc, char *argv[])
358 (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p",
359 "perf_gnunet_service_fs_p2p.conf",
363 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
368 /* end of perf_gnunet_service_fs_p2p.c */