aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/peerinfo-tool/Makefile.am2
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c406
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo_plugins.c178
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo_plugins.h58
4 files changed, 506 insertions, 138 deletions
diff --git a/src/peerinfo-tool/Makefile.am b/src/peerinfo-tool/Makefile.am
index 7270bfb51..77604d55f 100644
--- a/src/peerinfo-tool/Makefile.am
+++ b/src/peerinfo-tool/Makefile.am
@@ -14,7 +14,7 @@ bin_PROGRAMS = \
14 14
15gnunet_peerinfo_SOURCES = \ 15gnunet_peerinfo_SOURCES = \
16 gnunet-peerinfo.c \ 16 gnunet-peerinfo.c \
17 ../transport/gnunet-service-transport_plugins.c 17 gnunet-peerinfo_plugins.c
18 18
19gnunet_peerinfo_LDADD = \ 19gnunet_peerinfo_LDADD = \
20 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ 20 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index 4ffb61b35..6902e605c 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -31,60 +31,153 @@
31#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
32#include "gnunet_program_lib.h" 32#include "gnunet_program_lib.h"
33#include "gnunet_transport_plugin.h" 33#include "gnunet_transport_plugin.h"
34#include "../transport/gnunet-service-transport_plugins.h" 34#include "gnunet-peerinfo_plugins.h"
35 35
36
37/**
38 * Structure we use to collect printable address information.
39 */
40struct PrintContext
41{
42 /**
43 * Identity of the peer.
44 */
45 struct GNUNET_PeerIdentity peer;
46
47 /**
48 * List of printable addresses.
49 */
50 char **address_list;
51
52 /**
53 * Number of addresses in 'address_list'.
54 */
55 unsigned int num_addresses;
56
57 /**
58 * Current offset in 'address_list'
59 */
60 uint32_t off;
61
62 /**
63 * URI (FIXME: overloaded struct!)
64 */
65 char *uri;
66
67 /**
68 * Length of 'uri' (FIXME: not nice)
69 */
70 size_t uri_len;
71};
72
73
74/**
75 * FIXME.
76 */
77struct GNUNET_PEERINFO_HelloAddressParsingContext
78{
79 /**
80 * FIXME.
81 */
82 char *tmp;
83
84 /**
85 * FIXME.
86 */
87 char *pos;
88
89 /**
90 * FIXME.
91 */
92 size_t tmp_len;
93};
94
95
96/**
97 * Option '-n'
98 */
36static int no_resolve; 99static int no_resolve;
37 100
101/**
102 * Option '-q'
103 */
38static int be_quiet; 104static int be_quiet;
39 105
106/**
107 * Option '-s'
108 */
40static int get_self; 109static int get_self;
41 110
111/**
112 * Option
113 */
42static int get_uri; 114static int get_uri;
43 115
116/**
117 * Option '-i'
118 */
119static int get_info;
120
121/**
122 * Option
123 */
44static char *put_uri; 124static char *put_uri;
45 125
126/**
127 * Handle to peerinfo service.
128 */
46static struct GNUNET_PEERINFO_Handle *peerinfo; 129static struct GNUNET_PEERINFO_Handle *peerinfo;
47 130
48/** 131/**
49 * Configuration handle. 132 * Configuration handle.
50 */ 133 */
51const struct GNUNET_CONFIGURATION_Handle *GST_cfg; 134static const struct GNUNET_CONFIGURATION_Handle *cfg;
52 135
53/** 136/**
54 * Statistics handle. 137 * Main state machine task (if active).
55 */ 138 */
56struct GNUNET_STATISTICS_Handle *GST_stats; 139static GNUNET_SCHEDULER_TaskIdentifier tt;
57 140
58/** 141/**
59 * Configuration handle. 142 * Current iterator context (if active, otherwise NULL).
60 */ 143 */
61struct GNUNET_PeerIdentity GST_my_identity; 144static struct GNUNET_PEERINFO_IteratorContext *pic;
62 145
63struct GNUNET_MessageHeader *our_hello = NULL; 146/**
147 * Current address-to-string context (if active, otherwise NULL).
148 */
149static struct GNUNET_TRANSPORT_AddressToStringContext *atsc;
64 150
65static const struct GNUNET_CONFIGURATION_Handle *cfg; 151/**
152 * My peer identity.
153 */
154static struct GNUNET_PeerIdentity my_peer_identity;
155
156/**
157 * My public key.
158 */
159static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
66 160
67struct PrintContext
68{
69 struct GNUNET_PeerIdentity peer;
70 char **address_list;
71 unsigned int num_addresses;
72 uint32_t off;
73 char *uri;
74 size_t uri_len;
75};
76 161
77/** 162/**
78 * Obtain this peers HELLO message. 163 * Main state machine that goes over all options and
164 * runs the next requested function.
79 * 165 *
80 * @return our HELLO message 166 * @param cls unused
167 * @param tc unused
81 */ 168 */
82const struct GNUNET_MessageHeader * 169static void
83GST_hello_get () 170state_machine (void *cls,
84{ 171 const struct GNUNET_SCHEDULER_TaskContext *tc);
85 return (struct GNUNET_MessageHeader *) our_hello; 172
86}
87 173
174/* ********************* 'get_info' ******************* */
175
176/**
177 * Print the collected address information to the console and free 'pc'.
178 *
179 * @param pc printing context
180 */
88static void 181static void
89dump_pc (struct PrintContext *pc) 182dump_pc (struct PrintContext *pc)
90{ 183{
@@ -115,6 +208,7 @@ process_resolved_address (void *cls, const char *address)
115{ 208{
116 struct PrintContext *pc = cls; 209 struct PrintContext *pc = cls;
117 210
211 atsc = NULL;
118 if (address == NULL) 212 if (address == NULL)
119 { 213 {
120 pc->off--; 214 pc->off--;
@@ -160,10 +254,11 @@ print_address (void *cls, const struct GNUNET_HELLO_Address *address,
160{ 254{
161 struct PrintContext *pc = cls; 255 struct PrintContext *pc = cls;
162 256
163 GNUNET_TRANSPORT_address_to_string (cfg, address, no_resolve, 257 // FIXME: this is called many times in parallel!
164 GNUNET_TIME_relative_multiply 258 atsc = GNUNET_TRANSPORT_address_to_string (cfg, address, no_resolve,
165 (GNUNET_TIME_UNIT_SECONDS, 10), 259 GNUNET_TIME_relative_multiply
166 &process_resolved_address, pc); 260 (GNUNET_TIME_UNIT_SECONDS, 10),
261 &process_resolved_address, pc);
167 return GNUNET_OK; 262 return GNUNET_OK;
168} 263}
169 264
@@ -184,9 +279,9 @@ print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
184 { 279 {
185 if (err_msg != NULL) 280 if (err_msg != NULL)
186 FPRINTF (stderr, "%s", _("Error in communication with PEERINFO service\n")); 281 FPRINTF (stderr, "%s", _("Error in communication with PEERINFO service\n"));
187 GNUNET_PEERINFO_disconnect (peerinfo); 282 // FIXME: this doesn't mean we're fully done with the printing!
188 GST_plugins_unload (); 283 // (as the a2s calls happen asynchronously!)
189 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); 284 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
190 return; 285 return;
191 } 286 }
192 if ((be_quiet) || (NULL == hello)) 287 if ((be_quiet) || (NULL == hello))
@@ -206,6 +301,17 @@ print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
206 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc); 301 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc);
207} 302}
208 303
304
305
306
307
308
309
310
311
312
313
314
209static int 315static int
210compose_uri (void *cls, const struct GNUNET_HELLO_Address *address, 316compose_uri (void *cls, const struct GNUNET_HELLO_Address *address,
211 struct GNUNET_TIME_Absolute expiration) 317 struct GNUNET_TIME_Absolute expiration)
@@ -214,7 +320,7 @@ compose_uri (void *cls, const struct GNUNET_HELLO_Address *address,
214 struct GNUNET_TRANSPORT_PluginFunctions *papi; 320 struct GNUNET_TRANSPORT_PluginFunctions *papi;
215 static const char *addr; 321 static const char *addr;
216 322
217 papi = GST_plugins_find (address->transport_name); 323 papi = GPI_plugins_find (address->transport_name);
218 if (papi == NULL) 324 if (papi == NULL)
219 { 325 {
220 /* Not an error - we might just not have the right plugin. */ 326 /* Not an error - we might just not have the right plugin. */
@@ -243,6 +349,7 @@ compose_uri (void *cls, const struct GNUNET_HELLO_Address *address,
243 return GNUNET_OK; 349 return GNUNET_OK;
244} 350}
245 351
352
246/** 353/**
247 * Print information about the peer. 354 * Print information about the peer.
248 */ 355 */
@@ -257,9 +364,7 @@ print_my_uri (void *cls, const struct GNUNET_PeerIdentity *peer,
257 { 364 {
258 if (err_msg != NULL) 365 if (err_msg != NULL)
259 FPRINTF (stderr, "%s", _("Error in communication with PEERINFO service\n")); 366 FPRINTF (stderr, "%s", _("Error in communication with PEERINFO service\n"));
260 GNUNET_PEERINFO_disconnect (peerinfo); 367 GNUNET_free (pc->uri);
261 GST_plugins_unload ();
262 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
263 return; 368 return;
264 } 369 }
265 if ((be_quiet) || (NULL == hello)) 370 if ((be_quiet) || (NULL == hello))
@@ -278,12 +383,7 @@ print_my_uri (void *cls, const struct GNUNET_PeerIdentity *peer,
278 printf ("%s\n", pc->uri); 383 printf ("%s\n", pc->uri);
279} 384}
280 385
281struct GNUNET_PEERINFO_HelloAddressParsingContext 386
282{
283 char *tmp;
284 char *pos;
285 size_t tmp_len;
286};
287 387
288static size_t 388static size_t
289add_addr_to_hello (void *cls, size_t max, void *buffer) 389add_addr_to_hello (void *cls, size_t max, void *buffer)
@@ -397,7 +497,7 @@ add_addr_to_hello (void *cls, size_t max, void *buffer)
397 if (exp2 == NULL) 497 if (exp2 == NULL)
398 exp2 = &ctx->tmp[ctx->tmp_len]; 498 exp2 = &ctx->tmp[ctx->tmp_len];
399 499
400 papi = GST_plugins_find (ctx->pos); 500 papi = GPI_plugins_find (ctx->pos);
401 if (papi == NULL) 501 if (papi == NULL)
402 { 502 {
403 /* Not an error - we might just not have the right plugin. 503 /* Not an error - we might just not have the right plugin.
@@ -409,7 +509,16 @@ add_addr_to_hello (void *cls, size_t max, void *buffer)
409 return 0; 509 return 0;
410 return add_addr_to_hello (cls, max, buffer); 510 return add_addr_to_hello (cls, max, buffer);
411 } 511 }
412 512 if (NULL == papi->string_to_address)
513 {
514 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
515 _("Plugin `%s' does not support URIs yet\n"),
516 ctx->pos);
517 ctx->pos = exp2 + 1;
518 if (ctx->pos - ctx->tmp >= ctx->tmp_len)
519 return 0;
520 return add_addr_to_hello (cls, max, buffer);
521 }
413 if (GNUNET_OK == papi->string_to_address (papi->cls, &exp1[1], exp2 - &exp1[1], &addr, &addr_len)) 522 if (GNUNET_OK == papi->string_to_address (papi->cls, &exp1[1], exp2 - &exp1[1], &addr, &addr_len))
414 { 523 {
415 struct GNUNET_HELLO_Address address; 524 struct GNUNET_HELLO_Address address;
@@ -427,7 +536,8 @@ add_addr_to_hello (void *cls, size_t max, void *buffer)
427 return 0; 536 return 0;
428} 537}
429 538
430void 539
540static void
431parse_hello (const struct GNUNET_CONFIGURATION_Handle *c, 541parse_hello (const struct GNUNET_CONFIGURATION_Handle *c,
432 const char *put_uri) 542 const char *put_uri)
433{ 543{
@@ -435,7 +545,6 @@ parse_hello (const struct GNUNET_CONFIGURATION_Handle *c,
435 char *scheme_part = NULL; 545 char *scheme_part = NULL;
436 char *path_part = NULL; 546 char *path_part = NULL;
437 char *exc; 547 char *exc;
438 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
439 int std_result; 548 int std_result;
440 struct GNUNET_HELLO_Message *hello; 549 struct GNUNET_HELLO_Message *hello;
441 struct GNUNET_PEERINFO_HelloAddressParsingContext ctx; 550 struct GNUNET_PEERINFO_HelloAddressParsingContext ctx;
@@ -462,53 +571,54 @@ parse_hello (const struct GNUNET_CONFIGURATION_Handle *c,
462 ctx.pos = exc; 571 ctx.pos = exc;
463 572
464 std_result = GNUNET_STRINGS_string_to_data (ctx.tmp, exc - ctx.tmp, 573 std_result = GNUNET_STRINGS_string_to_data (ctx.tmp, exc - ctx.tmp,
465 (unsigned char *) &pub, sizeof (pub)); 574 (unsigned char *) &my_public_key, sizeof (my_public_key));
466 if (std_result != GNUNET_OK) 575 if (std_result != GNUNET_OK)
467 { 576 {
468 GNUNET_free (ctx.tmp); 577 GNUNET_free (ctx.tmp);
469 return; 578 return;
470 } 579 }
471 580
472 hello = GNUNET_HELLO_create (&pub, add_addr_to_hello, &ctx); 581 hello = GNUNET_HELLO_create (&my_public_key, add_addr_to_hello, &ctx);
473 GNUNET_free (ctx.tmp); 582 GNUNET_free (ctx.tmp);
474 583
475 /* WARNING: this adds the address from URI WITHOUT verification! */ 584 /* WARNING: this adds the address from URI WITHOUT verification! */
476 GNUNET_PEERINFO_add_peer (peerinfo, hello); 585 GNUNET_PEERINFO_add_peer (peerinfo, hello);
477 GNUNET_free (hello); 586 GNUNET_free (hello);
587 /* wait 1s to give peerinfo operation a chance to succeed */
588 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
589 &state_machine, NULL);
478} 590}
479 591
480static struct GNUNET_TIME_Relative
481receive_stub (void *cls, const struct GNUNET_PeerIdentity *peer,
482 const struct GNUNET_MessageHeader *message,
483 const struct GNUNET_ATS_Information *ats, uint32_t ats_count,
484 struct Session *session, const char *sender_address,
485 uint16_t sender_address_len)
486{
487 struct GNUNET_TIME_Relative t;
488 t.rel_value = 0;
489 return t;
490}
491
492static void
493address_notification_stub (void *cls, int add_remove,
494 const void *addr, size_t addrlen)
495{
496}
497 592
593/**
594 * Main state machine that goes over all options and
595 * runs the next requested function.
596 *
597 * @param cls unused
598 * @param tc scheduler context
599 */
498static void 600static void
499session_end_stub (void *cls, const struct GNUNET_PeerIdentity *peer, 601shutdown_task (void *cls,
500 struct Session * session) 602 const struct GNUNET_SCHEDULER_TaskContext *tc)
501{
502}
503
504static const struct GNUNET_ATS_Information
505address_to_type_stub (void *cls, const struct sockaddr *addr,
506 size_t addrlen)
507{ 603{
508 struct GNUNET_ATS_Information t; 604 if (GNUNET_SCHEDULER_NO_TASK != tt)
509 t.type = 0; 605 {
510 t.value = 0; 606 GNUNET_SCHEDULER_cancel (tt);
511 return t; 607 tt = GNUNET_SCHEDULER_NO_TASK;
608 }
609 if (NULL != pic)
610 {
611 GNUNET_PEERINFO_iterate_cancel (pic);
612 pic = NULL;
613 }
614 if (NULL != atsc)
615 {
616 GNUNET_TRANSPORT_address_to_string_cancel (atsc);
617 atsc = NULL;
618 }
619 GPI_plugins_unload ();
620 GNUNET_PEERINFO_disconnect (peerinfo);
621 peerinfo = NULL;
512} 622}
513 623
514 624
@@ -525,9 +635,6 @@ run (void *cls, char *const *args, const char *cfgfile,
525 const struct GNUNET_CONFIGURATION_Handle *c) 635 const struct GNUNET_CONFIGURATION_Handle *c)
526{ 636{
527 struct GNUNET_CRYPTO_RsaPrivateKey *priv; 637 struct GNUNET_CRYPTO_RsaPrivateKey *priv;
528 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
529 struct GNUNET_PeerIdentity pid;
530 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
531 char *fn; 638 char *fn;
532 639
533 cfg = c; 640 cfg = c;
@@ -536,86 +643,108 @@ run (void *cls, char *const *args, const char *cfgfile,
536 FPRINTF (stderr, _("Invalid command line argument `%s'\n"), args[0]); 643 FPRINTF (stderr, _("Invalid command line argument `%s'\n"), args[0]);
537 return; 644 return;
538 } 645 }
539 if (put_uri != NULL && get_uri == GNUNET_YES) 646 peerinfo = GNUNET_PEERINFO_connect (cfg);
647 if (peerinfo == NULL)
540 { 648 {
541 FPRINTF (stderr, "%s", _("--put-uri and --get-uri are mutually exclusive\n")); 649 FPRINTF (stderr, "%s", _("Could not access PEERINFO service. Exiting.\n"));
542 return; 650 return;
543 } 651 }
544 if (put_uri != NULL || get_uri == GNUNET_YES || get_self != GNUNET_YES) 652 if ( (GNUNET_YES == get_self) || (GNUNET_YES == get_uri) )
545 { 653 {
546 peerinfo = GNUNET_PEERINFO_connect (cfg); 654 /* load private key */
547 if (peerinfo == NULL) 655 if (GNUNET_OK !=
656 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
657 &fn))
548 { 658 {
549 FPRINTF (stderr, "%s", _("Could not access PEERINFO service. Exiting.\n")); 659 FPRINTF (stderr, _("Could not find option `%s:%s' in configuration.\n"),
660 "GNUNETD", "HOSTKEYFILE");
550 return; 661 return;
551 } 662 }
552 GST_cfg = c; 663
553 GST_stats = GNUNET_STATISTICS_create ("transport", c); 664 if (NULL == (priv = GNUNET_CRYPTO_rsa_key_create_from_file (fn)))
554 /* FIXME: shouldn't we free GST_stats somewhere? */ 665 {
555 GST_plugins_load (receive_stub, address_notification_stub, 666 FPRINTF (stderr, _("Loading hostkey from `%s' failed.\n"), fn);
556 session_end_stub, address_to_type_stub); 667 GNUNET_free (fn);
668 return;
669 }
670 GNUNET_free (fn);
671 GNUNET_CRYPTO_rsa_key_get_public (priv, &my_public_key);
672 GNUNET_CRYPTO_rsa_key_free (priv);
673 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_peer_identity.hashPubKey);
557 } 674 }
558 if (put_uri != NULL) 675
676 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
677 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
678 &shutdown_task,
679 NULL);
680}
681
682
683/**
684 * Main state machine that goes over all options and
685 * runs the next requested function.
686 *
687 * @param cls unused
688 * @param tc scheduler context
689 */
690static void
691state_machine (void *cls,
692 const struct GNUNET_SCHEDULER_TaskContext *tc)
693{
694 tt = GNUNET_SCHEDULER_NO_TASK;
695
696 if (NULL != put_uri)
559 { 697 {
560 parse_hello (c, put_uri); 698 GPI_plugins_load (cfg);
561 GST_plugins_unload (); 699 parse_hello (cfg, put_uri);
562 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); 700 put_uri = NULL;
563 return; 701 return;
564 } 702 }
565 if (get_self != GNUNET_YES) 703 if (GNUNET_YES == get_info)
566 { 704 {
705 get_info = GNUNET_NO;
706 GPI_plugins_load (cfg);
567 GNUNET_PEERINFO_iterate (peerinfo, NULL, 707 GNUNET_PEERINFO_iterate (peerinfo, NULL,
568 GNUNET_TIME_relative_multiply 708 GNUNET_TIME_relative_multiply
569 (GNUNET_TIME_UNIT_SECONDS, 5), &print_peer_info, 709 (GNUNET_TIME_UNIT_SECONDS, 5), &print_peer_info,
570 NULL); 710 NULL);
711 return;
571 } 712 }
572 else 713 if (GNUNET_YES == get_self)
573 { 714 {
574 if (GNUNET_OK != 715 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
575 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY", 716
576 &fn)) 717 get_self = GNUNET_NO;
577 { 718 GNUNET_CRYPTO_hash_to_enc (&my_peer_identity.hashPubKey, &enc);
578 FPRINTF (stderr, _("Could not find option `%s:%s' in configuration.\n"),
579 "GNUNETD", "HOSTKEYFILE");
580 return;
581 }
582 priv = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
583 if (priv == NULL)
584 {
585 FPRINTF (stderr, _("Loading hostkey from `%s' failed.\n"), fn);
586 GNUNET_free (fn);
587 return;
588 }
589 GNUNET_free (fn);
590 GNUNET_CRYPTO_rsa_key_get_public (priv, &pub);
591 GNUNET_CRYPTO_rsa_key_free (priv);
592 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
593 GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc);
594 if (be_quiet) 719 if (be_quiet)
595 printf ("%s\n", (char *) &enc); 720 printf ("%s\n", (char *) &enc);
596 else 721 else
597 printf (_("I am peer `%s'.\n"), (const char *) &enc); 722 printf (_("I am peer `%s'.\n"), (const char *) &enc);
598 if (get_uri == GNUNET_YES)
599 {
600 struct PrintContext *pc;
601 char *pkey;
602 ssize_t l, pl;
603
604 pc = GNUNET_malloc (sizeof (struct PrintContext));
605 pkey = GNUNET_CRYPTO_rsa_public_key_to_string (&pub);
606 pl = strlen ("gnunet://hello/");
607 l = strlen (pkey) + pl;
608 pc->uri = GNUNET_malloc (l + 1);
609 strcpy (pc->uri, "gnunet://hello/");
610 strcpy (&pc->uri[pl], pkey);
611 pc->uri_len = l;
612 GNUNET_PEERINFO_iterate (peerinfo, &pid,
613 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
614 print_my_uri, pc);
615 GNUNET_free (pc->uri);
616 GNUNET_free (pc);
617 }
618 } 723 }
724 if (GNUNET_YES == get_uri)
725 {
726 struct PrintContext *pc;
727 char *pkey;
728 ssize_t l;
729 ssize_t pl;
730
731 // FIXME...
732 pc = GNUNET_malloc (sizeof (struct PrintContext));
733 pkey = GNUNET_CRYPTO_rsa_public_key_to_string (&my_public_key);
734 pl = strlen ("gnunet://hello/");
735 l = strlen (pkey) + pl;
736 pc->uri = GNUNET_malloc (l + 1);
737 strcpy (pc->uri, "gnunet://hello/");
738 strcpy (&pc->uri[pl], pkey);
739 pc->uri_len = l;
740
741 GPI_plugins_load (cfg);
742 pic = GNUNET_PEERINFO_iterate (peerinfo, &my_peer_identity,
743 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
744 &print_my_uri, pc);
745 return;
746 }
747 GNUNET_SCHEDULER_shutdown ();
619} 748}
620 749
621 750
@@ -639,6 +768,9 @@ main (int argc, char *const *argv)
639 {'s', "self", NULL, 768 {'s', "self", NULL,
640 gettext_noop ("output our own identity only"), 769 gettext_noop ("output our own identity only"),
641 0, &GNUNET_GETOPT_set_one, &get_self}, 770 0, &GNUNET_GETOPT_set_one, &get_self},
771 {'i', "info", NULL,
772 gettext_noop ("list all known peers"),
773 0, &GNUNET_GETOPT_set_one, &get_info},
642 {'g', "get-hello", NULL, 774 {'g', "get-hello", NULL,
643 gettext_noop ("also output HELLO uri(s)"), 775 gettext_noop ("also output HELLO uri(s)"),
644 0, &GNUNET_GETOPT_set_one, &get_uri}, 776 0, &GNUNET_GETOPT_set_one, &get_uri},
diff --git a/src/peerinfo-tool/gnunet-peerinfo_plugins.c b/src/peerinfo-tool/gnunet-peerinfo_plugins.c
new file mode 100644
index 000000000..ba7c1d392
--- /dev/null
+++ b/src/peerinfo-tool/gnunet-peerinfo_plugins.c
@@ -0,0 +1,178 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010,2011 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_plugins.c
23 * @brief plugin management
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet-peerinfo_plugins.h"
28#include "gnunet_transport_plugin.h"
29#include "gnunet_hello_lib.h"
30
31/**
32 * Entry in doubly-linked list of all of our plugins.
33 */
34struct TransportPlugin
35{
36 /**
37 * This is a doubly-linked list.
38 */
39 struct TransportPlugin *next;
40
41 /**
42 * This is a doubly-linked list.
43 */
44 struct TransportPlugin *prev;
45
46 /**
47 * API of the transport as returned by the plugin's
48 * initialization function.
49 */
50 struct GNUNET_TRANSPORT_PluginFunctions *api;
51
52 /**
53 * Short name for the plugin (i.e. "tcp").
54 */
55 char *short_name;
56
57 /**
58 * Name of the library (i.e. "gnunet_plugin_transport_tcp").
59 */
60 char *lib_name;
61
62 /**
63 * Environment this transport service is using
64 * for this plugin.
65 */
66 struct GNUNET_TRANSPORT_PluginEnvironment env;
67
68};
69
70/**
71 * Head of DLL of all loaded plugins.
72 */
73static struct TransportPlugin *plugins_head;
74
75/**
76 * Head of DLL of all loaded plugins.
77 */
78static struct TransportPlugin *plugins_tail;
79
80
81
82/**
83 * Load and initialize all plugins. The respective functions will be
84 * invoked by the plugins when the respective events happen. The
85 * closure will be set to a 'const char*' containing the name of the
86 * plugin that caused the call.
87 *
88 * @param cfg configuration to use
89 */
90void
91GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
92{
93 struct TransportPlugin *plug;
94 struct TransportPlugin *next;
95 char *libname;
96 char *plugs;
97 char *pos;
98
99 if (NULL != plugins_head)
100 return; /* already loaded */
101 if (GNUNET_OK !=
102 GNUNET_CONFIGURATION_get_value_string (cfg, "TRANSPORT", "PLUGINS",
103 &plugs))
104 return;
105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"),
106 plugs);
107 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
108 {
109 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"),
110 pos);
111 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos);
112 plug = GNUNET_malloc (sizeof (struct TransportPlugin));
113 plug->short_name = GNUNET_strdup (pos);
114 plug->lib_name = libname;
115 plug->env.cfg = cfg;
116 plug->env.cls = plug->short_name;
117 GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug);
118 }
119 GNUNET_free (plugs);
120 next = plugins_head;
121 while (next != NULL)
122 {
123 plug = next;
124 next = plug->next;
125 plug->api = GNUNET_PLUGIN_load (plug->lib_name, &plug->env);
126 if (plug->api == NULL)
127 {
128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
129 _("Failed to load transport plugin for `%s'\n"),
130 plug->lib_name);
131 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
132 GNUNET_free (plug->short_name);
133 GNUNET_free (plug->lib_name);
134 GNUNET_free (plug);
135 }
136 }
137}
138
139
140/**
141 * Unload all plugins
142 */
143void
144GPI_plugins_unload ()
145{
146 struct TransportPlugin *plug;
147
148 while (NULL != (plug = plugins_head))
149 {
150 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
151 GNUNET_free (plug->lib_name);
152 GNUNET_free (plug->short_name);
153 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
154 GNUNET_free (plug);
155 }
156}
157
158
159/**
160 * Obtain the plugin API based on a plugin name.
161 *
162 * @param name name of the plugin
163 * @return the plugin's API, NULL if the plugin is not loaded
164 */
165struct GNUNET_TRANSPORT_PluginFunctions *
166GPI_plugins_find (const char *name)
167{
168 struct TransportPlugin *head = plugins_head;
169
170 while ((head != NULL) && (0 != strcmp (name, head->short_name)))
171 head = head->next;
172 if (NULL == head)
173 return NULL;
174 return head->api;
175}
176
177
178/* end of file gnunet-peerinfo_plugins.c */
diff --git a/src/peerinfo-tool/gnunet-peerinfo_plugins.h b/src/peerinfo-tool/gnunet-peerinfo_plugins.h
new file mode 100644
index 000000000..9640ed598
--- /dev/null
+++ b/src/peerinfo-tool/gnunet-peerinfo_plugins.h
@@ -0,0 +1,58 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010,2011 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_plugins.h
23 * @brief plugin management API
24 * @author Christian Grothoff
25 */
26#ifndef GNUNET_PEERINFO_PLUGINS_H
27#define GNUNET_PEERINFO_PLUGINS_H
28
29#include "gnunet_util_lib.h"
30
31/**
32 * Load transport plugins.
33 *
34 * @param cfg configuration to use
35 */
36void
37GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
38
39
40/**
41 * Unload all plugins
42 */
43void
44GPI_plugins_unload (void);
45
46
47/**
48 * Obtain the plugin API based on a plugin name.
49 *
50 * @param name name of the plugin
51 * @return the plugin's API, NULL if the plugin is not loaded
52 */
53struct GNUNET_TRANSPORT_PluginFunctions *
54GPI_plugins_find (const char *name);
55
56
57#endif
58/* end of file gnunet-peerinfo_plugins.h */