gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11016 - in gnunet: . src/core src/hostlist src/include src


From: gnunet
Subject: [GNUnet-SVN] r11016 - in gnunet: . src/core src/hostlist src/include src/peerinfo src/peerinfo-tool src/transport
Date: Wed, 21 Apr 2010 22:19:43 +0200

Author: grothoff
Date: 2010-04-21 22:19:43 +0200 (Wed, 21 Apr 2010)
New Revision: 11016

Modified:
   gnunet/TODO
   gnunet/src/core/gnunet-service-core.c
   gnunet/src/hostlist/hostlist-server.c
   gnunet/src/include/gnunet_peerinfo_service.h
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/peerinfo-tool/gnunet-peerinfo.c
   gnunet/src/peerinfo/gnunet-service-peerinfo.c
   gnunet/src/peerinfo/peerinfo.h
   gnunet/src/peerinfo/peerinfo_api.c
   gnunet/src/peerinfo/test_peerinfo_api.c
   gnunet/src/transport/gnunet-service-transport.c
Log:
activating new peerinfo API

Modified: gnunet/TODO
===================================================================
--- gnunet/TODO 2010-04-21 19:57:04 UTC (rev 11015)
+++ gnunet/TODO 2010-04-21 20:19:43 UTC (rev 11016)
@@ -1,9 +1,4 @@
 0.9.0pre1:
-* PEERINFO: [CG]
-  - finish implementing NEW API (cancel, timeout, submit-during-receive 
prevention)
-  - test new API
-  - transition existing code to new API
-  - remove support for old API
 * FS: [CG]
   - support recursive download even if filename is NULL and we hence
     do not generate files on disk (use temp_filename)
@@ -175,6 +170,11 @@
 * DATASTORE (?):
   - check for duplicates on insertion (currently, same content is frequently
     stored again [seen with KBLOCKS and SBLOCKS]!)
+* PEERINFO:
+  - merge multiple HELLOs of the same peer in the transmission queue
+    (theoretically reduces overhead; bounds message queue size)
+  - merge multiple iteration requests over "all" peers in the queue
+    (theoretically reduces overhead; bounds messgae queue size)
 
 Minor features:
 * TCP:

Modified: gnunet/src/core/gnunet-service-core.c
===================================================================
--- gnunet/src/core/gnunet-service-core.c       2010-04-21 19:57:04 UTC (rev 
11015)
+++ gnunet/src/core/gnunet-service-core.c       2010-04-21 20:19:43 UTC (rev 
11016)
@@ -656,6 +656,11 @@
 struct GNUNET_SCHEDULER_Handle *sched;
 
 /**
+ * Handle to peerinfo service.
+ */
+static struct GNUNET_PEERINFO_Handle *peerinfo;
+
+/**
  * Our configuration.
  */
 const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -2491,8 +2496,7 @@
                   GNUNET_i2s (&n->peer));
 #endif
       GNUNET_assert (n->pitr == NULL);
-      n->pitr = GNUNET_PEERINFO_iterate (cfg,
-                                        sched,
+      n->pitr = GNUNET_PEERINFO_iterate (peerinfo,
                                         &n->peer,
                                         0,
                                         
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20),
@@ -2923,8 +2927,7 @@
       /* lookup n's public key, then try again */
       GNUNET_assert (n->skm == NULL);
       n->skm = m_cpy;
-      n->pitr = GNUNET_PEERINFO_iterate (cfg,
-                                        sched,
+      n->pitr = GNUNET_PEERINFO_iterate (peerinfo,
                                         &n->peer,
                                         0,
                                         GNUNET_TIME_UNIT_MINUTES,
@@ -3737,6 +3740,8 @@
     GNUNET_CRYPTO_rsa_key_free (my_private_key);
   if (stats != NULL)
     GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+  if (peerinfo != NULL)
+    GNUNET_PEERINFO_disconnect (peerinfo);
 }
 
 
@@ -3781,12 +3786,21 @@
       GNUNET_SCHEDULER_shutdown (s);
       return;
     }
+  peerinfo = GNUNET_PEERINFO_connect (sched, cfg);
+  if (NULL == peerinfo)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  _("Could not access PEERINFO service.  Exiting.\n"));
+      GNUNET_SCHEDULER_shutdown (s);
+      return;
+    }
   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
   GNUNET_free (keyfile);
   if (my_private_key == NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   _("Core service could not access hostkey.  Exiting.\n"));
+      GNUNET_PEERINFO_disconnect (peerinfo);
       GNUNET_SCHEDULER_shutdown (s);
       return;
     }

