diff options
Diffstat (limited to 'src/cadet')
-rw-r--r-- | src/cadet/gnunet-cadet-profiler.c | 2 | ||||
-rw-r--r-- | src/cadet/gnunet-cadet.c | 348 | ||||
-rw-r--r-- | src/cadet/test_cadet.c | 10 | ||||
-rw-r--r-- | src/cadet/test_cadet_flow.c | 10 |
4 files changed, 156 insertions, 214 deletions
diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c index 2de17dc9e..34ea53a57 100644 --- a/src/cadet/gnunet-cadet-profiler.c +++ b/src/cadet/gnunet-cadet-profiler.c | |||
@@ -305,7 +305,7 @@ show_end_data (void) | |||
305 | for (j = 0; j < peers_pinging; j++) | 305 | for (j = 0; j < peers_pinging; j++) |
306 | { | 306 | { |
307 | peer = &peers[j]; | 307 | peer = &peers[j]; |
308 | FPRINTF (stdout, | 308 | fprintf (stdout, |
309 | "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n", | 309 | "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n", |
310 | i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)), | 310 | i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)), |
311 | peer->pings[i], peer->pongs[i]); | 311 | peer->pings[i], peer->pongs[i]); |
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index 262cdf64d..4e81d52f2 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #include "gnunet_cadet_service.h" | 29 | #include "gnunet_cadet_service.h" |
30 | #include "cadet.h" | 30 | #include "cadet.h" |
31 | 31 | ||
32 | #define STREAM_BUFFER_SIZE 1024 // Pakets | 32 | #define STREAM_BUFFER_SIZE 1024 // Pakets |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Option -P. | 35 | * Option -P. |
@@ -158,16 +158,16 @@ enc_2s (uint16_t status) | |||
158 | { | 158 | { |
159 | switch (status) | 159 | switch (status) |
160 | { | 160 | { |
161 | case 0: | 161 | case 0: |
162 | return "NULL "; | 162 | return "NULL "; |
163 | case 1: | 163 | case 1: |
164 | return "KSENT"; | 164 | return "KSENT"; |
165 | case 2: | 165 | case 2: |
166 | return "KRECV"; | 166 | return "KRECV"; |
167 | case 3: | 167 | case 3: |
168 | return "READY"; | 168 | return "READY"; |
169 | default: | 169 | default: |
170 | return ""; | 170 | return ""; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
@@ -184,23 +184,22 @@ conn_2s (uint16_t status) | |||
184 | { | 184 | { |
185 | switch (status) | 185 | switch (status) |
186 | { | 186 | { |
187 | case 0: | 187 | case 0: |
188 | return "NEW "; | 188 | return "NEW "; |
189 | case 1: | 189 | case 1: |
190 | return "SRCH "; | 190 | return "SRCH "; |
191 | case 2: | 191 | case 2: |
192 | return "WAIT "; | 192 | return "WAIT "; |
193 | case 3: | 193 | case 3: |
194 | return "READY"; | 194 | return "READY"; |
195 | case 4: | 195 | case 4: |
196 | return "SHUTD"; | 196 | return "SHUTD"; |
197 | default: | 197 | default: |
198 | return ""; | 198 | return ""; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | 202 | ||
203 | |||
204 | /** | 203 | /** |
205 | * Task to shut down this application. | 204 | * Task to shut down this application. |
206 | * | 205 | * |
@@ -209,8 +208,7 @@ conn_2s (uint16_t status) | |||
209 | static void | 208 | static void |
210 | shutdown_task (void *cls) | 209 | shutdown_task (void *cls) |
211 | { | 210 | { |
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); |
213 | "Shutdown\n"); | ||
214 | if (NULL != lp) | 212 | if (NULL != lp) |
215 | { | 213 | { |
216 | GNUNET_CADET_close_port (lp); | 214 | GNUNET_CADET_close_port (lp); |
@@ -259,7 +257,7 @@ shutdown_task (void *cls) | |||
259 | } | 257 | } |
260 | 258 | ||
261 | void | 259 | void |
262 | mq_cb(void *cls) | 260 | mq_cb (void *cls) |
263 | { | 261 | { |
264 | listen_stdio (); | 262 | listen_stdio (); |
265 | } | 263 | } |
@@ -279,27 +277,21 @@ read_stdio (void *cls) | |||
279 | ssize_t data_size; | 277 | ssize_t data_size; |
280 | 278 | ||
281 | rd_task = NULL; | 279 | rd_task = NULL; |
282 | data_size = read (0, | 280 | data_size = read (0, buf, 60000); |
283 | buf, | ||
284 | 60000); | ||
285 | if (data_size < 1) | 281 | if (data_size < 1) |
286 | { | 282 | { |
287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
288 | "read() returned %s\n", strerror(errno)); | 284 | "read() returned %s\n", |
289 | GNUNET_SCHEDULER_shutdown(); | 285 | strerror (errno)); |
286 | GNUNET_SCHEDULER_shutdown (); | ||
290 | return; | 287 | return; |
291 | } | 288 | } |
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
293 | "Read %u bytes from stdio\n", | 290 | "Read %u bytes from stdio\n", |
294 | (unsigned int) data_size); | 291 | (unsigned int) data_size); |
295 | env = GNUNET_MQ_msg_extra (msg, | 292 | env = GNUNET_MQ_msg_extra (msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI); |
296 | data_size, | 293 | GNUNET_memcpy (&msg[1], buf, data_size); |
297 | GNUNET_MESSAGE_TYPE_CADET_CLI); | 294 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); |
298 | GNUNET_memcpy (&msg[1], | ||
299 | buf, | ||
300 | data_size); | ||
301 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), | ||
302 | env); | ||
303 | 295 | ||
304 | sent_pkt++; | 296 | sent_pkt++; |
305 | 297 | ||
@@ -333,8 +325,7 @@ listen_stdio () | |||
333 | 325 | ||
334 | /* FIXME: why use 'rs' here, seems overly complicated... */ | 326 | /* FIXME: why use 'rs' here, seems overly complicated... */ |
335 | rs = GNUNET_NETWORK_fdset_create (); | 327 | rs = GNUNET_NETWORK_fdset_create (); |
336 | GNUNET_NETWORK_fdset_set_native (rs, | 328 | GNUNET_NETWORK_fdset_set_native (rs, 0); /* STDIN */ |
337 | 0); /* STDIN */ | ||
338 | rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 329 | rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
339 | GNUNET_TIME_UNIT_FOREVER_REL, | 330 | GNUNET_TIME_UNIT_FOREVER_REL, |
340 | rs, | 331 | rs, |
@@ -355,11 +346,9 @@ listen_stdio () | |||
355 | * @param channel connection to the other end (henceforth invalid) | 346 | * @param channel connection to the other end (henceforth invalid) |
356 | */ | 347 | */ |
357 | static void | 348 | static void |
358 | channel_ended (void *cls, | 349 | channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel) |
359 | const struct GNUNET_CADET_Channel *channel) | ||
360 | { | 350 | { |
361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n"); |
362 | "Channel ended!\n"); | ||
363 | GNUNET_assert (channel == ch); | 352 | GNUNET_assert (channel == ch); |
364 | ch = NULL; | 353 | ch = NULL; |
365 | GNUNET_SCHEDULER_shutdown (); | 354 | GNUNET_SCHEDULER_shutdown (); |
@@ -413,10 +402,8 @@ send_echo (void *cls) | |||
413 | echo_task = NULL; | 402 | echo_task = NULL; |
414 | if (NULL == ch) | 403 | if (NULL == ch) |
415 | return; | 404 | return; |
416 | env = GNUNET_MQ_msg (msg, | 405 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CLI); |
417 | GNUNET_MESSAGE_TYPE_CADET_CLI); | 406 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); |
418 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), | ||
419 | env); | ||
420 | } | 407 | } |
421 | 408 | ||
422 | 409 | ||
@@ -429,8 +416,7 @@ send_echo (void *cls) | |||
429 | * #GNUNET_SYSERR to close it (signal serious error). | 416 | * #GNUNET_SYSERR to close it (signal serious error). |
430 | */ | 417 | */ |
431 | static int | 418 | static int |
432 | check_data (void *cls, | 419 | check_data (void *cls, const struct GNUNET_MessageHeader *message) |
433 | const struct GNUNET_MessageHeader *message) | ||
434 | { | 420 | { |
435 | return GNUNET_OK; /* all is well-formed */ | 421 | return GNUNET_OK; /* all is well-formed */ |
436 | } | 422 | } |
@@ -447,8 +433,7 @@ check_data (void *cls, | |||
447 | * @param message The actual message. | 433 | * @param message The actual message. |
448 | */ | 434 | */ |
449 | static void | 435 | static void |
450 | handle_data (void *cls, | 436 | handle_data (void *cls, const struct GNUNET_MessageHeader *message) |
451 | const struct GNUNET_MessageHeader *message) | ||
452 | { | 437 | { |
453 | size_t payload_size = ntohs (message->size) - sizeof (*message); | 438 | size_t payload_size = ntohs (message->size) - sizeof (*message); |
454 | uint16_t len; | 439 | uint16_t len; |
@@ -464,14 +449,10 @@ handle_data (void *cls, | |||
464 | struct GNUNET_MQ_Envelope *env; | 449 | struct GNUNET_MQ_Envelope *env; |
465 | struct GNUNET_MessageHeader *msg; | 450 | struct GNUNET_MessageHeader *msg; |
466 | 451 | ||
467 | env = GNUNET_MQ_msg_extra (msg, | 452 | env = |
468 | payload_size, | 453 | GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI); |
469 | GNUNET_MESSAGE_TYPE_CADET_CLI); | 454 | GNUNET_memcpy (&msg[1], &message[1], payload_size); |
470 | GNUNET_memcpy (&msg[1], | 455 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); |
471 | &message[1], | ||
472 | payload_size); | ||
473 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), | ||
474 | env); | ||
475 | return; | 456 | return; |
476 | } | 457 | } |
477 | else | 458 | else |
@@ -482,8 +463,7 @@ handle_data (void *cls, | |||
482 | echo_time = GNUNET_TIME_UNIT_FOREVER_ABS; | 463 | echo_time = GNUNET_TIME_UNIT_FOREVER_ABS; |
483 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 464 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
484 | "time: %s\n", | 465 | "time: %s\n", |
485 | GNUNET_STRINGS_relative_time_to_string (latency, | 466 | GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO)); |
486 | GNUNET_NO)); | ||
487 | echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 467 | echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
488 | &send_echo, | 468 | &send_echo, |
489 | NULL); | 469 | NULL); |
@@ -491,21 +471,16 @@ handle_data (void *cls, | |||
491 | } | 471 | } |
492 | 472 | ||
493 | len = ntohs (message->size) - sizeof (*message); | 473 | len = ntohs (message->size) - sizeof (*message); |
494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); |
495 | "Got %u bytes\n", | ||
496 | len); | ||
497 | buf = (const char *) &message[1]; | 475 | buf = (const char *) &message[1]; |
498 | off = 0; | 476 | off = 0; |
499 | while (off < len) | 477 | while (off < len) |
500 | { | 478 | { |
501 | done = write (1, | 479 | done = write (1, &buf[off], len - off); |
502 | &buf[off], | ||
503 | len - off); | ||
504 | if (done <= 0) | 480 | if (done <= 0) |
505 | { | 481 | { |
506 | if (-1 == done) | 482 | if (-1 == done) |
507 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 483 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write"); |
508 | "write"); | ||
509 | GNUNET_SCHEDULER_shutdown (); | 484 | GNUNET_SCHEDULER_shutdown (); |
510 | return; | 485 | return; |
511 | } | 486 | } |
@@ -524,16 +499,15 @@ handle_data (void *cls, | |||
524 | * @param ple information about peer, or NULL on "EOF". | 499 | * @param ple information about peer, or NULL on "EOF". |
525 | */ | 500 | */ |
526 | static void | 501 | static void |
527 | peers_callback (void *cls, | 502 | peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple) |
528 | const struct GNUNET_CADET_PeerListEntry *ple) | ||
529 | { | 503 | { |
530 | if (NULL == ple) | 504 | if (NULL == ple) |
531 | { | 505 | { |
532 | plo = NULL; | 506 | plo = NULL; |
533 | GNUNET_SCHEDULER_shutdown(); | 507 | GNUNET_SCHEDULER_shutdown (); |
534 | return; | 508 | return; |
535 | } | 509 | } |
536 | FPRINTF (stdout, | 510 | fprintf (stdout, |
537 | "%s tunnel: %c, paths: %u\n", | 511 | "%s tunnel: %c, paths: %u\n", |
538 | GNUNET_i2s_full (&ple->peer), | 512 | GNUNET_i2s_full (&ple->peer), |
539 | ple->have_tunnel ? 'Y' : 'N', | 513 | ple->have_tunnel ? 'Y' : 'N', |
@@ -549,24 +523,20 @@ peers_callback (void *cls, | |||
549 | * @param ppd path detail | 523 | * @param ppd path detail |
550 | */ | 524 | */ |
551 | static void | 525 | static void |
552 | path_callback (void *cls, | 526 | path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd) |
553 | const struct GNUNET_CADET_PeerPathDetail *ppd) | ||
554 | { | 527 | { |
555 | if (NULL == ppd) | 528 | if (NULL == ppd) |
556 | { | 529 | { |
557 | gpo = NULL; | 530 | gpo = NULL; |
558 | GNUNET_SCHEDULER_shutdown(); | 531 | GNUNET_SCHEDULER_shutdown (); |
559 | return; | 532 | return; |
560 | } | 533 | } |
561 | FPRINTF (stdout, | 534 | fprintf (stdout, "Path of length %u: ", ppd->path_length); |
562 | "Path of length %u: ", | ||
563 | ppd->path_length); | ||
564 | for (unsigned int i = 0; i < ppd->path_length; i++) | 535 | for (unsigned int i = 0; i < ppd->path_length; i++) |
565 | FPRINTF (stdout, | 536 | fprintf (stdout, |
566 | (i == ppd->target_offset) ? "*%s* " : "%s ", | 537 | (i == ppd->target_offset) ? "*%s* " : "%s ", |
567 | GNUNET_i2s (&ppd->path[i])); | 538 | GNUNET_i2s (&ppd->path[i])); |
568 | FPRINTF (stdout, | 539 | fprintf (stdout, "\n"); |
569 | "\n"); | ||
570 | } | 540 | } |
571 | 541 | ||
572 | 542 | ||
@@ -577,16 +547,15 @@ path_callback (void *cls, | |||
577 | * @param td tunnel details | 547 | * @param td tunnel details |
578 | */ | 548 | */ |
579 | static void | 549 | static void |
580 | tunnels_callback (void *cls, | 550 | tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td) |
581 | const struct GNUNET_CADET_TunnelDetails *td) | ||
582 | { | 551 | { |
583 | if (NULL == td) | 552 | if (NULL == td) |
584 | { | 553 | { |
585 | tio = NULL; | 554 | tio = NULL; |
586 | GNUNET_SCHEDULER_shutdown(); | 555 | GNUNET_SCHEDULER_shutdown (); |
587 | return; | 556 | return; |
588 | } | 557 | } |
589 | FPRINTF (stdout, | 558 | fprintf (stdout, |
590 | "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", | 559 | "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", |
591 | GNUNET_i2s_full (&td->peer), | 560 | GNUNET_i2s_full (&td->peer), |
592 | enc_2s (td->estate), | 561 | enc_2s (td->estate), |
@@ -605,9 +574,7 @@ static void | |||
605 | get_peers (void *cls) | 574 | get_peers (void *cls) |
606 | { | 575 | { |
607 | job = NULL; | 576 | job = NULL; |
608 | plo = GNUNET_CADET_list_peers (my_cfg, | 577 | plo = GNUNET_CADET_list_peers (my_cfg, &peers_callback, NULL); |
609 | &peers_callback, | ||
610 | NULL); | ||
611 | } | 578 | } |
612 | 579 | ||
613 | 580 | ||
@@ -622,21 +589,15 @@ show_peer (void *cls) | |||
622 | struct GNUNET_PeerIdentity pid; | 589 | struct GNUNET_PeerIdentity pid; |
623 | 590 | ||
624 | job = NULL; | 591 | job = NULL; |
625 | if (GNUNET_OK != | 592 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, |
626 | GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, | 593 | strlen (peer_id), |
627 | strlen (peer_id), | 594 | &pid.public_key)) |
628 | &pid.public_key)) | ||
629 | { | 595 | { |
630 | fprintf (stderr, | 596 | fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id); |
631 | _("Invalid peer ID `%s'\n"), | 597 | GNUNET_SCHEDULER_shutdown (); |
632 | peer_id); | ||
633 | GNUNET_SCHEDULER_shutdown(); | ||
634 | return; | 598 | return; |
635 | } | 599 | } |
636 | gpo = GNUNET_CADET_get_path (my_cfg, | 600 | gpo = GNUNET_CADET_get_path (my_cfg, &pid, &path_callback, NULL); |
637 | &pid, | ||
638 | &path_callback, | ||
639 | NULL); | ||
640 | } | 601 | } |
641 | 602 | ||
642 | 603 | ||
@@ -649,9 +610,7 @@ static void | |||
649 | get_tunnels (void *cls) | 610 | get_tunnels (void *cls) |
650 | { | 611 | { |
651 | job = NULL; | 612 | job = NULL; |
652 | tio = GNUNET_CADET_list_tunnels (my_cfg, | 613 | tio = GNUNET_CADET_list_tunnels (my_cfg, &tunnels_callback, NULL); |
653 | &tunnels_callback, | ||
654 | NULL); | ||
655 | } | 614 | } |
656 | 615 | ||
657 | 616 | ||
@@ -695,13 +654,12 @@ run (void *cls, | |||
695 | const char *cfgfile, | 654 | const char *cfgfile, |
696 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 655 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
697 | { | 656 | { |
698 | struct GNUNET_MQ_MessageHandler handlers[] = { | 657 | struct GNUNET_MQ_MessageHandler handlers[] = |
699 | GNUNET_MQ_hd_var_size (data, | 658 | {GNUNET_MQ_hd_var_size (data, |
700 | GNUNET_MESSAGE_TYPE_CADET_CLI, | 659 | GNUNET_MESSAGE_TYPE_CADET_CLI, |
701 | struct GNUNET_MessageHeader, | 660 | struct GNUNET_MessageHeader, |
702 | NULL), | 661 | NULL), |
703 | GNUNET_MQ_handler_end () | 662 | GNUNET_MQ_handler_end ()}; |
704 | }; | ||
705 | 663 | ||
706 | /* FIXME add option to monitor apps */ | 664 | /* FIXME add option to monitor apps */ |
707 | my_cfg = cfg; | 665 | my_cfg = cfg; |
@@ -709,58 +667,45 @@ run (void *cls, | |||
709 | if (target_id && args[1]) | 667 | if (target_id && args[1]) |
710 | target_port = args[1]; | 668 | target_port = args[1]; |
711 | 669 | ||
712 | if ( (0 != (request_peers | request_tunnels) | 670 | if ((0 != (request_peers | request_tunnels) || NULL != conn_id || |
713 | || NULL != conn_id | 671 | NULL != channel_id) && |
714 | || NULL != channel_id) | 672 | target_id != NULL) |
715 | && target_id != NULL) | ||
716 | { | 673 | { |
717 | FPRINTF (stderr, | 674 | fprintf (stderr, |
718 | _("Extra arguments are not applicable " | 675 | _ ("Extra arguments are not applicable " |
719 | "in combination with this option.\n")); | 676 | "in combination with this option.\n")); |
720 | return; | 677 | return; |
721 | } | 678 | } |
722 | 679 | ||
723 | if (NULL != peer_id) | 680 | if (NULL != peer_id) |
724 | { | 681 | { |
725 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 682 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n"); |
726 | "Show peer\n"); | 683 | job = GNUNET_SCHEDULER_add_now (&show_peer, NULL); |
727 | job = GNUNET_SCHEDULER_add_now (&show_peer, | ||
728 | NULL); | ||
729 | } | 684 | } |
730 | else if (NULL != channel_id) | 685 | else if (NULL != channel_id) |
731 | { | 686 | { |
732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 687 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n"); |
733 | "Show channel\n"); | 688 | job = GNUNET_SCHEDULER_add_now (&show_channel, NULL); |
734 | job = GNUNET_SCHEDULER_add_now (&show_channel, | ||
735 | NULL); | ||
736 | } | 689 | } |
737 | else if (NULL != conn_id) | 690 | else if (NULL != conn_id) |
738 | { | 691 | { |
739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n"); |
740 | "Show connection\n"); | 693 | job = GNUNET_SCHEDULER_add_now (&show_connection, NULL); |
741 | job = GNUNET_SCHEDULER_add_now (&show_connection, | ||
742 | NULL); | ||
743 | } | 694 | } |
744 | else if (GNUNET_YES == request_peers) | 695 | else if (GNUNET_YES == request_peers) |
745 | { | 696 | { |
746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 697 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n"); |
747 | "Show all peers\n"); | 698 | job = GNUNET_SCHEDULER_add_now (&get_peers, NULL); |
748 | job = GNUNET_SCHEDULER_add_now (&get_peers, | ||
749 | NULL); | ||
750 | } | 699 | } |
751 | else if (GNUNET_YES == request_tunnels) | 700 | else if (GNUNET_YES == request_tunnels) |
752 | { | 701 | { |
753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n"); |
754 | "Show all tunnels\n"); | 703 | job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL); |
755 | job = GNUNET_SCHEDULER_add_now (&get_tunnels, | ||
756 | NULL); | ||
757 | } | 704 | } |
758 | 705 | ||
759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n"); |
760 | "Connecting to CADET service\n"); | ||
761 | mh = GNUNET_CADET_connect (cfg); | 707 | mh = GNUNET_CADET_connect (cfg); |
762 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 708 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
763 | NULL); | ||
764 | if (NULL == mh) | 709 | if (NULL == mh) |
765 | { | 710 | { |
766 | GNUNET_SCHEDULER_shutdown (); | 711 | GNUNET_SCHEDULER_shutdown (); |
@@ -768,11 +713,8 @@ run (void *cls, | |||
768 | } | 713 | } |
769 | if (NULL != listen_port) | 714 | if (NULL != listen_port) |
770 | { | 715 | { |
771 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n"); |
772 | "Opening CADET listen port\n"); | 717 | GNUNET_CRYPTO_hash (listen_port, strlen (listen_port), &porthash); |
773 | GNUNET_CRYPTO_hash (listen_port, | ||
774 | strlen (listen_port), | ||
775 | &porthash); | ||
776 | lp = GNUNET_CADET_open_port (mh, | 718 | lp = GNUNET_CADET_open_port (mh, |
777 | &porthash, | 719 | &porthash, |
778 | &channel_incoming, | 720 | &channel_incoming, |
@@ -791,7 +733,7 @@ run (void *cls, | |||
791 | &pid.public_key)) | 733 | &pid.public_key)) |
792 | { | 734 | { |
793 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 735 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
794 | _("Invalid target `%s'\n"), | 736 | _ ("Invalid target `%s'\n"), |
795 | target_id); | 737 | target_id); |
796 | GNUNET_SCHEDULER_shutdown (); | 738 | GNUNET_SCHEDULER_shutdown (); |
797 | return; | 739 | return; |
@@ -800,9 +742,7 @@ run (void *cls, | |||
800 | "Connecting to `%s:%s'\n", | 742 | "Connecting to `%s:%s'\n", |
801 | target_id, | 743 | target_id, |
802 | target_port); | 744 | target_port); |
803 | GNUNET_CRYPTO_hash (target_port, | 745 | GNUNET_CRYPTO_hash (target_port, strlen (target_port), &porthash); |
804 | strlen(target_port), | ||
805 | &porthash); | ||
806 | ch = GNUNET_CADET_channel_create (mh, | 746 | ch = GNUNET_CADET_channel_create (mh, |
807 | NULL, | 747 | NULL, |
808 | &pid, | 748 | &pid, |
@@ -812,8 +752,7 @@ run (void *cls, | |||
812 | handlers); | 752 | handlers); |
813 | if (GNUNET_YES == echo) | 753 | if (GNUNET_YES == echo) |
814 | { | 754 | { |
815 | echo_task = GNUNET_SCHEDULER_add_now (&send_echo, | 755 | echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL); |
816 | NULL); | ||
817 | } | 756 | } |
818 | else | 757 | else |
819 | { | 758 | { |
@@ -821,12 +760,9 @@ run (void *cls, | |||
821 | } | 760 | } |
822 | } | 761 | } |
823 | 762 | ||
824 | if ( (NULL == lp) && | 763 | if ((NULL == lp) && (NULL == job) && (NULL == ch)) |
825 | (NULL == job) && | ||
826 | (NULL == ch) ) | ||
827 | { | 764 | { |
828 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 765 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _ ("No action requested\n")); |
829 | _("No action requested\n")); | ||
830 | GNUNET_SCHEDULER_shutdown (); | 766 | GNUNET_SCHEDULER_shutdown (); |
831 | return; | 767 | return; |
832 | } | 768 | } |
@@ -841,52 +777,58 @@ run (void *cls, | |||
841 | * @return 0 ok, 1 on error | 777 | * @return 0 ok, 1 on error |
842 | */ | 778 | */ |
843 | int | 779 | int |
844 | main (int argc, | 780 | main (int argc, char *const *argv) |
845 | char *const *argv) | ||
846 | { | 781 | { |
847 | int res; | 782 | int res; |
848 | const char helpstr[] = "Create tunnels and retrieve info about CADET's status."; | 783 | const char helpstr[] = |
849 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 784 | "Create tunnels and retrieve info about CADET's status."; |
850 | /* I would use the terminology 'circuit' here... --lynX */ | 785 | struct GNUNET_GETOPT_CommandLineOption options[] = |
851 | GNUNET_GETOPT_option_string ('C', | 786 | {/* I would use the terminology 'circuit' here... --lynX */ |
852 | "connection", | 787 | GNUNET_GETOPT_option_string ( |
853 | "CONNECTION_ID", | 788 | 'C', |
854 | gettext_noop ("Provide information about a particular connection"), | 789 | "connection", |
855 | &conn_id), | 790 | "CONNECTION_ID", |
856 | GNUNET_GETOPT_option_flag ('e', | 791 | gettext_noop ("Provide information about a particular connection"), |
857 | "echo", | 792 | &conn_id), |
858 | gettext_noop ("Activate echo mode"), | 793 | GNUNET_GETOPT_option_flag ('e', |
859 | &echo), | 794 | "echo", |
860 | GNUNET_GETOPT_option_string ('o', | 795 | gettext_noop ("Activate echo mode"), |
861 | "open-port", | 796 | &echo), |
862 | "SHARED_SECRET", | 797 | GNUNET_GETOPT_option_string ( |
863 | gettext_noop ("Listen for connections using a shared secret among sender and recipient"), | 798 | 'o', |
864 | &listen_port), | 799 | "open-port", |
865 | GNUNET_GETOPT_option_string ('p', | 800 | "SHARED_SECRET", |
866 | "peer", | 801 | gettext_noop ( |
867 | "PEER_ID", | 802 | "Listen for connections using a shared secret among sender and recipient"), |
868 | gettext_noop ("Provide information about a patricular peer"), | 803 | &listen_port), |
869 | &peer_id), | 804 | GNUNET_GETOPT_option_string ('p', |
870 | GNUNET_GETOPT_option_flag ('P', | 805 | "peer", |
871 | "peers", | 806 | "PEER_ID", |
872 | gettext_noop ("Provide information about all peers"), | 807 | gettext_noop ( |
873 | &request_peers), | 808 | "Provide information about a patricular peer"), |
874 | GNUNET_GETOPT_option_flag ('T', | 809 | &peer_id), |
875 | "tunnels", | 810 | GNUNET_GETOPT_option_flag ('P', |
876 | gettext_noop ("Provide information about all tunnels"), | 811 | "peers", |
877 | &request_tunnels), | 812 | gettext_noop ( |
878 | GNUNET_GETOPT_OPTION_END | 813 | "Provide information about all peers"), |
879 | }; | 814 | &request_peers), |
880 | 815 | GNUNET_GETOPT_option_flag ('T', | |
881 | if (GNUNET_OK != | 816 | "tunnels", |
882 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 817 | gettext_noop ( |
883 | &argc, &argv)) | 818 | "Provide information about all tunnels"), |
819 | &request_tunnels), | ||
820 | GNUNET_GETOPT_OPTION_END}; | ||
821 | |||
822 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
884 | return 2; | 823 | return 2; |
885 | 824 | ||
886 | res = GNUNET_PROGRAM_run (argc, argv, | 825 | res = GNUNET_PROGRAM_run (argc, |
826 | argv, | ||
887 | "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)", | 827 | "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)", |
888 | gettext_noop (helpstr), | 828 | gettext_noop (helpstr), |
889 | options, &run, NULL); | 829 | options, |
830 | &run, | ||
831 | NULL); | ||
890 | 832 | ||
891 | GNUNET_free ((void *) argv); | 833 | GNUNET_free ((void *) argv); |
892 | 834 | ||
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index 80a6e8227..5a28b439e 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c | |||
@@ -280,16 +280,16 @@ show_end_data (void) | |||
280 | 280 | ||
281 | end_time = GNUNET_TIME_absolute_get (); | 281 | end_time = GNUNET_TIME_absolute_get (); |
282 | total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); | 282 | total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); |
283 | FPRINTF (stderr, | 283 | fprintf (stderr, |
284 | "\nResults of test \"%s\"\n", | 284 | "\nResults of test \"%s\"\n", |
285 | test_name); | 285 | test_name); |
286 | FPRINTF (stderr, | 286 | fprintf (stderr, |
287 | "Test time %s\n", | 287 | "Test time %s\n", |
288 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); | 288 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); |
289 | FPRINTF (stderr, | 289 | fprintf (stderr, |
290 | "Test bandwidth: %f kb/s\n", | 290 | "Test bandwidth: %f kb/s\n", |
291 | 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms | 291 | 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms |
292 | FPRINTF (stderr, | 292 | fprintf (stderr, |
293 | "Test throughput: %f packets/s\n\n", | 293 | "Test throughput: %f packets/s\n\n", |
294 | total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms | 294 | total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms |
295 | GAUGER ("CADET", | 295 | GAUGER ("CADET", |
@@ -1171,7 +1171,7 @@ main (int argc, char *argv[]) | |||
1171 | short_time = SHORT_TIME; | 1171 | short_time = SHORT_TIME; |
1172 | if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv)) | 1172 | if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv)) |
1173 | { | 1173 | { |
1174 | FPRINTF (stderr, "test failed: problem with CLI parameters\n"); | 1174 | fprintf (stderr, "test failed: problem with CLI parameters\n"); |
1175 | exit (1); | 1175 | exit (1); |
1176 | } | 1176 | } |
1177 | 1177 | ||
diff --git a/src/cadet/test_cadet_flow.c b/src/cadet/test_cadet_flow.c index 552d0fdb3..87e7b9a03 100644 --- a/src/cadet/test_cadet_flow.c +++ b/src/cadet/test_cadet_flow.c | |||
@@ -216,16 +216,16 @@ show_end_data (void) | |||
216 | 216 | ||
217 | end_time = GNUNET_TIME_absolute_get (); | 217 | end_time = GNUNET_TIME_absolute_get (); |
218 | total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); | 218 | total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); |
219 | FPRINTF (stderr, | 219 | fprintf (stderr, |
220 | "\nResults of test \"%s\"\n", | 220 | "\nResults of test \"%s\"\n", |
221 | test_name); | 221 | test_name); |
222 | FPRINTF (stderr, | 222 | fprintf (stderr, |
223 | "Test time %s\n", | 223 | "Test time %s\n", |
224 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); | 224 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); |
225 | FPRINTF (stderr, | 225 | fprintf (stderr, |
226 | "Test bandwidth: %f kb/s\n", | 226 | "Test bandwidth: %f kb/s\n", |
227 | 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms | 227 | 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms |
228 | FPRINTF (stderr, | 228 | fprintf (stderr, |
229 | "Test throughput: %f packets/s\n\n", | 229 | "Test throughput: %f packets/s\n\n", |
230 | total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms | 230 | total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms |
231 | GAUGER ("CADET", | 231 | GAUGER ("CADET", |
@@ -863,7 +863,7 @@ main (int argc, | |||
863 | argc, | 863 | argc, |
864 | argv)) | 864 | argv)) |
865 | { | 865 | { |
866 | FPRINTF (stderr, | 866 | fprintf (stderr, |
867 | "test failed: problem with CLI parameters\n"); | 867 | "test failed: problem with CLI parameters\n"); |
868 | return 1; | 868 | return 1; |
869 | } | 869 | } |