peerinfo fixes
authorChristian Grothoff <christian@grothoff.org>
Mon, 18 Jan 2010 09:45:40 +0000 (09:45 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 18 Jan 2010 09:45:40 +0000 (09:45 +0000)
src/peerinfo/gnunet-service-peerinfo.c
src/peerinfo/peerinfo_api.c
src/peerinfo/test_peerinfo_api.c

index 30723be0ba3406b42969af10b9c4646cacdb4c3d..f0d8b060668307f7c414c6ec0c8057031c50c2d8 100644 (file)
@@ -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),
index f3479ab7be34eff01e127b852895607eec77a978..0f95a421a2e50986bcc9322a126048204d6bc4d0 100644 (file)
@@ -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,
index 4cbbb7bf618565ff96a04e0aba9daeeb14f14add..0b5230eb6c5421b9a45c55c633e5150b960dd816 100644 (file)
 #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;