Modified: gnunet/src/hostlist/hostlist-server.c
===================================================================
--- gnunet/src/hostlist/hostlist-server.c       2010-04-21 19:57:04 UTC (rev 
11015)
+++ gnunet/src/hostlist/hostlist-server.c       2010-04-21 20:19:43 UTC (rev 
11016)
@@ -95,6 +95,11 @@
 static struct GNUNET_PEERINFO_IteratorContext *pitr;
 
 /**
+ * Handle for accessing peerinfo service.
+ */
+static struct GNUNET_PEERINFO_Handle *peerinfo;
+
+/**
  * Context for host processor.
  */
 struct HostSet
@@ -280,7 +285,8 @@
 
   response_task = GNUNET_SCHEDULER_NO_TASK;
   results = GNUNET_malloc(sizeof(struct HostSet));
-  pitr = GNUNET_PEERINFO_iterate (cfg, sched, 
+  GNUNET_assert (peerinfo != NULL);
+  pitr = GNUNET_PEERINFO_iterate (peerinfo,
                                  NULL,
                                  0, 
                                  GNUNET_TIME_UNIT_MINUTES,
@@ -596,6 +602,13 @@
   sched = s;
   cfg = c;
   stats = st;
+  peerinfo = GNUNET_PEERINFO_connect (sched, cfg);
+  if (peerinfo == NULL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Could not access PEERINFO service.  Exiting.\n"));     
+      return GNUNET_SYSERR;
+    }
   if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg,
                                                   "HOSTLIST",
                                                   "HTTPPORT", 
@@ -724,6 +737,11 @@
       MHD_destroy_response (response);
       response = NULL;
     }
+  if (peerinfo != NULL)
+    {
+      GNUNET_PEERINFO_disconnect (peerinfo);
+      peerinfo = NULL;
+    }
 }
 
 /* end of hostlist-server.c */

Modified: gnunet/src/include/gnunet_peerinfo_service.h
===================================================================
--- gnunet/src/include/gnunet_peerinfo_service.h        2010-04-21 19:57:04 UTC 
(rev 11015)
+++ gnunet/src/include/gnunet_peerinfo_service.h        2010-04-21 20:19:43 UTC 
(rev 11016)
@@ -51,14 +51,15 @@
 /**
  * Connect to the peerinfo service.
  *
- * @param cfg configuration to use
  * @param sched scheduler to use
+ * @param cfg configuration to use
  * @return NULL on error (configuration related, actual connection
  *         etablishment may happen asynchronously).
  */
 struct GNUNET_PEERINFO_Handle *
-GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                        struct GNUNET_SCHEDULER_Handle *sched);
+GNUNET_PEERINFO_connect (struct GNUNET_SCHEDULER_Handle *sched,
+                        const struct GNUNET_CONFIGURATION_Handle *cfg);
+                        
 
 
 /**
@@ -86,26 +87,11 @@
  * @param hello the verified (!) HELLO message
  */
 void
-GNUNET_PEERINFO_add_peer_new (struct GNUNET_PEERINFO_Handle *h,
-                             const struct GNUNET_HELLO_Message *hello);
+GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
+                         const struct GNUNET_HELLO_Message *hello);
 
 
-
 /**
- * Add a host to the persistent list.
- *
- * @param cfg configuration to use
- * @param sched scheduler to use
- * @param peer identity of the peer
- * @param hello the verified (!) HELLO message
- */
-void
-GNUNET_PEERINFO_add_peer (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                          struct GNUNET_SCHEDULER_Handle *sched,
-                          const struct GNUNET_PeerIdentity *peer,
-                          const struct GNUNET_HELLO_Message *hello);
-
-/**
  * Type of an iterator over the hosts.  Note that each
  * host will be called with each available protocol.
  *
@@ -128,40 +114,6 @@
 
 
 /**
- * Call a method for each known matching host and change
- * its trust value.  The method will be invoked once for
- * each host and then finally once with a NULL pointer.  After
- * that final invocation, the iterator context must no longer
- * be used.
- *
- * Note that the last call can be triggered by timeout or by simply
- * being done; however, the trust argument will be set to zero if we
- * are done, 1 if we timed out and 2 for fatal error.
- *
- * @param cfg configuration to use
- * @param sched scheduler to use
- * @param peer restrict iteration to this peer only (can be NULL)
- * @param trust_delta how much to change the trust in all matching peers
- * @param timeout how long to wait until timing out
- * @param callback the method to call for each peer
- * @param callback_cls closure for callback
- * @return NULL on error (in this case, 'callback' is never called!), 
- *         otherwise an iterator context
- */
-struct GNUNET_PEERINFO_IteratorContext *
-GNUNET_PEERINFO_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                         struct GNUNET_SCHEDULER_Handle *sched,
-                         const struct GNUNET_PeerIdentity *peer,
-                         int trust_delta,
-                         struct GNUNET_TIME_Relative timeout,
-                         GNUNET_PEERINFO_Processor callback,
-                         void *callback_cls);
-
-
-struct GNUNET_PEERINFO_NewIteratorContext;
-
-
-/**
  * Call a method for each known matching host and change its trust
  * value.  The callback method will be invoked once for each matching
  * host and then finally once with a NULL pointer.  After that final
@@ -183,13 +135,13 @@
  * @return NULL on error (in this case, 'callback' is never called!), 
  *         otherwise an iterator context
  */
