aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-nse-profiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nse/gnunet-nse-profiler.c')
-rw-r--r--src/nse/gnunet-nse-profiler.c615
1 files changed, 293 insertions, 322 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index d32456a1c..b88dbc3fc 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -148,48 +148,47 @@ static void
148shutdown_callback (void *cls, const char *emsg) 148shutdown_callback (void *cls, const char *emsg)
149{ 149{
150 if (emsg != NULL) 150 if (emsg != NULL)
151 { 151 {
152#if VERBOSE 152#if VERBOSE
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
154#endif 154#endif
155 if (ok == 0) 155 if (ok == 0)
156 ok = 666; 156 ok = 666;
157 } 157 }
158 else 158 else
159 { 159 {
160#if VERBOSE 160#if VERBOSE
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
162 "All peers successfully shut down!\n");
163#endif 162#endif
164 ok = 0; 163 ok = 0;
165 } 164 }
166} 165}
167 166
168 167
169static void 168static void
170shutdown_task (void *cls, 169shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
171 const struct GNUNET_SCHEDULER_TaskContext *tc)
172{ 170{
173 struct NSEPeer *pos; 171 struct NSEPeer *pos;
172
174#if VERBOSE 173#if VERBOSE
175 fprintf(stderr, "Ending test.\n"); 174 fprintf (stderr, "Ending test.\n");
176#endif 175#endif
177 176
178 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) 177 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
179 { 178 {
180 GNUNET_SCHEDULER_cancel(disconnect_task); 179 GNUNET_SCHEDULER_cancel (disconnect_task);
181 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 180 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
182 } 181 }
183 while (NULL != (pos = peer_head)) 182 while (NULL != (pos = peer_head))
184 { 183 {
185 if (pos->nse_handle != NULL) 184 if (pos->nse_handle != NULL)
186 GNUNET_NSE_disconnect(pos->nse_handle); 185 GNUNET_NSE_disconnect (pos->nse_handle);
187 GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos); 186 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
188 GNUNET_free(pos); 187 GNUNET_free (pos);
189 } 188 }
190 189
191 if (data_file != NULL) 190 if (data_file != NULL)
192 GNUNET_DISK_file_close(data_file); 191 GNUNET_DISK_file_close (data_file);
193 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 192 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
194} 193}
195 194
@@ -205,72 +204,68 @@ shutdown_task (void *cls,
205 * 204 *
206 */ 205 */
207static void 206static void
208handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, double estimate, double std_dev) 207handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
208 double estimate, double std_dev)
209{ 209{
210 struct NSEPeer *peer = cls; 210 struct NSEPeer *peer = cls;
211 char *output_buffer; 211 char *output_buffer;
212 size_t size; 212 size_t size;
213 213
214 if (output_file != NULL) 214 if (output_file != NULL)
215 { 215 {
216 size = GNUNET_asprintf(&output_buffer, 216 size = GNUNET_asprintf (&output_buffer,
217 "%s %llu %llu %f %f %f\n", 217 "%s %llu %llu %f %f %f\n",
218 GNUNET_i2s(&peer->daemon->id), 218 GNUNET_i2s (&peer->daemon->id),
219 peers_running, 219 peers_running,
220 timestamp.abs_value, 220 timestamp.abs_value,
221 GNUNET_NSE_log_estimate_to_n(estimate), 221 GNUNET_NSE_log_estimate_to_n (estimate),
222 estimate, 222 estimate, std_dev);
223 std_dev); 223 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
224 if (size != GNUNET_DISK_file_write(output_file, output_buffer, size)) 224 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
225 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 225 GNUNET_free (output_buffer);
226 "Unable to write to file!\n"); 226 }
227 GNUNET_free (output_buffer);
228 }
229 else 227 else
230 fprintf(stderr, 228 fprintf (stderr,
231 "Received network size estimate from peer %s. Size: %f std.dev. %f\n", 229 "Received network size estimate from peer %s. Size: %f std.dev. %f\n",
232 GNUNET_i2s(&peer->daemon->id), 230 GNUNET_i2s (&peer->daemon->id), estimate, std_dev);
233 estimate,
234 std_dev);
235 231
236} 232}
237 233
238 234
239static void 235static void
240connect_nse_service (void *cls, 236connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
241 const struct GNUNET_SCHEDULER_TaskContext *tc)
242{ 237{
243 struct NSEPeer *current_peer; 238 struct NSEPeer *current_peer;
244 unsigned int i; 239 unsigned int i;
245 240
246#if VERBOSE 241#if VERBOSE
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to nse service of peers\n");
248 "Connecting to nse service of peers\n");
249#endif 243#endif
250 for (i = 0; i < num_peers; i++) 244 for (i = 0; i < num_peers; i++)
251 { 245 {
252 if ((connection_limit > 0) && (i % (num_peers / connection_limit) != 0)) 246 if ((connection_limit > 0) && (i % (num_peers / connection_limit) != 0))
253 continue; 247 continue;
254#if VERBOSE 248#if VERBOSE
255 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "nse-profiler: connecting to nse service of peer %d\n", i); 249 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
250 "nse-profiler: connecting to nse service of peer %d\n", i);
256#endif 251#endif
257 current_peer = GNUNET_malloc(sizeof(struct NSEPeer)); 252 current_peer = GNUNET_malloc (sizeof (struct NSEPeer));
258 current_peer->daemon = GNUNET_TESTING_daemon_get(pg, i); 253 current_peer->daemon = GNUNET_TESTING_daemon_get (pg, i);
259 if (GNUNET_YES == GNUNET_TESTING_daemon_running(GNUNET_TESTING_daemon_get(pg, i))) 254 if (GNUNET_YES ==
260 { 255 GNUNET_TESTING_daemon_running (GNUNET_TESTING_daemon_get (pg, i)))
261 current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg, 256 {
262 &handle_estimate, 257 current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg,
263 current_peer); 258 &handle_estimate,
264 GNUNET_assert(current_peer->nse_handle != NULL); 259 current_peer);
265 } 260 GNUNET_assert (current_peer->nse_handle != NULL);
266 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
267 } 261 }
262 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
263 }
268} 264}
269 265
270 266
271static void 267static void
272churn_peers (void *cls, 268churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
273 const struct GNUNET_SCHEDULER_TaskContext *tc);
274 269
275 270
276/** 271/**
@@ -280,31 +275,30 @@ churn_peers (void *cls,
280 * @param success GNUNET_OK if statistics were 275 * @param success GNUNET_OK if statistics were
281 * successfully obtained, GNUNET_SYSERR if not. 276 * successfully obtained, GNUNET_SYSERR if not.
282 */ 277 */
283static void 278static void
284stats_finished_callback (void *cls, int success) 279stats_finished_callback (void *cls, int success)
285{ 280{
286 struct StatsContext *stats_context = cls; 281 struct StatsContext *stats_context = cls;
287 char *buf; 282 char *buf;
288 int buf_len; 283 int buf_len;
289 284
290 if ( (GNUNET_OK == success) && 285 if ((GNUNET_OK == success) && (data_file != NULL))
291 (data_file != NULL) ) 286 {
287 /* Stats lookup successful, write out data */
288 buf = NULL;
289 buf_len = GNUNET_asprintf (&buf,
290 "TOTAL_NSE_BYTES: %u\n",
291 stats_context->total_nse_bytes);
292 if (buf_len > 0)
292 { 293 {
293 /* Stats lookup successful, write out data */ 294 GNUNET_DISK_file_write (data_file, buf, buf_len);
294 buf = NULL;
295 buf_len = GNUNET_asprintf(&buf,
296 "TOTAL_NSE_BYTES: %u\n",
297 stats_context->total_nse_bytes);
298 if (buf_len > 0)
299 {
300 GNUNET_DISK_file_write(data_file, buf, buf_len);
301 }
302 GNUNET_free_non_null(buf);
303 } 295 }
296 GNUNET_free_non_null (buf);
297 }
304 298
305 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == shutdown_handle); 299 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == shutdown_handle);
306 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 300 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
307 GNUNET_free(stats_context); 301 GNUNET_free (stats_context);
308} 302}
309 303
310 304
@@ -319,69 +313,62 @@ stats_finished_callback (void *cls, int success)
319 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not 313 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
320 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 314 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
321 */ 315 */
322static int 316static int
323statistics_iterator (void *cls, 317statistics_iterator (void *cls,
324 const struct GNUNET_PeerIdentity *peer, 318 const struct GNUNET_PeerIdentity *peer,
325 const char *subsystem, 319 const char *subsystem,
326 const char *name, 320 const char *name, uint64_t value, int is_persistent)
327 uint64_t value,
328 int is_persistent)
329{ 321{
330 struct StatsContext *stats_context = cls; 322 struct StatsContext *stats_context = cls;
331 323
332 if ( (0 == strstr(subsystem, "nse")) && 324 if ((0 == strstr (subsystem, "nse")) &&
333 (0 == strstr(name, "# flood messages received")) ) 325 (0 == strstr (name, "# flood messages received")))
334 stats_context->total_nse_bytes += value; 326 stats_context->total_nse_bytes += value;
335 return GNUNET_OK; 327 return GNUNET_OK;
336} 328}
337 329
338 330
339static void 331static void
340disconnect_nse_peers (void *cls, 332disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
341 const struct GNUNET_SCHEDULER_TaskContext *tc)
342{ 333{
343 struct NSEPeer *pos; 334 struct NSEPeer *pos;
344 char *buf; 335 char *buf;
345 struct StatsContext *stats_context; 336 struct StatsContext *stats_context;
346 337
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n");
348 "disconnecting nse service of peers\n");
349 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 339 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
350 pos = peer_head; 340 pos = peer_head;
351 while (NULL != (pos = peer_head)) 341 while (NULL != (pos = peer_head))
342 {
343 if (pos->nse_handle != NULL)
352 { 344 {
353 if (pos->nse_handle != NULL) 345 GNUNET_NSE_disconnect (pos->nse_handle);
354 { 346 pos->nse_handle = NULL;
355 GNUNET_NSE_disconnect(pos->nse_handle);
356 pos->nse_handle = NULL;
357 }
358 GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos);
359 GNUNET_free(pos);
360 }
361
362 GNUNET_asprintf(&buf,
363 "round%llu",
364 current_round);
365 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg,
366 "nse-profiler",
367 buf,
368 &peers_next_round))
369 {
370 current_round++;
371 GNUNET_assert(churn_task == GNUNET_SCHEDULER_NO_TASK);
372 churn_task = GNUNET_SCHEDULER_add_now(&churn_peers, NULL);
373 } 347 }
374 else /* No more rounds, let's shut it down! */ 348 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
375 { 349 GNUNET_free (pos);
376 stats_context = GNUNET_malloc(sizeof(struct StatsContext)); 350 }
377 GNUNET_SCHEDULER_cancel(shutdown_handle); 351
378 shutdown_handle = GNUNET_SCHEDULER_NO_TASK; 352 GNUNET_asprintf (&buf, "round%llu", current_round);
379 GNUNET_TESTING_get_statistics(pg, 353 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg,
380 &stats_finished_callback, 354 "nse-profiler",
381 &statistics_iterator, 355 buf,
382 stats_context); 356 &peers_next_round))
383 } 357 {
384 GNUNET_free(buf); 358 current_round++;
359 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK);
360 churn_task = GNUNET_SCHEDULER_add_now (&churn_peers, NULL);
361 }
362 else /* No more rounds, let's shut it down! */
363 {
364 stats_context = GNUNET_malloc (sizeof (struct StatsContext));
365 GNUNET_SCHEDULER_cancel (shutdown_handle);
366 shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
367 GNUNET_TESTING_get_statistics (pg,
368 &stats_finished_callback,
369 &statistics_iterator, stats_context);
370 }
371 GNUNET_free (buf);
385} 372}
386 373
387 374
@@ -391,12 +378,12 @@ disconnect_nse_peers (void *cls,
391 * @param cls unused 378 * @param cls unused
392 * @param emsg NULL on success 379 * @param emsg NULL on success
393 */ 380 */
394static void 381static void
395topology_output_callback (void *cls, const char *emsg) 382topology_output_callback (void *cls, const char *emsg)
396{ 383{
397 disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time, 384 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time,
398 &disconnect_nse_peers, NULL); 385 &disconnect_nse_peers, NULL);
399 GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL); 386 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
400} 387}
401 388
402 389
@@ -411,131 +398,117 @@ churn_callback (void *cls, const char *emsg)
411{ 398{
412 char *temp_output_file; 399 char *temp_output_file;
413 400
414 if (emsg == NULL) /* Everything is okay! */ 401 if (emsg == NULL) /* Everything is okay! */
415 { 402 {
416 peers_running = peers_next_round; 403 peers_running = peers_next_round;
417 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 404 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
418 "Round %llu, churn finished successfully.\n", 405 "Round %llu, churn finished successfully.\n", current_round);
419 current_round); 406 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
420 GNUNET_assert(disconnect_task == GNUNET_SCHEDULER_NO_TASK); 407 GNUNET_asprintf (&temp_output_file,
421 GNUNET_asprintf(&temp_output_file, 408 "%s_%llu.dot", topology_file, current_round);
422 "%s_%llu.dot", 409 GNUNET_TESTING_peergroup_topology_to_file (pg,
423 topology_file, 410 temp_output_file,
424 current_round); 411 &topology_output_callback, NULL);
425 GNUNET_TESTING_peergroup_topology_to_file(pg, 412 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
426 temp_output_file, 413 "Writing topology to file %s\n", temp_output_file);
427 &topology_output_callback, 414 GNUNET_free (temp_output_file);
428 NULL); 415 }
429 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
430 "Writing topology to file %s\n",
431 temp_output_file);
432 GNUNET_free(temp_output_file);
433 }
434 else 416 else
435 { 417 {
436 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 418 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
437 "Round %llu, churn FAILED!!\n", 419 "Round %llu, churn FAILED!!\n", current_round);
438 current_round); 420 GNUNET_SCHEDULER_cancel (shutdown_handle);
439 GNUNET_SCHEDULER_cancel(shutdown_handle); 421 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
440 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 422 }
441 }
442} 423}
443 424
444 425
445static void 426static void
446churn_peers (void *cls, 427churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
447 const struct GNUNET_SCHEDULER_TaskContext *tc)
448{ 428{
449 /* peers_running = GNUNET_TESTING_daemons_running(pg); */ 429 /* peers_running = GNUNET_TESTING_daemons_running(pg); */
450 churn_task = GNUNET_SCHEDULER_NO_TASK; 430 churn_task = GNUNET_SCHEDULER_NO_TASK;
451 if (peers_next_round == peers_running) 431 if (peers_next_round == peers_running)
452 { 432 {
453 /* Nothing to do... */ 433 /* Nothing to do... */
454 GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL); 434 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
455 GNUNET_assert(disconnect_task == GNUNET_SCHEDULER_NO_TASK); 435 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
456 disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time, 436 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time,
457 &disconnect_nse_peers, NULL); 437 &disconnect_nse_peers,
458 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 438 NULL);
459 "Round %lu, doing nothing!\n", 439 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n",
460 current_round); 440 current_round);
461 } 441 }
462 else 442 else
443 {
444 if (peers_next_round > num_peers)
463 { 445 {
464 if (peers_next_round > num_peers) 446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
465 { 447 "Asked to turn on more peers than we have!!\n");
466 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 448 GNUNET_SCHEDULER_cancel (shutdown_handle);
467 "Asked to turn on more peers than we have!!\n"); 449 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
468 GNUNET_SCHEDULER_cancel(shutdown_handle);
469 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
470 }
471 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
472 "Round %llu, turning off %llu peers, turning on %llu peers!\n",
473 current_round,
474 (peers_running > peers_next_round)
475 ? peers_running - peers_next_round
476 : 0,
477 (peers_next_round > peers_running)
478 ? peers_next_round - peers_running
479 : 0);
480 GNUNET_TESTING_daemons_churn (pg, "nse",
481 (peers_running > peers_next_round)
482 ? peers_running - peers_next_round
483 : 0,
484 (peers_next_round > peers_running)
485 ? peers_next_round - peers_running
486 : 0,
487 wait_time,
488 &churn_callback, NULL);
489 } 450 }
451 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
452 "Round %llu, turning off %llu peers, turning on %llu peers!\n",
453 current_round,
454 (peers_running > peers_next_round)
455 ? peers_running - peers_next_round
456 : 0,
457 (peers_next_round > peers_running)
458 ? peers_next_round - peers_running : 0);
459 GNUNET_TESTING_daemons_churn (pg, "nse",
460 (peers_running > peers_next_round)
461 ? peers_running - peers_next_round
462 : 0,
463 (peers_next_round > peers_running)
464 ? peers_next_round - peers_running
465 : 0, wait_time, &churn_callback, NULL);
466 }
490} 467}
491 468
492 469
493static void 470static void
494nse_started_cb(void *cls, const char *emsg) 471nse_started_cb (void *cls, const char *emsg)
495{ 472{
496 GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL); 473 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
497 disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time, &disconnect_nse_peers, NULL); 474 disconnect_task =
475 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
498} 476}
499 477
500 478
501static void 479static void
502my_cb (void *cls, 480my_cb (void *cls, const char *emsg)
503 const char *emsg)
504{ 481{
505 char *buf; 482 char *buf;
506 int buf_len; 483 int buf_len;
484
507 if (emsg != NULL) 485 if (emsg != NULL)
508 { 486 {
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Peergroup callback called with error, aborting test!\n"); 488 "Peergroup callback called with error, aborting test!\n");
511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
512 ok = 1; 490 ok = 1;
513 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 491 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
514 return; 492 return;
515 } 493 }
516#if VERBOSE 494#if VERBOSE
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "Peer Group started successfully, connecting to NSE service for each peer!\n"); 496 "Peer Group started successfully, connecting to NSE service for each peer!\n");
519#endif 497#endif
520 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 498 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
521 "Have %u connections\n", 499 "Have %u connections\n", total_connections);
522 total_connections);
523 if (data_file != NULL) 500 if (data_file != NULL)
524 { 501 {
525 buf = NULL; 502 buf = NULL;
526 buf_len = GNUNET_asprintf(&buf, 503 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
527 "CONNECTIONS_0: %u\n", 504 if (buf_len > 0)
528 total_connections); 505 GNUNET_DISK_file_write (data_file, buf, buf_len);
529 if (buf_len > 0) 506 GNUNET_free (buf);
530 GNUNET_DISK_file_write(data_file, buf, buf_len); 507 }
531 GNUNET_free (buf); 508 peers_running = GNUNET_TESTING_daemons_running (pg);
532 }
533 peers_running = GNUNET_TESTING_daemons_running(pg);
534 GNUNET_TESTING_daemons_start_service (pg, 509 GNUNET_TESTING_daemons_start_service (pg,
535 "nse", 510 "nse",
536 wait_time, 511 wait_time, &nse_started_cb, NULL);
537 &nse_started_cb,
538 NULL);
539 512
540} 513}
541 514
@@ -554,16 +527,15 @@ my_cb (void *cls,
554 * @param second_daemon handle for the second daemon 527 * @param second_daemon handle for the second daemon
555 * @param emsg error message (NULL on success) 528 * @param emsg error message (NULL on success)
556 */ 529 */
557static void 530static void
558connect_cb (void *cls, 531connect_cb (void *cls,
559 const struct GNUNET_PeerIdentity *first, 532 const struct GNUNET_PeerIdentity *first,
560 const struct GNUNET_PeerIdentity *second, 533 const struct GNUNET_PeerIdentity *second,
561 uint32_t distance, 534 uint32_t distance,
562 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 535 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
563 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 536 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
564 struct GNUNET_TESTING_Daemon *first_daemon, 537 struct GNUNET_TESTING_Daemon *first_daemon,
565 struct GNUNET_TESTING_Daemon *second_daemon, 538 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
566 const char *emsg)
567{ 539{
568 if (emsg == NULL) 540 if (emsg == NULL)
569 total_connections++; 541 total_connections++;
@@ -580,109 +552,108 @@ run (void *cls,
580 struct GNUNET_TESTING_Host *hosts; 552 struct GNUNET_TESTING_Host *hosts;
581 553
582 ok = 1; 554 ok = 1;
583 testing_cfg = GNUNET_CONFIGURATION_create(); 555 testing_cfg = GNUNET_CONFIGURATION_create ();
584#if VERBOSE 556#if VERBOSE
585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
586 GNUNET_CONFIGURATION_set_value_string (testing_cfg, 558 GNUNET_CONFIGURATION_set_value_string (testing_cfg,
587 "testing", 559 "testing", "use_progressbars", "YES");
588 "use_progressbars",
589 "YES");
590#endif 560#endif
591 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 561 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
592 "testing", 562 "testing",
593 "num_peers", &num_peers)) 563 "num_peers",
594 { 564 &num_peers))
595 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Option TESTING:NUM_PEERS is required!\n"); 565 {
596 return; 566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
597 } 567 "Option TESTING:NUM_PEERS is required!\n");
598 568 return;
599 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 569 }
600 "nse-profiler", 570
601 "wait_time", 571 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
602 &temp_wait)) 572 "nse-profiler",
603 { 573 "wait_time",
604 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 574 &temp_wait))
605 "Option nse-profiler:wait_time is required!\n"); 575 {
606 return; 576 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
607 } 577 "Option nse-profiler:wait_time is required!\n");
608 578 return;
609 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 579 }
610 "nse-profiler", "connection_limit", 580
611 &connection_limit)) 581 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
612 { 582 "nse-profiler",
613 connection_limit = 0; 583 "connection_limit",
614 } 584 &connection_limit))
615 585 {
616 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 586 connection_limit = 0;
617 "nse-profiler", "topology_output_file", 587 }
618 &topology_file)) 588
619 { 589 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
620 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 590 "nse-profiler",
621 "Option nse-profiler:topology_output_file is required!\n"); 591 "topology_output_file",
622 return; 592 &topology_file))
623 } 593 {
624 594 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
625 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 595 "Option nse-profiler:topology_output_file is required!\n");
626 "nse-profiler", "data_output_file", 596 return;
627 &data_filename)) 597 }
628 { 598
629 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 599 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
630 "Option nse-profiler:data_output_file is required!\n"); 600 "nse-profiler",
631 return; 601 "data_output_file",
632 } 602 &data_filename))
633 603 {
634 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (testing_cfg, 604 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
635 "nse-profiler", 605 "Option nse-profiler:data_output_file is required!\n");
636 "skew_clock")) 606 return;
637 { 607 }
638 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 608
639 "Setting our clock as skewed...\n"); 609 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (testing_cfg,
640 clock_skew = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 610 "nse-profiler",
641 GNUNET_TIME_UNIT_MINUTES.rel_value); 611 "skew_clock"))
642 } 612 {
613 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Setting our clock as skewed...\n");
614 clock_skew = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
615 GNUNET_TIME_UNIT_MINUTES.rel_value);
616 }
643 617
644 618
645 data_file = GNUNET_DISK_file_open (data_filename, 619 data_file = GNUNET_DISK_file_open (data_filename,
646 GNUNET_DISK_OPEN_READWRITE 620 GNUNET_DISK_OPEN_READWRITE
647 | GNUNET_DISK_OPEN_CREATE, 621 | GNUNET_DISK_OPEN_CREATE,
648 GNUNET_DISK_PERM_USER_READ | 622 GNUNET_DISK_PERM_USER_READ |
649 GNUNET_DISK_PERM_USER_WRITE); 623 GNUNET_DISK_PERM_USER_WRITE);
650 if (data_file == NULL) 624 if (data_file == NULL)
651 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 625 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
652 "Failed to open %s for output!\n", 626 "Failed to open %s for output!\n", data_filename);
653 data_filename); 627 GNUNET_free (data_filename);
654 GNUNET_free(data_filename); 628
655 629 wait_time =
656 wait_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_wait); 630 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
657 631
658 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(cfg, 632 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg,
659 "nse-profiler", 633 "nse-profiler",
660 "output_file", 634 "output_file",
661 &temp_str)) 635 &temp_str))
662 { 636 {
663 output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE 637 output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE
664 | GNUNET_DISK_OPEN_CREATE, 638 | GNUNET_DISK_OPEN_CREATE,
665 GNUNET_DISK_PERM_USER_READ | 639 GNUNET_DISK_PERM_USER_READ |
666 GNUNET_DISK_PERM_USER_WRITE); 640 GNUNET_DISK_PERM_USER_WRITE);
667 if (output_file == NULL) 641 if (output_file == NULL)
668 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 642 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
669 "Failed to open %s for output!\n", 643 "Failed to open %s for output!\n", temp_str);
670 temp_str); 644 }
671 } 645 GNUNET_free_non_null (temp_str);
672 GNUNET_free_non_null(temp_str);
673 646
674 hosts = GNUNET_TESTING_hosts_load (testing_cfg); 647 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
675 648
676 pg = GNUNET_TESTING_peergroup_start(testing_cfg, 649 pg = GNUNET_TESTING_peergroup_start (testing_cfg,
677 num_peers, 650 num_peers,
678 TIMEOUT, 651 TIMEOUT,
679 &connect_cb, 652 &connect_cb, &my_cb, NULL, hosts);
680 &my_cb, NULL,
681 hosts);
682 GNUNET_assert (pg != NULL); 653 GNUNET_assert (pg != NULL);
683 shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever(), 654 shutdown_handle =
684 &shutdown_task, 655 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
685 NULL); 656 &shutdown_task, NULL);
686} 657}
687 658
688 659
@@ -709,10 +680,10 @@ main (int argc, char *argv[])
709#endif 680#endif
710 NULL); 681 NULL);
711 GNUNET_PROGRAM_run (argc, 682 GNUNET_PROGRAM_run (argc,
712 argv, "nse-profiler", 683 argv, "nse-profiler",
713 gettext_noop ("Measure quality and performance of the NSE service."), 684 gettext_noop
714 options, 685 ("Measure quality and performance of the NSE service."),
715 &run, NULL); 686 options, &run, NULL);
716#if REMOVE_DIR 687#if REMOVE_DIR
717 GNUNET_DISK_directory_remove ("/tmp/nse-profiler"); 688 GNUNET_DISK_directory_remove ("/tmp/nse-profiler");
718#endif 689#endif