From 8c699617fdbb02dfcd3a95a53d0087b5eb3a0653 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Mon, 10 Mar 2014 09:52:43 +0000 Subject: [PATCH] - refactor --- src/mesh/gnunet-service-mesh_connection.c | 9 +-------- src/mesh/mesh.h | 11 +++++++++++ src/mesh/mesh_common.c | 10 ++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index f1dc2dfc9..e6c38f467 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -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)); } diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index bea589923..87af414e6 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -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: diff --git a/src/mesh/mesh_common.c b/src/mesh/mesh_common.c index eb8ad764b..bd6c0949c 100644 --- a/src/mesh/mesh_common.c +++ b/src/mesh/mesh_common.c @@ -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) -- 2.25.1