summaryrefslogtreecommitdiff
path: root/src/fs/perf_gnunet_service_fs_p2p.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/perf_gnunet_service_fs_p2p.c')
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p.c312
1 files changed, 155 insertions, 157 deletions
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c
index 0d76dfc3d..515144eb1 100644
--- a/src/fs/perf_gnunet_service_fs_p2p.c
+++ b/src/fs/perf_gnunet_service_fs_p2p.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file fs/perf_gnunet_service_fs_p2p.c 22 * @file fs/perf_gnunet_service_fs_p2p.c
@@ -37,7 +37,7 @@
37/** 37/**
38 * How long until we give up on transmitting the message? 38 * How long until we give up on transmitting the message?
39 */ 39 */
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) 40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30)
41 41
42#define NUM_DAEMONS 2 42#define NUM_DAEMONS 2
43 43
@@ -57,16 +57,14 @@ static struct GNUNET_TIME_Absolute start_time;
57/** 57/**
58 * Master context for 'stat_run'. 58 * Master context for 'stat_run'.
59 */ 59 */
60struct StatMaster 60struct StatMaster {
61{
62 struct GNUNET_STATISTICS_Handle *stat; 61 struct GNUNET_STATISTICS_Handle *stat;
63 struct GNUNET_TESTBED_Operation *op; 62 struct GNUNET_TESTBED_Operation *op;
64 unsigned int daemon; 63 unsigned int daemon;
65 unsigned int value; 64 unsigned int value;
66}; 65};
67 66
68struct StatValues 67struct StatValues {
69{
70 const char *subsystem; 68 const char *subsystem;
71 const char *name; 69 const char *name;
72}; 70};
@@ -75,28 +73,28 @@ struct StatValues
75 * Statistics we print out. 73 * Statistics we print out.
76 */ 74 */
77static struct StatValues stats[] = { 75static struct StatValues stats[] = {
78 {"fs", "# queries forwarded"}, 76 { "fs", "# queries forwarded" },
79 {"fs", "# replies received and matched"}, 77 { "fs", "# replies received and matched" },
80 {"fs", "# results found locally"}, 78 { "fs", "# results found locally" },
81 {"fs", "# requests forwarded due to high load"}, 79 { "fs", "# requests forwarded due to high load" },
82 {"fs", "# requests done for free (low load)"}, 80 { "fs", "# requests done for free (low load)" },
83 {"fs", "# requests dropped, priority insufficient"}, 81 { "fs", "# requests dropped, priority insufficient" },
84 {"fs", "# requests done for a price (normal load)"}, 82 { "fs", "# requests done for a price (normal load)" },
85 {"fs", "# requests dropped by datastore (queue length limit)"}, 83 { "fs", "# requests dropped by datastore (queue length limit)" },
86 {"fs", "# P2P searches received"}, 84 { "fs", "# P2P searches received" },
87 {"fs", "# P2P searches discarded (queue length bound)"}, 85 { "fs", "# P2P searches discarded (queue length bound)" },
88 {"fs", "# replies received for local clients"}, 86 { "fs", "# replies received for local clients" },
89 {"fs", "# queries retransmitted to same target"}, 87 { "fs", "# queries retransmitted to same target" },
90 {"core", "# bytes decrypted"}, 88 { "core", "# bytes decrypted" },
91 {"core", "# bytes encrypted"}, 89 { "core", "# bytes encrypted" },
92 {"core", "# discarded CORE_SEND requests"}, 90 { "core", "# discarded CORE_SEND requests" },
93 {"core", "# discarded CORE_SEND request bytes"}, 91 { "core", "# discarded CORE_SEND request bytes" },
94 {"core", "# discarded lower priority CORE_SEND requests"}, 92 { "core", "# discarded lower priority CORE_SEND requests" },
95 {"core", "# discarded lower priority CORE_SEND request bytes"}, 93 { "core", "# discarded lower priority CORE_SEND request bytes" },
96 {"transport", "# bytes received via TCP"}, 94 { "transport", "# bytes received via TCP" },
97 {"transport", "# bytes transmitted via TCP"}, 95 { "transport", "# bytes transmitted via TCP" },
98 {"datacache", "# bytes stored"}, 96 { "datacache", "# bytes stored" },
99 {NULL, NULL} 97 { NULL, NULL }
100}; 98};
101 99
102 100
@@ -111,17 +109,17 @@ static struct StatValues stats[] = {
111 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 109 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
112 */ 110 */
113static int 111static int
114print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, 112print_stat(void *cls, const char *subsystem, const char *name, uint64_t value,
115 int is_persistent) 113 int is_persistent)
116{ 114{
117 struct StatMaster *sm = cls; 115 struct StatMaster *sm = cls;
118 116
119 fprintf (stderr, 117 fprintf(stderr,
120 "Peer %2u: %12s/%50s = %12llu\n", 118 "Peer %2u: %12s/%50s = %12llu\n",
121 sm->daemon, 119 sm->daemon,
122 subsystem, 120 subsystem,
123 name, 121 name,
124 (unsigned long long) value); 122 (unsigned long long)value);
125 return GNUNET_OK; 123 return GNUNET_OK;
126} 124}
127 125
@@ -130,23 +128,23 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
130 * Function that gathers stats from all daemons. 128 * Function that gathers stats from all daemons.
131 */ 129 */
132static void 130static void
133stat_run (void *cls, 131stat_run(void *cls,
134 struct GNUNET_TESTBED_Operation *op, 132 struct GNUNET_TESTBED_Operation *op,
135 void *ca_result, 133 void *ca_result,
136 const char *emsg); 134 const char *emsg);
137 135
138 136
139/** 137/**
140 * Function called when GET operation on stats is done. 138 * Function called when GET operation on stats is done.
141 */ 139 */
142static void 140static void
143get_done (void *cls, int success) 141get_done(void *cls, int success)
144{ 142{
145 struct StatMaster *sm = cls; 143 struct StatMaster *sm = cls;
146 144
147 GNUNET_break (GNUNET_OK == success); 145 GNUNET_break(GNUNET_OK == success);
148 sm->value++; 146 sm->value++;
149 stat_run (sm, sm->op, sm->stat, NULL); 147 stat_run(sm, sm->op, sm->stat, NULL);
150} 148}
151 149
152 150
@@ -161,11 +159,11 @@ get_done (void *cls, int success)
161 * @return service handle to return in 'op_result', NULL on error 159 * @return service handle to return in 'op_result', NULL on error
162 */ 160 */
163static void * 161static void *
164statistics_connect_adapter (void *cls, 162statistics_connect_adapter(void *cls,
165 const struct GNUNET_CONFIGURATION_Handle *cfg) 163 const struct GNUNET_CONFIGURATION_Handle *cfg)
166{ 164{
167 return GNUNET_STATISTICS_create ("<driver>", 165 return GNUNET_STATISTICS_create("<driver>",
168 cfg); 166 cfg);
169} 167}
170 168
171 169
@@ -177,10 +175,10 @@ statistics_connect_adapter (void *cls,
177 * @param op_result service handle returned from the connect adapter 175 * @param op_result service handle returned from the connect adapter
178 */ 176 */
179static void 177static void
180statistics_disconnect_adapter (void *cls, 178statistics_disconnect_adapter(void *cls,
181 void *op_result) 179 void *op_result)
182{ 180{
183 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); 181 GNUNET_STATISTICS_destroy(op_result, GNUNET_NO);
184} 182}
185 183
186 184
@@ -188,57 +186,57 @@ statistics_disconnect_adapter (void *cls,
188 * Function that gathers stats from all daemons. 186 * Function that gathers stats from all daemons.
189 */ 187 */
190static void 188static void
191stat_run (void *cls, 189stat_run(void *cls,
192 struct GNUNET_TESTBED_Operation *op, 190 struct GNUNET_TESTBED_Operation *op,
193 void *ca_result, 191 void *ca_result,
194 const char *emsg) 192 const char *emsg)
195{ 193{
196 struct StatMaster *sm = cls; 194 struct StatMaster *sm = cls;
197 195
198 if (NULL != emsg) 196 if (NULL != emsg)
199 { 197 {
200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 198 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
201 "Failed to statistics service: %s\n", 199 "Failed to statistics service: %s\n",
202 emsg); 200 emsg);
203 GNUNET_SCHEDULER_shutdown (); 201 GNUNET_SCHEDULER_shutdown();
204 return; 202 return;
205 } 203 }
206 sm->stat = ca_result; 204 sm->stat = ca_result;
207 205
208 if (stats[sm->value].name != NULL) 206 if (stats[sm->value].name != NULL)
209 { 207 {
210 GNUNET_STATISTICS_get (sm->stat, 208 GNUNET_STATISTICS_get(sm->stat,
211#if 0 209#if 0
212 NULL, NULL, 210 NULL, NULL,
213#else 211#else
214 stats[sm->value].subsystem, stats[sm->value].name, 212 stats[sm->value].subsystem, stats[sm->value].name,
215#endif 213#endif
216 &get_done, &print_stat, 214 &get_done, &print_stat,
217 sm); 215 sm);
218 return; 216 return;
219 } 217 }
220 GNUNET_TESTBED_operation_done (sm->op); 218 GNUNET_TESTBED_operation_done(sm->op);
221 sm->value = 0; 219 sm->value = 0;
222 sm->daemon++; 220 sm->daemon++;
223 if (NUM_DAEMONS == sm->daemon) 221 if (NUM_DAEMONS == sm->daemon)
224 { 222 {
225 GNUNET_free (sm); 223 GNUNET_free(sm);
226 GNUNET_SCHEDULER_shutdown (); 224 GNUNET_SCHEDULER_shutdown();
227 return; 225 return;
228 } 226 }
229 sm->op = 227 sm->op =
230 GNUNET_TESTBED_service_connect (NULL, 228 GNUNET_TESTBED_service_connect(NULL,
231 daemons[sm->daemon], 229 daemons[sm->daemon],
232 "statistics", 230 "statistics",
233 &stat_run, sm, 231 &stat_run, sm,
234 &statistics_connect_adapter, 232 &statistics_connect_adapter,
235 &statistics_disconnect_adapter, 233 &statistics_disconnect_adapter,
236 NULL); 234 NULL);
237} 235}
238 236
239 237
240static void 238static void
241do_report (void *cls) 239do_report(void *cls)
242{ 240{
243 char *fn = cls; 241 char *fn = cls;
244 struct GNUNET_TIME_Relative del; 242 struct GNUNET_TIME_Relative del;
@@ -246,120 +244,120 @@ do_report (void *cls)
246 struct StatMaster *sm; 244 struct StatMaster *sm;
247 245
248 if (NULL != fn) 246 if (NULL != fn)
249 { 247 {
250 GNUNET_DISK_directory_remove (fn); 248 GNUNET_DISK_directory_remove(fn);
251 GNUNET_free (fn); 249 GNUNET_free(fn);
252 } 250 }
253 if (0 == 251 if (0 ==
254 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, 252 GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time,
255 TIMEOUT)).rel_value_us) 253 TIMEOUT)).rel_value_us)
256 { 254 {
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 255 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
258 "Timeout during download, shutting down with error\n"); 256 "Timeout during download, shutting down with error\n");
259 ok = 1; 257 ok = 1;
260 GNUNET_SCHEDULER_shutdown (); 258 GNUNET_SCHEDULER_shutdown();
261 return; 259 return;
262 } 260 }
263 261
264 del = GNUNET_TIME_absolute_get_duration (start_time); 262 del = GNUNET_TIME_absolute_get_duration(start_time);
265 if (del.rel_value_us == 0) 263 if (del.rel_value_us == 0)
266 del.rel_value_us = 1; 264 del.rel_value_us = 1;
267 fancy = 265 fancy =
268 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 266 GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) *
269 1000000LL / del.rel_value_us); 267 1000000LL / del.rel_value_us);
270 fprintf (stdout, 268 fprintf(stdout,
271 "Download speed was %s/s\n", 269 "Download speed was %s/s\n",
272 fancy); 270 fancy);
273 GNUNET_free (fancy); 271 GNUNET_free(fancy);
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
275 "Finished download, shutting down\n"); 273 "Finished download, shutting down\n");
276 sm = GNUNET_new (struct StatMaster); 274 sm = GNUNET_new(struct StatMaster);
277 sm->op = 275 sm->op =
278 GNUNET_TESTBED_service_connect (NULL, 276 GNUNET_TESTBED_service_connect(NULL,
279 daemons[sm->daemon], 277 daemons[sm->daemon],
280 "statistics", 278 "statistics",
281 &stat_run, sm, 279 &stat_run, sm,
282 &statistics_connect_adapter, 280 &statistics_connect_adapter,
283 &statistics_disconnect_adapter, 281 &statistics_disconnect_adapter,
284 NULL); 282 NULL);
285} 283}
286 284
287 285
288static void 286static void
289do_download (void *cls, 287do_download(void *cls,
290 const struct GNUNET_FS_Uri *uri, 288 const struct GNUNET_FS_Uri *uri,
291 const char *fn) 289 const char *fn)
292{ 290{
293 int anonymity; 291 int anonymity;
294 292
295 if (NULL == uri) 293 if (NULL == uri)
296 { 294 {
297 GNUNET_SCHEDULER_shutdown (); 295 GNUNET_SCHEDULER_shutdown();
298 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 296 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
299 "Timeout during upload attempt, shutting down with error\n"); 297 "Timeout during upload attempt, shutting down with error\n");
300 ok = 1; 298 ok = 1;
301 return; 299 return;
302 } 300 }
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", 301 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
304 (unsigned long long) FILESIZE); 302 (unsigned long long)FILESIZE);
305 start_time = GNUNET_TIME_absolute_get (); 303 start_time = GNUNET_TIME_absolute_get();
306 if (NULL != strstr (progname, "dht")) 304 if (NULL != strstr(progname, "dht"))
307 anonymity = 0; 305 anonymity = 0;
308 else 306 else
309 anonymity = 1; 307 anonymity = 1;
310 start_time = GNUNET_TIME_absolute_get (); 308 start_time = GNUNET_TIME_absolute_get();
311 GNUNET_FS_TEST_download (daemons[0], 309 GNUNET_FS_TEST_download(daemons[0],
312 TIMEOUT, 310 TIMEOUT,
313 anonymity, 311 anonymity,
314 SEED, 312 SEED,
315 uri, 313 uri,
316 VERBOSE, 314 VERBOSE,
317 &do_report, 315 &do_report,
318 (NULL == fn) ? NULL : GNUNET_strdup (fn)); 316 (NULL == fn) ? NULL : GNUNET_strdup(fn));
319} 317}
320 318
321 319
322static void 320static void
323do_publish (void *cls, 321do_publish(void *cls,
324 struct GNUNET_TESTBED_RunHandle *h, 322 struct GNUNET_TESTBED_RunHandle *h,
325 unsigned int num_peers, 323 unsigned int num_peers,
326 struct GNUNET_TESTBED_Peer **peers, 324 struct GNUNET_TESTBED_Peer **peers,
327 unsigned int links_succeeded, 325 unsigned int links_succeeded,
328 unsigned int links_failed) 326 unsigned int links_failed)
329{ 327{
330 unsigned int i; 328 unsigned int i;
331 int do_index; 329 int do_index;
332 int anonymity; 330 int anonymity;
333 331
334 GNUNET_assert (NUM_DAEMONS == num_peers); 332 GNUNET_assert(NUM_DAEMONS == num_peers);
335 for (i=0;i<num_peers;i++) 333 for (i = 0; i < num_peers; i++)
336 daemons[i] = peers[i]; 334 daemons[i] = peers[i];
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", 335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
338 (unsigned long long) FILESIZE); 336 (unsigned long long)FILESIZE);
339 if (NULL != strstr (progname, "index")) 337 if (NULL != strstr(progname, "index"))
340 do_index = GNUNET_YES; 338 do_index = GNUNET_YES;
341 else 339 else
342 do_index = GNUNET_NO; 340 do_index = GNUNET_NO;
343 if (NULL != strstr (progname, "dht")) 341 if (NULL != strstr(progname, "dht"))
344 anonymity = 0; 342 anonymity = 0;
345 else 343 else
346 anonymity = 1; 344 anonymity = 1;
347 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, 345 GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
348 do_index, FILESIZE, SEED, VERBOSE, &do_download, 346 do_index, FILESIZE, SEED, VERBOSE, &do_download,
349 NULL); 347 NULL);
350} 348}
351 349
352 350
353int 351int
354main (int argc, char *argv[]) 352main(int argc, char *argv[])
355{ 353{
356 progname = argv[0]; 354 progname = argv[0];
357 (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p", 355 (void)GNUNET_TESTBED_test_run("perf-gnunet-service-fs-p2p",
358 "perf_gnunet_service_fs_p2p.conf", 356 "perf_gnunet_service_fs_p2p.conf",
359 NUM_DAEMONS, 357 NUM_DAEMONS,
360 0, NULL, NULL, 358 0, NULL, NULL,
361 &do_publish, NULL); 359 &do_publish, NULL);
362 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 360 GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/");
363 return ok; 361 return ok;
364} 362}
365 363