Changed peerinfo api to distinguish between last element and timeout
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 3 Jan 2011 14:21:25 +0000 (14:21 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 3 Jan 2011 14:21:25 +0000 (14:21 +0000)
src/core/gnunet-service-core.c
src/dv/gnunet-service-dv.c
src/hostlist/hostlist-server.c
src/include/gnunet_peerinfo_service.h
src/peerinfo-tool/gnunet-peerinfo.c
src/peerinfo/peerinfo_api.c
src/peerinfo/peerinfo_api_notify.c
src/peerinfo/perf_peerinfo_api.c
src/peerinfo/test_peerinfo_api.c
src/topology/gnunet-daemon-topology.c
src/transport/gnunet-service-transport.c

index 290160414c40040df7ac771f1014e67c126a5c9f..dd1937f06cbf1c98e88877231e6bc68da9122588 100644 (file)
@@ -3006,10 +3006,18 @@ handle_client_request_connect (void *cls,
 static void
 process_hello_retry_send_key (void *cls,
                               const struct GNUNET_PeerIdentity *peer,
-                              const struct GNUNET_HELLO_Message *hello)
+                              const struct GNUNET_HELLO_Message *hello,
+                              const char *err_msg)
 {
   struct Neighbour *n = cls;
 
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service\n"));
+       /* return; */
+  }
+
   if (peer == NULL)
     {
 #if DEBUG_CORE
@@ -3318,11 +3326,19 @@ handle_set_key (struct Neighbour *n,
 static void
 process_hello_retry_handle_set_key (void *cls,
                                     const struct GNUNET_PeerIdentity *peer,
-                                    const struct GNUNET_HELLO_Message *hello)
+                                    const struct GNUNET_HELLO_Message *hello,
+                                    const char *err_msg)
 {
   struct Neighbour *n = cls;
   struct SetKeyMessage *sm = n->skm;
 
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service\n"));
+       /* return; */
+  }
+
   if (peer == NULL)
     {
       n->skm = NULL;
index cd54686f3433e7b67a07e284afe34b022652631e..223b95fedd3af3d957ab629bd4a48bc98316eb1e 100644 (file)
@@ -2806,11 +2806,13 @@ add_all_direct_neighbors (void *cls,
  * @param cls closure
  * @param peer id of the peer, NULL for last call
  * @param hello hello message for the peer (can be NULL)
+ * @param err_msg NULL if successful, otherwise contains error message
  */
 static void
 process_peerinfo (void *cls,
                   const struct GNUNET_PeerIdentity *peer,
-                  const struct GNUNET_HELLO_Message *hello)
+                  const struct GNUNET_HELLO_Message *hello,
+                  const char *err_msg)
 {
   struct PeerIteratorContext *peerinfo_iterator = cls;
   struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor;
@@ -2819,7 +2821,12 @@ process_peerinfo (void *cls,
   char *neighbor_pid;
 #endif
   int sent;
-
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service\n"));
+         /* return; */
+  }
   if (peer == NULL)
     {
       if (distant->pkey == NULL)
index 95272a555697f28a9b4c247a7340abc36ea572a6..4c88ae317f5ac738538e266393c79a3522f9dfa2 100644 (file)
@@ -178,13 +178,21 @@ check_has_addr (void *cls,
 static void
 host_processor (void *cls,
                const struct GNUNET_PeerIdentity * peer,
-                const struct GNUNET_HELLO_Message *hello)
+                const struct GNUNET_HELLO_Message *hello,
+                const char *err_msg)
 {
   struct HostSet *results = cls;
   size_t old;
   size_t s;
   int has_addr;
   
+  if (err_msg != NULL)
+  {
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service:\n `%s'"), err_msg);
+       return;
+  }
+
   if (peer == NULL)
     {
       pitr = NULL;
@@ -439,17 +447,25 @@ disconnect_handler (void *cls,
  * @param cls closure (not used)
  * @param peer potential peer to connect to
  * @param hello HELLO for this peer (or NULL)
+ * @param err_msg NULL if successful, otherwise contains error message
  */
 static void
 process_notify (void *cls,
                 const struct GNUNET_PeerIdentity *peer,
-                const struct GNUNET_HELLO_Message *hello)
+                const struct GNUNET_HELLO_Message *hello,
+                const char *err_msg)
 {
   struct HostSet *results;
 #if DEBUG_HOSTLIST_SERVER
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
             "Peerinfo is notifying us to rebuild our hostlist\n");
 #endif
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service\n"));
+       /* return; */
+  }
   results = GNUNET_malloc(sizeof(struct HostSet));
   GNUNET_assert (peerinfo != NULL);
   pitr = GNUNET_PEERINFO_iterate (peerinfo,
index 1c34d83bb1c02f975a36e0afe9660532ff51099c..1411168c0fa07b0f93aba1f8a2649eeb87d25cee 100644 (file)
@@ -95,11 +95,13 @@ GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
  * @param cls closure
  * @param peer id of the peer, NULL for last call
  * @param hello hello message for the peer (can be NULL)
+ * @param error message
  */
 typedef void
   (*GNUNET_PEERINFO_Processor) (void *cls,
                                 const struct GNUNET_PeerIdentity * peer,
-                                const struct GNUNET_HELLO_Message * hello);
+                                const struct GNUNET_HELLO_Message * hello,
+                                const char * err_msg);
 
 
 /**
index 42adcaad8a0e7f70df45285cb1ea1b40c24d4bbd..48cbb6038d95794e62ef82299ca9352b9a7ae026 100644 (file)
@@ -157,14 +157,15 @@ print_address (void *cls,
 static void
 print_peer_info (void *cls,
                  const struct GNUNET_PeerIdentity *peer,
-                 const struct GNUNET_HELLO_Message *hello)
+                 const struct GNUNET_HELLO_Message *hello,
+                 const char * err_msg)
 {
   struct GNUNET_CRYPTO_HashAsciiEncoded enc;
   struct PrintContext *pc;
 
   if (peer == NULL)    
     {
-      fprintf (stderr,_("Error in communication with PEERINFO service\n"));
+      if (err_msg != NULL) fprintf (stderr,_("Error in communication with PEERINFO service\n"));
       GNUNET_PEERINFO_disconnect (peerinfo);
       return;    
     }
index c2e091f00524fb75ec8d608a0e460c085cb01500..a3a396d90154f32427635026641e43c803f8ce42 100644 (file)
@@ -385,15 +385,16 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
   ic->h->in_receive = GNUNET_NO;
   if (msg == NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  _("Failed to receive response from `%s' service.\n"),
-                  "PEERINFO");
+         char * err_msg;
+         GNUNET_asprintf(&err_msg,_("Failed to receive response from `%s' service.\n"),"PEERINFO");
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,err_msg);
       reconnect (ic->h);
       trigger_transmit (ic->h);
       if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
        GNUNET_SCHEDULER_cancel (ic->timeout_task);
       if (ic->callback != NULL)
-       ic->callback (ic->callback_cls, NULL, NULL);
+         ic->callback (ic->callback_cls, NULL, NULL, err_msg);
+      GNUNET_free (err_msg);
       GNUNET_free (ic);
       return;
     }
@@ -408,7 +409,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
       if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
        GNUNET_SCHEDULER_cancel (ic->timeout_task);
       if (ic->callback != NULL)
-       ic->callback (ic->callback_cls, NULL, NULL);
+       ic->callback (ic->callback_cls, NULL, NULL, NULL);
       GNUNET_free (ic);
       return;
     }
@@ -416,13 +417,17 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
   if ((ms < sizeof (struct InfoMessage)) ||
       (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO))
     {
+         char * err_msg;
+         GNUNET_asprintf(&err_msg,_("Received invalid message from `%s' service.\n"),"PEERINFO");
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,err_msg);
       GNUNET_break (0);
       reconnect (ic->h);
       trigger_transmit (ic->h);
       if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
        GNUNET_SCHEDULER_cancel (ic->timeout_task);
       if (ic->callback != NULL)
-       ic->callback (ic->callback_cls, NULL, NULL);
+       ic->callback (ic->callback_cls, NULL, NULL, err_msg);
+      GNUNET_free (err_msg);
       GNUNET_free (ic);
       return;
     }
@@ -434,14 +439,17 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
       hello = (const struct GNUNET_HELLO_Message *) &im[1];
       if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
         {
-         GNUNET_break (0);
+      char * err_msg;
+      GNUNET_asprintf(&err_msg,_("Received invalid message from `%s' service.\n"),"PEERINFO");
+      GNUNET_break (0);
          reconnect (ic->h);
          trigger_transmit (ic->h);
          if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
            GNUNET_SCHEDULER_cancel (ic->timeout_task);
          if (ic->callback != NULL)
-           ic->callback (ic->callback_cls, NULL, NULL);
+           ic->callback (ic->callback_cls, NULL, NULL, err_msg);
          GNUNET_free (ic);
+         GNUNET_free (err_msg);
           return;
         }
     }
@@ -455,7 +463,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 #endif
   ic->h->in_receive = GNUNET_YES;
   if (ic->callback != NULL)
-    ic->callback (ic->callback_cls, &im->peer, hello);
+    ic->callback (ic->callback_cls, &im->peer, hello, NULL);
   GNUNET_CLIENT_receive (ic->h->client,
                          &peerinfo_handler,
                          ic,
@@ -478,10 +486,9 @@ iterator_start_receive (void *cls,
 
   if (GNUNET_OK != transmit_success)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 _("Failed to transmit iteration request to `%s' service (%d).\n"),
-                 "PEERINFO",
-                 transmit_success);
+      char * err_msg;
+      GNUNET_asprintf(&err_msg,_("Failed to transmit iteration request to `%s' service (%d).\n"),"PEERINFO",transmit_success);
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,err_msg);
       if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
        {
          GNUNET_SCHEDULER_cancel (ic->timeout_task);
@@ -490,7 +497,8 @@ iterator_start_receive (void *cls,
       reconnect (ic->h);
       trigger_transmit (ic->h);
       if (ic->callback != NULL)
-       ic->callback (ic->callback_cls, NULL, NULL);
+       ic->callback (ic->callback_cls, NULL, NULL, err_msg);
+      GNUNET_free (err_msg);
       GNUNET_free (ic);
       return;
     }  
@@ -520,19 +528,21 @@ signal_timeout (void *cls,
                const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_PEERINFO_IteratorContext *ic = cls;
+  char * err_msg;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
-             _("Timeout transmitting iteration request to `%s' service.\n"),
+  GNUNET_asprintf(&err_msg,_("Timeout transmitting iteration request to `%s' service.\n"),
              "PEERINFO");
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,err_msg);
   ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
   if (! ic->in_receive)
     GNUNET_CONTAINER_DLL_remove (ic->h->tq_head,
                                 ic->h->tq_tail,
                                 ic->tqe);
   reconnect (ic->h);
-  ic->callback (ic->callback_cls, NULL, NULL);
+  ic->callback (ic->callback_cls, NULL, NULL,err_msg);
   ic->callback = NULL;
   GNUNET_free_non_null (ic->tqe);
+  GNUNET_free (err_msg);
   GNUNET_free (ic);
 }
 
index 25f2b9d5e0b962542c0bd4a8fafe08b7641283c7..ab0d13f66616c067ea1363f7e15689da585a0e35 100644 (file)
@@ -138,7 +138,7 @@ process_notification (void *cls,
              "Received information about peer `%s' from peerinfo database\n",
              GNUNET_i2s (&im->peer));
 #endif
-  nc->callback (nc->callback_cls, &im->peer, hello);
+  nc->callback (nc->callback_cls, &im->peer, hello, NULL);
   receive_notifications (nc);
 }
 
