gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10038 - gnunet/src/peerinfo


From: gnunet
Subject: [GNUnet-SVN] r10038 - gnunet/src/peerinfo
Date: Mon, 18 Jan 2010 10:45:40 +0100

Author: grothoff
Date: 2010-01-18 10:45:40 +0100 (Mon, 18 Jan 2010)
New Revision: 10038

Modified:
   gnunet/src/peerinfo/gnunet-service-peerinfo.c
   gnunet/src/peerinfo/peerinfo_api.c
   gnunet/src/peerinfo/test_peerinfo_api.c
Log:
peerinfo fixes

Modified: gnunet/src/peerinfo/gnunet-service-peerinfo.c
===================================================================
--- gnunet/src/peerinfo/gnunet-service-peerinfo.c       2010-01-18 09:09:13 UTC 
(rev 10037)
+++ gnunet/src/peerinfo/gnunet-service-peerinfo.c       2010-01-18 09:45:40 UTC 
(rev 10038)
@@ -563,6 +563,7 @@
       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),

Modified: gnunet/src/peerinfo/peerinfo_api.c
===================================================================
--- gnunet/src/peerinfo/peerinfo_api.c  2010-01-18 09:09:13 UTC (rev 10037)
+++ gnunet/src/peerinfo/peerinfo_api.c  2010-01-18 09:45:40 UTC (rev 10038)
@@ -103,6 +103,12 @@
       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 @@
              "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,

Modified: gnunet/src/peerinfo/test_peerinfo_api.c
===================================================================
--- gnunet/src/peerinfo/test_peerinfo_api.c     2010-01-18 09:09:13 UTC (rev 
10037)
+++ gnunet/src/peerinfo/test_peerinfo_api.c     2010-01-18 09:45:40 UTC (rev 
10038)
@@ -34,8 +34,14 @@
 #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,
           const char *tname,
@@ -54,7 +60,42 @@
 }
 
 
+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,
          const struct GNUNET_HELLO_Message *hello, uint32_t trust)
@@ -64,6 +105,21 @@
 
   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 @@
 }
 
 
-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 @@
 {
   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;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]