-style fix
[oweals/gnunet.git] / src / core / gnunet-service-core_kx.c
index 48e70eec50b843d19651348c8dfb7fa38aaaccc0..d1990f8f4f5203edb4fd6aa1fa066c895ae3dad5 100644 (file)
@@ -553,8 +553,8 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx,
  * @param iv initialization vector to use
  * @param in ciphertext
  * @param out plaintext
- * @param size size of in/out
- * @return GNUNET_OK on success
+ * @param size size of @a in / @a out
+ * @return #GNUNET_OK on success
  */
 static int
 do_decrypt (struct GSC_KeyExchangeInfo *kx,
@@ -667,7 +667,7 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
   GNUNET_STATISTICS_update (GSC_stats,
                             gettext_noop ("# key exchanges initiated"), 1,
                             GNUNET_NO);
-  kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo));
+  kx = GNUNET_new (struct GSC_KeyExchangeInfo);
   kx->peer = *pid;
   kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
   GNUNET_CONTAINER_DLL_insert (kx_head,
@@ -676,15 +676,22 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
   GNUNET_CRYPTO_hash (pid, sizeof (struct GNUNET_PeerIdentity), &h1);
   GNUNET_CRYPTO_hash (&GSC_my_identity, sizeof (struct GNUNET_PeerIdentity), &h2);
 
+  kx->status = KX_STATE_KEY_SENT;
   if (0 < GNUNET_CRYPTO_hash_cmp (&h1,
                                  &h2))
   {
     /* peer with "lower" identity starts KX, otherwise we typically end up
        with both peers starting the exchange and transmit the 'set key'
        message twice */
-    kx->status = KX_STATE_KEY_SENT;
     send_key (kx);
   }
+  else
+  {
+    /* peer with "higher" identity starts a delayed  KX, if the "lower" peer
+     * does not start a KX since he sees no reasons to do so  */
+    kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+          &set_key_retry_task, kx);
+  }
   return kx;
 }