-struct GNUNET_PEERINFO_NewIteratorContext *
-GNUNET_PEERINFO_iterate_new (struct GNUNET_PEERINFO_Handle *h,
-                            const struct GNUNET_PeerIdentity *peer,
-                            int trust_delta,
-                            struct GNUNET_TIME_Relative timeout,
-                            GNUNET_PEERINFO_Processor callback,
-                            void *callback_cls);
+struct GNUNET_PEERINFO_IteratorContext *
+GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
+                        const struct GNUNET_PeerIdentity *peer,
+                        int trust_delta,
+                        struct GNUNET_TIME_Relative timeout,
+                        GNUNET_PEERINFO_Processor callback,
+                        void *callback_cls);
 
 
 
@@ -199,18 +151,10 @@
  * @param ic context of the iterator to cancel
  */
 void
-GNUNET_PEERINFO_iterate_cancel_new (struct GNUNET_PEERINFO_NewIteratorContext 
*ic);
-
-
-/**
- * Cancel an iteration over peer information.
- *
- * @param ic context of the iterator to cancel
- */
-void
 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
 
 
+
 /**
  * Handle for notifications about changes to the set of known peers.
  */

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2010-04-21 19:57:04 UTC (rev 
11015)
+++ gnunet/src/include/gnunet_protocols.h       2010-04-21 20:19:43 UTC (rev 
11016)
@@ -199,11 +199,6 @@
 #define GNUNET_MESSAGE_TYPE_TRANSPORT_PONG 33
 
 /**
- * Request addition of a HELLO
- */
-#define GNUNET_MESSAGE_TYPE_PEERINFO_ADD 36
-
-/**
  * Request update and listing of a peer.
  */
 #define GNUNET_MESSAGE_TYPE_PEERINFO_GET 37

Modified: gnunet/src/peerinfo/gnunet-service-peerinfo.c
===================================================================
--- gnunet/src/peerinfo/gnunet-service-peerinfo.c       2010-04-21 19:57:04 UTC 
(rev 11015)
+++ gnunet/src/peerinfo/gnunet-service-peerinfo.c       2010-04-21 20:19:43 UTC 
(rev 11016)
@@ -29,8 +29,6 @@
  *
  * TODO:
  * - HostEntries are never 'free'd (add expiration, upper bound?)
- * - AddPeer message is obsolete with NEW peerinfo API (remove handler,
- *   message struct and protocol)
  */
 
 #include "platform.h"
