2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2006, 2009 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
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
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file peerinfo/gnunet-peerinfo.c
23 * @brief Print information about other known peers.
24 * @author Christian Grothoff
27 #include "gnunet_crypto_lib.h"
28 #include "gnunet_configuration_lib.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_peerinfo_service.h"
31 #include "gnunet_program_lib.h"
33 static int no_resolve;
40 * Print information about the peer.
41 * Currently prints the GNUNET_PeerIdentity, trust and the IP.
42 * Could of course do more (e.g. resolve via DNS).
45 print_peer_info (void *cls,
46 const struct GNUNET_PeerIdentity *peer,
47 const struct GNUNET_HELLO_Message *hello, uint32_t trust)
49 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
51 /* FIXME: add printing of address information!
52 => need extended transport API! */
57 GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
59 printf ("%s\n", (const char *) &enc);
61 printf (_("Peer `%s' with trust %8u\n"), (const char *) &enc, trust);
65 * Main function that will be run by the scheduler.
68 * @param sched the scheduler to use
69 * @param args remaining command-line arguments
70 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
71 * @param cfg configuration
75 struct GNUNET_SCHEDULER_Handle *sched,
78 const struct GNUNET_CONFIGURATION_Handle *cfg)
80 struct GNUNET_CRYPTO_RsaPrivateKey *priv;
81 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
82 struct GNUNET_PeerIdentity pid;
83 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
86 if (get_self != GNUNET_YES)
88 (void) GNUNET_PEERINFO_iterate (cfg,
92 GNUNET_TIME_relative_multiply
93 (GNUNET_TIME_UNIT_SECONDS, 30),
94 &print_peer_info, NULL);
99 GNUNET_CONFIGURATION_get_value_filename (cfg,
104 _("Could not find option `%s:%s' in configuration.\n"),
109 priv = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
112 fprintf (stderr, _("Loading hostkey from `%s' failed.\n"), fn);
117 GNUNET_CRYPTO_rsa_key_get_public (priv, &pub);
118 GNUNET_CRYPTO_rsa_key_free (priv);
119 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
120 GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc);
122 printf ("%s\n", (char *) &enc);
124 printf (_("I am peer `%s'.\n"), (const char *) &enc);
130 * gnunet-peerinfo command line options
132 static struct GNUNET_GETOPT_CommandLineOption options[] = {
133 {'n', "numeric", NULL,
134 gettext_noop ("don't resolve host names"),
135 0, &GNUNET_GETOPT_set_one, &no_resolve},
137 gettext_noop ("output only the identity strings"),
138 0, &GNUNET_GETOPT_set_one, &be_quiet},
140 gettext_noop ("output our own identity only"),
141 0, &GNUNET_GETOPT_set_one, &get_self},
142 GNUNET_GETOPT_OPTION_END
146 * The main function to obtain peer information.
148 * @param argc number of arguments from the command line
149 * @param argv command line arguments
150 * @return 0 ok, 1 on error
153 main (int argc, char *const *argv)
156 GNUNET_PROGRAM_run (argc,
159 gettext_noop ("Print information about peers."),
160 options, &run, NULL)) ? 0 : 1;
163 /* end of gnunet-peerinfo.c */