index 1de0f46151fb926b3caf5d7365ac7964bd9cd5fb..4cae7ab60d02b396128c860a3dd5e51990de2c4e 100755 (executable)
@@ -107,7 +107,8 @@ add_peer (size_t i)
 static void
 process (void *cls,
          const struct GNUNET_PeerIdentity *peer,
-         const struct GNUNET_HELLO_Message *hello)
+         const struct GNUNET_HELLO_Message *hello,
+         const char * err_msg)
 {
   if (peer == NULL)
     {
index 4030820d7180a28309aa1d57e34a95c1b616a6cd..460a3764d7037568c733159d7b59976a660836b8 100644 (file)
@@ -100,11 +100,18 @@ add_peer ()
 static void
 process (void *cls,
          const struct GNUNET_PeerIdentity *peer,
-         const struct GNUNET_HELLO_Message *hello)
+         const struct GNUNET_HELLO_Message *hello,
+         const char * err_msg)
 {
   int *ok = cls;
   unsigned int agc;
 
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service\n"));
+  }
+
   if (peer == NULL)
     {
       ic = NULL;
index 4bbe4e19a286bc965c31f37df0548e7cf46f80ad..7cab16d15a7b89de04d0c4a09a6ba0bcada03de3 100644 (file)
@@ -924,14 +924,23 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
  * @param cls closure (not used)
  * @param peer potential peer to connect to
  * @param hello HELLO for this peer (or NULL)
+ * @param err_msg NULL if successful, otherwise contains error message
  */
 static void
 process_peer (void *cls,
              const struct GNUNET_PeerIdentity *peer,
-             const struct GNUNET_HELLO_Message *hello)
+             const struct GNUNET_HELLO_Message *hello,
+          const char *err_msg)
 {
   struct Peer *pos;
 
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service\n"));
+         /* return; */
+  }
+
   GNUNET_assert (peer != NULL);
   if (0 == memcmp (&my_identity,
                    peer, sizeof (struct GNUNET_PeerIdentity)))
index b2e0c2ee44d6deb2fb6ce6a185d10eda46d37a5b..43001dbc77476a92c8d76fd5f72182b8a8a047d0 100644 (file)
@@ -2710,15 +2710,23 @@ add_to_foreign_address_list (void *cls,
  * @param cls closure ('struct NeighbourList*')
  * @param peer id of the peer, NULL for last call
  * @param h hello message for the peer (can be NULL)
+ * @param err_msg NULL if successful, otherwise contains error message
  */
 static void
 add_hello_for_peer (void *cls,
                    const struct GNUNET_PeerIdentity *peer,
-                   const struct GNUNET_HELLO_Message *h)
+                   const struct GNUNET_HELLO_Message *h,
+                   const char *err_msg)
 {
   struct NeighbourList *n = cls;
 
-  if (peer == NULL)
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service\n"));
+       /* return; */
+  }
+  if ((peer == NULL))
     {
       GNUNET_STATISTICS_update (stats,
                                 gettext_noop ("# outstanding peerinfo iterate requests"),
@@ -4029,11 +4037,13 @@ run_validation (void *cls,
  * @param cls closure
  * @param peer id of the peer, NULL for last call
  * @param h hello message for the peer (can be NULL)
+ * @param err_msg NULL if successful, otherwise contains error message
  */
 static void
 check_hello_validated (void *cls,
                        const struct GNUNET_PeerIdentity *peer,
-                       const struct GNUNET_HELLO_Message *h)
+                       const struct GNUNET_HELLO_Message *h,
+                       const char *err_msg)
 {
   struct CheckHelloValidatedContext *chvc = cls;
   struct GNUNET_HELLO_Message *plain_hello;
@@ -4041,6 +4051,13 @@ check_hello_validated (void *cls,
   struct GNUNET_PeerIdentity target;
   struct NeighbourList *n;
 
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Error in communication with PEERINFO service\n"));
+        /* return; */
+  }
+
   if (peer == NULL)
     {
       GNUNET_STATISTICS_update (stats,