@@ -649,43 +647,6 @@
 
 
 /**
- * Handle ADD-message.
- *
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
- */
-static void
-handle_add (void *cls,
-            struct GNUNET_SERVER_Client *client,
-            const struct GNUNET_MessageHeader *message)
-{
-  const struct PeerAddMessage *pam;
-  const struct GNUNET_MessageHeader *hello;
-  uint16_t size;
-
-  size = ntohs (message->size);
-  if (size <
-      sizeof (struct PeerAddMessage) + sizeof (struct GNUNET_MessageHeader))
-    {
-      GNUNET_break (0);
-      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-      return;
-    }
-  pam = (const struct PeerAddMessage *) message;
-  hello = (const struct GNUNET_MessageHeader *) &pam[1];
-  if (size != sizeof (struct PeerAddMessage) + ntohs (hello->size))
-    {
-      GNUNET_break (0);
-      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-      return;
-    }
-  bind_address (&pam->peer, (const struct GNUNET_HELLO_Message *) hello);
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
-/**
  * Handle HELLO-message.
  *
  * @param cls closure
@@ -787,7 +748,6 @@
  */
 static struct GNUNET_SERVER_MessageHandler handlers[] = {
   {&handle_hello, NULL, GNUNET_MESSAGE_TYPE_HELLO, 0},
-  {&handle_add, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_ADD, 0},
   {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET,
    sizeof (struct ListPeerMessage)},
   {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,

Modified: gnunet/src/peerinfo/peerinfo.h
===================================================================
--- gnunet/src/peerinfo/peerinfo.h      2010-04-21 19:57:04 UTC (rev 11015)
+++ gnunet/src/peerinfo/peerinfo.h      2010-04-21 20:19:43 UTC (rev 11016)
@@ -30,31 +30,6 @@
 #define DEBUG_PEERINFO GNUNET_NO
 
 /**
- * Add the given peer to the list.  This message
- * is always followed by a verified HELLO message.
- */
-struct PeerAddMessage
-{
-
-  /**
-   * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_ADD
-   */
-  struct GNUNET_MessageHeader header;
-
-  /**
-   * Always zero.
-   */
-  uint32_t reserved GNUNET_PACKED;
-
-  /**
-   * For which peer do we provide a HELLO message here?
-   */
-  struct GNUNET_PeerIdentity peer;
-
-};
-
-
-/**
  * Message requesting a listing of all known peers,
  * possibly modified by the specified trust value
  * and restricted to the specified peer identity.

Modified: gnunet/src/peerinfo/peerinfo_api.c
===================================================================
--- gnunet/src/peerinfo/peerinfo_api.c  2010-04-21 19:57:04 UTC (rev 11015)
+++ gnunet/src/peerinfo/peerinfo_api.c  2010-04-21 20:19:43 UTC (rev 11016)
@@ -127,14 +127,14 @@
 /**
  * Connect to the peerinfo service.
  *
- * @param cfg configuration to use
  * @param sched scheduler to use
+ * @param cfg configuration to use
  * @return NULL on error (configuration related, actual connection
  *         etablishment may happen asynchronously).
  */
 struct GNUNET_PEERINFO_Handle *
-GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                        struct GNUNET_SCHEDULER_Handle *sched)
+GNUNET_PEERINFO_connect (struct GNUNET_SCHEDULER_Handle *sched,
+                        const struct GNUNET_CONFIGURATION_Handle *cfg)         
         
 {
   struct GNUNET_CLIENT_Connection *client;
   struct GNUNET_PEERINFO_Handle *ret;
@@ -197,7 +197,7 @@
 reconnect (struct GNUNET_PEERINFO_Handle *h)
 {
   GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR);
-  h->client = GNUNET_CLIENT_connect (h->sched, "client", h->cfg);
+  h->client = GNUNET_CLIENT_connect (h->sched, "peerinfo", h->cfg);
   GNUNET_assert (h->client != NULL);
 }
 
@@ -291,8 +291,8 @@
  * @param hello the verified (!) HELLO message
  */
 void
-GNUNET_PEERINFO_add_peer_new (struct GNUNET_PEERINFO_Handle *h,
-                             const struct GNUNET_HELLO_Message *hello)
+GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
+                         const struct GNUNET_HELLO_Message *hello)
 {
   uint16_t hs = GNUNET_HELLO_size (hello);
   struct TransmissionQueueEntry *tqe;
@@ -321,7 +321,7 @@
 /**
  * Context for an iteration request.
  */
-struct GNUNET_PEERINFO_NewIteratorContext
+struct GNUNET_PEERINFO_IteratorContext
 {
   /**
    * Handle to the PEERINFO service.
@@ -370,7 +370,7 @@
 static void
 peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 {
-  struct GNUNET_PEERINFO_NewIteratorContext *ic = cls;
+  struct GNUNET_PEERINFO_IteratorContext *ic = cls;
   const struct InfoMessage *im;
   const struct GNUNET_HELLO_Message *hello;
   uint16_t ms;
@@ -461,14 +461,14 @@
  * We've transmitted the iteration request.  Now get ready to process
  * the results (or handle transmission error).
  *
- * @param cls the 'struct GNUNET_PEERINFO_NewIteratorContext'
+ * @param cls the 'struct GNUNET_PEERINFO_IteratorContext'
  * @param transmit_success GNUNET_OK if transmission worked
  */
 static void
 iterator_start_receive (void *cls,
                        int transmit_success)
 {
-  struct GNUNET_PEERINFO_NewIteratorContext *ic = cls;
+  struct GNUNET_PEERINFO_IteratorContext *ic = cls;
 
   if (GNUNET_OK != transmit_success)
     {
@@ -491,14 +491,14 @@
 /**
  * Peerinfo iteration request has timed out.  
  *
- * @param cls the 'struct GNUNET_PEERINFO_NewIteratorContext*'
+ * @param cls the 'struct GNUNET_PEERINFO_IteratorContext*'
  * @param tc scheduler context
  */
 static void
 signal_timeout (void *cls,
                const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct GNUNET_PEERINFO_NewIteratorContext *ic = cls;
+  struct GNUNET_PEERINFO_IteratorContext *ic = cls;
 
   ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
   ic->callback (ic->callback_cls, NULL, NULL, 1);
@@ -535,17 +535,17 @@
  * @return NULL on error (in this case, 'callback' is never called!), 
  *         otherwise an iterator context
  */
-struct GNUNET_PEERINFO_NewIteratorContext *
-GNUNET_PEERINFO_iterate_new (struct GNUNET_PEERINFO_Handle *h,
-                            const struct GNUNET_PeerIdentity *peer,
-                            int trust_delta,
-                            struct GNUNET_TIME_Relative timeout,
-                            GNUNET_PEERINFO_Processor callback,
-                            void *callback_cls)
+struct GNUNET_PEERINFO_IteratorContext *
+GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
+                        const struct GNUNET_PeerIdentity *peer,
+                        int trust_delta,
+                        struct GNUNET_TIME_Relative timeout,
+                        GNUNET_PEERINFO_Processor callback,
+                        void *callback_cls)
 {
   struct ListAllPeersMessage *lapm;
   struct ListPeerMessage *lpm;
-  struct GNUNET_PEERINFO_NewIteratorContext *ic;
+  struct GNUNET_PEERINFO_IteratorContext *ic;
   struct TransmissionQueueEntry *tqe;
 
 #if DEBUG_PEERINFO
@@ -573,7 +573,7 @@
       lpm->trust_change = htonl (trust_delta);
       memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
     }
-  ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NewIteratorContext));
+  ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext));
   ic->h = h;
   ic->tqe = tqe;
   ic->callback = callback;
@@ -603,7 +603,7 @@
  * @param ic context of the iterator to cancel
  */
 void
-GNUNET_PEERINFO_iterate_cancel_new (struct GNUNET_PEERINFO_NewIteratorContext 
*ic)
+GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic)
 {
   if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
     {
@@ -622,304 +622,4 @@
 }
 
 
-
-/* ***************************** OLD API ****************************** */
-
-
-
-
-#define ADD_PEER_TIMEOUT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 30)
-
-
-struct CAFContext
-{
-  struct GNUNET_CLIENT_Connection *client;
-  struct GNUNET_MessageHeader *msg;
-};
-
-
-static size_t
-copy_and_free (void *cls, size_t size, void *buf)
-{
-  struct CAFContext *cc = cls;
-  struct GNUNET_MessageHeader *msg = cc->msg;
-  uint16_t msize;
-
-  if (buf == NULL)
-    {
-#if DEBUG_PEERINFO
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  _
-                  ("Failed to transmit message of type %u to `%s' service.\n"),
-                  ntohs (msg->type), "peerinfo");
-#endif
-      GNUNET_free (msg);
-      GNUNET_CLIENT_disconnect (cc->client, GNUNET_NO);
-      GNUNET_free (cc);
-      return 0;
-    }
-  msize = ntohs (msg->size);
-  GNUNET_assert (size >= msize);
-  memcpy (buf, msg, msize);
-  GNUNET_free (msg);
-  GNUNET_CLIENT_disconnect (cc->client, GNUNET_YES);
-  GNUNET_free (cc);
-  return msize;
-}
-
-
-
-/**
- * Add a host to the persistent list.
- *
- * @param cfg configuration to use
- * @param sched scheduler to use
- * @param peer identity of the peer
- * @param hello the verified (!) HELLO message
- */
-void
-GNUNET_PEERINFO_add_peer (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                          struct GNUNET_SCHEDULER_Handle *sched,
-                          const struct GNUNET_PeerIdentity *peer,
-                          const struct GNUNET_HELLO_Message *hello)
-{
-  struct GNUNET_CLIENT_Connection *client;
-  struct PeerAddMessage *pam;
-  uint16_t hs;
-  struct CAFContext *cc;
-
-#if DEBUG_PEERINFO
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Adding peer `%s' to peerinfo database\n",
-             GNUNET_i2s(peer));
-#endif
-  client = GNUNET_CLIENT_connect (sched, "peerinfo", cfg);
-  if (client == NULL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("Could not connect to `%s' service.\n"), "peerinfo");
-      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);
-  memcpy (&pam->peer, peer, sizeof (struct GNUNET_PeerIdentity));
-  memcpy (&pam[1], hello, hs);
-  cc = GNUNET_malloc (sizeof (struct CAFContext));
-  cc->client = client;
-  cc->msg = &pam->header;
-  GNUNET_CLIENT_notify_transmit_ready (client,
-                                       ntohs (pam->header.size),
-                                       ADD_PEER_TIMEOUT, 
-                                      GNUNET_NO,
-                                      &copy_and_free, cc);
-}
-
-
-/**
- * Context for the info handler.
- */
-struct GNUNET_PEERINFO_IteratorContext
-{
-
-  /**
-   * Our connection to the PEERINFO service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
-
-  /**
-   * Function to call with information.
-   */
-  GNUNET_PEERINFO_Processor callback;
-
-  /**
-   * Closure for callback.
-   */
-  void *callback_cls;
-
-  /**
-   * When should we time out?
-   */
-  struct GNUNET_TIME_Absolute timeout;
-
-};
-
-
-/**
- * Type of a function to call when we receive a message
- * from the service.
- *
- * @param cls closure
- * @param msg message received, NULL on timeout or fatal error
- */
-static void
-info_handler (void *cls, const struct GNUNET_MessageHeader *msg)
-{
-  struct GNUNET_PEERINFO_IteratorContext *ic = cls;
-  const struct InfoMessage *im;
-  const struct GNUNET_HELLO_Message *hello;
-  uint16_t ms;
-
-  if (msg == NULL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("Failed to receive response from `%s' service.\n"),
-                  "peerinfo");
-      ic->callback (ic->callback_cls, NULL, NULL, 1);
-      GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
-      GNUNET_free (ic);
-      return;
-    }
-  if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END)
-    {
-#if DEBUG_PEERINFO
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                 "Received end of list of peers from peerinfo database\n");
-#endif
-      ic->callback (ic->callback_cls, NULL, NULL, 0);
-      GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
-      GNUNET_free (ic);
-      return;
-    }
-  ms = ntohs (msg->size);
-  if ((ms < sizeof (struct InfoMessage)) ||
-      (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO))
-    {
-      GNUNET_break (0);
-      ic->callback (ic->callback_cls, NULL, NULL, 2);
-      GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
-      GNUNET_free (ic);
-      return;
-    }
-  im = (const struct InfoMessage *) msg;
-  hello = NULL;
-  if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader))
-    {
-      hello = (const struct GNUNET_HELLO_Message *) &im[1];
-      if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
-        {
-          GNUNET_break (0);
-          ic->callback (ic->callback_cls, NULL, NULL, 2);
-          GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
-          GNUNET_free (ic);
-          return;
-        }
-    }
-#if DEBUG_PEERINFO
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Received %u bytes of `%s' information about peer `%s' from 
PEERINFO database\n",
-             (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello),
-             "HELLO",
-             GNUNET_i2s (&im->peer));
-#endif
-  ic->callback (ic->callback_cls, &im->peer, hello, ntohl (im->trust));
-  GNUNET_CLIENT_receive (ic->client,
-                         &info_handler,
-                         ic,
-                         GNUNET_TIME_absolute_get_remaining (ic->timeout));
-}
-
-
-/**
- * Call a method for each known matching host and change
- * its trust value.  The method will be invoked once for
- * each host and then finally once with a NULL pointer.
- * Note that the last call can be triggered by timeout or
- * by simply being done; however, the trust argument will
- * be set to zero if we are done and to 1 if we timed out.
- *
- * @param cfg configuration to use
- * @param sched scheduler to use
- * @param peer restrict iteration to this peer only (can be NULL)
- * @param trust_delta how much to change the trust in all matching peers
- * @param timeout how long to wait until timing out
- * @param callback the method to call for each peer
- * @param callback_cls closure for callback
- * @return NULL on error, otherwise an iterator context
- */
-struct GNUNET_PEERINFO_IteratorContext *
-GNUNET_PEERINFO_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                         struct GNUNET_SCHEDULER_Handle *sched,
-                         const struct GNUNET_PeerIdentity *peer,
-                         int trust_delta,
-                         struct GNUNET_TIME_Relative timeout,
-                         GNUNET_PEERINFO_Processor callback,
-                         void *callback_cls)
-{
-  struct GNUNET_CLIENT_Connection *client;
-  struct ListAllPeersMessage *lapm;
-  struct ListPeerMessage *lpm;
-  struct GNUNET_PEERINFO_IteratorContext *ihc;
-
-  client = GNUNET_CLIENT_connect (sched, "peerinfo", cfg);
-  if (client == NULL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("Could not connect to `%s' service.\n"), "peerinfo");
-      return NULL;
-    }
-#if DEBUG_PEERINFO
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Requesting list of peers from peerinfo database\n");
-#endif
-  if (peer == NULL)
-    {
-      ihc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext) +
-                          sizeof (struct ListAllPeersMessage));
-      lapm = (struct ListAllPeersMessage *) &ihc[1];
-      lapm->header.size = htons (sizeof (struct ListAllPeersMessage));
-      lapm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
-      lapm->trust_change = htonl (trust_delta);
-    }
-  else
-    {
-      ihc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext) +
-                          sizeof (struct ListPeerMessage));
-      lpm = (struct ListPeerMessage *) &ihc[1];
-      lpm->header.size = htons (sizeof (struct ListPeerMessage));
-      lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET);
-      lpm->trust_change = htonl (trust_delta);
-      memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
-    }
-  ihc->client = client;
-  ihc->callback = callback;
-  ihc->callback_cls = callback_cls;
-  ihc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
-  if (GNUNET_OK != 
-      GNUNET_CLIENT_transmit_and_get_response (client,
-                                              (const struct 
GNUNET_MessageHeader*) &ihc[1],
-                                              timeout,
-                                              GNUNET_YES,
-                                              &info_handler,
-                                              ihc))
-    {
-      GNUNET_break (0);
-      GNUNET_CLIENT_disconnect (ihc->client, GNUNET_NO);
-      GNUNET_free (ihc);
-      return NULL;
-    }
-  return ihc;
-}
-
-
-/**
- * Cancel an iteration over peer information.
- *
- * @param ic context of the iterator to cancel
- */
-void
-GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic)
-{
-  GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
-  GNUNET_free (ic);
-}
-
-
 /* end of peerinfo_api.c */

