aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-05-10 17:20:46 +0000
committerBart Polot <bart@net.in.tum.de>2013-05-10 17:20:46 +0000
commit018cab1259cd62ef3377203520e777fbdfdab646 (patch)
treead2d7f2cf1183b2834bccaa6fd16b95f6f63254e /src
parent008d9420203f95633403ac677433bd4502836149 (diff)
downloadgnunet-018cab1259cd62ef3377203520e777fbdfdab646.tar.gz
gnunet-018cab1259cd62ef3377203520e777fbdfdab646.zip
- Change hash to speed up 16/32 bit lookups
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh-new.c14
-rw-r--r--src/mesh/mesh2.h12
-rw-r--r--src/mesh/mesh_common.c31
3 files changed, 26 insertions, 31 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c
index df078b542..8c98d4a34 100644
--- a/src/mesh/gnunet-service-mesh-new.c
+++ b/src/mesh/gnunet-service-mesh-new.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2001-2012 Christian Grothoff (and other contributing authors) 3 (C) 2001-2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -511,7 +511,8 @@ struct MeshClient
511 struct GNUNET_SERVER_Client *handle; 511 struct GNUNET_SERVER_Client *handle;
512 512
513 /** 513 /**
514 * Messages that this client has declared interest in 514 * Messages that this client has declared interest in.
515 * Indexed by a GMC_hash32 (type), contains *Client.
515 */ 516 */
516 struct GNUNET_CONTAINER_MultiHashMap *types; 517 struct GNUNET_CONTAINER_MultiHashMap *types;
517 518
@@ -1005,10 +1006,9 @@ client_get (struct GNUNET_SERVER_Client *client)
1005 * 1006 *
1006 * @return GNUNET_YES or GNUNET_NO, depending on subscription status 1007 * @return GNUNET_YES or GNUNET_NO, depending on subscription status
1007 * 1008 *
1008 * FIXME: use of crypto_hash slows it down 1009 * A real hash function alone takes 8-10us out of the ~55us for the whole
1009 * The hash function alone takes 8-10us out of the ~55us for the whole
1010 * process of retransmitting the message from one local client to another. 1010 * process of retransmitting the message from one local client to another.
1011 * Find faster implementation! 1011 * GMC_hash32 aim to imporve this speed.
1012 */ 1012 */
1013static int 1013static int
1014client_is_subscribed (uint16_t message_type, struct MeshClient *c) 1014client_is_subscribed (uint16_t message_type, struct MeshClient *c)
@@ -1018,7 +1018,7 @@ client_is_subscribed (uint16_t message_type, struct MeshClient *c)
1018 if (NULL == c->types) 1018 if (NULL == c->types)
1019 return GNUNET_NO; 1019 return GNUNET_NO;
1020 1020
1021 GNUNET_CRYPTO_hash (&message_type, sizeof (uint16_t), &hc); 1021 GMC_hash32 ((uint32_t) message_type, &hc);
1022 return GNUNET_CONTAINER_multihashmap_contains (c->types, &hc); 1022 return GNUNET_CONTAINER_multihashmap_contains (c->types, &hc);
1023} 1023}
1024 1024
@@ -4654,7 +4654,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
4654 { 4654 {
4655 u16 = ntohs (t[i]); 4655 u16 = ntohs (t[i]);
4656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " msg type: %u\n", u16); 4656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " msg type: %u\n", u16);
4657 GNUNET_CRYPTO_hash (&u16, sizeof (u16), &hc); // FIXME pseudo hash 4657 GMC_hash32 ((uint32_t) u16, &hc);
4658 4658
4659 /* store in clients hashmap */ 4659 /* store in clients hashmap */
4660 GNUNET_CONTAINER_multihashmap_put (c->types, &hc, c, 4660 GNUNET_CONTAINER_multihashmap_put (c->types, &hc, c,
diff --git a/src/mesh/mesh2.h b/src/mesh/mesh2.h
index eaf386fd8..4b55c3c4e 100644
--- a/src/mesh/mesh2.h
+++ b/src/mesh/mesh2.h
@@ -319,6 +319,18 @@ GMC_min_pid (uint32_t a, uint32_t b);
319 319
320 320
321/** 321/**
322 * Expand a 32 bit value (message type) into a hash for a MultiHashMap (fast).
323 * WARNING: do not use for anything other than MultiHashMap!
324 * does not alter anything other than bits used by idx_of !
325 *
326 * @param i 32 bit integer value.
327 * @param h Hash code to fill.
328 */
329void
330GMC_hash32 (uint32_t i, struct GNUNET_HashCode *h);
331
332
333/**
322 * Convert a message type into a string to help debug 334 * Convert a message type into a string to help debug
323 * Generated with: 335 * Generated with:
324 * FIND: "#define ([^ ]+)[ ]*([0-9]+)" 336 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
diff --git a/src/mesh/mesh_common.c b/src/mesh/mesh_common.c
index c9af35c22..b4fc40672 100644
--- a/src/mesh/mesh_common.c
+++ b/src/mesh/mesh_common.c
@@ -27,14 +27,6 @@
27#include "mesh.h" 27#include "mesh.h"
28 28
29 29
30/**
31 * Check if one pid is bigger than other, accounting for overflow.
32 *
33 * @param bigger Argument that should be bigger.
34 * @param smaller Argument that should be smaller.
35 *
36 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
37 */
38int 30int
39GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller) 31GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller)
40{ 32{
@@ -42,14 +34,7 @@ GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller)
42 (bigger > smaller && GNUNET_NO == PID_OVERFLOW(bigger, smaller))); 34 (bigger > smaller && GNUNET_NO == PID_OVERFLOW(bigger, smaller)));
43} 35}
44 36
45/** 37
46 * Get the higher ACK value out of two values, taking in account overflow.
47 *
48 * @param a First ACK value.
49 * @param b Second ACK value.
50 *
51 * @return Highest ACK value from the two.
52 */
53uint32_t 38uint32_t
54GMC_max_pid (uint32_t a, uint32_t b) 39GMC_max_pid (uint32_t a, uint32_t b)
55{ 40{
@@ -59,14 +44,6 @@ GMC_max_pid (uint32_t a, uint32_t b)
59} 44}
60 45
61 46
62/**
63 * Get the lower ACK value out of two values, taking in account overflow.
64 *
65 * @param a First ACK value.
66 * @param b Second ACK value.
67 *
68 * @return Lowest ACK value from the two.
69 */
70uint32_t 47uint32_t
71GMC_min_pid (uint32_t a, uint32_t b) 48GMC_min_pid (uint32_t a, uint32_t b)
72{ 49{
@@ -75,6 +52,12 @@ GMC_min_pid (uint32_t a, uint32_t b)
75 return a; 52 return a;
76} 53}
77 54
55void
56GMC_hash32 (uint32_t i, struct GNUNET_HashCode *h)
57{
58 *(unsigned int *) h = i;
59}
60
78 61
79#if !defined(GNUNET_CULL_LOGGING) 62#if !defined(GNUNET_CULL_LOGGING)
80const char * 63const char *