aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-09-16 18:26:17 +0000
committerChristian Grothoff <christian@grothoff.org>2011-09-16 18:26:17 +0000
commit1becdac841c29bd431ae86bfe8c9ddc5a724f125 (patch)
tree089e7ea0b10b863f0d2fb4995704c3fd1a9f3ab1 /src/dht/gnunet-service-dht.c
parent0e0b717e63900a72227232cb0d3ff296c63881d2 (diff)
downloadgnunet-1becdac841c29bd431ae86bfe8c9ddc5a724f125.tar.gz
gnunet-1becdac841c29bd431ae86bfe8c9ddc5a724f125.zip
fixing 1770, towards fixing 1769
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c93
1 files changed, 59 insertions, 34 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 53487f4be..d1d054a8b 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -483,7 +483,7 @@ struct DHTRouteSource
483 struct DHTRouteSource *prev; 483 struct DHTRouteSource *prev;
484 484
485 /** 485 /**
486 * UID of the request 486 * UID of the request, 0 if from another peer.
487 */ 487 */
488 uint64_t uid; 488 uint64_t uid;
489 489
@@ -623,7 +623,7 @@ struct RecentRequest
623 GNUNET_HashCode key; 623 GNUNET_HashCode key;
624 624
625 /** 625 /**
626 * Unique identifier for this request. 626 * Unique identifier for this request, 0 if from another peer.
627 */ 627 */
628 uint64_t uid; 628 uint64_t uid;
629 629
@@ -1072,12 +1072,16 @@ forward_result_message (const struct GNUNET_MessageHeader *msg,
1072 } 1072 }
1073 result_message->options = htonl (msg_ctx->msg_options); 1073 result_message->options = htonl (msg_ctx->msg_options);
1074 result_message->hop_count = htonl (msg_ctx->hop_count + 1); 1074 result_message->hop_count = htonl (msg_ctx->hop_count + 1);
1075#if HAVE_REPLY_BLOOMFILTER
1075 GNUNET_assert (GNUNET_OK == 1076 GNUNET_assert (GNUNET_OK ==
1076 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom, 1077 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom,
1077 result_message-> 1078 result_message->
1078 bloomfilter, 1079 bloomfilter,
1079 DHT_BLOOM_SIZE)); 1080 DHT_BLOOM_SIZE));
1081#endif
1082#if HAVE_UID_FOR_TESTING
1080 result_message->unique_id = GNUNET_htonll (msg_ctx->unique_id); 1083 result_message->unique_id = GNUNET_htonll (msg_ctx->unique_id);
1084#endif
1081 memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 1085 memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
1082 /* Copy the enc_msg, then the path history as well! */ 1086 /* Copy the enc_msg, then the path history as well! */
1083 memcpy (&result_message[1], msg, ntohs (msg->size)); 1087 memcpy (&result_message[1], msg, ntohs (msg->size));
@@ -1595,7 +1599,9 @@ forward_message (const struct GNUNET_MessageHeader *msg, struct PeerInfo *peer,
1595 route_message->hop_count = htonl (msg_ctx->hop_count + 1); 1599 route_message->hop_count = htonl (msg_ctx->hop_count + 1);
1596 route_message->network_size = htonl (msg_ctx->network_size); 1600 route_message->network_size = htonl (msg_ctx->network_size);
1597 route_message->desired_replication_level = htonl (msg_ctx->replication); 1601 route_message->desired_replication_level = htonl (msg_ctx->replication);
1602#if HAVE_UID_FOR_TESTING
1598 route_message->unique_id = GNUNET_htonll (msg_ctx->unique_id); 1603 route_message->unique_id = GNUNET_htonll (msg_ctx->unique_id);
1604#endif
1599 if (msg_ctx->bloom != NULL) 1605 if (msg_ctx->bloom != NULL)
1600 GNUNET_assert (GNUNET_OK == 1606 GNUNET_assert (GNUNET_OK ==
1601 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom, 1607 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom,
@@ -1921,11 +1927,13 @@ route_result_message (struct GNUNET_MessageHeader *msg,
1921 NULL); 1927 NULL);
1922 } 1928 }
1923#endif 1929#endif
1930#if HAVE_REPLY_BLOOMFILTER
1924 if (msg_ctx->bloom != NULL) 1931 if (msg_ctx->bloom != NULL)
1925 { 1932 {
1926 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom); 1933 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
1927 msg_ctx->bloom = NULL; 1934 msg_ctx->bloom = NULL;
1928 } 1935 }
1936#endif
1929 return 0; 1937 return 0;
1930 } 1938 }
1931 1939
@@ -1992,7 +2000,7 @@ route_result_message (struct GNUNET_MessageHeader *msg,
1992 pos = pos->next; 2000 pos = pos->next;
1993 continue; 2001 continue;
1994 } 2002 }
1995 2003#if HAVE_REPLY_BLOOMFILTER
1996 if (msg_ctx->bloom == NULL) 2004 if (msg_ctx->bloom == NULL)
1997 msg_ctx->bloom = 2005 msg_ctx->bloom =
1998 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, 2006 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
@@ -2002,48 +2010,44 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2002 if ((GNUNET_NO == 2010 if ((GNUNET_NO ==
2003 GNUNET_CONTAINER_bloomfilter_test (msg_ctx->bloom, 2011 GNUNET_CONTAINER_bloomfilter_test (msg_ctx->bloom,
2004 &peer_info->id.hashPubKey))) 2012 &peer_info->id.hashPubKey)))
2005 { 2013 {{{
2014#endif
2006#if DEBUG_DHT 2015#if DEBUG_DHT
2007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2008 "`%s:%s': Forwarding response key %s uid %llu to peer %s\n", 2017 "`%s:%s': Forwarding response key %s uid %llu to peer %s\n",
2009 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 2018 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
2010 msg_ctx->unique_id, GNUNET_i2s (&peer_info->id)); 2019 msg_ctx->unique_id, GNUNET_i2s (&peer_info->id));
2011#endif 2020#endif
2012#if DEBUG_DHT_ROUTING 2021#if DEBUG_DHT_ROUTING
2013 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2022 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2014 {
2015 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT,
2016 msg_ctx->hop_count, GNUNET_NO,
2017 &my_identity, &msg_ctx->key,
2018 &msg_ctx->peer, &pos->source);
2019 }
2020#endif
2021 forward_result_message (msg, peer_info, msg_ctx);
2022 /* Try removing forward entries after sending once, only allows ONE response per request */
2023 if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
2024 {
2025 GNUNET_SCHEDULER_cancel (pos->delete_task);
2026 pos->delete_task =
2027 GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos);
2028 }
2029 }
2030 else
2031 { 2023 {
2032#if DEBUG_DHT 2024 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT,
2033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2025 msg_ctx->hop_count, GNUNET_NO,
2034 "`%s:%s': NOT Forwarding response (bloom match) key %s uid %llu to peer %s\n", 2026 &my_identity, &msg_ctx->key,
2035 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 2027 &msg_ctx->peer, &pos->source);
2036 msg_ctx->unique_id, GNUNET_i2s (&peer_info->id)); 2028 }
2037#endif 2029#endif
2030 forward_result_message (msg, peer_info, msg_ctx);
2031 /* Try removing forward entries after sending once, only allows ONE response per request */
2032 if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
2033 {
2034 GNUNET_SCHEDULER_cancel (pos->delete_task);
2035 pos->delete_task =
2036 GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos);
2038 } 2037 }
2038#if HAVE_REPLY_BLOOMFILTER
2039 }}}
2040#endif
2039 } 2041 }
2040 pos = pos->next; 2042 pos = pos->next;
2041 } 2043 }
2044#if HAVE_REPLY_BLOOMFILTER
2042 if (msg_ctx->bloom != NULL) 2045 if (msg_ctx->bloom != NULL)
2043 { 2046 {
2044 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom); 2047 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
2045 msg_ctx->bloom = NULL; 2048 msg_ctx->bloom = NULL;
2046 } 2049 }
2050#endif
2047 return 0; 2051 return 0;
2048} 2052}
2049 2053
@@ -4057,7 +4061,12 @@ handle_dht_p2p_route_request (void *cls, const struct GNUNET_PeerIdentity *peer,
4057 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4061 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4058 { 4062 {
4059 /** Log routes that die due to high load! */ 4063 /** Log routes that die due to high load! */
4060 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id), 4064 dhtlog_handle->insert_route (NULL,
4065#if HAVE_UID_FOR_TESTING
4066 GNUNET_ntohll (incoming->unique_id),
4067#else
4068 0,
4069#endif
4061 DHTLOG_ROUTE, ntohl (incoming->hop_count), 4070 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4062 GNUNET_SYSERR, &my_identity, &incoming->key, 4071 GNUNET_SYSERR, &my_identity, &incoming->key,
4063 peer, NULL); 4072 peer, NULL);
@@ -4076,7 +4085,12 @@ handle_dht_p2p_route_request (void *cls, const struct GNUNET_PeerIdentity *peer,
4076 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4085 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4077 { 4086 {
4078 /** Log routes that die due to high load! */ 4087 /** Log routes that die due to high load! */
4079 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id), 4088 dhtlog_handle->insert_route (NULL,
4089#if HAVE_UID_FOR_TESTING
4090 GNUNET_ntohll (incoming->unique_id),
4091#else
4092 0,
4093#endif
4080 DHTLOG_ROUTE, ntohl (incoming->hop_count), 4094 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4081 GNUNET_SYSERR, &my_identity, &incoming->key, 4095 GNUNET_SYSERR, &my_identity, &incoming->key,
4082 peer, NULL); 4096 peer, NULL);
@@ -4092,7 +4106,9 @@ handle_dht_p2p_route_request (void *cls, const struct GNUNET_PeerIdentity *peer,
4092 msg_ctx->hop_count = ntohl (incoming->hop_count); 4106 msg_ctx->hop_count = ntohl (incoming->hop_count);
4093 memcpy (&msg_ctx->key, &incoming->key, sizeof (GNUNET_HashCode)); 4107 memcpy (&msg_ctx->key, &incoming->key, sizeof (GNUNET_HashCode));
4094 msg_ctx->replication = ntohl (incoming->desired_replication_level); 4108 msg_ctx->replication = ntohl (incoming->desired_replication_level);
4109#if HAVE_UID_FOR_TESTING
4095 msg_ctx->unique_id = GNUNET_ntohll (incoming->unique_id); 4110 msg_ctx->unique_id = GNUNET_ntohll (incoming->unique_id);
4111#endif
4096 msg_ctx->msg_options = ntohl (incoming->options); 4112 msg_ctx->msg_options = ntohl (incoming->options);
4097 if (GNUNET_DHT_RO_RECORD_ROUTE == 4113 if (GNUNET_DHT_RO_RECORD_ROUTE ==
4098 (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) 4114 (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
@@ -4174,7 +4190,12 @@ handle_dht_p2p_route_result (void *cls, const struct GNUNET_PeerIdentity *peer,
4174 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4190 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4175 { 4191 {
4176 /** Log routes that die due to high load! */ 4192 /** Log routes that die due to high load! */
4177 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id), 4193 dhtlog_handle->insert_route (NULL,
4194#if HAVE_UID_FOR_TESTING
4195 GNUNET_ntohll (incoming->unique_id),
4196#else
4197 0,
4198#endif
4178 DHTLOG_ROUTE, ntohl (incoming->hop_count), 4199 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4179 GNUNET_SYSERR, &my_identity, &incoming->key, 4200 GNUNET_SYSERR, &my_identity, &incoming->key,
4180 peer, NULL); 4201 peer, NULL);
@@ -4185,7 +4206,9 @@ handle_dht_p2p_route_result (void *cls, const struct GNUNET_PeerIdentity *peer,
4185 4206
4186 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 4207 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
4187 memcpy (&msg_ctx.key, &incoming->key, sizeof (GNUNET_HashCode)); 4208 memcpy (&msg_ctx.key, &incoming->key, sizeof (GNUNET_HashCode));
4209#if HAVE_UID_FOR_TESTING
4188 msg_ctx.unique_id = GNUNET_ntohll (incoming->unique_id); 4210 msg_ctx.unique_id = GNUNET_ntohll (incoming->unique_id);
4211#endif
4189 msg_ctx.msg_options = ntohl (incoming->options); 4212 msg_ctx.msg_options = ntohl (incoming->options);
4190 msg_ctx.hop_count = ntohl (incoming->hop_count); 4213 msg_ctx.hop_count = ntohl (incoming->hop_count);
4191 msg_ctx.peer = *peer; 4214 msg_ctx.peer = *peer;
@@ -4229,10 +4252,12 @@ handle_dht_p2p_route_result (void *cls, const struct GNUNET_PeerIdentity *peer,
4229 } 4252 }
4230#endif 4253#endif
4231 } 4254 }
4255#if HAVE_REPLY_BLOOMFILTER
4232 msg_ctx.bloom = 4256 msg_ctx.bloom =
4233 GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE, 4257 GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE,
4234 DHT_BLOOM_K); 4258 DHT_BLOOM_K);
4235 GNUNET_assert (msg_ctx.bloom != NULL); 4259 GNUNET_assert (msg_ctx.bloom != NULL);
4260#endif
4236 route_result_message (enc_msg, &msg_ctx); 4261 route_result_message (enc_msg, &msg_ctx);
4237 return GNUNET_YES; 4262 return GNUNET_YES;
4238} 4263}