Modified: gnunet/src/peerinfo/test_peerinfo_api.c
===================================================================
--- gnunet/src/peerinfo/test_peerinfo_api.c     2010-04-21 19:57:04 UTC (rev 
11015)
+++ gnunet/src/peerinfo/test_peerinfo_api.c     2010-04-21 20:19:43 UTC (rev 
11016)
@@ -40,7 +40,7 @@
 
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
-static struct GNUNET_PEERINFO_NewIteratorContext *ic;
+static struct GNUNET_PEERINFO_IteratorContext *ic;
 
 static struct GNUNET_PEERINFO_Handle *h;
 
@@ -93,7 +93,7 @@
   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_new (h, h2);
+  GNUNET_PEERINFO_add_peer (h, h2);
   GNUNET_free (h2);
 
 }
@@ -116,12 +116,12 @@
          /* try again */
          retries++;      
          add_peer ();
-         ic = GNUNET_PEERINFO_iterate_new (h,
-                                           NULL,
-                                           0,
-                                           GNUNET_TIME_relative_multiply
-                                           (GNUNET_TIME_UNIT_SECONDS, 15), 
-                                           &process, cls);
+         ic = GNUNET_PEERINFO_iterate (h,
+                                       NULL,
+                                       0,
+                                       GNUNET_TIME_relative_multiply
+                                       (GNUNET_TIME_UNIT_SECONDS, 15), 
+                                       &process, cls);
          return;
        }
       GNUNET_assert (peer == NULL);
