-track hello offer handle while it is active
authorChristian Grothoff <christian@grothoff.org>
Sun, 18 Oct 2015 13:53:16 +0000 (13:53 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 18 Oct 2015 13:53:16 +0000 (13:53 +0000)
src/cadet/gnunet-service-cadet_dht.c
src/cadet/gnunet-service-cadet_peer.c

index 2b9fdb0a35552e3d2f454d160c13dcd8c43b2cb1..fadf45e13fcbf9b319853bdb3edbb670feefaeea 100644 (file)
@@ -154,9 +154,9 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
  * @param exp when will this value expire
  * @param key key of the result
  * @param get_path path of the get request
- * @param get_path_length lenght of get_path
+ * @param get_path_length lenght of @a get_path
  * @param put_path path of the put request
- * @param put_path_length length of the put_path
+ * @param put_path_length length of the @a put_path
  * @param type type of the result
  * @param size number of bytes in data
  * @param data pointer to the result data
@@ -185,11 +185,15 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
   }
 
   s = path_2s (p);
-  LOG (GNUNET_ERROR_TYPE_INFO, "Got path from DHT: %s\n", s);
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Got path from DHT: %s\n",
+       s);
   GNUNET_free_non_null (s);
 
   peer = GCP_get_short (p->peers[p->length - 1], GNUNET_YES);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Got HELLO for %s\n", GCP_2s (peer));
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Got HELLO for %s\n",
+       GCP_2s (peer));
   h->callback (h->cls, p);
   path_destroy (p);
   hello = (struct GNUNET_HELLO_Message *) data;
index dfeeebd3b79a10e0c951ab342490d2b1b4df7f11..4d5c09260c56963392ba7093f079b85f16e650d3 100644 (file)
@@ -189,6 +189,11 @@ struct CadetPeer
    * Hello message.
    */
   struct GNUNET_HELLO_Message* hello;
+
+  /**
+   * Handle to us offering the HELLO to the transport.
+   */
+  struct GNUNET_TRANSPORT_OfferHelloHandle *hello_offer;
 };
 
 
@@ -742,7 +747,9 @@ peer_destroy (struct CadetPeer *peer)
   while (NULL != p)
   {
     nextp = p->next;
-    GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p);
+    GNUNET_CONTAINER_DLL_remove (peer->path_head,
+                                 peer->path_tail,
+                                 p);
     path_destroy (p);
     p = nextp;
   }
@@ -755,6 +762,11 @@ peer_destroy (struct CadetPeer *peer)
   }
   if (NULL != peer->core_transmit)
     GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit);
+  if (NULL != peer->hello_offer)
+  {
+    GNUNET_TRANSPORT_offer_hello_cancel (peer->hello_offer);
+    peer->hello_offer = NULL;
+  }
   GNUNET_free_non_null (peer->hello);
   GNUNET_free (peer);
   return GNUNET_OK;
@@ -1906,10 +1918,12 @@ GCP_get_short (const GNUNET_PEER_Id peer, int create)
  * @param tc TaskContext.
  */
 static void
-try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_connect (void *cls,
+             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct CadetPeer *peer = cls;
 
+  peer->hello_offer = NULL;
   if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
     return;
 
@@ -1934,8 +1948,9 @@ GCP_connect (struct CadetPeer *peer)
   int rerun_search;
 
   GCC_check_connections ();
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "peer_connect towards %s\n", GCP_2s (peer));
-
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "peer_connect towards %s\n",
+       GCP_2s (peer));
   /* If we have a current hello, try to connect using it. */
   GCP_try_connect (peer);
 
@@ -2539,10 +2554,10 @@ GCP_try_connect (struct CadetPeer *peer)
     return;
 
   mh = GNUNET_HELLO_get_header (hello);
-  GNUNET_TRANSPORT_offer_hello (transport_handle,
-                                mh,
-                                &try_connect,
-                                peer);
+  peer->hello_offer = GNUNET_TRANSPORT_offer_hello (transport_handle,
+                                                    mh,
+                                                    &try_connect,
+                                                    peer);
   GCC_check_connections ();
 }