aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-07 16:00:27 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-07 16:00:27 +0000
commitcfa7d229b27b9c387351c9bf3c8a9eb7994de13a (patch)
tree4fc0eba5eb000ed230d110cd79b5fe2933d11e97 /src/transport/gnunet-transport.c
parentf4c6b450aa848628fb07d0a9ede9465a81090691 (diff)
downloadgnunet-cfa7d229b27b9c387351c9bf3c8a9eb7994de13a.tar.gz
gnunet-cfa7d229b27b9c387351c9bf3c8a9eb7994de13a.zip
new monitoring API
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c633
1 files changed, 287 insertions, 346 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index aff4d30aa..a6ffb2bab 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors) 3 (C) 2011 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 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 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19 */
20 20
21/** 21/**
22 * @file src/transport/gnunet-transport.c 22 * @file src/transport/gnunet-transport.c
@@ -48,7 +48,6 @@
48 */ 48 */
49#define BLOCKSIZE 4 49#define BLOCKSIZE 4
50 50
51
52/** 51/**
53 * Which peer should we connect to? 52 * Which peer should we connect to?
54 */ 53 */
@@ -90,6 +89,11 @@ static int benchmark_receive;
90static int iterate_connections; 89static int iterate_connections;
91 90
92/** 91/**
92 * Option -a.
93 */
94static int iterate_all;
95
96/**
93 * Option -t. 97 * Option -t.
94 */ 98 */
95static int test_configuration; 99static int test_configuration;
@@ -147,7 +151,7 @@ static struct GNUNET_TRANSPORT_TransmitHandle *th;
147/** 151/**
148 * 152 *
149 */ 153 */
150struct GNUNET_TRANSPORT_PeerIterateContext *pic; 154struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
151 155
152/** 156/**
153 * Identity of the peer we transmit to / connect to. 157 * Identity of the peer we transmit to / connect to.
@@ -213,7 +217,6 @@ struct TestContext
213 217
214}; 218};
215 219
216
217/** 220/**
218 * Task run in monitor mode when the user presses CTRL-C to abort. 221 * Task run in monitor mode when the user presses CTRL-C to abort.
219 * Stops monitoring activity. 222 * Stops monitoring activity.
@@ -222,54 +225,53 @@ struct TestContext
222 * @param tc scheduler context 225 * @param tc scheduler context
223 */ 226 */
224static void 227static void
225shutdown_task (void *cls, 228shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
226 const struct GNUNET_SCHEDULER_TaskContext *tc)
227{ 229{
228 struct GNUNET_TIME_Relative duration; 230 struct GNUNET_TIME_Relative duration;
229 end = GNUNET_SCHEDULER_NO_TASK; 231 end = GNUNET_SCHEDULER_NO_TASK;
230 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 232 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
231 { 233 {
232 GNUNET_SCHEDULER_cancel (op_timeout); 234 GNUNET_SCHEDULER_cancel (op_timeout);
233 op_timeout = GNUNET_SCHEDULER_NO_TASK; 235 op_timeout = GNUNET_SCHEDULER_NO_TASK;
234 } 236 }
235 if (NULL != tc_handle) 237 if (NULL != tc_handle)
236 { 238 {
237 GNUNET_TRANSPORT_try_connect_cancel (tc_handle); 239 GNUNET_TRANSPORT_try_connect_cancel (tc_handle);
238 tc_handle = NULL; 240 tc_handle = NULL;
239 } 241 }
240 if (NULL != pic) 242 if (NULL != pic)
241 { 243 {
242 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic); 244 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
243 pic = NULL; 245 pic = NULL;
244 } 246 }
245 if (NULL != th) 247 if (NULL != th)
246 { 248 {
247 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 249 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
248 th = NULL; 250 th = NULL;
249 } 251 }
250 if (NULL != handle) 252 if (NULL != handle)
251 { 253 {
252 GNUNET_TRANSPORT_disconnect(handle); 254 GNUNET_TRANSPORT_disconnect (handle);
253 handle = NULL; 255 handle = NULL;
254 } 256 }
255 if (benchmark_send) 257 if (benchmark_send)
256 { 258 {
257 duration = GNUNET_TIME_absolute_get_duration (start_time); 259 duration = GNUNET_TIME_absolute_get_duration (start_time);
258 FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"), 260 FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
259 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), traffic_sent, 261 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
260 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); 262 traffic_sent,
263 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
261 } 264 }
262 if (benchmark_receive) 265 if (benchmark_receive)
263 { 266 {
264 duration = GNUNET_TIME_absolute_get_duration (start_time); 267 duration = GNUNET_TIME_absolute_get_duration (start_time);
265 FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"), 268 FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"),
266 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 269 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
267 traffic_received, 270 traffic_received,
268 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); 271 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
269 } 272 }
270} 273}
271 274
272
273static struct ResolutionContext *rc_head; 275static struct ResolutionContext *rc_head;
274static struct ResolutionContext *rc_tail; 276static struct ResolutionContext *rc_tail;
275 277
@@ -282,50 +284,45 @@ struct ResolutionContext
282 int printed; 284 int printed;
283}; 285};
284 286
285
286static void 287static void
287operation_timeout (void *cls, 288operation_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
288 const struct GNUNET_SCHEDULER_TaskContext *tc)
289{ 289{
290 struct ResolutionContext *cur; 290 struct ResolutionContext *cur;
291 struct ResolutionContext *next; 291 struct ResolutionContext *next;
292 op_timeout = GNUNET_SCHEDULER_NO_TASK; 292 op_timeout = GNUNET_SCHEDULER_NO_TASK;
293 if ((try_connect) || (benchmark_send) || 293 if ((try_connect) || (benchmark_send) || (benchmark_receive))
294 (benchmark_receive))
295 { 294 {
296 FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); 295 FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
297 if (GNUNET_SCHEDULER_NO_TASK != end) 296 if (GNUNET_SCHEDULER_NO_TASK != end)
298 GNUNET_SCHEDULER_cancel (end); 297 GNUNET_SCHEDULER_cancel (end);
299 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 298 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
300 ret = 1; 299 ret = 1;
301 return; 300 return;
302 } 301 }
303 if (iterate_connections) 302 if (iterate_connections)
304 { 303 {
305 next = rc_head; 304 next = rc_head;
306 while (NULL != (cur = next)) 305 while (NULL != (cur = next))
307 { 306 {
308 next = cur->next; 307 next = cur->next;
309 FPRINTF (stdout, _("Failed to resolve address for peer `%s'\n"), 308 FPRINTF (stdout, _("Failed to resolve address for peer `%s'\n"),
310 GNUNET_i2s (&cur->addrcp->peer)); 309 GNUNET_i2s (&cur->addrcp->peer));
311
312 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur);
313 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
314 GNUNET_free (cur->addrcp);
315 GNUNET_free (cur);
316
317 }
318 FPRINTF (stdout, "%s", _("Failed to list connections, timeout occured\n"));
319 if (GNUNET_SCHEDULER_NO_TASK != end)
320 GNUNET_SCHEDULER_cancel (end);
321 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
322 ret = 1;
323 return;
324 }
325 310
326} 311 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, cur);
312 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
313 GNUNET_free(cur->addrcp);
314 GNUNET_free(cur);
327 315
316 }
317 FPRINTF (stdout, "%s", _("Failed to list connections, timeout occured\n") );
318 if (GNUNET_SCHEDULER_NO_TASK != end)
319 GNUNET_SCHEDULER_cancel (end);
320 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
321 ret = 1;
322 return;
323 }
328 324
325}
329 326
330/** 327/**
331 * Display the result of the test. 328 * Display the result of the test.
@@ -354,17 +351,16 @@ display_test_result (struct TestContext *tc, int result)
354 GNUNET_NAT_test_stop (tc->tst); 351 GNUNET_NAT_test_stop (tc->tst);
355 tc->tst = NULL; 352 tc->tst = NULL;
356 } 353 }
357 GNUNET_free (tc); 354 GNUNET_free(tc);
358 resolver_users--; 355 resolver_users--;
359 if ((0 == resolver_users) && (NULL != resolver)) 356 if ((0 == resolver_users) && (NULL != resolver))
360 { 357 {
361 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, GNUNET_TERM_SIG)); 358 GNUNET_break(0 == GNUNET_OS_process_kill (resolver, GNUNET_TERM_SIG));
362 GNUNET_OS_process_destroy (resolver); 359 GNUNET_OS_process_destroy (resolver);
363 resolver = NULL; 360 resolver = NULL;
364 } 361 }
365} 362}
366 363
367
368/** 364/**
369 * Function called by NAT on success. 365 * Function called by NAT on success.
370 * Clean up and update GUI (with success). 366 * Clean up and update GUI (with success).
@@ -374,16 +370,13 @@ display_test_result (struct TestContext *tc, int result)
374 * @param emsg error message, NULL on success 370 * @param emsg error message, NULL on success
375 */ 371 */
376static void 372static void
377result_callback (void *cls, 373result_callback (void *cls, int success, const char *emsg)
378 int success,
379 const char *emsg)
380{ 374{
381 struct TestContext *tc = cls; 375 struct TestContext *tc = cls;
382 376
383 display_test_result (tc, success); 377 display_test_result (tc, success);
384} 378}
385 379
386
387/** 380/**
388 * Function called if NAT failed to confirm success. 381 * Function called if NAT failed to confirm success.
389 * Clean up and update GUI (with failure). 382 * Clean up and update GUI (with failure).
@@ -400,7 +393,6 @@ fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
400 display_test_result (tstc, GNUNET_NO); 393 display_test_result (tstc, GNUNET_NO);
401} 394}
402 395
403
404/** 396/**
405 * Test our plugin's configuration (NAT traversal, etc.). 397 * Test our plugin's configuration (NAT traversal, etc.).
406 * 398 *
@@ -416,53 +408,47 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
416 struct TestContext *tc; 408 struct TestContext *tc;
417 char *binary; 409 char *binary;
418 410
419 if (GNUNET_OK != 411 if (GNUNET_OK
420 GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins", 412 != GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
421 &plugins)) 413 &plugins))
422 { 414 {
423 FPRINTF (stderr, 415 FPRINTF (stderr, "%s", _
424 "%s", 416 ("No transport plugins configured, peer will never communicate\n") );
425 _
426 ("No transport plugins configured, peer will never communicate\n"));
427 ret = 4; 417 ret = 4;
428 return; 418 return;
429 } 419 }
430 for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " ")) 420 for (tok = strtok (plugins, " "); tok != NULL ; tok = strtok (NULL, " "))
431 { 421 {
432 char section[12 + strlen (tok)]; 422 char section[12 + strlen (tok)];
433 423
434 GNUNET_snprintf (section, sizeof (section), "transport-%s", tok); 424 GNUNET_snprintf (section, sizeof(section), "transport-%s", tok);
435 if (GNUNET_OK != 425 if (GNUNET_OK
436 GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port)) 426 != GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT",
427 &bnd_port))
437 { 428 {
438 FPRINTF (stderr, 429 FPRINTF (stderr,
439 _("No port configured for plugin `%s', cannot test it\n"), tok); 430 _("No port configured for plugin `%s', cannot test it\n"), tok);
440 continue; 431 continue;
441 } 432 }
442 if (GNUNET_OK != 433 if (GNUNET_OK
443 GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT", 434 != GNUNET_CONFIGURATION_get_value_number (cfg, section,
444 &adv_port)) 435 "ADVERTISED_PORT", &adv_port))
445 adv_port = bnd_port; 436 adv_port = bnd_port;
446 if (NULL == resolver) 437 if (NULL == resolver)
447 { 438 {
448 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); 439 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
449 resolver = 440 resolver = GNUNET_OS_start_process (GNUNET_YES,
450 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, 441 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary,
451 binary, 442 "gnunet-service-resolver", NULL );
452 "gnunet-service-resolver", NULL); 443 GNUNET_free(binary);
453 GNUNET_free (binary);
454 } 444 }
455 resolver_users++; 445 resolver_users++;
456 GNUNET_RESOLVER_connect (cfg); 446 GNUNET_RESOLVER_connect (cfg);
457 tc = GNUNET_new (struct TestContext); 447 tc = GNUNET_new (struct TestContext);
458 tc->name = GNUNET_strdup (tok); 448 tc->name = GNUNET_strdup (tok);
459 tc->tst = 449 tc->tst = GNUNET_NAT_test_start (cfg,
460 GNUNET_NAT_test_start (cfg, 450 (0 == strcasecmp (tok, "udp")) ? GNUNET_NO : GNUNET_YES,
461 (0 == 451 (uint16_t) bnd_port, (uint16_t) adv_port, &result_callback, tc);
462 strcasecmp (tok,
463 "udp")) ? GNUNET_NO : GNUNET_YES,
464 (uint16_t) bnd_port, (uint16_t) adv_port,
465 &result_callback, tc);
466 if (NULL == tc->tst) 452 if (NULL == tc->tst)
467 { 453 {
468 display_test_result (tc, GNUNET_SYSERR); 454 display_test_result (tc, GNUNET_SYSERR);
@@ -470,10 +456,9 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
470 } 456 }
471 tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc); 457 tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc);
472 } 458 }
473 GNUNET_free (plugins); 459 GNUNET_free(plugins);
474} 460}
475 461
476
477/** 462/**
478 * Function called to notify a client about the socket 463 * Function called to notify a client about the socket
479 * begin ready to queue more data. @a buf will be 464 * begin ready to queue more data. @a buf will be
@@ -496,22 +481,20 @@ transmit_data (void *cls, size_t size, void *buf)
496 return 0; 481 return 0;
497 } 482 }
498 483
499 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); 484 GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader));
500 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 485 GNUNET_assert(size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
501 m->size = ntohs (size); 486 m->size = ntohs (size);
502 m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY); 487 m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY);
503 memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader)); 488 memset (&m[1], 52, size - sizeof(struct GNUNET_MessageHeader));
504 traffic_sent += size; 489 traffic_sent += size;
505 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, BLOCKSIZE * 1024, 0, 490 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, BLOCKSIZE * 1024,
506 GNUNET_TIME_UNIT_FOREVER_REL, 491 0, GNUNET_TIME_UNIT_FOREVER_REL, &transmit_data, NULL );
507 &transmit_data, NULL);
508 if (verbosity > 0) 492 if (verbosity > 0)
509 FPRINTF (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size, 493 FPRINTF (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size,
510 GNUNET_i2s (&pid)); 494 GNUNET_i2s (&pid));
511 return size; 495 return size;
512} 496}
513 497
514
515/** 498/**
516 * Function called to notify transport users that another 499 * Function called to notify transport users that another
517 * peer connected to us. 500 * peer connected to us.
@@ -522,27 +505,26 @@ transmit_data (void *cls, size_t size, void *buf)
522static void 505static void
523notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 506notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
524{ 507{
525 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 508 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
526 return; 509 return;
527 ret = 0; 510 ret = 0;
528 if (try_connect) 511 if (try_connect)
529 { 512 {
530 /* all done, terminate instantly */ 513 /* all done, terminate instantly */
531 FPRINTF (stdout, 514 FPRINTF (stdout, _("Successfully connected to `%s'\n"),
532 _("Successfully connected to `%s'\n"), 515 GNUNET_i2s_full (peer));
533 GNUNET_i2s_full (peer)); 516 ret = 0;
534 ret = 0;
535 517
536 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 518 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
537 { 519 {
538 GNUNET_SCHEDULER_cancel (op_timeout); 520 GNUNET_SCHEDULER_cancel (op_timeout);
539 op_timeout = GNUNET_SCHEDULER_NO_TASK; 521 op_timeout = GNUNET_SCHEDULER_NO_TASK;
540 } 522 }
541 523
542 if (GNUNET_SCHEDULER_NO_TASK != end) 524 if (GNUNET_SCHEDULER_NO_TASK != end)
543 GNUNET_SCHEDULER_cancel (end); 525 GNUNET_SCHEDULER_cancel (end);
544 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 526 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
545 return; 527 return;
546 } 528 }
547 if (benchmark_send) 529 if (benchmark_send)
548 { 530 {
@@ -552,21 +534,20 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
552 op_timeout = GNUNET_SCHEDULER_NO_TASK; 534 op_timeout = GNUNET_SCHEDULER_NO_TASK;
553 } 535 }
554 if (verbosity > 0) 536 if (verbosity > 0)
555 FPRINTF (stdout, _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), 537 FPRINTF (stdout,
538 _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
556 GNUNET_i2s (&pid), BLOCKSIZE); 539 GNUNET_i2s (&pid), BLOCKSIZE);
557 start_time = GNUNET_TIME_absolute_get (); 540 start_time = GNUNET_TIME_absolute_get ();
558 if (NULL == th) 541 if (NULL == th)
559 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 542 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer,
560 BLOCKSIZE * 1024, 0, 543 BLOCKSIZE * 1024, 0, GNUNET_TIME_UNIT_FOREVER_REL, &transmit_data,
561 GNUNET_TIME_UNIT_FOREVER_REL, 544 NULL );
562 &transmit_data, NULL);
563 else 545 else
564 GNUNET_break (0); 546 GNUNET_break(0);
565 return; 547 return;
566 } 548 }
567} 549}
568 550
569
570/** 551/**
571 * Function called to notify transport users that another 552 * Function called to notify transport users that another
572 * peer disconnected from us. 553 * peer disconnected from us.
@@ -577,7 +558,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
577static void 558static void
578notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 559notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
579{ 560{
580 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 561 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
581 return; 562 return;
582 563
583 if (NULL != th) 564 if (NULL != th)
@@ -587,10 +568,11 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
587 } 568 }
588 if (benchmark_send) 569 if (benchmark_send)
589 { 570 {
590 FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"), GNUNET_i2s (&pid)); 571 FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"),
591 if (GNUNET_SCHEDULER_NO_TASK != end) 572 GNUNET_i2s (&pid));
592 GNUNET_SCHEDULER_cancel (end); 573 if (GNUNET_SCHEDULER_NO_TASK != end)
593 return; 574 GNUNET_SCHEDULER_cancel (end);
575 return;
594 } 576 }
595} 577}
596 578
@@ -604,19 +586,14 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
604static void 586static void
605monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 587monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
606{ 588{
607 monitor_connect_counter ++; 589 monitor_connect_counter++;
608 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 590 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
609 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 591 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
610 592
611 FPRINTF (stdout, 593 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str,
612 _("%24s: %-17s %4s (%u connections in total)\n"), 594 _("Connected to"), GNUNET_i2s (peer), monitor_connect_counter);
613 now_str,
614 _("Connected to"),
615 GNUNET_i2s (peer),
616 monitor_connect_counter);
617} 595}
618 596
619
620/** 597/**
621 * Function called to notify transport users that another 598 * Function called to notify transport users that another
622 * peer disconnected from us. 599 * peer disconnected from us.
@@ -627,22 +604,16 @@ monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
627static void 604static void
628monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 605monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
629{ 606{
630 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 607 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
631 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 608 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
632 609
633 GNUNET_assert (monitor_connect_counter > 0); 610 GNUNET_assert(monitor_connect_counter > 0);
634 monitor_connect_counter --; 611 monitor_connect_counter--;
635 612
636 FPRINTF (stdout, 613 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str,
637 _("%24s: %-17s %4s (%u connections in total)\n"), 614 _("Disconnected from"), GNUNET_i2s (peer), monitor_connect_counter);
638 now_str,
639 _("Disconnected from"),
640 GNUNET_i2s (peer),
641 monitor_connect_counter);
642} 615}
643 616
644
645
646/** 617/**
647 * Function called by the transport for each received message. 618 * Function called by the transport for each received message.
648 * 619 *
@@ -652,16 +623,15 @@ monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
652 */ 623 */
653static void 624static void
654notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 625notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
655 const struct GNUNET_MessageHeader *message) 626 const struct GNUNET_MessageHeader *message)
656{ 627{
657 if (benchmark_receive) 628 if (benchmark_receive)
658 { 629 {
659 if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type)) 630 if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type))
660 return; 631 return;
661 if (verbosity > 0) 632 if (verbosity > 0)
662 FPRINTF (stdout, 633 FPRINTF (stdout, _("Received %u bytes from %s\n"),
663 _("Received %u bytes from %s\n"), 634 (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
664 (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
665 635
666 if (traffic_received == 0) 636 if (traffic_received == 0)
667 start_time = GNUNET_TIME_absolute_get (); 637 start_time = GNUNET_TIME_absolute_get ();
@@ -670,11 +640,8 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
670 } 640 }
671} 641}
672 642
673
674static void 643static void
675resolve_address (const struct GNUNET_HELLO_Address *address, 644resolve_address (const struct GNUNET_HELLO_Address *address, int numeric);
676 int numeric);
677
678 645
679static void 646static void
680process_string (void *cls, const char *address) 647process_string (void *cls, const char *address)
@@ -682,136 +649,133 @@ process_string (void *cls, const char *address)
682 struct ResolutionContext *rc = cls; 649 struct ResolutionContext *rc = cls;
683 struct GNUNET_HELLO_Address *addrcp = rc->addrcp; 650 struct GNUNET_HELLO_Address *addrcp = rc->addrcp;
684 651
685 if (address != NULL) 652 if (address != NULL )
686 { 653 {
687 FPRINTF (stdout, 654 FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (&addrcp->peer),
688 _("Peer `%s': %s %s\n"), 655 addrcp->transport_name, address);
689 GNUNET_i2s (&addrcp->peer),
690 addrcp->transport_name,
691 address);
692 rc->printed = GNUNET_YES; 656 rc->printed = GNUNET_YES;
693 } 657 }
694 else 658 else
695 { 659 {
696 /* done */ 660 /* done */
697 GNUNET_assert (address_resolutions > 0); 661 GNUNET_assert(address_resolutions > 0);
698 address_resolutions --; 662 address_resolutions--;
699 if (GNUNET_NO == rc->printed) 663 if (GNUNET_NO == rc->printed)
700 { 664 {
701 if (numeric == GNUNET_NO) 665 if (numeric == GNUNET_NO)
702 { 666 {
703 resolve_address (rc->addrcp, GNUNET_YES ); /* Failed to resolve address, try numeric lookup */ 667 resolve_address (rc->addrcp, GNUNET_YES); /* Failed to resolve address, try numeric lookup */
704 } 668 }
705 else 669 else
706 FPRINTF (stdout, 670 FPRINTF (stdout, _("Peer `%s': %s <unable to resolve address>\n"),
707 _("Peer `%s': %s <unable to resolve address>\n"), 671 GNUNET_i2s (&addrcp->peer), addrcp->transport_name);
708 GNUNET_i2s (&addrcp->peer),
709 addrcp->transport_name);
710 } 672 }
711 GNUNET_free (rc->addrcp); 673 GNUNET_free(rc->addrcp);
712 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); 674 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc);
713 GNUNET_free (rc); 675 GNUNET_free(rc);
714 if ((0 == address_resolutions) && (iterate_connections)) 676 if ((0 == address_resolutions) && (iterate_connections))
715 { 677 {
716 if (GNUNET_SCHEDULER_NO_TASK != end) 678 if (GNUNET_SCHEDULER_NO_TASK != end)
717 { 679 {
718 GNUNET_SCHEDULER_cancel (end); 680 GNUNET_SCHEDULER_cancel (end);
719 end = GNUNET_SCHEDULER_NO_TASK; 681 end = GNUNET_SCHEDULER_NO_TASK;
720 } 682 }
721 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 683 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
722 { 684 {
723 GNUNET_SCHEDULER_cancel (op_timeout); 685 GNUNET_SCHEDULER_cancel (op_timeout);
724 op_timeout = GNUNET_SCHEDULER_NO_TASK; 686 op_timeout = GNUNET_SCHEDULER_NO_TASK;
725 } 687 }
726 ret = 0; 688 ret = 0;
727 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 689 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
728 } 690 }
729 } 691 }
730} 692}
731 693
732
733static void 694static void
734resolve_address (const struct GNUNET_HELLO_Address *address, 695resolve_address (const struct GNUNET_HELLO_Address *address, int numeric)
735 int numeric)
736{ 696{
737 struct ResolutionContext *rc; 697 struct ResolutionContext *rc;
738 698
739 rc = GNUNET_new (struct ResolutionContext); 699 rc = GNUNET_new (struct ResolutionContext);
740 GNUNET_assert (NULL != rc); 700 GNUNET_assert(NULL != rc);
741 GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc); 701 GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc);
742 address_resolutions ++; 702 address_resolutions++;
743 703
744 rc->addrcp = GNUNET_HELLO_address_copy(address); 704 rc->addrcp = GNUNET_HELLO_address_copy (address);
745 rc->printed = GNUNET_NO; 705 rc->printed = GNUNET_NO;
746 /* Resolve address to string */ 706 /* Resolve address to string */
747 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, 707 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric,
748 RESOLUTION_TIMEOUT, &process_string, 708 RESOLUTION_TIMEOUT, &process_string, rc);
749 rc);
750} 709}
751 710
752/** 711/**
753 * Function to call with a binary address 712 * Function called with information about a peers
754 * 713 *
755 * @param cls closure 714 * @param cls closure
756 * @param peer identity of the peer 715 * @param peer identity of the peer, NULL for final callback when operation done
757 * @param address binary address (NULL on disconnect) 716 * @param address binary address used to communicate with this peer,
717 * NULL on disconnect or when done
718 * @param state current state this peer is in
719 * @param state_timeout time out for the current state
720 *
758 */ 721 */
759static void 722static void
760process_address (void *cls, const struct GNUNET_PeerIdentity *peer, 723process_peer_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
761 const struct GNUNET_HELLO_Address *address) 724 const struct GNUNET_HELLO_Address *address,
725 enum GNUNET_TRANSPORT_PeerState state,
726 struct GNUNET_TIME_Absolute state_timeout)
762{ 727{
763 if (peer == NULL) 728 if (peer == NULL )
764 { 729 {
765 /* done */ 730 /* done */
766 address_resolution_in_progress = GNUNET_NO; 731 address_resolution_in_progress = GNUNET_NO;
767 pic = NULL; 732 pic = NULL;
768 if (GNUNET_SCHEDULER_NO_TASK != end) 733 if (GNUNET_SCHEDULER_NO_TASK != end)
769 GNUNET_SCHEDULER_cancel (end); 734 GNUNET_SCHEDULER_cancel (end);
770 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 735 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
771 return; 736 return;
772 } 737 }
773 if (address == NULL) 738 if (address == NULL )
774 { 739 {
775 FPRINTF (stdout, _("Peer `%s' disconnected\n"), GNUNET_i2s (peer)); 740 FPRINTF (stdout, _("Peer `%s' disconnected\n"), GNUNET_i2s (peer));
776 return; 741 return;
777 } 742 }
778 743
779 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 744 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
780 GNUNET_SCHEDULER_cancel (op_timeout); 745 GNUNET_SCHEDULER_cancel (op_timeout);
781 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 746 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
782 &operation_timeout, NULL); 747 NULL );
783 748
784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received address for peer `%s': %s\n", 749 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received address for peer `%s': %s\n",
785 GNUNET_i2s (peer), address->transport_name); 750 GNUNET_i2s (peer), address->transport_name);
786 resolve_address (address, numeric); 751 resolve_address (address, numeric);
787} 752}
788 753
789
790static void 754static void
791try_connect_cb (void *cls, 755try_connect_cb (void *cls, const int result)
792 const int result)
793{ 756{
794 static int retries = 0; 757 static int retries = 0;
795 if (GNUNET_OK == result) 758 if (GNUNET_OK == result)
796 { 759 {
797 tc_handle = NULL; 760 tc_handle = NULL;
798 return; 761 return;
799 } 762 }
800 retries ++; 763 retries++;
801 if (retries < 10) 764 if (retries < 10)
802 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL); 765 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
766 NULL );
803 else 767 else
804 { 768 {
805 FPRINTF (stderr, "%s", _("Failed to send connect request to transport service\n")); 769 FPRINTF (stderr, "%s",
770 _("Failed to send connect request to transport service\n") );
806 if (GNUNET_SCHEDULER_NO_TASK != end) 771 if (GNUNET_SCHEDULER_NO_TASK != end)
807 GNUNET_SCHEDULER_cancel (end); 772 GNUNET_SCHEDULER_cancel (end);
808 ret = 1; 773 ret = 1;
809 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 774 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
810 return; 775 return;
811 } 776 }
812} 777}
813 778
814
815/** 779/**
816 * Function called with the result of the check if the 'transport' 780 * Function called with the result of the check if the 'transport'
817 * service is running. 781 * service is running.
@@ -820,43 +784,43 @@ try_connect_cb (void *cls,
820 * @param result #GNUNET_YES if transport is running 784 * @param result #GNUNET_YES if transport is running
821 */ 785 */
822static void 786static void
823testservice_task (void *cls, 787testservice_task (void *cls, int result)
824 int result)
825{ 788{
826 int counter = 0; 789 int counter = 0;
827 ret = 1; 790 ret = 1;
828 791
829 if (GNUNET_YES != result) 792 if (GNUNET_YES != result)
830 { 793 {
831 FPRINTF (stderr, 794 FPRINTF (stderr, _("Service `%s' is not running\n"), "transport");
832 _("Service `%s' is not running\n"), "transport");
833 return; 795 return;
834 } 796 }
835 797
836 if ( (NULL != cpid) && 798 if ((NULL != cpid)
837 (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, 799 && (GNUNET_OK
838 strlen (cpid), 800 != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, strlen (cpid),
839 &pid.public_key))) 801 &pid.public_key)))
840 { 802 {
841 FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid); 803 FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
842 return; 804 return;
843 } 805 }
844 806
845 counter = benchmark_send + benchmark_receive + iterate_connections + 807 counter = benchmark_send + benchmark_receive + iterate_connections
846 monitor_connections + monitor_connects + try_connect; 808 + monitor_connections + monitor_connects + try_connect;
847 809
848 if (1 < counter) 810 if (1 < counter)
849 { 811 {
850 FPRINTF (stderr, 812 FPRINTF (stderr,
851 _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s\n"), 813 _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s\n"),
852 "connect", "benchmark send", "benchmark receive", "information", "monitor", "events"); 814 "connect", "benchmark send", "benchmark receive", "information",
815 "monitor", "events");
853 return; 816 return;
854 } 817 }
855 if (0 == counter) 818 if (0 == counter)
856 { 819 {
857 FPRINTF (stderr, 820 FPRINTF (stderr,
858 _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s\n"), 821 _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s\n"),
859 "connect", "benchmark send", "benchmark receive", "information", "monitor", "events"); 822 "connect", "benchmark send", "benchmark receive", "information",
823 "monitor", "events");
860 return; 824 return;
861 } 825 }
862 826
@@ -864,35 +828,30 @@ testservice_task (void *cls,
864 { 828 {
865 if (NULL == cpid) 829 if (NULL == cpid)
866 { 830 {
867 FPRINTF (stderr, 831 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
868 _("Option `%s' makes no sense without option `%s'.\n"), 832 "-C", "-p");
869 "-C", "-p");
870 ret = 1; 833 ret = 1;
871 return; 834 return;
872 } 835 }
873 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 836 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
874 &notify_receive, 837 &notify_connect, &notify_disconnect);
875 &notify_connect,
876 &notify_disconnect);
877 if (NULL == handle) 838 if (NULL == handle)
878 { 839 {
879 FPRINTF (stderr, 840 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
880 "%s", 841 ret = 1;
881 _("Failed to connect to transport service\n")); 842 return;
882 ret = 1;
883 return;
884 } 843 }
885 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL); 844 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
845 NULL );
886 if (NULL == tc_handle) 846 if (NULL == tc_handle)
887 { 847 {
888 FPRINTF (stderr, 848 FPRINTF (stderr, "%s",
889 "%s", 849 _("Failed to send request to transport service\n") );
890 _("Failed to send request to transport service\n"));
891 ret = 1; 850 ret = 1;
892 return; 851 return;
893 } 852 }
894 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 853 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
895 &operation_timeout, NULL); 854 NULL );
896 855
897 } 856 }
898 else if (benchmark_send) /* -s: Benchmark sending */ 857 else if (benchmark_send) /* -s: Benchmark sending */
@@ -900,76 +859,68 @@ testservice_task (void *cls,
900 if (NULL == cpid) 859 if (NULL == cpid)
901 { 860 {
902 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"), 861 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
903 "-s", "-p"); 862 "-s", "-p");
904 ret = 1; 863 ret = 1;
905 return; 864 return;
906 } 865 }
907 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 866 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
908 &notify_receive, 867 &notify_connect, &notify_disconnect);
909 &notify_connect,
910 &notify_disconnect);
911 if (NULL == handle) 868 if (NULL == handle)
912 { 869 {
913 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n")); 870 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
914 ret = 1; 871 ret = 1;
915 return; 872 return;
916 } 873 }
917 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL); 874 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
875 NULL );
918 if (NULL == tc_handle) 876 if (NULL == tc_handle)
919 { 877 {
920 FPRINTF (stderr, "%s", _("Failed to send request to transport service\n")); 878 FPRINTF (stderr, "%s",
921 ret = 1; 879 _("Failed to send request to transport service\n") );
922 return; 880 ret = 1;
881 return;
923 } 882 }
924 start_time = GNUNET_TIME_absolute_get (); 883 start_time = GNUNET_TIME_absolute_get ();
925 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 884 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
926 &operation_timeout, NULL); 885 NULL );
927 } 886 }
928 else if (benchmark_receive) /* -b: Benchmark receiving */ 887 else if (benchmark_receive) /* -b: Benchmark receiving */
929 { 888 {
930 handle = 889 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive, NULL,
931 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive, 890 NULL );
932 NULL, NULL);
933 if (NULL == handle) 891 if (NULL == handle)
934 { 892 {
935 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n")); 893 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
936 ret = 1; 894 ret = 1;
937 return; 895 return;
938 } 896 }
939 if (verbosity > 0) 897 if (verbosity > 0)
940 FPRINTF (stdout, "%s", _("Starting to receive benchmark data\n")); 898 FPRINTF (stdout, "%s", _("Starting to receive benchmark data\n") );
941 start_time = GNUNET_TIME_absolute_get (); 899 start_time = GNUNET_TIME_absolute_get ();
942 900
943 } 901 }
944 else if (iterate_connections) /* -i: List all active addresses once */ 902 else if (iterate_connections) /* -i: List information about peers once */
945 { 903 {
946 address_resolution_in_progress = GNUNET_YES; 904 address_resolution_in_progress = GNUNET_YES;
947 pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, 905 pic = GNUNET_TRANSPORT_monitor_peers (cfg, (NULL == cpid) ? NULL : &pid,
948 (NULL == cpid) ? NULL : &pid, 906 GNUNET_YES, TIMEOUT, &process_peer_cb, (void *) cfg);
949 GNUNET_YES, 907 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
950 TIMEOUT, 908 NULL );
951 &process_address, (void *) cfg);
952 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
953 &operation_timeout, NULL);
954 } 909 }
955 else if (monitor_connections) /* -m: List all active addresses continously */ 910 else if (monitor_connections) /* -m: List information about peers continuously */
956 { 911 {
957 address_resolution_in_progress = GNUNET_YES; 912 address_resolution_in_progress = GNUNET_YES;
958 pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, 913 pic = GNUNET_TRANSPORT_monitor_peers (cfg, (NULL == cpid) ? NULL : &pid,
959 (NULL == cpid) ? NULL : &pid, 914 GNUNET_NO, TIMEOUT, &process_peer_cb, (void *) cfg);
960 GNUNET_NO,
961 TIMEOUT,
962 &process_address, (void *) cfg);
963 } 915 }
964 else if (monitor_connects) /* -e : Monitor (dis)connect events continously */ 916 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
965 { 917 {
966 monitor_connect_counter = 0; 918 monitor_connect_counter = 0;
967 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, 919 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL,
968 &monitor_notify_connect, 920 &monitor_notify_connect, &monitor_notify_disconnect);
969 &monitor_notify_disconnect);
970 if (NULL == handle) 921 if (NULL == handle)
971 { 922 {
972 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n")); 923 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
973 ret = 1; 924 ret = 1;
974 return; 925 return;
975 } 926 }
@@ -977,17 +928,15 @@ testservice_task (void *cls,
977 } 928 }
978 else 929 else
979 { 930 {
980 GNUNET_break (0); 931 GNUNET_break(0);
981 return; 932 return;
982 } 933 }
983 934
984 end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 935 end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
985 &shutdown_task, 936 &shutdown_task, NULL );
986 NULL);
987 937
988} 938}
989 939
990
991/** 940/**
992 * Main function that will be run by the scheduler. 941 * Main function that will be run by the scheduler.
993 * 942 *
@@ -997,8 +946,8 @@ testservice_task (void *cls,
997 * @param mycfg configuration 946 * @param mycfg configuration
998 */ 947 */
999static void 948static void
1000run (void *cls, char *const *args, const char *cfgfile, 949run (void *cls, char * const *args, const char *cfgfile,
1001 const struct GNUNET_CONFIGURATION_Handle *mycfg) 950 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1002{ 951{
1003 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; 952 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1004 if (test_configuration) 953 if (test_configuration)
@@ -1006,62 +955,54 @@ run (void *cls, char *const *args, const char *cfgfile,
1006 do_test_configuration (cfg); 955 do_test_configuration (cfg);
1007 return; 956 return;
1008 } 957 }
1009 GNUNET_CLIENT_service_test ("transport", cfg, 958 GNUNET_CLIENT_service_test ("transport", cfg, GNUNET_TIME_UNIT_SECONDS,
1010 GNUNET_TIME_UNIT_SECONDS, 959 &testservice_task, (void *) cfg);
1011 &testservice_task,
1012 (void *) cfg);
1013} 960}
1014 961
1015
1016int 962int
1017main (int argc, char *const *argv) 963main (int argc, char * const *argv)
1018{ 964{
1019 int res; 965 int res;
1020 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 966 static const struct GNUNET_GETOPT_CommandLineOption options[] =
1021 {'b', "benchmark", NULL, 967 {
1022 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"), 968 { 'a', "all", NULL,
1023 0, &GNUNET_GETOPT_set_one, &benchmark_receive}, 969 gettext_noop ("print information for all peers (instead of only connected peers )"),
1024 {'C', "connect", NULL, 970 0, &GNUNET_GETOPT_set_one, &iterate_all },
1025 gettext_noop ("connect to a peer"), 971 { 'b', "benchmark", NULL,
1026 0, &GNUNET_GETOPT_set_one, &try_connect}, 972 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"),
1027 {'i', "information", NULL, 973 0, &GNUNET_GETOPT_set_one, &benchmark_receive }, { 'C', "connect",
1028 gettext_noop ("provide information about all current connections (once)"), 974 NULL, gettext_noop ("connect to a peer"), 0,
1029 0, &GNUNET_GETOPT_set_one, &iterate_connections}, 975 &GNUNET_GETOPT_set_one, &try_connect },
1030 {'m', "monitor", NULL, 976 { 'i', "information", NULL,
1031 gettext_noop ("provide information about all current connections (continuously)"), 977 gettext_noop ("provide information about all current connections (once)"),
1032 0, &GNUNET_GETOPT_set_one, &monitor_connections}, 978 0, &GNUNET_GETOPT_set_one, &iterate_connections },
1033 {'e', "events", NULL, 979 { 'm', "monitor", NULL,
1034 gettext_noop ("provide information about all connects and disconnect events (continuously)"), 980 gettext_noop ("provide information about all current connections (continuously)"),
1035 0, &GNUNET_GETOPT_set_one, &monitor_connects}, 981 0, &GNUNET_GETOPT_set_one, &monitor_connections },
1036 {'n', "numeric", NULL, 982 { 'e', "events", NULL,
1037 gettext_noop ("do not resolve hostnames"), 983 gettext_noop ("provide information about all connects and disconnect events (continuously)"),
1038 0, &GNUNET_GETOPT_set_one, &numeric}, 984 0, &GNUNET_GETOPT_set_one, &monitor_connects }, { 'n', "numeric",
1039 {'p', "peer", "PEER", 985 NULL, gettext_noop ("do not resolve hostnames"), 0,
1040 gettext_noop ("peer identity"), 986 &GNUNET_GETOPT_set_one, &numeric }, { 'p', "peer", "PEER",
1041 1, &GNUNET_GETOPT_set_string, &cpid}, 987 gettext_noop ("peer identity"), 1, &GNUNET_GETOPT_set_string,
1042 {'s', "send", NULL, 988 &cpid }, { 's', "send", NULL, gettext_noop
1043 gettext_noop 989 ("send data for benchmarking to the other peer (until CTRL-C)"), 0,
1044 ("send data for benchmarking to the other peer (until CTRL-C)"), 990 &GNUNET_GETOPT_set_one, &benchmark_send },
1045 0, &GNUNET_GETOPT_set_one, &benchmark_send}, 991 { 't', "test", NULL,
1046 {'t', "test", NULL, 992 gettext_noop ("test transport configuration (involves external server)"),
1047 gettext_noop ("test transport configuration (involves external server)"), 993 0, &GNUNET_GETOPT_set_one, &test_configuration },
1048 0, &GNUNET_GETOPT_set_one, &test_configuration}, 994 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
1049 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), 995 GNUNET_GETOPT_OPTION_END };
1050 GNUNET_GETOPT_OPTION_END
1051 };
1052 996
1053 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 997 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1054 return 2; 998 return 2;
1055 999
1056 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", 1000 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", gettext_noop
1057 gettext_noop 1001 ("Direct access to transport service."), options, &run, NULL );
1058 ("Direct access to transport service."), options, 1002 GNUNET_free((void * ) argv);
1059 &run, NULL);
1060 GNUNET_free ((void *) argv);
1061 if (GNUNET_OK == res) 1003 if (GNUNET_OK == res)
1062 return ret; 1004 return ret;
1063 return 1; 1005 return 1;
1064} 1006}
1065 1007
1066
1067/* end of gnunet-transport.c */ 1008/* end of gnunet-transport.c */