aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-04-10 12:55:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-04-10 12:55:53 +0000
commit5d3b18290de4f55f75f7afaf5a452ae87c9c7ffd (patch)
tree38d65f23d1772963587c65c2c178698053e261ac
parent8cb36e97194eef321a9aa6d74c00e477c937a3dc (diff)
downloadgnunet-5d3b18290de4f55f75f7afaf5a452ae87c9c7ffd.tar.gz
gnunet-5d3b18290de4f55f75f7afaf5a452ae87c9c7ffd.zip
dump hello to file
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c96
1 files changed, 95 insertions, 1 deletions
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index 93c765ced..6a5ae08cb 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -150,6 +150,11 @@ static int get_info;
150static char *put_uri; 150static char *put_uri;
151 151
152/** 152/**
153 * Option -d
154 */
155static char *dump_hello;
156
157/**
153 * Handle to peerinfo service. 158 * Handle to peerinfo service.
154 */ 159 */
155static struct GNUNET_PEERINFO_Handle *peerinfo; 160static struct GNUNET_PEERINFO_Handle *peerinfo;
@@ -379,6 +384,86 @@ print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
379 &print_address, pc); 384 &print_address, pc);
380} 385}
381 386
387/* ************************* DUMP Hello ************************** */
388
389static int count_addr(void *cls,
390 const struct GNUNET_HELLO_Address *address,
391 struct GNUNET_TIME_Absolute expiration)
392{
393 int *c = cls;
394 (*c) ++;
395 return GNUNET_OK;
396}
397
398/**
399 * Write Hello of my peer to a file.
400 *
401 * @param cls the 'struct GetUriContext'
402 * @param peer identity of the peer (unused)
403 * @param hello addresses of the peer
404 * @param err_msg error message
405 */
406static void
407dump_my_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
408 const struct GNUNET_HELLO_Message *hello,
409 const char *err_msg)
410{
411 unsigned int size;
412 unsigned int c_addr;
413 if (peer == NULL)
414 {
415 pic = NULL;
416 if (err_msg != NULL)
417 FPRINTF (stderr,
418 _("Error in communication with PEERINFO service: %s\n"),
419 err_msg);
420 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
421 return;
422 }
423
424 if (NULL == hello)
425 {
426 FPRINTF (stderr,
427 _("Failure: Did not receive HELLO\n"));
428 return;
429 }
430
431 size = GNUNET_HELLO_size (hello);
432 if (0 == size)
433 {
434 FPRINTF (stderr,
435 _("Failure: Received invalid HELLO\n"));
436 return;
437 }
438 if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello, hello, size,
439 GNUNET_DISK_PERM_USER_READ |
440 GNUNET_DISK_PERM_USER_WRITE |
441 GNUNET_DISK_PERM_GROUP_READ |
442 GNUNET_DISK_PERM_OTHER_READ))
443 {
444 FPRINTF (stderr, _("Failed to write HELLO with %u bytes to file `%s'\n"),
445 size, dump_hello);
446 if (0 != UNLINK (dump_hello))
447 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
448 GNUNET_ERROR_TYPE_BULK, "unlink", dump_hello);
449
450 }
451 c_addr = 0;
452 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, count_addr, &c_addr);
453
454 if (!be_quiet)
455 {
456 FPRINTF (stderr,
457 _("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"),
458 (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) ? "friend-only": "public",
459 c_addr, size, dump_hello);
460 }
461
462 GNUNET_free (dump_hello);
463 dump_hello = NULL;
464
465}
466
382 467
383/* ************************* GET URI ************************** */ 468/* ************************* GET URI ************************** */
384 469
@@ -564,7 +649,7 @@ run (void *cls, char *const *args, const char *cfgfile,
564 FPRINTF (stderr, "%s", _("Could not access PEERINFO service. Exiting.\n")); 649 FPRINTF (stderr, "%s", _("Could not access PEERINFO service. Exiting.\n"));
565 return; 650 return;
566 } 651 }
567 if ( (GNUNET_YES == get_self) || (GNUNET_YES == get_uri) ) 652 if ( (GNUNET_YES == get_self) || (GNUNET_YES == get_uri) || (NULL != dump_hello) )
568 { 653 {
569 /* load private key */ 654 /* load private key */
570 if (GNUNET_OK != 655 if (GNUNET_OK !=
@@ -649,6 +734,12 @@ state_machine (void *cls,
649 get_uri = GNUNET_NO; 734 get_uri = GNUNET_NO;
650 return; 735 return;
651 } 736 }
737 if (NULL != dump_hello)
738 {
739 pic = GNUNET_PEERINFO_iterate (peerinfo, include_friend_only, &my_peer_identity,
740 TIMEOUT, &dump_my_hello, NULL);
741 return;
742 }
652 GNUNET_SCHEDULER_shutdown (); 743 GNUNET_SCHEDULER_shutdown ();
653} 744}
654 745
@@ -679,6 +770,9 @@ main (int argc, char *const *argv)
679 {'i', "info", NULL, 770 {'i', "info", NULL,
680 gettext_noop ("list all known peers"), 771 gettext_noop ("list all known peers"),
681 0, &GNUNET_GETOPT_set_one, &get_info}, 772 0, &GNUNET_GETOPT_set_one, &get_info},
773 {'d', "dump-hello", NULL,
774 gettext_noop ("dump hello to file"),
775 1, &GNUNET_GETOPT_set_string, &dump_hello},
682 {'g', "get-hello", NULL, 776 {'g', "get-hello", NULL,
683 gettext_noop ("also output HELLO uri(s)"), 777 gettext_noop ("also output HELLO uri(s)"),
684 0, &GNUNET_GETOPT_set_one, &get_uri}, 778 0, &GNUNET_GETOPT_set_one, &get_uri},