diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-10-03 21:37:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-10-03 21:37:15 +0000 |
commit | bd271d337e6e406862e9784051b30045d8d649a6 (patch) | |
tree | 96e5d3e1417f17f635039abdb68cccdf5917a276 | |
parent | d27974ef39701bdd6c2dfc6a8b6f9e06239db330 (diff) | |
download | gnunet-bd271d337e6e406862e9784051b30045d8d649a6.tar.gz gnunet-bd271d337e6e406862e9784051b30045d8d649a6.zip |
making test_dht_api work
-rw-r--r-- | src/dht/dht_api.c | 31 | ||||
-rw-r--r-- | src/dht/dht_api_get_put.c | 14 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 54 | ||||
-rw-r--r-- | src/dht/test_dht_api.c | 149 | ||||
-rw-r--r-- | src/dht/test_dht_api_data.conf | 2 |
5 files changed, 130 insertions, 120 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index c89a92dd5..5abc228a3 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -231,6 +231,8 @@ try_connect (struct GNUNET_DHT_Handle *handle) | |||
231 | _("Failed to connect to the DHT service!\n")); | 231 | _("Failed to connect to the DHT service!\n")); |
232 | return GNUNET_NO; | 232 | return GNUNET_NO; |
233 | } | 233 | } |
234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
235 | "Starting to process replies from DHT\n"); | ||
234 | GNUNET_CLIENT_receive (handle->client, | 236 | GNUNET_CLIENT_receive (handle->client, |
235 | &service_message_handler, | 237 | &service_message_handler, |
236 | handle, | 238 | handle, |
@@ -373,6 +375,9 @@ transmit_pending (void *cls, | |||
373 | if (GNUNET_YES == head->free_on_send) | 375 | if (GNUNET_YES == head->free_on_send) |
374 | GNUNET_free (head); | 376 | GNUNET_free (head); |
375 | process_pending_messages (handle); | 377 | process_pending_messages (handle); |
378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
379 | "Forwarded request of %u bytes to DHT service\n", | ||
380 | (unsigned int) tsize); | ||
376 | return tsize; | 381 | return tsize; |
377 | } | 382 | } |
378 | 383 | ||
@@ -396,7 +401,11 @@ process_reply (void *cls, | |||
396 | 401 | ||
397 | uid = GNUNET_ntohll (dht_msg->unique_id); | 402 | uid = GNUNET_ntohll (dht_msg->unique_id); |
398 | if (uid != rh->uid) | 403 | if (uid != rh->uid) |
399 | return GNUNET_YES; | 404 | { |
405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
406 | "Reply UID did not match request UID\n"); | ||
407 | return GNUNET_YES; | ||
408 | } | ||
400 | enc_size = ntohs (dht_msg->header.size) - sizeof (struct GNUNET_DHT_RouteResultMessage); | 409 | enc_size = ntohs (dht_msg->header.size) - sizeof (struct GNUNET_DHT_RouteResultMessage); |
401 | if (enc_size < sizeof (struct GNUNET_MessageHeader)) | 410 | if (enc_size < sizeof (struct GNUNET_MessageHeader)) |
402 | { | 411 | { |
@@ -409,6 +418,8 @@ process_reply (void *cls, | |||
409 | GNUNET_break (0); | 418 | GNUNET_break (0); |
410 | return GNUNET_NO; | 419 | return GNUNET_NO; |
411 | } | 420 | } |
421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
422 | "Processing reply.\n"); | ||
412 | rh->iter (rh->iter_cls, | 423 | rh->iter (rh->iter_cls, |
413 | &rh->key, | 424 | &rh->key, |
414 | enc_msg); | 425 | enc_msg); |
@@ -429,9 +440,14 @@ service_message_handler (void *cls, | |||
429 | { | 440 | { |
430 | struct GNUNET_DHT_Handle *handle = cls; | 441 | struct GNUNET_DHT_Handle *handle = cls; |
431 | const struct GNUNET_DHT_RouteResultMessage *dht_msg; | 442 | const struct GNUNET_DHT_RouteResultMessage *dht_msg; |
432 | 443 | ||
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
445 | "%s called\n", | ||
446 | __FUNCTION__); | ||
433 | if (msg == NULL) | 447 | if (msg == NULL) |
434 | { | 448 | { |
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
450 | "Error receiving data from DHT service, reconnecting\n"); | ||
435 | reconnect (handle); | 451 | reconnect (handle); |
436 | return; | 452 | return; |
437 | } | 453 | } |
@@ -448,10 +464,16 @@ service_message_handler (void *cls, | |||
448 | return; | 464 | return; |
449 | } | 465 | } |
450 | dht_msg = (const struct GNUNET_DHT_RouteResultMessage *) msg; | 466 | dht_msg = (const struct GNUNET_DHT_RouteResultMessage *) msg; |
467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
468 | "Comparing reply `%s' against %u pending requests.\n", | ||
469 | GNUNET_h2s (&dht_msg->key), | ||
470 | GNUNET_CONTAINER_multihashmap_size (handle->active_requests)); | ||
451 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, | 471 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, |
452 | &dht_msg->key, | 472 | &dht_msg->key, |
453 | &process_reply, | 473 | &process_reply, |
454 | (void*) dht_msg); | 474 | (void*) dht_msg); |
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
476 | "Continuing to process replies from DHT\n"); | ||
455 | GNUNET_CLIENT_receive (handle->client, | 477 | GNUNET_CLIENT_receive (handle->client, |
456 | &service_message_handler, | 478 | &service_message_handler, |
457 | handle, GNUNET_TIME_UNIT_FOREVER_REL); | 479 | handle, GNUNET_TIME_UNIT_FOREVER_REL); |
@@ -656,6 +678,9 @@ GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle, | |||
656 | pending); | 678 | pending); |
657 | pending->in_pending_queue = GNUNET_YES; | 679 | pending->in_pending_queue = GNUNET_YES; |
658 | process_pending_messages (handle); | 680 | process_pending_messages (handle); |
681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
682 | "DHT route start request processed, returning %p\n", | ||
683 | route_handle); | ||
659 | return route_handle; | 684 | return route_handle; |
660 | } | 685 | } |
661 | 686 | ||
@@ -708,6 +733,8 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle) | |||
708 | route_handle)); | 733 | route_handle)); |
709 | GNUNET_free(route_handle->message); | 734 | GNUNET_free(route_handle->message); |
710 | GNUNET_free(route_handle); | 735 | GNUNET_free(route_handle); |
736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
737 | "DHT route stop request processed\n"); | ||
711 | } | 738 | } |
712 | 739 | ||
713 | 740 | ||
diff --git a/src/dht/dht_api_get_put.c b/src/dht/dht_api_get_put.c index 362f5dce6..b1b80b01e 100644 --- a/src/dht/dht_api_get_put.c +++ b/src/dht/dht_api_get_put.c | |||
@@ -75,7 +75,10 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | |||
75 | put_msg->type = htons (type); | 75 | put_msg->type = htons (type); |
76 | put_msg->expiration = GNUNET_TIME_absolute_hton (exp); | 76 | put_msg->expiration = GNUNET_TIME_absolute_hton (exp); |
77 | memcpy (&put_msg[1], data, size); | 77 | memcpy (&put_msg[1], data, size); |
78 | 78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
79 | "Starting route for %u byte `%s' message\n", | ||
80 | (unsigned int) (sizeof (struct GNUNET_DHT_PutMessage) + size), | ||
81 | "PUT"); | ||
79 | GNUNET_break (NULL == | 82 | GNUNET_break (NULL == |
80 | GNUNET_DHT_route_start (handle, | 83 | GNUNET_DHT_route_start (handle, |
81 | key, | 84 | key, |
@@ -132,7 +135,10 @@ get_reply_iterator (void *cls, | |||
132 | size_t payload; | 135 | size_t payload; |
133 | 136 | ||
134 | if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) | 137 | if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) |
135 | return; | 138 | { |
139 | GNUNET_break (0); | ||
140 | return; | ||
141 | } | ||
136 | 142 | ||
137 | GNUNET_assert (ntohs (reply->size) >= | 143 | GNUNET_assert (ntohs (reply->size) >= |
138 | sizeof (struct GNUNET_DHT_GetResultMessage)); | 144 | sizeof (struct GNUNET_DHT_GetResultMessage)); |
@@ -194,6 +200,10 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | |||
194 | get_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET); | 200 | get_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET); |
195 | get_msg.header.size = htons (sizeof (struct GNUNET_DHT_GetMessage)); | 201 | get_msg.header.size = htons (sizeof (struct GNUNET_DHT_GetMessage)); |
196 | get_msg.type = htons (type); | 202 | get_msg.type = htons (type); |
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
204 | "Starting route for %u byte `%s' message\n", | ||
205 | (unsigned int) sizeof (struct GNUNET_DHT_GetMessage), | ||
206 | "GET"); | ||
197 | get_handle->route_handle = | 207 | get_handle->route_handle = |
198 | GNUNET_DHT_route_start (handle, | 208 | GNUNET_DHT_route_start (handle, |
199 | key, | 209 | key, |
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 66facaa53..b97f56893 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #define REAL_DISTANCE GNUNET_NO | 48 | #define REAL_DISTANCE GNUNET_NO |
49 | 49 | ||
50 | #define EXTRA_CHECKS GNUNET_NO | 50 | #define EXTRA_CHECKS GNUNET_NO |
51 | |||
51 | /** | 52 | /** |
52 | * How many buckets will we allow total. | 53 | * How many buckets will we allow total. |
53 | */ | 54 | */ |
@@ -1818,6 +1819,11 @@ send_generic_reply (void *cls, size_t size, void *buf) | |||
1818 | off += msize; | 1819 | off += msize; |
1819 | } | 1820 | } |
1820 | process_pending_messages (client); | 1821 | process_pending_messages (client); |
1822 | #if DEBUG_DHT | ||
1823 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1824 | "Transmitted %u bytes of replies to client\n", | ||
1825 | (unsigned int) off); | ||
1826 | #endif | ||
1821 | return off; | 1827 | return off; |
1822 | } | 1828 | } |
1823 | 1829 | ||
@@ -1853,7 +1859,8 @@ add_pending_message (struct ClientList *client, | |||
1853 | static void | 1859 | static void |
1854 | send_reply_to_client (struct ClientList *client, | 1860 | send_reply_to_client (struct ClientList *client, |
1855 | const struct GNUNET_MessageHeader *message, | 1861 | const struct GNUNET_MessageHeader *message, |
1856 | unsigned long long uid) | 1862 | unsigned long long uid, |
1863 | const GNUNET_HashCode *key) | ||
1857 | { | 1864 | { |
1858 | struct GNUNET_DHT_RouteResultMessage *reply; | 1865 | struct GNUNET_DHT_RouteResultMessage *reply; |
1859 | struct PendingMessage *pending_message; | 1866 | struct PendingMessage *pending_message; |
@@ -1877,6 +1884,7 @@ send_reply_to_client (struct ClientList *client, | |||
1877 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT); | 1884 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT); |
1878 | reply->header.size = htons (tsize); | 1885 | reply->header.size = htons (tsize); |
1879 | reply->unique_id = GNUNET_htonll (uid); | 1886 | reply->unique_id = GNUNET_htonll (uid); |
1887 | reply->key = *key; | ||
1880 | memcpy (&reply[1], message, msize); | 1888 | memcpy (&reply[1], message, msize); |
1881 | 1889 | ||
1882 | add_pending_message (client, pending_message); | 1890 | add_pending_message (client, pending_message); |
@@ -1969,7 +1977,7 @@ static int route_result_message(void *cls, | |||
1969 | #if DEBUG_DHT | 1977 | #if DEBUG_DHT |
1970 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1978 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1971 | "`%s:%s': Have no record of response key %s uid %llu\n", my_short_id, | 1979 | "`%s:%s': Have no record of response key %s uid %llu\n", my_short_id, |
1972 | "DHT", GNUNET_h2s (message_context->key), message_context->unique_id); | 1980 | "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id); |
1973 | #endif | 1981 | #endif |
1974 | #if DEBUG_DHT_ROUTING | 1982 | #if DEBUG_DHT_ROUTING |
1975 | if ((debug_routes_extended) && (dhtlog_handle != NULL)) | 1983 | if ((debug_routes_extended) && (dhtlog_handle != NULL)) |
@@ -2014,7 +2022,7 @@ static int route_result_message(void *cls, | |||
2014 | #if DEBUG_DHT | 2022 | #if DEBUG_DHT |
2015 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2016 | "`%s:%s': Sending response key %s uid %llu to client\n", my_short_id, | 2024 | "`%s:%s': Sending response key %s uid %llu to client\n", my_short_id, |
2017 | "DHT", GNUNET_h2s (message_context->key), message_context->unique_id); | 2025 | "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id); |
2018 | #endif | 2026 | #endif |
2019 | #if DEBUG_DHT_ROUTING | 2027 | #if DEBUG_DHT_ROUTING |
2020 | if ((debug_routes_extended) && (dhtlog_handle != NULL)) | 2028 | if ((debug_routes_extended) && (dhtlog_handle != NULL)) |
@@ -2029,7 +2037,9 @@ static int route_result_message(void *cls, | |||
2029 | if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) | 2037 | if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) |
2030 | increment_stats(STAT_GET_REPLY); | 2038 | increment_stats(STAT_GET_REPLY); |
2031 | 2039 | ||
2032 | send_reply_to_client(pos->client, msg, message_context->unique_id); | 2040 | send_reply_to_client(pos->client, msg, |
2041 | message_context->unique_id, | ||
2042 | &message_context->key); | ||
2033 | } | 2043 | } |
2034 | else /* Send to peer */ | 2044 | else /* Send to peer */ |
2035 | { | 2045 | { |
@@ -2048,7 +2058,7 @@ static int route_result_message(void *cls, | |||
2048 | #if DEBUG_DHT | 2058 | #if DEBUG_DHT |
2049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2059 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2050 | "`%s:%s': Forwarding response key %s uid %llu to peer %s\n", my_short_id, | 2060 | "`%s:%s': Forwarding response key %s uid %llu to peer %s\n", my_short_id, |
2051 | "DHT", GNUNET_h2s (message_context->key), message_context->unique_id, GNUNET_i2s(&peer_info->id)); | 2061 | "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id, GNUNET_i2s(&peer_info->id)); |
2052 | #endif | 2062 | #endif |
2053 | #if DEBUG_DHT_ROUTING | 2063 | #if DEBUG_DHT_ROUTING |
2054 | if ((debug_routes_extended) && (dhtlog_handle != NULL)) | 2064 | if ((debug_routes_extended) && (dhtlog_handle != NULL)) |
@@ -2067,7 +2077,7 @@ static int route_result_message(void *cls, | |||
2067 | #if DEBUG_DHT | 2077 | #if DEBUG_DHT |
2068 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2069 | "`%s:%s': NOT Forwarding response (bloom match) key %s uid %llu to peer %s\n", my_short_id, | 2079 | "`%s:%s': NOT Forwarding response (bloom match) key %s uid %llu to peer %s\n", my_short_id, |
2070 | "DHT", GNUNET_h2s (message_context->key), message_context->unique_id, GNUNET_i2s(&peer_info->id)); | 2080 | "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id, GNUNET_i2s(&peer_info->id)); |
2071 | #endif | 2081 | #endif |
2072 | } | 2082 | } |
2073 | } | 2083 | } |
@@ -2159,7 +2169,7 @@ handle_dht_get (void *cls, | |||
2159 | #if DEBUG_DHT | 2169 | #if DEBUG_DHT |
2160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2161 | "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n", my_short_id, | 2171 | "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n", my_short_id, |
2162 | "DHT", "GET", get_type, GNUNET_h2s (message_context->key), | 2172 | "DHT", "GET", get_type, GNUNET_h2s (&message_context->key), |
2163 | message_context->unique_id); | 2173 | message_context->unique_id); |
2164 | #endif | 2174 | #endif |
2165 | increment_stats(STAT_GETS); | 2175 | increment_stats(STAT_GETS); |
@@ -2279,7 +2289,7 @@ handle_dht_find_peer (void *cls, | |||
2279 | #if DEBUG_DHT | 2289 | #if DEBUG_DHT |
2280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2281 | "`%s:%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n", | 2291 | "`%s:%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n", |
2282 | my_short_id, "DHT", "FIND PEER", GNUNET_h2s (message_context->key), | 2292 | my_short_id, "DHT", "FIND PEER", GNUNET_h2s (&message_context->key), |
2283 | ntohs (find_msg->size), | 2293 | ntohs (find_msg->size), |
2284 | sizeof (struct GNUNET_MessageHeader)); | 2294 | sizeof (struct GNUNET_MessageHeader)); |
2285 | #endif | 2295 | #endif |
@@ -2422,7 +2432,7 @@ handle_dht_put (void *cls, | |||
2422 | #if DEBUG_DHT | 2432 | #if DEBUG_DHT |
2423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2424 | "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n", | 2434 | "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n", |
2425 | my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (message_context->key), message_context->unique_id); | 2435 | my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (&message_context->key), message_context->unique_id); |
2426 | #endif | 2436 | #endif |
2427 | #if DEBUG_DHT_ROUTING | 2437 | #if DEBUG_DHT_ROUTING |
2428 | if (message_context->hop_count == 0) /* Locally initiated request */ | 2438 | if (message_context->hop_count == 0) /* Locally initiated request */ |
@@ -3219,7 +3229,7 @@ static int cache_response(void *cls, struct DHT_MessageContext *msg_ctx) | |||
3219 | #if DEBUG_DHT > 1 | 3229 | #if DEBUG_DHT > 1 |
3220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3221 | "`%s:%s': Created new forward source info for %s uid %llu\n", my_short_id, | 3231 | "`%s:%s': Created new forward source info for %s uid %llu\n", my_short_id, |
3222 | "DHT", GNUNET_h2s (msg_ctx->key), msg_ctx->unique_id); | 3232 | "DHT", GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id); |
3223 | #endif | 3233 | #endif |
3224 | return GNUNET_YES; | 3234 | return GNUNET_YES; |
3225 | } | 3235 | } |
@@ -3412,7 +3422,7 @@ static int route_message(void *cls, | |||
3412 | nearest_buf = GNUNET_strdup(GNUNET_i2s(&nearest->id)); | 3422 | nearest_buf = GNUNET_strdup(GNUNET_i2s(&nearest->id)); |
3413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3414 | "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n", my_short_id, | 3424 | "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n", my_short_id, |
3415 | "DHT", GNUNET_h2s (message_context->key), message_context->unique_id, GNUNET_i2s(&selected->id), nearest_buf, GNUNET_CRYPTO_hash_matching_bits(&nearest->id.hashPubKey, message_context->key), distance(&nearest->id.hashPubKey, message_context->key)); | 3425 | "DHT", GNUNET_h2s (&message_context->key), message_context->unique_id, GNUNET_i2s(&selected->id), nearest_buf, GNUNET_CRYPTO_hash_matching_bits(&nearest->id.hashPubKey, message_context->key), distance(&nearest->id.hashPubKey, message_context->key)); |
3416 | GNUNET_free(nearest_buf); | 3426 | GNUNET_free(nearest_buf); |
3417 | #endif | 3427 | #endif |
3418 | #if DEBUG_DHT_ROUTING | 3428 | #if DEBUG_DHT_ROUTING |
@@ -3859,11 +3869,16 @@ handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client, | |||
3859 | const struct GNUNET_DHT_RouteMessage *dht_msg = (const struct GNUNET_DHT_RouteMessage *) message; | 3869 | const struct GNUNET_DHT_RouteMessage *dht_msg = (const struct GNUNET_DHT_RouteMessage *) message; |
3860 | const struct GNUNET_MessageHeader *enc_msg; | 3870 | const struct GNUNET_MessageHeader *enc_msg; |
3861 | struct DHT_MessageContext message_context; | 3871 | struct DHT_MessageContext message_context; |
3872 | |||
3862 | enc_msg = (const struct GNUNET_MessageHeader *) &dht_msg[1]; | 3873 | enc_msg = (const struct GNUNET_MessageHeader *) &dht_msg[1]; |
3863 | #if DEBUG_DHT | 3874 | #if DEBUG_DHT |
3864 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3865 | "`%s:%s': Received `%s' request from client, message type %d, key %s, uid %llu\n", | 3876 | "`%s:%s': Received `%s' request from client, message type %d, key %s, uid %llu\n", |
3866 | my_short_id, "DHT", "GENERIC", enc_type, GNUNET_h2s (&dht_msg->key), | 3877 | my_short_id, |
3878 | "DHT", | ||
3879 | "GENERIC", | ||
3880 | ntohs (message->type), | ||
3881 | GNUNET_h2s (&dht_msg->key), | ||
3867 | GNUNET_ntohll (dht_msg->unique_id)); | 3882 | GNUNET_ntohll (dht_msg->unique_id)); |
3868 | #endif | 3883 | #endif |
3869 | #if DEBUG_DHT_ROUTING | 3884 | #if DEBUG_DHT_ROUTING |
@@ -3928,7 +3943,8 @@ handle_dht_control_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
3928 | if (malicious_getter != GNUNET_YES) | 3943 | if (malicious_getter != GNUNET_YES) |
3929 | GNUNET_SCHEDULER_add_now(sched, &malicious_get_task, NULL); | 3944 | GNUNET_SCHEDULER_add_now(sched, &malicious_get_task, NULL); |
3930 | malicious_getter = GNUNET_YES; | 3945 | malicious_getter = GNUNET_YES; |
3931 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious GET behavior, frequency %d\n", my_short_id, "DHT", malicious_get_frequency); | 3946 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3947 | "%s:%s Initiating malicious GET behavior, frequency %d\n", my_short_id, "DHT", malicious_get_frequency); | ||
3932 | break; | 3948 | break; |
3933 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT: | 3949 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT: |
3934 | if (ntohs(dht_control_msg->variable) > 0) | 3950 | if (ntohs(dht_control_msg->variable) > 0) |
@@ -3938,7 +3954,8 @@ handle_dht_control_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
3938 | if (malicious_putter != GNUNET_YES) | 3954 | if (malicious_putter != GNUNET_YES) |
3939 | GNUNET_SCHEDULER_add_now(sched, &malicious_put_task, NULL); | 3955 | GNUNET_SCHEDULER_add_now(sched, &malicious_put_task, NULL); |
3940 | malicious_putter = GNUNET_YES; | 3956 | malicious_putter = GNUNET_YES; |
3941 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious PUT behavior, frequency %d\n", my_short_id, "DHT", malicious_put_frequency); | 3957 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3958 | "%s:%s Initiating malicious PUT behavior, frequency %d\n", my_short_id, "DHT", malicious_put_frequency); | ||
3942 | break; | 3959 | break; |
3943 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP: | 3960 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP: |
3944 | #if DEBUG_DHT_ROUTING | 3961 | #if DEBUG_DHT_ROUTING |
@@ -3946,10 +3963,15 @@ handle_dht_control_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
3946 | dhtlog_handle->set_malicious(&my_identity); | 3963 | dhtlog_handle->set_malicious(&my_identity); |
3947 | #endif | 3964 | #endif |
3948 | malicious_dropper = GNUNET_YES; | 3965 | malicious_dropper = GNUNET_YES; |
3949 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious DROP behavior\n", my_short_id, "DHT"); | 3966 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3967 | "%s:%s Initiating malicious DROP behavior\n", my_short_id, "DHT"); | ||
3950 | break; | 3968 | break; |
3951 | default: | 3969 | default: |
3952 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Unknown control command type `%d'!\n", ntohs(dht_control_msg->command)); | 3970 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3971 | "%s:%s Unknown control command type `%d'!\n", | ||
3972 | my_short_id, "DHT", | ||
3973 | ntohs(dht_control_msg->command)); | ||
3974 | break; | ||
3953 | } | 3975 | } |
3954 | 3976 | ||
3955 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3977 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index f0b330d3a..b4014a92c 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #include "gnunet_dht_service.h" | 34 | #include "gnunet_dht_service.h" |
35 | #include "gnunet_hello_lib.h" | 35 | #include "gnunet_hello_lib.h" |
36 | 36 | ||
37 | #define VERBOSE GNUNET_YES | 37 | #define VERBOSE GNUNET_NO |
38 | 38 | ||
39 | #define VERBOSE_ARM GNUNET_NO | 39 | #define VERBOSE_ARM GNUNET_NO |
40 | 40 | ||
@@ -109,25 +109,12 @@ GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
109 | static void | 109 | static void |
110 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 110 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
111 | { | 111 | { |
112 | /* do work here */ | ||
113 | sleep(2); | ||
114 | GNUNET_SCHEDULER_cancel (sched, die_task); | 112 | GNUNET_SCHEDULER_cancel (sched, die_task); |
115 | |||
116 | GNUNET_DHT_disconnect (p1.dht_handle); | ||
117 | die_task = GNUNET_SCHEDULER_NO_TASK; | 113 | die_task = GNUNET_SCHEDULER_NO_TASK; |
118 | 114 | GNUNET_DHT_disconnect (p1.dht_handle); | |
119 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
120 | { | 116 | "DHT disconnected, returning success!\n"); |
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 117 | ok = 0; |
122 | "DHT disconnected, returning FAIL!\n"); | ||
123 | ok = 365; | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
128 | "DHT disconnected, returning success!\n"); | ||
129 | ok = 0; | ||
130 | } | ||
131 | } | 118 | } |
132 | 119 | ||
133 | static void | 120 | static void |
@@ -150,76 +137,17 @@ end_badly () | |||
150 | fprintf (stderr, "Ending on an unhappy note.\n"); | 137 | fprintf (stderr, "Ending on an unhappy note.\n"); |
151 | #endif | 138 | #endif |
152 | 139 | ||
153 | if ((retry_context.peer_ctx != NULL) && (retry_context.peer_ctx->find_peer_handle != NULL)) | 140 | if ( (retry_context.peer_ctx != NULL) && |
141 | (retry_context.peer_ctx->find_peer_handle != NULL) ) | ||
154 | GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle); | 142 | GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle); |
143 | if ( (retry_context.peer_ctx != NULL) && | ||
144 | (retry_context.peer_ctx->get_handle != NULL) ) | ||
145 | GNUNET_DHT_get_stop (retry_context.peer_ctx->get_handle); | ||
155 | if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK) | 146 | if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK) |
156 | GNUNET_SCHEDULER_cancel(sched, retry_context.retry_task); | 147 | GNUNET_SCHEDULER_cancel(sched, retry_context.retry_task); |
157 | GNUNET_DHT_disconnect (p1.dht_handle); | 148 | GNUNET_DHT_disconnect (p1.dht_handle); |
158 | |||
159 | ok = 1; | 149 | ok = 1; |
160 | return; | ||
161 | } | ||
162 | |||
163 | #if HAVE_MALICIOUS | ||
164 | |||
165 | /** | ||
166 | * Signature of the main function of a task. | ||
167 | * | ||
168 | * @param cls closure | ||
169 | * @param tc context information (why was this task triggered now) | ||
170 | */ | ||
171 | void test_set_peer_malicious_drop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
172 | { | ||
173 | struct PeerContext *peer = cls; | ||
174 | |||
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_drop!\n"); | ||
176 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
177 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
178 | |||
179 | GNUNET_assert (peer->dht_handle != NULL); | ||
180 | |||
181 | GNUNET_DHT_set_malicious_dropper (peer->dht_handle, &end, &p1); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Signature of the main function of a task. | ||
186 | * | ||
187 | * @param cls closure | ||
188 | * @param tc context information (why was this task triggered now) | ||
189 | */ | ||
190 | void test_set_peer_malicious_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
191 | { | ||
192 | struct PeerContext *peer = cls; | ||
193 | |||
194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_put!\n"); | ||
195 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
196 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
197 | |||
198 | GNUNET_assert (peer->dht_handle != NULL); | ||
199 | |||
200 | GNUNET_DHT_set_malicious_putter (peer->dht_handle, 750, &test_set_peer_malicious_drop, &p1); | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Signature of the main function of a task. | ||
205 | * | ||
206 | * @param cls closure | ||
207 | * @param tc context information (why was this task triggered now) | ||
208 | */ | ||
209 | static void | ||
210 | test_set_peer_malicious_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
211 | { | ||
212 | struct PeerContext *peer = cls; | ||
213 | |||
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_get!\n"); | ||
215 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
216 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
217 | |||
218 | GNUNET_assert (peer->dht_handle != NULL); | ||
219 | |||
220 | GNUNET_DHT_set_malicious_getter (peer->dht_handle, 1500, &test_set_peer_malicious_put, &p1); | ||
221 | } | 150 | } |
222 | #endif | ||
223 | 151 | ||
224 | 152 | ||
225 | /** | 153 | /** |
@@ -235,20 +163,25 @@ test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
235 | 163 | ||
236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); | 164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); |
237 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 165 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
238 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | 166 | { |
167 | GNUNET_break (0); | ||
168 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
169 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
170 | return; | ||
171 | } | ||
239 | 172 | ||
240 | GNUNET_assert (peer->dht_handle != NULL); | 173 | GNUNET_assert (peer->dht_handle != NULL); |
241 | 174 | ||
242 | GNUNET_DHT_find_peer_stop (peer->find_peer_handle); | 175 | GNUNET_DHT_find_peer_stop (peer->find_peer_handle); |
243 | 176 | ||
244 | #if HAVE_MALICIOUS | 177 | #if HAVE_MALICIOUS |
245 | GNUNET_SCHEDULER_add_now (sched, | 178 | GNUNET_DHT_set_malicious_getter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS); |
246 | &test_set_peer_malicious_get, &p1); | 179 | GNUNET_DHT_set_malicious_putter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS); |
247 | #else | 180 | GNUNET_DHT_set_malicious_dropper (peer->dht_handle); |
248 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), | ||
249 | &end, &p1); | ||
250 | #endif | 181 | #endif |
251 | 182 | GNUNET_SCHEDULER_add_delayed(sched, | |
183 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), | ||
184 | &end, &p1); | ||
252 | } | 185 | } |
253 | 186 | ||
254 | 187 | ||
@@ -330,9 +263,13 @@ retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
330 | } | 263 | } |
331 | 264 | ||
332 | if (retry_ctx->peer_ctx->find_peer_handle == NULL) | 265 | if (retry_ctx->peer_ctx->find_peer_handle == NULL) |
333 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | 266 | { |
334 | else | 267 | GNUNET_break (0); |
335 | retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer_stop, retry_ctx); | 268 | GNUNET_SCHEDULER_cancel (sched, die_task); |
269 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | ||
270 | return; | ||
271 | } | ||
272 | retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer_stop, retry_ctx); | ||
336 | } | 273 | } |
337 | 274 | ||
338 | /** | 275 | /** |
@@ -383,9 +320,13 @@ test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
383 | &test_find_peer_processor, &retry_context); | 320 | &test_find_peer_processor, &retry_context); |
384 | 321 | ||
385 | if (peer->find_peer_handle == NULL) | 322 | if (peer->find_peer_handle == NULL) |
386 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | 323 | { |
387 | else | 324 | GNUNET_break (0); |
388 | retry_context.retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_context.next_timeout, &retry_find_peer_stop, &retry_context); | 325 | GNUNET_SCHEDULER_cancel (sched, die_task); |
326 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | ||
327 | return; | ||
328 | } | ||
329 | retry_context.retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_context.next_timeout, &retry_find_peer_stop, &retry_context); | ||
389 | } | 330 | } |
390 | 331 | ||
391 | /** | 332 | /** |
@@ -401,7 +342,12 @@ test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
401 | 342 | ||
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); | 343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); |
403 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 344 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
404 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | 345 | { |
346 | GNUNET_break (0); | ||
347 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
348 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
349 | return; | ||
350 | } | ||
405 | GNUNET_assert (peer->dht_handle != NULL); | 351 | GNUNET_assert (peer->dht_handle != NULL); |
406 | GNUNET_DHT_get_stop (peer->get_handle); | 352 | GNUNET_DHT_get_stop (peer->get_handle); |
407 | GNUNET_SCHEDULER_add_now(sched, | 353 | GNUNET_SCHEDULER_add_now(sched, |
@@ -445,7 +391,7 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
445 | peer->get_handle = | 391 | peer->get_handle = |
446 | GNUNET_DHT_get_start (peer->dht_handle, | 392 | GNUNET_DHT_get_start (peer->dht_handle, |
447 | TOTAL_TIMEOUT, | 393 | TOTAL_TIMEOUT, |
448 | 49 /* fixme: use test type */, | 394 | GNUNET_BLOCK_TYPE_TEST, |
449 | &hash, | 395 | &hash, |
450 | GNUNET_DHT_RO_NONE, | 396 | GNUNET_DHT_RO_NONE, |
451 | NULL, 0, | 397 | NULL, 0, |
@@ -453,7 +399,12 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
453 | &test_get_iterator, NULL); | 399 | &test_get_iterator, NULL); |
454 | 400 | ||
455 | if (peer->get_handle == NULL) | 401 | if (peer->get_handle == NULL) |
456 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | 402 | { |
403 | GNUNET_break (0); | ||
404 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
405 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | ||
406 | return; | ||
407 | } | ||
457 | } | 408 | } |
458 | 409 | ||
459 | /** | 410 | /** |
@@ -479,7 +430,7 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
479 | 430 | ||
480 | GNUNET_DHT_put (peer->dht_handle, &hash, | 431 | GNUNET_DHT_put (peer->dht_handle, &hash, |
481 | GNUNET_DHT_RO_NONE, | 432 | GNUNET_DHT_RO_NONE, |
482 | 49 /* fixme: use test type */, | 433 | GNUNET_BLOCK_TYPE_TEST, |
483 | data_size, data, | 434 | data_size, data, |
484 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), | 435 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), |
485 | TOTAL_TIMEOUT, | 436 | TOTAL_TIMEOUT, |
diff --git a/src/dht/test_dht_api_data.conf b/src/dht/test_dht_api_data.conf index 6250eb57b..df2c53d2a 100644 --- a/src/dht/test_dht_api_data.conf +++ b/src/dht/test_dht_api_data.conf | |||
@@ -23,7 +23,7 @@ TOTAL_QUOTA_IN = 3932160 | |||
23 | PORT = 2092 | 23 | PORT = 2092 |
24 | 24 | ||
25 | [dht] | 25 | [dht] |
26 | DEBUG = NO | 26 | DEBUG = YES |
27 | PORT = 12370 | 27 | PORT = 12370 |
28 | 28 | ||
29 | [transport] | 29 | [transport] |