From: Christian Grothoff Date: Mon, 18 Jan 2010 09:45:40 +0000 (+0000) Subject: peerinfo fixes X-Git-Tag: initial-import-from-subversion-38251~22951 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=260b2ebb0662c22d14f2482700c2211acb22b0d8;p=oweals%2Fgnunet.git peerinfo fixes --- diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 30723be0b..f0d8b0606 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c @@ -563,6 +563,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, host->hello = mrg; } fn = get_host_filename (peer); + GNUNET_DISK_directory_create_for_file (fn); GNUNET_DISK_fn_write (fn, host->hello, GNUNET_HELLO_size (host->hello), diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index f3479ab7b..0f95a421a 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c @@ -103,6 +103,12 @@ GNUNET_PEERINFO_add_peer (const struct GNUNET_CONFIGURATION_Handle *cfg, return; } hs = GNUNET_HELLO_size (hello); +#if DEBUG_PEERINFO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Size of `%s' is %u bytes\n", + "HELLO", + (unsigned int) GNUNET_HELLO_size (hello)); +#endif pam = GNUNET_malloc (sizeof (struct PeerAddMessage) + hs); pam->header.size = htons (hs + sizeof (struct PeerAddMessage)); pam->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_ADD); @@ -213,6 +219,12 @@ info_handler (void *cls, const struct GNUNET_MessageHeader *msg) "Received information about peer `%s' from peerinfo database\n", GNUNET_i2s (&im->peer)); #endif +#if DEBUG_PEERINFO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Size of `%s' is %u bytes\n", + "HELLO", + (unsigned int) GNUNET_HELLO_size (hello)); +#endif ic->callback (ic->callback_cls, &im->peer, hello, ntohl (im->trust)); GNUNET_CLIENT_receive (ic->client, &info_handler, diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 4cbbb7bf6..0b5230eb6 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c @@ -34,7 +34,13 @@ #include "gnunet_peerinfo_service.h" #include "gnunet_program_lib.h" #include "gnunet_time_lib.h" +#include "peerinfo.h" +static struct GNUNET_SCHEDULER_Handle *sched; + +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +static unsigned int retries; static int check_it (void *cls, @@ -54,6 +60,41 @@ check_it (void *cls, } +static size_t +address_generator (void *cls, size_t max, void *buf) +{ + size_t *agc = cls; + size_t ret; + + if (0 == *agc) + return 0; + ret = GNUNET_HELLO_add_address ("peerinfotest", + GNUNET_TIME_relative_to_absolute + (GNUNET_TIME_UNIT_HOURS), "Address", *agc, + buf, max); + (*agc)--; + return ret; +} + + +static void +add_peer () +{ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; + struct GNUNET_PeerIdentity pid; + struct GNUNET_HELLO_Message *h2; + size_t agc; + + agc = 2; + memset (&pkey, 32, sizeof (pkey)); + GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); + h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc); + GNUNET_PEERINFO_add_peer (cfg, sched, &pid, h2); + GNUNET_free (h2); + +} + + static void process (void *cls, const struct GNUNET_PeerIdentity *peer, @@ -64,6 +105,21 @@ process (void *cls, if (peer == NULL) { + if ( (3 == *ok) && + (retries < 5) ) + { + /* try again */ + retries++; + add_peer (); + GNUNET_PEERINFO_iterate (cfg, + sched, + NULL, + 0, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 15), + &process, cls); + return; + } GNUNET_assert (peer == NULL); GNUNET_assert (2 == *ok); GNUNET_assert (trust == 0); @@ -82,48 +138,22 @@ process (void *cls, } -static size_t -address_generator (void *cls, size_t max, void *buf) -{ - size_t *agc = cls; - size_t ret; - - if (0 == *agc) - return 0; - ret = GNUNET_HELLO_add_address ("peerinfotest", - GNUNET_TIME_relative_to_absolute - (GNUNET_TIME_UNIT_HOURS), "Address", *agc, - buf, max); - (*agc)--; - return ret; -} - - 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_HELLO_Message *hello; - struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; - size_t agc; - struct GNUNET_PeerIdentity pid; - - memset (&pkey, 32, sizeof (pkey)); - GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); - agc = 2; - hello = GNUNET_HELLO_create (&pkey, &address_generator, &agc); - GNUNET_assert (hello != NULL); - GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); + sched = s; + cfg = c; + add_peer (); GNUNET_PEERINFO_iterate (cfg, sched, NULL, 0, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); - GNUNET_free (hello); } @@ -167,6 +197,13 @@ main (int argc, char *argv[]) { int ret = 0; + GNUNET_log_setup ("test_peerinfo_api", +#if DEBUG_PEERINFO + "DEBUG", +#else + "WARNING", +#endif + NULL); ret = check (); GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-peerinfo"); return ret;