diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-04-29 13:13:50 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-04-29 13:13:50 +0000 |
commit | 829a8f6820744897bbfa7d8ab25aeafcd9ba26d5 (patch) | |
tree | 501fafad71af530164dc6f99ab88b55658592f30 /src/vpn | |
parent | d01130162e011a122118203144a3ff2b057d87e8 (diff) | |
download | gnunet-829a8f6820744897bbfa7d8ab25aeafcd9ba26d5.tar.gz gnunet-829a8f6820744897bbfa7d8ab25aeafcd9ba26d5.zip |
better hashing for the connection-tracking in the -exit
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-daemon-exit.c | 28 |
1 files 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) { | |||
194 | GNUNET_free(state); | 194 | GNUNET_free(state); |
195 | } | 195 | } |
196 | 196 | ||
197 | static void | ||
198 | hash_redirect_info(GNUNET_HashCode* hash, struct redirect_info* u_i, size_t addrlen) | ||
199 | { | ||
200 | |||
201 | /* the gnunet hashmap only uses the first 32bit of the hash | ||
202 | * | ||
203 | * build the hash out of the last two bytes of the address and the 2 bytes of | ||
204 | * the port | ||
205 | */ | ||
206 | memcpy(&hash, &u_i->pt, sizeof(u_i->pt)); | ||
207 | memcpy(((unsigned char*)&hash)+2, u_i->addr+(addrlen-2), 2); | ||
208 | } | ||
209 | |||
197 | /** | 210 | /** |
198 | * cls is the pointer to a GNUNET_MessageHeader that is | 211 | * cls is the pointer to a GNUNET_MessageHeader that is |
199 | * followed by the service-descriptor and the udp-packet that should be sent; | 212 | * 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, | |||
233 | u_i.pt = udp->dpt; | 246 | u_i.pt = udp->dpt; |
234 | 247 | ||
235 | /* get tunnel and service-descriptor from this */ | 248 | /* get tunnel and service-descriptor from this */ |
236 | /* FIXME better hashing */ | ||
237 | GNUNET_HashCode hash; | 249 | GNUNET_HashCode hash; |
238 | GNUNET_CRYPTO_hash (&u_i, sizeof (struct redirect_info), &hash); | 250 | hash_redirect_info(&hash, &u_i, addrlen); |
239 | 251 | ||
240 | struct redirect_state *state = | 252 | struct redirect_state *state = |
241 | GNUNET_CONTAINER_multihashmap_get (udp_connections, &hash); | 253 | GNUNET_CONTAINER_multihashmap_get (udp_connections, &hash); |
@@ -317,10 +329,10 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
317 | memcpy (&u_i.addr, dadr, addrlen); | 329 | memcpy (&u_i.addr, dadr, addrlen); |
318 | u_i.pt = tcp->dpt; | 330 | u_i.pt = tcp->dpt; |
319 | 331 | ||
320 | /* FIXME better hashing */ | ||
321 | /* get tunnel and service-descriptor from this */ | 332 | /* get tunnel and service-descriptor from this */ |
322 | GNUNET_HashCode hash; | 333 | GNUNET_HashCode hash; |
323 | GNUNET_CRYPTO_hash (&u_i, sizeof (struct redirect_info), &hash); | 334 | hash_redirect_info(&hash, &u_i, addrlen); |
335 | |||
324 | struct redirect_state *state = | 336 | struct redirect_state *state = |
325 | GNUNET_CONTAINER_multihashmap_get (tcp_connections, &hash); | 337 | GNUNET_CONTAINER_multihashmap_get (tcp_connections, &hash); |
326 | 338 | ||
@@ -880,9 +892,7 @@ receive_tcp_service (void *cls, | |||
880 | break; | 892 | break; |
881 | } | 893 | } |
882 | 894 | ||
883 | /* FIXME better hashing */ | 895 | hash_redirect_info(&state->hash, &state->redirect_info, serv->version == 4 ? 4 : 16); |
884 | GNUNET_CRYPTO_hash (&state->redirect_info, sizeof (struct redirect_info), | ||
885 | &state->hash); | ||
886 | 896 | ||
887 | if (GNUNET_NO == | 897 | if (GNUNET_NO == |
888 | GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash)) | 898 | GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash)) |
@@ -984,9 +994,7 @@ receive_udp_service (void *cls, | |||
984 | break; | 994 | break; |
985 | } | 995 | } |
986 | 996 | ||
987 | /* FIXME better hashing */ | 997 | hash_redirect_info(&state->hash, &state->redirect_info, serv->version == 4 ? 4 : 16); |
988 | GNUNET_CRYPTO_hash (&state->redirect_info, sizeof (struct redirect_info), | ||
989 | &state->hash); | ||
990 | 998 | ||
991 | if (GNUNET_NO == | 999 | if (GNUNET_NO == |
992 | GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash)) | 1000 | GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash)) |