From 829a8f6820744897bbfa7d8ab25aeafcd9ba26d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Fri, 29 Apr 2011 13:13:50 +0000 Subject: [PATCH] better hashing for the connection-tracking in the -exit --- src/vpn/gnunet-daemon-exit.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index 9ffa6886d..7ef9e6a36 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c @@ -194,6 +194,19 @@ collect_connections(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { GNUNET_free(state); } +static void +hash_redirect_info(GNUNET_HashCode* hash, struct redirect_info* u_i, size_t addrlen) +{ + + /* the gnunet hashmap only uses the first 32bit of the hash + * + * build the hash out of the last two bytes of the address and the 2 bytes of + * the port + */ + memcpy(&hash, &u_i->pt, sizeof(u_i->pt)); + memcpy(((unsigned char*)&hash)+2, u_i->addr+(addrlen-2), 2); +} + /** * cls is the pointer to a GNUNET_MessageHeader that is * followed by the service-descriptor and the udp-packet that should be sent; @@ -233,9 +246,8 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen, u_i.pt = udp->dpt; /* get tunnel and service-descriptor from this */ - /* FIXME better hashing */ GNUNET_HashCode hash; - GNUNET_CRYPTO_hash (&u_i, sizeof (struct redirect_info), &hash); + hash_redirect_info(&hash, &u_i, addrlen); struct redirect_state *state = GNUNET_CONTAINER_multihashmap_get (udp_connections, &hash); @@ -317,10 +329,10 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, memcpy (&u_i.addr, dadr, addrlen); u_i.pt = tcp->dpt; - /* FIXME better hashing */ /* get tunnel and service-descriptor from this */ GNUNET_HashCode hash; - GNUNET_CRYPTO_hash (&u_i, sizeof (struct redirect_info), &hash); + hash_redirect_info(&hash, &u_i, addrlen); + struct redirect_state *state = GNUNET_CONTAINER_multihashmap_get (tcp_connections, &hash); @@ -880,9 +892,7 @@ receive_tcp_service (void *cls, break; } - /* FIXME better hashing */ - GNUNET_CRYPTO_hash (&state->redirect_info, sizeof (struct redirect_info), - &state->hash); + hash_redirect_info(&state->hash, &state->redirect_info, serv->version == 4 ? 4 : 16); if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash)) @@ -984,9 +994,7 @@ receive_udp_service (void *cls, break; } - /* FIXME better hashing */ - GNUNET_CRYPTO_hash (&state->redirect_info, sizeof (struct redirect_info), - &state->hash); + hash_redirect_info(&state->hash, &state->redirect_info, serv->version == 4 ? 4 : 16); if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash)) -- 2.25.1