From 197610adefaed55ac4eeb192b3ed075593835758 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 18 Mar 2010 14:55:38 +0000 Subject: [PATCH] stuff --- TODO | 6 ++- src/peerinfo/gnunet-peerinfo.c | 85 ++++++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index adc41743d..a0a86789c 100644 --- a/TODO +++ b/TODO @@ -23,8 +23,10 @@ away), in order in which they will likely be done: - disconnect notifications from TCP not always as nice as we might want them to be (but how can we do this cleanly given that UDP is connectionless?) - implement transport API to pretty-print transport address - + transport_api extension (API extension!) - + service-transport extension (protocol extension) + + resolve cyclic dependency (gnunet-peerinfo -> transport_api -> peerinfo!) + + gnunet-transport-service crashes when asked to resolve address (!) + + asynchronous transport lookup and non-CPS iterator in peerinfo require + some work to ensure printing in the proper order... - instantly filter addresses from *other* peers that are *equal* to our own address + port (i.e., localhost:2086). We no longer filter those for outgoing (helps with loopback testing diff --git a/src/peerinfo/gnunet-peerinfo.c b/src/peerinfo/gnunet-peerinfo.c index 7e72be366..d4a36a059 100644 --- a/src/peerinfo/gnunet-peerinfo.c +++ b/src/peerinfo/gnunet-peerinfo.c @@ -28,6 +28,7 @@ #include "gnunet_configuration_lib.h" #include "gnunet_getopt_lib.h" #include "gnunet_peerinfo_service.h" +#include "gnunet_transport_service.h" #include "gnunet_program_lib.h" static int no_resolve; @@ -36,6 +37,63 @@ static int be_quiet; static int get_self; +static struct GNUNET_SCHEDULER_Handle *sched; + +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +#if FIXME +/** + * Function to call with a human-readable format of an address + * + * @param cls closure + * @param address NULL on error, otherwise 0-terminated printable UTF-8 string + */ +static void +print_resolved_address (void *cls, + const char *address) +{ + /* FIXME: need to buffer output from all requests and print it at + once, otherwise we mix results... */ + if (address == NULL) + { + fprintf (stderr, "\n"); + return; + } + fprintf (stderr, " %s\n", address); +} +#endif + +/** + * Iterator callback to go over all addresses. + * + * @param cls closure + * @param tname name of the transport + * @param expiration expiration time + * @param addr the address + * @param addrlen length of the address + * @return GNUNET_OK to keep the address and continue + */ +static int +print_address (void *cls, + const char *tname, + struct GNUNET_TIME_Absolute expiration, + const void *addr, size_t addrlen) +{ +#if FIXME + GNUNET_TRANSPORT_address_lookup (sched, + cfg, + addr, + addrlen, + no_resolve, + tname, + GNUNET_TIME_UNIT_SECONDS, + &print_resolved_address, + NULL); +#endif + return GNUNET_OK; +} + + /** * Print information about the peer. * Currently prints the GNUNET_PeerIdentity, trust and the IP. @@ -48,34 +106,33 @@ print_peer_info (void *cls, { struct GNUNET_CRYPTO_HashAsciiEncoded enc; - /* FIXME: add printing of address information! - => need extended transport API! */ - if (peer == NULL) - { - return; - } + if (peer == NULL) + return; GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc); if (be_quiet) - printf ("%s\n", (const char *) &enc); - else - printf (_("Peer `%s' with trust %8u\n"), (const char *) &enc, trust); + { + printf ("%s\n", (const char *) &enc); + return; + } + printf (_("Peer `%s' with trust %8u\n"), (const char *) &enc, trust); + GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, NULL); } /** * Main function that will be run by the scheduler. * * @param cls closure - * @param sched the scheduler to use + * @param s the scheduler to use * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) - * @param cfg configuration + * @param c configuration */ static void run (void *cls, - struct GNUNET_SCHEDULER_Handle *sched, + struct GNUNET_SCHEDULER_Handle *s, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_CRYPTO_RsaPrivateKey *priv; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; @@ -83,6 +140,8 @@ run (void *cls, struct GNUNET_CRYPTO_HashAsciiEncoded enc; char *fn; + sched = s; + cfg = c; if (get_self != GNUNET_YES) { (void) GNUNET_PEERINFO_iterate (cfg, -- 2.25.1