@@ -152,14 +152,14 @@
 {
   sched = s;
   cfg = c;
-  h = GNUNET_PEERINFO_connect (cfg, sched);
+  h = GNUNET_PEERINFO_connect (sched, cfg);
   add_peer ();
-  ic = GNUNET_PEERINFO_iterate_new (h,
-                                   NULL,
-                                   0,
-                                   GNUNET_TIME_relative_multiply
-                                   (GNUNET_TIME_UNIT_SECONDS, 15),
-                                   &process, cls);
+  ic = GNUNET_PEERINFO_iterate (h,
+                               NULL,
+                               0,
+                               GNUNET_TIME_relative_multiply
+                               (GNUNET_TIME_UNIT_SECONDS, 15),
+                               &process, cls);
 }
 
 

Modified: gnunet/src/peerinfo-tool/gnunet-peerinfo.c
===================================================================
--- gnunet/src/peerinfo-tool/gnunet-peerinfo.c  2010-04-21 19:57:04 UTC (rev 
11015)
+++ gnunet/src/peerinfo-tool/gnunet-peerinfo.c  2010-04-21 20:19:43 UTC (rev 
11016)
@@ -39,6 +39,8 @@
 
 static struct GNUNET_SCHEDULER_Handle *sched;
 
+static struct GNUNET_PEERINFO_Handle *peerinfo;
+
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 struct PrintContext
@@ -166,7 +168,10 @@
   struct PrintContext *pc;
 
   if (peer == NULL)    
