- fix disconnect task scheduling
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_tunnel.c
index 6888cc862b45d4462e44068c8de54a83a81f6056..f475e2d0c3b9f338f6657de009496486c989985b 100644 (file)
@@ -729,11 +729,12 @@ queue_data (struct MeshTunnel3 *t, const struct GNUNET_MessageHeader *msg)
  */
 static void
 t_hmac (struct MeshTunnel3 *t, const void *plaintext, size_t size, uint32_t iv,
-        int outgoing, struct GNUNET_HashCode *hmac)
+        int outgoing, struct GNUNET_MeshHash *hmac)
 {
   struct GNUNET_CRYPTO_AuthKey auth_key;
   static const char ctx[] = "mesh authentication key";
   struct GNUNET_CRYPTO_SymmetricSessionKey *key;
+  struct GNUNET_HashCode hash;
 
   key = outgoing ? &t->e_key : &t->d_key;
   GNUNET_CRYPTO_hmac_derive_key (&auth_key, key,
@@ -741,7 +742,8 @@ t_hmac (struct MeshTunnel3 *t, const void *plaintext, size_t size, uint32_t iv,
                                  key, sizeof (*key),
                                  ctx, sizeof (ctx),
                                  NULL);
-  GNUNET_CRYPTO_hmac (&auth_key, plaintext, size, hmac);
+  GNUNET_CRYPTO_hmac (&auth_key, plaintext, size, &hash);
+  memcpy (hmac, &hash, sizeof (*hmac));
 }
 
 
@@ -802,7 +804,7 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message,
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED);
   msg->iv = iv;
   GNUNET_assert (t_encrypt (t, &msg[1], message, size, iv) == size);
-  t_hmac (t, message, size, iv, GNUNET_YES, &msg->hmac);
+  t_hmac (t, &msg[1], size, iv, GNUNET_YES, &msg->hmac);
   msg->header.size = htons (sizeof (struct GNUNET_MESH_Encrypted) + size);
 
   if (NULL == c)
@@ -1585,6 +1587,7 @@ handle_decrypted (struct MeshTunnel3 *t,
   {
     case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
       /* Do nothing, connection aleady got updated. */
+      GNUNET_STATISTICS_update (stats, "# keepalives received", 1, GNUNET_NO);
       break;
 
     case GNUNET_MESSAGE_TYPE_MESH_DATA:
@@ -1648,14 +1651,14 @@ GMT_handle_encrypted (struct MeshTunnel3 *t,
   char cbuf [payload_size];
   struct GNUNET_MessageHeader *msgh;
   unsigned int off;
-  struct GNUNET_HashCode hmac;
+  struct GNUNET_MeshHash hmac;
 
   decrypted_size = t_decrypt (t, cbuf, &msg[1], payload_size, msg->iv);
-  t_hmac (t, cbuf, payload_size, msg->iv, GNUNET_NO, &hmac);
-  if (0 != memcmp (&hmac, &msg->hmac, sizeof (struct GNUNET_HashCode)))
+  t_hmac (t, &msg[1], payload_size, msg->iv, GNUNET_NO, &hmac);
+  if (0 != memcmp (&hmac, &msg->hmac, sizeof (hmac)))
   {
     /* checksum failed */
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Failed checksum validation for a message on tunnel `%s'\n",
                 GMT_2s (t));
     GNUNET_STATISTICS_update (stats, "# wrong HMAC", 1, GNUNET_NO);
@@ -2178,7 +2181,7 @@ struct MeshConnection *
 GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p)
 {
   struct MeshConnection *c;
-  struct GNUNET_HashCode cid;
+  struct GNUNET_MeshHash cid;
   unsigned int own_pos;
 
   if (NULL == t || NULL == p)
@@ -2204,7 +2207,7 @@ GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p)
     return NULL;
   }
 
-  GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, &cid);
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof (cid));
   c = GMC_new (&cid, t, p, own_pos);
   if (NULL == c)
   {