diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
commit | 83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch) | |
tree | d0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/dht | |
parent | 28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff) | |
download | gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip |
curly wars / auto-indentation
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/dht_api.c | 52 | ||||
-rw-r--r-- | src/dht/gnunet-dht-get.c | 12 | ||||
-rw-r--r-- | src/dht/gnunet-dht-put.c | 6 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 44 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_clients.c | 491 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_clients.h | 17 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.c | 121 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.h | 28 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_hello.c | 36 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 982 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.h | 52 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_nse.c | 10 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_routing.c | 144 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_routing.h | 27 | ||||
-rw-r--r-- | src/dht/test_dht_2dtorus.c | 208 | ||||
-rw-r--r-- | src/dht/test_dht_api.c | 16 | ||||
-rw-r--r-- | src/dht/test_dht_multipeer.c | 210 | ||||
-rw-r--r-- | src/dht/test_dht_twopeer.c | 30 | ||||
-rw-r--r-- | src/dht/test_dht_twopeer_get_put.c | 22 | ||||
-rw-r--r-- | src/dht/test_dht_twopeer_path_tracking.c | 24 | ||||
-rw-r--r-- | src/dht/test_dht_twopeer_put_get.c | 21 |
21 files changed, 1140 insertions, 1413 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 720e82a41..ac69b7a4e 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -249,12 +249,11 @@ add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value) | |||
249 | struct GNUNET_DHT_GetHandle *rh = value; | 249 | struct GNUNET_DHT_GetHandle *rh = value; |
250 | 250 | ||
251 | if (GNUNET_NO == rh->message->in_pending_queue) | 251 | if (GNUNET_NO == rh->message->in_pending_queue) |
252 | { | 252 | { |
253 | #if DEBUG_DHT | 253 | #if DEBUG_DHT |
254 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 254 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
255 | "Retransmitting request related to %s to DHT %p\n", | 255 | "Retransmitting request related to %s to DHT %p\n", GNUNET_h2s (key), |
256 | GNUNET_h2s (key), | 256 | handle); |
257 | handle); | ||
258 | #endif | 257 | #endif |
259 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, | 258 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, |
260 | rh->message); | 259 | rh->message); |
@@ -284,9 +283,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
284 | struct GNUNET_DHT_Handle *handle = cls; | 283 | struct GNUNET_DHT_Handle *handle = cls; |
285 | 284 | ||
286 | #if DEBUG_DHT | 285 | #if DEBUG_DHT |
287 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 286 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle); |
288 | "Reconnecting with DHT %p\n", | ||
289 | handle); | ||
290 | #endif | 287 | #endif |
291 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 288 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
292 | if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) | 289 | if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) |
@@ -324,8 +321,8 @@ do_disconnect (struct GNUNET_DHT_Handle *handle) | |||
324 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); | 321 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); |
325 | handle->th = NULL; | 322 | handle->th = NULL; |
326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
327 | "Disconnecting from DHT service, will try to reconnect in %llu ms\n", | 324 | "Disconnecting from DHT service, will try to reconnect in %llu ms\n", |
328 | (unsigned long long) handle->retry_time.rel_value); | 325 | (unsigned long long) handle->retry_time.rel_value); |
329 | GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); | 326 | GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); |
330 | handle->client = NULL; | 327 | handle->client = NULL; |
331 | handle->reconnect_task = | 328 | handle->reconnect_task = |
@@ -351,7 +348,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle) | |||
351 | if (handle->client == NULL) | 348 | if (handle->client == NULL) |
352 | { | 349 | { |
353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
354 | "process_pending_messages called, but client is null, reconnecting\n"); | 351 | "process_pending_messages called, but client is null, reconnecting\n"); |
355 | do_disconnect (handle); | 352 | do_disconnect (handle); |
356 | return; | 353 | return; |
357 | } | 354 | } |
@@ -368,7 +365,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle) | |||
368 | if (NULL != handle->th) | 365 | if (NULL != handle->th) |
369 | return; | 366 | return; |
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
371 | "notify_transmit_ready returned NULL, reconnecting\n"); | 368 | "notify_transmit_ready returned NULL, reconnecting\n"); |
372 | do_disconnect (handle); | 369 | do_disconnect (handle); |
373 | } | 370 | } |
374 | 371 | ||
@@ -432,7 +429,7 @@ transmit_pending (void *cls, size_t size, void *buf) | |||
432 | #endif | 429 | #endif |
433 | handle->in_receive = GNUNET_YES; | 430 | handle->in_receive = GNUNET_YES; |
434 | GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle, | 431 | GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle, |
435 | GNUNET_TIME_UNIT_FOREVER_REL); | 432 | GNUNET_TIME_UNIT_FOREVER_REL); |
436 | } | 433 | } |
437 | return tsize; | 434 | return tsize; |
438 | } | 435 | } |
@@ -466,9 +463,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value) | |||
466 | { | 463 | { |
467 | /* UID mismatch */ | 464 | /* UID mismatch */ |
468 | #if DEBUG_DHT | 465 | #if DEBUG_DHT |
469 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 466 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
470 | "Ignoring reply for %s: UID mismatch: %llu/%llu\n", | 467 | "Ignoring reply for %s: UID mismatch: %llu/%llu\n", GNUNET_h2s (key), |
471 | GNUNET_h2s (key), | ||
472 | dht_msg->unique_id, get_handle->unique_id); | 468 | dht_msg->unique_id, get_handle->unique_id); |
473 | #endif | 469 | #endif |
474 | return GNUNET_YES; | 470 | return GNUNET_YES; |
@@ -490,10 +486,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value) | |||
490 | } | 486 | } |
491 | data_length = msize - meta_length; | 487 | data_length = msize - meta_length; |
492 | #if DEBUG_DHT | 488 | #if DEBUG_DHT |
493 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 489 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n", |
494 | "Giving %u byte reply for %s to application\n", | 490 | (unsigned int) data_length, GNUNET_h2s (key)); |
495 | (unsigned int) data_length, | ||
496 | GNUNET_h2s (key)); | ||
497 | #endif | 491 | #endif |
498 | put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1]; | 492 | put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1]; |
499 | get_path = &put_path[put_path_length]; | 493 | get_path = &put_path[put_path_length]; |
@@ -542,10 +536,8 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
542 | } | 536 | } |
543 | dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg; | 537 | dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg; |
544 | #if DEBUG_DHT | 538 | #if DEBUG_DHT |
545 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 539 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply for `%s' from DHT service %p\n", |
546 | "Received reply for `%s' from DHT service %p\n", | 540 | GNUNET_h2s (&dht_msg->key), handle); |
547 | GNUNET_h2s (&dht_msg->key), | ||
548 | handle); | ||
549 | #endif | 541 | #endif |
550 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, | 542 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, |
551 | &dht_msg->key, &process_reply, | 543 | &dht_msg->key, &process_reply, |
@@ -641,7 +633,7 @@ timeout_put_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
641 | struct GNUNET_DHT_Handle *handle; | 633 | struct GNUNET_DHT_Handle *handle; |
642 | 634 | ||
643 | handle = pending->handle; | 635 | handle = pending->handle; |
644 | GNUNET_assert (GNUNET_YES == pending->in_pending_queue); | 636 | GNUNET_assert (GNUNET_YES == pending->in_pending_queue); |
645 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, | 637 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, |
646 | pending); | 638 | pending); |
647 | pending->in_pending_queue = GNUNET_NO; | 639 | pending->in_pending_queue = GNUNET_NO; |
@@ -752,10 +744,8 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | |||
752 | return NULL; | 744 | return NULL; |
753 | } | 745 | } |
754 | #if DEBUG_DHT | 746 | #if DEBUG_DHT |
755 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 747 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending query for %s to DHT %p\n", |
756 | "Sending query for %s to DHT %p\n", | 748 | GNUNET_h2s (key), handle); |
757 | GNUNET_h2s (key), | ||
758 | handle); | ||
759 | #endif | 749 | #endif |
760 | pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); | 750 | pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); |
761 | get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1]; | 751 | get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1]; |
@@ -803,10 +793,8 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) | |||
803 | get_msg = | 793 | get_msg = |
804 | (const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg; | 794 | (const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg; |
805 | #if DEBUG_DHT | 795 | #if DEBUG_DHT |
806 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 796 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending STOP for %s to DHT via %p\n", |
807 | "Sending STOP for %s to DHT via %p\n", | 797 | GNUNET_h2s (&get_msg->key), handle); |
808 | GNUNET_h2s (&get_msg->key), | ||
809 | handle); | ||
810 | #endif | 798 | #endif |
811 | /* generate STOP */ | 799 | /* generate STOP */ |
812 | pending = | 800 | pending = |
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index 8720e76aa..763ff8e6f 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c | |||
@@ -124,10 +124,10 @@ static void | |||
124 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 124 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, |
125 | const GNUNET_HashCode * key, | 125 | const GNUNET_HashCode * key, |
126 | const struct GNUNET_PeerIdentity *get_path, | 126 | const struct GNUNET_PeerIdentity *get_path, |
127 | unsigned int get_path_length, | 127 | unsigned int get_path_length, |
128 | const struct GNUNET_PeerIdentity *put_path, | 128 | const struct GNUNET_PeerIdentity *put_path, |
129 | unsigned int put_path_length, | 129 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
130 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 130 | size_t size, const void *data) |
131 | { | 131 | { |
132 | fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, | 132 | fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, |
133 | (unsigned int) size, (char *) data); | 133 | (unsigned int) size, (char *) data); |
@@ -186,9 +186,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
186 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining | 186 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
187 | (absolute_timeout), &cleanup_task, NULL); | 187 | (absolute_timeout), &cleanup_task, NULL); |
188 | get_handle = | 188 | get_handle = |
189 | GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, | 189 | GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, replication, |
190 | replication, GNUNET_DHT_RO_NONE, NULL, | 190 | GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator, |
191 | 0, &get_result_iterator, NULL); | 191 | NULL); |
192 | 192 | ||
193 | } | 193 | } |
194 | 194 | ||
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c index f165aa4a4..079a8866e 100644 --- a/src/dht/gnunet-dht-put.c +++ b/src/dht/gnunet-dht-put.c | |||
@@ -151,9 +151,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
151 | if (verbose) | 151 | if (verbose) |
152 | fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"), | 152 | fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"), |
153 | query_key, data); | 153 | query_key, data); |
154 | GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, | 154 | GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, query_type, |
155 | query_type, strlen (data), data, expiration, timeout, | 155 | strlen (data), data, expiration, timeout, &message_sent_cont, |
156 | &message_sent_cont, NULL); | 156 | NULL); |
157 | 157 | ||
158 | } | 158 | } |
159 | 159 | ||
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 3e0f3c8d9..72575acae 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -81,8 +81,7 @@ static struct GNUNET_TRANSPORT_GetHelloHandle *ghh; | |||
81 | * @param message HELLO message of peer | 81 | * @param message HELLO message of peer |
82 | */ | 82 | */ |
83 | static void | 83 | static void |
84 | process_hello (void *cls, | 84 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
85 | const struct GNUNET_MessageHeader *message) | ||
86 | { | 85 | { |
87 | GNUNET_assert (message != NULL); | 86 | GNUNET_assert (message != NULL); |
88 | GNUNET_free_non_null (GDS_my_hello); | 87 | GNUNET_free_non_null (GDS_my_hello); |
@@ -149,24 +148,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
149 | GDS_DATACACHE_init (); | 148 | GDS_DATACACHE_init (); |
150 | GDS_HELLO_init (); | 149 | GDS_HELLO_init (); |
151 | GDS_CLIENTS_init (server); | 150 | GDS_CLIENTS_init (server); |
152 | if (GNUNET_OK != | 151 | if (GNUNET_OK != GDS_NEIGHBOURS_init ()) |
153 | GDS_NEIGHBOURS_init ()) | 152 | { |
154 | { | 153 | shutdown_task (NULL, NULL); |
155 | shutdown_task (NULL, NULL); | 154 | return; |
156 | return; | 155 | } |
157 | } | 156 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 157 | NULL); |
159 | &shutdown_task, NULL); | ||
160 | GDS_transport_handle = | 158 | GDS_transport_handle = |
161 | GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL); | 159 | GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL); |
162 | if (GDS_transport_handle == NULL) | 160 | if (GDS_transport_handle == NULL) |
163 | { | 161 | { |
164 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
165 | _("Failed to connect to transport service!\n")); | 163 | _("Failed to connect to transport service!\n")); |
166 | return; | 164 | return; |
167 | } | 165 | } |
168 | ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, | 166 | ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, &process_hello, NULL); |
169 | &process_hello, NULL); | ||
170 | } | 167 | } |
171 | 168 | ||
172 | 169 | ||
@@ -181,12 +178,11 @@ int | |||
181 | main (int argc, char *const *argv) | 178 | main (int argc, char *const *argv) |
182 | { | 179 | { |
183 | int ret; | 180 | int ret; |
184 | 181 | ||
185 | ret = (GNUNET_OK == | 182 | ret = |
186 | GNUNET_SERVICE_run (argc, argv, | 183 | (GNUNET_OK == |
187 | "dht", | 184 | GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run, |
188 | GNUNET_SERVICE_OPTION_NONE, | 185 | NULL)) ? 0 : 1; |
189 | &run, NULL)) ? 0 : 1; | ||
190 | GDS_CLIENTS_done (); | 186 | GDS_CLIENTS_done (); |
191 | return ret; | 187 | return ret; |
192 | } | 188 | } |
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 4b9eecc58..dde8c6d7a 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -53,7 +53,7 @@ struct PendingMessage | |||
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Actual message to be sent, allocated at the end of the struct: | 55 | * Actual message to be sent, allocated at the end of the struct: |
56 | * // msg = (cast) &pm[1]; | 56 | * // msg = (cast) &pm[1]; |
57 | * // memcpy (&pm[1], data, len); | 57 | * // memcpy (&pm[1], data, len); |
58 | */ | 58 | */ |
59 | const struct GNUNET_MessageHeader *msg; | 59 | const struct GNUNET_MessageHeader *msg; |
@@ -224,15 +224,13 @@ find_active_client (struct GNUNET_SERVER_Client *client) | |||
224 | } | 224 | } |
225 | ret = GNUNET_malloc (sizeof (struct ClientList)); | 225 | ret = GNUNET_malloc (sizeof (struct ClientList)); |
226 | ret->client_handle = client; | 226 | ret->client_handle = client; |
227 | GNUNET_CONTAINER_DLL_insert (client_head, | 227 | GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ret); |
228 | client_tail, | ||
229 | ret); | ||
230 | return ret; | 228 | return ret; |
231 | } | 229 | } |
232 | 230 | ||
233 | 231 | ||
234 | /** | 232 | /** |
235 | * Iterator over hash map entries that frees all entries | 233 | * Iterator over hash map entries that frees all entries |
236 | * associated with the given client. | 234 | * associated with the given client. |
237 | * | 235 | * |
238 | * @param cls client to search for in source routes | 236 | * @param cls client to search for in source routes |
@@ -250,18 +248,15 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value) | |||
250 | return GNUNET_YES; | 248 | return GNUNET_YES; |
251 | #if DEBUG_DHT | 249 | #if DEBUG_DHT |
252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
253 | "Removing client %p's record for key %s\n", | 251 | "Removing client %p's record for key %s\n", client, |
254 | client, | 252 | GNUNET_h2s (key)); |
255 | GNUNET_h2s (key)); | ||
256 | #endif | 253 | #endif |
257 | GNUNET_assert (GNUNET_YES == | 254 | GNUNET_assert (GNUNET_YES == |
258 | GNUNET_CONTAINER_multihashmap_remove (forward_map, | 255 | GNUNET_CONTAINER_multihashmap_remove (forward_map, key, |
259 | key, record)); | 256 | record)); |
260 | if (NULL != record->hnode) | 257 | if (NULL != record->hnode) |
261 | GNUNET_CONTAINER_heap_remove_node (record->hnode); | 258 | GNUNET_CONTAINER_heap_remove_node (record->hnode); |
262 | GNUNET_array_grow (record->seen_replies, | 259 | GNUNET_array_grow (record->seen_replies, record->seen_replies_count, 0); |
263 | record->seen_replies_count, | ||
264 | 0); | ||
265 | GNUNET_free (record); | 260 | GNUNET_free (record); |
266 | return GNUNET_YES; | 261 | return GNUNET_YES; |
267 | } | 262 | } |
@@ -276,37 +271,31 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value) | |||
276 | * for the last call when the server is destroyed | 271 | * for the last call when the server is destroyed |
277 | */ | 272 | */ |
278 | static void | 273 | static void |
279 | handle_client_disconnect (void *cls, | 274 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
280 | struct GNUNET_SERVER_Client *client) | ||
281 | { | 275 | { |
282 | struct ClientList *pos; | 276 | struct ClientList *pos; |
283 | struct PendingMessage *reply; | 277 | struct PendingMessage *reply; |
284 | 278 | ||
285 | #if DEBUG_DHT | 279 | #if DEBUG_DHT |
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Local client %p disconnects\n", client); |
287 | "Local client %p disconnects\n", | ||
288 | client); | ||
289 | #endif | 281 | #endif |
290 | pos = find_active_client (client); | 282 | pos = find_active_client (client); |
291 | GNUNET_CONTAINER_DLL_remove (client_head, | 283 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos); |
292 | client_tail, | ||
293 | pos); | ||
294 | if (pos->transmit_handle != NULL) | 284 | if (pos->transmit_handle != NULL) |
295 | GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->transmit_handle); | 285 | GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->transmit_handle); |
296 | while (NULL != (reply = pos->pending_head)) | 286 | while (NULL != (reply = pos->pending_head)) |
297 | { | 287 | { |
298 | GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, | 288 | GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, reply); |
299 | reply); | 289 | GNUNET_free (reply); |
300 | GNUNET_free (reply); | 290 | } |
301 | } | 291 | GNUNET_CONTAINER_multihashmap_iterate (forward_map, &remove_client_records, |
302 | GNUNET_CONTAINER_multihashmap_iterate (forward_map, | 292 | pos); |
303 | &remove_client_records, pos); | ||
304 | GNUNET_free (pos); | 293 | GNUNET_free (pos); |
305 | } | 294 | } |
306 | 295 | ||
307 | 296 | ||
308 | /** | 297 | /** |
309 | * Route the given request via the DHT. This includes updating | 298 | * Route the given request via the DHT. This includes updating |
310 | * the bloom filter and retransmission times, building the P2P | 299 | * the bloom filter and retransmission times, building the P2P |
311 | * message and initiating the routing operation. | 300 | * message and initiating the routing operation. |
312 | */ | 301 | */ |
@@ -318,33 +307,30 @@ transmit_request (struct ClientQueryRecord *cqr) | |||
318 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 307 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
319 | 308 | ||
320 | GNUNET_STATISTICS_update (GDS_stats, | 309 | GNUNET_STATISTICS_update (GDS_stats, |
321 | gettext_noop ("# GET requests from clients injected"), 1, | 310 | gettext_noop |
311 | ("# GET requests from clients injected"), 1, | ||
322 | GNUNET_NO); | 312 | GNUNET_NO); |
323 | reply_bf_mutator = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 313 | reply_bf_mutator = |
324 | UINT32_MAX); | 314 | (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
325 | reply_bf = GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, | 315 | UINT32_MAX); |
326 | cqr->seen_replies, | 316 | reply_bf = |
327 | cqr->seen_replies_count); | 317 | GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, cqr->seen_replies, |
328 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, | 318 | cqr->seen_replies_count); |
329 | DHT_BLOOM_SIZE, | 319 | peer_bf = |
330 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 320 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, |
331 | GDS_NEIGHBOURS_handle_get (cqr->type, | 321 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
332 | cqr->msg_options, | 322 | GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication, |
333 | cqr->replication, | 323 | 0 /* hop count */ , |
334 | 0 /* hop count */, | 324 | &cqr->key, cqr->xquery, cqr->xquery_size, reply_bf, |
335 | &cqr->key, | 325 | reply_bf_mutator, peer_bf); |
336 | cqr->xquery, | ||
337 | cqr->xquery_size, | ||
338 | reply_bf, | ||
339 | reply_bf_mutator, | ||
340 | peer_bf); | ||
341 | GNUNET_CONTAINER_bloomfilter_free (reply_bf); | 326 | GNUNET_CONTAINER_bloomfilter_free (reply_bf); |
342 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); | 327 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
343 | 328 | ||
344 | /* exponential back-off for retries, max 1h */ | 329 | /* exponential back-off for retries, max 1h */ |
345 | cqr->retry_frequency = | 330 | cqr->retry_frequency = |
346 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, | 331 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, |
347 | GNUNET_TIME_relative_multiply (cqr->retry_frequency, 2)); | 332 | GNUNET_TIME_relative_multiply |
333 | (cqr->retry_frequency, 2)); | ||
348 | cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency); | 334 | cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency); |
349 | } | 335 | } |
350 | 336 | ||
@@ -359,7 +345,7 @@ transmit_request (struct ClientQueryRecord *cqr) | |||
359 | */ | 345 | */ |
360 | static void | 346 | static void |
361 | transmit_next_request_task (void *cls, | 347 | transmit_next_request_task (void *cls, |
362 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 348 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
363 | { | 349 | { |
364 | struct ClientQueryRecord *cqr; | 350 | struct ClientQueryRecord *cqr; |
365 | struct GNUNET_TIME_Relative delay; | 351 | struct GNUNET_TIME_Relative delay; |
@@ -368,22 +354,24 @@ transmit_next_request_task (void *cls, | |||
368 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 354 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
369 | return; | 355 | return; |
370 | while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap))) | 356 | while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap))) |
357 | { | ||
358 | cqr->hnode = NULL; | ||
359 | delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time); | ||
360 | if (delay.rel_value > 0) | ||
371 | { | 361 | { |
372 | cqr->hnode = NULL; | 362 | cqr->hnode = |
373 | delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time); | 363 | GNUNET_CONTAINER_heap_insert (retry_heap, cqr, |
374 | if (delay.rel_value > 0) | 364 | cqr->retry_time.abs_value); |
375 | { | 365 | retry_task = |
376 | cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, | 366 | GNUNET_SCHEDULER_add_delayed (delay, &transmit_next_request_task, |
377 | cqr->retry_time.abs_value); | 367 | NULL); |
378 | retry_task = GNUNET_SCHEDULER_add_delayed (delay, | 368 | return; |
379 | &transmit_next_request_task, | ||
380 | NULL); | ||
381 | return; | ||
382 | } | ||
383 | transmit_request (cqr); | ||
384 | cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, | ||
385 | cqr->retry_time.abs_value); | ||
386 | } | 369 | } |
370 | transmit_request (cqr); | ||
371 | cqr->hnode = | ||
372 | GNUNET_CONTAINER_heap_insert (retry_heap, cqr, | ||
373 | cqr->retry_time.abs_value); | ||
374 | } | ||
387 | } | 375 | } |
388 | 376 | ||
389 | 377 | ||
@@ -396,58 +384,52 @@ transmit_next_request_task (void *cls, | |||
396 | */ | 384 | */ |
397 | static void | 385 | static void |
398 | handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, | 386 | handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, |
399 | const struct GNUNET_MessageHeader *message) | 387 | const struct GNUNET_MessageHeader *message) |
400 | { | 388 | { |
401 | const struct GNUNET_DHT_ClientPutMessage *dht_msg; | 389 | const struct GNUNET_DHT_ClientPutMessage *dht_msg; |
402 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 390 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
403 | uint16_t size; | 391 | uint16_t size; |
404 | 392 | ||
405 | size = ntohs (message->size); | 393 | size = ntohs (message->size); |
406 | if (size < sizeof (struct GNUNET_DHT_ClientPutMessage)) | 394 | if (size < sizeof (struct GNUNET_DHT_ClientPutMessage)) |
407 | { | 395 | { |
408 | GNUNET_break (0); | 396 | GNUNET_break (0); |
409 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 397 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
410 | return; | 398 | return; |
411 | } | 399 | } |
412 | GNUNET_STATISTICS_update (GDS_stats, | 400 | GNUNET_STATISTICS_update (GDS_stats, |
413 | gettext_noop ("# PUT requests received from clients"), 1, | 401 | gettext_noop |
402 | ("# PUT requests received from clients"), 1, | ||
414 | GNUNET_NO); | 403 | GNUNET_NO); |
415 | dht_msg = (const struct GNUNET_DHT_ClientPutMessage *) message; | 404 | dht_msg = (const struct GNUNET_DHT_ClientPutMessage *) message; |
416 | /* give to local clients */ | 405 | /* give to local clients */ |
417 | #if DEBUG_DHT | 406 | #if DEBUG_DHT |
418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
419 | "Handling local PUT of %u-bytes for query %s\n", | 408 | "Handling local PUT of %u-bytes for query %s\n", |
420 | size - sizeof (struct GNUNET_DHT_ClientPutMessage), | 409 | size - sizeof (struct GNUNET_DHT_ClientPutMessage), |
421 | GNUNET_h2s (&dht_msg->key)); | 410 | GNUNET_h2s (&dht_msg->key)); |
422 | #endif | 411 | #endif |
423 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), | 412 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), |
424 | &dht_msg->key, | 413 | &dht_msg->key, 0, NULL, 0, NULL, |
425 | 0, NULL, | 414 | ntohl (dht_msg->type), |
426 | 0, NULL, | 415 | size - sizeof (struct GNUNET_DHT_ClientPutMessage), |
427 | ntohl (dht_msg->type), | 416 | &dht_msg[1]); |
428 | size - sizeof (struct GNUNET_DHT_ClientPutMessage), | ||
429 | &dht_msg[1]); | ||
430 | /* store locally */ | 417 | /* store locally */ |
431 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), | 418 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), |
432 | &dht_msg->key, | 419 | &dht_msg->key, 0, NULL, ntohl (dht_msg->type), |
433 | 0, NULL, | 420 | size - sizeof (struct GNUNET_DHT_ClientPutMessage), |
434 | ntohl (dht_msg->type), | 421 | &dht_msg[1]); |
435 | size - sizeof (struct GNUNET_DHT_ClientPutMessage), | ||
436 | &dht_msg[1]); | ||
437 | /* route to other peers */ | 422 | /* route to other peers */ |
438 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, | 423 | peer_bf = |
439 | DHT_BLOOM_SIZE, | 424 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, |
440 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 425 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
441 | GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), | 426 | GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), ntohl (dht_msg->options), |
442 | ntohl (dht_msg->options), | 427 | ntohl (dht_msg->desired_replication_level), |
443 | ntohl (dht_msg->desired_replication_level), | 428 | GNUNET_TIME_absolute_ntoh (dht_msg->expiration), |
444 | GNUNET_TIME_absolute_ntoh (dht_msg->expiration), | 429 | 0 /* hop count */ , |
445 | 0 /* hop count */, | 430 | peer_bf, &dht_msg->key, 0, NULL, &dht_msg[1], |
446 | peer_bf, | 431 | size - |
447 | &dht_msg->key, | 432 | sizeof (struct GNUNET_DHT_ClientPutMessage)); |
448 | 0, NULL, | ||
449 | &dht_msg[1], | ||
450 | size - sizeof (struct GNUNET_DHT_ClientPutMessage)); | ||
451 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); | 433 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
452 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 434 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
453 | } | 435 | } |
@@ -464,58 +446,55 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, | |||
464 | */ | 446 | */ |
465 | static void | 447 | static void |
466 | handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client, | 448 | handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client, |
467 | const struct GNUNET_MessageHeader *message) | 449 | const struct GNUNET_MessageHeader *message) |
468 | { | 450 | { |
469 | const struct GNUNET_DHT_ClientGetMessage *get; | 451 | const struct GNUNET_DHT_ClientGetMessage *get; |
470 | struct ClientQueryRecord *cqr; | 452 | struct ClientQueryRecord *cqr; |
471 | size_t xquery_size; | 453 | size_t xquery_size; |
472 | const char* xquery; | 454 | const char *xquery; |
473 | uint16_t size; | 455 | uint16_t size; |
474 | 456 | ||
475 | size = ntohs (message->size); | 457 | size = ntohs (message->size); |
476 | if (size < sizeof (struct GNUNET_DHT_ClientGetMessage)) | 458 | if (size < sizeof (struct GNUNET_DHT_ClientGetMessage)) |
477 | { | 459 | { |
478 | GNUNET_break (0); | 460 | GNUNET_break (0); |
479 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 461 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
480 | return; | 462 | return; |
481 | } | 463 | } |
482 | xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage); | 464 | xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage); |
483 | get = (const struct GNUNET_DHT_ClientGetMessage *) message; | 465 | get = (const struct GNUNET_DHT_ClientGetMessage *) message; |
484 | xquery = (const char*) &get[1]; | 466 | xquery = (const char *) &get[1]; |
485 | GNUNET_STATISTICS_update (GDS_stats, | 467 | GNUNET_STATISTICS_update (GDS_stats, |
486 | gettext_noop ("# GET requests received from clients"), 1, | 468 | gettext_noop |
469 | ("# GET requests received from clients"), 1, | ||
487 | GNUNET_NO); | 470 | GNUNET_NO); |
488 | #if DEBUG_DHT | 471 | #if DEBUG_DHT |
489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
490 | "Received request for %s from local client %p\n", | 473 | "Received request for %s from local client %p\n", |
491 | GNUNET_h2s (&get->key), | 474 | GNUNET_h2s (&get->key), client); |
492 | client); | ||
493 | #endif | 475 | #endif |
494 | cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size); | 476 | cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size); |
495 | cqr->key = get->key; | 477 | cqr->key = get->key; |
496 | cqr->client = find_active_client (client); | 478 | cqr->client = find_active_client (client); |
497 | cqr->xquery = (void*) &cqr[1]; | 479 | cqr->xquery = (void *) &cqr[1]; |
498 | memcpy (&cqr[1], xquery, xquery_size); | 480 | memcpy (&cqr[1], xquery, xquery_size); |
499 | cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); | 481 | cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); |
500 | cqr->retry_frequency = GNUNET_TIME_UNIT_MILLISECONDS; | 482 | cqr->retry_frequency = GNUNET_TIME_UNIT_MILLISECONDS; |
501 | cqr->retry_time = GNUNET_TIME_absolute_get (); | 483 | cqr->retry_time = GNUNET_TIME_absolute_get (); |
502 | cqr->unique_id = get->unique_id; | 484 | cqr->unique_id = get->unique_id; |
503 | cqr->xquery_size = xquery_size; | 485 | cqr->xquery_size = xquery_size; |
504 | cqr->replication = ntohl (get->desired_replication_level); | 486 | cqr->replication = ntohl (get->desired_replication_level); |
505 | cqr->msg_options = ntohl (get->options); | 487 | cqr->msg_options = ntohl (get->options); |
506 | cqr->type = ntohl (get->type); | 488 | cqr->type = ntohl (get->type); |
507 | GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr, | 489 | GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr, |
508 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 490 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
509 | /* start remote requests */ | 491 | /* start remote requests */ |
510 | if (GNUNET_SCHEDULER_NO_TASK != retry_task) | 492 | if (GNUNET_SCHEDULER_NO_TASK != retry_task) |
511 | GNUNET_SCHEDULER_cancel (retry_task); | 493 | GNUNET_SCHEDULER_cancel (retry_task); |
512 | retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL); | 494 | retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL); |
513 | /* perform local lookup */ | 495 | /* perform local lookup */ |
514 | GDS_DATACACHE_handle_get (&get->key, | 496 | GDS_DATACACHE_handle_get (&get->key, cqr->type, cqr->xquery, xquery_size, |
515 | cqr->type, | 497 | NULL, 0); |
516 | cqr->xquery, | ||
517 | xquery_size, | ||
518 | NULL, 0); | ||
519 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 498 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
520 | } | 499 | } |
521 | 500 | ||
@@ -538,7 +517,7 @@ struct RemoveByUniqueIdContext | |||
538 | 517 | ||
539 | 518 | ||
540 | /** | 519 | /** |
541 | * Iterator over hash map entries that frees all entries | 520 | * Iterator over hash map entries that frees all entries |
542 | * that match the given client and unique ID. | 521 | * that match the given client and unique ID. |
543 | * | 522 | * |
544 | * @param cls unique ID and client to search for in source routes | 523 | * @param cls unique ID and client to search for in source routes |
@@ -556,9 +535,8 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value) | |||
556 | return GNUNET_YES; | 535 | return GNUNET_YES; |
557 | #if DEBUG_DHT | 536 | #if DEBUG_DHT |
558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
559 | "Removing client %p's record for key %s (by unique id)\n", | 538 | "Removing client %p's record for key %s (by unique id)\n", |
560 | ctx->client->client_handle, | 539 | ctx->client->client_handle, GNUNET_h2s (key)); |
561 | GNUNET_h2s (key)); | ||
562 | #endif | 540 | #endif |
563 | return remove_client_records (ctx->client, key, record); | 541 | return remove_client_records (ctx->client, key, record); |
564 | } | 542 | } |
@@ -575,27 +553,24 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value) | |||
575 | */ | 553 | */ |
576 | static void | 554 | static void |
577 | handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client, | 555 | handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client, |
578 | const struct GNUNET_MessageHeader *message) | 556 | const struct GNUNET_MessageHeader *message) |
579 | { | 557 | { |
580 | const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg = | 558 | const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg = |
581 | (const struct GNUNET_DHT_ClientGetStopMessage *) message; | 559 | (const struct GNUNET_DHT_ClientGetStopMessage *) message; |
582 | struct RemoveByUniqueIdContext ctx; | 560 | struct RemoveByUniqueIdContext ctx; |
583 | 561 | ||
584 | GNUNET_STATISTICS_update (GDS_stats, | 562 | GNUNET_STATISTICS_update (GDS_stats, |
585 | gettext_noop ("# GET STOP requests received from clients"), 1, | 563 | gettext_noop |
564 | ("# GET STOP requests received from clients"), 1, | ||
586 | GNUNET_NO); | 565 | GNUNET_NO); |
587 | #if DEBUG_DHT | 566 | #if DEBUG_DHT |
588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p stopped request for key %s\n", |
589 | "Client %p stopped request for key %s\n", | 568 | client, GNUNET_h2s (&dht_stop_msg->key)); |
590 | client, | ||
591 | GNUNET_h2s (&dht_stop_msg->key)); | ||
592 | #endif | 569 | #endif |
593 | ctx.client = find_active_client (client); | 570 | ctx.client = find_active_client (client); |
594 | ctx.unique_id = dht_stop_msg->unique_id; | 571 | ctx.unique_id = dht_stop_msg->unique_id; |
595 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, | 572 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, &dht_stop_msg->key, |
596 | &dht_stop_msg->key, | 573 | &remove_by_unique_id, &ctx); |
597 | &remove_by_unique_id, | ||
598 | &ctx); | ||
599 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 574 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
600 | } | 575 | } |
601 | 576 | ||
@@ -636,8 +611,8 @@ send_reply_to_client (void *cls, size_t size, void *buf) | |||
636 | /* client disconnected */ | 611 | /* client disconnected */ |
637 | #if DEBUG_DHT | 612 | #if DEBUG_DHT |
638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
639 | "Client %p disconnected, pending messages will be discarded\n", | 614 | "Client %p disconnected, pending messages will be discarded\n", |
640 | client->client_handle); | 615 | client->client_handle); |
641 | #endif | 616 | #endif |
642 | return 0; | 617 | return 0; |
643 | } | 618 | } |
@@ -650,20 +625,15 @@ send_reply_to_client (void *cls, size_t size, void *buf) | |||
650 | memcpy (&cbuf[off], reply->msg, msize); | 625 | memcpy (&cbuf[off], reply->msg, msize); |
651 | GNUNET_free (reply); | 626 | GNUNET_free (reply); |
652 | #if DEBUG_DHT | 627 | #if DEBUG_DHT |
653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to client %p\n", |
654 | "Transmitting %u bytes to client %p\n", | 629 | msize, client->client_handle); |
655 | msize, | ||
656 | client->client_handle); | ||
657 | #endif | 630 | #endif |
658 | off += msize; | 631 | off += msize; |
659 | } | 632 | } |
660 | process_pending_messages (client); | 633 | process_pending_messages (client); |
661 | #if DEBUG_DHT | 634 | #if DEBUG_DHT |
662 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 635 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitted %u/%u bytes to client %p\n", |
663 | "Transmitted %u/%u bytes to client %p\n", | 636 | (unsigned int) off, (unsigned int) size, client->client_handle); |
664 | (unsigned int) off, | ||
665 | (unsigned int) size, | ||
666 | client->client_handle); | ||
667 | #endif | 637 | #endif |
668 | return off; | 638 | return off; |
669 | } | 639 | } |
@@ -681,20 +651,17 @@ process_pending_messages (struct ClientList *client) | |||
681 | { | 651 | { |
682 | #if DEBUG_DHT | 652 | #if DEBUG_DHT |
683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
684 | "Not asking for transmission to %p now: %s\n", | 654 | "Not asking for transmission to %p now: %s\n", |
685 | client->client_handle, | 655 | client->client_handle, |
686 | client->pending_head == NULL | 656 | client->pending_head == |
687 | ? "no more messages" | 657 | NULL ? "no more messages" : "request already pending"); |
688 | : "request already pending"); | ||
689 | #endif | 658 | #endif |
690 | return; | 659 | return; |
691 | } | 660 | } |
692 | #if DEBUG_DHT | 661 | #if DEBUG_DHT |
693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 662 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
694 | "Asking for transmission of %u bytes to client %p\n", | 663 | "Asking for transmission of %u bytes to client %p\n", |
695 | ntohs (client->pending_head-> | 664 | ntohs (client->pending_head->msg->size), client->client_handle); |
696 | msg->size), | ||
697 | client->client_handle); | ||
698 | #endif | 665 | #endif |
699 | client->transmit_handle = | 666 | client->transmit_handle = |
700 | GNUNET_SERVER_notify_transmit_ready (client->client_handle, | 667 | GNUNET_SERVER_notify_transmit_ready (client->client_handle, |
@@ -716,7 +683,7 @@ add_pending_message (struct ClientList *client, | |||
716 | struct PendingMessage *pending_message) | 683 | struct PendingMessage *pending_message) |
717 | { | 684 | { |
718 | GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail, | 685 | GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail, |
719 | pending_message); | 686 | pending_message); |
720 | process_pending_messages (client); | 687 | process_pending_messages (client); |
721 | } | 688 | } |
722 | 689 | ||
@@ -728,7 +695,7 @@ struct ForwardReplyContext | |||
728 | { | 695 | { |
729 | 696 | ||
730 | /** | 697 | /** |
731 | * Actual message to send to matching clients. | 698 | * Actual message to send to matching clients. |
732 | */ | 699 | */ |
733 | struct PendingMessage *pm; | 700 | struct PendingMessage *pm; |
734 | 701 | ||
@@ -777,51 +744,43 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) | |||
777 | int do_free; | 744 | int do_free; |
778 | GNUNET_HashCode ch; | 745 | GNUNET_HashCode ch; |
779 | unsigned int i; | 746 | unsigned int i; |
780 | 747 | ||
781 | if ( (record->type != GNUNET_BLOCK_TYPE_ANY) && | 748 | if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type)) |
782 | (record->type != frc->type) ) | 749 | { |
750 | #if DEBUG_DHT | ||
751 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
752 | "Record type missmatch, not passing request for key %s to local client\n", | ||
753 | GNUNET_h2s (key)); | ||
754 | #endif | ||
755 | GNUNET_STATISTICS_update (GDS_stats, | ||
756 | gettext_noop | ||
757 | ("# Key match, type mismatches in REPLY to CLIENT"), | ||
758 | 1, GNUNET_NO); | ||
759 | return GNUNET_YES; /* type mismatch */ | ||
760 | } | ||
761 | GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch); | ||
762 | for (i = 0; i < record->seen_replies_count; i++) | ||
763 | if (0 == memcmp (&record->seen_replies[i], &ch, sizeof (GNUNET_HashCode))) | ||
783 | { | 764 | { |
784 | #if DEBUG_DHT | 765 | #if DEBUG_DHT |
785 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
786 | "Record type missmatch, not passing request for key %s to local client\n", | 767 | "Duplicate reply, not passing request for key %s to local client\n", |
787 | GNUNET_h2s (key)); | 768 | GNUNET_h2s (key)); |
788 | #endif | 769 | #endif |
789 | GNUNET_STATISTICS_update (GDS_stats, | 770 | GNUNET_STATISTICS_update (GDS_stats, |
790 | gettext_noop ("# Key match, type mismatches in REPLY to CLIENT"), 1, | 771 | gettext_noop |
791 | GNUNET_NO); | 772 | ("# Duplicate REPLIES to CLIENT request dropped"), |
792 | return GNUNET_YES; /* type mismatch */ | 773 | 1, GNUNET_NO); |
774 | return GNUNET_YES; /* duplicate */ | ||
793 | } | 775 | } |
794 | GNUNET_CRYPTO_hash (frc->data, | ||
795 | frc->data_size, | ||
796 | &ch); | ||
797 | for (i=0;i<record->seen_replies_count;i++) | ||
798 | if (0 == memcmp (&record->seen_replies[i], | ||
799 | &ch, | ||
800 | sizeof (GNUNET_HashCode))) | ||
801 | { | ||
802 | #if DEBUG_DHT | ||
803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
804 | "Duplicate reply, not passing request for key %s to local client\n", | ||
805 | GNUNET_h2s (key)); | ||
806 | #endif | ||
807 | GNUNET_STATISTICS_update (GDS_stats, | ||
808 | gettext_noop ("# Duplicate REPLIES to CLIENT request dropped"), 1, | ||
809 | GNUNET_NO); | ||
810 | return GNUNET_YES; /* duplicate */ | ||
811 | } | ||
812 | eval = | 776 | eval = |
813 | GNUNET_BLOCK_evaluate (GDS_block_context, | 777 | GNUNET_BLOCK_evaluate (GDS_block_context, record->type, key, NULL, 0, |
814 | record->type, key, | 778 | record->xquery, record->xquery_size, frc->data, |
815 | NULL, 0, | 779 | frc->data_size); |
816 | record->xquery, | ||
817 | record->xquery_size, | ||
818 | frc->data, | ||
819 | frc->data_size); | ||
820 | #if DEBUG_DHT | 780 | #if DEBUG_DHT |
821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 781 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
822 | "Evaluation result is %d for key %s for local client's query\n", | 782 | "Evaluation result is %d for key %s for local client's query\n", |
823 | (int) eval, | 783 | (int) eval, GNUNET_h2s (key)); |
824 | GNUNET_h2s (key)); | ||
825 | #endif | 784 | #endif |
826 | switch (eval) | 785 | switch (eval) |
827 | { | 786 | { |
@@ -829,9 +788,7 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) | |||
829 | do_free = GNUNET_YES; | 788 | do_free = GNUNET_YES; |
830 | break; | 789 | break; |
831 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 790 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
832 | GNUNET_array_append (record->seen_replies, | 791 | GNUNET_array_append (record->seen_replies, record->seen_replies_count, ch); |
833 | record->seen_replies_count, | ||
834 | ch); | ||
835 | do_free = GNUNET_NO; | 792 | do_free = GNUNET_NO; |
836 | break; | 793 | break; |
837 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 794 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
@@ -849,38 +806,36 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) | |||
849 | return GNUNET_NO; | 806 | return GNUNET_NO; |
850 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 807 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
851 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 808 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
852 | _("Unsupported block type (%u) in request!\n"), | 809 | _("Unsupported block type (%u) in request!\n"), record->type); |
853 | record->type); | ||
854 | return GNUNET_NO; | 810 | return GNUNET_NO; |
855 | default: | 811 | default: |
856 | GNUNET_break (0); | 812 | GNUNET_break (0); |
857 | return GNUNET_NO; | 813 | return GNUNET_NO; |
858 | } | 814 | } |
859 | if (GNUNET_NO == frc->do_copy) | 815 | if (GNUNET_NO == frc->do_copy) |
860 | { | 816 | { |
861 | /* first time, we can use the original data */ | 817 | /* first time, we can use the original data */ |
862 | pm = frc->pm; | 818 | pm = frc->pm; |
863 | frc->do_copy = GNUNET_YES; | 819 | frc->do_copy = GNUNET_YES; |
864 | } | 820 | } |
865 | else | 821 | else |
866 | { | 822 | { |
867 | /* two clients waiting for same reply, must copy for queueing */ | 823 | /* two clients waiting for same reply, must copy for queueing */ |
868 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + | 824 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + |
869 | ntohs (frc->pm->msg->size)); | 825 | ntohs (frc->pm->msg->size)); |
870 | memcpy (pm, frc->pm, | 826 | memcpy (pm, frc->pm, |
871 | sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size)); | 827 | sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size)); |
872 | pm->next = pm->prev = NULL; | 828 | pm->next = pm->prev = NULL; |
873 | } | 829 | } |
874 | GNUNET_STATISTICS_update (GDS_stats, | 830 | GNUNET_STATISTICS_update (GDS_stats, |
875 | gettext_noop ("# RESULTS queued for clients"), 1, | 831 | gettext_noop ("# RESULTS queued for clients"), 1, |
876 | GNUNET_NO); | 832 | GNUNET_NO); |
877 | reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; | 833 | reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; |
878 | reply->unique_id = record->unique_id; | 834 | reply->unique_id = record->unique_id; |
879 | #if DEBUG_DHT | 835 | #if DEBUG_DHT |
880 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
881 | "Queueing reply to query %s for client %p\n", | 837 | "Queueing reply to query %s for client %p\n", GNUNET_h2s (key), |
882 | GNUNET_h2s (key), | 838 | record->client->client_handle); |
883 | record->client->client_handle); | ||
884 | #endif | 839 | #endif |
885 | add_pending_message (record->client, pm); | 840 | add_pending_message (record->client, pm); |
886 | if (GNUNET_YES == do_free) | 841 | if (GNUNET_YES == do_free) |
@@ -906,14 +861,13 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) | |||
906 | */ | 861 | */ |
907 | void | 862 | void |
908 | GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | 863 | GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, |
909 | const GNUNET_HashCode *key, | 864 | const GNUNET_HashCode * key, |
910 | unsigned int get_path_length, | 865 | unsigned int get_path_length, |
911 | const struct GNUNET_PeerIdentity *get_path, | 866 | const struct GNUNET_PeerIdentity *get_path, |
912 | unsigned int put_path_length, | 867 | unsigned int put_path_length, |
913 | const struct GNUNET_PeerIdentity *put_path, | 868 | const struct GNUNET_PeerIdentity *put_path, |
914 | enum GNUNET_BLOCK_Type type, | 869 | enum GNUNET_BLOCK_Type type, size_t data_size, |
915 | size_t data_size, | 870 | const void *data) |
916 | const void *data) | ||
917 | { | 871 | { |
918 | struct ForwardReplyContext frc; | 872 | struct ForwardReplyContext frc; |
919 | struct PendingMessage *pm; | 873 | struct PendingMessage *pm; |
@@ -921,57 +875,57 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | |||
921 | struct GNUNET_PeerIdentity *paths; | 875 | struct GNUNET_PeerIdentity *paths; |
922 | size_t msize; | 876 | size_t msize; |
923 | 877 | ||
924 | if (NULL == | 878 | if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key)) |
925 | GNUNET_CONTAINER_multihashmap_get (forward_map, key)) | ||
926 | { | 879 | { |
927 | GNUNET_STATISTICS_update (GDS_stats, | 880 | GNUNET_STATISTICS_update (GDS_stats, |
928 | gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, | 881 | gettext_noop |
929 | GNUNET_NO); | 882 | ("# REPLIES ignored for CLIENTS (no match)"), 1, |
930 | return; /* no matching request, fast exit! */ | 883 | GNUNET_NO); |
884 | return; /* no matching request, fast exit! */ | ||
931 | } | 885 | } |
932 | msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size + | 886 | msize = |
933 | (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); | 887 | sizeof (struct GNUNET_DHT_ClientResultMessage) + data_size + |
888 | (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); | ||
934 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 889 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
935 | { | 890 | { |
936 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 891 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
937 | _("Could not pass reply to client, message too big!\n")); | 892 | _("Could not pass reply to client, message too big!\n")); |
938 | return; | 893 | return; |
939 | } | 894 | } |
940 | pm = (struct PendingMessage *) GNUNET_malloc (msize + sizeof (struct PendingMessage)); | 895 | pm = (struct PendingMessage *) GNUNET_malloc (msize + |
941 | reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; | 896 | sizeof (struct PendingMessage)); |
897 | reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; | ||
942 | pm->msg = &reply->header; | 898 | pm->msg = &reply->header; |
943 | reply->header.size = htons ((uint16_t) msize); | 899 | reply->header.size = htons ((uint16_t) msize); |
944 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); | 900 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); |
945 | reply->type = htonl (type); | 901 | reply->type = htonl (type); |
946 | reply->get_path_length = htonl (get_path_length); | 902 | reply->get_path_length = htonl (get_path_length); |
947 | reply->put_path_length = htonl (put_path_length); | 903 | reply->put_path_length = htonl (put_path_length); |
948 | reply->unique_id = 0; /* filled in later */ | 904 | reply->unique_id = 0; /* filled in later */ |
949 | reply->expiration = GNUNET_TIME_absolute_hton (expiration); | 905 | reply->expiration = GNUNET_TIME_absolute_hton (expiration); |
950 | reply->key = *key; | 906 | reply->key = *key; |
951 | paths = (struct GNUNET_PeerIdentity*) &reply[1]; | 907 | paths = (struct GNUNET_PeerIdentity *) &reply[1]; |
952 | memcpy (paths, put_path, | 908 | memcpy (paths, put_path, |
953 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | 909 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); |
954 | memcpy (&paths[put_path_length], | 910 | memcpy (&paths[put_path_length], get_path, |
955 | get_path, sizeof (struct GNUNET_PeerIdentity) * get_path_length); | 911 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); |
956 | memcpy (&paths[get_path_length + put_path_length], | 912 | memcpy (&paths[get_path_length + put_path_length], data, data_size); |
957 | data, | ||
958 | data_size); | ||
959 | frc.do_copy = GNUNET_NO; | 913 | frc.do_copy = GNUNET_NO; |
960 | frc.pm = pm; | 914 | frc.pm = pm; |
961 | frc.data = data; | 915 | frc.data = data; |
962 | frc.data_size = data_size; | 916 | frc.data_size = data_size; |
963 | frc.type = type; | 917 | frc.type = type; |
964 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, | 918 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply, |
965 | &forward_reply, | 919 | &frc); |
966 | &frc); | ||
967 | if (GNUNET_NO == frc.do_copy) | 920 | if (GNUNET_NO == frc.do_copy) |
968 | { | 921 | { |
969 | /* did not match any of the requests, free! */ | 922 | /* did not match any of the requests, free! */ |
970 | GNUNET_STATISTICS_update (GDS_stats, | 923 | GNUNET_STATISTICS_update (GDS_stats, |
971 | gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, | 924 | gettext_noop |
972 | GNUNET_NO); | 925 | ("# REPLIES ignored for CLIENTS (no match)"), 1, |
973 | GNUNET_free (pm); | 926 | GNUNET_NO); |
974 | } | 927 | GNUNET_free (pm); |
928 | } | ||
975 | } | 929 | } |
976 | 930 | ||
977 | 931 | ||
@@ -980,17 +934,17 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | |||
980 | * | 934 | * |
981 | * @param server the initialized server | 935 | * @param server the initialized server |
982 | */ | 936 | */ |
983 | void | 937 | void |
984 | GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server) | 938 | GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server) |
985 | { | 939 | { |
986 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | 940 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { |
987 | {&handle_dht_local_put, NULL, | 941 | {&handle_dht_local_put, NULL, |
988 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, 0}, | 942 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, 0}, |
989 | {&handle_dht_local_get, NULL, | 943 | {&handle_dht_local_get, NULL, |
990 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, 0}, | 944 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, 0}, |
991 | {&handle_dht_local_get_stop, NULL, | 945 | {&handle_dht_local_get_stop, NULL, |
992 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, | 946 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, |
993 | sizeof (struct GNUNET_DHT_ClientGetStopMessage) }, | 947 | sizeof (struct GNUNET_DHT_ClientGetStopMessage)}, |
994 | {NULL, NULL, 0, 0} | 948 | {NULL, NULL, 0, 0} |
995 | }; | 949 | }; |
996 | forward_map = GNUNET_CONTAINER_multihashmap_create (1024); | 950 | forward_map = GNUNET_CONTAINER_multihashmap_create (1024); |
@@ -1009,10 +963,10 @@ GDS_CLIENTS_done () | |||
1009 | GNUNET_assert (client_head == NULL); | 963 | GNUNET_assert (client_head == NULL); |
1010 | GNUNET_assert (client_tail == NULL); | 964 | GNUNET_assert (client_tail == NULL); |
1011 | if (GNUNET_SCHEDULER_NO_TASK != retry_task) | 965 | if (GNUNET_SCHEDULER_NO_TASK != retry_task) |
1012 | { | 966 | { |
1013 | GNUNET_SCHEDULER_cancel (retry_task); | 967 | GNUNET_SCHEDULER_cancel (retry_task); |
1014 | retry_task = GNUNET_SCHEDULER_NO_TASK; | 968 | retry_task = GNUNET_SCHEDULER_NO_TASK; |
1015 | } | 969 | } |
1016 | GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap)); | 970 | GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap)); |
1017 | GNUNET_CONTAINER_heap_destroy (retry_heap); | 971 | GNUNET_CONTAINER_heap_destroy (retry_heap); |
1018 | retry_heap = NULL; | 972 | retry_heap = NULL; |
@@ -1022,4 +976,3 @@ GDS_CLIENTS_done () | |||
1022 | } | 976 | } |
1023 | 977 | ||
1024 | /* end of gnunet-service-dht_clients.c */ | 978 | /* end of gnunet-service-dht_clients.c */ |
1025 | |||
diff --git a/src/dht/gnunet-service-dht_clients.h b/src/dht/gnunet-service-dht_clients.h index 66fa433c0..21b2343e7 100644 --- a/src/dht/gnunet-service-dht_clients.h +++ b/src/dht/gnunet-service-dht_clients.h | |||
@@ -47,14 +47,13 @@ | |||
47 | */ | 47 | */ |
48 | void | 48 | void |
49 | GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | 49 | GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, |
50 | const GNUNET_HashCode *key, | 50 | const GNUNET_HashCode * key, |
51 | unsigned int get_path_length, | 51 | unsigned int get_path_length, |
52 | const struct GNUNET_PeerIdentity *get_path, | 52 | const struct GNUNET_PeerIdentity *get_path, |
53 | unsigned int put_path_length, | 53 | unsigned int put_path_length, |
54 | const struct GNUNET_PeerIdentity *put_path, | 54 | const struct GNUNET_PeerIdentity *put_path, |
55 | enum GNUNET_BLOCK_Type type, | 55 | enum GNUNET_BLOCK_Type type, size_t data_size, |
56 | size_t data_size, | 56 | const void *data); |
57 | const void *data); | ||
58 | 57 | ||
59 | 58 | ||
60 | /** | 59 | /** |
@@ -62,7 +61,7 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | |||
62 | * | 61 | * |
63 | * @param server the initialized server | 62 | * @param server the initialized server |
64 | */ | 63 | */ |
65 | void | 64 | void |
66 | GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server); | 65 | GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server); |
67 | 66 | ||
68 | 67 | ||
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index f3b2e5b2f..82cd06727 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c | |||
@@ -74,44 +74,42 @@ struct DHTPutEntry | |||
74 | */ | 74 | */ |
75 | void | 75 | void |
76 | GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | 76 | GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, |
77 | const GNUNET_HashCode *key, | 77 | const GNUNET_HashCode * key, |
78 | unsigned int put_path_length, | 78 | unsigned int put_path_length, |
79 | const struct GNUNET_PeerIdentity *put_path, | 79 | const struct GNUNET_PeerIdentity *put_path, |
80 | enum GNUNET_BLOCK_Type type, | 80 | enum GNUNET_BLOCK_Type type, size_t data_size, |
81 | size_t data_size, | 81 | const void *data) |
82 | const void *data) | ||
83 | { | 82 | { |
84 | size_t plen = data_size + put_path_length * sizeof(struct GNUNET_PeerIdentity) + sizeof(struct DHTPutEntry); | 83 | size_t plen = |
84 | data_size + put_path_length * sizeof (struct GNUNET_PeerIdentity) + | ||
85 | sizeof (struct DHTPutEntry); | ||
85 | char buf[plen]; | 86 | char buf[plen]; |
86 | struct DHTPutEntry *pe; | 87 | struct DHTPutEntry *pe; |
87 | struct GNUNET_PeerIdentity *pp; | 88 | struct GNUNET_PeerIdentity *pp; |
88 | 89 | ||
89 | if (datacache == NULL) | 90 | if (datacache == NULL) |
90 | { | 91 | { |
91 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 92 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
92 | _("%s request received, but have no datacache!\n"), | 93 | _("%s request received, but have no datacache!\n"), "PUT"); |
93 | "PUT"); | 94 | return; |
94 | return; | 95 | } |
95 | } | ||
96 | if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 96 | if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
97 | { | 97 | { |
98 | GNUNET_break (0); | 98 | GNUNET_break (0); |
99 | return; | 99 | return; |
100 | } | 100 | } |
101 | /* Put size is actual data size plus struct overhead plus path length (if any) */ | 101 | /* Put size is actual data size plus struct overhead plus path length (if any) */ |
102 | GNUNET_STATISTICS_update (GDS_stats, | 102 | GNUNET_STATISTICS_update (GDS_stats, |
103 | gettext_noop ("# ITEMS stored in datacache"), 1, | 103 | gettext_noop ("# ITEMS stored in datacache"), 1, |
104 | GNUNET_NO); | 104 | GNUNET_NO); |
105 | pe = (struct DHTPutEntry *) buf; | 105 | pe = (struct DHTPutEntry *) buf; |
106 | pe->data_size = htons (data_size); | 106 | pe->data_size = htons (data_size); |
107 | pe->path_length = htons ((uint16_t) put_path_length); | 107 | pe->path_length = htons ((uint16_t) put_path_length); |
108 | pp = (struct GNUNET_PeerIdentity *) &pe[1]; | 108 | pp = (struct GNUNET_PeerIdentity *) &pe[1]; |
109 | memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); | 109 | memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); |
110 | memcpy (&pp[put_path_length], | 110 | memcpy (&pp[put_path_length], data, data_size); |
111 | data, data_size); | 111 | (void) GNUNET_DATACACHE_put (datacache, key, plen, (const char *) pe, type, |
112 | (void) GNUNET_DATACACHE_put (datacache, key, | 112 | expiration); |
113 | plen, (const char *) pe, type, | ||
114 | expiration); | ||
115 | } | 113 | } |
116 | 114 | ||
117 | 115 | ||
@@ -190,20 +188,15 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
190 | return GNUNET_OK; | 188 | return GNUNET_OK; |
191 | } | 189 | } |
192 | pp = (const struct GNUNET_PeerIdentity *) &pe[1]; | 190 | pp = (const struct GNUNET_PeerIdentity *) &pe[1]; |
193 | rdata = (const char*) &pp[put_path_length]; | 191 | rdata = (const char *) &pp[put_path_length]; |
194 | eval = | 192 | eval = |
195 | GNUNET_BLOCK_evaluate (GDS_block_context, type, key, | 193 | GNUNET_BLOCK_evaluate (GDS_block_context, type, key, ctx->reply_bf, |
196 | ctx->reply_bf, | 194 | ctx->reply_bf_mutator, ctx->xquery, |
197 | ctx->reply_bf_mutator, | 195 | ctx->xquery_size, rdata, rdata_size); |
198 | ctx->xquery, | ||
199 | ctx->xquery_size, | ||
200 | rdata, | ||
201 | rdata_size); | ||
202 | #if DEBUG_DHT | 196 | #if DEBUG_DHT |
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
204 | "Found reply for query %s in datacache, evaluation result is %d\n", | 198 | "Found reply for query %s in datacache, evaluation result is %d\n", |
205 | GNUNET_h2s (key), | 199 | GNUNET_h2s (key), (int) eval); |
206 | (int) eval); | ||
207 | #endif | 200 | #endif |
208 | ctx->eval = eval; | 201 | ctx->eval = eval; |
209 | switch (eval) | 202 | switch (eval) |
@@ -212,27 +205,26 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
212 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 205 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
213 | /* forward to local clients */ | 206 | /* forward to local clients */ |
214 | GNUNET_STATISTICS_update (GDS_stats, | 207 | GNUNET_STATISTICS_update (GDS_stats, |
215 | gettext_noop ("# Good RESULTS found in datacache"), 1, | 208 | gettext_noop |
216 | GNUNET_NO); | 209 | ("# Good RESULTS found in datacache"), 1, |
217 | GDS_CLIENTS_handle_reply (exp, | 210 | GNUNET_NO); |
218 | key, | 211 | GDS_CLIENTS_handle_reply (exp, key, 0, NULL, put_path_length, pp, type, |
219 | 0, NULL, | 212 | rdata_size, rdata); |
220 | put_path_length, pp, | ||
221 | type, rdata_size, rdata); | ||
222 | /* forward to other peers */ | 213 | /* forward to other peers */ |
223 | GDS_ROUTING_process (type, exp, | 214 | GDS_ROUTING_process (type, exp, key, put_path_length, pp, 0, NULL, rdata, |
224 | key, put_path_length, pp, | 215 | rdata_size); |
225 | 0, NULL, rdata, rdata_size); | ||
226 | break; | 216 | break; |
227 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 217 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
228 | GNUNET_STATISTICS_update (GDS_stats, | 218 | GNUNET_STATISTICS_update (GDS_stats, |
229 | gettext_noop ("# Duplicate RESULTS found in datacache"), 1, | 219 | gettext_noop |
230 | GNUNET_NO); | 220 | ("# Duplicate RESULTS found in datacache"), 1, |
221 | GNUNET_NO); | ||
231 | break; | 222 | break; |
232 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 223 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
233 | GNUNET_STATISTICS_update (GDS_stats, | 224 | GNUNET_STATISTICS_update (GDS_stats, |
234 | gettext_noop ("# Invalid RESULTS found in datacache"), 1, | 225 | gettext_noop |
235 | GNUNET_NO); | 226 | ("# Invalid RESULTS found in datacache"), 1, |
227 | GNUNET_NO); | ||
236 | break; | 228 | break; |
237 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | 229 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: |
238 | GNUNET_break (0); | 230 | GNUNET_break (0); |
@@ -242,11 +234,11 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
242 | return GNUNET_SYSERR; | 234 | return GNUNET_SYSERR; |
243 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 235 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
244 | GNUNET_STATISTICS_update (GDS_stats, | 236 | GNUNET_STATISTICS_update (GDS_stats, |
245 | gettext_noop ("# Unsupported RESULTS found in datacache"), 1, | 237 | gettext_noop |
246 | GNUNET_NO); | 238 | ("# Unsupported RESULTS found in datacache"), 1, |
239 | GNUNET_NO); | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
248 | _("Unsupported block type (%u) in local response!\n"), | 241 | _("Unsupported block type (%u) in local response!\n"), type); |
249 | type); | ||
250 | break; | 242 | break; |
251 | } | 243 | } |
252 | return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; | 244 | return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; |
@@ -256,7 +248,7 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
256 | /** | 248 | /** |
257 | * Handle a GET request we've received from another peer. | 249 | * Handle a GET request we've received from another peer. |
258 | * | 250 | * |
259 | * @param key the query | 251 | * @param key the query |
260 | * @param type requested data type | 252 | * @param type requested data type |
261 | * @param xquery extended query | 253 | * @param xquery extended query |
262 | * @param xquery_size number of bytes in xquery | 254 | * @param xquery_size number of bytes in xquery |
@@ -265,28 +257,27 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
265 | * @return evaluation result for the local replies | 257 | * @return evaluation result for the local replies |
266 | */ | 258 | */ |
267 | enum GNUNET_BLOCK_EvaluationResult | 259 | enum GNUNET_BLOCK_EvaluationResult |
268 | GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, | 260 | GDS_DATACACHE_handle_get (const GNUNET_HashCode * key, |
269 | enum GNUNET_BLOCK_Type type, | 261 | enum GNUNET_BLOCK_Type type, const void *xquery, |
270 | const void *xquery, | 262 | size_t xquery_size, |
271 | size_t xquery_size, | 263 | struct GNUNET_CONTAINER_BloomFilter **reply_bf, |
272 | struct GNUNET_CONTAINER_BloomFilter **reply_bf, | 264 | uint32_t reply_bf_mutator) |
273 | uint32_t reply_bf_mutator) | ||
274 | { | 265 | { |
275 | struct GetRequestContext ctx; | 266 | struct GetRequestContext ctx; |
276 | 267 | ||
277 | if (datacache == NULL) | 268 | if (datacache == NULL) |
278 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 269 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
279 | GNUNET_STATISTICS_update (GDS_stats, | 270 | GNUNET_STATISTICS_update (GDS_stats, |
280 | gettext_noop ("# GET requests given to datacache"), 1, | 271 | gettext_noop ("# GET requests given to datacache"), |
281 | GNUNET_NO); | 272 | 1, GNUNET_NO); |
282 | ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 273 | ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
283 | ctx.key = *key; | 274 | ctx.key = *key; |
284 | ctx.xquery = xquery; | 275 | ctx.xquery = xquery; |
285 | ctx.xquery_size = xquery_size; | 276 | ctx.xquery_size = xquery_size; |
286 | ctx.reply_bf = reply_bf; | 277 | ctx.reply_bf = reply_bf; |
287 | ctx.reply_bf_mutator = reply_bf_mutator; | 278 | ctx.reply_bf_mutator = reply_bf_mutator; |
288 | (void) GNUNET_DATACACHE_get (datacache, key, type, | 279 | (void) GNUNET_DATACACHE_get (datacache, key, type, &datacache_get_iterator, |
289 | &datacache_get_iterator, &ctx); | 280 | &ctx); |
290 | return ctx.eval; | 281 | return ctx.eval; |
291 | } | 282 | } |
292 | 283 | ||
@@ -294,7 +285,7 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, | |||
294 | /** | 285 | /** |
295 | * Initialize datacache subsystem. | 286 | * Initialize datacache subsystem. |
296 | */ | 287 | */ |
297 | void | 288 | void |
298 | GDS_DATACACHE_init () | 289 | GDS_DATACACHE_init () |
299 | { | 290 | { |
300 | datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); | 291 | datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); |
diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h index ccd854570..926ad5326 100644 --- a/src/dht/gnunet-service-dht_datacache.h +++ b/src/dht/gnunet-service-dht_datacache.h | |||
@@ -44,18 +44,17 @@ | |||
44 | */ | 44 | */ |
45 | void | 45 | void |
46 | GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | 46 | GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, |
47 | const GNUNET_HashCode *key, | 47 | const GNUNET_HashCode * key, |
48 | unsigned int put_path_length, | 48 | unsigned int put_path_length, |
49 | const struct GNUNET_PeerIdentity *put_path, | 49 | const struct GNUNET_PeerIdentity *put_path, |
50 | enum GNUNET_BLOCK_Type type, | 50 | enum GNUNET_BLOCK_Type type, size_t data_size, |
51 | size_t data_size, | 51 | const void *data); |
52 | const void *data); | ||
53 | 52 | ||
54 | 53 | ||
55 | /** | 54 | /** |
56 | * Handle a GET request we've received from another peer. | 55 | * Handle a GET request we've received from another peer. |
57 | * | 56 | * |
58 | * @param key the query | 57 | * @param key the query |
59 | * @param type requested data type | 58 | * @param type requested data type |
60 | * @param xquery extended query | 59 | * @param xquery extended query |
61 | * @param xquery_size number of bytes in xquery | 60 | * @param xquery_size number of bytes in xquery |
@@ -63,19 +62,18 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | |||
63 | * @param reply_bf_mutator mutation value for reply_bf | 62 | * @param reply_bf_mutator mutation value for reply_bf |
64 | * @return evaluation result for the local replies | 63 | * @return evaluation result for the local replies |
65 | */ | 64 | */ |
66 | enum GNUNET_BLOCK_EvaluationResult | 65 | enum GNUNET_BLOCK_EvaluationResult |
67 | GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, | 66 | GDS_DATACACHE_handle_get (const GNUNET_HashCode * key, |
68 | enum GNUNET_BLOCK_Type type, | 67 | enum GNUNET_BLOCK_Type type, const void *xquery, |
69 | const void *xquery, | 68 | size_t xquery_size, |
70 | size_t xquery_size, | 69 | struct GNUNET_CONTAINER_BloomFilter **reply_bf, |
71 | struct GNUNET_CONTAINER_BloomFilter **reply_bf, | 70 | uint32_t reply_bf_mutator); |
72 | uint32_t reply_bf_mutator); | ||
73 | 71 | ||
74 | 72 | ||
75 | /** | 73 | /** |
76 | * Initialize datacache subsystem. | 74 | * Initialize datacache subsystem. |
77 | */ | 75 | */ |
78 | void | 76 | void |
79 | GDS_DATACACHE_init (void); | 77 | GDS_DATACACHE_init (void); |
80 | 78 | ||
81 | 79 | ||
diff --git a/src/dht/gnunet-service-dht_hello.c b/src/dht/gnunet-service-dht_hello.c index 5be0cbfec..578e651f8 100644 --- a/src/dht/gnunet-service-dht_hello.c +++ b/src/dht/gnunet-service-dht_hello.c | |||
@@ -54,8 +54,7 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer) | |||
54 | { | 54 | { |
55 | if (NULL == peer_to_hello) | 55 | if (NULL == peer_to_hello) |
56 | return NULL; | 56 | return NULL; |
57 | return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, | 57 | return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey); |
58 | &peer->hashPubKey); | ||
59 | } | 58 | } |
60 | 59 | ||
61 | 60 | ||
@@ -68,11 +67,8 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer) | |||
68 | * @param error message | 67 | * @param error message |
69 | */ | 68 | */ |
70 | static void | 69 | static void |
71 | process_hello (void *cls, | 70 | process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, |
72 | const struct GNUNET_PeerIdentity * | 71 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
73 | peer, | ||
74 | const struct GNUNET_HELLO_Message * | ||
75 | hello, const char *err_msg) | ||
76 | { | 72 | { |
77 | struct GNUNET_TIME_Absolute ex; | 73 | struct GNUNET_TIME_Absolute ex; |
78 | struct GNUNET_HELLO_Message *hm; | 74 | struct GNUNET_HELLO_Message *hm; |
@@ -83,18 +79,16 @@ process_hello (void *cls, | |||
83 | if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0) | 79 | if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0) |
84 | return; | 80 | return; |
85 | GNUNET_STATISTICS_update (GDS_stats, | 81 | GNUNET_STATISTICS_update (GDS_stats, |
86 | gettext_noop ("# HELLOs obtained from peerinfo"), 1, | 82 | gettext_noop ("# HELLOs obtained from peerinfo"), 1, |
87 | GNUNET_NO); | 83 | GNUNET_NO); |
88 | hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, | 84 | hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey); |
89 | &peer->hashPubKey); | ||
90 | GNUNET_free_non_null (hm); | 85 | GNUNET_free_non_null (hm); |
91 | hm = GNUNET_malloc (GNUNET_HELLO_size (hello)); | 86 | hm = GNUNET_malloc (GNUNET_HELLO_size (hello)); |
92 | memcpy (hm, hello, GNUNET_HELLO_size (hello)); | 87 | memcpy (hm, hello, GNUNET_HELLO_size (hello)); |
93 | GNUNET_assert (GNUNET_SYSERR != | 88 | GNUNET_assert (GNUNET_SYSERR != |
94 | GNUNET_CONTAINER_multihashmap_put (peer_to_hello, | 89 | GNUNET_CONTAINER_multihashmap_put (peer_to_hello, |
95 | &peer->hashPubKey, | 90 | &peer->hashPubKey, hm, |
96 | hm, | 91 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); |
97 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); | ||
98 | } | 92 | } |
99 | 93 | ||
100 | 94 | ||
@@ -104,9 +98,7 @@ process_hello (void *cls, | |||
104 | void | 98 | void |
105 | GDS_HELLO_init () | 99 | GDS_HELLO_init () |
106 | { | 100 | { |
107 | pnc = GNUNET_PEERINFO_notify (GDS_cfg, | 101 | pnc = GNUNET_PEERINFO_notify (GDS_cfg, &process_hello, NULL); |
108 | &process_hello, | ||
109 | NULL); | ||
110 | peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256); | 102 | peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256); |
111 | } | 103 | } |
112 | 104 | ||
@@ -115,9 +107,7 @@ GDS_HELLO_init () | |||
115 | * Free memory occopied by the HELLO. | 107 | * Free memory occopied by the HELLO. |
116 | */ | 108 | */ |
117 | static int | 109 | static int |
118 | free_hello (void *cls, | 110 | free_hello (void *cls, const GNUNET_HashCode * key, void *hello) |
119 | const GNUNET_HashCode *key, | ||
120 | void *hello) | ||
121 | { | 111 | { |
122 | GNUNET_free (hello); | 112 | GNUNET_free (hello); |
123 | return GNUNET_OK; | 113 | return GNUNET_OK; |
@@ -137,9 +127,7 @@ GDS_HELLO_done () | |||
137 | } | 127 | } |
138 | if (NULL != peer_to_hello) | 128 | if (NULL != peer_to_hello) |
139 | { | 129 | { |
140 | GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, | 130 | GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, &free_hello, NULL); |
141 | &free_hello, | ||
142 | NULL); | ||
143 | GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello); | 131 | GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello); |
144 | } | 132 | } |
145 | } | 133 | } |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 02124b488..9ebf16400 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -275,7 +275,7 @@ struct P2PPendingMessage | |||
275 | 275 | ||
276 | /** | 276 | /** |
277 | * Actual message to be sent, allocated at the end of the struct: | 277 | * Actual message to be sent, allocated at the end of the struct: |
278 | * // msg = (cast) &pm[1]; | 278 | * // msg = (cast) &pm[1]; |
279 | * // memcpy (&pm[1], data, len); | 279 | * // memcpy (&pm[1], data, len); |
280 | */ | 280 | */ |
281 | const struct GNUNET_MessageHeader *msg; | 281 | const struct GNUNET_MessageHeader *msg; |
@@ -399,7 +399,7 @@ static GNUNET_SCHEDULER_TaskIdentifier find_peer_task; | |||
399 | 399 | ||
400 | /** | 400 | /** |
401 | * Identity of this peer. | 401 | * Identity of this peer. |
402 | */ | 402 | */ |
403 | static struct GNUNET_PeerIdentity my_identity; | 403 | static struct GNUNET_PeerIdentity my_identity; |
404 | 404 | ||
405 | /** | 405 | /** |
@@ -428,11 +428,11 @@ find_bucket (const GNUNET_HashCode * hc) | |||
428 | 428 | ||
429 | bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc); | 429 | bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc); |
430 | if (bits == MAX_BUCKETS) | 430 | if (bits == MAX_BUCKETS) |
431 | { | 431 | { |
432 | /* How can all bits match? Got my own ID? */ | 432 | /* How can all bits match? Got my own ID? */ |
433 | GNUNET_break (0); | 433 | GNUNET_break (0); |
434 | return GNUNET_SYSERR; | 434 | return GNUNET_SYSERR; |
435 | } | 435 | } |
436 | return MAX_BUCKETS - bits - 1; | 436 | return MAX_BUCKETS - bits - 1; |
437 | } | 437 | } |
438 | 438 | ||
@@ -442,7 +442,7 @@ find_bucket (const GNUNET_HashCode * hc) | |||
442 | * | 442 | * |
443 | * @param cls the 'struct PeerInfo' of the peer | 443 | * @param cls the 'struct PeerInfo' of the peer |
444 | * @param tc scheduler context. | 444 | * @param tc scheduler context. |
445 | */ | 445 | */ |
446 | static void | 446 | static void |
447 | update_core_preference (void *cls, | 447 | update_core_preference (void *cls, |
448 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 448 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -454,10 +454,10 @@ update_core_preference (void *cls, | |||
454 | 454 | ||
455 | peer->preference_task = GNUNET_SCHEDULER_NO_TASK; | 455 | peer->preference_task = GNUNET_SCHEDULER_NO_TASK; |
456 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 456 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
457 | return; | 457 | return; |
458 | matching = | 458 | matching = |
459 | GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, | 459 | GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, |
460 | &peer->id.hashPubKey); | 460 | &peer->id.hashPubKey); |
461 | if (matching >= 64) | 461 | if (matching >= 64) |
462 | matching = 63; | 462 | matching = 63; |
463 | bucket = find_bucket (&peer->id.hashPubKey); | 463 | bucket = find_bucket (&peer->id.hashPubKey); |
@@ -469,22 +469,21 @@ update_core_preference (void *cls, | |||
469 | preference = (1LL << matching) / k_buckets[bucket].peers_size; | 469 | preference = (1LL << matching) / k_buckets[bucket].peers_size; |
470 | } | 470 | } |
471 | if (preference == 0) | 471 | if (preference == 0) |
472 | { | 472 | { |
473 | peer->preference_task | 473 | peer->preference_task = |
474 | = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, | 474 | GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, |
475 | &update_core_preference, peer); | 475 | &update_core_preference, peer); |
476 | return; | 476 | return; |
477 | } | 477 | } |
478 | GNUNET_STATISTICS_update (GDS_stats, | 478 | GNUNET_STATISTICS_update (GDS_stats, |
479 | gettext_noop ("# Preference updates given to core"), 1, | 479 | gettext_noop ("# Preference updates given to core"), |
480 | GNUNET_NO); | 480 | 1, GNUNET_NO); |
481 | GNUNET_ATS_change_preference (atsAPI, &peer->id, | 481 | GNUNET_ATS_change_preference (atsAPI, &peer->id, |
482 | GNUNET_ATS_PREFERENCE_BANDWIDTH, | 482 | GNUNET_ATS_PREFERENCE_BANDWIDTH, |
483 | (double) preference, | 483 | (double) preference, GNUNET_ATS_PREFERENCE_END); |
484 | GNUNET_ATS_PREFERENCE_END); | 484 | peer->preference_task = |
485 | peer->preference_task | 485 | GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, |
486 | = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, | 486 | &update_core_preference, peer); |
487 | &update_core_preference, peer); | ||
488 | 487 | ||
489 | 488 | ||
490 | } | 489 | } |
@@ -525,9 +524,8 @@ add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value) | |||
525 | GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh); | 524 | GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh); |
526 | #if DEBUG_DHT | 525 | #if DEBUG_DHT |
527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 526 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
528 | "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", | 527 | "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", |
529 | GNUNET_h2s (key), | 528 | GNUNET_h2s (key), ctx->bf_mutator); |
530 | ctx->bf_mutator); | ||
531 | #endif | 529 | #endif |
532 | GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh); | 530 | GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh); |
533 | return GNUNET_YES; | 531 | return GNUNET_YES; |
@@ -553,46 +551,46 @@ send_find_peer_message (void *cls, | |||
553 | find_peer_task = GNUNET_SCHEDULER_NO_TASK; | 551 | find_peer_task = GNUNET_SCHEDULER_NO_TASK; |
554 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 552 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
555 | return; | 553 | return; |
556 | if (newly_found_peers > bucket_size) | 554 | if (newly_found_peers > bucket_size) |
557 | { | 555 | { |
558 | /* If we are finding many peers already, no need to send out our request right now! */ | 556 | /* If we are finding many peers already, no need to send out our request right now! */ |
559 | find_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 557 | find_peer_task = |
560 | &send_find_peer_message, NULL); | 558 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
559 | &send_find_peer_message, NULL); | ||
561 | newly_found_peers = 0; | 560 | newly_found_peers = 0; |
562 | return; | 561 | return; |
563 | } | 562 | } |
564 | bcc.bf_mutator = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | 563 | bcc.bf_mutator = |
564 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | ||
565 | bcc.bloom = | 565 | bcc.bloom = |
566 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K); | 566 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, |
567 | GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, | 567 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
568 | &add_known_to_bloom, | 568 | GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom, |
569 | &bcc); | 569 | &bcc); |
570 | GNUNET_STATISTICS_update (GDS_stats, | 570 | GNUNET_STATISTICS_update (GDS_stats, |
571 | gettext_noop ("# FIND PEER messages initiated"), 1, | 571 | gettext_noop ("# FIND PEER messages initiated"), 1, |
572 | GNUNET_NO); | 572 | GNUNET_NO); |
573 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, | 573 | peer_bf = |
574 | DHT_BLOOM_SIZE, | 574 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, |
575 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 575 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
576 | // FIXME: pass priority!? | 576 | // FIXME: pass priority!? |
577 | GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, | 577 | GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, |
578 | GNUNET_DHT_RO_FIND_PEER, | 578 | GNUNET_DHT_RO_FIND_PEER, |
579 | FIND_PEER_REPLICATION_LEVEL, | 579 | FIND_PEER_REPLICATION_LEVEL, 0, |
580 | 0, | 580 | &my_identity.hashPubKey, NULL, 0, bcc.bloom, |
581 | &my_identity.hashPubKey, | 581 | bcc.bf_mutator, peer_bf); |
582 | NULL, 0, | ||
583 | bcc.bloom, bcc.bf_mutator, | ||
584 | peer_bf); | ||
585 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); | 582 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
586 | GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); | 583 | GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); |
587 | /* schedule next round */ | 584 | /* schedule next round */ |
588 | next_send_time.rel_value = | 585 | next_send_time.rel_value = |
589 | DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + | 586 | DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + |
590 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 587 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
591 | DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / (newly_found_peers+1)); | 588 | DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / |
589 | (newly_found_peers + 1)); | ||
592 | newly_found_peers = 0; | 590 | newly_found_peers = 0; |
593 | find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, | 591 | find_peer_task = |
594 | &send_find_peer_message, | 592 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message, |
595 | NULL); | 593 | NULL); |
596 | } | 594 | } |
597 | 595 | ||
598 | 596 | ||
@@ -607,7 +605,7 @@ send_find_peer_message (void *cls, | |||
607 | static void | 605 | static void |
608 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 606 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
609 | const struct GNUNET_ATS_Information *atsi, | 607 | const struct GNUNET_ATS_Information *atsi, |
610 | unsigned int atsi_count) | 608 | unsigned int atsi_count) |
611 | { | 609 | { |
612 | struct PeerInfo *ret; | 610 | struct PeerInfo *ret; |
613 | int peer_bucket; | 611 | int peer_bucket; |
@@ -616,10 +614,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
616 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 614 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
617 | return; | 615 | return; |
618 | #if DEBUG_DHT | 616 | #if DEBUG_DHT |
619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 617 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected %s to %s\n", |
620 | "Connected %s to %s\n", | 618 | GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); |
621 | GNUNET_i2s (&my_identity), | ||
622 | GNUNET_h2s (&peer->hashPubKey)); | ||
623 | #endif | 619 | #endif |
624 | if (GNUNET_YES == | 620 | if (GNUNET_YES == |
625 | GNUNET_CONTAINER_multihashmap_contains (all_known_peers, | 621 | GNUNET_CONTAINER_multihashmap_contains (all_known_peers, |
@@ -628,11 +624,10 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
628 | GNUNET_break (0); | 624 | GNUNET_break (0); |
629 | return; | 625 | return; |
630 | } | 626 | } |
631 | GNUNET_STATISTICS_update (GDS_stats, | 627 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), 1, |
632 | gettext_noop ("# Peers connected"), 1, | 628 | GNUNET_NO); |
633 | GNUNET_NO); | ||
634 | peer_bucket = find_bucket (&peer->hashPubKey); | 629 | peer_bucket = find_bucket (&peer->hashPubKey); |
635 | GNUNET_assert ( (peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS) ); | 630 | GNUNET_assert ((peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS)); |
636 | ret = GNUNET_malloc (sizeof (struct PeerInfo)); | 631 | ret = GNUNET_malloc (sizeof (struct PeerInfo)); |
637 | #if 0 | 632 | #if 0 |
638 | ret->latency = latency; | 633 | ret->latency = latency; |
@@ -640,25 +635,23 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
640 | #endif | 635 | #endif |
641 | ret->id = *peer; | 636 | ret->id = *peer; |
642 | GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head, | 637 | GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head, |
643 | k_buckets[peer_bucket].tail, ret); | 638 | k_buckets[peer_bucket].tail, ret); |
644 | k_buckets[peer_bucket].peers_size++; | 639 | k_buckets[peer_bucket].peers_size++; |
645 | closest_bucket = GNUNET_MAX (closest_bucket, | 640 | closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket); |
646 | peer_bucket); | 641 | if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size)) |
647 | if ( (peer_bucket > 0) && | ||
648 | (k_buckets[peer_bucket].peers_size <= bucket_size) ) | ||
649 | { | 642 | { |
650 | ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret); | 643 | ret->preference_task = |
644 | GNUNET_SCHEDULER_add_now (&update_core_preference, ret); | ||
651 | newly_found_peers++; | 645 | newly_found_peers++; |
652 | } | 646 | } |
653 | GNUNET_assert (GNUNET_OK == | 647 | GNUNET_assert (GNUNET_OK == |
654 | GNUNET_CONTAINER_multihashmap_put (all_known_peers, | 648 | GNUNET_CONTAINER_multihashmap_put (all_known_peers, |
655 | &peer->hashPubKey, ret, | 649 | &peer->hashPubKey, ret, |
656 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 650 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
657 | if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)) | 651 | if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)) |
658 | { | 652 | { |
659 | /* got a first connection, good time to start with FIND PEER requests... */ | 653 | /* got a first connection, good time to start with FIND PEER requests... */ |
660 | find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, | 654 | find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL); |
661 | NULL); | ||
662 | } | 655 | } |
663 | } | 656 | } |
664 | 657 | ||
@@ -681,21 +674,18 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
681 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 674 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
682 | return; | 675 | return; |
683 | #if DEBUG_DHT | 676 | #if DEBUG_DHT |
684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnected %s from %s\n", |
685 | "Disconnected %s from %s\n", | 678 | GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); |
686 | GNUNET_i2s (&my_identity), | ||
687 | GNUNET_h2s (&peer->hashPubKey)); | ||
688 | #endif | 679 | #endif |
689 | to_remove = | 680 | to_remove = |
690 | GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey); | 681 | GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey); |
691 | if (NULL == to_remove) | 682 | if (NULL == to_remove) |
692 | { | 683 | { |
693 | GNUNET_break (0); | 684 | GNUNET_break (0); |
694 | return; | 685 | return; |
695 | } | 686 | } |
696 | GNUNET_STATISTICS_update (GDS_stats, | 687 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), -1, |
697 | gettext_noop ("# Peers connected"), -1, | 688 | GNUNET_NO); |
698 | GNUNET_NO); | ||
699 | GNUNET_assert (GNUNET_YES == | 689 | GNUNET_assert (GNUNET_YES == |
700 | GNUNET_CONTAINER_multihashmap_remove (all_known_peers, | 690 | GNUNET_CONTAINER_multihashmap_remove (all_known_peers, |
701 | &peer->hashPubKey, | 691 | &peer->hashPubKey, |
@@ -708,15 +698,13 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
708 | current_bucket = find_bucket (&to_remove->id.hashPubKey); | 698 | current_bucket = find_bucket (&to_remove->id.hashPubKey); |
709 | GNUNET_assert (current_bucket >= 0); | 699 | GNUNET_assert (current_bucket >= 0); |
710 | GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head, | 700 | GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head, |
711 | k_buckets[current_bucket].tail, | 701 | k_buckets[current_bucket].tail, to_remove); |
712 | to_remove); | ||
713 | GNUNET_assert (k_buckets[current_bucket].peers_size > 0); | 702 | GNUNET_assert (k_buckets[current_bucket].peers_size > 0); |
714 | k_buckets[current_bucket].peers_size--; | 703 | k_buckets[current_bucket].peers_size--; |
715 | while ( (closest_bucket > 0) && | 704 | while ((closest_bucket > 0) && (k_buckets[closest_bucket].peers_size == 0)) |
716 | (k_buckets[closest_bucket].peers_size == 0) ) | ||
717 | closest_bucket--; | 705 | closest_bucket--; |
718 | 706 | ||
719 | if (to_remove->th != NULL) | 707 | if (to_remove->th != NULL) |
720 | { | 708 | { |
721 | GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th); | 709 | GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th); |
722 | to_remove->th = NULL; | 710 | to_remove->th = NULL; |
@@ -724,15 +712,14 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
724 | discarded = 0; | 712 | discarded = 0; |
725 | while (NULL != (pos = to_remove->head)) | 713 | while (NULL != (pos = to_remove->head)) |
726 | { | 714 | { |
727 | GNUNET_CONTAINER_DLL_remove (to_remove->head, | 715 | GNUNET_CONTAINER_DLL_remove (to_remove->head, to_remove->tail, pos); |
728 | to_remove->tail, | ||
729 | pos); | ||
730 | discarded++; | 716 | discarded++; |
731 | GNUNET_free (pos); | 717 | GNUNET_free (pos); |
732 | } | 718 | } |
733 | GNUNET_STATISTICS_update (GDS_stats, | 719 | GNUNET_STATISTICS_update (GDS_stats, |
734 | gettext_noop ("# Queued messages discarded (peer disconnected)"), discarded, | 720 | gettext_noop |
735 | GNUNET_NO); | 721 | ("# Queued messages discarded (peer disconnected)"), |
722 | discarded, GNUNET_NO); | ||
736 | GNUNET_free (to_remove); | 723 | GNUNET_free (to_remove); |
737 | } | 724 | } |
738 | 725 | ||
@@ -756,8 +743,8 @@ core_transmit_notify (void *cls, size_t size, void *buf) | |||
756 | size_t msize; | 743 | size_t msize; |
757 | 744 | ||
758 | peer->th = NULL; | 745 | peer->th = NULL; |
759 | while ( (NULL != (pending = peer->head)) && | 746 | while ((NULL != (pending = peer->head)) && |
760 | (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0) ) | 747 | (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0)) |
761 | { | 748 | { |
762 | peer->pending_count--; | 749 | peer->pending_count--; |
763 | GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); | 750 | GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); |
@@ -770,22 +757,24 @@ core_transmit_notify (void *cls, size_t size, void *buf) | |||
770 | } | 757 | } |
771 | if (buf == NULL) | 758 | if (buf == NULL) |
772 | { | 759 | { |
773 | peer->th | 760 | peer->th = |
774 | = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, | 761 | GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, |
775 | pending->importance, | 762 | pending->importance, |
776 | GNUNET_TIME_absolute_get_remaining (pending->timeout), | 763 | GNUNET_TIME_absolute_get_remaining |
777 | &peer->id, ntohs (pending->msg->size), | 764 | (pending->timeout), &peer->id, |
778 | &core_transmit_notify, peer); | 765 | ntohs (pending->msg->size), |
766 | &core_transmit_notify, peer); | ||
779 | GNUNET_break (NULL != peer->th); | 767 | GNUNET_break (NULL != peer->th); |
780 | return 0; | 768 | return 0; |
781 | } | 769 | } |
782 | off = 0; | 770 | off = 0; |
783 | while ( (NULL != (pending = peer->head)) && | 771 | while ((NULL != (pending = peer->head)) && |
784 | (size - off >= (msize = ntohs (pending->msg->size))) ) | 772 | (size - off >= (msize = ntohs (pending->msg->size)))) |
785 | { | 773 | { |
786 | GNUNET_STATISTICS_update (GDS_stats, | 774 | GNUNET_STATISTICS_update (GDS_stats, |
787 | gettext_noop ("# Bytes transmitted to other peers"), msize, | 775 | gettext_noop |
788 | GNUNET_NO); | 776 | ("# Bytes transmitted to other peers"), msize, |
777 | GNUNET_NO); | ||
789 | memcpy (&cbuf[off], pending->msg, msize); | 778 | memcpy (&cbuf[off], pending->msg, msize); |
790 | off += msize; | 779 | off += msize; |
791 | peer->pending_count--; | 780 | peer->pending_count--; |
@@ -794,12 +783,12 @@ core_transmit_notify (void *cls, size_t size, void *buf) | |||
794 | } | 783 | } |
795 | if (peer->head != NULL) | 784 | if (peer->head != NULL) |
796 | { | 785 | { |
797 | peer->th | 786 | peer->th = |
798 | = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, | 787 | GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, |
799 | pending->importance, | 788 | pending->importance, |
800 | GNUNET_TIME_absolute_get_remaining (pending->timeout), | 789 | GNUNET_TIME_absolute_get_remaining |
801 | &peer->id, msize, | 790 | (pending->timeout), &peer->id, msize, |
802 | &core_transmit_notify, peer); | 791 | &core_transmit_notify, peer); |
803 | GNUNET_break (NULL != peer->th); | 792 | GNUNET_break (NULL != peer->th); |
804 | } | 793 | } |
805 | return off; | 794 | return off; |
@@ -821,16 +810,16 @@ process_peer_queue (struct PeerInfo *peer) | |||
821 | if (NULL != peer->th) | 810 | if (NULL != peer->th) |
822 | return; | 811 | return; |
823 | GNUNET_STATISTICS_update (GDS_stats, | 812 | GNUNET_STATISTICS_update (GDS_stats, |
824 | gettext_noop ("# Bytes of bandwdith requested from core"), | 813 | gettext_noop |
825 | ntohs (pending->msg->size), | 814 | ("# Bytes of bandwdith requested from core"), |
826 | GNUNET_NO); | 815 | ntohs (pending->msg->size), GNUNET_NO); |
827 | peer->th | 816 | peer->th = |
828 | = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, | 817 | GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, |
829 | pending->importance, | 818 | pending->importance, |
830 | GNUNET_TIME_absolute_get_remaining (pending->timeout), | 819 | GNUNET_TIME_absolute_get_remaining |
831 | &peer->id, | 820 | (pending->timeout), &peer->id, |
832 | ntohs (pending->msg->size), | 821 | ntohs (pending->msg->size), |
833 | &core_transmit_notify, peer); | 822 | &core_transmit_notify, peer); |
834 | GNUNET_break (NULL != peer->th); | 823 | GNUNET_break (NULL != peer->th); |
835 | } | 824 | } |
836 | 825 | ||
@@ -844,8 +833,7 @@ process_peer_queue (struct PeerInfo *peer) | |||
844 | * @return Some number of peers to forward the message to | 833 | * @return Some number of peers to forward the message to |
845 | */ | 834 | */ |
846 | static unsigned int | 835 | static unsigned int |
847 | get_forward_count (uint32_t hop_count, | 836 | get_forward_count (uint32_t hop_count, uint32_t target_replication) |
848 | uint32_t target_replication) | ||
849 | { | 837 | { |
850 | uint32_t random_value; | 838 | uint32_t random_value; |
851 | uint32_t forward_count; | 839 | uint32_t forward_count; |
@@ -862,18 +850,18 @@ get_forward_count (uint32_t hop_count, | |||
862 | return 1; | 850 | return 1; |
863 | } | 851 | } |
864 | /* bound by system-wide maximum */ | 852 | /* bound by system-wide maximum */ |
865 | target_replication = GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, | 853 | target_replication = |
866 | target_replication); | 854 | GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication); |
867 | target_value = | 855 | target_value = |
868 | 1 + (target_replication - 1.0) / (GDS_NSE_get () + | 856 | 1 + (target_replication - 1.0) / (GDS_NSE_get () + |
869 | ((float) (target_replication - 1.0) * | 857 | ((float) (target_replication - 1.0) * |
870 | hop_count)); | 858 | hop_count)); |
871 | /* Set forward count to floor of target_value */ | 859 | /* Set forward count to floor of target_value */ |
872 | forward_count = (uint32_t) target_value; | 860 | forward_count = (uint32_t) target_value; |
873 | /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ | 861 | /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ |
874 | target_value = target_value - forward_count; | 862 | target_value = target_value - forward_count; |
875 | random_value = | 863 | random_value = |
876 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | 864 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); |
877 | if (random_value < (target_value * UINT32_MAX)) | 865 | if (random_value < (target_value * UINT32_MAX)) |
878 | forward_count++; | 866 | forward_count++; |
879 | return forward_count; | 867 | return forward_count; |
@@ -950,7 +938,7 @@ get_distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have) | |||
950 | * GNUNET_NO otherwise. | 938 | * GNUNET_NO otherwise. |
951 | */ | 939 | */ |
952 | static int | 940 | static int |
953 | am_closest_peer (const GNUNET_HashCode *key, | 941 | am_closest_peer (const GNUNET_HashCode * key, |
954 | const struct GNUNET_CONTAINER_BloomFilter *bloom) | 942 | const struct GNUNET_CONTAINER_BloomFilter *bloom) |
955 | { | 943 | { |
956 | int bits; | 944 | int bits; |
@@ -978,7 +966,7 @@ am_closest_peer (const GNUNET_HashCode *key, | |||
978 | other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key); | 966 | other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key); |
979 | if (other_bits > bits) | 967 | if (other_bits > bits) |
980 | return GNUNET_NO; | 968 | return GNUNET_NO; |
981 | if (other_bits == bits) /* We match the same number of bits */ | 969 | if (other_bits == bits) /* We match the same number of bits */ |
982 | return GNUNET_YES; | 970 | return GNUNET_YES; |
983 | pos = pos->next; | 971 | pos = pos->next; |
984 | } | 972 | } |
@@ -997,7 +985,7 @@ am_closest_peer (const GNUNET_HashCode *key, | |||
997 | * exponentially declining probability. | 985 | * exponentially declining probability. |
998 | * | 986 | * |
999 | * FIXME: double-check that this is fine | 987 | * FIXME: double-check that this is fine |
1000 | * | 988 | * |
1001 | * | 989 | * |
1002 | * @param key the key we are selecting a peer to route to | 990 | * @param key the key we are selecting a peer to route to |
1003 | * @param bloom a bloomfilter containing entries this request has seen already | 991 | * @param bloom a bloomfilter containing entries this request has seen already |
@@ -1005,9 +993,8 @@ am_closest_peer (const GNUNET_HashCode *key, | |||
1005 | * @return Peer to route to, or NULL on error | 993 | * @return Peer to route to, or NULL on error |
1006 | */ | 994 | */ |
1007 | static struct PeerInfo * | 995 | static struct PeerInfo * |
1008 | select_peer (const GNUNET_HashCode *key, | 996 | select_peer (const GNUNET_HashCode * key, |
1009 | const struct GNUNET_CONTAINER_BloomFilter *bloom, | 997 | const struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hops) |
1010 | uint32_t hops) | ||
1011 | { | 998 | { |
1012 | unsigned int bc; | 999 | unsigned int bc; |
1013 | unsigned int count; | 1000 | unsigned int count; |
@@ -1028,10 +1015,10 @@ select_peer (const GNUNET_HashCode *key, | |||
1028 | count = 0; | 1015 | count = 0; |
1029 | while ((pos != NULL) && (count < bucket_size)) | 1016 | while ((pos != NULL) && (count < bucket_size)) |
1030 | { | 1017 | { |
1031 | if ( (bloom == NULL) || | 1018 | if ((bloom == NULL) || |
1032 | (GNUNET_NO == | 1019 | (GNUNET_NO == |
1033 | GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) | 1020 | GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) |
1034 | { | 1021 | { |
1035 | dist = get_distance (key, &pos->id.hashPubKey); | 1022 | dist = get_distance (key, &pos->id.hashPubKey); |
1036 | if (dist < smallest_distance) | 1023 | if (dist < smallest_distance) |
1037 | { | 1024 | { |
@@ -1040,25 +1027,25 @@ select_peer (const GNUNET_HashCode *key, | |||
1040 | } | 1027 | } |
1041 | } | 1028 | } |
1042 | else | 1029 | else |
1043 | { | 1030 | { |
1044 | #if DEBUG_DHT | 1031 | #if DEBUG_DHT |
1045 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1046 | "Excluded peer `%s' due to BF match in greedy routing for %s\n", | 1033 | "Excluded peer `%s' due to BF match in greedy routing for %s\n", |
1047 | GNUNET_i2s (&pos->id), | 1034 | GNUNET_i2s (&pos->id), GNUNET_h2s (key)); |
1048 | GNUNET_h2s (key)); | ||
1049 | #endif | 1035 | #endif |
1050 | GNUNET_STATISTICS_update (GDS_stats, | 1036 | GNUNET_STATISTICS_update (GDS_stats, |
1051 | gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, | 1037 | gettext_noop |
1052 | GNUNET_NO); | 1038 | ("# Peers excluded from routing due to Bloomfilter"), |
1053 | } | 1039 | 1, GNUNET_NO); |
1040 | } | ||
1054 | count++; | 1041 | count++; |
1055 | pos = pos->next; | 1042 | pos = pos->next; |
1056 | } | 1043 | } |
1057 | } | 1044 | } |
1058 | if (NULL == chosen) | 1045 | if (NULL == chosen) |
1059 | GNUNET_STATISTICS_update (GDS_stats, | 1046 | GNUNET_STATISTICS_update (GDS_stats, |
1060 | gettext_noop ("# Peer selection failed"), 1, | 1047 | gettext_noop ("# Peer selection failed"), 1, |
1061 | GNUNET_NO); | 1048 | GNUNET_NO); |
1062 | return chosen; | 1049 | return chosen; |
1063 | } | 1050 | } |
1064 | 1051 | ||
@@ -1070,18 +1057,18 @@ select_peer (const GNUNET_HashCode *key, | |||
1070 | pos = k_buckets[bc].head; | 1057 | pos = k_buckets[bc].head; |
1071 | while ((pos != NULL) && (count < bucket_size)) | 1058 | while ((pos != NULL) && (count < bucket_size)) |
1072 | { | 1059 | { |
1073 | if ( (bloom != NULL) && | 1060 | if ((bloom != NULL) && |
1074 | (GNUNET_YES == | 1061 | (GNUNET_YES == |
1075 | GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) | 1062 | GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) |
1076 | { | 1063 | { |
1077 | GNUNET_STATISTICS_update (GDS_stats, | 1064 | GNUNET_STATISTICS_update (GDS_stats, |
1078 | gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, | 1065 | gettext_noop |
1079 | GNUNET_NO); | 1066 | ("# Peers excluded from routing due to Bloomfilter"), |
1067 | 1, GNUNET_NO); | ||
1080 | #if DEBUG_DHT | 1068 | #if DEBUG_DHT |
1081 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1069 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1082 | "Excluded peer `%s' due to BF match in random routing for %s\n", | 1070 | "Excluded peer `%s' due to BF match in random routing for %s\n", |
1083 | GNUNET_i2s (&pos->id), | 1071 | GNUNET_i2s (&pos->id), GNUNET_h2s (key)); |
1084 | GNUNET_h2s (key)); | ||
1085 | #endif | 1072 | #endif |
1086 | pos = pos->next; | 1073 | pos = pos->next; |
1087 | continue; /* Ignore bloomfiltered peers */ | 1074 | continue; /* Ignore bloomfiltered peers */ |
@@ -1093,8 +1080,8 @@ select_peer (const GNUNET_HashCode *key, | |||
1093 | if (count == 0) /* No peers to select from! */ | 1080 | if (count == 0) /* No peers to select from! */ |
1094 | { | 1081 | { |
1095 | GNUNET_STATISTICS_update (GDS_stats, | 1082 | GNUNET_STATISTICS_update (GDS_stats, |
1096 | gettext_noop ("# Peer selection failed"), 1, | 1083 | gettext_noop ("# Peer selection failed"), 1, |
1097 | GNUNET_NO); | 1084 | GNUNET_NO); |
1098 | return NULL; | 1085 | return NULL; |
1099 | } | 1086 | } |
1100 | /* Now actually choose a peer */ | 1087 | /* Now actually choose a peer */ |
@@ -1105,9 +1092,9 @@ select_peer (const GNUNET_HashCode *key, | |||
1105 | pos = k_buckets[bc].head; | 1092 | pos = k_buckets[bc].head; |
1106 | while ((pos != NULL) && (count < bucket_size)) | 1093 | while ((pos != NULL) && (count < bucket_size)) |
1107 | { | 1094 | { |
1108 | if ( (bloom != NULL) && | 1095 | if ((bloom != NULL) && |
1109 | (GNUNET_YES == | 1096 | (GNUNET_YES == |
1110 | GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) | 1097 | GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) |
1111 | { | 1098 | { |
1112 | pos = pos->next; | 1099 | pos = pos->next; |
1113 | continue; /* Ignore bloomfiltered peers */ | 1100 | continue; /* Ignore bloomfiltered peers */ |
@@ -1136,11 +1123,10 @@ select_peer (const GNUNET_HashCode *key, | |||
1136 | * @return number of peers returned in 'targets'. | 1123 | * @return number of peers returned in 'targets'. |
1137 | */ | 1124 | */ |
1138 | static unsigned int | 1125 | static unsigned int |
1139 | get_target_peers (const GNUNET_HashCode *key, | 1126 | get_target_peers (const GNUNET_HashCode * key, |
1140 | struct GNUNET_CONTAINER_BloomFilter *bloom, | 1127 | struct GNUNET_CONTAINER_BloomFilter *bloom, |
1141 | uint32_t hop_count, | 1128 | uint32_t hop_count, uint32_t target_replication, |
1142 | uint32_t target_replication, | 1129 | struct PeerInfo ***targets) |
1143 | struct PeerInfo ***targets) | ||
1144 | { | 1130 | { |
1145 | unsigned int ret; | 1131 | unsigned int ret; |
1146 | unsigned int off; | 1132 | unsigned int off; |
@@ -1154,25 +1140,23 @@ get_target_peers (const GNUNET_HashCode *key, | |||
1154 | *targets = NULL; | 1140 | *targets = NULL; |
1155 | return 0; | 1141 | return 0; |
1156 | } | 1142 | } |
1157 | rtargets = GNUNET_malloc (sizeof (struct PeerInfo*) * ret); | 1143 | rtargets = GNUNET_malloc (sizeof (struct PeerInfo *) * ret); |
1158 | for (off = 0; off < ret; off++) | 1144 | for (off = 0; off < ret; off++) |
1159 | { | 1145 | { |
1160 | nxt = select_peer (key, bloom, hop_count); | 1146 | nxt = select_peer (key, bloom, hop_count); |
1161 | if (nxt == NULL) | 1147 | if (nxt == NULL) |
1162 | break; | 1148 | break; |
1163 | rtargets[off] = nxt; | 1149 | rtargets[off] = nxt; |
1164 | GNUNET_break (GNUNET_NO == | 1150 | GNUNET_break (GNUNET_NO == |
1165 | GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey)); | 1151 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1152 | &nxt->id.hashPubKey)); | ||
1166 | GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey); | 1153 | GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey); |
1167 | } | 1154 | } |
1168 | #if DEBUG_DHT | 1155 | #if DEBUG_DHT |
1169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1170 | "Selected %u/%u peers at hop %u for %s (target was %u)\n", | 1157 | "Selected %u/%u peers at hop %u for %s (target was %u)\n", off, |
1171 | off, | 1158 | GNUNET_CONTAINER_multihashmap_size (all_known_peers), |
1172 | GNUNET_CONTAINER_multihashmap_size (all_known_peers), | 1159 | (unsigned int) hop_count, GNUNET_h2s (key), ret); |
1173 | (unsigned int) hop_count, | ||
1174 | GNUNET_h2s (key), | ||
1175 | ret); | ||
1176 | #endif | 1160 | #endif |
1177 | if (0 == off) | 1161 | if (0 == off) |
1178 | { | 1162 | { |
@@ -1206,16 +1190,15 @@ get_target_peers (const GNUNET_HashCode *key, | |||
1206 | */ | 1190 | */ |
1207 | void | 1191 | void |
1208 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | 1192 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, |
1209 | enum GNUNET_DHT_RouteOption options, | 1193 | enum GNUNET_DHT_RouteOption options, |
1210 | uint32_t desired_replication_level, | 1194 | uint32_t desired_replication_level, |
1211 | struct GNUNET_TIME_Absolute expiration_time, | 1195 | struct GNUNET_TIME_Absolute expiration_time, |
1212 | uint32_t hop_count, | 1196 | uint32_t hop_count, |
1213 | struct GNUNET_CONTAINER_BloomFilter *bf, | 1197 | struct GNUNET_CONTAINER_BloomFilter *bf, |
1214 | const GNUNET_HashCode *key, | 1198 | const GNUNET_HashCode * key, |
1215 | unsigned int put_path_length, | 1199 | unsigned int put_path_length, |
1216 | struct GNUNET_PeerIdentity *put_path, | 1200 | struct GNUNET_PeerIdentity *put_path, |
1217 | const void *data, | 1201 | const void *data, size_t data_size) |
1218 | size_t data_size) | ||
1219 | { | 1202 | { |
1220 | unsigned int target_count; | 1203 | unsigned int target_count; |
1221 | unsigned int i; | 1204 | unsigned int i; |
@@ -1225,33 +1208,32 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1225 | size_t msize; | 1208 | size_t msize; |
1226 | struct PeerPutMessage *ppm; | 1209 | struct PeerPutMessage *ppm; |
1227 | struct GNUNET_PeerIdentity *pp; | 1210 | struct GNUNET_PeerIdentity *pp; |
1228 | 1211 | ||
1229 | GNUNET_assert (NULL != bf); | 1212 | GNUNET_assert (NULL != bf); |
1230 | #if DEBUG_DHT | 1213 | #if DEBUG_DHT |
1231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1232 | "Adding myself (%s) to PUT bloomfilter for %s\n", | 1215 | "Adding myself (%s) to PUT bloomfilter for %s\n", |
1233 | GNUNET_i2s (&my_identity), | 1216 | GNUNET_i2s (&my_identity), GNUNET_h2s (key)); |
1234 | GNUNET_h2s (key)); | ||
1235 | #endif | 1217 | #endif |
1236 | GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); | 1218 | GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); |
1237 | GNUNET_STATISTICS_update (GDS_stats, | 1219 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"), |
1238 | gettext_noop ("# PUT requests routed"), 1, | 1220 | 1, GNUNET_NO); |
1239 | GNUNET_NO); | 1221 | target_count = |
1240 | target_count = get_target_peers (key, bf, hop_count, | 1222 | get_target_peers (key, bf, hop_count, desired_replication_level, |
1241 | desired_replication_level, | 1223 | &targets); |
1242 | &targets); | ||
1243 | if (0 == target_count) | 1224 | if (0 == target_count) |
1244 | { | 1225 | { |
1245 | #if DEBUG_DHT | 1226 | #if DEBUG_DHT |
1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1247 | "Routing PUT for %s terminates after %u hops at %s\n", | 1228 | "Routing PUT for %s terminates after %u hops at %s\n", |
1248 | GNUNET_h2s (key), | 1229 | GNUNET_h2s (key), (unsigned int) hop_count, |
1249 | (unsigned int) hop_count, | 1230 | GNUNET_i2s (&my_identity)); |
1250 | GNUNET_i2s (&my_identity)); | ||
1251 | #endif | 1231 | #endif |
1252 | return; | 1232 | return; |
1253 | } | 1233 | } |
1254 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage); | 1234 | msize = |
1235 | put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + | ||
1236 | sizeof (struct PeerPutMessage); | ||
1255 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1237 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1256 | { | 1238 | { |
1257 | put_path_length = 0; | 1239 | put_path_length = 0; |
@@ -1264,22 +1246,21 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1264 | return; | 1246 | return; |
1265 | } | 1247 | } |
1266 | GNUNET_STATISTICS_update (GDS_stats, | 1248 | GNUNET_STATISTICS_update (GDS_stats, |
1267 | gettext_noop ("# PUT messages queued for transmission"), target_count, | 1249 | gettext_noop |
1268 | GNUNET_NO); | 1250 | ("# PUT messages queued for transmission"), |
1269 | for (i=0;i<target_count;i++) | 1251 | target_count, GNUNET_NO); |
1252 | for (i = 0; i < target_count; i++) | ||
1270 | { | 1253 | { |
1271 | target = targets[i]; | 1254 | target = targets[i]; |
1272 | #if DEBUG_DHT | 1255 | #if DEBUG_DHT |
1273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1274 | "Routing PUT for %s after %u hops to %s\n", | 1257 | "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key), |
1275 | GNUNET_h2s (key), | 1258 | (unsigned int) hop_count, GNUNET_i2s (&target->id)); |
1276 | (unsigned int) hop_count, | ||
1277 | GNUNET_i2s (&target->id)); | ||
1278 | #endif | 1259 | #endif |
1279 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1260 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1280 | pending->importance = 0; /* FIXME */ | 1261 | pending->importance = 0; /* FIXME */ |
1281 | pending->timeout = expiration_time; | 1262 | pending->timeout = expiration_time; |
1282 | ppm = (struct PeerPutMessage*) &pending[1]; | 1263 | ppm = (struct PeerPutMessage *) &pending[1]; |
1283 | pending->msg = &ppm->header; | 1264 | pending->msg = &ppm->header; |
1284 | ppm->header.size = htons (msize); | 1265 | ppm->header.size = htons (msize); |
1285 | ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); | 1266 | ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); |
@@ -1289,18 +1270,19 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1289 | ppm->desired_replication_level = htonl (desired_replication_level); | 1270 | ppm->desired_replication_level = htonl (desired_replication_level); |
1290 | ppm->put_path_length = htonl (put_path_length); | 1271 | ppm->put_path_length = htonl (put_path_length); |
1291 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); | 1272 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
1292 | GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &target->id.hashPubKey)); | 1273 | GNUNET_break (GNUNET_YES == |
1274 | GNUNET_CONTAINER_bloomfilter_test (bf, | ||
1275 | &target->id.hashPubKey)); | ||
1293 | GNUNET_assert (GNUNET_OK == | 1276 | GNUNET_assert (GNUNET_OK == |
1294 | GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, | 1277 | GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, |
1295 | ppm->bloomfilter, | 1278 | ppm->bloomfilter, |
1296 | DHT_BLOOM_SIZE)); | 1279 | DHT_BLOOM_SIZE)); |
1297 | ppm->key = *key; | 1280 | ppm->key = *key; |
1298 | pp = (struct GNUNET_PeerIdentity*) &ppm[1]; | 1281 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; |
1299 | memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length); | 1282 | memcpy (pp, put_path, |
1283 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | ||
1300 | memcpy (&pp[put_path_length], data, data_size); | 1284 | memcpy (&pp[put_path_length], data, data_size); |
1301 | GNUNET_CONTAINER_DLL_insert_tail (target->head, | 1285 | GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending); |
1302 | target->tail, | ||
1303 | pending); | ||
1304 | target->pending_count++; | 1286 | target->pending_count++; |
1305 | process_peer_queue (target); | 1287 | process_peer_queue (target); |
1306 | } | 1288 | } |
@@ -1327,15 +1309,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1327 | */ | 1309 | */ |
1328 | void | 1310 | void |
1329 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | 1311 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, |
1330 | enum GNUNET_DHT_RouteOption options, | 1312 | enum GNUNET_DHT_RouteOption options, |
1331 | uint32_t desired_replication_level, | 1313 | uint32_t desired_replication_level, |
1332 | uint32_t hop_count, | 1314 | uint32_t hop_count, const GNUNET_HashCode * key, |
1333 | const GNUNET_HashCode *key, | 1315 | const void *xquery, size_t xquery_size, |
1334 | const void *xquery, | 1316 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, |
1335 | size_t xquery_size, | 1317 | uint32_t reply_bf_mutator, |
1336 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, | 1318 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) |
1337 | uint32_t reply_bf_mutator, | ||
1338 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) | ||
1339 | { | 1319 | { |
1340 | unsigned int target_count; | 1320 | unsigned int target_count; |
1341 | unsigned int i; | 1321 | unsigned int i; |
@@ -1347,28 +1327,25 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1347 | char *xq; | 1327 | char *xq; |
1348 | size_t reply_bf_size; | 1328 | size_t reply_bf_size; |
1349 | 1329 | ||
1350 | GNUNET_assert (NULL != peer_bf); | 1330 | GNUNET_assert (NULL != peer_bf); |
1351 | GNUNET_STATISTICS_update (GDS_stats, | 1331 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"), |
1352 | gettext_noop ("# GET requests routed"), 1, | 1332 | 1, GNUNET_NO); |
1353 | GNUNET_NO); | 1333 | target_count = |
1354 | target_count = get_target_peers (key, peer_bf, hop_count, | 1334 | get_target_peers (key, peer_bf, hop_count, desired_replication_level, |
1355 | desired_replication_level, | 1335 | &targets); |
1356 | &targets); | ||
1357 | #if DEBUG_DHT | 1336 | #if DEBUG_DHT |
1358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1359 | "Adding myself (%s) to GET bloomfilter for %s\n", | 1338 | "Adding myself (%s) to GET bloomfilter for %s\n", |
1360 | GNUNET_i2s (&my_identity), | 1339 | GNUNET_i2s (&my_identity), GNUNET_h2s (key)); |
1361 | GNUNET_h2s (key)); | ||
1362 | #endif | 1340 | #endif |
1363 | GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey); | 1341 | GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey); |
1364 | if (0 == target_count) | 1342 | if (0 == target_count) |
1365 | { | 1343 | { |
1366 | #if DEBUG_DHT | 1344 | #if DEBUG_DHT |
1367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1345 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1368 | "Routing GET for %s terminates after %u hops at %s\n", | 1346 | "Routing GET for %s terminates after %u hops at %s\n", |
1369 | GNUNET_h2s (key), | 1347 | GNUNET_h2s (key), (unsigned int) hop_count, |
1370 | (unsigned int) hop_count, | 1348 | GNUNET_i2s (&my_identity)); |
1371 | GNUNET_i2s (&my_identity)); | ||
1372 | #endif | 1349 | #endif |
1373 | return; | 1350 | return; |
1374 | } | 1351 | } |
@@ -1381,23 +1358,22 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1381 | return; | 1358 | return; |
1382 | } | 1359 | } |
1383 | GNUNET_STATISTICS_update (GDS_stats, | 1360 | GNUNET_STATISTICS_update (GDS_stats, |
1384 | gettext_noop ("# GET messages queued for transmission"), target_count, | 1361 | gettext_noop |
1385 | GNUNET_NO); | 1362 | ("# GET messages queued for transmission"), |
1363 | target_count, GNUNET_NO); | ||
1386 | /* forward request */ | 1364 | /* forward request */ |
1387 | for (i=0;i<target_count;i++) | 1365 | for (i = 0; i < target_count; i++) |
1388 | { | 1366 | { |
1389 | target = targets[i]; | 1367 | target = targets[i]; |
1390 | #if DEBUG_DHT | 1368 | #if DEBUG_DHT |
1391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1392 | "Routing GET for %s after %u hops to %s\n", | 1370 | "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key), |
1393 | GNUNET_h2s (key), | 1371 | (unsigned int) hop_count, GNUNET_i2s (&target->id)); |
1394 | (unsigned int) hop_count, | ||
1395 | GNUNET_i2s (&target->id)); | ||
1396 | #endif | 1372 | #endif |
1397 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1373 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1398 | pending->importance = 0; /* FIXME */ | 1374 | pending->importance = 0; /* FIXME */ |
1399 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 1375 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
1400 | pgm = (struct PeerGetMessage*) &pending[1]; | 1376 | pgm = (struct PeerGetMessage *) &pending[1]; |
1401 | pending->msg = &pgm->header; | 1377 | pending->msg = &pgm->header; |
1402 | pgm->header.size = htons (msize); | 1378 | pgm->header.size = htons (msize); |
1403 | pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); | 1379 | pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); |
@@ -1406,23 +1382,24 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1406 | pgm->hop_count = htonl (hop_count + 1); | 1382 | pgm->hop_count = htonl (hop_count + 1); |
1407 | pgm->desired_replication_level = htonl (desired_replication_level); | 1383 | pgm->desired_replication_level = htonl (desired_replication_level); |
1408 | pgm->xquery_size = htonl (xquery_size); | 1384 | pgm->xquery_size = htonl (xquery_size); |
1409 | pgm->bf_mutator = reply_bf_mutator; | 1385 | pgm->bf_mutator = reply_bf_mutator; |
1410 | GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &target->id.hashPubKey)); | 1386 | GNUNET_break (GNUNET_YES == |
1387 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, | ||
1388 | &target->id.hashPubKey)); | ||
1411 | GNUNET_assert (GNUNET_OK == | 1389 | GNUNET_assert (GNUNET_OK == |
1412 | GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, | 1390 | GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, |
1413 | pgm->bloomfilter, | 1391 | pgm->bloomfilter, |
1414 | DHT_BLOOM_SIZE)); | 1392 | DHT_BLOOM_SIZE)); |
1415 | pgm->key = *key; | 1393 | pgm->key = *key; |
1416 | xq = (char *) &pgm[1]; | 1394 | xq = (char *) &pgm[1]; |
1417 | memcpy (xq, xquery, xquery_size); | 1395 | memcpy (xq, xquery, xquery_size); |
1418 | if (NULL != reply_bf) | 1396 | if (NULL != reply_bf) |
1419 | GNUNET_assert (GNUNET_OK == | 1397 | GNUNET_assert (GNUNET_OK == |
1420 | GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, | 1398 | GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, |
1421 | &xq[xquery_size], | 1399 | &xq |
1422 | reply_bf_size)); | 1400 | [xquery_size], |
1423 | GNUNET_CONTAINER_DLL_insert_tail (target->head, | 1401 | reply_bf_size)); |
1424 | target->tail, | 1402 | GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending); |
1425 | pending); | ||
1426 | target->pending_count++; | 1403 | target->pending_count++; |
1427 | process_peer_queue (target); | 1404 | process_peer_queue (target); |
1428 | } | 1405 | } |
@@ -1448,46 +1425,49 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1448 | */ | 1425 | */ |
1449 | void | 1426 | void |
1450 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | 1427 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, |
1451 | enum GNUNET_BLOCK_Type type, | 1428 | enum GNUNET_BLOCK_Type type, |
1452 | struct GNUNET_TIME_Absolute expiration_time, | 1429 | struct GNUNET_TIME_Absolute expiration_time, |
1453 | const GNUNET_HashCode *key, | 1430 | const GNUNET_HashCode * key, |
1454 | unsigned int put_path_length, | 1431 | unsigned int put_path_length, |
1455 | const struct GNUNET_PeerIdentity *put_path, | 1432 | const struct GNUNET_PeerIdentity *put_path, |
1456 | unsigned int get_path_length, | 1433 | unsigned int get_path_length, |
1457 | const struct GNUNET_PeerIdentity *get_path, | 1434 | const struct GNUNET_PeerIdentity *get_path, |
1458 | const void *data, | 1435 | const void *data, size_t data_size) |
1459 | size_t data_size) | ||
1460 | { | 1436 | { |
1461 | struct PeerInfo *pi; | 1437 | struct PeerInfo *pi; |
1462 | struct P2PPendingMessage *pending; | 1438 | struct P2PPendingMessage *pending; |
1463 | size_t msize; | 1439 | size_t msize; |
1464 | struct PeerResultMessage *prm; | 1440 | struct PeerResultMessage *prm; |
1465 | struct GNUNET_PeerIdentity *paths; | 1441 | struct GNUNET_PeerIdentity *paths; |
1466 | 1442 | ||
1467 | msize = data_size + sizeof (struct PeerResultMessage) + | 1443 | msize = |
1468 | (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); | 1444 | data_size + sizeof (struct PeerResultMessage) + (get_path_length + |
1469 | if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 1445 | put_path_length) * |
1470 | (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || | 1446 | sizeof (struct GNUNET_PeerIdentity); |
1471 | (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || | 1447 | if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
1472 | (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) ) | 1448 | (get_path_length > |
1449 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || | ||
1450 | (put_path_length > | ||
1451 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || | ||
1452 | (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)) | ||
1473 | { | 1453 | { |
1474 | GNUNET_break (0); | 1454 | GNUNET_break (0); |
1475 | return; | 1455 | return; |
1476 | } | 1456 | } |
1477 | pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, | 1457 | pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &target->hashPubKey); |
1478 | &target->hashPubKey); | ||
1479 | if (NULL == pi) | 1458 | if (NULL == pi) |
1480 | { | 1459 | { |
1481 | /* peer disconnected in the meantime, drop reply */ | 1460 | /* peer disconnected in the meantime, drop reply */ |
1482 | return; | 1461 | return; |
1483 | } | 1462 | } |
1484 | GNUNET_STATISTICS_update (GDS_stats, | 1463 | GNUNET_STATISTICS_update (GDS_stats, |
1485 | gettext_noop ("# RESULT messages queued for transmission"), 1, | 1464 | gettext_noop |
1486 | GNUNET_NO); | 1465 | ("# RESULT messages queued for transmission"), 1, |
1487 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1466 | GNUNET_NO); |
1488 | pending->importance = 0; /* FIXME */ | 1467 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1468 | pending->importance = 0; /* FIXME */ | ||
1489 | pending->timeout = expiration_time; | 1469 | pending->timeout = expiration_time; |
1490 | prm = (struct PeerResultMessage*) &pending[1]; | 1470 | prm = (struct PeerResultMessage *) &pending[1]; |
1491 | pending->msg = &prm->header; | 1471 | pending->msg = &prm->header; |
1492 | prm->header.size = htons (msize); | 1472 | prm->header.size = htons (msize); |
1493 | prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); | 1473 | prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); |
@@ -1496,15 +1476,13 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | |||
1496 | prm->get_path_length = htonl (get_path_length); | 1476 | prm->get_path_length = htonl (get_path_length); |
1497 | prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); | 1477 | prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
1498 | prm->key = *key; | 1478 | prm->key = *key; |
1499 | paths = (struct GNUNET_PeerIdentity*) &prm[1]; | 1479 | paths = (struct GNUNET_PeerIdentity *) &prm[1]; |
1500 | memcpy (paths, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); | 1480 | memcpy (paths, put_path, |
1501 | memcpy (&paths[put_path_length], | 1481 | put_path_length * sizeof (struct GNUNET_PeerIdentity)); |
1502 | get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 1482 | memcpy (&paths[put_path_length], get_path, |
1503 | memcpy (&paths[put_path_length + get_path_length], | 1483 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
1504 | data, data_size); | 1484 | memcpy (&paths[put_path_length + get_path_length], data, data_size); |
1505 | GNUNET_CONTAINER_DLL_insert (pi->head, | 1485 | GNUNET_CONTAINER_DLL_insert (pi->head, pi->tail, pending); |
1506 | pi->tail, | ||
1507 | pending); | ||
1508 | pi->pending_count++; | 1486 | pi->pending_count++; |
1509 | process_peer_queue (pi); | 1487 | process_peer_queue (pi); |
1510 | } | 1488 | } |
@@ -1539,12 +1517,10 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
1539 | * GNUNET_SYSERR to close it (signal serious error) | 1517 | * GNUNET_SYSERR to close it (signal serious error) |
1540 | */ | 1518 | */ |
1541 | static int | 1519 | static int |
1542 | handle_dht_p2p_put (void *cls, | 1520 | handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, |
1543 | const struct GNUNET_PeerIdentity *peer, | 1521 | const struct GNUNET_MessageHeader *message, |
1544 | const struct GNUNET_MessageHeader *message, | 1522 | const struct GNUNET_ATS_Information *atsi, |
1545 | const struct GNUNET_ATS_Information | 1523 | unsigned int atsi_count) |
1546 | *atsi, | ||
1547 | unsigned int atsi_count) | ||
1548 | { | 1524 | { |
1549 | const struct PeerPutMessage *put; | 1525 | const struct PeerPutMessage *put; |
1550 | const struct GNUNET_PeerIdentity *put_path; | 1526 | const struct GNUNET_PeerIdentity *put_path; |
@@ -1555,33 +1531,36 @@ handle_dht_p2p_put (void *cls, | |||
1555 | enum GNUNET_DHT_RouteOption options; | 1531 | enum GNUNET_DHT_RouteOption options; |
1556 | struct GNUNET_CONTAINER_BloomFilter *bf; | 1532 | struct GNUNET_CONTAINER_BloomFilter *bf; |
1557 | GNUNET_HashCode test_key; | 1533 | GNUNET_HashCode test_key; |
1558 | 1534 | ||
1559 | msize = ntohs (message->size); | 1535 | msize = ntohs (message->size); |
1560 | if (msize < sizeof (struct PeerPutMessage)) | 1536 | if (msize < sizeof (struct PeerPutMessage)) |
1561 | { | 1537 | { |
1562 | GNUNET_break_op (0); | 1538 | GNUNET_break_op (0); |
1563 | return GNUNET_YES; | 1539 | return GNUNET_YES; |
1564 | } | 1540 | } |
1565 | put = (const struct PeerPutMessage*) message; | 1541 | put = (const struct PeerPutMessage *) message; |
1566 | putlen = ntohl (put->put_path_length); | 1542 | putlen = ntohl (put->put_path_length); |
1567 | if ( (msize < sizeof (struct PeerPutMessage) + putlen * sizeof (struct GNUNET_PeerIdentity)) || | 1543 | if ((msize < |
1568 | (putlen > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) | 1544 | sizeof (struct PeerPutMessage) + |
1569 | { | 1545 | putlen * sizeof (struct GNUNET_PeerIdentity)) || |
1570 | GNUNET_break_op (0); | 1546 | (putlen > |
1571 | return GNUNET_YES; | 1547 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) |
1572 | } | 1548 | { |
1549 | GNUNET_break_op (0); | ||
1550 | return GNUNET_YES; | ||
1551 | } | ||
1573 | GNUNET_STATISTICS_update (GDS_stats, | 1552 | GNUNET_STATISTICS_update (GDS_stats, |
1574 | gettext_noop ("# P2P PUT requests received"), 1, | 1553 | gettext_noop ("# P2P PUT requests received"), 1, |
1575 | GNUNET_NO); | 1554 | GNUNET_NO); |
1576 | put_path = (const struct GNUNET_PeerIdentity*) &put[1]; | 1555 | put_path = (const struct GNUNET_PeerIdentity *) &put[1]; |
1577 | payload = &put_path[putlen]; | 1556 | payload = &put_path[putlen]; |
1578 | options = ntohl (put->options); | 1557 | options = ntohl (put->options); |
1579 | payload_size = msize - (sizeof (struct PeerPutMessage) + | 1558 | payload_size = |
1580 | putlen * sizeof (struct GNUNET_PeerIdentity)); | 1559 | msize - (sizeof (struct PeerPutMessage) + |
1581 | switch (GNUNET_BLOCK_get_key (GDS_block_context, | 1560 | putlen * sizeof (struct GNUNET_PeerIdentity)); |
1582 | ntohl (put->type), | 1561 | switch (GNUNET_BLOCK_get_key |
1583 | payload, payload_size, | 1562 | (GDS_block_context, ntohl (put->type), payload, payload_size, |
1584 | &test_key)) | 1563 | &test_key)) |
1585 | { | 1564 | { |
1586 | case GNUNET_YES: | 1565 | case GNUNET_YES: |
1587 | if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode))) | 1566 | if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode))) |
@@ -1598,18 +1577,16 @@ handle_dht_p2p_put (void *cls, | |||
1598 | break; | 1577 | break; |
1599 | } | 1578 | } |
1600 | #if DEBUG_DHT | 1579 | #if DEBUG_DHT |
1601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1580 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for %s at %s\n", |
1602 | "PUT for %s at %s\n", | 1581 | GNUNET_h2s (&put->key), GNUNET_i2s (&my_identity)); |
1603 | GNUNET_h2s (&put->key), | ||
1604 | GNUNET_i2s (&my_identity)); | ||
1605 | #endif | 1582 | #endif |
1606 | bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, | 1583 | bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE, |
1607 | DHT_BLOOM_SIZE, | 1584 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
1608 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 1585 | GNUNET_break_op (GNUNET_YES == |
1609 | GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); | 1586 | GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); |
1610 | { | 1587 | { |
1611 | struct GNUNET_PeerIdentity pp[putlen+1]; | 1588 | struct GNUNET_PeerIdentity pp[putlen + 1]; |
1612 | 1589 | ||
1613 | /* extend 'put path' by sender */ | 1590 | /* extend 'put path' by sender */ |
1614 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 1591 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
1615 | { | 1592 | { |
@@ -1619,37 +1596,23 @@ handle_dht_p2p_put (void *cls, | |||
1619 | } | 1596 | } |
1620 | else | 1597 | else |
1621 | putlen = 0; | 1598 | putlen = 0; |
1622 | 1599 | ||
1623 | /* give to local clients */ | 1600 | /* give to local clients */ |
1624 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1601 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), |
1625 | &put->key, | 1602 | &put->key, 0, NULL, putlen, pp, ntohl (put->type), |
1626 | 0, NULL, | 1603 | payload_size, payload); |
1627 | putlen, | ||
1628 | pp, | ||
1629 | ntohl (put->type), | ||
1630 | payload_size, | ||
1631 | payload); | ||
1632 | /* store locally */ | 1604 | /* store locally */ |
1633 | if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 1605 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
1634 | (am_closest_peer (&put->key, | 1606 | (am_closest_peer (&put->key, bf))) |
1635 | bf) ) ) | 1607 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh |
1636 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1608 | (put->expiration_time), &put->key, putlen, pp, |
1637 | &put->key, | 1609 | ntohl (put->type), payload_size, payload); |
1638 | putlen, pp, | ||
1639 | ntohl (put->type), | ||
1640 | payload_size, | ||
1641 | payload); | ||
1642 | /* route to other peers */ | 1610 | /* route to other peers */ |
1643 | GDS_NEIGHBOURS_handle_put (ntohl (put->type), | 1611 | GDS_NEIGHBOURS_handle_put (ntohl (put->type), options, |
1644 | options, | 1612 | ntohl (put->desired_replication_level), |
1645 | ntohl (put->desired_replication_level), | 1613 | GNUNET_TIME_absolute_ntoh (put->expiration_time), |
1646 | GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1614 | ntohl (put->hop_count), bf, &put->key, putlen, |
1647 | ntohl (put->hop_count), | 1615 | pp, payload, payload_size); |
1648 | bf, | ||
1649 | &put->key, | ||
1650 | putlen, pp, | ||
1651 | payload, | ||
1652 | payload_size); | ||
1653 | } | 1616 | } |
1654 | GNUNET_CONTAINER_bloomfilter_free (bf); | 1617 | GNUNET_CONTAINER_bloomfilter_free (bf); |
1655 | return GNUNET_YES; | 1618 | return GNUNET_YES; |
@@ -1667,9 +1630,8 @@ handle_dht_p2p_put (void *cls, | |||
1667 | */ | 1630 | */ |
1668 | static void | 1631 | static void |
1669 | handle_find_peer (const struct GNUNET_PeerIdentity *sender, | 1632 | handle_find_peer (const struct GNUNET_PeerIdentity *sender, |
1670 | const GNUNET_HashCode *key, | 1633 | const GNUNET_HashCode * key, |
1671 | struct GNUNET_CONTAINER_BloomFilter *bf, | 1634 | struct GNUNET_CONTAINER_BloomFilter *bf, uint32_t bf_mutator) |
1672 | uint32_t bf_mutator) | ||
1673 | { | 1635 | { |
1674 | int bucket_idx; | 1636 | int bucket_idx; |
1675 | struct PeerBucket *bucket; | 1637 | struct PeerBucket *bucket; |
@@ -1682,30 +1644,31 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1682 | if (NULL != GDS_my_hello) | 1644 | if (NULL != GDS_my_hello) |
1683 | { | 1645 | { |
1684 | GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash); | 1646 | GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash); |
1685 | if ( (NULL == bf) || | 1647 | if ((NULL == bf) || |
1686 | (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ) | 1648 | (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash))) |
1687 | { | 1649 | { |
1688 | GDS_NEIGHBOURS_handle_reply (sender, | 1650 | GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO, |
1689 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1651 | GNUNET_TIME_relative_to_absolute |
1690 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), | 1652 | (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), |
1691 | key, | 1653 | key, 0, NULL, 0, NULL, GDS_my_hello, |
1692 | 0, NULL, | 1654 | GNUNET_HELLO_size ((const struct |
1693 | 0, NULL, | 1655 | GNUNET_HELLO_Message *) |
1694 | GDS_my_hello, | 1656 | GDS_my_hello)); |
1695 | GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*) GDS_my_hello)); | ||
1696 | } | 1657 | } |
1697 | else | 1658 | else |
1698 | { | 1659 | { |
1699 | GNUNET_STATISTICS_update (GDS_stats, | 1660 | GNUNET_STATISTICS_update (GDS_stats, |
1700 | gettext_noop ("# FIND PEER requests ignored due to Bloomfilter"), 1, | 1661 | gettext_noop |
1701 | GNUNET_NO); | 1662 | ("# FIND PEER requests ignored due to Bloomfilter"), |
1663 | 1, GNUNET_NO); | ||
1702 | } | 1664 | } |
1703 | } | 1665 | } |
1704 | else | 1666 | else |
1705 | { | 1667 | { |
1706 | GNUNET_STATISTICS_update (GDS_stats, | 1668 | GNUNET_STATISTICS_update (GDS_stats, |
1707 | gettext_noop ("# FIND PEER requests ignored due to lack of HELLO"), 1, | 1669 | gettext_noop |
1708 | GNUNET_NO); | 1670 | ("# FIND PEER requests ignored due to lack of HELLO"), |
1671 | 1, GNUNET_NO); | ||
1709 | } | 1672 | } |
1710 | 1673 | ||
1711 | /* then, also consider sending a random HELLO from the closest bucket */ | 1674 | /* then, also consider sending a random HELLO from the closest bucket */ |
@@ -1718,8 +1681,8 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1718 | bucket = &k_buckets[bucket_idx]; | 1681 | bucket = &k_buckets[bucket_idx]; |
1719 | if (bucket->peers_size == 0) | 1682 | if (bucket->peers_size == 0) |
1720 | return; | 1683 | return; |
1721 | choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1684 | choice = |
1722 | bucket->peers_size); | 1685 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, bucket->peers_size); |
1723 | peer = bucket->head; | 1686 | peer = bucket->head; |
1724 | while (choice > 0) | 1687 | while (choice > 0) |
1725 | { | 1688 | { |
@@ -1729,25 +1692,22 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1729 | } | 1692 | } |
1730 | choice = bucket->peers_size; | 1693 | choice = bucket->peers_size; |
1731 | do | 1694 | do |
1732 | { | 1695 | { |
1733 | peer = peer->next; | 1696 | peer = peer->next; |
1734 | if (choice-- == 0) | 1697 | if (choice-- == 0) |
1735 | return; /* no non-masked peer available */ | 1698 | return; /* no non-masked peer available */ |
1736 | if (peer == NULL) | 1699 | if (peer == NULL) |
1737 | peer = bucket->head; | 1700 | peer = bucket->head; |
1738 | GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); | 1701 | GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); |
1739 | hello = GDS_HELLO_get (&peer->id); | 1702 | hello = GDS_HELLO_get (&peer->id); |
1740 | } | 1703 | } |
1741 | while ( (hello == NULL) || | 1704 | while ((hello == NULL) || |
1742 | (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ); | 1705 | (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash))); |
1743 | GDS_NEIGHBOURS_handle_reply (sender, | 1706 | GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO, |
1744 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1707 | GNUNET_TIME_relative_to_absolute |
1745 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), | 1708 | (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), key, |
1746 | key, | 1709 | 0, NULL, 0, NULL, hello, |
1747 | 0, NULL, | 1710 | GNUNET_HELLO_size (hello)); |
1748 | 0, NULL, | ||
1749 | hello, | ||
1750 | GNUNET_HELLO_size (hello)); | ||
1751 | } | 1711 | } |
1752 | 1712 | ||
1753 | 1713 | ||
@@ -1765,10 +1725,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1765 | */ | 1725 | */ |
1766 | static int | 1726 | static int |
1767 | handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | 1727 | handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, |
1768 | const struct GNUNET_MessageHeader *message, | 1728 | const struct GNUNET_MessageHeader *message, |
1769 | const struct GNUNET_ATS_Information | 1729 | const struct GNUNET_ATS_Information *atsi, |
1770 | *atsi, | 1730 | unsigned int atsi_count) |
1771 | unsigned int atsi_count) | ||
1772 | { | 1731 | { |
1773 | struct PeerGetMessage *get; | 1732 | struct PeerGetMessage *get; |
1774 | uint32_t xquery_size; | 1733 | uint32_t xquery_size; |
@@ -1781,7 +1740,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1781 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 1740 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
1782 | const char *xquery; | 1741 | const char *xquery; |
1783 | 1742 | ||
1784 | GNUNET_break (0 != memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))); | 1743 | GNUNET_break (0 != |
1744 | memcmp (peer, &my_identity, | ||
1745 | sizeof (struct GNUNET_PeerIdentity))); | ||
1785 | /* parse and validate message */ | 1746 | /* parse and validate message */ |
1786 | msize = ntohs (message->size); | 1747 | msize = ntohs (message->size); |
1787 | if (msize < sizeof (struct PeerGetMessage)) | 1748 | if (msize < sizeof (struct PeerGetMessage)) |
@@ -1797,24 +1758,20 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1797 | return GNUNET_YES; | 1758 | return GNUNET_YES; |
1798 | } | 1759 | } |
1799 | GNUNET_STATISTICS_update (GDS_stats, | 1760 | GNUNET_STATISTICS_update (GDS_stats, |
1800 | gettext_noop ("# P2P GET requests received"), 1, | 1761 | gettext_noop ("# P2P GET requests received"), 1, |
1801 | GNUNET_NO); | 1762 | GNUNET_NO); |
1802 | reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size); | 1763 | reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size); |
1803 | type = ntohl (get->type); | 1764 | type = ntohl (get->type); |
1804 | options = ntohl (get->options); | 1765 | options = ntohl (get->options); |
1805 | xquery = (const char*) &get[1]; | 1766 | xquery = (const char *) &get[1]; |
1806 | reply_bf = NULL; | 1767 | reply_bf = NULL; |
1807 | if (reply_bf_size > 0) | 1768 | if (reply_bf_size > 0) |
1808 | reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], | 1769 | reply_bf = |
1809 | reply_bf_size, | 1770 | GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], reply_bf_size, |
1810 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 1771 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
1811 | eval = GNUNET_BLOCK_evaluate (GDS_block_context, | 1772 | eval = |
1812 | type, | 1773 | GNUNET_BLOCK_evaluate (GDS_block_context, type, &get->key, &reply_bf, |
1813 | &get->key, | 1774 | get->bf_mutator, xquery, xquery_size, NULL, 0); |
1814 | &reply_bf, | ||
1815 | get->bf_mutator, | ||
1816 | xquery, xquery_size, | ||
1817 | NULL, 0); | ||
1818 | if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) | 1775 | if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) |
1819 | { | 1776 | { |
1820 | /* request invalid or block type not supported */ | 1777 | /* request invalid or block type not supported */ |
@@ -1824,70 +1781,55 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1824 | return GNUNET_YES; | 1781 | return GNUNET_YES; |
1825 | } | 1782 | } |
1826 | peer_bf = | 1783 | peer_bf = |
1827 | GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, | 1784 | GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, DHT_BLOOM_SIZE, |
1828 | DHT_BLOOM_SIZE, | 1785 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
1829 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 1786 | GNUNET_break_op (GNUNET_YES == |
1830 | GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &peer->hashPubKey)); | 1787 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, |
1788 | &peer->hashPubKey)); | ||
1831 | /* remember request for routing replies */ | 1789 | /* remember request for routing replies */ |
1832 | GDS_ROUTING_add (peer, | 1790 | GDS_ROUTING_add (peer, type, options, &get->key, xquery, xquery_size, |
1833 | type, | 1791 | reply_bf, get->bf_mutator); |
1834 | options, | ||
1835 | &get->key, | ||
1836 | xquery, xquery_size, | ||
1837 | reply_bf, get->bf_mutator); | ||
1838 | #if DEBUG_DHT | 1792 | #if DEBUG_DHT |
1839 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1793 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n", |
1840 | "GET for %s at %s after %u hops\n", | 1794 | GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity), |
1841 | GNUNET_h2s (&get->key), | 1795 | (unsigned int) ntohl (get->hop_count)); |
1842 | GNUNET_i2s (&my_identity), | ||
1843 | (unsigned int) ntohl (get->hop_count)); | ||
1844 | #endif | 1796 | #endif |
1845 | /* local lookup (this may update the reply_bf) */ | 1797 | /* local lookup (this may update the reply_bf) */ |
1846 | if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 1798 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
1847 | (am_closest_peer (&get->key, | 1799 | (am_closest_peer (&get->key, peer_bf))) |
1848 | peer_bf) ) ) | 1800 | { |
1849 | { | 1801 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) |
1850 | if ( (0 != (options & GNUNET_DHT_RO_FIND_PEER))) | ||
1851 | { | 1802 | { |
1852 | GNUNET_STATISTICS_update (GDS_stats, | 1803 | GNUNET_STATISTICS_update (GDS_stats, |
1853 | gettext_noop ("# P2P FIND PEER requests processed"), 1, | 1804 | gettext_noop |
1854 | GNUNET_NO); | 1805 | ("# P2P FIND PEER requests processed"), 1, |
1855 | handle_find_peer (peer, | 1806 | GNUNET_NO); |
1856 | &get->key, | 1807 | handle_find_peer (peer, &get->key, reply_bf, get->bf_mutator); |
1857 | reply_bf, | ||
1858 | get->bf_mutator); | ||
1859 | } | 1808 | } |
1860 | else | 1809 | else |
1861 | { | 1810 | { |
1862 | eval = GDS_DATACACHE_handle_get (&get->key, | 1811 | eval = |
1863 | type, | 1812 | GDS_DATACACHE_handle_get (&get->key, type, xquery, xquery_size, |
1864 | xquery, xquery_size, | 1813 | &reply_bf, get->bf_mutator); |
1865 | &reply_bf, | ||
1866 | get->bf_mutator); | ||
1867 | } | 1814 | } |
1868 | } | 1815 | } |
1869 | else | 1816 | else |
1870 | { | 1817 | { |
1871 | GNUNET_STATISTICS_update (GDS_stats, | 1818 | GNUNET_STATISTICS_update (GDS_stats, |
1872 | gettext_noop ("# P2P GET requests ONLY routed"), 1, | 1819 | gettext_noop ("# P2P GET requests ONLY routed"), |
1873 | GNUNET_NO); | 1820 | 1, GNUNET_NO); |
1874 | } | 1821 | } |
1875 | 1822 | ||
1876 | /* P2P forwarding */ | 1823 | /* P2P forwarding */ |
1877 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) | 1824 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) |
1878 | GDS_NEIGHBOURS_handle_get (type, | 1825 | GDS_NEIGHBOURS_handle_get (type, options, |
1879 | options, | 1826 | ntohl (get->desired_replication_level), |
1880 | ntohl (get->desired_replication_level), | 1827 | ntohl (get->hop_count), &get->key, xquery, |
1881 | ntohl (get->hop_count), | 1828 | xquery_size, reply_bf, get->bf_mutator, peer_bf); |
1882 | &get->key, | ||
1883 | xquery, xquery_size, | ||
1884 | reply_bf, | ||
1885 | get->bf_mutator, | ||
1886 | peer_bf); | ||
1887 | /* clean up */ | 1829 | /* clean up */ |
1888 | if (NULL != reply_bf) | 1830 | if (NULL != reply_bf) |
1889 | GNUNET_CONTAINER_bloomfilter_free (reply_bf); | 1831 | GNUNET_CONTAINER_bloomfilter_free (reply_bf); |
1890 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); | 1832 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
1891 | return GNUNET_YES; | 1833 | return GNUNET_YES; |
1892 | } | 1834 | } |
1893 | 1835 | ||
@@ -1904,10 +1846,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1904 | */ | 1846 | */ |
1905 | static int | 1847 | static int |
1906 | handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | 1848 | handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, |
1907 | const struct GNUNET_MessageHeader *message, | 1849 | const struct GNUNET_MessageHeader *message, |
1908 | const struct GNUNET_ATS_Information | 1850 | const struct GNUNET_ATS_Information *atsi, |
1909 | *atsi, | 1851 | unsigned int atsi_count) |
1910 | unsigned int atsi_count) | ||
1911 | { | 1852 | { |
1912 | const struct PeerResultMessage *prm; | 1853 | const struct PeerResultMessage *prm; |
1913 | const struct GNUNET_PeerIdentity *put_path; | 1854 | const struct GNUNET_PeerIdentity *put_path; |
@@ -1918,7 +1859,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1918 | uint16_t msize; | 1859 | uint16_t msize; |
1919 | size_t data_size; | 1860 | size_t data_size; |
1920 | enum GNUNET_BLOCK_Type type; | 1861 | enum GNUNET_BLOCK_Type type; |
1921 | 1862 | ||
1922 | /* parse and validate message */ | 1863 | /* parse and validate message */ |
1923 | msize = ntohs (message->size); | 1864 | msize = ntohs (message->size); |
1924 | if (msize < sizeof (struct PeerResultMessage)) | 1865 | if (msize < sizeof (struct PeerResultMessage)) |
@@ -1929,23 +1870,28 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1929 | prm = (struct PeerResultMessage *) message; | 1870 | prm = (struct PeerResultMessage *) message; |
1930 | put_path_length = ntohl (prm->put_path_length); | 1871 | put_path_length = ntohl (prm->put_path_length); |
1931 | get_path_length = ntohl (prm->get_path_length); | 1872 | get_path_length = ntohl (prm->get_path_length); |
1932 | if ( (msize < sizeof (struct PeerResultMessage) + | 1873 | if ((msize < |
1933 | (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)) || | 1874 | sizeof (struct PeerResultMessage) + (get_path_length + |
1934 | (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || | 1875 | put_path_length) * |
1935 | (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) | 1876 | sizeof (struct GNUNET_PeerIdentity)) || |
1877 | (get_path_length > | ||
1878 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || | ||
1879 | (put_path_length > | ||
1880 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | ||
1936 | { | 1881 | { |
1937 | GNUNET_break_op (0); | 1882 | GNUNET_break_op (0); |
1938 | return GNUNET_YES; | 1883 | return GNUNET_YES; |
1939 | } | 1884 | } |
1940 | GNUNET_STATISTICS_update (GDS_stats, | 1885 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P RESULTS received"), |
1941 | gettext_noop ("# P2P RESULTS received"), 1, | 1886 | 1, GNUNET_NO); |
1942 | GNUNET_NO); | 1887 | put_path = (const struct GNUNET_PeerIdentity *) &prm[1]; |
1943 | put_path = (const struct GNUNET_PeerIdentity*) &prm[1]; | ||
1944 | get_path = &put_path[put_path_length]; | 1888 | get_path = &put_path[put_path_length]; |
1945 | type = ntohl (prm->type); | 1889 | type = ntohl (prm->type); |
1946 | data = (const void*) &get_path[get_path_length]; | 1890 | data = (const void *) &get_path[get_path_length]; |
1947 | data_size = msize - (sizeof (struct PeerResultMessage) + | 1891 | data_size = |
1948 | (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)); | 1892 | msize - (sizeof (struct PeerResultMessage) + |
1893 | (get_path_length + | ||
1894 | put_path_length) * sizeof (struct GNUNET_PeerIdentity)); | ||
1949 | 1895 | ||
1950 | /* if we got a HELLO, consider it for our own routing table */ | 1896 | /* if we got a HELLO, consider it for our own routing table */ |
1951 | if (type == GNUNET_BLOCK_TYPE_DHT_HELLO) | 1897 | if (type == GNUNET_BLOCK_TYPE_DHT_HELLO) |
@@ -1967,8 +1913,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1967 | return GNUNET_YES; | 1913 | return GNUNET_YES; |
1968 | } | 1914 | } |
1969 | if (GNUNET_OK != | 1915 | if (GNUNET_OK != |
1970 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) h, | 1916 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, &pid)) |
1971 | &pid)) | ||
1972 | { | 1917 | { |
1973 | GNUNET_break_op (0); | 1918 | GNUNET_break_op (0); |
1974 | return GNUNET_YES; | 1919 | return GNUNET_YES; |
@@ -1976,49 +1921,35 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1976 | if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity))) | 1921 | if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity))) |
1977 | { | 1922 | { |
1978 | bucket = find_bucket (&pid.hashPubKey); | 1923 | bucket = find_bucket (&pid.hashPubKey); |
1979 | if ( (bucket >= 0) && | 1924 | if ((bucket >= 0) && (k_buckets[bucket].peers_size < bucket_size)) |
1980 | (k_buckets[bucket].peers_size < bucket_size) ) | 1925 | { |
1981 | { | 1926 | if (NULL != GDS_transport_handle) |
1982 | if (NULL != GDS_transport_handle) | 1927 | { |
1983 | { | 1928 | GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL); |
1984 | GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, | 1929 | GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid); |
1985 | h, NULL, NULL); | 1930 | } |
1986 | GNUNET_TRANSPORT_try_connect (GDS_transport_handle, | 1931 | } |
1987 | &pid); | ||
1988 | } | ||
1989 | } | ||
1990 | } | 1932 | } |
1991 | } | 1933 | } |
1992 | 1934 | ||
1993 | /* append 'peer' to 'get_path' */ | 1935 | /* append 'peer' to 'get_path' */ |
1994 | { | 1936 | { |
1995 | struct GNUNET_PeerIdentity xget_path[get_path_length+1]; | 1937 | struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; |
1996 | 1938 | ||
1997 | memcpy (xget_path, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 1939 | memcpy (xget_path, get_path, |
1940 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1998 | xget_path[get_path_length] = *peer; | 1941 | xget_path[get_path_length] = *peer; |
1999 | get_path_length++; | 1942 | get_path_length++; |
2000 | 1943 | ||
2001 | /* forward to local clients */ | 1944 | /* forward to local clients */ |
2002 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time), | 1945 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time), |
2003 | &prm->key, | 1946 | &prm->key, get_path_length, xget_path, |
2004 | get_path_length, | 1947 | put_path_length, put_path, type, data_size, data); |
2005 | xget_path, | ||
2006 | put_path_length, | ||
2007 | put_path, | ||
2008 | type, | ||
2009 | data_size, | ||
2010 | data); | ||
2011 | 1948 | ||
2012 | /* forward to other peers */ | 1949 | /* forward to other peers */ |
2013 | GDS_ROUTING_process (type, | 1950 | GDS_ROUTING_process (type, GNUNET_TIME_absolute_ntoh (prm->expiration_time), |
2014 | GNUNET_TIME_absolute_ntoh (prm->expiration_time), | 1951 | &prm->key, put_path_length, put_path, get_path_length, |
2015 | &prm->key, | 1952 | xget_path, data, data_size); |
2016 | put_path_length, | ||
2017 | put_path, | ||
2018 | get_path_length, | ||
2019 | xget_path, | ||
2020 | data, | ||
2021 | data_size); | ||
2022 | } | 1953 | } |
2023 | return GNUNET_YES; | 1954 | return GNUNET_YES; |
2024 | } | 1955 | } |
@@ -2039,21 +1970,16 @@ GDS_NEIGHBOURS_init () | |||
2039 | {NULL, 0, 0} | 1970 | {NULL, 0, 0} |
2040 | }; | 1971 | }; |
2041 | unsigned long long temp_config_num; | 1972 | unsigned long long temp_config_num; |
2042 | 1973 | ||
2043 | if (GNUNET_OK == | 1974 | if (GNUNET_OK == |
2044 | GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", | 1975 | GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", |
2045 | &temp_config_num)) | 1976 | &temp_config_num)) |
2046 | bucket_size = (unsigned int) temp_config_num; | 1977 | bucket_size = (unsigned int) temp_config_num; |
2047 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); | 1978 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); |
2048 | coreAPI = GNUNET_CORE_connect (GDS_cfg, | 1979 | coreAPI = |
2049 | 1, | 1980 | GNUNET_CORE_connect (GDS_cfg, 1, NULL, &core_init, &handle_core_connect, |
2050 | NULL, | 1981 | &handle_core_disconnect, NULL, GNUNET_NO, NULL, |
2051 | &core_init, | 1982 | GNUNET_NO, core_handlers); |
2052 | &handle_core_connect, | ||
2053 | &handle_core_disconnect, | ||
2054 | NULL, GNUNET_NO, | ||
2055 | NULL, GNUNET_NO, | ||
2056 | core_handlers); | ||
2057 | if (coreAPI == NULL) | 1983 | if (coreAPI == NULL) |
2058 | return GNUNET_SYSERR; | 1984 | return GNUNET_SYSERR; |
2059 | all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); | 1985 | all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); |
@@ -2070,9 +1996,9 @@ GDS_NEIGHBOURS_done () | |||
2070 | if (coreAPI == NULL) | 1996 | if (coreAPI == NULL) |
2071 | return; | 1997 | return; |
2072 | GNUNET_CORE_disconnect (coreAPI); | 1998 | GNUNET_CORE_disconnect (coreAPI); |
2073 | coreAPI = NULL; | 1999 | coreAPI = NULL; |
2074 | GNUNET_ATS_performance_done (atsAPI); | 2000 | GNUNET_ATS_performance_done (atsAPI); |
2075 | atsAPI = NULL; | 2001 | atsAPI = NULL; |
2076 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); | 2002 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); |
2077 | GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); | 2003 | GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); |
2078 | all_known_peers = NULL; | 2004 | all_known_peers = NULL; |
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h index d23ea10ab..b6e0f0ec0 100644 --- a/src/dht/gnunet-service-dht_neighbours.h +++ b/src/dht/gnunet-service-dht_neighbours.h | |||
@@ -52,16 +52,15 @@ | |||
52 | */ | 52 | */ |
53 | void | 53 | void |
54 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | 54 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, |
55 | enum GNUNET_DHT_RouteOption options, | 55 | enum GNUNET_DHT_RouteOption options, |
56 | uint32_t desired_replication_level, | 56 | uint32_t desired_replication_level, |
57 | struct GNUNET_TIME_Absolute expiration_time, | 57 | struct GNUNET_TIME_Absolute expiration_time, |
58 | uint32_t hop_count, | 58 | uint32_t hop_count, |
59 | struct GNUNET_CONTAINER_BloomFilter *bf, | 59 | struct GNUNET_CONTAINER_BloomFilter *bf, |
60 | const GNUNET_HashCode *key, | 60 | const GNUNET_HashCode * key, |
61 | unsigned int put_path_length, | 61 | unsigned int put_path_length, |
62 | struct GNUNET_PeerIdentity *put_path, | 62 | struct GNUNET_PeerIdentity *put_path, |
63 | const void *data, | 63 | const void *data, size_t data_size); |
64 | size_t data_size); | ||
65 | 64 | ||
66 | 65 | ||
67 | /** | 66 | /** |
@@ -83,15 +82,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
83 | */ | 82 | */ |
84 | void | 83 | void |
85 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | 84 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, |
86 | enum GNUNET_DHT_RouteOption options, | 85 | enum GNUNET_DHT_RouteOption options, |
87 | uint32_t desired_replication_level, | 86 | uint32_t desired_replication_level, |
88 | uint32_t hop_count, | 87 | uint32_t hop_count, const GNUNET_HashCode * key, |
89 | const GNUNET_HashCode *key, | 88 | const void *xquery, size_t xquery_size, |
90 | const void *xquery, | 89 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, |
91 | size_t xquery_size, | 90 | uint32_t reply_bf_mutator, |
92 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, | 91 | struct GNUNET_CONTAINER_BloomFilter *peer_bf); |
93 | uint32_t reply_bf_mutator, | ||
94 | struct GNUNET_CONTAINER_BloomFilter *peer_bf); | ||
95 | 92 | ||
96 | 93 | ||
97 | /** | 94 | /** |
@@ -112,15 +109,14 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
112 | */ | 109 | */ |
113 | void | 110 | void |
114 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | 111 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, |
115 | enum GNUNET_BLOCK_Type type, | 112 | enum GNUNET_BLOCK_Type type, |
116 | struct GNUNET_TIME_Absolute expiration_time, | 113 | struct GNUNET_TIME_Absolute expiration_time, |
117 | const GNUNET_HashCode *key, | 114 | const GNUNET_HashCode * key, |
118 | unsigned int put_path_length, | 115 | unsigned int put_path_length, |
119 | const struct GNUNET_PeerIdentity *put_path, | 116 | const struct GNUNET_PeerIdentity *put_path, |
120 | unsigned int get_path_length, | 117 | unsigned int get_path_length, |
121 | const struct GNUNET_PeerIdentity *get_path, | 118 | const struct GNUNET_PeerIdentity *get_path, |
122 | const void *data, | 119 | const void *data, size_t data_size); |
123 | size_t data_size); | ||
124 | 120 | ||
125 | 121 | ||
126 | /** | 122 | /** |
diff --git a/src/dht/gnunet-service-dht_nse.c b/src/dht/gnunet-service-dht_nse.c index 0a662ec7b..777998967 100644 --- a/src/dht/gnunet-service-dht_nse.c +++ b/src/dht/gnunet-service-dht_nse.c | |||
@@ -56,10 +56,10 @@ update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, | |||
56 | double logestimate, double std_dev) | 56 | double logestimate, double std_dev) |
57 | { | 57 | { |
58 | GNUNET_STATISTICS_update (GDS_stats, | 58 | GNUNET_STATISTICS_update (GDS_stats, |
59 | gettext_noop ("# Network size estimates received"), 1, | 59 | gettext_noop ("# Network size estimates received"), |
60 | GNUNET_NO); | 60 | 1, GNUNET_NO); |
61 | /* do not allow estimates < 0.5 */ | 61 | /* do not allow estimates < 0.5 */ |
62 | log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate); | 62 | log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate); |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
@@ -90,9 +90,9 @@ GDS_NSE_init () | |||
90 | */ | 90 | */ |
91 | void | 91 | void |
92 | GDS_NSE_done () | 92 | GDS_NSE_done () |
93 | { | 93 | { |
94 | if (NULL != nse) | 94 | if (NULL != nse) |
95 | { | 95 | { |
96 | GNUNET_NSE_disconnect (nse); | 96 | GNUNET_NSE_disconnect (nse); |
97 | nse = NULL; | 97 | nse = NULL; |
98 | } | 98 | } |
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c index 607c756c6..a880bf7cd 100644 --- a/src/dht/gnunet-service-dht_routing.c +++ b/src/dht/gnunet-service-dht_routing.c | |||
@@ -66,7 +66,7 @@ struct RecentRequest | |||
66 | * Type of the requested block. | 66 | * Type of the requested block. |
67 | */ | 67 | */ |
68 | enum GNUNET_BLOCK_Type type; | 68 | enum GNUNET_BLOCK_Type type; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * extended query (see gnunet_block_lib.h). Allocated at the | 71 | * extended query (see gnunet_block_lib.h). Allocated at the |
72 | * end of this struct. | 72 | * end of this struct. |
@@ -114,7 +114,7 @@ struct ProcessContext | |||
114 | 114 | ||
115 | /** | 115 | /** |
116 | * Path of the reply. | 116 | * Path of the reply. |
117 | */ | 117 | */ |
118 | const struct GNUNET_PeerIdentity *get_path; | 118 | const struct GNUNET_PeerIdentity *get_path; |
119 | 119 | ||
120 | /** | 120 | /** |
@@ -156,13 +156,11 @@ struct ProcessContext | |||
156 | * @param cls the 'struct ProcessContext' with the result | 156 | * @param cls the 'struct ProcessContext' with the result |
157 | * @param key the query | 157 | * @param key the query |
158 | * @param value the 'struct RecentRequest' with the request | 158 | * @param value the 'struct RecentRequest' with the request |
159 | * @return GNUNET_OK (continue to iterate), | 159 | * @return GNUNET_OK (continue to iterate), |
160 | * GNUNET_SYSERR if the result is malformed or type unsupported | 160 | * GNUNET_SYSERR if the result is malformed or type unsupported |
161 | */ | 161 | */ |
162 | static int | 162 | static int |
163 | process (void *cls, | 163 | process (void *cls, const GNUNET_HashCode * key, void *value) |
164 | const GNUNET_HashCode *key, | ||
165 | void *value) | ||
166 | { | 164 | { |
167 | struct ProcessContext *pc = cls; | 165 | struct ProcessContext *pc = cls; |
168 | struct RecentRequest *rr = value; | 166 | struct RecentRequest *rr = value; |
@@ -172,9 +170,8 @@ process (void *cls, | |||
172 | GNUNET_HashCode hc; | 170 | GNUNET_HashCode hc; |
173 | const GNUNET_HashCode *eval_key; | 171 | const GNUNET_HashCode *eval_key; |
174 | 172 | ||
175 | if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) && | 173 | if ((rr->type != GNUNET_BLOCK_TYPE_ANY) && (rr->type != pc->type)) |
176 | (rr->type != pc->type) ) | 174 | return GNUNET_OK; /* type missmatch */ |
177 | return GNUNET_OK; /* type missmatch */ | ||
178 | 175 | ||
179 | if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) | 176 | if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) |
180 | { | 177 | { |
@@ -186,59 +183,48 @@ process (void *cls, | |||
186 | gpl = 0; | 183 | gpl = 0; |
187 | ppl = 0; | 184 | ppl = 0; |
188 | } | 185 | } |
189 | if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && | 186 | if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && |
190 | (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) ) | 187 | (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO)) |
191 | { | 188 | { |
192 | /* key may not match HELLO, which is OK since | 189 | /* key may not match HELLO, which is OK since |
193 | the search is approximate. Still, the evaluation | 190 | * the search is approximate. Still, the evaluation |
194 | would fail since the match is not exact. So | 191 | * would fail since the match is not exact. So |
195 | we fake it by changing the key to the actual PID ... */ | 192 | * we fake it by changing the key to the actual PID ... */ |
196 | GNUNET_BLOCK_get_key (GDS_block_context, | 193 | GNUNET_BLOCK_get_key (GDS_block_context, GNUNET_BLOCK_TYPE_DHT_HELLO, |
197 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 194 | pc->data, pc->data_size, &hc); |
198 | pc->data, pc->data_size, | ||
199 | &hc); | ||
200 | eval_key = &hc; | 195 | eval_key = &hc; |
201 | } | 196 | } |
202 | else | 197 | else |
203 | { | 198 | { |
204 | eval_key = key; | 199 | eval_key = key; |
205 | } | 200 | } |
206 | eval = GNUNET_BLOCK_evaluate (GDS_block_context, | 201 | eval = |
207 | pc->type, | 202 | GNUNET_BLOCK_evaluate (GDS_block_context, pc->type, eval_key, |
208 | eval_key, | 203 | &rr->reply_bf, rr->reply_bf_mutator, rr->xquery, |
209 | &rr->reply_bf, | 204 | rr->xquery_size, pc->data, pc->data_size); |
210 | rr->reply_bf_mutator, | ||
211 | rr->xquery, | ||
212 | rr->xquery_size, | ||
213 | pc->data, | ||
214 | pc->data_size); | ||
215 | switch (eval) | 205 | switch (eval) |
216 | { | 206 | { |
217 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 207 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
218 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 208 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
219 | GNUNET_STATISTICS_update (GDS_stats, | 209 | GNUNET_STATISTICS_update (GDS_stats, |
220 | gettext_noop ("# Good REPLIES matched against routing table"), 1, | 210 | gettext_noop |
221 | GNUNET_NO); | 211 | ("# Good REPLIES matched against routing table"), |
222 | GDS_NEIGHBOURS_handle_reply (&rr->peer, | 212 | 1, GNUNET_NO); |
223 | pc->type, | 213 | GDS_NEIGHBOURS_handle_reply (&rr->peer, pc->type, pc->expiration_time, key, |
224 | pc->expiration_time, | 214 | ppl, pc->put_path, gpl, pc->get_path, pc->data, |
225 | key, | 215 | pc->data_size); |
226 | ppl, | ||
227 | pc->put_path, | ||
228 | gpl, | ||
229 | pc->get_path, | ||
230 | pc->data, | ||
231 | pc->data_size); | ||
232 | break; | 216 | break; |
233 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 217 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
234 | GNUNET_STATISTICS_update (GDS_stats, | 218 | GNUNET_STATISTICS_update (GDS_stats, |
235 | gettext_noop ("# Duplicate REPLIES matched against routing table"), 1, | 219 | gettext_noop |
236 | GNUNET_NO); | 220 | ("# Duplicate REPLIES matched against routing table"), |
221 | 1, GNUNET_NO); | ||
237 | return GNUNET_OK; | 222 | return GNUNET_OK; |
238 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 223 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
239 | GNUNET_STATISTICS_update (GDS_stats, | 224 | GNUNET_STATISTICS_update (GDS_stats, |
240 | gettext_noop ("# Invalid REPLIES matched against routing table"), 1, | 225 | gettext_noop |
241 | GNUNET_NO); | 226 | ("# Invalid REPLIES matched against routing table"), |
227 | 1, GNUNET_NO); | ||
242 | return GNUNET_SYSERR; | 228 | return GNUNET_SYSERR; |
243 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | 229 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: |
244 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | 230 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: |
@@ -246,12 +232,13 @@ process (void *cls, | |||
246 | return GNUNET_OK; | 232 | return GNUNET_OK; |
247 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 233 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
248 | GNUNET_STATISTICS_update (GDS_stats, | 234 | GNUNET_STATISTICS_update (GDS_stats, |
249 | gettext_noop ("# Unsupported REPLIES matched against routing table"), 1, | 235 | gettext_noop |
250 | GNUNET_NO); | 236 | ("# Unsupported REPLIES matched against routing table"), |
237 | 1, GNUNET_NO); | ||
251 | return GNUNET_SYSERR; | 238 | return GNUNET_SYSERR; |
252 | default: | 239 | default: |
253 | GNUNET_break (0); | 240 | GNUNET_break (0); |
254 | return GNUNET_SYSERR; | 241 | return GNUNET_SYSERR; |
255 | } | 242 | } |
256 | return GNUNET_OK; | 243 | return GNUNET_OK; |
257 | } | 244 | } |
@@ -276,14 +263,12 @@ process (void *cls, | |||
276 | */ | 263 | */ |
277 | void | 264 | void |
278 | GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, | 265 | GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, |
279 | struct GNUNET_TIME_Absolute expiration_time, | 266 | struct GNUNET_TIME_Absolute expiration_time, |
280 | const GNUNET_HashCode *key, | 267 | const GNUNET_HashCode * key, unsigned int put_path_length, |
281 | unsigned int put_path_length, | 268 | const struct GNUNET_PeerIdentity *put_path, |
282 | const struct GNUNET_PeerIdentity *put_path, | 269 | unsigned int get_path_length, |
283 | unsigned int get_path_length, | 270 | const struct GNUNET_PeerIdentity *get_path, |
284 | const struct GNUNET_PeerIdentity *get_path, | 271 | const void *data, size_t data_size) |
285 | const void *data, | ||
286 | size_t data_size) | ||
287 | { | 272 | { |
288 | struct ProcessContext pc; | 273 | struct ProcessContext pc; |
289 | 274 | ||
@@ -295,10 +280,7 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, | |||
295 | pc.get_path = get_path; | 280 | pc.get_path = get_path; |
296 | pc.data = data; | 281 | pc.data = data; |
297 | pc.data_size = data_size; | 282 | pc.data_size = data_size; |
298 | GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, | 283 | GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, key, &process, &pc); |
299 | key, | ||
300 | &process, | ||
301 | &pc); | ||
302 | } | 284 | } |
303 | 285 | ||
304 | 286 | ||
@@ -316,21 +298,21 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, | |||
316 | */ | 298 | */ |
317 | void | 299 | void |
318 | GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, | 300 | GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, |
319 | enum GNUNET_BLOCK_Type type, | 301 | enum GNUNET_BLOCK_Type type, |
320 | enum GNUNET_DHT_RouteOption options, | 302 | enum GNUNET_DHT_RouteOption options, |
321 | const GNUNET_HashCode *key, | 303 | const GNUNET_HashCode * key, const void *xquery, |
322 | const void *xquery, | 304 | size_t xquery_size, |
323 | size_t xquery_size, | 305 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, |
324 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, | 306 | uint32_t reply_bf_mutator) |
325 | uint32_t reply_bf_mutator) | ||
326 | { | 307 | { |
327 | struct RecentRequest *recent_req; | 308 | struct RecentRequest *recent_req; |
328 | 309 | ||
329 | while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) | 310 | while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) |
330 | { | 311 | { |
331 | GNUNET_STATISTICS_update (GDS_stats, | 312 | GNUNET_STATISTICS_update (GDS_stats, |
332 | gettext_noop ("# Entries removed from routing table"), 1, | 313 | gettext_noop |
333 | GNUNET_NO); | 314 | ("# Entries removed from routing table"), 1, |
315 | GNUNET_NO); | ||
334 | recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); | 316 | recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); |
335 | GNUNET_assert (recent_req != NULL); | 317 | GNUNET_assert (recent_req != NULL); |
336 | GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); | 318 | GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); |
@@ -339,25 +321,22 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, | |||
339 | } | 321 | } |
340 | 322 | ||
341 | GNUNET_STATISTICS_update (GDS_stats, | 323 | GNUNET_STATISTICS_update (GDS_stats, |
342 | gettext_noop ("# Entries added to routing table"), 1, | 324 | gettext_noop ("# Entries added to routing table"), |
343 | GNUNET_NO); | 325 | 1, GNUNET_NO); |
344 | recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size); | 326 | recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size); |
345 | recent_req->peer = *sender; | 327 | recent_req->peer = *sender; |
346 | recent_req->key = *key; | 328 | recent_req->key = *key; |
347 | recent_req->heap_node = | 329 | recent_req->heap_node = |
348 | GNUNET_CONTAINER_heap_insert (recent_heap, recent_req, | 330 | GNUNET_CONTAINER_heap_insert (recent_heap, recent_req, |
349 | GNUNET_TIME_absolute_get ().abs_value); | 331 | GNUNET_TIME_absolute_get ().abs_value); |
350 | recent_req->reply_bf = | 332 | recent_req->reply_bf = GNUNET_CONTAINER_bloomfilter_copy (reply_bf); |
351 | GNUNET_CONTAINER_bloomfilter_copy (reply_bf); | ||
352 | recent_req->type = type; | 333 | recent_req->type = type; |
353 | recent_req->options = options; | 334 | recent_req->options = options; |
354 | recent_req->xquery = &recent_req[1]; | 335 | recent_req->xquery = &recent_req[1]; |
355 | recent_req->xquery_size = xquery_size; | 336 | recent_req->xquery_size = xquery_size; |
356 | recent_req->reply_bf_mutator = reply_bf_mutator; | 337 | recent_req->reply_bf_mutator = reply_bf_mutator; |
357 | GNUNET_CONTAINER_multihashmap_put (recent_map, | 338 | GNUNET_CONTAINER_multihashmap_put (recent_map, key, recent_req, |
358 | key, | 339 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
359 | recent_req, | ||
360 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
361 | 340 | ||
362 | 341 | ||
363 | } | 342 | } |
@@ -369,10 +348,8 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, | |||
369 | void | 348 | void |
370 | GDS_ROUTING_init () | 349 | GDS_ROUTING_init () |
371 | { | 350 | { |
372 | recent_heap = | 351 | recent_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
373 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 352 | recent_map = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3); |
374 | recent_map = | ||
375 | GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3); | ||
376 | } | 353 | } |
377 | 354 | ||
378 | 355 | ||
@@ -387,8 +364,9 @@ GDS_ROUTING_done () | |||
387 | while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0) | 364 | while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0) |
388 | { | 365 | { |
389 | GNUNET_STATISTICS_update (GDS_stats, | 366 | GNUNET_STATISTICS_update (GDS_stats, |
390 | gettext_noop ("# Entries removed from routing table"), 1, | 367 | gettext_noop |
391 | GNUNET_NO); | 368 | ("# Entries removed from routing table"), 1, |
369 | GNUNET_NO); | ||
392 | recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); | 370 | recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); |
393 | GNUNET_assert (recent_req != NULL); | 371 | GNUNET_assert (recent_req != NULL); |
394 | GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); | 372 | GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); |
diff --git a/src/dht/gnunet-service-dht_routing.h b/src/dht/gnunet-service-dht_routing.h index a2576a3bb..9b12c71de 100644 --- a/src/dht/gnunet-service-dht_routing.h +++ b/src/dht/gnunet-service-dht_routing.h | |||
@@ -50,14 +50,12 @@ | |||
50 | */ | 50 | */ |
51 | void | 51 | void |
52 | GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, | 52 | GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, |
53 | struct GNUNET_TIME_Absolute expiration_time, | 53 | struct GNUNET_TIME_Absolute expiration_time, |
54 | const GNUNET_HashCode *key, | 54 | const GNUNET_HashCode * key, unsigned int put_path_length, |
55 | unsigned int put_path_length, | 55 | const struct GNUNET_PeerIdentity *put_path, |
56 | const struct GNUNET_PeerIdentity *put_path, | 56 | unsigned int get_path_length, |
57 | unsigned int get_path_length, | 57 | const struct GNUNET_PeerIdentity *get_path, |
58 | const struct GNUNET_PeerIdentity *get_path, | 58 | const void *data, size_t data_size); |
59 | const void *data, | ||
60 | size_t data_size); | ||
61 | 59 | ||
62 | 60 | ||
63 | /** | 61 | /** |
@@ -74,13 +72,12 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, | |||
74 | */ | 72 | */ |
75 | void | 73 | void |
76 | GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, | 74 | GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, |
77 | enum GNUNET_BLOCK_Type type, | 75 | enum GNUNET_BLOCK_Type type, |
78 | enum GNUNET_DHT_RouteOption options, | 76 | enum GNUNET_DHT_RouteOption options, |
79 | const GNUNET_HashCode *key, | 77 | const GNUNET_HashCode * key, const void *xquery, |
80 | const void *xquery, | 78 | size_t xquery_size, |
81 | size_t xquery_size, | 79 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, |
82 | const struct GNUNET_CONTAINER_BloomFilter *reply_bf, | 80 | uint32_t reply_bf_mutator); |
83 | uint32_t reply_bf_mutator); | ||
84 | 81 | ||
85 | 82 | ||
86 | /** | 83 | /** |
diff --git a/src/dht/test_dht_2dtorus.c b/src/dht/test_dht_2dtorus.c index 220554e15..1db351841 100644 --- a/src/dht/test_dht_2dtorus.c +++ b/src/dht/test_dht_2dtorus.c | |||
@@ -138,7 +138,8 @@ shutdown_callback (void *cls, const char *emsg) | |||
138 | else | 138 | else |
139 | { | 139 | { |
140 | #if VERBOSE | 140 | #if VERBOSE |
141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); | 141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
142 | "test: All peers successfully shut down!\n"); | ||
142 | #endif | 143 | #endif |
143 | } | 144 | } |
144 | } | 145 | } |
@@ -169,22 +170,21 @@ disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
169 | { | 170 | { |
170 | unsigned int i; | 171 | unsigned int i; |
171 | 172 | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); |
173 | "test: disconnecting peers\n"); | ||
174 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 174 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
175 | GNUNET_SCHEDULER_cancel (put_task); | 175 | GNUNET_SCHEDULER_cancel (put_task); |
176 | if (NULL != get_h) | 176 | if (NULL != get_h) |
177 | GNUNET_DHT_get_stop(get_h); | 177 | GNUNET_DHT_get_stop (get_h); |
178 | if (NULL != get_h_2) | 178 | if (NULL != get_h_2) |
179 | GNUNET_DHT_get_stop(get_h_2); | 179 | GNUNET_DHT_get_stop (get_h_2); |
180 | if (NULL != get_h_far) | 180 | if (NULL != get_h_far) |
181 | GNUNET_DHT_get_stop(get_h_far); | 181 | GNUNET_DHT_get_stop (get_h_far); |
182 | for (i = 0; i < num_peers; i++) | 182 | for (i = 0; i < num_peers; i++) |
183 | { | 183 | { |
184 | GNUNET_DHT_disconnect(hs[i]); | 184 | GNUNET_DHT_disconnect (hs[i]); |
185 | } | 185 | } |
186 | GNUNET_SCHEDULER_cancel (shutdown_handle); | 186 | GNUNET_SCHEDULER_cancel (shutdown_handle); |
187 | shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); | 187 | shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
188 | } | 188 | } |
189 | 189 | ||
190 | static void | 190 | static void |
@@ -193,44 +193,39 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
193 | const struct GNUNET_PeerIdentity *get_path, | 193 | const struct GNUNET_PeerIdentity *get_path, |
194 | unsigned int get_path_length, | 194 | unsigned int get_path_length, |
195 | const struct GNUNET_PeerIdentity *put_path, | 195 | const struct GNUNET_PeerIdentity *put_path, |
196 | unsigned int put_path_length, | 196 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
197 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 197 | size_t size, const void *data) |
198 | { | 198 | { |
199 | int i; | 199 | int i; |
200 | 200 | ||
201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
202 | "test: ************* FOUND!!! ***********\n"); | 202 | "test: ************* FOUND!!! ***********\n"); |
203 | if (sizeof(GNUNET_HashCode) == size) | 203 | if (sizeof (GNUNET_HashCode) == size) |
204 | { | 204 | { |
205 | const GNUNET_HashCode *h = data; | 205 | const GNUNET_HashCode *h = data; |
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | |
207 | "test: Contents: %s\n", | 207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n", |
208 | GNUNET_h2s_full (h)); | 208 | GNUNET_h2s_full (h)); |
209 | 209 | ||
210 | } | 210 | } |
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n", |
212 | "test: PATH: (get %u, put %u)\n", | 212 | get_path_length, put_path_length); |
213 | get_path_length, | 213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n"); |
214 | put_path_length); | ||
215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
216 | "test: LOCAL\n"); | ||
217 | for (i = get_path_length - 1; i >= 0; i--) | 214 | for (i = get_path_length - 1; i >= 0; i--) |
218 | { | 215 | { |
219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", |
220 | "test: %s\n", | 217 | GNUNET_i2s (&get_path[i])); |
221 | GNUNET_i2s (&get_path[i])); | ||
222 | } | 218 | } |
223 | for (i = put_path_length - 1; i >= 0; i--) | 219 | for (i = put_path_length - 1; i >= 0; i--) |
224 | { | 220 | { |
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", |
226 | "test: %s\n", | 222 | GNUNET_i2s (&put_path[i])); |
227 | GNUNET_i2s (&put_path[i])); | ||
228 | } | 223 | } |
229 | found++; | 224 | found++; |
230 | if (found < 3) | 225 | if (found < 3) |
231 | return; | 226 | return; |
232 | ok = 0; | 227 | ok = 0; |
233 | GNUNET_SCHEDULER_cancel(disconnect_task); | 228 | GNUNET_SCHEDULER_cancel (disconnect_task); |
234 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | 229 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); |
235 | } | 230 | } |
236 | 231 | ||
@@ -263,7 +258,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
263 | if (strcmp (id_aux, id_near2) == 0) | 258 | if (strcmp (id_aux, id_near2) == 0) |
264 | d2 = aux; | 259 | d2 = aux; |
265 | } | 260 | } |
266 | if ( (NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) | 261 | if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) |
267 | { | 262 | { |
268 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
269 | "test: Peers not found (hostkey file changed?)\n"); | 264 | "test: Peers not found (hostkey file changed?)\n"); |
@@ -272,55 +267,39 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
272 | return; | 267 | return; |
273 | } | 268 | } |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); | 269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); |
275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", |
276 | "test: looking for %s\n", | ||
277 | GNUNET_h2s_full (&d->id.hashPubKey)); | 271 | GNUNET_h2s_full (&d->id.hashPubKey)); |
278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", |
279 | "test: looking for %s\n", | ||
280 | GNUNET_h2s_full (&d2->id.hashPubKey)); | 273 | GNUNET_h2s_full (&d2->id.hashPubKey)); |
281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", |
282 | "test: looking for %s\n", | ||
283 | GNUNET_h2s_full (&d_far->id.hashPubKey)); | 275 | GNUNET_h2s_full (&d_far->id.hashPubKey)); |
284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n", |
285 | "test: from %s\n", | ||
286 | GNUNET_h2s_full (&o->id.hashPubKey)); | 277 | GNUNET_h2s_full (&o->id.hashPubKey)); |
287 | found = 0; | 278 | found = 0; |
288 | get_h = GNUNET_DHT_get_start (hs[0], | 279 | get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
289 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 280 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
290 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 281 | &d->id.hashPubKey, /*key to search */ |
291 | &d->id.hashPubKey, /*key to search */ | 282 | 4U, /* replication level */ |
292 | 4U, /* replication level */ | 283 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ |
293 | GNUNET_DHT_RO_RECORD_ROUTE | | 284 | 0, /* xquery bits */ |
294 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 285 | &dht_get_id_handler, NULL); |
295 | NULL, /* xquery */ | 286 | get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
296 | 0, /* xquery bits */ | 287 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
297 | &dht_get_id_handler, | ||
298 | NULL); | ||
299 | get_h_2 = GNUNET_DHT_get_start (hs[0], | ||
300 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | ||
301 | GNUNET_BLOCK_TYPE_TEST, /* type */ | ||
302 | &d2->id.hashPubKey, /*key to search */ | 288 | &d2->id.hashPubKey, /*key to search */ |
303 | 4U, /* replication level */ | 289 | 4U, /* replication level */ |
304 | GNUNET_DHT_RO_RECORD_ROUTE | | 290 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ |
305 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 291 | 0, /* xquery bits */ |
306 | NULL, /* xquery */ | 292 | &dht_get_id_handler, NULL); |
307 | 0, /* xquery bits */ | 293 | get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
308 | &dht_get_id_handler, | 294 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
309 | NULL); | 295 | &d_far->id.hashPubKey, /*key to search */ |
310 | get_h_far = GNUNET_DHT_get_start (hs[0], | 296 | 4U, /* replication level */ |
311 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 297 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ |
312 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 298 | 0, /* xquery bits */ |
313 | &d_far->id.hashPubKey, /*key to search */ | 299 | &dht_get_id_handler, NULL); |
314 | 4U, /* replication level */ | ||
315 | GNUNET_DHT_RO_RECORD_ROUTE | | ||
316 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
317 | NULL, /* xquery */ | ||
318 | 0, /* xquery bits */ | ||
319 | &dht_get_id_handler, | ||
320 | NULL); | ||
321 | GNUNET_SCHEDULER_cancel (disconnect_task); | 300 | GNUNET_SCHEDULER_cancel (disconnect_task); |
322 | disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, | 301 | disconnect_task = |
323 | &disconnect_peers, NULL); | 302 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); |
324 | } | 303 | } |
325 | 304 | ||
326 | 305 | ||
@@ -331,28 +310,20 @@ put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
331 | unsigned int i; | 310 | unsigned int i; |
332 | 311 | ||
333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n"); | 312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n"); |
334 | for (i = 0; i < num_peers; i++) | 313 | for (i = 0; i < num_peers; i++) |
335 | { | 314 | { |
336 | d = GNUNET_TESTING_daemon_get (pg, i); | 315 | d = GNUNET_TESTING_daemon_get (pg, i); |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n", |
338 | "test: putting into DHT: %s\n", | ||
339 | GNUNET_h2s_full (&d->id.hashPubKey)); | 317 | GNUNET_h2s_full (&d->id.hashPubKey)); |
340 | GNUNET_DHT_put(hs[i], | 318 | GNUNET_DHT_put (hs[i], &d->id.hashPubKey, 10U, |
341 | &d->id.hashPubKey, | 319 | GNUNET_DHT_RO_RECORD_ROUTE | |
342 | 10U, | 320 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
343 | GNUNET_DHT_RO_RECORD_ROUTE | | 321 | GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity), |
344 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 322 | (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS, |
345 | GNUNET_BLOCK_TYPE_TEST, | 323 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); |
346 | sizeof(struct GNUNET_PeerIdentity), | ||
347 | (const char *) &d->id, | ||
348 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
349 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
350 | NULL, | ||
351 | NULL); | ||
352 | 324 | ||
353 | } | 325 | } |
354 | put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, | 326 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL); |
355 | &put_id, NULL); | ||
356 | } | 327 | } |
357 | 328 | ||
358 | 329 | ||
@@ -373,8 +344,8 @@ peergroup_ready (void *cls, const char *emsg) | |||
373 | { | 344 | { |
374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 345 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
375 | "test: Peergroup callback called with error, aborting test!\n"); | 346 | "test: Peergroup callback called with error, aborting test!\n"); |
376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n", |
377 | "test: Error from testing: `%s'\n", emsg); | 348 | emsg); |
378 | ok++; | 349 | ok++; |
379 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 350 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
380 | return; | 351 | return; |
@@ -384,8 +355,7 @@ peergroup_ready (void *cls, const char *emsg) | |||
384 | "************************************************************\n"); | 355 | "************************************************************\n"); |
385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
386 | "test: Peer Group started successfully!\n"); | 357 | "test: Peer Group started successfully!\n"); |
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n", |
388 | "test: Have %u connections\n", | ||
389 | total_connections); | 359 | total_connections); |
390 | #endif | 360 | #endif |
391 | 361 | ||
@@ -398,24 +368,22 @@ peergroup_ready (void *cls, const char *emsg) | |||
398 | GNUNET_free (buf); | 368 | GNUNET_free (buf); |
399 | } | 369 | } |
400 | peers_running = GNUNET_TESTING_daemons_running (pg); | 370 | peers_running = GNUNET_TESTING_daemons_running (pg); |
401 | 371 | ||
402 | GNUNET_assert (peers_running == num_peers); | 372 | GNUNET_assert (peers_running == num_peers); |
403 | hs = GNUNET_malloc (num_peers * sizeof(struct GNUNET_DHT_Handle *)); | 373 | hs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *)); |
404 | for (i = 0; i < num_peers; i++) | 374 | for (i = 0; i < num_peers; i++) |
405 | { | 375 | { |
406 | d = GNUNET_TESTING_daemon_get (pg, i); | 376 | d = GNUNET_TESTING_daemon_get (pg, i); |
407 | hs[i] = GNUNET_DHT_connect(d->cfg, 32); | 377 | hs[i] = GNUNET_DHT_connect (d->cfg, 32); |
408 | } | 378 | } |
409 | 379 | ||
410 | put_task = GNUNET_SCHEDULER_add_now(&put_id, NULL); | 380 | put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL); |
411 | test_task = | 381 | test_task = |
412 | GNUNET_SCHEDULER_add_delayed( | 382 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
413 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), | 383 | (GNUNET_TIME_UNIT_SECONDS, 2), &do_test, |
414 | &do_test, NULL); | ||
415 | disconnect_task = | ||
416 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, | ||
417 | &disconnect_peers, | ||
418 | NULL); | 384 | NULL); |
385 | disconnect_task = | ||
386 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); | ||
419 | 387 | ||
420 | } | 388 | } |
421 | 389 | ||
@@ -446,14 +414,13 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | |||
446 | if (emsg == NULL) | 414 | if (emsg == NULL) |
447 | { | 415 | { |
448 | total_connections++; | 416 | total_connections++; |
449 | GNUNET_PEER_intern(first); | 417 | GNUNET_PEER_intern (first); |
450 | GNUNET_PEER_intern(second); | 418 | GNUNET_PEER_intern (second); |
451 | } | 419 | } |
452 | else | 420 | else |
453 | { | 421 | { |
454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
455 | "test: Problem with new connection (%s)\n", | 423 | "test: Problem with new connection (%s)\n", emsg); |
456 | emsg); | ||
457 | } | 424 | } |
458 | 425 | ||
459 | } | 426 | } |
@@ -496,7 +463,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
496 | "num_peers", &num_peers)) | 463 | "num_peers", &num_peers)) |
497 | { | 464 | { |
498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 465 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
499 | "Option TESTING:NUM_PEERS is required!\n"); | 466 | "Option TESTING:NUM_PEERS is required!\n"); |
500 | return; | 467 | return; |
501 | } | 468 | } |
502 | 469 | ||
@@ -516,17 +483,17 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
516 | &data_filename)) | 483 | &data_filename)) |
517 | { | 484 | { |
518 | data_file = | 485 | data_file = |
519 | GNUNET_DISK_file_open (data_filename, | 486 | GNUNET_DISK_file_open (data_filename, |
520 | GNUNET_DISK_OPEN_READWRITE | | 487 | GNUNET_DISK_OPEN_READWRITE | |
521 | GNUNET_DISK_OPEN_CREATE, | 488 | GNUNET_DISK_OPEN_CREATE, |
522 | GNUNET_DISK_PERM_USER_READ | | 489 | GNUNET_DISK_PERM_USER_READ | |
523 | GNUNET_DISK_PERM_USER_WRITE); | 490 | GNUNET_DISK_PERM_USER_WRITE); |
524 | if (data_file == NULL) | 491 | if (data_file == NULL) |
525 | { | 492 | { |
526 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | 493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", |
527 | data_filename); | 494 | data_filename); |
528 | GNUNET_free (data_filename); | 495 | GNUNET_free (data_filename); |
529 | } | 496 | } |
530 | } | 497 | } |
531 | 498 | ||
532 | if (GNUNET_YES == | 499 | if (GNUNET_YES == |
@@ -552,7 +519,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
552 | hosts); | 519 | hosts); |
553 | GNUNET_assert (pg != NULL); | 520 | GNUNET_assert (pg != NULL); |
554 | shutdown_handle = | 521 | shutdown_handle = |
555 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 522 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
556 | &shutdown_task, NULL); | 523 | &shutdown_task, NULL); |
557 | } | 524 | } |
558 | 525 | ||
@@ -584,7 +551,8 @@ main (int xargc, char *xargv[]) | |||
584 | NULL | 551 | NULL |
585 | }; | 552 | }; |
586 | 553 | ||
587 | GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus", | 554 | GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv, |
555 | "test_dht_2dtorus", | ||
588 | gettext_noop ("Test dht in a small 2D torus."), options, | 556 | gettext_noop ("Test dht in a small 2D torus."), options, |
589 | &run, NULL); | 557 | &run, NULL); |
590 | #if REMOVE_DIR | 558 | #if REMOVE_DIR |
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 51f7d947c..e636c08ba 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -179,10 +179,10 @@ static void | |||
179 | test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 179 | test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, |
180 | const GNUNET_HashCode * key, | 180 | const GNUNET_HashCode * key, |
181 | const struct GNUNET_PeerIdentity *get_path, | 181 | const struct GNUNET_PeerIdentity *get_path, |
182 | unsigned int get_path_length, | 182 | unsigned int get_path_length, |
183 | const struct GNUNET_PeerIdentity *put_path, | 183 | const struct GNUNET_PeerIdentity *put_path, |
184 | unsigned int put_path_length, | 184 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
185 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 185 | size_t size, const void *data) |
186 | { | 186 | { |
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
188 | "test_get_iterator called (we got a result), stopping get request!\n"); | 188 | "test_get_iterator called (we got a result), stopping get request!\n"); |
@@ -213,9 +213,9 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
213 | 213 | ||
214 | peer->get_handle = | 214 | peer->get_handle = |
215 | GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, | 215 | GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, |
216 | GNUNET_BLOCK_TYPE_TEST, &hash, | 216 | GNUNET_BLOCK_TYPE_TEST, &hash, 1, |
217 | 1, GNUNET_DHT_RO_NONE, NULL, | 217 | GNUNET_DHT_RO_NONE, NULL, 0, &test_get_iterator, |
218 | 0, &test_get_iterator, NULL); | 218 | NULL); |
219 | 219 | ||
220 | if (peer->get_handle == NULL) | 220 | if (peer->get_handle == NULL) |
221 | { | 221 | { |
@@ -250,8 +250,8 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
250 | 250 | ||
251 | GNUNET_assert (peer->dht_handle != NULL); | 251 | GNUNET_assert (peer->dht_handle != NULL); |
252 | 252 | ||
253 | GNUNET_DHT_put (peer->dht_handle, &hash, 1, | 253 | GNUNET_DHT_put (peer->dht_handle, &hash, 1, GNUNET_DHT_RO_NONE, |
254 | GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data, | 254 | GNUNET_BLOCK_TYPE_TEST, data_size, data, |
255 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), | 255 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), |
256 | TOTAL_TIMEOUT, &test_get, &p1); | 256 | TOTAL_TIMEOUT, &test_get, &p1); |
257 | GNUNET_free (data); | 257 | GNUNET_free (data); |
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c index 62833a583..f6519239b 100644 --- a/src/dht/test_dht_multipeer.c +++ b/src/dht/test_dht_multipeer.c | |||
@@ -95,12 +95,12 @@ struct TestPutContext | |||
95 | struct TestGetContext | 95 | struct TestGetContext |
96 | { | 96 | { |
97 | /** | 97 | /** |
98 | * This is a linked list | 98 | * This is a linked list |
99 | */ | 99 | */ |
100 | struct TestGetContext *next; | 100 | struct TestGetContext *next; |
101 | 101 | ||
102 | /** | 102 | /** |
103 | * This is a linked list | 103 | * This is a linked list |
104 | */ | 104 | */ |
105 | struct TestGetContext *prev; | 105 | struct TestGetContext *prev; |
106 | 106 | ||
@@ -220,9 +220,7 @@ shutdown_callback (void *cls, const char *emsg) | |||
220 | { | 220 | { |
221 | if (emsg != NULL) | 221 | if (emsg != NULL) |
222 | { | 222 | { |
223 | fprintf (stderr, | 223 | fprintf (stderr, "Failed to shutdown testing topology: %s\n", emsg); |
224 | "Failed to shutdown testing topology: %s\n", | ||
225 | emsg); | ||
226 | if (ok == 0) | 224 | if (ok == 0) |
227 | ok = 2; | 225 | ok = 2; |
228 | } | 226 | } |
@@ -370,18 +368,18 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
370 | GNUNET_free (sm); | 368 | GNUNET_free (sm); |
371 | i = 0; | 369 | i = 0; |
372 | while (stats[i].name != NULL) | 370 | while (stats[i].name != NULL) |
373 | { | 371 | { |
374 | fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem, | 372 | fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem, |
375 | stats[i].name, (unsigned long long) stats[i].total); | 373 | stats[i].name, (unsigned long long) stats[i].total); |
376 | i++; | 374 | i++; |
377 | } | 375 | } |
378 | die_task = GNUNET_SCHEDULER_add_now (&do_stop, NULL); | 376 | die_task = GNUNET_SCHEDULER_add_now (&do_stop, NULL); |
379 | return; | 377 | return; |
380 | } | 378 | } |
381 | sm->stat = | 379 | sm->stat = |
382 | GNUNET_STATISTICS_create ("<driver>", | 380 | GNUNET_STATISTICS_create ("<driver>", |
383 | GNUNET_TESTING_daemon_get (pg, | 381 | GNUNET_TESTING_daemon_get (pg, |
384 | sm->daemon)->cfg); | 382 | sm->daemon)->cfg); |
385 | die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); | 383 | die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); |
386 | } | 384 | } |
387 | 385 | ||
@@ -404,9 +402,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
404 | GNUNET_SCHEDULER_cancel (test_put->task); | 402 | GNUNET_SCHEDULER_cancel (test_put->task); |
405 | if (test_put->dht_handle != NULL) | 403 | if (test_put->dht_handle != NULL) |
406 | GNUNET_DHT_disconnect (test_put->dht_handle); | 404 | GNUNET_DHT_disconnect (test_put->dht_handle); |
407 | GNUNET_CONTAINER_DLL_remove (all_puts_head, | 405 | GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); |
408 | all_puts_tail, | ||
409 | test_put); | ||
410 | GNUNET_free (test_put); | 406 | GNUNET_free (test_put); |
411 | } | 407 | } |
412 | 408 | ||
@@ -418,16 +414,14 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
418 | GNUNET_DHT_get_stop (test_get->get_handle); | 414 | GNUNET_DHT_get_stop (test_get->get_handle); |
419 | if (test_get->dht_handle != NULL) | 415 | if (test_get->dht_handle != NULL) |
420 | GNUNET_DHT_disconnect (test_get->dht_handle); | 416 | GNUNET_DHT_disconnect (test_get->dht_handle); |
421 | GNUNET_CONTAINER_DLL_remove (all_gets_head, | 417 | GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); |
422 | all_gets_tail, | ||
423 | test_get); | ||
424 | GNUNET_free (test_get); | 418 | GNUNET_free (test_get); |
425 | } | 419 | } |
426 | sm = GNUNET_malloc (sizeof (struct StatMaster)); | 420 | sm = GNUNET_malloc (sizeof (struct StatMaster)); |
427 | sm->stat = | 421 | sm->stat = |
428 | GNUNET_STATISTICS_create ("<driver>", | 422 | GNUNET_STATISTICS_create ("<driver>", |
429 | GNUNET_TESTING_daemon_get (pg, | 423 | GNUNET_TESTING_daemon_get (pg, |
430 | sm->daemon)->cfg); | 424 | sm->daemon)->cfg); |
431 | die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); | 425 | die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); |
432 | } | 426 | } |
433 | 427 | ||
@@ -445,18 +439,14 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
445 | struct TestGetContext *test_get; | 439 | struct TestGetContext *test_get; |
446 | 440 | ||
447 | die_task = GNUNET_SCHEDULER_NO_TASK; | 441 | die_task = GNUNET_SCHEDULER_NO_TASK; |
448 | fprintf (stderr, | 442 | fprintf (stderr, "Failing test with error: `%s'!\n", emsg); |
449 | "Failing test with error: `%s'!\n", | ||
450 | emsg); | ||
451 | while (NULL != (test_put = all_puts_head)) | 443 | while (NULL != (test_put = all_puts_head)) |
452 | { | 444 | { |
453 | if (test_put->task != GNUNET_SCHEDULER_NO_TASK) | 445 | if (test_put->task != GNUNET_SCHEDULER_NO_TASK) |
454 | GNUNET_SCHEDULER_cancel (test_put->task); | 446 | GNUNET_SCHEDULER_cancel (test_put->task); |
455 | if (test_put->dht_handle != NULL) | 447 | if (test_put->dht_handle != NULL) |
456 | GNUNET_DHT_disconnect (test_put->dht_handle); | 448 | GNUNET_DHT_disconnect (test_put->dht_handle); |
457 | GNUNET_CONTAINER_DLL_remove (all_puts_head, | 449 | GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); |
458 | all_puts_tail, | ||
459 | test_put); | ||
460 | GNUNET_free (test_put); | 450 | GNUNET_free (test_put); |
461 | } | 451 | } |
462 | 452 | ||
@@ -468,9 +458,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
468 | GNUNET_DHT_get_stop (test_get->get_handle); | 458 | GNUNET_DHT_get_stop (test_get->get_handle); |
469 | if (test_get->dht_handle != NULL) | 459 | if (test_get->dht_handle != NULL) |
470 | GNUNET_DHT_disconnect (test_get->dht_handle); | 460 | GNUNET_DHT_disconnect (test_get->dht_handle); |
471 | GNUNET_CONTAINER_DLL_remove (all_gets_head, | 461 | GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); |
472 | all_gets_tail, | ||
473 | test_get); | ||
474 | GNUNET_free (test_get); | 462 | GNUNET_free (test_get); |
475 | } | 463 | } |
476 | ok = 1; | 464 | ok = 1; |
@@ -495,10 +483,8 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
495 | if (test_get->succeeded != GNUNET_YES) | 483 | if (test_get->succeeded != GNUNET_YES) |
496 | { | 484 | { |
497 | gets_failed++; | 485 | gets_failed++; |
498 | fprintf (stderr, | 486 | fprintf (stderr, "Get from peer %s for key %s failed!\n", |
499 | "Get from peer %s for key %s failed!\n", | 487 | GNUNET_i2s (&test_get->daemon->id), GNUNET_h2s (&search_key)); |
500 | GNUNET_i2s (&test_get->daemon->id), | ||
501 | GNUNET_h2s (&search_key)); | ||
502 | } | 488 | } |
503 | GNUNET_assert (test_get->get_handle != NULL); | 489 | GNUNET_assert (test_get->get_handle != NULL); |
504 | GNUNET_DHT_get_stop (test_get->get_handle); | 490 | GNUNET_DHT_get_stop (test_get->get_handle); |
@@ -508,29 +494,25 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
508 | GNUNET_DHT_disconnect (test_get->dht_handle); | 494 | GNUNET_DHT_disconnect (test_get->dht_handle); |
509 | test_get->dht_handle = NULL; | 495 | test_get->dht_handle = NULL; |
510 | 496 | ||
511 | GNUNET_CONTAINER_DLL_remove (all_gets_head, | 497 | GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get); |
512 | all_gets_tail, | ||
513 | test_get); | ||
514 | GNUNET_free (test_get); | 498 | GNUNET_free (test_get); |
515 | if ((gets_failed > 10) && (outstanding_gets == 0)) | 499 | if ((gets_failed > 10) && (outstanding_gets == 0)) |
516 | { | 500 | { |
517 | /* Had more than 10% failures */ | 501 | /* Had more than 10% failures */ |
518 | fprintf (stderr, | 502 | fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed, |
519 | "%llu gets succeeded, %llu gets failed!\n", | 503 | gets_failed); |
520 | gets_completed, gets_failed); | ||
521 | GNUNET_SCHEDULER_cancel (die_task); | 504 | GNUNET_SCHEDULER_cancel (die_task); |
522 | ok = 1; | 505 | ok = 1; |
523 | die_task = GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded"); | 506 | die_task = |
507 | GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded"); | ||
524 | return; | 508 | return; |
525 | } | 509 | } |
526 | if ( (gets_completed + gets_failed == num_peers * num_peers) && | 510 | if ((gets_completed + gets_failed == num_peers * num_peers) && (outstanding_gets == 0)) /* All gets successful */ |
527 | (outstanding_gets == 0) ) /* All gets successful */ | ||
528 | { | 511 | { |
529 | fprintf (stderr, | 512 | fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed, |
530 | "%llu gets succeeded, %llu gets failed!\n", | 513 | gets_failed); |
531 | gets_completed, gets_failed); | ||
532 | GNUNET_SCHEDULER_cancel (die_task); | 514 | GNUNET_SCHEDULER_cancel (die_task); |
533 | ok = 0; | 515 | ok = 0; |
534 | die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 516 | die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
535 | } | 517 | } |
536 | } | 518 | } |
@@ -550,10 +532,10 @@ static void | |||
550 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 532 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, |
551 | const GNUNET_HashCode * key, | 533 | const GNUNET_HashCode * key, |
552 | const struct GNUNET_PeerIdentity *get_path, | 534 | const struct GNUNET_PeerIdentity *get_path, |
553 | unsigned int get_path_length, | 535 | unsigned int get_path_length, |
554 | const struct GNUNET_PeerIdentity *put_path, | 536 | const struct GNUNET_PeerIdentity *put_path, |
555 | unsigned int put_path_length, | 537 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
556 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 538 | size_t size, const void *data) |
557 | { | 539 | { |
558 | struct TestGetContext *test_get = cls; | 540 | struct TestGetContext *test_get = cls; |
559 | GNUNET_HashCode search_key; /* Key stored under */ | 541 | GNUNET_HashCode search_key; /* Key stored under */ |
@@ -569,9 +551,8 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
569 | { | 551 | { |
570 | unsigned int i; | 552 | unsigned int i; |
571 | 553 | ||
572 | fprintf (stderr, "PUT (%u) Path: ", | 554 | fprintf (stderr, "PUT (%u) Path: ", test_get->uid); |
573 | test_get->uid); | 555 | for (i = 0; i < put_path_length; i++) |
574 | for (i = 0; i<put_path_length; i++) | ||
575 | fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i])); | 556 | fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i])); |
576 | fprintf (stderr, "\n"); | 557 | fprintf (stderr, "\n"); |
577 | } | 558 | } |
@@ -579,25 +560,22 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
579 | { | 560 | { |
580 | unsigned int i; | 561 | unsigned int i; |
581 | 562 | ||
582 | fprintf (stderr, "GET (%u) Path: ", | 563 | fprintf (stderr, "GET (%u) Path: ", test_get->uid); |
583 | test_get->uid); | ||
584 | for (i = 0; i < get_path_length; i++) | 564 | for (i = 0; i < get_path_length; i++) |
585 | fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i])); | 565 | fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i])); |
586 | fprintf (stderr, "%s%s\n", | 566 | fprintf (stderr, "%s%s\n", get_path_length > 0 ? "->" : "", |
587 | get_path_length > 0 ? "->":"", | 567 | GNUNET_i2s (&test_get->daemon->id)); |
588 | GNUNET_i2s (&test_get->daemon->id)); | ||
589 | } | 568 | } |
590 | #endif | 569 | #endif |
591 | 570 | ||
592 | if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) || | 571 | if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) || |
593 | (0 != memcmp (original_data, data, sizeof (original_data)))) | 572 | (0 != memcmp (original_data, data, sizeof (original_data)))) |
594 | { | 573 | { |
595 | fprintf (stderr, | 574 | fprintf (stderr, "Key or data is not the same as was inserted!\n"); |
596 | "Key or data is not the same as was inserted!\n"); | ||
597 | return; | 575 | return; |
598 | } | 576 | } |
599 | gets_completed++; | 577 | gets_completed++; |
600 | test_get->succeeded = GNUNET_YES; | 578 | test_get->succeeded = GNUNET_YES; |
601 | GNUNET_SCHEDULER_cancel (test_get->task); | 579 | GNUNET_SCHEDULER_cancel (test_get->task); |
602 | test_get->task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get); | 580 | test_get->task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get); |
603 | } | 581 | } |
@@ -615,7 +593,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
615 | 593 | ||
616 | if (outstanding_gets > MAX_OUTSTANDING_GETS) | 594 | if (outstanding_gets > MAX_OUTSTANDING_GETS) |
617 | { | 595 | { |
618 | test_get->task = GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); | 596 | test_get->task = |
597 | GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); | ||
619 | return; | 598 | return; |
620 | } | 599 | } |
621 | memset (data, test_get->uid, sizeof (data)); | 600 | memset (data, test_get->uid, sizeof (data)); |
@@ -624,12 +603,11 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
624 | GNUNET_assert (test_get->dht_handle != NULL); | 603 | GNUNET_assert (test_get->dht_handle != NULL); |
625 | outstanding_gets++; | 604 | outstanding_gets++; |
626 | test_get->get_handle = | 605 | test_get->get_handle = |
627 | GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, | 606 | GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, |
628 | GNUNET_BLOCK_TYPE_TEST, &key, | 607 | GNUNET_BLOCK_TYPE_TEST, &key, 1, route_option, NULL, |
629 | 1, route_option, NULL, 0, | 608 | 0, &get_result_iterator, test_get); |
630 | &get_result_iterator, test_get); | ||
631 | test_get->task = | 609 | test_get->task = |
632 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); | 610 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); |
633 | } | 611 | } |
634 | 612 | ||
635 | 613 | ||
@@ -644,9 +622,7 @@ put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
644 | test_put->task = GNUNET_SCHEDULER_NO_TASK; | 622 | test_put->task = GNUNET_SCHEDULER_NO_TASK; |
645 | GNUNET_DHT_disconnect (test_put->dht_handle); | 623 | GNUNET_DHT_disconnect (test_put->dht_handle); |
646 | test_put->dht_handle = NULL; | 624 | test_put->dht_handle = NULL; |
647 | GNUNET_CONTAINER_DLL_remove (all_puts_head, | 625 | GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put); |
648 | all_puts_tail, | ||
649 | test_put); | ||
650 | GNUNET_free (test_put); | 626 | GNUNET_free (test_put); |
651 | } | 627 | } |
652 | 628 | ||
@@ -661,23 +637,19 @@ start_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
661 | unsigned long long j; | 637 | unsigned long long j; |
662 | struct TestGetContext *test_get; | 638 | struct TestGetContext *test_get; |
663 | 639 | ||
664 | #if VERBOSE | 640 | #if VERBOSE |
665 | fprintf (stderr, | 641 | fprintf (stderr, "Issuing %llu GETs\n", |
666 | "Issuing %llu GETs\n", | 642 | (unsigned long long) (num_peers * num_peers)); |
667 | (unsigned long long) (num_peers * num_peers)); | ||
668 | #endif | 643 | #endif |
669 | for (i = 0; i < num_peers; i++) | 644 | for (i = 0; i < num_peers; i++) |
670 | for (j = 0; j < num_peers; j++) | 645 | for (j = 0; j < num_peers; j++) |
671 | { | 646 | { |
672 | test_get = GNUNET_malloc (sizeof (struct TestGetContext)); | 647 | test_get = GNUNET_malloc (sizeof (struct TestGetContext)); |
673 | test_get->uid = i + j*num_peers; | 648 | test_get->uid = i + j * num_peers; |
674 | test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); | 649 | test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); |
675 | GNUNET_CONTAINER_DLL_insert (all_gets_head, | 650 | GNUNET_CONTAINER_DLL_insert (all_gets_head, all_gets_tail, test_get); |
676 | all_gets_tail, | 651 | test_get->task = GNUNET_SCHEDULER_add_now (&do_get, test_get); |
677 | test_get); | 652 | } |
678 | test_get->task = GNUNET_SCHEDULER_add_now (&do_get, | ||
679 | test_get); | ||
680 | } | ||
681 | } | 653 | } |
682 | 654 | ||
683 | 655 | ||
@@ -692,15 +664,12 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
692 | outstanding_puts--; | 664 | outstanding_puts--; |
693 | puts_completed++; | 665 | puts_completed++; |
694 | GNUNET_SCHEDULER_cancel (test_put->task); | 666 | GNUNET_SCHEDULER_cancel (test_put->task); |
695 | test_put->task = | 667 | test_put->task = GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); |
696 | GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); | ||
697 | if (puts_completed != num_peers * num_peers) | 668 | if (puts_completed != num_peers * num_peers) |
698 | return; | 669 | return; |
699 | 670 | ||
700 | GNUNET_assert (outstanding_puts == 0); | 671 | GNUNET_assert (outstanding_puts == 0); |
701 | GNUNET_SCHEDULER_add_delayed (START_DELAY, | 672 | GNUNET_SCHEDULER_add_delayed (START_DELAY, &start_gets, NULL); |
702 | &start_gets, | ||
703 | NULL); | ||
704 | } | 673 | } |
705 | 674 | ||
706 | 675 | ||
@@ -717,7 +686,8 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
717 | test_put->task = GNUNET_SCHEDULER_NO_TASK; | 686 | test_put->task = GNUNET_SCHEDULER_NO_TASK; |
718 | if (outstanding_puts > MAX_OUTSTANDING_PUTS) | 687 | if (outstanding_puts > MAX_OUTSTANDING_PUTS) |
719 | { | 688 | { |
720 | test_put->task = GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); | 689 | test_put->task = |
690 | GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); | ||
721 | return; | 691 | return; |
722 | } | 692 | } |
723 | memset (data, test_put->uid, sizeof (data)); | 693 | memset (data, test_put->uid, sizeof (data)); |
@@ -726,46 +696,43 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
726 | GNUNET_assert (test_put->dht_handle != NULL); | 696 | GNUNET_assert (test_put->dht_handle != NULL); |
727 | outstanding_puts++; | 697 | outstanding_puts++; |
728 | #if VERBOSE > 2 | 698 | #if VERBOSE > 2 |
729 | fprintf (stderr, "PUT %u at `%s'\n", | 699 | fprintf (stderr, "PUT %u at `%s'\n", test_put->uid, |
730 | test_put->uid, | 700 | GNUNET_i2s (&test_put->daemon->id)); |
731 | GNUNET_i2s (&test_put->daemon->id)); | ||
732 | #endif | 701 | #endif |
733 | GNUNET_DHT_put (test_put->dht_handle, &key, 1, | 702 | GNUNET_DHT_put (test_put->dht_handle, &key, 1, route_option, |
734 | route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, | 703 | GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, |
735 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, | 704 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, |
736 | &put_finished, test_put); | 705 | &put_finished, test_put); |
737 | test_put->task = | 706 | test_put->task = |
738 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 707 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
739 | &put_disconnect_task, test_put); | 708 | &put_disconnect_task, test_put); |
740 | } | 709 | } |
741 | 710 | ||
742 | 711 | ||
743 | static void | 712 | static void |
744 | run_dht_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 713 | run_dht_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
745 | { | 714 | { |
746 | unsigned long long i; | 715 | unsigned long long i; |
747 | struct TestPutContext *test_put; | 716 | struct TestPutContext *test_put; |
748 | 717 | ||
749 | #if PATH_TRACKING | 718 | #if PATH_TRACKING |
750 | route_option = GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; | 719 | route_option = |
720 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; | ||
751 | #else | 721 | #else |
752 | route_option = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; | 722 | route_option = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; |
753 | #endif | 723 | #endif |
754 | die_task = | 724 | die_task = |
755 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, | 725 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, |
756 | "from setup puts/gets"); | 726 | "from setup puts/gets"); |
757 | fprintf (stderr, | 727 | fprintf (stderr, "Issuing %llu PUTs (one per peer)\n", |
758 | "Issuing %llu PUTs (one per peer)\n", | 728 | (unsigned long long) (num_peers * num_peers)); |
759 | (unsigned long long) (num_peers * num_peers)); | ||
760 | for (i = 0; i < num_peers * num_peers; i++) | 729 | for (i = 0; i < num_peers * num_peers; i++) |
761 | { | 730 | { |
762 | test_put = GNUNET_malloc (sizeof (struct TestPutContext)); | 731 | test_put = GNUNET_malloc (sizeof (struct TestPutContext)); |
763 | test_put->uid = i; | 732 | test_put->uid = i; |
764 | test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers); | 733 | test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers); |
765 | test_put->task = GNUNET_SCHEDULER_add_now (&do_put, test_put); | 734 | test_put->task = GNUNET_SCHEDULER_add_now (&do_put, test_put); |
766 | GNUNET_CONTAINER_DLL_insert (all_puts_head, | 735 | GNUNET_CONTAINER_DLL_insert (all_puts_head, all_puts_tail, test_put); |
767 | all_puts_tail, | ||
768 | test_put); | ||
769 | } | 736 | } |
770 | } | 737 | } |
771 | 738 | ||
@@ -782,17 +749,13 @@ startup_done (void *cls, const char *emsg) | |||
782 | { | 749 | { |
783 | if (emsg != NULL) | 750 | if (emsg != NULL) |
784 | { | 751 | { |
785 | fprintf (stderr, | 752 | fprintf (stderr, "Failed to setup topology: %s\n", emsg); |
786 | "Failed to setup topology: %s\n", | 753 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "topology setup failed"); |
787 | emsg); | ||
788 | die_task = | ||
789 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
790 | "topology setup failed"); | ||
791 | return; | 754 | return; |
792 | } | 755 | } |
793 | die_task = | 756 | die_task = |
794 | GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test, | 757 | GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test, |
795 | "from setup puts/gets"); | 758 | "from setup puts/gets"); |
796 | } | 759 | } |
797 | 760 | ||
798 | 761 | ||
@@ -813,13 +776,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
813 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", | 776 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", |
814 | &num_peers)) | 777 | &num_peers)) |
815 | num_peers = DEFAULT_NUM_PEERS; | 778 | num_peers = DEFAULT_NUM_PEERS; |
816 | pg = GNUNET_TESTING_peergroup_start (cfg, | 779 | pg = GNUNET_TESTING_peergroup_start (cfg, num_peers, TIMEOUT, NULL, |
817 | num_peers, | 780 | &startup_done, NULL, NULL); |
818 | TIMEOUT, | ||
819 | NULL, | ||
820 | &startup_done, | ||
821 | NULL, | ||
822 | NULL); | ||
823 | GNUNET_assert (NULL != pg); | 781 | GNUNET_assert (NULL != pg); |
824 | } | 782 | } |
825 | 783 | ||
diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c index 8947739c4..04198b48b 100644 --- a/src/dht/test_dht_twopeer.c +++ b/src/dht/test_dht_twopeer.c | |||
@@ -138,9 +138,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
138 | { | 138 | { |
139 | const char *emsg = cls; | 139 | const char *emsg = cls; |
140 | 140 | ||
141 | fprintf (stderr, | 141 | fprintf (stderr, "Error: %s\n", emsg); |
142 | "Error: %s\n", | ||
143 | emsg); | ||
144 | if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) | 142 | if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) |
145 | { | 143 | { |
146 | GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task); | 144 | GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task); |
@@ -175,10 +173,10 @@ static void | |||
175 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 173 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, |
176 | const GNUNET_HashCode * key, | 174 | const GNUNET_HashCode * key, |
177 | const struct GNUNET_PeerIdentity *get_path, | 175 | const struct GNUNET_PeerIdentity *get_path, |
178 | unsigned int get_path_length, | 176 | unsigned int get_path_length, |
179 | const struct GNUNET_PeerIdentity *put_path, | 177 | const struct GNUNET_PeerIdentity *put_path, |
180 | unsigned int put_path_length, | 178 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
181 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 179 | size_t size, const void *data) |
182 | { | 180 | { |
183 | struct PeerGetContext *get_context = cls; | 181 | struct PeerGetContext *get_context = cls; |
184 | 182 | ||
@@ -257,9 +255,9 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
257 | GNUNET_TIME_relative_multiply | 255 | GNUNET_TIME_relative_multiply |
258 | (GNUNET_TIME_UNIT_SECONDS, 5), | 256 | (GNUNET_TIME_UNIT_SECONDS, 5), |
259 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 257 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
260 | &get_context->peer->hashPubKey, | 258 | &get_context->peer->hashPubKey, 1, |
261 | 1, GNUNET_DHT_RO_NONE, NULL, | 259 | GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator, |
262 | 0, &get_result_iterator, get_context); | 260 | get_context); |
263 | } | 261 | } |
264 | 262 | ||
265 | 263 | ||
@@ -292,9 +290,9 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
292 | GNUNET_TIME_relative_multiply | 290 | GNUNET_TIME_relative_multiply |
293 | (GNUNET_TIME_UNIT_SECONDS, 5), | 291 | (GNUNET_TIME_UNIT_SECONDS, 5), |
294 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 292 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
295 | &get_context->peer->hashPubKey, | 293 | &get_context->peer->hashPubKey, 1, |
296 | 1, GNUNET_DHT_RO_FIND_PEER, NULL, | 294 | GNUNET_DHT_RO_FIND_PEER, NULL, 0, |
297 | 0, &get_result_iterator, get_context); | 295 | &get_result_iterator, get_context); |
298 | } | 296 | } |
299 | 297 | ||
300 | 298 | ||
@@ -335,8 +333,8 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, | |||
335 | #endif | 333 | #endif |
336 | GNUNET_SCHEDULER_cancel (die_task); | 334 | GNUNET_SCHEDULER_cancel (die_task); |
337 | die_task = | 335 | die_task = |
338 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 336 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, |
339 | &end_badly, "Timeout trying to GET"); | 337 | "Timeout trying to GET"); |
340 | 338 | ||
341 | curr_get_ctx.dht_handle = peer1dht; | 339 | curr_get_ctx.dht_handle = peer1dht; |
342 | curr_get_ctx.peer = &peer2id; | 340 | curr_get_ctx.peer = &peer2id; |
@@ -383,9 +381,7 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id, | |||
383 | { | 381 | { |
384 | if (emsg != NULL) | 382 | if (emsg != NULL) |
385 | { | 383 | { |
386 | fprintf (stderr, | 384 | fprintf (stderr, "Failed to start daemon: `%s'\n", emsg); |
387 | "Failed to start daemon: `%s'\n", | ||
388 | emsg); | ||
389 | return; | 385 | return; |
390 | } | 386 | } |
391 | GNUNET_assert (id != NULL); | 387 | GNUNET_assert (id != NULL); |
diff --git a/src/dht/test_dht_twopeer_get_put.c b/src/dht/test_dht_twopeer_get_put.c index 2a79c9ffb..d0da778ea 100644 --- a/src/dht/test_dht_twopeer_get_put.c +++ b/src/dht/test_dht_twopeer_get_put.c | |||
@@ -215,12 +215,11 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
215 | void | 215 | void |
216 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 216 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, |
217 | const GNUNET_HashCode * key, | 217 | const GNUNET_HashCode * key, |
218 | const struct GNUNET_PeerIdentity *get_path, | 218 | const struct GNUNET_PeerIdentity *get_path, |
219 | unsigned int get_path_size, | 219 | unsigned int get_path_size, |
220 | const struct GNUNET_PeerIdentity *put_path, | 220 | const struct GNUNET_PeerIdentity *put_path, |
221 | unsigned int put_path_size, | 221 | unsigned int put_path_size, enum GNUNET_BLOCK_Type type, |
222 | enum GNUNET_BLOCK_Type type, size_t size, | 222 | size_t size, const void *result_data) |
223 | const void *result_data) | ||
224 | { | 223 | { |
225 | GNUNET_HashCode original_key; /* Key data was stored data under */ | 224 | GNUNET_HashCode original_key; /* Key data was stored data under */ |
226 | char original_data[4]; /* Made up data that was stored */ | 225 | char original_data[4]; /* Made up data that was stored */ |
@@ -279,8 +278,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
279 | #else | 278 | #else |
280 | GNUNET_BLOCK_TYPE_TEST, | 279 | GNUNET_BLOCK_TYPE_TEST, |
281 | #endif | 280 | #endif |
282 | &key, 1, GNUNET_DHT_RO_NONE, | 281 | &key, 1, GNUNET_DHT_RO_NONE, NULL, 0, |
283 | NULL, 0, &get_result_iterator, NULL); | 282 | &get_result_iterator, NULL); |
284 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 283 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
285 | (GNUNET_TIME_UNIT_SECONDS, 10), &do_put, NULL); | 284 | (GNUNET_TIME_UNIT_SECONDS, 10), &do_put, NULL); |
286 | } | 285 | } |
@@ -313,10 +312,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
313 | memset (data, 43, sizeof (data)); | 312 | memset (data, 43, sizeof (data)); |
314 | 313 | ||
315 | /* Insert the data at the first peer */ | 314 | /* Insert the data at the first peer */ |
316 | GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, | 315 | GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, |
317 | GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, | 316 | sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, |
318 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, | 317 | GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); |
319 | &put_finished, NULL); | ||
320 | } | 318 | } |
321 | #else | 319 | #else |
322 | 320 | ||
diff --git a/src/dht/test_dht_twopeer_path_tracking.c b/src/dht/test_dht_twopeer_path_tracking.c index f2d86e38e..61a3df0a4 100644 --- a/src/dht/test_dht_twopeer_path_tracking.c +++ b/src/dht/test_dht_twopeer_path_tracking.c | |||
@@ -191,10 +191,10 @@ static void | |||
191 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 191 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, |
192 | const GNUNET_HashCode * key, | 192 | const GNUNET_HashCode * key, |
193 | const struct GNUNET_PeerIdentity *get_path, | 193 | const struct GNUNET_PeerIdentity *get_path, |
194 | unsigned int get_path_length, | 194 | unsigned int get_path_length, |
195 | const struct GNUNET_PeerIdentity *put_path, | 195 | const struct GNUNET_PeerIdentity *put_path, |
196 | unsigned int put_path_length, | 196 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
197 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 197 | size_t size, const void *data) |
198 | { | 198 | { |
199 | GNUNET_HashCode original_key; /* Key data was stored data under */ | 199 | GNUNET_HashCode original_key; /* Key data was stored data under */ |
200 | char original_data[4]; /* Made up data that was stored */ | 200 | char original_data[4]; /* Made up data that was stored */ |
@@ -220,14 +220,14 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
220 | if (put_path != NULL) | 220 | if (put_path != NULL) |
221 | { | 221 | { |
222 | fprintf (stderr, "PUT Path: "); | 222 | fprintf (stderr, "PUT Path: "); |
223 | for (i = 0; i<put_path_length; i++) | 223 | for (i = 0; i < put_path_length; i++) |
224 | fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i])); | 224 | fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i])); |
225 | fprintf (stderr, "\n"); | 225 | fprintf (stderr, "\n"); |
226 | } | 226 | } |
227 | if (get_path != NULL) | 227 | if (get_path != NULL) |
228 | { | 228 | { |
229 | fprintf (stderr, "GET Path: "); | 229 | fprintf (stderr, "GET Path: "); |
230 | for (i = 0; i<get_path_length; i++) | 230 | for (i = 0; i < get_path_length; i++) |
231 | fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i])); | 231 | fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i])); |
232 | fprintf (stderr, "\n"); | 232 | fprintf (stderr, "\n"); |
233 | } | 233 | } |
@@ -256,9 +256,9 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
256 | memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ | 256 | memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ |
257 | global_get_handle = | 257 | global_get_handle = |
258 | GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (), | 258 | GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (), |
259 | GNUNET_BLOCK_TYPE_TEST, &key, | 259 | GNUNET_BLOCK_TYPE_TEST, &key, 1, |
260 | 1, GNUNET_DHT_RO_RECORD_ROUTE, | 260 | GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, |
261 | NULL, 0, &get_result_iterator, NULL); | 261 | &get_result_iterator, NULL); |
262 | } | 262 | } |
263 | 263 | ||
264 | /** | 264 | /** |
@@ -274,10 +274,10 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
274 | memset (data, 43, sizeof (data)); | 274 | memset (data, 43, sizeof (data)); |
275 | 275 | ||
276 | /* Insert the data at the first peer */ | 276 | /* Insert the data at the first peer */ |
277 | GNUNET_DHT_put (peer1dht, &key, 1, | 277 | GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_RECORD_ROUTE, |
278 | GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_BLOCK_TYPE_TEST, | 278 | GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, |
279 | sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, | 279 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, |
280 | GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); | 280 | &put_finished, NULL); |
281 | } | 281 | } |
282 | 282 | ||
283 | /** | 283 | /** |
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c index 44009c257..275a01a32 100644 --- a/src/dht/test_dht_twopeer_put_get.c +++ b/src/dht/test_dht_twopeer_put_get.c | |||
@@ -207,11 +207,10 @@ static void | |||
207 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 207 | get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, |
208 | const GNUNET_HashCode * key, | 208 | const GNUNET_HashCode * key, |
209 | const struct GNUNET_PeerIdentity *get_path, | 209 | const struct GNUNET_PeerIdentity *get_path, |
210 | unsigned int get_path_size, | 210 | unsigned int get_path_size, |
211 | const struct GNUNET_PeerIdentity *put_path, | 211 | const struct GNUNET_PeerIdentity *put_path, |
212 | unsigned int put_path_size, | 212 | unsigned int put_path_size, enum GNUNET_BLOCK_Type type, |
213 | enum GNUNET_BLOCK_Type type, size_t size, | 213 | size_t size, const void *result_data) |
214 | const void *result_data) | ||
215 | { | 214 | { |
216 | GNUNET_HashCode original_key; /* Key data was stored data under */ | 215 | GNUNET_HashCode original_key; /* Key data was stored data under */ |
217 | char original_data[4]; /* Made up data that was stored */ | 216 | char original_data[4]; /* Made up data that was stored */ |
@@ -254,10 +253,9 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
254 | 253 | ||
255 | memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ | 254 | memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ |
256 | global_get_handle = | 255 | global_get_handle = |
257 | GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL, | 256 | GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL, |
258 | GNUNET_BLOCK_TYPE_TEST, | 257 | GNUNET_BLOCK_TYPE_TEST, &key, 1, GNUNET_DHT_RO_NONE, |
259 | &key, 1, GNUNET_DHT_RO_NONE, | 258 | NULL, 0, &get_result_iterator, NULL); |
260 | NULL, 0, &get_result_iterator, NULL); | ||
261 | } | 259 | } |
262 | 260 | ||
263 | 261 | ||
@@ -274,10 +272,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
274 | memset (data, 43, sizeof (data)); | 272 | memset (data, 43, sizeof (data)); |
275 | 273 | ||
276 | /* Insert the data at the first peer */ | 274 | /* Insert the data at the first peer */ |
277 | GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, | 275 | GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, |
278 | GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, | 276 | sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, |
279 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, | 277 | GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); |
280 | &put_finished, NULL); | ||
281 | } | 278 | } |
282 | 279 | ||
283 | 280 | ||