fix for bug #0003416: do not stop parsing uri when plugin is not found
[oweals/gnunet.git] / src / peerinfo-tool / gnunet-peerinfo.c
1 /*
2      This file is part of GNUnet.
3      (C) 2001-2012 Christian Grothoff (and other contributing authors)
4
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 3, or (at your
8      option) any later version.
9
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.
14
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.
19 */
20
21 /**
22  * @file peerinfo-tool/gnunet-peerinfo.c
23  * @brief Print information about other known peers.
24  * @author Christian Grothoff
25  * @author Matthias Wachs
26  */
27 #include "platform.h"
28 #include "gnunet_crypto_lib.h"
29 #include "gnunet_configuration_lib.h"
30 #include "gnunet_getopt_lib.h"
31 #include "gnunet_program_lib.h"
32 #include "gnunet_hello_lib.h"
33 #include "gnunet_transport_service.h"
34 #include "gnunet_peerinfo_service.h"
35 #include "gnunet-peerinfo_plugins.h"
36
37 /**
38  * How long until we time out during peerinfo iterations?
39  */
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
41
42 /**
43  * Structure we use to collect printable address information.
44  */
45 struct PrintContext;
46
47 /**
48  * Record we keep for each printable address.
49  */
50 struct AddressRecord
51 {
52   /**
53    * Current address-to-string context (if active, otherwise NULL).
54    */
55   struct GNUNET_TRANSPORT_AddressToStringContext *atsc;
56
57   /**
58    * Address expiration time
59    */
60   struct GNUNET_TIME_Absolute expiration;
61
62   /**
63    * Printable address.
64    */
65   char *result;
66
67   /**
68    * Print context this address record belongs to.
69    */
70   struct PrintContext *pc;
71 };
72
73
74 /**
75  * Structure we use to collect printable address information.
76  */
77 struct PrintContext
78 {
79
80   /**
81    * Kept in DLL.
82    */
83   struct PrintContext *next;
84
85   /**
86    * Kept in DLL.
87    */
88   struct PrintContext *prev;
89
90   /**
91    * Identity of the peer.
92    */
93   struct GNUNET_PeerIdentity peer;
94
95   /**
96    * List of printable addresses.
97    */
98   struct AddressRecord *address_list;
99
100   /**
101    * Number of completed addresses in 'address_list'.
102    */
103   unsigned int num_addresses;
104
105   /**
106    * Number of addresses allocated in 'address_list'.
107    */
108   unsigned int address_list_size;
109
110   /**
111    * Current offset in 'address_list' (counted down).
112    */
113   unsigned int off;
114
115   /**
116    * Hello was friend only, GNUNET_YES or GNUNET_NO
117    */
118   int friend_only;
119
120 };
121
122
123 /**
124  * Option '-n'
125  */
126 static int no_resolve;
127
128 /**
129  * Option '-q'
130  */
131 static int be_quiet;
132
133 /**
134  * Option '-f'
135  */
136 static int include_friend_only;
137
138 /**
139  * Option '-s'
140  */
141 static int get_self;
142
143 /**
144  * Option
145  */
146 static int get_uri;
147
148 /**
149  * Option
150  */
151 static int default_operation;
152
153 /**
154  * Option '-i'
155  */
156 static int get_info;
157
158 /**
159  * Option
160  */
161 static char *put_uri;
162
163 /**
164  * Option -d
165  */
166 static char *dump_hello;
167
168 /**
169  * Handle to peerinfo service.
170  */
171 static struct GNUNET_PEERINFO_Handle *peerinfo;
172
173 /**
174  * Configuration handle.
175  */
176 static const struct GNUNET_CONFIGURATION_Handle *cfg;
177
178 /**
179  * Main state machine task (if active).
180  */
181 static GNUNET_SCHEDULER_TaskIdentifier tt;
182
183 /**
184  * Current iterator context (if active, otherwise NULL).
185  */
186 static struct GNUNET_PEERINFO_IteratorContext *pic;
187
188 /**
189  * My peer identity.
190  */
191 static struct GNUNET_PeerIdentity my_peer_identity;
192
193 /**
194  * Head of list of print contexts.
195  */
196 static struct PrintContext *pc_head;
197
198 /**
199  * Tail of list of print contexts.
200  */
201 static struct PrintContext *pc_tail;
202
203 /**
204  * Handle to current 'GNUNET_PEERINFO_add_peer' operation.
205  */
206 static struct GNUNET_PEERINFO_AddContext *ac;
207
208
209 /**
210  * Main state machine that goes over all options and
211  * runs the next requested function.
212  *
213  * @param cls unused
214  * @param tc unused
215  */
216 static void
217 state_machine (void *cls,
218                const struct GNUNET_SCHEDULER_TaskContext *tc);
219
220
221 /* ********************* 'get_info' ******************* */
222
223 /**
224  * Print the collected address information to the console and free 'pc'.
225  *
226  * @param pc printing context
227  */
228 static void
229 dump_pc (struct PrintContext *pc)
230 {
231   unsigned int i;
232
233   printf (_("%sPeer `%s'\n"),
234           (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
235           GNUNET_i2s_full (&pc->peer));
236   for (i = 0; i < pc->num_addresses; i++)
237   {
238     if (NULL != pc->address_list[i].result)
239     {
240       printf (_("\tExpires: %s \t %s\n"), GNUNET_STRINGS_absolute_time_to_string(pc->address_list[i].expiration), pc->address_list[i].result);
241       GNUNET_free (pc->address_list[i].result);
242     }
243   }
244   printf ("\n");
245   GNUNET_free_non_null (pc->address_list);
246   GNUNET_CONTAINER_DLL_remove (pc_head,
247                                pc_tail,
248                                pc);
249   GNUNET_free (pc);
250   if ( (NULL == pc_head) &&
251        (NULL == pic) )
252     tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
253 }
254
255
256 /* ************************* list all known addresses **************** */
257
258
259 /**
260  * Function to call with a human-readable format of an address
261  *
262  * @param cls closure
263  * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
264  */
265 static void
266 process_resolved_address (void *cls, const char *address, int res)
267 {
268   struct AddressRecord * ar = cls;
269   struct PrintContext *pc = ar->pc;
270
271   if (NULL != address)
272   {
273     if (NULL == ar->result)
274       ar->result = GNUNET_strdup (address);
275     return;
276   }
277
278   ar->atsc = NULL;
279   if (GNUNET_SYSERR == res)
280   {
281     FPRINTF (stderr,
282              _("Failure: Cannot convert address to string for peer `%s'\n"),
283              GNUNET_i2s (&ar->pc->peer));
284   }
285   else
286   {
287     pc->num_addresses++;
288   }
289   if (pc->num_addresses == pc->address_list_size)
290     dump_pc (pc);
291 }
292
293
294 /**
295  * Iterator callback to go over all addresses and count them.
296  *
297  * @param cls 'struct PrintContext' with 'off' to increment
298  * @param address the address
299  * @param expiration expiration time
300  * @return GNUNET_OK to keep the address and continue
301  */
302 static int
303 count_address (void *cls, const struct GNUNET_HELLO_Address *address,
304                struct GNUNET_TIME_Absolute expiration)
305 {
306   struct PrintContext *pc = cls;
307
308   pc->off++;
309   return GNUNET_OK;
310 }
311
312
313 /**
314  * Iterator callback to go over all addresses.
315  *
316  * @param cls closure
317  * @param address the address
318  * @param expiration expiration time
319  * @return GNUNET_OK to keep the address and continue
320  */
321 static int
322 print_address (void *cls, const struct GNUNET_HELLO_Address *address,
323                struct GNUNET_TIME_Absolute expiration)
324 {
325   struct PrintContext *pc = cls;
326   struct AddressRecord *ar;
327   GNUNET_assert (0 < pc->off);
328   ar = &pc->address_list[--pc->off];
329   ar->pc = pc;
330   ar->expiration = expiration;
331   ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, address, no_resolve,
332                                                  GNUNET_TIME_relative_multiply
333                                                  (GNUNET_TIME_UNIT_SECONDS, 10),
334                                                  &process_resolved_address, ar);
335   return GNUNET_OK;
336 }
337
338
339 /**
340  * Print information about the peer.
341  * Currently prints the GNUNET_PeerIdentity and the transport address.
342  *
343  * @param cls the 'struct PrintContext'
344  * @param peer identity of the peer
345  * @param hello addresses of the peer
346  * @param err_msg error message
347  */
348 static void
349 print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
350                  const struct GNUNET_HELLO_Message *hello, const char *err_msg)
351 {
352   struct PrintContext *pc;
353   int friend_only;
354
355   if (NULL == peer)
356   {
357     pic = NULL; /* end of iteration */
358     if (NULL != err_msg)
359     {
360       FPRINTF (stderr,
361                _("Error in communication with PEERINFO service: %s\n"),
362                err_msg);
363     }
364     if (NULL == pc_head)
365       tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
366     return;
367   }
368   friend_only = GNUNET_NO;
369   if (NULL != hello)
370         friend_only = GNUNET_HELLO_is_friend_only (hello);
371   if ((GNUNET_YES == be_quiet) || (NULL == hello))
372   {
373     printf ("%s%s\n",
374             (GNUNET_YES == friend_only) ? "F2F: " : "",
375             GNUNET_i2s_full (peer));
376     return;
377   }
378   pc = GNUNET_new (struct PrintContext);
379   GNUNET_CONTAINER_DLL_insert (pc_head,
380                                pc_tail,
381                                pc);
382   pc->peer = *peer;
383   pc->friend_only = friend_only;
384   GNUNET_HELLO_iterate_addresses (hello,
385                                   GNUNET_NO,
386                                   &count_address,
387                                   pc);
388   if (0 == pc->off)
389   {
390     dump_pc (pc);
391     return;
392   }
393   pc->address_list_size = pc->off;
394   pc->address_list = GNUNET_malloc (sizeof (struct AddressRecord) * pc->off);
395   GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
396                                   &print_address, pc);
397 }
398
399 /* ************************* DUMP Hello  ************************** */
400
401 static int count_addr(void *cls,
402                                                                                  const struct GNUNET_HELLO_Address *address,
403                                                                                  struct GNUNET_TIME_Absolute expiration)
404 {
405         int *c = cls;
406   (*c) ++;
407   return GNUNET_OK;
408 }
409
410 /**
411  * Write Hello of my peer to a file.
412  *
413  * @param cls the 'struct GetUriContext'
414  * @param peer identity of the peer (unused)
415  * @param hello addresses of the peer
416  * @param err_msg error message
417  */
418 static void
419 dump_my_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
420               const struct GNUNET_HELLO_Message *hello,
421               const char *err_msg)
422 {
423         unsigned int size;
424         unsigned int c_addr;
425   if (peer == NULL)
426   {
427     pic = NULL;
428     if (err_msg != NULL)
429       FPRINTF (stderr,
430                _("Error in communication with PEERINFO service: %s\n"),
431                err_msg);
432     tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
433     return;
434   }
435
436   if (NULL == hello)
437   {
438                 FPRINTF (stderr,
439                          _("Failure: Did not receive %s\n"), "HELLO");
440     return;
441   }
442
443   size = GNUNET_HELLO_size (hello);
444   if (0 == size)
445   {
446                 FPRINTF (stderr,
447                          _("Failure: Received invalid %s\n"), "HELLO");
448       return;
449   }
450   if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello, hello, size,
451                             GNUNET_DISK_PERM_USER_READ |
452                             GNUNET_DISK_PERM_USER_WRITE |
453                             GNUNET_DISK_PERM_GROUP_READ |
454                             GNUNET_DISK_PERM_OTHER_READ))
455   {
456                 FPRINTF (stderr, _("Failed to write HELLO with %u bytes to file `%s'\n"),
457                          size, dump_hello);
458                 if (0 != UNLINK (dump_hello))
459                 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
460                               GNUNET_ERROR_TYPE_BULK, "unlink", dump_hello);
461
462   }
463   c_addr = 0;
464   GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, count_addr, &c_addr);
465
466   if (!be_quiet)
467   {
468                 FPRINTF (stderr,
469                          _("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"),
470                          (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) ? "friend-only": "public",
471                                         c_addr, size, dump_hello);
472   }
473
474   GNUNET_free (dump_hello);
475   dump_hello = NULL;
476
477 }
478
479
480 /* ************************* GET URI ************************** */
481
482
483 /**
484  * Print URI of the peer.
485  *
486  * @param cls the 'struct GetUriContext'
487  * @param peer identity of the peer (unused)
488  * @param hello addresses of the peer
489  * @param err_msg error message
490  */
491 static void
492 print_my_uri (void *cls, const struct GNUNET_PeerIdentity *peer,
493               const struct GNUNET_HELLO_Message *hello,
494               const char *err_msg)
495 {
496   if (peer == NULL)
497   {
498     pic = NULL;
499     if (err_msg != NULL)
500       FPRINTF (stderr,
501                _("Error in communication with PEERINFO service: %s\n"),
502                err_msg);
503     tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
504     return;
505   }
506
507   if (NULL == hello)
508     return;
509   char *uri = GNUNET_HELLO_compose_uri(hello, &GPI_plugins_find);
510   if (NULL != uri) {
511     printf ("%s\n", (const char *) uri);
512     GNUNET_free (uri);
513   }
514 }
515
516
517 /* ************************* import HELLO by URI ********************* */
518
519
520 /**
521  * Continuation called from 'GNUNET_PEERINFO_add_peer'
522  *
523  * @param cls closure, NULL
524  * @param emsg error message, NULL on success
525  */
526 static void
527 add_continuation (void *cls,
528                   const char *emsg)
529 {
530   ac = NULL;
531   if (NULL != emsg)
532     fprintf (stderr,
533              _("Failure adding HELLO: %s\n"),
534              emsg);
535   tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
536 }
537
538
539 /**
540  * Parse the PUT URI given at the command line and add it to our peerinfo
541  * database.
542  *
543  * @param put_uri URI string to parse
544  * @return GNUNET_OK on success, GNUNET_SYSERR if the URI was invalid, GNUNET_NO on other errors
545  */
546 static int
547 parse_hello_uri (const char *put_uri)
548 {
549   struct GNUNET_HELLO_Message *hello = NULL;
550
551   int ret = GNUNET_HELLO_parse_uri(put_uri, &my_peer_identity.public_key,
552                                    &hello, &GPI_plugins_find);
553
554   if (NULL != hello) {
555     /* WARNING: this adds the address from URI WITHOUT verification! */
556     if (GNUNET_OK == ret)
557       ac = GNUNET_PEERINFO_add_peer (peerinfo, hello, &add_continuation, NULL);
558     else
559       tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
560     GNUNET_free (hello);
561   }
562
563   /* wait 1s to give peerinfo operation a chance to succeed */
564   /* FIXME: current peerinfo API sucks to require this; not to mention
565      that we get no feedback to determine if the operation actually succeeded */
566   return ret;
567 }
568
569
570 /* ************************ Main state machine ********************* */
571
572
573 /**
574  * Main state machine that goes over all options and
575  * runs the next requested function.
576  *
577  * @param cls unused
578  * @param tc scheduler context
579  */
580 static void
581 shutdown_task (void *cls,
582                const struct GNUNET_SCHEDULER_TaskContext *tc)
583 {
584   struct PrintContext *pc;
585   struct AddressRecord *ar;
586   unsigned int i;
587
588   if (NULL != ac)
589   {
590     GNUNET_PEERINFO_add_peer_cancel (ac);
591     ac = NULL;
592   }
593   if (GNUNET_SCHEDULER_NO_TASK != tt)
594   {
595     GNUNET_SCHEDULER_cancel (tt);
596     tt = GNUNET_SCHEDULER_NO_TASK;
597   }
598   if (NULL != pic)
599   {
600     GNUNET_PEERINFO_iterate_cancel (pic);
601     pic = NULL;
602   }
603   while (NULL != (pc = pc_head))
604   {
605     GNUNET_CONTAINER_DLL_remove (pc_head,
606                                  pc_tail,
607                                  pc);
608     for (i=0;i<pc->address_list_size;i++)
609     {
610       ar = &pc->address_list[i];
611       GNUNET_free_non_null (ar->result);
612       if (NULL != ar->atsc)
613       {
614         GNUNET_TRANSPORT_address_to_string_cancel (ar->atsc);
615         ar->atsc = NULL;
616       }
617     }
618     GNUNET_free_non_null (pc->address_list);
619     GNUNET_free (pc);
620   }
621   GPI_plugins_unload ();
622   if (NULL != peerinfo)
623   {
624     GNUNET_PEERINFO_disconnect (peerinfo);
625     peerinfo = NULL;
626   }
627 }
628
629 /**
630  * Function called with the result of the check if the 'peerinfo'
631  * service is running.
632  *
633  * @param cls closure with our configuration
634  * @param result #GNUNET_YES if transport is running
635  */
636 static void
637 testservice_task (void *cls, int result)
638 {
639   struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
640   char *fn;
641
642   if (GNUNET_YES != result)
643   {
644     FPRINTF (stderr, _("Service `%s' is not running, please start GNUnet\n"), "peerinfo");
645     return;
646   }
647
648   if (NULL == (peerinfo = GNUNET_PEERINFO_connect (cfg)))
649   {
650     FPRINTF (stderr, "%s",  _("Could not access PEERINFO service.  Exiting.\n"));
651     return;
652   }
653   if ( (GNUNET_YES == get_self) || (GNUNET_YES == get_uri) || (NULL != dump_hello) )
654   {
655     /* load private key */
656     if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER",
657                                                               "PRIVATE_KEY",
658                                                                &fn))
659     {
660       GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "PEER", "PRIVATE_KEY");
661       return;
662     }
663     if (NULL == (priv = GNUNET_CRYPTO_eddsa_key_create_from_file (fn)))
664     {
665       FPRINTF (stderr, _("Loading hostkey from `%s' failed.\n"), fn);
666       GNUNET_free (fn);
667       return;
668     }
669     GNUNET_free (fn);
670     GNUNET_CRYPTO_eddsa_key_get_public (priv,
671                                         &my_peer_identity.public_key);
672     GNUNET_free (priv);
673   }
674
675   tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
676   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
677                                 &shutdown_task,
678                                 NULL);
679 }
680
681
682 /**
683  * Main function that will be run by the scheduler.
684  *
685  * @param cls closure
686  * @param args remaining command-line arguments
687  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
688  * @param c configuration
689  */
690 static void
691 run (void *cls, char *const *args, const char *cfgfile,
692      const struct GNUNET_CONFIGURATION_Handle *c)
693 {
694   cfg = c;
695   if ( (NULL != args[0]) &&
696        (NULL == put_uri) &&
697        (args[0] == strcasestr (args[0], "gnunet://hello/")) )
698   {
699     put_uri = GNUNET_strdup (args[0]);
700     args++;
701   }
702   if (NULL != args[0])
703   {
704     FPRINTF (stderr,
705              _("Invalid command line argument `%s'\n"),
706              args[0]);
707     return;
708   }
709
710   GNUNET_CLIENT_service_test ("peerinfo", cfg, GNUNET_TIME_UNIT_SECONDS,
711       &testservice_task, (void *) cfg);
712 }
713
714
715 /**
716  * Main state machine that goes over all options and
717  * runs the next requested function.
718  *
719  * @param cls unused
720  * @param tc scheduler context
721  */
722 static void
723 state_machine (void *cls,
724                const struct GNUNET_SCHEDULER_TaskContext *tc)
725 {
726   tt = GNUNET_SCHEDULER_NO_TASK;
727
728   if (NULL != put_uri)
729   {
730     GPI_plugins_load (cfg);
731     if (GNUNET_SYSERR == parse_hello_uri (put_uri))
732     {
733       fprintf (stderr,
734                _("Invalid URI `%s'\n"),
735                put_uri);
736       GNUNET_SCHEDULER_shutdown ();
737     }
738     GNUNET_free (put_uri);
739     put_uri = NULL;
740   }
741   else if (GNUNET_YES == get_info)
742   {
743     get_info = GNUNET_NO;
744     GPI_plugins_load (cfg);
745     pic = GNUNET_PEERINFO_iterate (peerinfo, include_friend_only, NULL,
746                                    TIMEOUT,
747                                    &print_peer_info, NULL);
748   }
749   else if (GNUNET_YES == get_self)
750   {
751     get_self = GNUNET_NO;
752     if (be_quiet)
753       printf ("%s\n",
754               GNUNET_i2s_full (&my_peer_identity));
755     else
756       printf (_("I am peer `%s'.\n"),
757               GNUNET_i2s_full (&my_peer_identity));
758     tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
759   }
760   else if (GNUNET_YES == get_uri)
761   {
762     GPI_plugins_load (cfg);
763     pic = GNUNET_PEERINFO_iterate (peerinfo, include_friend_only, &my_peer_identity,
764                                    TIMEOUT, &print_my_uri, NULL);
765     get_uri = GNUNET_NO;
766   }
767   else if (NULL != dump_hello)
768   {
769     pic = GNUNET_PEERINFO_iterate (peerinfo, include_friend_only, &my_peer_identity,
770                                    TIMEOUT, &dump_my_hello, NULL);
771   }
772   else if (GNUNET_YES == default_operation)
773   {
774         /* default operation list all */
775         default_operation = GNUNET_NO;
776         get_info = GNUNET_YES;
777         tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
778   }
779   else
780   {
781         GNUNET_SCHEDULER_shutdown ();
782   }
783         default_operation = GNUNET_NO;
784 }
785
786
787 /**
788  * The main function to obtain peer information.
789  *
790  * @param argc number of arguments from the command line
791  * @param argv command line arguments
792  * @return 0 ok, 1 on error
793  */
794 int
795 main (int argc, char *const *argv)
796 {
797         default_operation = GNUNET_YES;
798   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
799     {'n', "numeric", NULL,
800      gettext_noop ("don't resolve host names"),
801      0, &GNUNET_GETOPT_set_one, &no_resolve},
802     {'q', "quiet", NULL,
803      gettext_noop ("output only the identity strings"),
804      0, &GNUNET_GETOPT_set_one, &be_quiet},
805     {'f', "friends", NULL,
806      gettext_noop ("include friend-only information"),
807      0, &GNUNET_GETOPT_set_one, &include_friend_only},
808     {'s', "self", NULL,
809      gettext_noop ("output our own identity only"),
810      0, &GNUNET_GETOPT_set_one, &get_self},
811     {'i', "info", NULL,
812      gettext_noop ("list all known peers"),
813      0, &GNUNET_GETOPT_set_one, &get_info},
814     {'d', "dump-hello", NULL,
815      gettext_noop ("dump hello to file"),
816      1, &GNUNET_GETOPT_set_string, &dump_hello},
817     {'g', "get-hello", NULL,
818      gettext_noop ("also output HELLO uri(s)"),
819      0, &GNUNET_GETOPT_set_one, &get_uri},
820     {'p', "put-hello", "HELLO",
821      gettext_noop ("add given HELLO uri to the database"),
822      1, &GNUNET_GETOPT_set_string, &put_uri},
823     GNUNET_GETOPT_OPTION_END
824   };
825   int ret;
826
827   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
828     return 2;
829
830   ret = (GNUNET_OK ==
831          GNUNET_PROGRAM_run (argc, argv, "gnunet-peerinfo",
832                              gettext_noop ("Print information about peers."),
833                              options, &run, NULL)) ? 0 : 1;
834   GNUNET_free ((void*) argv);
835   return ret;
836 }
837
838 /* end of gnunet-peerinfo.c */