- refactor
authorBart Polot <bart@net.in.tum.de>
Mon, 10 Mar 2014 09:52:43 +0000 (09:52 +0000)
committerBart Polot <bart@net.in.tum.de>
Mon, 10 Mar 2014 09:52:43 +0000 (09:52 +0000)
src/mesh/gnunet-service-mesh_connection.c
src/mesh/mesh.h
src/mesh/mesh_common.c

index f1dc2dfc90743d88290a9c1311b26470014bf721..e6c38f4679bc9a9392dca9fd34c4477e606f4301 100644 (file)
@@ -415,14 +415,7 @@ fc_init (struct MeshFlowControl *fc)
 static struct MeshConnection *
 connection_get (const struct GNUNET_MeshHash *cid)
 {
-  struct GNUNET_HashCode hash;
-  struct GNUNET_MeshHash *aux;
-
-  memcpy (&hash, cid, sizeof (cid));
-  aux = (struct GNUNET_MeshHash *) &hash;
-  memset (&aux[1], 0, sizeof (hash) - sizeof (*cid));
-
-  return GNUNET_CONTAINER_multihashmap_get (connections, &hash);
+  return GNUNET_CONTAINER_multihashmap_get (connections, GM_h2hc (cid));
 }
 
 
index bea5899239e04049d4492a6f45b78effc6a01397..87af414e6940d259d395116d70dd0b19f86762a6 100644 (file)
@@ -321,6 +321,17 @@ uint32_t
 GM_min_pid (uint32_t a, uint32_t b);
 
 
+/**
+ * Convert a 256 bit MeshHash into a 512 HashCode to use in GNUNET_h2s,
+ * multihashmap, and other HashCode-based functions.
+ *
+ * @param id A 256 bit hash to expand.
+ *
+ * @return A HashCode containing the original 256 bit hash right-padded with 0.
+ */
+struct GNUNET_HashCode *
+GM_h2hc (const struct GNUNET_MeshHash *id);
+
 /**
  * Convert a message type into a string to help debug
  * Generated with:
index eb8ad764bfaf6ba09f1c375d859efc57e9a705da..bd6c0949c0844697eaaad3e20bde81e606aa8b16 100644 (file)
@@ -77,6 +77,16 @@ GM_min_pid (uint32_t a, uint32_t b)
 }
 
 
+struct GNUNET_HashCode *
+GM_h2hc (const struct GNUNET_MeshHash *id)
+{
+  static struct GNUNET_HashCode hc;
+  memcpy (&hc, id, sizeof (*id));
+
+  return &hc;
+}
+
+
 #if !defined(GNUNET_CULL_LOGGING)
 const char *
 GM_m2s (uint16_t m)