diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-02-02 11:54:21 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-02-02 11:54:21 +0000 |
commit | 0aa66524bd2ef85668ba8de14792eb39480b59ba (patch) | |
tree | c84691a6fad3cbdbcc963e6194ba2b49971963a3 /src/dht/gnunet-service-dht.c | |
parent | 3b3eb36e3a01c7046fe4c9a3c4bb7834d83442d6 (diff) | |
download | gnunet-0aa66524bd2ef85668ba8de14792eb39480b59ba.tar.gz gnunet-0aa66524bd2ef85668ba8de14792eb39480b59ba.zip |
path tracking commit, hopefully a fix for dht_api connect bug, needs tested
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r-- | src/dht/gnunet-service-dht.c | 173 |
1 files changed, 144 insertions, 29 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index b8f7e4732..2f5be7691 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -1096,6 +1096,10 @@ forward_result_message (const struct GNUNET_MessageHeader *msg, | |||
1096 | size_t msize; | 1096 | size_t msize; |
1097 | size_t psize; | 1097 | size_t psize; |
1098 | char *path_start; | 1098 | char *path_start; |
1099 | char *path_offset; | ||
1100 | #if DEBUG_PATH | ||
1101 | unsigned int i; | ||
1102 | #endif | ||
1099 | 1103 | ||
1100 | increment_stats (STAT_RESULT_FORWARDS); | 1104 | increment_stats (STAT_RESULT_FORWARDS); |
1101 | msize = | 1105 | msize = |
@@ -1118,6 +1122,13 @@ forward_result_message (const struct GNUNET_MessageHeader *msg, | |||
1118 | /* Offset by the size of the enc_msg */ | 1122 | /* Offset by the size of the enc_msg */ |
1119 | path_start += ntohs (msg->size); | 1123 | path_start += ntohs (msg->size); |
1120 | memcpy(path_start, msg_ctx->path_history, msg_ctx->path_history_len * (sizeof(struct GNUNET_PeerIdentity))); | 1124 | memcpy(path_start, msg_ctx->path_history, msg_ctx->path_history_len * (sizeof(struct GNUNET_PeerIdentity))); |
1125 | #if DEBUG_PATH | ||
1126 | for (i = 0; i < msg_ctx->path_history_len; i++) | ||
1127 | { | ||
1128 | path_offset = &msg_ctx->path_history[i * sizeof(struct GNUNET_PeerIdentity)]; | ||
1129 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(forward_result) Key %s Found peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); | ||
1130 | } | ||
1131 | #endif | ||
1121 | } | 1132 | } |
1122 | result_message->options = htonl (msg_ctx->msg_options); | 1133 | result_message->options = htonl (msg_ctx->msg_options); |
1123 | result_message->hop_count = htonl (msg_ctx->hop_count + 1); | 1134 | result_message->hop_count = htonl (msg_ctx->hop_count + 1); |
@@ -1128,7 +1139,13 @@ forward_result_message (const struct GNUNET_MessageHeader *msg, | |||
1128 | DHT_BLOOM_SIZE)); | 1139 | DHT_BLOOM_SIZE)); |
1129 | result_message->unique_id = GNUNET_htonll (msg_ctx->unique_id); | 1140 | result_message->unique_id = GNUNET_htonll (msg_ctx->unique_id); |
1130 | memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); | 1141 | memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); |
1142 | /* Copy the enc_msg, then the path history as well! */ | ||
1131 | memcpy (&result_message[1], msg, ntohs (msg->size)); | 1143 | memcpy (&result_message[1], msg, ntohs (msg->size)); |
1144 | path_offset = (char *)&result_message[1]; | ||
1145 | path_offset += ntohs (msg->size); | ||
1146 | /* If we have path history, copy it to the end of the whole thing */ | ||
1147 | if (msg_ctx->path_history_len > 0) | ||
1148 | memcpy(path_offset, msg_ctx->path_history, msg_ctx->path_history_len * (sizeof(struct GNUNET_PeerIdentity))); | ||
1132 | #if DEBUG_DHT > 1 | 1149 | #if DEBUG_DHT > 1 |
1133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1134 | "%s:%s Adding pending message size %d for peer %s\n", | 1151 | "%s:%s Adding pending message size %d for peer %s\n", |
@@ -1774,7 +1791,7 @@ forward_message (const struct GNUNET_MessageHeader *msg, | |||
1774 | memcpy (&route_message[1], msg, ntohs (msg->size)); | 1791 | memcpy (&route_message[1], msg, ntohs (msg->size)); |
1775 | if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) | 1792 | if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) |
1776 | { | 1793 | { |
1777 | route_message->route_path_length = htonl(msg_ctx->path_history_len); | 1794 | route_message->outgoing_path_length = htonl(msg_ctx->path_history_len); |
1778 | /* Set pointer to start of enc_msg */ | 1795 | /* Set pointer to start of enc_msg */ |
1779 | route_path = (char *)&route_message[1]; | 1796 | route_path = (char *)&route_message[1]; |
1780 | /* Offset to the end of the enc_msg */ | 1797 | /* Offset to the end of the enc_msg */ |
@@ -1992,18 +2009,23 @@ add_pending_message (struct ClientList *client, | |||
1992 | static void | 2009 | static void |
1993 | send_reply_to_client (struct ClientList *client, | 2010 | send_reply_to_client (struct ClientList *client, |
1994 | const struct GNUNET_MessageHeader *message, | 2011 | const struct GNUNET_MessageHeader *message, |
1995 | unsigned long long uid, const GNUNET_HashCode * key) | 2012 | struct DHT_MessageContext *msg_ctx) |
1996 | { | 2013 | { |
1997 | struct GNUNET_DHT_RouteResultMessage *reply; | 2014 | struct GNUNET_DHT_RouteResultMessage *reply; |
1998 | struct PendingMessage *pending_message; | 2015 | struct PendingMessage *pending_message; |
1999 | uint16_t msize; | 2016 | uint16_t msize; |
2000 | size_t tsize; | 2017 | size_t tsize; |
2018 | char *reply_offset; | ||
2019 | #if DEBUG_PATH | ||
2020 | char *path_offset; | ||
2021 | unsigned int i; | ||
2022 | #endif | ||
2001 | #if DEBUG_DHT | 2023 | #if DEBUG_DHT |
2002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2024 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2003 | "`%s:%s': Sending reply to client.\n", my_short_id, "DHT"); | 2025 | "`%s:%s': Sending reply to client.\n", my_short_id, "DHT"); |
2004 | #endif | 2026 | #endif |
2005 | msize = ntohs (message->size); | 2027 | msize = ntohs (message->size); |
2006 | tsize = sizeof (struct GNUNET_DHT_RouteResultMessage) + msize; | 2028 | tsize = sizeof (struct GNUNET_DHT_RouteResultMessage) + msize + (msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); |
2007 | if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 2029 | if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
2008 | { | 2030 | { |
2009 | GNUNET_break_op (0); | 2031 | GNUNET_break_op (0); |
@@ -2014,11 +2036,24 @@ send_reply_to_client (struct ClientList *client, | |||
2014 | reply = (struct GNUNET_DHT_RouteResultMessage *) &pending_message[1]; | 2036 | reply = (struct GNUNET_DHT_RouteResultMessage *) &pending_message[1]; |
2015 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT); | 2037 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT); |
2016 | reply->header.size = htons (tsize); | 2038 | reply->header.size = htons (tsize); |
2017 | reply->put_path_length = htons (0); /* FIXME: implement */ | 2039 | reply->outgoing_path_length = htonl(msg_ctx->path_history_len); |
2018 | reply->get_path_length = htons (0); /* FIXME: implement */ | 2040 | reply->unique_id = GNUNET_htonll (msg_ctx->unique_id); |
2019 | reply->unique_id = GNUNET_htonll (uid); | 2041 | memcpy (&reply->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); |
2020 | reply->key = *key; | 2042 | reply_offset = (char *)&reply[1]; |
2021 | memcpy (&reply[1], message, msize); | 2043 | memcpy (&reply[1], message, msize); |
2044 | if (msg_ctx->path_history_len > 0) | ||
2045 | { | ||
2046 | reply_offset += msize; | ||
2047 | memcpy(reply_offset, msg_ctx->path_history, msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); | ||
2048 | } | ||
2049 | #if DEBUG_PATH | ||
2050 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Returning message with outgoing path length %d\n", msg_ctx->path_history_len); | ||
2051 | for (i = 0; i < msg_ctx->path_history_len; i++) | ||
2052 | { | ||
2053 | path_offset = &msg_ctx->path_history[i * sizeof(struct GNUNET_PeerIdentity)]; | ||
2054 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found peer %d:%s\n", i, GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); | ||
2055 | } | ||
2056 | #endif | ||
2022 | add_pending_message (client, pending_message); | 2057 | add_pending_message (client, pending_message); |
2023 | } | 2058 | } |
2024 | 2059 | ||
@@ -2105,6 +2140,8 @@ route_result_message (struct GNUNET_MessageHeader *msg, | |||
2105 | struct DHTRouteSource *pos; | 2140 | struct DHTRouteSource *pos; |
2106 | struct PeerInfo *peer_info; | 2141 | struct PeerInfo *peer_info; |
2107 | const struct GNUNET_MessageHeader *hello_msg; | 2142 | const struct GNUNET_MessageHeader *hello_msg; |
2143 | unsigned int i; | ||
2144 | char *path_offset; | ||
2108 | 2145 | ||
2109 | increment_stats (STAT_RESULTS); | 2146 | increment_stats (STAT_RESULTS); |
2110 | /** | 2147 | /** |
@@ -2221,8 +2258,12 @@ route_result_message (struct GNUNET_MessageHeader *msg, | |||
2221 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) | 2258 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) |
2222 | increment_stats (STAT_GET_REPLY); | 2259 | increment_stats (STAT_GET_REPLY); |
2223 | 2260 | ||
2224 | send_reply_to_client (pos->client, msg, | 2261 | for (i = 0; i < msg_ctx->path_history_len; i++) |
2225 | msg_ctx->unique_id, &msg_ctx->key); | 2262 | { |
2263 | path_offset = &msg_ctx->path_history[i * sizeof(struct GNUNET_PeerIdentity)]; | ||
2264 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(before client) Key %s Found peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); | ||
2265 | } | ||
2266 | send_reply_to_client (pos->client, msg, msg_ctx); | ||
2226 | } | 2267 | } |
2227 | else /* Send to peer */ | 2268 | else /* Send to peer */ |
2228 | { | 2269 | { |
@@ -2313,6 +2354,12 @@ datacache_get_iterator (void *cls, | |||
2313 | struct DHT_MessageContext *new_msg_ctx; | 2354 | struct DHT_MessageContext *new_msg_ctx; |
2314 | struct GNUNET_DHT_GetResultMessage *get_result; | 2355 | struct GNUNET_DHT_GetResultMessage *get_result; |
2315 | enum GNUNET_BLOCK_EvaluationResult eval; | 2356 | enum GNUNET_BLOCK_EvaluationResult eval; |
2357 | const struct DHTPutEntry *put_entry; | ||
2358 | int get_size; | ||
2359 | char *path_offset; | ||
2360 | #if DEBUG_PATH | ||
2361 | unsigned int i; | ||
2362 | #endif | ||
2316 | 2363 | ||
2317 | #if DEBUG_DHT | 2364 | #if DEBUG_DHT |
2318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2326,6 +2373,24 @@ datacache_get_iterator (void *cls, | |||
2326 | msg_ctx->reply_bf_mutator, | 2373 | msg_ctx->reply_bf_mutator, |
2327 | msg_ctx->xquery, | 2374 | msg_ctx->xquery, |
2328 | msg_ctx->xquery_size, data, size); | 2375 | msg_ctx->xquery_size, data, size); |
2376 | |||
2377 | put_entry = (const struct DHTPutEntry *)data; | ||
2378 | |||
2379 | if (size != sizeof(struct DHTPutEntry) + | ||
2380 | put_entry->data_size + | ||
2381 | (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity))) | ||
2382 | { | ||
2383 | GNUNET_log( | ||
2384 | GNUNET_ERROR_TYPE_WARNING, | ||
2385 | "Path + data size doesn't add up for data inserted into datacache!\nData size %d, path length %d, expected %d, got %d\n", | ||
2386 | put_entry->data_size, put_entry->path_length, | ||
2387 | sizeof(struct DHTPutEntry) + put_entry->data_size | ||
2388 | + (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity)), | ||
2389 | size); | ||
2390 | msg_ctx->do_forward = GNUNET_NO; | ||
2391 | return GNUNET_OK; | ||
2392 | } | ||
2393 | |||
2329 | switch (eval) | 2394 | switch (eval) |
2330 | { | 2395 | { |
2331 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 2396 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
@@ -2339,15 +2404,32 @@ datacache_get_iterator (void *cls, | |||
2339 | new_msg_ctx->path_history_len = msg_ctx->path_history_len; | 2404 | new_msg_ctx->path_history_len = msg_ctx->path_history_len; |
2340 | /* Assign to previous msg_ctx path history, caller should free after our return */ | 2405 | /* Assign to previous msg_ctx path history, caller should free after our return */ |
2341 | new_msg_ctx->path_history = msg_ctx->path_history; | 2406 | new_msg_ctx->path_history = msg_ctx->path_history; |
2407 | #if DEBUG_PATH | ||
2408 | for (i = 0; i < new_msg_ctx->path_history_len; i++) | ||
2409 | { | ||
2410 | path_offset = &new_msg_ctx->path_history[i * sizeof(struct GNUNET_PeerIdentity)]; | ||
2411 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(get_iterator) Key %s Found peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); | ||
2412 | } | ||
2413 | #endif | ||
2342 | } | 2414 | } |
2343 | get_result = | 2415 | |
2344 | GNUNET_malloc (sizeof (struct GNUNET_DHT_GetResultMessage) + size); | 2416 | get_size = sizeof (struct GNUNET_DHT_GetResultMessage) + put_entry->data_size + (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity)); |
2417 | get_result = GNUNET_malloc (get_size); | ||
2345 | get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT); | 2418 | get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT); |
2346 | get_result->header.size = | 2419 | get_result->header.size = htons (get_size); |
2347 | htons (sizeof (struct GNUNET_DHT_GetResultMessage) + size); | ||
2348 | get_result->expiration = GNUNET_TIME_absolute_hton (exp); | 2420 | get_result->expiration = GNUNET_TIME_absolute_hton (exp); |
2349 | get_result->type = htons (type); | 2421 | get_result->type = htons (type); |
2350 | memcpy (&get_result[1], data, size); | 2422 | get_result->put_path_length = htons(put_entry->path_length); |
2423 | path_offset = (char *)&put_entry[1]; | ||
2424 | path_offset += put_entry->data_size; | ||
2425 | #if DEBUG_PATH | ||
2426 | for (i = 0; i < put_entry->path_length; i++) | ||
2427 | { | ||
2428 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(get_iterator PUT path) Key %s Found peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct GNUNET_PeerIdentity *)&path_offset[i * sizeof(struct GNUNET_PeerIdentity)])); | ||
2429 | } | ||
2430 | #endif | ||
2431 | /* Copy the actual data and the path_history to the end of the get result */ | ||
2432 | memcpy (&get_result[1], &put_entry[1], put_entry->data_size + (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity))); | ||
2351 | new_msg_ctx->peer = &my_identity; | 2433 | new_msg_ctx->peer = &my_identity; |
2352 | new_msg_ctx->bloom = | 2434 | new_msg_ctx->bloom = |
2353 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); | 2435 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); |
@@ -2367,7 +2449,7 @@ datacache_get_iterator (void *cls, | |||
2367 | break; | 2449 | break; |
2368 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 2450 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
2369 | #if DEBUG_DHT | 2451 | #if DEBUG_DHT |
2370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2452 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2371 | "`%s:%s': Invalid request error\n", my_short_id, "DHT"); | 2453 | "`%s:%s': Invalid request error\n", my_short_id, "DHT"); |
2372 | #endif | 2454 | #endif |
2373 | break; | 2455 | break; |
@@ -2385,7 +2467,7 @@ datacache_get_iterator (void *cls, | |||
2385 | break; | 2467 | break; |
2386 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 2468 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
2387 | #if DEBUG_DHT | 2469 | #if DEBUG_DHT |
2388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2470 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2389 | "`%s:%s': Unsupported block type (%u) in response!\n", | 2471 | "`%s:%s': Unsupported block type (%u) in response!\n", |
2390 | my_short_id, "DHT", type); | 2472 | my_short_id, "DHT", type); |
2391 | #endif | 2473 | #endif |
@@ -2781,6 +2863,9 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, | |||
2781 | struct DHT_MessageContext *msg_ctx) | 2863 | struct DHT_MessageContext *msg_ctx) |
2782 | { | 2864 | { |
2783 | const struct GNUNET_DHT_PutMessage *put_msg; | 2865 | const struct GNUNET_DHT_PutMessage *put_msg; |
2866 | struct DHTPutEntry *put_entry; | ||
2867 | unsigned int put_size; | ||
2868 | char *path_offset; | ||
2784 | enum GNUNET_BLOCK_Type put_type; | 2869 | enum GNUNET_BLOCK_Type put_type; |
2785 | size_t data_size; | 2870 | size_t data_size; |
2786 | int ret; | 2871 | int ret; |
@@ -2789,7 +2874,6 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, | |||
2789 | 2874 | ||
2790 | GNUNET_assert (ntohs (msg->size) >= sizeof (struct GNUNET_DHT_PutMessage)); | 2875 | GNUNET_assert (ntohs (msg->size) >= sizeof (struct GNUNET_DHT_PutMessage)); |
2791 | 2876 | ||
2792 | |||
2793 | put_msg = (const struct GNUNET_DHT_PutMessage *) msg; | 2877 | put_msg = (const struct GNUNET_DHT_PutMessage *) msg; |
2794 | put_type = (enum GNUNET_BLOCK_Type) ntohl (put_msg->type); | 2878 | put_type = (enum GNUNET_BLOCK_Type) ntohl (put_msg->type); |
2795 | #if HAVE_MALICIOUS | 2879 | #if HAVE_MALICIOUS |
@@ -2897,8 +2981,22 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, | |||
2897 | increment_stats (STAT_PUTS_INSERTED); | 2981 | increment_stats (STAT_PUTS_INSERTED); |
2898 | if (datacache != NULL) | 2982 | if (datacache != NULL) |
2899 | { | 2983 | { |
2900 | ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, data_size, | 2984 | /* Put size is actual data size plus struct overhead plus path length (if any) */ |
2901 | (char *) &put_msg[1], put_type, | 2985 | put_size = data_size + sizeof(struct DHTPutEntry) + (msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); |
2986 | put_entry = GNUNET_malloc(put_size); | ||
2987 | put_entry->data_size = data_size; | ||
2988 | put_entry->path_length = msg_ctx->path_history_len; | ||
2989 | /* Copy data to end of put entry */ | ||
2990 | memcpy(&put_entry[1], &put_msg[1], data_size); | ||
2991 | if (msg_ctx->path_history_len > 0) | ||
2992 | { | ||
2993 | /* Copy path after data */ | ||
2994 | path_offset = (char *)&put_entry[1]; | ||
2995 | path_offset += data_size; | ||
2996 | memcpy(path_offset, msg_ctx->path_history, msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); | ||
2997 | } | ||
2998 | ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size, | ||
2999 | (char *) put_entry, put_type, | ||
2902 | GNUNET_TIME_absolute_ntoh | 3000 | GNUNET_TIME_absolute_ntoh |
2903 | (put_msg->expiration)); | 3001 | (put_msg->expiration)); |
2904 | 3002 | ||
@@ -4776,7 +4874,7 @@ handle_dht_p2p_route_request (void *cls, | |||
4776 | msg_ctx->msg_options = ntohl (incoming->options); | 4874 | msg_ctx->msg_options = ntohl (incoming->options); |
4777 | if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) | 4875 | if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) |
4778 | { | 4876 | { |
4779 | path_size = ntohl(incoming->route_path_length) * sizeof(struct GNUNET_PeerIdentity); | 4877 | path_size = ntohl(incoming->outgoing_path_length) * sizeof(struct GNUNET_PeerIdentity); |
4780 | GNUNET_assert(ntohs(message->size) == | 4878 | GNUNET_assert(ntohs(message->size) == |
4781 | (sizeof(struct GNUNET_DHT_P2PRouteMessage) + | 4879 | (sizeof(struct GNUNET_DHT_P2PRouteMessage) + |
4782 | ntohs(enc_msg->size) + | 4880 | ntohs(enc_msg->size) + |
@@ -4786,7 +4884,7 @@ handle_dht_p2p_route_request (void *cls, | |||
4786 | msg_ctx->path_history = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity) + path_size); | 4884 | msg_ctx->path_history = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity) + path_size); |
4787 | memcpy(msg_ctx->path_history, route_path, path_size); | 4885 | memcpy(msg_ctx->path_history, route_path, path_size); |
4788 | memcpy(&msg_ctx->path_history[path_size], &my_identity, sizeof(struct GNUNET_PeerIdentity)); | 4886 | memcpy(&msg_ctx->path_history[path_size], &my_identity, sizeof(struct GNUNET_PeerIdentity)); |
4789 | msg_ctx->path_history_len = ntohl(incoming->route_path_length) + 1; | 4887 | msg_ctx->path_history_len = ntohl(incoming->outgoing_path_length) + 1; |
4790 | } | 4888 | } |
4791 | msg_ctx->network_size = ntohl (incoming->network_size); | 4889 | msg_ctx->network_size = ntohl (incoming->network_size); |
4792 | msg_ctx->peer = peer; | 4890 | msg_ctx->peer = peer; |
@@ -4829,7 +4927,10 @@ handle_dht_p2p_route_result (void *cls, | |||
4829 | struct GNUNET_MessageHeader *enc_msg = | 4927 | struct GNUNET_MessageHeader *enc_msg = |
4830 | (struct GNUNET_MessageHeader *) &incoming[1]; | 4928 | (struct GNUNET_MessageHeader *) &incoming[1]; |
4831 | struct DHT_MessageContext msg_ctx; | 4929 | struct DHT_MessageContext msg_ctx; |
4832 | 4930 | #if DEBUG_PATH | |
4931 | char *path_offset; | ||
4932 | unsigned int i; | ||
4933 | #endif | ||
4833 | if (ntohs (enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1) | 4934 | if (ntohs (enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1) |
4834 | { | 4935 | { |
4835 | GNUNET_break_op (0); | 4936 | GNUNET_break_op (0); |
@@ -4871,16 +4972,22 @@ handle_dht_p2p_route_result (void *cls, | |||
4871 | if (ntohs(message->size) - sizeof(struct GNUNET_DHT_P2PRouteResultMessage) - ntohs(enc_msg->size) != | 4972 | if (ntohs(message->size) - sizeof(struct GNUNET_DHT_P2PRouteResultMessage) - ntohs(enc_msg->size) != |
4872 | ntohl (incoming->outgoing_path_length) * sizeof(struct GNUNET_PeerIdentity)) | 4973 | ntohl (incoming->outgoing_path_length) * sizeof(struct GNUNET_PeerIdentity)) |
4873 | { | 4974 | { |
4874 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Return message indicated a path was included, but sizes are wrong!\nTotal message size %d, enc_msg size %d, left over %d, expected %d\n", | 4975 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Return message indicated a path was included, but sizes are wrong!\nTotal message size %d, enc_msg size %d, left over %d, expected %d\n", |
4875 | ntohs(message->size), ntohs(enc_msg->size), | 4976 | ntohs(message->size), ntohs(enc_msg->size), |
4876 | ntohs(message->size) - sizeof(struct GNUNET_DHT_P2PRouteResultMessage) - ntohs(enc_msg->size), | 4977 | ntohs(message->size) - sizeof(struct GNUNET_DHT_P2PRouteResultMessage) - ntohs(enc_msg->size), |
4877 | ntohl(incoming->outgoing_path_length) * sizeof(struct GNUNET_PeerIdentity)); | 4978 | ntohl(incoming->outgoing_path_length) * sizeof(struct GNUNET_PeerIdentity)); |
4878 | return GNUNET_NO; | 4979 | return GNUNET_NO; |
4879 | } | 4980 | } |
4880 | |||
4881 | msg_ctx.path_history = (char *)&incoming[1]; | 4981 | msg_ctx.path_history = (char *)&incoming[1]; |
4882 | msg_ctx.path_history += ntohs(enc_msg->size); | 4982 | msg_ctx.path_history += ntohs(enc_msg->size); |
4883 | msg_ctx.path_history_len = ntohl (incoming->outgoing_path_length); | 4983 | msg_ctx.path_history_len = ntohl (incoming->outgoing_path_length); |
4984 | #if DEBUG_PATH | ||
4985 | for (i = 0; i < msg_ctx.path_history_len; i++) | ||
4986 | { | ||
4987 | path_offset = &msg_ctx.path_history[i * sizeof(struct GNUNET_PeerIdentity)]; | ||
4988 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(handle_p2p_route_result) Key %s Found peer %d:%s\n", GNUNET_h2s(&msg_ctx.key), i, GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); | ||
4989 | } | ||
4990 | #endif | ||
4884 | } | 4991 | } |
4885 | route_result_message (enc_msg, &msg_ctx); | 4992 | route_result_message (enc_msg, &msg_ctx); |
4886 | return GNUNET_YES; | 4993 | return GNUNET_YES; |
@@ -5057,7 +5164,7 @@ handle_core_connect (void *cls, | |||
5057 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 5164 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
5058 | { | 5165 | { |
5059 | struct PeerInfo *ret; | 5166 | struct PeerInfo *ret; |
5060 | 5167 | struct DHTPutEntry *put_entry; | |
5061 | /* Check for connect to self message */ | 5168 | /* Check for connect to self message */ |
5062 | if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) | 5169 | if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) |
5063 | return; | 5170 | return; |
@@ -5079,10 +5186,18 @@ handle_core_connect (void *cls, | |||
5079 | } | 5186 | } |
5080 | 5187 | ||
5081 | if (datacache != NULL) | 5188 | if (datacache != NULL) |
5082 | GNUNET_DATACACHE_put (datacache, &peer->hashPubKey, | 5189 | { |
5083 | sizeof (struct GNUNET_PeerIdentity), | 5190 | put_entry = GNUNET_malloc(sizeof(struct DHTPutEntry) + sizeof (struct GNUNET_PeerIdentity)); |
5084 | (const char *) peer, GNUNET_BLOCK_TYPE_DHT_HELLO, | 5191 | put_entry->path_length = 0; |
5085 | GNUNET_TIME_absolute_get_forever ()); | 5192 | put_entry->data_size = sizeof (struct GNUNET_PeerIdentity); |
5193 | memcpy(&put_entry[1], peer, sizeof (struct GNUNET_PeerIdentity)); | ||
5194 | GNUNET_DATACACHE_put (datacache, &peer->hashPubKey, | ||
5195 | sizeof(struct DHTPutEntry) + sizeof (struct GNUNET_PeerIdentity), | ||
5196 | (char *)put_entry, GNUNET_BLOCK_TYPE_DHT_HELLO, | ||
5197 | GNUNET_TIME_absolute_get_forever ()); | ||
5198 | } | ||
5199 | else | ||
5200 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DHT has no connection to datacache!\n"); | ||
5086 | ret = try_add_peer (peer, find_current_bucket (&peer->hashPubKey), atsi); | 5201 | ret = try_add_peer (peer, find_current_bucket (&peer->hashPubKey), atsi); |
5087 | if (ret != NULL) | 5202 | if (ret != NULL) |
5088 | { | 5203 | { |