-    return;    
+    {
+      GNUNET_PEERINFO_disconnect (peerinfo);
+      return;    
+    }
   if (be_quiet)
     {
       GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
@@ -212,8 +217,14 @@
   cfg = c;
   if (get_self != GNUNET_YES)
     {
-      (void) GNUNET_PEERINFO_iterate (cfg,
-                                     sched,
+      peerinfo = GNUNET_PEERINFO_connect (sched, cfg);
+      if (peerinfo == NULL)
+       {
+         fprintf (stderr,
+                  _("Could not access PEERINFO service.  Exiting.\n"));
+         return;
+       }
+      (void) GNUNET_PEERINFO_iterate (peerinfo,
                                      NULL,
                                      0,
                                      GNUNET_TIME_relative_multiply

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2010-04-21 19:57:04 UTC 
(rev 11015)
+++ gnunet/src/transport/gnunet-service-transport.c     2010-04-21 20:19:43 UTC 
(rev 11016)
@@ -835,6 +835,11 @@
 static struct GNUNET_SERVER_Handle *server;
 
 /**
+ * Handle to peerinfo service.
+ */
+static struct GNUNET_PEERINFO_Handle *peerinfo;
+
+/**
  * All known neighbours and their HELLOs.
  */
 static struct NeighbourList *neighbours;
@@ -1775,7 +1780,7 @@
   GNUNET_free_non_null (our_hello);
   our_hello = hello;
   our_hello_version++;
-  GNUNET_PEERINFO_add_peer (cfg, sched, &my_identity, our_hello);
+  GNUNET_PEERINFO_add_peer (peerinfo, our_hello);
   npos = neighbours;
   while (npos != NULL)
     {
@@ -2567,7 +2572,7 @@
                                                   &neighbour_timeout_task, n);
   if (do_hello)
     {
-      n->piter = GNUNET_PEERINFO_iterate (cfg, sched, peer,
+      n->piter = GNUNET_PEERINFO_iterate (peerinfo, peer,
                                          0, GNUNET_TIME_UNIT_FOREVER_REL,
                                          &add_hello_for_peer, n);
       transmit_to_peer (NULL, NULL, 0,
@@ -3245,8 +3250,7 @@
       hello = GNUNET_HELLO_create (&ve->publicKey,
                                   &add_validated_address,
                                   &avac);
-      GNUNET_PEERINFO_add_peer (cfg, sched,
-                               &target,
+      GNUNET_PEERINFO_add_peer (peerinfo,
                                hello);
       GNUNET_free (hello);
     }
@@ -3596,7 +3600,7 @@
          plain_hello = GNUNET_HELLO_create (&pk,
                                             NULL, 
                                             NULL);
-         GNUNET_PEERINFO_add_peer (cfg, sched, &target, plain_hello);
+         GNUNET_PEERINFO_add_peer (peerinfo, plain_hello);
          GNUNET_free (plain_hello);
 #if DEBUG_TRANSPORT
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3732,8 +3736,7 @@
                               chvc);
   /* finally, check if HELLO was previously validated
      (continuation will then schedule actual validation) */
-  chvc->piter = GNUNET_PEERINFO_iterate (cfg,
-                                         sched,
+  chvc->piter = GNUNET_PEERINFO_iterate (peerinfo,
                                          &target,
                                          0,
                                          HELLO_VERIFICATION_TIMEOUT,
@@ -4788,6 +4791,22 @@
       return;
     }
   max_connect_per_transport = (uint32_t) tneigh;
+  peerinfo = GNUNET_PEERINFO_connect (sched, cfg);
+  if (peerinfo == NULL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Could not access PEERINFO service.  Exiting.\n"));     
+      GNUNET_SCHEDULER_shutdown (s);
+      if (stats != NULL)
+       {
+         GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+         stats = NULL;
+       }
+      GNUNET_CONTAINER_multihashmap_destroy (validation_map);
+      validation_map = NULL;
+      GNUNET_free (keyfile);
+      return;
+    }
   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
   GNUNET_free (keyfile);
   if (my_private_key == NULL)





reply via email to

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