aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/dht
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/dht.h4
-rw-r--r--src/dht/dht_api.c534
-rw-r--r--src/dht/dht_api_find_peer.c56
-rw-r--r--src/dht/dht_api_get_put.c163
-rw-r--r--src/dht/dhtlog.c37
-rw-r--r--src/dht/dhtlog.h46
-rw-r--r--src/dht/gnunet-dht-driver.c3415
-rw-r--r--src/dht/gnunet-dht-get-peer.c88
-rw-r--r--src/dht/gnunet-dht-get.c74
-rw-r--r--src/dht/gnunet-dht-put.c50
-rw-r--r--src/dht/gnunet-service-dht.c3691
-rw-r--r--src/dht/plugin_dhtlog_dummy.c59
-rw-r--r--src/dht/plugin_dhtlog_mysql.c1071
-rw-r--r--src/dht/plugin_dhtlog_mysql_dump.c383
-rw-r--r--src/dht/plugin_dhtlog_mysql_dump_load.c638
-rw-r--r--src/dht/test_dht_api.c254
-rw-r--r--src/dht/test_dht_multipeer.c785
-rw-r--r--src/dht/test_dht_twopeer.c331
-rw-r--r--src/dht/test_dht_twopeer_path_tracking.c348
-rw-r--r--src/dht/test_dht_twopeer_put_get.c419
-rw-r--r--src/dht/test_dhtlog.c147
21 files changed, 6432 insertions, 6161 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h
index 6881b61ed..e73789220 100644
--- a/src/dht/dht.h
+++ b/src/dht/dht.h
@@ -90,8 +90,8 @@
90 * FIXME: document. 90 * FIXME: document.
91 */ 91 */
92typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, 92typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
93 const struct GNUNET_MessageHeader 93 const struct
94 *msg); 94 GNUNET_MessageHeader * msg);
95 95
96 96
97/** 97/**
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 11f13b184..101751487 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -60,12 +60,12 @@ struct PendingMessage
60 * of this struct. 60 * of this struct.
61 */ 61 */
62 const struct GNUNET_MessageHeader *msg; 62 const struct GNUNET_MessageHeader *msg;
63 63
64 /** 64 /**
65 * Handle to the DHT API context. 65 * Handle to the DHT API context.
66 */ 66 */
67 struct GNUNET_DHT_Handle *handle; 67 struct GNUNET_DHT_Handle *handle;
68 68
69 /** 69 /**
70 * Continuation to call when the request has been 70 * Continuation to call when the request has been
71 * transmitted (for the first time) to the service; can be NULL. 71 * transmitted (for the first time) to the service; can be NULL.
@@ -203,10 +203,7 @@ struct GNUNET_DHT_Handle
203/** 203/**
204 * Transmit the next pending message, called by notify_transmit_ready 204 * Transmit the next pending message, called by notify_transmit_ready
205 */ 205 */
206static size_t 206static size_t transmit_pending (void *cls, size_t size, void *buf);
207transmit_pending (void *cls,
208 size_t size,
209 void *buf);
210 207
211 208
212/** 209/**
@@ -215,8 +212,7 @@ transmit_pending (void *cls,
215 * 212 *
216 */ 213 */
217static void 214static void
218service_message_handler (void *cls, 215service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg);
219 const struct GNUNET_MessageHeader *msg);
220 216
221 217
222 218
@@ -233,19 +229,18 @@ try_connect (struct GNUNET_DHT_Handle *handle)
233 return GNUNET_OK; 229 return GNUNET_OK;
234 handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg); 230 handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg);
235 if (handle->client == NULL) 231 if (handle->client == NULL)
236 { 232 {
237 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 233 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
238 _("Failed to connect to the DHT service!\n")); 234 _("Failed to connect to the DHT service!\n"));
239 return GNUNET_NO; 235 return GNUNET_NO;
240 } 236 }
241#if DEBUG_DHT 237#if DEBUG_DHT
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
243 "Starting to process replies from DHT\n"); 239 "Starting to process replies from DHT\n");
244#endif 240#endif
245 GNUNET_CLIENT_receive (handle->client, 241 GNUNET_CLIENT_receive (handle->client,
246 &service_message_handler, 242 &service_message_handler,
247 handle, 243 handle, GNUNET_TIME_UNIT_FOREVER_REL);
248 GNUNET_TIME_UNIT_FOREVER_REL);
249 return GNUNET_YES; 244 return GNUNET_YES;
250} 245}
251 246
@@ -260,20 +255,17 @@ try_connect (struct GNUNET_DHT_Handle *handle)
260 * @return GNUNET_YES (always) 255 * @return GNUNET_YES (always)
261 */ 256 */
262static int 257static int
263add_request_to_pending (void *cls, 258add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value)
264 const GNUNET_HashCode *key,
265 void *value)
266{ 259{
267 struct GNUNET_DHT_Handle *handle = cls; 260 struct GNUNET_DHT_Handle *handle = cls;
268 struct GNUNET_DHT_RouteHandle *rh = value; 261 struct GNUNET_DHT_RouteHandle *rh = value;
269 262
270 if (GNUNET_NO == rh->message->in_pending_queue) 263 if (GNUNET_NO == rh->message->in_pending_queue)
271 { 264 {
272 GNUNET_CONTAINER_DLL_insert (handle->pending_head, 265 GNUNET_CONTAINER_DLL_insert (handle->pending_head,
273 handle->pending_tail, 266 handle->pending_tail, rh->message);
274 rh->message); 267 rh->message->in_pending_queue = GNUNET_YES;
275 rh->message->in_pending_queue = GNUNET_YES; 268 }
276 }
277 return GNUNET_YES; 269 return GNUNET_YES;
278} 270}
279 271
@@ -282,8 +274,7 @@ add_request_to_pending (void *cls,
282 * Try to send messages from list of messages to send 274 * Try to send messages from list of messages to send
283 * @param handle DHT_Handle 275 * @param handle DHT_Handle
284 */ 276 */
285static void 277static void process_pending_messages (struct GNUNET_DHT_Handle *handle);
286process_pending_messages (struct GNUNET_DHT_Handle *handle);
287 278
288 279
289/** 280/**
@@ -293,8 +284,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle);
293 * @param tc scheduler context 284 * @param tc scheduler context
294 */ 285 */
295static void 286static void
296try_reconnect (void *cls, 287try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
297 const struct GNUNET_SCHEDULER_TaskContext *tc)
298{ 288{
299 struct GNUNET_DHT_Handle *handle = cls; 289 struct GNUNET_DHT_Handle *handle = cls;
300 290
@@ -308,14 +298,12 @@ try_reconnect (void *cls,
308 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 298 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
309 handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg); 299 handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg);
310 if (handle->client == NULL) 300 if (handle->client == NULL)
311 { 301 {
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dht reconnect failed(!)\n");
313 "dht reconnect failed(!)\n"); 303 return;
314 return; 304 }
315 }
316 GNUNET_CONTAINER_multihashmap_iterate (handle->active_requests, 305 GNUNET_CONTAINER_multihashmap_iterate (handle->active_requests,
317 &add_request_to_pending, 306 &add_request_to_pending, handle);
318 handle);
319 process_pending_messages (handle); 307 process_pending_messages (handle);
320} 308}
321 309
@@ -330,7 +318,7 @@ do_disconnect (struct GNUNET_DHT_Handle *handle)
330{ 318{
331 if (handle->client == NULL) 319 if (handle->client == NULL)
332 return; 320 return;
333 GNUNET_assert(handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK); 321 GNUNET_assert (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
334 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); 322 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
335 handle->client = NULL; 323 handle->client = NULL;
336 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->retry_time, 324 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->retry_time,
@@ -348,25 +336,24 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle)
348 struct PendingMessage *head; 336 struct PendingMessage *head;
349 337
350 if (handle->client == NULL) 338 if (handle->client == NULL)
351 { 339 {
352 do_disconnect(handle); 340 do_disconnect (handle);
353 return; 341 return;
354 } 342 }
355 if (handle->th != NULL) 343 if (handle->th != NULL)
356 return; 344 return;
357 if (NULL == (head = handle->pending_head)) 345 if (NULL == (head = handle->pending_head))
358 return; 346 return;
359 handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client, 347 handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client,
360 ntohs (head->msg->size), 348 ntohs (head->msg->size),
361 GNUNET_TIME_UNIT_FOREVER_REL, 349 GNUNET_TIME_UNIT_FOREVER_REL,
362 GNUNET_YES, 350 GNUNET_YES,
363 &transmit_pending, 351 &transmit_pending, handle);
364 handle); 352 if (NULL == handle->th)
365 if (NULL == handle->th) 353 {
366 { 354 do_disconnect (handle);
367 do_disconnect (handle); 355 return;
368 return; 356 }
369 }
370} 357}
371 358
372 359
@@ -374,9 +361,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle)
374 * Transmit the next pending message, called by notify_transmit_ready 361 * Transmit the next pending message, called by notify_transmit_ready
375 */ 362 */
376static size_t 363static size_t
377transmit_pending (void *cls, 364transmit_pending (void *cls, size_t size, void *buf)
378 size_t size,
379 void *buf)
380{ 365{
381 struct GNUNET_DHT_Handle *handle = cls; 366 struct GNUNET_DHT_Handle *handle = cls;
382 struct PendingMessage *head; 367 struct PendingMessage *head;
@@ -384,44 +369,44 @@ transmit_pending (void *cls,
384 369
385 handle->th = NULL; 370 handle->th = NULL;
386 if (buf == NULL) 371 if (buf == NULL)
387 { 372 {
388 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Transmission to DHT service failed! Reconnecting!\n"); 373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
389 do_disconnect (handle); 374 "Transmission to DHT service failed! Reconnecting!\n");
390 return 0; 375 do_disconnect (handle);
391 } 376 return 0;
377 }
392 if (NULL == (head = handle->pending_head)) 378 if (NULL == (head = handle->pending_head))
393 return 0; 379 return 0;
394 380
395 tsize = ntohs (head->msg->size); 381 tsize = ntohs (head->msg->size);
396 if (size < tsize) 382 if (size < tsize)
397 { 383 {
398 process_pending_messages (handle); 384 process_pending_messages (handle);
399 return 0; 385 return 0;
400 } 386 }
401 memcpy (buf, head->msg, tsize); 387 memcpy (buf, head->msg, tsize);
402 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 388 GNUNET_CONTAINER_DLL_remove (handle->pending_head,
403 handle->pending_tail, 389 handle->pending_tail, head);
404 head);
405 if (head->timeout_task != GNUNET_SCHEDULER_NO_TASK) 390 if (head->timeout_task != GNUNET_SCHEDULER_NO_TASK)
406 { 391 {
407 GNUNET_SCHEDULER_cancel (head->timeout_task); 392 GNUNET_SCHEDULER_cancel (head->timeout_task);
408 head->timeout_task = GNUNET_SCHEDULER_NO_TASK; 393 head->timeout_task = GNUNET_SCHEDULER_NO_TASK;
409 } 394 }
410 if (NULL != head->cont) 395 if (NULL != head->cont)
411 { 396 {
412 GNUNET_SCHEDULER_add_continuation (head->cont, 397 GNUNET_SCHEDULER_add_continuation (head->cont,
413 head->cont_cls, 398 head->cont_cls,
414 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 399 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
415 head->cont = NULL; 400 head->cont = NULL;
416 head->cont_cls = NULL; 401 head->cont_cls = NULL;
417 } 402 }
418 head->in_pending_queue = GNUNET_NO; 403 head->in_pending_queue = GNUNET_NO;
419 if (GNUNET_YES == head->free_on_send) 404 if (GNUNET_YES == head->free_on_send)
420 GNUNET_free (head); 405 GNUNET_free (head);
421 process_pending_messages (handle); 406 process_pending_messages (handle);
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 "Forwarded request of %u bytes to DHT service\n", 408 "Forwarded request of %u bytes to DHT service\n",
424 (unsigned int) tsize); 409 (unsigned int) tsize);
425 return tsize; 410 return tsize;
426} 411}
427 412
@@ -431,9 +416,7 @@ transmit_pending (void *cls,
431 * request. 416 * request.
432 */ 417 */
433static int 418static int
434process_reply (void *cls, 419process_reply (void *cls, const GNUNET_HashCode * key, void *value)
435 const GNUNET_HashCode *key,
436 void *value)
437{ 420{
438 const struct GNUNET_DHT_RouteResultMessage *dht_msg = cls; 421 const struct GNUNET_DHT_RouteResultMessage *dht_msg = cls;
439 struct GNUNET_DHT_RouteHandle *rh = value; 422 struct GNUNET_DHT_RouteHandle *rh = value;
@@ -448,47 +431,46 @@ process_reply (void *cls,
448 431
449 uid = GNUNET_ntohll (dht_msg->unique_id); 432 uid = GNUNET_ntohll (dht_msg->unique_id);
450 if (uid != rh->uid) 433 if (uid != rh->uid)
451 { 434 {
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 "Reply UID did not match request UID\n"); 436 "Reply UID did not match request UID\n");
454 return GNUNET_YES; 437 return GNUNET_YES;
455 } 438 }
456 enc_msg = (const struct GNUNET_MessageHeader *)&dht_msg[1]; 439 enc_msg = (const struct GNUNET_MessageHeader *) &dht_msg[1];
457 enc_size = ntohs (enc_msg->size); 440 enc_size = ntohs (enc_msg->size);
458 if (enc_size < sizeof (struct GNUNET_MessageHeader)) 441 if (enc_size < sizeof (struct GNUNET_MessageHeader))
459 { 442 {
460 GNUNET_break (0); 443 GNUNET_break (0);
461 return GNUNET_NO; 444 return GNUNET_NO;
462 } 445 }
463 path_offset = (char *)&dht_msg[1]; 446 path_offset = (char *) &dht_msg[1];
464 path_offset += enc_size; 447 path_offset += enc_size;
465 pos = (const struct GNUNET_PeerIdentity *) path_offset; 448 pos = (const struct GNUNET_PeerIdentity *) path_offset;
466 outgoing_path_length = ntohl (dht_msg->outgoing_path_length); 449 outgoing_path_length = ntohl (dht_msg->outgoing_path_length);
467 if (outgoing_path_length * sizeof (struct GNUNET_PeerIdentity) > ntohs(dht_msg->header.size) - enc_size) 450 if (outgoing_path_length * sizeof (struct GNUNET_PeerIdentity) >
468 { 451 ntohs (dht_msg->header.size) - enc_size)
469 GNUNET_break (0); 452 {
470 return GNUNET_NO; 453 GNUNET_break (0);
471 } 454 return GNUNET_NO;
455 }
472 456
473 if (outgoing_path_length > 0) 457 if (outgoing_path_length > 0)
458 {
459 outgoing_path =
460 GNUNET_malloc ((outgoing_path_length +
461 1) * sizeof (struct GNUNET_PeerIdentity *));
462 for (i = 0; i < outgoing_path_length; i++)
474 { 463 {
475 outgoing_path = GNUNET_malloc ((outgoing_path_length + 1) * sizeof (struct GNUNET_PeerIdentity*)); 464 outgoing_path[i] = pos;
476 for (i = 0; i < outgoing_path_length; i++) 465 pos++;
477 {
478 outgoing_path[i] = pos;
479 pos++;
480 }
481 outgoing_path[outgoing_path_length] = NULL;
482 } 466 }
467 outgoing_path[outgoing_path_length] = NULL;
468 }
483 else 469 else
484 outgoing_path = NULL; 470 outgoing_path = NULL;
485 471
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing reply.\n");
487 "Processing reply.\n"); 473 rh->iter (rh->iter_cls, &rh->key, outgoing_path, enc_msg);
488 rh->iter (rh->iter_cls,
489 &rh->key,
490 outgoing_path,
491 enc_msg);
492 GNUNET_free_non_null (outgoing_path); 474 GNUNET_free_non_null (outgoing_path);
493 return GNUNET_YES; 475 return GNUNET_YES;
494} 476}
@@ -502,42 +484,40 @@ process_reply (void *cls,
502 * @param msg the incoming message 484 * @param msg the incoming message
503 */ 485 */
504static void 486static void
505service_message_handler (void *cls, 487service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
506 const struct GNUNET_MessageHeader *msg)
507{ 488{
508 struct GNUNET_DHT_Handle *handle = cls; 489 struct GNUNET_DHT_Handle *handle = cls;
509 const struct GNUNET_DHT_RouteResultMessage *dht_msg; 490 const struct GNUNET_DHT_RouteResultMessage *dht_msg;
510 491
511 if (msg == NULL) 492 if (msg == NULL)
512 { 493 {
513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
514 "Error receiving data from DHT service, reconnecting\n"); 495 "Error receiving data from DHT service, reconnecting\n");
515 do_disconnect (handle); 496 do_disconnect (handle);
516 return; 497 return;
517 } 498 }
518 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT) 499 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT)
519 { 500 {
520 GNUNET_break (0); 501 GNUNET_break (0);
521 do_disconnect (handle); 502 do_disconnect (handle);
522 return; 503 return;
523 } 504 }
524 if (ntohs (msg->size) < sizeof (struct GNUNET_DHT_RouteResultMessage)) 505 if (ntohs (msg->size) < sizeof (struct GNUNET_DHT_RouteResultMessage))
525 { 506 {
526 GNUNET_break (0); 507 GNUNET_break (0);
527 do_disconnect (handle); 508 do_disconnect (handle);
528 return; 509 return;
529 } 510 }
530 dht_msg = (const struct GNUNET_DHT_RouteResultMessage *) msg; 511 dht_msg = (const struct GNUNET_DHT_RouteResultMessage *) msg;
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
532 "Comparing reply `%s' against %u pending requests.\n", 513 "Comparing reply `%s' against %u pending requests.\n",
533 GNUNET_h2s (&dht_msg->key), 514 GNUNET_h2s (&dht_msg->key),
534 GNUNET_CONTAINER_multihashmap_size (handle->active_requests)); 515 GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
535 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, 516 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests,
536 &dht_msg->key, 517 &dht_msg->key,
537 &process_reply, 518 &process_reply, (void *) dht_msg);
538 (void*) dht_msg);
539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
540 "Continuing to process replies from DHT\n"); 520 "Continuing to process replies from DHT\n");
541 GNUNET_CLIENT_receive (handle->client, 521 GNUNET_CLIENT_receive (handle->client,
542 &service_message_handler, 522 &service_message_handler,
543 handle, GNUNET_TIME_UNIT_FOREVER_REL); 523 handle, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -562,13 +542,14 @@ GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
562 542
563 handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_Handle)); 543 handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_Handle));
564 handle->cfg = cfg; 544 handle->cfg = cfg;
565 handle->uid_gen = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 545 handle->uid_gen =
546 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
566 handle->active_requests = GNUNET_CONTAINER_multihashmap_create (ht_len); 547 handle->active_requests = GNUNET_CONTAINER_multihashmap_create (ht_len);
567 if (GNUNET_NO == try_connect (handle)) 548 if (GNUNET_NO == try_connect (handle))
568 { 549 {
569 GNUNET_DHT_disconnect (handle); 550 GNUNET_DHT_disconnect (handle);
570 return NULL; 551 return NULL;
571 } 552 }
572 return handle; 553 return handle;
573} 554}
574 555
@@ -582,36 +563,37 @@ void
582GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) 563GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle)
583{ 564{
584 struct PendingMessage *pm; 565 struct PendingMessage *pm;
585 GNUNET_assert(handle != NULL); 566
586 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size(handle->active_requests)); 567 GNUNET_assert (handle != NULL);
568 GNUNET_assert (0 ==
569 GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
587 if (handle->th != NULL) 570 if (handle->th != NULL)
588 { 571 {
589 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 572 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
590 handle->th = NULL; 573 handle->th = NULL;
591 } 574 }
592 while (NULL != (pm = handle->pending_head)) 575 while (NULL != (pm = handle->pending_head))
593 { 576 {
594 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 577 GNUNET_CONTAINER_DLL_remove (handle->pending_head,
595 handle->pending_tail, 578 handle->pending_tail, pm);
596 pm); 579 GNUNET_assert (GNUNET_YES == pm->free_on_send);
597 GNUNET_assert (GNUNET_YES == pm->free_on_send); 580 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task)
598 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task) 581 GNUNET_SCHEDULER_cancel (pm->timeout_task);
599 GNUNET_SCHEDULER_cancel (pm->timeout_task); 582 if (NULL != pm->cont)
600 if (NULL != pm->cont) 583 GNUNET_SCHEDULER_add_continuation (pm->cont,
601 GNUNET_SCHEDULER_add_continuation (pm->cont, 584 pm->cont_cls,
602 pm->cont_cls, 585 GNUNET_SCHEDULER_REASON_TIMEOUT);
603 GNUNET_SCHEDULER_REASON_TIMEOUT); 586 pm->in_pending_queue = GNUNET_NO;
604 pm->in_pending_queue = GNUNET_NO; 587 GNUNET_free (pm);
605 GNUNET_free (pm); 588 }
606 }
607 if (handle->client != NULL) 589 if (handle->client != NULL)
608 { 590 {
609 GNUNET_CLIENT_disconnect (handle->client, GNUNET_YES); 591 GNUNET_CLIENT_disconnect (handle->client, GNUNET_YES);
610 handle->client = NULL; 592 handle->client = NULL;
611 } 593 }
612 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) 594 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
613 GNUNET_SCHEDULER_cancel(handle->reconnect_task); 595 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
614 GNUNET_CONTAINER_multihashmap_destroy(handle->active_requests); 596 GNUNET_CONTAINER_multihashmap_destroy (handle->active_requests);
615 GNUNET_free (handle); 597 GNUNET_free (handle);
616} 598}
617 599
@@ -628,25 +610,22 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle)
628 * @param tc scheduler context 610 * @param tc scheduler context
629 */ 611 */
630static void 612static void
631timeout_route_request (void *cls, 613timeout_route_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
632 const struct GNUNET_SCHEDULER_TaskContext *tc)
633{ 614{
634 struct PendingMessage *pending = cls; 615 struct PendingMessage *pending = cls;
635 struct GNUNET_DHT_Handle *handle; 616 struct GNUNET_DHT_Handle *handle;
636 617
637 if (pending->free_on_send != GNUNET_YES) 618 if (pending->free_on_send != GNUNET_YES)
638 { 619 {
639 /* timeouts should only apply to fire & forget requests! */ 620 /* timeouts should only apply to fire & forget requests! */
640 GNUNET_break (0); 621 GNUNET_break (0);
641 return; 622 return;
642 } 623 }
643 handle = pending->handle; 624 handle = pending->handle;
644 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 625 GNUNET_CONTAINER_DLL_remove (handle->pending_head,
645 handle->pending_tail, 626 handle->pending_tail, pending);
646 pending);
647 if (pending->cont != NULL) 627 if (pending->cont != NULL)
648 pending->cont (pending->cont_cls, 628 pending->cont (pending->cont_cls, tc);
649 tc);
650 GNUNET_free (pending); 629 GNUNET_free (pending);
651} 630}
652 631
@@ -674,15 +653,14 @@ timeout_route_request (void *cls,
674 */ 653 */
675struct GNUNET_DHT_RouteHandle * 654struct GNUNET_DHT_RouteHandle *
676GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle, 655GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
677 const GNUNET_HashCode *key, 656 const GNUNET_HashCode * key,
678 uint32_t desired_replication_level, 657 uint32_t desired_replication_level,
679 enum GNUNET_DHT_RouteOption options, 658 enum GNUNET_DHT_RouteOption options,
680 const struct GNUNET_MessageHeader *enc, 659 const struct GNUNET_MessageHeader *enc,
681 struct GNUNET_TIME_Relative timeout, 660 struct GNUNET_TIME_Relative timeout,
682 GNUNET_DHT_ReplyProcessor iter, 661 GNUNET_DHT_ReplyProcessor iter,
683 void *iter_cls, 662 void *iter_cls,
684 GNUNET_SCHEDULER_Task cont, 663 GNUNET_SCHEDULER_Task cont, void *cont_cls)
685 void *cont_cls)
686{ 664{
687 struct PendingMessage *pending; 665 struct PendingMessage *pending;
688 struct GNUNET_DHT_RouteMessage *message; 666 struct GNUNET_DHT_RouteMessage *message;
@@ -691,19 +669,20 @@ GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
691 uint16_t esize; 669 uint16_t esize;
692 670
693 esize = ntohs (enc->size); 671 esize = ntohs (enc->size);
694 if (sizeof (struct GNUNET_DHT_RouteMessage) + esize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 672 if (sizeof (struct GNUNET_DHT_RouteMessage) + esize >=
695 { 673 GNUNET_SERVER_MAX_MESSAGE_SIZE)
696 GNUNET_break (0); 674 {
697 return NULL; 675 GNUNET_break (0);
698 } 676 return NULL;
677 }
699 msize = sizeof (struct GNUNET_DHT_RouteMessage) + esize; 678 msize = sizeof (struct GNUNET_DHT_RouteMessage) + esize;
700 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 679 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
701 message = (struct GNUNET_DHT_RouteMessage*) &pending[1]; 680 message = (struct GNUNET_DHT_RouteMessage *) &pending[1];
702 pending->msg = &message->header; 681 pending->msg = &message->header;
703 pending->handle = handle; 682 pending->handle = handle;
704 pending->cont = cont; 683 pending->cont = cont;
705 pending->cont_cls = cont_cls; 684 pending->cont_cls = cont_cls;
706 685
707 message->header.size = htons (msize); 686 message->header.size = htons (msize);
708 message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE); 687 message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE);
709 message->options = htonl ((uint32_t) options); 688 message->options = htonl ((uint32_t) options);
@@ -715,35 +694,34 @@ GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
715 memcpy (&message[1], enc, esize); 694 memcpy (&message[1], enc, esize);
716 695
717 if (iter != NULL) 696 if (iter != NULL)
718 { 697 {
719 route_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_RouteHandle)); 698 route_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_RouteHandle));
720 route_handle->key = *key; 699 route_handle->key = *key;
721 route_handle->iter = iter; 700 route_handle->iter = iter;
722 route_handle->iter_cls = iter_cls; 701 route_handle->iter_cls = iter_cls;
723 route_handle->dht_handle = handle; 702 route_handle->dht_handle = handle;
724 route_handle->uid = handle->uid_gen; 703 route_handle->uid = handle->uid_gen;
725 route_handle->message = pending; 704 route_handle->message = pending;
726 GNUNET_CONTAINER_multihashmap_put (handle->active_requests, 705 GNUNET_CONTAINER_multihashmap_put (handle->active_requests,
727 key, 706 key,
728 route_handle, 707 route_handle,
729 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 708 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
730 } 709 }
731 else 710 else
732 { 711 {
733 route_handle = NULL; 712 route_handle = NULL;
734 pending->free_on_send = GNUNET_YES; 713 pending->free_on_send = GNUNET_YES;
735 pending->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 714 pending->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
736 &timeout_route_request, 715 &timeout_route_request,
737 pending); 716 pending);
738 } 717 }
739 GNUNET_CONTAINER_DLL_insert (handle->pending_head, 718 GNUNET_CONTAINER_DLL_insert (handle->pending_head,
740 handle->pending_tail, 719 handle->pending_tail, pending);
741 pending);
742 pending->in_pending_queue = GNUNET_YES; 720 pending->in_pending_queue = GNUNET_YES;
743 process_pending_messages (handle); 721 process_pending_messages (handle);
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "DHT route start request processed, returning %p\n", 723 "DHT route start request processed, returning %p\n",
746 route_handle); 724 route_handle);
747 return route_handle; 725 return route_handle;
748} 726}
749 727
@@ -763,42 +741,38 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle)
763 741
764 handle = route_handle->dht_handle; 742 handle = route_handle->dht_handle;
765 if (GNUNET_NO == route_handle->message->in_pending_queue) 743 if (GNUNET_NO == route_handle->message->in_pending_queue)
766 { 744 {
767 /* need to send stop message */ 745 /* need to send stop message */
768 msize = sizeof (struct GNUNET_DHT_StopMessage); 746 msize = sizeof (struct GNUNET_DHT_StopMessage);
769 pending = GNUNET_malloc (sizeof (struct PendingMessage) + 747 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
770 msize); 748 message = (struct GNUNET_DHT_StopMessage *) &pending[1];
771 message = (struct GNUNET_DHT_StopMessage*) &pending[1]; 749 pending->msg = &message->header;
772 pending->msg = &message->header; 750 message->header.size = htons (msize);
773 message->header.size = htons (msize); 751 message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_STOP);
774 message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_STOP); 752 message->reserved = 0;
775 message->reserved = 0; 753 message->unique_id = GNUNET_htonll (route_handle->uid);
776 message->unique_id = GNUNET_htonll (route_handle->uid); 754 message->key = route_handle->key;
777 message->key = route_handle->key; 755 pending->handle = handle;
778 pending->handle = handle; 756 pending->free_on_send = GNUNET_YES;
779 pending->free_on_send = GNUNET_YES; 757 pending->in_pending_queue = GNUNET_YES;
780 pending->in_pending_queue = GNUNET_YES; 758 GNUNET_CONTAINER_DLL_insert (handle->pending_head,
781 GNUNET_CONTAINER_DLL_insert (handle->pending_head, 759 handle->pending_tail, pending);
782 handle->pending_tail, 760 process_pending_messages (handle);
783 pending); 761 }
784 process_pending_messages (handle);
785 }
786 else 762 else
787 { 763 {
788 /* simply remove pending request from message queue before 764 /* simply remove pending request from message queue before
789 transmission, no need to transmit STOP request! */ 765 * transmission, no need to transmit STOP request! */
790 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 766 GNUNET_CONTAINER_DLL_remove (handle->pending_head,
791 handle->pending_tail, 767 handle->pending_tail, route_handle->message);
792 route_handle->message); 768 }
793 }
794 GNUNET_assert (GNUNET_YES == 769 GNUNET_assert (GNUNET_YES ==
795 GNUNET_CONTAINER_multihashmap_remove (route_handle->dht_handle->active_requests, 770 GNUNET_CONTAINER_multihashmap_remove
796 &route_handle->key, 771 (route_handle->dht_handle->active_requests, &route_handle->key,
797 route_handle)); 772 route_handle));
798 GNUNET_free(route_handle->message); 773 GNUNET_free (route_handle->message);
799 GNUNET_free(route_handle); 774 GNUNET_free (route_handle);
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DHT route stop request processed\n");
801 "DHT route stop request processed\n");
802} 776}
803 777
804 778
@@ -817,29 +791,27 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle)
817 */ 791 */
818static void 792static void
819send_control_message (struct GNUNET_DHT_Handle *handle, 793send_control_message (struct GNUNET_DHT_Handle *handle,
820 uint16_t command, 794 uint16_t command,
821 uint16_t variable, 795 uint16_t variable,
822 GNUNET_SCHEDULER_Task cont, 796 GNUNET_SCHEDULER_Task cont, void *cont_cls)
823 void *cont_cls)
824{ 797{
825 struct GNUNET_DHT_ControlMessage *msg; 798 struct GNUNET_DHT_ControlMessage *msg;
826 struct PendingMessage *pending; 799 struct PendingMessage *pending;
827 800
828 pending = GNUNET_malloc (sizeof (struct PendingMessage) + 801 pending = GNUNET_malloc (sizeof (struct PendingMessage) +
829 sizeof(struct GNUNET_DHT_ControlMessage)); 802 sizeof (struct GNUNET_DHT_ControlMessage));
830 msg = (struct GNUNET_DHT_ControlMessage*) &pending[1]; 803 msg = (struct GNUNET_DHT_ControlMessage *) &pending[1];
831 pending->msg = &msg->header; 804 pending->msg = &msg->header;
832 msg->header.size = htons (sizeof(struct GNUNET_DHT_ControlMessage)); 805 msg->header.size = htons (sizeof (struct GNUNET_DHT_ControlMessage));
833 msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CONTROL); 806 msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CONTROL);
834 msg->command = htons (command); 807 msg->command = htons (command);
835 msg->variable = htons (variable); 808 msg->variable = htons (variable);
836 pending->free_on_send = GNUNET_YES; 809 pending->free_on_send = GNUNET_YES;
837 pending->cont = cont; 810 pending->cont = cont;
838 pending->cont_cls = cont_cls; 811 pending->cont_cls = cont_cls;
839 pending->in_pending_queue = GNUNET_YES; 812 pending->in_pending_queue = GNUNET_YES;
840 GNUNET_CONTAINER_DLL_insert (handle->pending_head, 813 GNUNET_CONTAINER_DLL_insert (handle->pending_head,
841 handle->pending_tail, 814 handle->pending_tail, pending);
842 pending);
843 process_pending_messages (handle); 815 process_pending_messages (handle);
844} 816}
845 817
@@ -857,12 +829,10 @@ send_control_message (struct GNUNET_DHT_Handle *handle,
857 */ 829 */
858void 830void
859GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle, 831GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
860 GNUNET_SCHEDULER_Task cont, 832 GNUNET_SCHEDULER_Task cont, void *cont_cls)
861 void *cont_cls)
862{ 833{
863 send_control_message (handle, 834 send_control_message (handle,
864 GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0, 835 GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0, cont, cont_cls);
865 cont, cont_cls);
866} 836}
867 837
868 838
@@ -880,17 +850,17 @@ GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
880 */ 850 */
881void 851void
882GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, 852GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
883 struct GNUNET_TIME_Relative frequency, GNUNET_SCHEDULER_Task cont, 853 struct GNUNET_TIME_Relative frequency,
884 void *cont_cls) 854 GNUNET_SCHEDULER_Task cont, void *cont_cls)
885{ 855{
886 if (frequency.rel_value > UINT16_MAX) 856 if (frequency.rel_value > UINT16_MAX)
887 { 857 {
888 GNUNET_break (0); 858 GNUNET_break (0);
889 return; 859 return;
890 } 860 }
891 send_control_message (handle, 861 send_control_message (handle,
892 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET, frequency.rel_value, 862 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET,
893 cont, cont_cls); 863 frequency.rel_value, cont, cont_cls);
894} 864}
895 865
896/** 866/**
@@ -902,20 +872,20 @@ GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
902 * @param cont continuation to call when done (transmitting request to service) 872 * @param cont continuation to call when done (transmitting request to service)
903 * @param cont_cls closure for cont 873 * @param cont_cls closure for cont
904 */ 874 */
905void 875void
906GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle, 876GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
907 struct GNUNET_TIME_Relative frequency, GNUNET_SCHEDULER_Task cont, 877 struct GNUNET_TIME_Relative frequency,
908 void *cont_cls) 878 GNUNET_SCHEDULER_Task cont, void *cont_cls)
909{ 879{
910 if (frequency.rel_value > UINT16_MAX) 880 if (frequency.rel_value > UINT16_MAX)
911 { 881 {
912 GNUNET_break (0); 882 GNUNET_break (0);
913 return; 883 return;
914 } 884 }
915 885
916 send_control_message (handle, 886 send_control_message (handle,
917 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT, frequency.rel_value, 887 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT,
918 cont, cont_cls); 888 frequency.rel_value, cont, cont_cls);
919} 889}
920 890
921 891
@@ -928,9 +898,9 @@ GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
928 * @param cont_cls closure for cont 898 * @param cont_cls closure for cont
929 * 899 *
930 */ 900 */
931void 901void
932GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle, GNUNET_SCHEDULER_Task cont, 902GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
933 void *cont_cls) 903 GNUNET_SCHEDULER_Task cont, void *cont_cls)
934{ 904{
935 send_control_message (handle, 905 send_control_message (handle,
936 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP, 0, 906 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP, 0,
diff --git a/src/dht/dht_api_find_peer.c b/src/dht/dht_api_find_peer.c
index 8196e394c..bcf1b50b7 100644
--- a/src/dht/dht_api_find_peer.c
+++ b/src/dht/dht_api_find_peer.c
@@ -71,28 +71,29 @@ struct GNUNET_DHT_FindPeerHandle
71 * @param reply response 71 * @param reply response
72 */ 72 */
73static void 73static void
74find_peer_reply_iterator (void *cls, 74find_peer_reply_iterator (void *cls,
75 const GNUNET_HashCode *key, 75 const GNUNET_HashCode * key,
76 const struct GNUNET_PeerIdentity * const *outgoing_path, 76 const struct GNUNET_PeerIdentity *const
77 const struct GNUNET_MessageHeader *reply) 77 *outgoing_path,
78 const struct GNUNET_MessageHeader *reply)
78{ 79{
79 struct GNUNET_DHT_FindPeerHandle *find_peer_handle = cls; 80 struct GNUNET_DHT_FindPeerHandle *find_peer_handle = cls;
80 const struct GNUNET_MessageHeader *hello; 81 const struct GNUNET_MessageHeader *hello;
81 82
82 if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT) 83 if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT)
83 { 84 {
84 GNUNET_break (0); 85 GNUNET_break (0);
85 return; 86 return;
86 } 87 }
87 GNUNET_assert (ntohs (reply->size) >= sizeof (struct GNUNET_MessageHeader)); 88 GNUNET_assert (ntohs (reply->size) >= sizeof (struct GNUNET_MessageHeader));
88 hello = (const struct GNUNET_MessageHeader *)&reply[1]; 89 hello = (const struct GNUNET_MessageHeader *) &reply[1];
89 if (ntohs(hello->type) != GNUNET_MESSAGE_TYPE_HELLO) 90 if (ntohs (hello->type) != GNUNET_MESSAGE_TYPE_HELLO)
90 { 91 {
91 GNUNET_break (0); 92 GNUNET_break (0);
92 return; 93 return;
93 } 94 }
94 find_peer_handle->proc (find_peer_handle->proc_cls, 95 find_peer_handle->proc (find_peer_handle->proc_cls,
95 (const struct GNUNET_HELLO_Message *)hello); 96 (const struct GNUNET_HELLO_Message *) hello);
96} 97}
97 98
98 99
@@ -112,27 +113,26 @@ find_peer_reply_iterator (void *cls,
112struct GNUNET_DHT_FindPeerHandle * 113struct GNUNET_DHT_FindPeerHandle *
113GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle, 114GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
114 struct GNUNET_TIME_Relative timeout, 115 struct GNUNET_TIME_Relative timeout,
115 const GNUNET_HashCode *key, 116 const GNUNET_HashCode * key,
116 enum GNUNET_DHT_RouteOption options, 117 enum GNUNET_DHT_RouteOption options,
117 GNUNET_DHT_FindPeerProcessor proc, 118 GNUNET_DHT_FindPeerProcessor proc, void *proc_cls)
118 void *proc_cls)
119{ 119{
120 struct GNUNET_DHT_FindPeerHandle *find_peer_handle; 120 struct GNUNET_DHT_FindPeerHandle *find_peer_handle;
121 struct GNUNET_DHT_FindPeerMessage find_peer_msg; 121 struct GNUNET_DHT_FindPeerMessage find_peer_msg;
122 122
123 find_peer_handle = 123 find_peer_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerHandle));
124 GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerHandle));
125 find_peer_handle->proc = proc; 124 find_peer_handle->proc = proc;
126 find_peer_handle->proc_cls = proc_cls; 125 find_peer_handle->proc_cls = proc_cls;
127 find_peer_msg.header.size = htons(sizeof(struct GNUNET_DHT_FindPeerMessage)); 126 find_peer_msg.header.size =
128 find_peer_msg.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); 127 htons (sizeof (struct GNUNET_DHT_FindPeerMessage));
128 find_peer_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER);
129 find_peer_handle->route_handle = 129 find_peer_handle->route_handle =
130 GNUNET_DHT_route_start (handle, key, 130 GNUNET_DHT_route_start (handle, key,
131 0, options, 131 0, options,
132 &find_peer_msg.header, 132 &find_peer_msg.header,
133 timeout, 133 timeout,
134 &find_peer_reply_iterator, find_peer_handle, 134 &find_peer_reply_iterator, find_peer_handle,
135 NULL, NULL); 135 NULL, NULL);
136 GNUNET_break (find_peer_handle->route_handle != NULL); 136 GNUNET_break (find_peer_handle->route_handle != NULL);
137 return find_peer_handle; 137 return find_peer_handle;
138} 138}
diff --git a/src/dht/dht_api_get_put.c b/src/dht/dht_api_get_put.c
index 5b5baa531..30b73e1f1 100644
--- a/src/dht/dht_api_get_put.c
+++ b/src/dht/dht_api_get_put.c
@@ -55,41 +55,38 @@ void
55GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, 55GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
56 const GNUNET_HashCode * key, 56 const GNUNET_HashCode * key,
57 uint32_t desired_replication_level, 57 uint32_t desired_replication_level,
58 enum GNUNET_DHT_RouteOption options, 58 enum GNUNET_DHT_RouteOption options,
59 enum GNUNET_BLOCK_Type type, 59 enum GNUNET_BLOCK_Type type,
60 size_t size, 60 size_t size,
61 const char *data, 61 const char *data,
62 struct GNUNET_TIME_Absolute exp, 62 struct GNUNET_TIME_Absolute exp,
63 struct GNUNET_TIME_Relative timeout, 63 struct GNUNET_TIME_Relative timeout,
64 GNUNET_SCHEDULER_Task cont, 64 GNUNET_SCHEDULER_Task cont, void *cont_cls)
65 void *cont_cls)
66{ 65{
67 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 66 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
68 struct GNUNET_DHT_PutMessage *put_msg; 67 struct GNUNET_DHT_PutMessage *put_msg;
69 68
70 if (size >= sizeof (buf) - sizeof (struct GNUNET_DHT_PutMessage)) 69 if (size >= sizeof (buf) - sizeof (struct GNUNET_DHT_PutMessage))
71 { 70 {
72 GNUNET_break (0); 71 GNUNET_break (0);
73 return; 72 return;
74 } 73 }
75 put_msg = (struct GNUNET_DHT_PutMessage*) buf; 74 put_msg = (struct GNUNET_DHT_PutMessage *) buf;
76 put_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_PUT); 75 put_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_PUT);
77 put_msg->header.size = htons (sizeof (struct GNUNET_DHT_PutMessage) + size); 76 put_msg->header.size = htons (sizeof (struct GNUNET_DHT_PutMessage) + size);
78 put_msg->type = htonl ((uint32_t)type); 77 put_msg->type = htonl ((uint32_t) type);
79 put_msg->expiration = GNUNET_TIME_absolute_hton (exp); 78 put_msg->expiration = GNUNET_TIME_absolute_hton (exp);
80 memcpy (&put_msg[1], data, size); 79 memcpy (&put_msg[1], data, size);
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
82 "Starting route for %u byte `%s' message of type %u \n", 81 "Starting route for %u byte `%s' message of type %u \n",
83 (unsigned int) (sizeof (struct GNUNET_DHT_PutMessage) + size), 82 (unsigned int) (sizeof (struct GNUNET_DHT_PutMessage) + size),
84 "PUT", type); 83 "PUT", type);
85 GNUNET_break (NULL == 84 GNUNET_break (NULL ==
86 GNUNET_DHT_route_start (handle, 85 GNUNET_DHT_route_start (handle,
87 key, 86 key,
88 desired_replication_level, options, 87 desired_replication_level, options,
89 &put_msg->header, 88 &put_msg->header,
90 timeout, 89 timeout, NULL, NULL, cont, cont_cls));
91 NULL, NULL,
92 cont, cont_cls));
93} 90}
94 91
95 92
@@ -129,10 +126,10 @@ struct GNUNET_DHT_GetHandle
129 * @param reply response 126 * @param reply response
130 */ 127 */
131static void 128static void
132get_reply_iterator (void *cls, 129get_reply_iterator (void *cls,
133 const GNUNET_HashCode *key, 130 const GNUNET_HashCode * key,
134 const struct GNUNET_PeerIdentity * const *outgoing_path, 131 const struct GNUNET_PeerIdentity *const *outgoing_path,
135 const struct GNUNET_MessageHeader *reply) 132 const struct GNUNET_MessageHeader *reply)
136{ 133{
137 struct GNUNET_DHT_GetHandle *get_handle = cls; 134 struct GNUNET_DHT_GetHandle *get_handle = cls;
138 const struct GNUNET_DHT_GetResultMessage *result; 135 const struct GNUNET_DHT_GetResultMessage *result;
@@ -145,44 +142,46 @@ get_reply_iterator (void *cls,
145 uint16_t data_size; 142 uint16_t data_size;
146 143
147 if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) 144 if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_GET_RESULT)
148 { 145 {
149 GNUNET_break (0); 146 GNUNET_break (0);
150 return; 147 return;
151 } 148 }
152 149
153 GNUNET_assert (ntohs (reply->size) >= 150 GNUNET_assert (ntohs (reply->size) >=
154 sizeof (struct GNUNET_DHT_GetResultMessage)); 151 sizeof (struct GNUNET_DHT_GetResultMessage));
155 result = (const struct GNUNET_DHT_GetResultMessage *) reply; 152 result = (const struct GNUNET_DHT_GetResultMessage *) reply;
156 153
157 put_path = NULL; 154 put_path = NULL;
158 put_path_length = ntohs(result->put_path_length); 155 put_path_length = ntohs (result->put_path_length);
159 if (put_path_length > 0) 156 if (put_path_length > 0)
157 {
158 data_size =
159 ntohs (result->header.size) -
160 (put_path_length * sizeof (struct GNUNET_PeerIdentity)) -
161 sizeof (struct GNUNET_DHT_GetResultMessage);
162 path_offset = (char *) &result[1];
163 //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "In get_reply_iterator, result->header.size is %d, put_path_length %d, offset is %d, data_size is %d\n", ntohs(result->header.size), put_path_length, ntohs(result->header.size) - (put_path_length * sizeof(struct GNUNET_PeerIdentity)), data_size);
164 path_offset += data_size;
165 pos = (const struct GNUNET_PeerIdentity *) path_offset;
166 //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found put peer %s\n", GNUNET_i2s((const struct GNUNET_PeerIdentity *)path_offset));
167 put_path =
168 GNUNET_malloc ((put_path_length +
169 1) * sizeof (struct GNUNET_PeerIdentity *));
170 for (i = 0; i < put_path_length; i++)
160 { 171 {
161 data_size = ntohs(result->header.size) - (put_path_length * sizeof(struct GNUNET_PeerIdentity)) - sizeof(struct GNUNET_DHT_GetResultMessage); 172 put_path[i] = pos;
162 path_offset = (char *)&result[1]; 173 pos++;
163 //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "In get_reply_iterator, result->header.size is %d, put_path_length %d, offset is %d, data_size is %d\n", ntohs(result->header.size), put_path_length, ntohs(result->header.size) - (put_path_length * sizeof(struct GNUNET_PeerIdentity)), data_size);
164 path_offset += data_size;
165 pos = (const struct GNUNET_PeerIdentity *)path_offset;
166 //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found put peer %s\n", GNUNET_i2s((const struct GNUNET_PeerIdentity *)path_offset));
167 put_path = GNUNET_malloc ((put_path_length + 1) * sizeof (struct GNUNET_PeerIdentity*));
168 for (i = 0; i < put_path_length; i++)
169 {
170 put_path[i] = pos;
171 pos++;
172 }
173 put_path[put_path_length] = NULL;
174 } 174 }
175 put_path[put_path_length] = NULL;
176 }
175 177
176 payload = ntohs (reply->size) - sizeof(struct GNUNET_DHT_GetResultMessage); 178 payload = ntohs (reply->size) - sizeof (struct GNUNET_DHT_GetResultMessage);
177 get_handle->iter (get_handle->iter_cls, 179 get_handle->iter (get_handle->iter_cls,
178 GNUNET_TIME_absolute_ntoh (result->expiration), 180 GNUNET_TIME_absolute_ntoh (result->expiration),
179 key, 181 key,
180 outgoing_path, 182 outgoing_path,
181 put_path, 183 put_path, ntohs (result->type), payload, &result[1]);
182 ntohs (result->type), 184 GNUNET_free_non_null (put_path);
183 payload,
184 &result[1]);
185 GNUNET_free_non_null(put_path);
186} 185}
187 186
188 187
@@ -213,61 +212,55 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
213 enum GNUNET_BLOCK_Type type, 212 enum GNUNET_BLOCK_Type type,
214 const GNUNET_HashCode * key, 213 const GNUNET_HashCode * key,
215 uint32_t desired_replication_level, 214 uint32_t desired_replication_level,
216 enum GNUNET_DHT_RouteOption options, 215 enum GNUNET_DHT_RouteOption options,
217 const struct GNUNET_CONTAINER_BloomFilter *bf, 216 const struct GNUNET_CONTAINER_BloomFilter *bf,
218 int32_t bf_mutator, 217 int32_t bf_mutator,
219 const void *xquery, 218 const void *xquery,
220 size_t xquery_size, 219 size_t xquery_size,
221 GNUNET_DHT_GetIterator iter, 220 GNUNET_DHT_GetIterator iter, void *iter_cls)
222 void *iter_cls)
223{ 221{
224 struct GNUNET_DHT_GetHandle *get_handle; 222 struct GNUNET_DHT_GetHandle *get_handle;
225 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; 223 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
226 struct GNUNET_DHT_GetMessage *get_msg; 224 struct GNUNET_DHT_GetMessage *get_msg;
227 size_t bf_size; 225 size_t bf_size;
228 226
229 bf_size = GNUNET_CONTAINER_bloomfilter_get_size (bf); 227 bf_size = GNUNET_CONTAINER_bloomfilter_get_size (bf);
230 if ( (sizeof (buf) <= 228 if ((sizeof (buf) <=
231 sizeof (struct GNUNET_DHT_GetMessage) + xquery_size + bf_size) || 229 sizeof (struct GNUNET_DHT_GetMessage) + xquery_size + bf_size) ||
232 (sizeof (buf) <= bf_size)) 230 (sizeof (buf) <= bf_size))
233 { 231 {
234 GNUNET_break (0); 232 GNUNET_break (0);
235 return NULL; 233 return NULL;
236 } 234 }
237 get_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle)); 235 get_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle));
238 get_handle->iter = iter; 236 get_handle->iter = iter;
239 get_handle->iter_cls = iter_cls; 237 get_handle->iter_cls = iter_cls;
240 get_msg = (struct GNUNET_DHT_GetMessage*) buf; 238 get_msg = (struct GNUNET_DHT_GetMessage *) buf;
241 get_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET); 239 get_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET);
242 get_msg->header.size = htons (sizeof (struct GNUNET_DHT_GetMessage) + 240 get_msg->header.size = htons (sizeof (struct GNUNET_DHT_GetMessage) +
243 xquery_size + 241 xquery_size + bf_size);
244 bf_size);
245 get_msg->type = htonl ((uint32_t) type); 242 get_msg->type = htonl ((uint32_t) type);
246 get_msg->bf_mutator = bf_mutator; 243 get_msg->bf_mutator = bf_mutator;
247 get_msg->xquery_size = htons ((uint16_t) xquery_size); 244 get_msg->xquery_size = htons ((uint16_t) xquery_size);
248 get_msg->bf_size = htons (bf_size); 245 get_msg->bf_size = htons (bf_size);
249 if (xquery != NULL) 246 if (xquery != NULL)
250 memcpy (&buf[sizeof(struct GNUNET_DHT_GetMessage)], 247 memcpy (&buf[sizeof (struct GNUNET_DHT_GetMessage)], xquery, xquery_size);
251 xquery,
252 xquery_size);
253 else 248 else
254 GNUNET_assert (xquery_size == 0); 249 GNUNET_assert (xquery_size == 0);
255 (void) GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, 250 (void) GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
256 &buf[sizeof(struct GNUNET_DHT_GetMessage) + xquery_size], 251 &buf[sizeof
257 bf_size); 252 (struct
253 GNUNET_DHT_GetMessage)
254 + xquery_size],
255 bf_size);
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
259 "Starting route for %u byte `%s' message\n", 257 "Starting route for %u byte `%s' message\n",
260 (unsigned int) (sizeof (struct GNUNET_DHT_GetMessage) + xquery_size + bf_size) , 258 (unsigned int) (sizeof (struct GNUNET_DHT_GetMessage) +
261 "GET"); 259 xquery_size + bf_size), "GET");
262 get_handle->route_handle = 260 get_handle->route_handle =
263 GNUNET_DHT_route_start (handle, 261 GNUNET_DHT_route_start (handle, key, desired_replication_level, options,
264 key, 262 &get_msg->header, timeout, &get_reply_iterator,
265 desired_replication_level, 263 get_handle, NULL, NULL);
266 options,
267 &get_msg->header,
268 timeout,
269 &get_reply_iterator, get_handle,
270 NULL, NULL);
271 GNUNET_break (NULL != get_handle->route_handle); 264 GNUNET_break (NULL != get_handle->route_handle);
272 return get_handle; 265 return get_handle;
273} 266}
diff --git a/src/dht/dhtlog.c b/src/dht/dhtlog.c
index 7d66fb87c..7b9c05268 100644
--- a/src/dht/dhtlog.c
+++ b/src/dht/dhtlog.c
@@ -47,26 +47,26 @@ GNUNET_DHTLOG_connect (const struct GNUNET_CONFIGURATION_Handle *c)
47 struct GNUNET_DHTLOG_Handle *api; 47 struct GNUNET_DHTLOG_Handle *api;
48 char *plugin_name; 48 char *plugin_name;
49 49
50 plugin = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Plugin)); 50 plugin = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Plugin));
51 plugin->cfg = c; 51 plugin->cfg = c;
52 if (GNUNET_OK == 52 if (GNUNET_OK ==
53 GNUNET_CONFIGURATION_get_value_string (c, 53 GNUNET_CONFIGURATION_get_value_string (c,
54 "DHTLOG", "PLUGIN", &plugin_name)) 54 "DHTLOG", "PLUGIN", &plugin_name))
55 { 55 {
56 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 56 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
57 _("Loading `%s' dhtlog plugin\n"), plugin_name); 57 _("Loading `%s' dhtlog plugin\n"), plugin_name);
58 GNUNET_asprintf (&libname, "libgnunet_plugin_dhtlog_%s", plugin_name); 58 GNUNET_asprintf (&libname, "libgnunet_plugin_dhtlog_%s", plugin_name);
59 GNUNET_PLUGIN_load (libname, plugin); 59 GNUNET_PLUGIN_load (libname, plugin);
60 } 60 }
61 61
62 if (plugin->dhtlog_api == NULL) 62 if (plugin->dhtlog_api == NULL)
63 { 63 {
64 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 64 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
65 _("Failed to load dhtlog plugin for `%s'\n"), plugin_name); 65 _("Failed to load dhtlog plugin for `%s'\n"), plugin_name);
66 GNUNET_free (plugin_name); 66 GNUNET_free (plugin_name);
67 GNUNET_free (plugin); 67 GNUNET_free (plugin);
68 return NULL; 68 return NULL;
69 } 69 }
70 70
71 api = plugin->dhtlog_api; 71 api = plugin->dhtlog_api;
72 GNUNET_free (plugin_name); 72 GNUNET_free (plugin_name);
@@ -81,14 +81,13 @@ void
81GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api) 81GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api)
82{ 82{
83#if DEBUG_DHTLOG 83#if DEBUG_DHTLOG
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database shutdown\n");
85 "MySQL DHT Logger: database shutdown\n");
86#endif 85#endif
87 if (api != NULL) 86 if (api != NULL)
88 { 87 {
89 GNUNET_PLUGIN_unload(libname, api); 88 GNUNET_PLUGIN_unload (libname, api);
90 } 89 }
91 GNUNET_free_non_null(libname); 90 GNUNET_free_non_null (libname);
92} 91}
93 92
94/* end of dhtlog.c */ 93/* end of dhtlog.c */
diff --git a/src/dht/dhtlog.h b/src/dht/dhtlog.h
index c86d98ee2..6a8a6f1bb 100644
--- a/src/dht/dhtlog.h
+++ b/src/dht/dhtlog.h
@@ -178,7 +178,7 @@ struct GNUNET_DHTLOG_Handle
178 * 178 *
179 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 179 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
180 */ 180 */
181 int (*insert_trial) (struct GNUNET_DHTLOG_TrialInfo *trial_info); 181 int (*insert_trial) (struct GNUNET_DHTLOG_TrialInfo * trial_info);
182 182
183 /* 183 /*
184 * Inserts the specified stats into the dhttests.node_statistics table 184 * Inserts the specified stats into the dhttests.node_statistics table
@@ -204,15 +204,15 @@ struct GNUNET_DHTLOG_Handle
204 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 204 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
205 */ 205 */
206 int (*insert_stat) 206 int (*insert_stat)
207 (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests, 207 (const struct GNUNET_PeerIdentity * peer, unsigned int route_requests,
208 unsigned int route_forwards, unsigned int result_requests, 208 unsigned int route_forwards, unsigned int result_requests,
209 unsigned int client_requests, unsigned int result_forwards, 209 unsigned int client_requests, unsigned int result_forwards,
210 unsigned int gets, unsigned int puts, 210 unsigned int gets, unsigned int puts,
211 unsigned int data_inserts, unsigned int find_peer_requests, 211 unsigned int data_inserts, unsigned int find_peer_requests,
212 unsigned int find_peers_started, unsigned int gets_started, 212 unsigned int find_peers_started, unsigned int gets_started,
213 unsigned int puts_started, unsigned int find_peer_responses_received, 213 unsigned int puts_started, unsigned int find_peer_responses_received,
214 unsigned int get_responses_received, unsigned int find_peer_responses_sent, 214 unsigned int get_responses_received,
215 unsigned int get_responses_sent); 215 unsigned int find_peer_responses_sent, unsigned int get_responses_sent);
216 216
217 /* 217 /*
218 * Update dhttests.trials table with current server time as end time 218 * Update dhttests.trials table with current server time as end time
@@ -231,7 +231,7 @@ struct GNUNET_DHTLOG_Handle
231 * 231 *
232 * @return GNUNET_OK on success, GNUNET_SYSERR on failure. 232 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
233 */ 233 */
234 int (*set_malicious) (struct GNUNET_PeerIdentity *peer); 234 int (*set_malicious) (struct GNUNET_PeerIdentity * peer);
235 235
236 /* 236 /*
237 * Records the current topology (number of connections, time, trial) 237 * Records the current topology (number of connections, time, trial)
@@ -250,7 +250,8 @@ struct GNUNET_DHTLOG_Handle
250 * 250 *
251 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 251 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
252 */ 252 */
253 int (*insert_extended_topology) (const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second); 253 int (*insert_extended_topology) (const struct GNUNET_PeerIdentity * first,
254 const struct GNUNET_PeerIdentity * second);
254 255
255 /* 256 /*
256 * Inserts the specified stats into the dhttests.generic_stats table 257 * Inserts the specified stats into the dhttests.generic_stats table
@@ -262,10 +263,9 @@ struct GNUNET_DHTLOG_Handle
262 * 263 *
263 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 264 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
264 */ 265 */
265 int 266 int (*add_generic_stat) (const struct GNUNET_PeerIdentity * peer,
266 (*add_generic_stat) (const struct GNUNET_PeerIdentity *peer, 267 const char *name,
267 const char *name, 268 const char *section, uint64_t value);
268 const char *section, uint64_t value);
269 269
270 /* 270 /*
271 * Inserts the specified round into the dhttests.rounds table 271 * Inserts the specified round into the dhttests.rounds table
@@ -288,8 +288,10 @@ struct GNUNET_DHTLOG_Handle
288 * 288 *
289 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 289 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
290 */ 290 */
291 int (*insert_round_details) (unsigned int round_type, unsigned int round_count, 291 int (*insert_round_details) (unsigned int round_type,
292 unsigned int num_messages, unsigned int num_messages_succeeded); 292 unsigned int round_count,
293 unsigned int num_messages,
294 unsigned int num_messages_succeeded);
293 295
294 /* 296 /*
295 * Update dhttests.trials table with total connections information 297 * Update dhttests.trials table with total connections information
@@ -371,14 +373,14 @@ struct GNUNET_DHTLOG_Plugin
371 * 373 *
372 * @param c a configuration to use 374 * @param c a configuration to use
373 */ 375 */
374struct GNUNET_DHTLOG_Handle * 376struct GNUNET_DHTLOG_Handle *GNUNET_DHTLOG_connect (const struct
375GNUNET_DHTLOG_connect (const struct GNUNET_CONFIGURATION_Handle *c); 377 GNUNET_CONFIGURATION_Handle
378 *c);
376 379
377/** 380/**
378 * Shutdown the module. 381 * Shutdown the module.
379 */ 382 */
380void 383void GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api);
381GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api);
382 384
383 385
384#if 0 /* keep Emacsens' auto-indent happy */ 386#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c
index 6039e196b..a5158fba5 100644
--- a/src/dht/gnunet-dht-driver.c
+++ b/src/dht/gnunet-dht-driver.c
@@ -778,11 +778,9 @@ static char *blacklist_transports;
778 778
779static enum GNUNET_TESTING_Topology topology; 779static enum GNUNET_TESTING_Topology topology;
780 780
781static enum GNUNET_TESTING_Topology blacklist_topology = 781static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
782 GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
783 782
784static enum GNUNET_TESTING_Topology connect_topology = 783static enum GNUNET_TESTING_Topology connect_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
785 GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
786 784
787static enum GNUNET_TESTING_TopologyOption connect_topology_option = 785static enum GNUNET_TESTING_TopologyOption connect_topology_option =
788 GNUNET_TESTING_TOPOLOGY_OPTION_ALL; 786 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
@@ -815,18 +813,19 @@ static int ok;
815 * @return the progress meter 813 * @return the progress meter
816 */ 814 */
817static struct ProgressMeter * 815static struct ProgressMeter *
818create_meter(unsigned int total, char * start_string, int print) 816create_meter (unsigned int total, char *start_string, int print)
819{ 817{
820 struct ProgressMeter *ret; 818 struct ProgressMeter *ret;
821 ret = GNUNET_malloc(sizeof(struct ProgressMeter)); 819
820 ret = GNUNET_malloc (sizeof (struct ProgressMeter));
822 ret->print = print; 821 ret->print = print;
823 ret->total = total; 822 ret->total = total;
824 ret->modnum = total / 4; 823 ret->modnum = total / 4;
825 ret->dotnum = (total / 50) + 1; 824 ret->dotnum = (total / 50) + 1;
826 if (start_string != NULL) 825 if (start_string != NULL)
827 ret->startup_string = GNUNET_strdup(start_string); 826 ret->startup_string = GNUNET_strdup (start_string);
828 else 827 else
829 ret->startup_string = GNUNET_strdup(""); 828 ret->startup_string = GNUNET_strdup ("");
830 829
831 return ret; 830 return ret;
832} 831}
@@ -840,27 +839,27 @@ create_meter(unsigned int total, char * start_string, int print)
840 * GNUNET_NO if more items expected 839 * GNUNET_NO if more items expected
841 */ 840 */
842static int 841static int
843update_meter(struct ProgressMeter *meter) 842update_meter (struct ProgressMeter *meter)
844{ 843{
845 if (meter->print == GNUNET_YES) 844 if (meter->print == GNUNET_YES)
845 {
846 if (meter->completed % meter->modnum == 0)
846 { 847 {
847 if (meter->completed % meter->modnum == 0) 848 if (meter->completed == 0)
848 { 849 {
849 if (meter->completed == 0) 850 fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
850 { 851 }
851 fprintf (stdout, "%sProgress: [0%%", meter->startup_string); 852 else
852 } 853 fprintf (stdout, "%d%%", (int) (((float) meter->completed
853 else 854 / meter->total) * 100));
854 fprintf (stdout, "%d%%", (int) (((float) meter->completed
855 / meter->total) * 100));
856 }
857 else if (meter->completed % meter->dotnum == 0)
858 fprintf (stdout, ".");
859
860 if (meter->completed + 1 == meter->total)
861 fprintf (stdout, "%d%%]\n", 100);
862 fflush (stdout);
863 } 855 }
856 else if (meter->completed % meter->dotnum == 0)
857 fprintf (stdout, ".");
858
859 if (meter->completed + 1 == meter->total)
860 fprintf (stdout, "%d%%]\n", 100);
861 fflush (stdout);
862 }
864 meter->completed++; 863 meter->completed++;
865 864
866 if (meter->completed == meter->total) 865 if (meter->completed == meter->total)
@@ -877,7 +876,7 @@ update_meter(struct ProgressMeter *meter)
877 * GNUNET_SYSERR on error 876 * GNUNET_SYSERR on error
878 */ 877 */
879static int 878static int
880reset_meter(struct ProgressMeter *meter) 879reset_meter (struct ProgressMeter *meter)
881{ 880{
882 if (meter == NULL) 881 if (meter == NULL)
883 return GNUNET_SYSERR; 882 return GNUNET_SYSERR;
@@ -892,7 +891,7 @@ reset_meter(struct ProgressMeter *meter)
892 * @param meter the meter to free 891 * @param meter the meter to free
893 */ 892 */
894static void 893static void
895free_meter(struct ProgressMeter *meter) 894free_meter (struct ProgressMeter *meter)
896{ 895{
897 GNUNET_free_non_null (meter->startup_string); 896 GNUNET_free_non_null (meter->startup_string);
898 GNUNET_free (meter); 897 GNUNET_free (meter);
@@ -902,32 +901,31 @@ free_meter(struct ProgressMeter *meter)
902 * Check whether peers successfully shut down. 901 * Check whether peers successfully shut down.
903 */ 902 */
904static void 903static void
905shutdown_callback(void *cls, const char *emsg) 904shutdown_callback (void *cls, const char *emsg)
906{ 905{
907 if (emsg != NULL) 906 if (emsg != NULL)
908 { 907 {
909 if (ok == 0) 908 if (ok == 0)
910 ok = 2; 909 ok = 2;
911 } 910 }
912} 911}
913 912
914/** 913/**
915 * Task to release DHT handles for PUT 914 * Task to release DHT handles for PUT
916 */ 915 */
917static void 916static void
918put_disconnect_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 917put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
919{ 918{
920 struct TestPutContext *test_put = cls; 919 struct TestPutContext *test_put = cls;
920
921 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 921 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
922 GNUNET_DHT_disconnect (test_put->dht_handle); 922 GNUNET_DHT_disconnect (test_put->dht_handle);
923 test_put->dht_handle = NULL; 923 test_put->dht_handle = NULL;
924 if (replicate_same == GNUNET_NO) 924 if (replicate_same == GNUNET_NO)
925 test_put->daemon 925 test_put->daemon
926 = GNUNET_TESTING_daemon_get ( 926 = GNUNET_TESTING_daemon_get (pg,
927 pg, 927 GNUNET_CRYPTO_random_u32
928 GNUNET_CRYPTO_random_u32 ( 928 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
929 GNUNET_CRYPTO_QUALITY_WEAK,
930 num_peers));
931} 929}
932 930
933/** 931/**
@@ -935,7 +933,7 @@ put_disconnect_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
935 * testcase. 933 * testcase.
936 */ 934 */
937static void 935static void
938finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 936finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
939{ 937{
940 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending test normally!\n", 938 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending test normally!\n",
941 (char *) cls); 939 (char *) cls);
@@ -946,34 +944,34 @@ finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
946 char *revision_str; 944 char *revision_str;
947 945
948 while (test_put != NULL) 946 while (test_put != NULL)
949 { 947 {
950 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 948 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
951 GNUNET_SCHEDULER_cancel (test_put->disconnect_task); 949 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
952 if (test_put->dht_handle != NULL) 950 if (test_put->dht_handle != NULL)
953 GNUNET_DHT_disconnect (test_put->dht_handle); 951 GNUNET_DHT_disconnect (test_put->dht_handle);
954 test_put = test_put->next; 952 test_put = test_put->next;
955 } 953 }
956 954
957 while (test_get != NULL) 955 while (test_get != NULL)
958 { 956 {
959 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 957 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
960 GNUNET_SCHEDULER_cancel (test_get->disconnect_task); 958 GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
961 if (test_get->get_handle != NULL) 959 if (test_get->get_handle != NULL)
962 GNUNET_DHT_get_stop (test_get->get_handle); 960 GNUNET_DHT_get_stop (test_get->get_handle);
963 if (test_get->dht_handle != NULL) 961 if (test_get->dht_handle != NULL)
964 GNUNET_DHT_disconnect (test_get->dht_handle); 962 GNUNET_DHT_disconnect (test_get->dht_handle);
965 test_get = test_get->next; 963 test_get = test_get->next;
966 } 964 }
967 965
968 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL); 966 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
969 967
970 if (dhtlog_handle != NULL) 968 if (dhtlog_handle != NULL)
971 { 969 {
972 fprintf (stderr, "Update trial endtime\n"); 970 fprintf (stderr, "Update trial endtime\n");
973 dhtlog_handle->update_trial (cumulative_successful_gets); 971 dhtlog_handle->update_trial (cumulative_successful_gets);
974 GNUNET_DHTLOG_disconnect (dhtlog_handle); 972 GNUNET_DHTLOG_disconnect (dhtlog_handle);
975 dhtlog_handle = NULL; 973 dhtlog_handle = NULL;
976 } 974 }
977 975
978 if (hostkey_meter != NULL) 976 if (hostkey_meter != NULL)
979 free_meter (hostkey_meter); 977 free_meter (hostkey_meter);
@@ -989,13 +987,14 @@ finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
989 GNUNET_asprintf (&temp_get_string, "DHT Successful GETs", trial_to_run); 987 GNUNET_asprintf (&temp_get_string, "DHT Successful GETs", trial_to_run);
990 GNUNET_asprintf (&revision_str, "%llu", revision); 988 GNUNET_asprintf (&revision_str, "%llu", revision);
991 if (GNUNET_YES == insert_gauger_data) 989 if (GNUNET_YES == insert_gauger_data)
992 GAUGER_ID("DHT_TESTING", temp_get_string, cumulative_successful_gets / (double)cumulative_num_gets, "percent successful", revision_str); 990 GAUGER_ID ("DHT_TESTING", temp_get_string,
993 fprintf ( 991 cumulative_successful_gets / (double) cumulative_num_gets,
994 stderr, 992 "percent successful", revision_str);
993 fprintf (stderr,
995 "Finished trial, had %llu successful gets out of %llu total, %.2f percent succeeded\n", 994 "Finished trial, had %llu successful gets out of %llu total, %.2f percent succeeded\n",
996 cumulative_successful_gets, cumulative_num_gets, 995 cumulative_successful_gets, cumulative_num_gets,
997 cumulative_successful_gets / (double) cumulative_num_gets); 996 cumulative_successful_gets / (double) cumulative_num_gets);
998 GNUNET_free(temp_get_string); 997 GNUNET_free (temp_get_string);
999 998
1000 ok = 0; 999 ok = 0;
1001} 1000}
@@ -1004,40 +1003,42 @@ finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1004 * Callback for iterating over all the peer connections of a peer group. 1003 * Callback for iterating over all the peer connections of a peer group.
1005 */ 1004 */
1006static void 1005static void
1007log_topology_cb(void *cls, const struct GNUNET_PeerIdentity *first, 1006log_topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
1008 const struct GNUNET_PeerIdentity *second, const char *emsg) 1007 const struct GNUNET_PeerIdentity *second, const char *emsg)
1009{ 1008{
1010 struct TopologyIteratorContext *topo_ctx = cls; 1009 struct TopologyIteratorContext *topo_ctx = cls;
1010
1011 if ((first != NULL) && (second != NULL)) 1011 if ((first != NULL) && (second != NULL))
1012 {
1013 if ((topo_ctx->peers_seen != NULL) && (GNUNET_NO
1014 ==
1015 GNUNET_CONTAINER_multihashmap_contains
1016 (topo_ctx->peers_seen,
1017 &first->hashPubKey)))
1012 { 1018 {
1013 if ((topo_ctx->peers_seen != NULL) && (GNUNET_NO 1019 GNUNET_CONTAINER_multihashmap_put (topo_ctx->peers_seen,
1014 == GNUNET_CONTAINER_multihashmap_contains (topo_ctx->peers_seen, 1020 &first->hashPubKey, NULL,
1015 &first->hashPubKey))) 1021 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1016 { 1022 topo_ctx->total_peers++;
1017 GNUNET_CONTAINER_multihashmap_put (topo_ctx->peers_seen,
1018 &first->hashPubKey, NULL,
1019 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1020 topo_ctx->total_peers++;
1021 }
1022 topo_ctx->total_connections++;
1023 if ((GNUNET_NO == dhtlog_minimal) && (dhtlog_handle != NULL))
1024 dhtlog_handle->insert_extended_topology (first, second);
1025 } 1023 }
1024 topo_ctx->total_connections++;
1025 if ((GNUNET_NO == dhtlog_minimal) && (dhtlog_handle != NULL))
1026 dhtlog_handle->insert_extended_topology (first, second);
1027 }
1026 else 1028 else
1027 { 1029 {
1028 GNUNET_assert(dhtlog_handle != NULL); 1030 GNUNET_assert (dhtlog_handle != NULL);
1029 GNUNET_log ( 1031 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1030 GNUNET_ERROR_TYPE_WARNING, 1032 "Topology iteration (%u/%u) finished (%u connections, %u peers)\n",
1031 "Topology iteration (%u/%u) finished (%u connections, %u peers)\n", 1033 topo_ctx->current_iteration, topo_ctx->total_iterations,
1032 topo_ctx->current_iteration, topo_ctx->total_iterations, 1034 topo_ctx->total_connections, topo_ctx->total_peers);
1033 topo_ctx->total_connections, topo_ctx->total_peers); 1035 dhtlog_handle->update_topology (topo_ctx->total_connections);
1034 dhtlog_handle->update_topology (topo_ctx->total_connections); 1036 if (topo_ctx->cont != NULL)
1035 if (topo_ctx->cont != NULL) 1037 GNUNET_SCHEDULER_add_now (topo_ctx->cont, topo_ctx->cls);
1036 GNUNET_SCHEDULER_add_now (topo_ctx->cont, topo_ctx->cls); 1038 if (topo_ctx->peers_seen != NULL)
1037 if (topo_ctx->peers_seen != NULL) 1039 GNUNET_CONTAINER_multihashmap_destroy (topo_ctx->peers_seen);
1038 GNUNET_CONTAINER_multihashmap_destroy (topo_ctx->peers_seen); 1040 GNUNET_free (topo_ctx);
1039 GNUNET_free(topo_ctx); 1041 }
1040 }
1041} 1042}
1042 1043
1043/** 1044/**
@@ -1051,9 +1052,10 @@ log_topology_cb(void *cls, const struct GNUNET_PeerIdentity *first,
1051 * GNUNET_NO if not. 1052 * GNUNET_NO if not.
1052 */ 1053 */
1053static int 1054static int
1054stats_iterate(void *cls, const GNUNET_HashCode * key, void *value) 1055stats_iterate (void *cls, const GNUNET_HashCode * key, void *value)
1055{ 1056{
1056 struct StatisticsIteratorContext *stats_ctx; 1057 struct StatisticsIteratorContext *stats_ctx;
1058
1057 if (value == NULL) 1059 if (value == NULL)
1058 return GNUNET_NO; 1060 return GNUNET_NO;
1059 stats_ctx = value; 1061 stats_ctx = value;
@@ -1072,12 +1074,12 @@ stats_iterate(void *cls, const GNUNET_HashCode * key, void *value)
1072 stats_ctx->stat_get_reply, 1074 stats_ctx->stat_get_reply,
1073 stats_ctx->stat_find_peer_answer, 1075 stats_ctx->stat_find_peer_answer,
1074 stats_ctx->stat_get_response_start); 1076 stats_ctx->stat_get_response_start);
1075 GNUNET_free(stats_ctx); 1077 GNUNET_free (stats_ctx);
1076 return GNUNET_YES; 1078 return GNUNET_YES;
1077} 1079}
1078 1080
1079static void 1081static void
1080stats_finished(void *cls, int result) 1082stats_finished (void *cls, int result)
1081{ 1083{
1082 fprintf (stderr, "Finished getting all peers statistics, iterating!\n"); 1084 fprintf (stderr, "Finished getting all peers statistics, iterating!\n");
1083 GNUNET_CONTAINER_multihashmap_iterate (stats_map, &stats_iterate, NULL); 1085 GNUNET_CONTAINER_multihashmap_iterate (stats_map, &stats_iterate, NULL);
@@ -1097,28 +1099,28 @@ stats_finished(void *cls, int result)
1097 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 1099 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1098 */ 1100 */
1099static int 1101static int
1100stats_handle(void *cls, const struct GNUNET_PeerIdentity *peer, 1102stats_handle (void *cls, const struct GNUNET_PeerIdentity *peer,
1101 const char *subsystem, const char *name, uint64_t value, 1103 const char *subsystem, const char *name, uint64_t value,
1102 int is_persistent) 1104 int is_persistent)
1103{ 1105{
1104 struct StatisticsIteratorContext *stats_ctx; 1106 struct StatisticsIteratorContext *stats_ctx;
1105 1107
1106 if (dhtlog_handle != NULL) 1108 if (dhtlog_handle != NULL)
1107 dhtlog_handle->add_generic_stat (peer, name, subsystem, value); 1109 dhtlog_handle->add_generic_stat (peer, name, subsystem, value);
1108 if (GNUNET_CONTAINER_multihashmap_contains (stats_map, &peer->hashPubKey)) 1110 if (GNUNET_CONTAINER_multihashmap_contains (stats_map, &peer->hashPubKey))
1109 { 1111 {
1110 stats_ctx = GNUNET_CONTAINER_multihashmap_get (stats_map, 1112 stats_ctx = GNUNET_CONTAINER_multihashmap_get (stats_map,
1111 &peer->hashPubKey); 1113 &peer->hashPubKey);
1112 } 1114 }
1113 else 1115 else
1114 { 1116 {
1115 stats_ctx = GNUNET_malloc(sizeof(struct StatisticsIteratorContext)); 1117 stats_ctx = GNUNET_malloc (sizeof (struct StatisticsIteratorContext));
1116 stats_ctx->peer = peer; 1118 stats_ctx->peer = peer;
1117 GNUNET_CONTAINER_multihashmap_put (stats_map, &peer->hashPubKey, 1119 GNUNET_CONTAINER_multihashmap_put (stats_map, &peer->hashPubKey,
1118 stats_ctx, 1120 stats_ctx,
1119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1121 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1120 } 1122 }
1121 GNUNET_assert(stats_ctx != NULL); 1123 GNUNET_assert (stats_ctx != NULL);
1122 1124
1123 if (strcmp (name, STAT_ROUTES) == 0) 1125 if (strcmp (name, STAT_ROUTES) == 0)
1124 stats_ctx->stat_routes = value; 1126 stats_ctx->stat_routes = value;
@@ -1161,7 +1163,7 @@ stats_handle(void *cls, const struct GNUNET_PeerIdentity *peer,
1161 * dht statistics for safe keeping. 1163 * dht statistics for safe keeping.
1162 */ 1164 */
1163static void 1165static void
1164log_dht_statistics(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 1166log_dht_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1165{ 1167{
1166 stats_map = GNUNET_CONTAINER_multihashmap_create (num_peers); 1168 stats_map = GNUNET_CONTAINER_multihashmap_create (num_peers);
1167 fprintf (stderr, "Starting statistics logging\n"); 1169 fprintf (stderr, "Starting statistics logging\n");
@@ -1173,10 +1175,11 @@ log_dht_statistics(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1173 * connections. 1175 * connections.
1174 */ 1176 */
1175static void 1177static void
1176capture_current_topology(void *cls, 1178capture_current_topology (void *cls,
1177 const struct GNUNET_SCHEDULER_TaskContext * tc) 1179 const struct GNUNET_SCHEDULER_TaskContext *tc)
1178{ 1180{
1179 struct TopologyIteratorContext *topo_ctx = cls; 1181 struct TopologyIteratorContext *topo_ctx = cls;
1182
1180 dhtlog_handle->insert_topology (0); 1183 dhtlog_handle->insert_topology (0);
1181 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Called capture_current_topology\n"); 1184 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Called capture_current_topology\n");
1182 GNUNET_TESTING_get_topology (pg, &log_topology_cb, topo_ctx); 1185 GNUNET_TESTING_get_topology (pg, &log_topology_cb, topo_ctx);
@@ -1188,7 +1191,7 @@ capture_current_topology(void *cls,
1188 * test. 1191 * test.
1189 */ 1192 */
1190static void 1193static void
1191end_badly(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 1194end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1192{ 1195{
1193 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing test with error: `%s'!\n", 1196 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing test with error: `%s'!\n",
1194 (char *) cls); 1197 (char *) cls);
@@ -1197,34 +1200,34 @@ end_badly(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1197 struct TestGetContext *test_get = all_gets; 1200 struct TestGetContext *test_get = all_gets;
1198 1201
1199 while (test_put != NULL) 1202 while (test_put != NULL)
1200 { 1203 {
1201 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 1204 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
1202 GNUNET_SCHEDULER_cancel (test_put->disconnect_task); 1205 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
1203 if (test_put->dht_handle != NULL) 1206 if (test_put->dht_handle != NULL)
1204 GNUNET_DHT_disconnect (test_put->dht_handle); 1207 GNUNET_DHT_disconnect (test_put->dht_handle);
1205 test_put = test_put->next; 1208 test_put = test_put->next;
1206 } 1209 }
1207 1210
1208 while (test_get != NULL) 1211 while (test_get != NULL)
1209 { 1212 {
1210 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 1213 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
1211 GNUNET_SCHEDULER_cancel (test_get->disconnect_task); 1214 GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
1212 if (test_get->get_handle != NULL) 1215 if (test_get->get_handle != NULL)
1213 GNUNET_DHT_get_stop (test_get->get_handle); 1216 GNUNET_DHT_get_stop (test_get->get_handle);
1214 if (test_get->dht_handle != NULL) 1217 if (test_get->dht_handle != NULL)
1215 GNUNET_DHT_disconnect (test_get->dht_handle); 1218 GNUNET_DHT_disconnect (test_get->dht_handle);
1216 test_get = test_get->next; 1219 test_get = test_get->next;
1217 } 1220 }
1218 1221
1219 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL); 1222 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
1220 1223
1221 if (dhtlog_handle != NULL) 1224 if (dhtlog_handle != NULL)
1222 { 1225 {
1223 fprintf (stderr, "Update trial endtime\n"); 1226 fprintf (stderr, "Update trial endtime\n");
1224 dhtlog_handle->update_trial (gets_completed); 1227 dhtlog_handle->update_trial (gets_completed);
1225 GNUNET_DHTLOG_disconnect (dhtlog_handle); 1228 GNUNET_DHTLOG_disconnect (dhtlog_handle);
1226 dhtlog_handle = NULL; 1229 dhtlog_handle = NULL;
1227 } 1230 }
1228 1231
1229 if (hostkey_meter != NULL) 1232 if (hostkey_meter != NULL)
1230 free_meter (hostkey_meter); 1233 free_meter (hostkey_meter);
@@ -1243,14 +1246,12 @@ end_badly(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1243/** 1246/**
1244 * Forward declaration. 1247 * Forward declaration.
1245 */ 1248 */
1246static void 1249static void do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1247do_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
1248 1250
1249/** 1251/**
1250 * Forward declaration. 1252 * Forward declaration.
1251 */ 1253 */
1252static void 1254static void do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1253do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
1254 1255
1255/** 1256/**
1256 * Iterator over hash map entries. 1257 * Iterator over hash map entries.
@@ -1263,11 +1264,12 @@ do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
1263 * GNUNET_NO if not. 1264 * GNUNET_NO if not.
1264 */ 1265 */
1265static int 1266static int
1266remove_peer_count(void *cls, const GNUNET_HashCode * key, void *value) 1267remove_peer_count (void *cls, const GNUNET_HashCode * key, void *value)
1267{ 1268{
1268 struct PeerCount *peer_count = value; 1269 struct PeerCount *peer_count = value;
1270
1269 GNUNET_CONTAINER_heap_remove_node (peer_count->heap_node); 1271 GNUNET_CONTAINER_heap_remove_node (peer_count->heap_node);
1270 GNUNET_free(peer_count); 1272 GNUNET_free (peer_count);
1271 1273
1272 return GNUNET_YES; 1274 return GNUNET_YES;
1273} 1275}
@@ -1277,9 +1279,10 @@ remove_peer_count(void *cls, const GNUNET_HashCode * key, void *value)
1277 * connections. 1279 * connections.
1278 */ 1280 */
1279static void 1281static void
1280count_new_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 1282count_new_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1281{ 1283{
1282 struct FindPeerContext *find_peer_context = cls; 1284 struct FindPeerContext *find_peer_context = cls;
1285
1283 find_peer_context->previous_peers = find_peer_context->current_peers; 1286 find_peer_context->previous_peers = find_peer_context->current_peers;
1284 find_peer_context->current_peers = 0; 1287 find_peer_context->current_peers = 0;
1285 GNUNET_TESTING_get_topology (pg, find_peer_context->count_peers_cb, 1288 GNUNET_TESTING_get_topology (pg, find_peer_context->count_peers_cb,
@@ -1287,18 +1290,19 @@ count_new_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1287} 1290}
1288 1291
1289static void 1292static void
1290decrement_find_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 1293decrement_find_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1291{ 1294{
1292 struct TestFindPeer *test_find_peer = cls; 1295 struct TestFindPeer *test_find_peer = cls;
1293 GNUNET_assert(test_find_peer->find_peer_context->outstanding > 0); 1296
1297 GNUNET_assert (test_find_peer->find_peer_context->outstanding > 0);
1294 test_find_peer->find_peer_context->outstanding--; 1298 test_find_peer->find_peer_context->outstanding--;
1295 test_find_peer->find_peer_context->total--; 1299 test_find_peer->find_peer_context->total--;
1296 if (0 == test_find_peer->find_peer_context->total) 1300 if (0 == test_find_peer->find_peer_context->total)
1297 { 1301 {
1298 GNUNET_SCHEDULER_add_now (&count_new_peers, 1302 GNUNET_SCHEDULER_add_now (&count_new_peers,
1299 test_find_peer->find_peer_context); 1303 test_find_peer->find_peer_context);
1300 } 1304 }
1301 GNUNET_free(test_find_peer); 1305 GNUNET_free (test_find_peer);
1302} 1306}
1303 1307
1304/** 1308/**
@@ -1309,42 +1313,41 @@ decrement_find_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1309 * @param tc context the task is being called with 1313 * @param tc context the task is being called with
1310 */ 1314 */
1311static void 1315static void
1312handle_find_peer_sent(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 1316handle_find_peer_sent (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1313{ 1317{
1314 struct TestFindPeer *test_find_peer = cls; 1318 struct TestFindPeer *test_find_peer = cls;
1315 1319
1316 GNUNET_DHT_disconnect (test_find_peer->dht_handle); 1320 GNUNET_DHT_disconnect (test_find_peer->dht_handle);
1317 GNUNET_SCHEDULER_add_delayed ( 1321 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
1318 GNUNET_TIME_relative_divide (find_peer_delay, 2), 1322 (find_peer_delay, 2), &decrement_find_peers,
1319 &decrement_find_peers, test_find_peer); 1323 test_find_peer);
1320} 1324}
1321 1325
1322static void 1326static void
1323send_find_peer_request(void *cls, 1327send_find_peer_request (void *cls,
1324 const struct GNUNET_SCHEDULER_TaskContext * tc) 1328 const struct GNUNET_SCHEDULER_TaskContext *tc)
1325{ 1329{
1326 struct TestFindPeer *test_find_peer = cls; 1330 struct TestFindPeer *test_find_peer = cls;
1327 1331
1328 if (test_find_peer->find_peer_context->outstanding 1332 if (test_find_peer->find_peer_context->outstanding
1329 > max_outstanding_find_peers) 1333 > max_outstanding_find_peers)
1330 { 1334 {
1331 GNUNET_SCHEDULER_add_delayed (find_peer_offset, &send_find_peer_request, 1335 GNUNET_SCHEDULER_add_delayed (find_peer_offset, &send_find_peer_request,
1332 test_find_peer); 1336 test_find_peer);
1333 return; 1337 return;
1334 } 1338 }
1335 1339
1336 test_find_peer->find_peer_context->outstanding++; 1340 test_find_peer->find_peer_context->outstanding++;
1337 if (GNUNET_TIME_absolute_get_remaining ( 1341 if (GNUNET_TIME_absolute_get_remaining
1338 test_find_peer->find_peer_context->endtime).rel_value 1342 (test_find_peer->find_peer_context->endtime).rel_value == 0)
1339 == 0) 1343 {
1340 { 1344 GNUNET_SCHEDULER_add_now (&decrement_find_peers, test_find_peer);
1341 GNUNET_SCHEDULER_add_now (&decrement_find_peers, test_find_peer); 1345 return;
1342 return; 1346 }
1343 }
1344 1347
1345 test_find_peer->dht_handle = GNUNET_DHT_connect (test_find_peer->daemon->cfg, 1348 test_find_peer->dht_handle = GNUNET_DHT_connect (test_find_peer->daemon->cfg,
1346 1); 1349 1);
1347 GNUNET_assert(test_find_peer->dht_handle != NULL); 1350 GNUNET_assert (test_find_peer->dht_handle != NULL);
1348 GNUNET_DHT_find_peers (test_find_peer->dht_handle, &handle_find_peer_sent, 1351 GNUNET_DHT_find_peers (test_find_peer->dht_handle, &handle_find_peer_sent,
1349 test_find_peer); 1352 test_find_peer);
1350} 1353}
@@ -1355,63 +1358,63 @@ send_find_peer_request(void *cls,
1355 * the least connections to initiate find peer requests from. 1358 * the least connections to initiate find peer requests from.
1356 */ 1359 */
1357static void 1360static void
1358add_new_connection(struct FindPeerContext *find_peer_context, 1361add_new_connection (struct FindPeerContext *find_peer_context,
1359 const struct GNUNET_PeerIdentity *first, 1362 const struct GNUNET_PeerIdentity *first,
1360 const struct GNUNET_PeerIdentity *second) 1363 const struct GNUNET_PeerIdentity *second)
1361{ 1364{
1362 struct PeerCount *first_count; 1365 struct PeerCount *first_count;
1363 struct PeerCount *second_count; 1366 struct PeerCount *second_count;
1364 1367
1365 if (GNUNET_CONTAINER_multihashmap_contains (find_peer_context->peer_hash, 1368 if (GNUNET_CONTAINER_multihashmap_contains (find_peer_context->peer_hash,
1366 &first->hashPubKey)) 1369 &first->hashPubKey))
1367 { 1370 {
1368 first_count 1371 first_count
1369 = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash, 1372 = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash,
1370 &first->hashPubKey); 1373 &first->hashPubKey);
1371 GNUNET_assert(first_count != NULL); 1374 GNUNET_assert (first_count != NULL);
1372 first_count->count++; 1375 first_count->count++;
1373 GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap, 1376 GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap,
1374 first_count->heap_node, 1377 first_count->heap_node,
1375 first_count->count); 1378 first_count->count);
1376 } 1379 }
1377 else 1380 else
1378 { 1381 {
1379 first_count = GNUNET_malloc(sizeof(struct PeerCount)); 1382 first_count = GNUNET_malloc (sizeof (struct PeerCount));
1380 first_count->count = 1; 1383 first_count->count = 1;
1381 memcpy (&first_count->peer_id, first, sizeof(struct GNUNET_PeerIdentity)); 1384 memcpy (&first_count->peer_id, first, sizeof (struct GNUNET_PeerIdentity));
1382 first_count->heap_node 1385 first_count->heap_node
1383 = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap, 1386 = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
1384 first_count, first_count->count); 1387 first_count, first_count->count);
1385 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash, 1388 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
1386 &first->hashPubKey, first_count, 1389 &first->hashPubKey, first_count,
1387 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1390 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1388 } 1391 }
1389 1392
1390 if (GNUNET_CONTAINER_multihashmap_contains (find_peer_context->peer_hash, 1393 if (GNUNET_CONTAINER_multihashmap_contains (find_peer_context->peer_hash,
1391 &second->hashPubKey)) 1394 &second->hashPubKey))
1392 { 1395 {
1393 second_count 1396 second_count
1394 = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash, 1397 = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash,
1395 &second->hashPubKey); 1398 &second->hashPubKey);
1396 GNUNET_assert(second_count != NULL); 1399 GNUNET_assert (second_count != NULL);
1397 second_count->count++; 1400 second_count->count++;
1398 GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap, 1401 GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap,
1399 second_count->heap_node, 1402 second_count->heap_node,
1400 second_count->count); 1403 second_count->count);
1401 } 1404 }
1402 else 1405 else
1403 { 1406 {
1404 second_count = GNUNET_malloc(sizeof(struct PeerCount)); 1407 second_count = GNUNET_malloc (sizeof (struct PeerCount));
1405 second_count->count = 1; 1408 second_count->count = 1;
1406 memcpy (&second_count->peer_id, second, 1409 memcpy (&second_count->peer_id, second,
1407 sizeof(struct GNUNET_PeerIdentity)); 1410 sizeof (struct GNUNET_PeerIdentity));
1408 second_count->heap_node 1411 second_count->heap_node
1409 = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap, 1412 = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
1410 second_count, second_count->count); 1413 second_count, second_count->count);
1411 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash, 1414 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
1412 &second->hashPubKey, second_count, 1415 &second->hashPubKey, second_count,
1413 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1416 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1414 } 1417 }
1415} 1418}
1416 1419
1417/** 1420/**
@@ -1427,46 +1430,43 @@ add_new_connection(struct FindPeerContext *find_peer_context,
1427 * GNUNET_NO if not. 1430 * GNUNET_NO if not.
1428 */ 1431 */
1429static int 1432static int
1430iterate_min_heap_peers(void *cls, struct GNUNET_CONTAINER_HeapNode *node, 1433iterate_min_heap_peers (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
1431 void *element, GNUNET_CONTAINER_HeapCostType cost) 1434 void *element, GNUNET_CONTAINER_HeapCostType cost)
1432{ 1435{
1433 struct FindPeerContext *find_peer_context = cls; 1436 struct FindPeerContext *find_peer_context = cls;
1434 struct PeerCount *peer_count = element; 1437 struct PeerCount *peer_count = element;
1435 struct GNUNET_TESTING_Daemon *d1; 1438 struct GNUNET_TESTING_Daemon *d1;
1436 struct GNUNET_TESTING_Daemon *d2; 1439 struct GNUNET_TESTING_Daemon *d2;
1437 struct GNUNET_TIME_Relative timeout; 1440 struct GNUNET_TIME_Relative timeout;
1441
1438 if (cost == 0) 1442 if (cost == 0)
1443 {
1444 d1 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
1445 GNUNET_assert (d1 != NULL);
1446 d2 = d1;
1447 while ((d2 == d1) || (GNUNET_YES != GNUNET_TESTING_daemon_running (d2)))
1439 { 1448 {
1440 d1 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id); 1449 d2 = GNUNET_TESTING_daemon_get (pg,
1441 GNUNET_assert(d1 != NULL); 1450 GNUNET_CRYPTO_random_u32
1442 d2 = d1; 1451 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
1443 while ((d2 == d1) || (GNUNET_YES != GNUNET_TESTING_daemon_running (d2))) 1452 GNUNET_assert (d2 != NULL);
1444 { 1453 }
1445 d2
1446 = GNUNET_TESTING_daemon_get (
1447 pg,
1448 GNUNET_CRYPTO_random_u32 (
1449 GNUNET_CRYPTO_QUALITY_WEAK,
1450 num_peers));
1451 GNUNET_assert(d2 != NULL);
1452 }
1453 1454
1454 /** Just try to connect the peers, don't worry about callbacks, etc. **/ 1455 /** Just try to connect the peers, don't worry about callbacks, etc. **/
1455 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1456 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1456 "Peer %s has 0 connections. Trying to connect to %s...\n", 1457 "Peer %s has 0 connections. Trying to connect to %s...\n",
1457 GNUNET_i2s (&peer_count->peer_id), d2->shortname); 1458 GNUNET_i2s (&peer_count->peer_id), d2->shortname);
1458 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1459 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1459 DEFAULT_CONNECT_TIMEOUT); 1460 DEFAULT_CONNECT_TIMEOUT);
1460 if (GNUNET_TIME_relative_to_absolute (timeout).abs_value 1461 if (GNUNET_TIME_relative_to_absolute (timeout).abs_value
1461 > find_peer_context->endtime.abs_value) 1462 > find_peer_context->endtime.abs_value)
1462 { 1463 {
1463 timeout 1464 timeout = GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime);
1464 = GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime);
1465 }
1466 GNUNET_TESTING_daemons_connect (d1, d2, timeout,
1467 DEFAULT_RECONNECT_ATTEMPTS, GNUNET_YES,
1468 NULL, NULL);
1469 } 1465 }
1466 GNUNET_TESTING_daemons_connect (d1, d2, timeout,
1467 DEFAULT_RECONNECT_ATTEMPTS, GNUNET_YES,
1468 NULL, NULL);
1469 }
1470 if (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).rel_value 1470 if (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).rel_value
1471 > 0) 1471 > 0)
1472 return GNUNET_YES; 1472 return GNUNET_YES;
@@ -1478,9 +1478,9 @@ iterate_min_heap_peers(void *cls, struct GNUNET_CONTAINER_HeapNode *node,
1478 * Forward declaration. 1478 * Forward declaration.
1479 */ 1479 */
1480static void 1480static void
1481 schedule_churn_find_peer_requests( 1481schedule_churn_find_peer_requests (void *cls,
1482 void *cls, 1482 const struct GNUNET_SCHEDULER_TaskContext
1483 const struct GNUNET_SCHEDULER_TaskContext * tc); 1483 *tc);
1484 1484
1485/** 1485/**
1486 * Callback for iterating over all the peer connections of a peer group. 1486 * Callback for iterating over all the peer connections of a peer group.
@@ -1488,39 +1488,39 @@ static void
1488 * connections so we can make them issue find peer requests. 1488 * connections so we can make them issue find peer requests.
1489 */ 1489 */
1490static void 1490static void
1491count_peers_churn_cb(void *cls, const struct GNUNET_PeerIdentity *first, 1491count_peers_churn_cb (void *cls, const struct GNUNET_PeerIdentity *first,
1492 const struct GNUNET_PeerIdentity *second, const char *emsg) 1492 const struct GNUNET_PeerIdentity *second,
1493 const char *emsg)
1493{ 1494{
1494 struct FindPeerContext *find_peer_context = cls; 1495 struct FindPeerContext *find_peer_context = cls;
1495 struct TopologyIteratorContext *topo_ctx; 1496 struct TopologyIteratorContext *topo_ctx;
1496 struct PeerCount *peer_count; 1497 struct PeerCount *peer_count;
1497 1498
1498 if ((first != NULL) && (second != NULL)) 1499 if ((first != NULL) && (second != NULL))
1499 { 1500 {
1500 add_new_connection (find_peer_context, first, second); 1501 add_new_connection (find_peer_context, first, second);
1501 find_peer_context->current_peers++; 1502 find_peer_context->current_peers++;
1502 } 1503 }
1503 else 1504 else
1504 { 1505 {
1505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1506 "Peer count finished (%u connections)\n", 1507 "Peer count finished (%u connections)\n",
1507 find_peer_context->current_peers); 1508 find_peer_context->current_peers);
1508 peer_count 1509 peer_count = GNUNET_CONTAINER_heap_peek (find_peer_context->peer_min_heap);
1509 = GNUNET_CONTAINER_heap_peek (find_peer_context->peer_min_heap); 1510 GNUNET_assert (peer_count != NULL);
1510 GNUNET_assert(peer_count != NULL); 1511 /* WAIT. When peers are churned they will come back with their peers (at least in peerinfo), because the HOSTS file doesn't likely get removed. CRAP. */
1511 /* WAIT. When peers are churned they will come back with their peers (at least in peerinfo), because the HOSTS file doesn't likely get removed. CRAP. */ 1512 /* NO they won't, because we have disabled peerinfo writing to disk (remember?) so we WILL have to give them new connections */
1512 /* NO they won't, because we have disabled peerinfo writing to disk (remember?) so we WILL have to give them new connections */ 1513 /* Best course of action: have DHT automatically try to add peers from peerinfo on startup. This way IF peerinfo writes to file
1513 /* Best course of action: have DHT automatically try to add peers from peerinfo on startup. This way IF peerinfo writes to file 1514 * then some peers will end up connected.
1514 * then some peers will end up connected. 1515 *
1515 * 1516 * Also, find any peers that have zero connections here and set up a task to choose at random another peer in the network to
1516 * Also, find any peers that have zero connections here and set up a task to choose at random another peer in the network to 1517 * connect to. Of course, if they are blacklisted from that peer they won't be able to connect, so we will have to keep trying
1517 * connect to. Of course, if they are blacklisted from that peer they won't be able to connect, so we will have to keep trying 1518 * until they get a peer.
1518 * until they get a peer. 1519 */
1519 */ 1520 /* However, they won't automatically be connected to any of their previous peers... How can we handle that? */
1520 /* However, they won't automatically be connected to any of their previous peers... How can we handle that? */ 1521 /* So now we have choices: do we want them to come back with all their connections? Probably not, but it solves this mess. */
1521 /* So now we have choices: do we want them to come back with all their connections? Probably not, but it solves this mess. */ 1522
1522 1523 /* Second problem, which is still a problem, is that a FIND_PEER request won't work when a peer has no connections */
1523 /* Second problem, which is still a problem, is that a FIND_PEER request won't work when a peer has no connections */
1524 1524
1525 /** 1525 /**
1526 * Okay, so here's how this *should* work now. 1526 * Okay, so here's how this *should* work now.
@@ -1555,77 +1555,73 @@ count_peers_churn_cb(void *cls, const struct GNUNET_PeerIdentity *first,
1555 * into the general testing churn options seems like overkill because 1555 * into the general testing churn options seems like overkill because
1556 * these are very specialized cases. 1556 * these are very specialized cases.
1557 */ 1557 */
1558 GNUNET_log ( 1558 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1559 GNUNET_ERROR_TYPE_WARNING, 1559 "Out of %u peers, fewest connections is %d\n",
1560 "Out of %u peers, fewest connections is %d\n", 1560 GNUNET_CONTAINER_heap_get_size
1561 GNUNET_CONTAINER_heap_get_size ( 1561 (find_peer_context->peer_min_heap), peer_count->count);
1562 find_peer_context->peer_min_heap), 1562 if ((peer_count->count == 0) &&
1563 peer_count->count); 1563 (GNUNET_TIME_absolute_get_remaining
1564 if ((peer_count->count == 0) 1564 (find_peer_context->endtime).rel_value > 0))
1565 && (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).rel_value 1565 {
1566 > 0)) 1566 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1567 { 1567 "Found peer with no connections, will choose some peer(s) at random to connect to!\n");
1568 GNUNET_log ( 1568 GNUNET_CONTAINER_heap_iterate (find_peer_context->peer_min_heap,
1569 GNUNET_ERROR_TYPE_WARNING, 1569 &iterate_min_heap_peers,
1570 "Found peer with no connections, will choose some peer(s) at random to connect to!\n"); 1570 find_peer_context);
1571 GNUNET_CONTAINER_heap_iterate (find_peer_context->peer_min_heap, 1571 GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests,
1572 &iterate_min_heap_peers, 1572 find_peer_context);
1573 find_peer_context); 1573 }
1574 GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests, 1574 else if ((GNUNET_TIME_absolute_get_remaining
1575 find_peer_context); 1575 (find_peer_context->endtime).rel_value > 0) &&
1576 } 1576 (find_peer_context->last_sent != 0))
1577 else if ((GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).rel_value 1577 {
1578 > 0) && (find_peer_context->last_sent != 0)) 1578 GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests,
1579 { 1579 find_peer_context);
1580 GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests, 1580 }
1581 find_peer_context); 1581 else
1582 } 1582 {
1583 GNUNET_CONTAINER_multihashmap_iterate (find_peer_context->peer_hash,
1584 &remove_peer_count,
1585 find_peer_context);
1586 GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
1587 GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
1588 GNUNET_free (find_peer_context);
1589 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1590 "Churn round %u of %llu finished, scheduling next GET round.\n",
1591 current_churn_round, churn_rounds);
1592 if (dhtlog_handle != NULL)
1593 {
1594 topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
1595 topo_ctx->cont = &do_get;
1596 topo_ctx->cls = all_gets;
1597 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
1598 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
1599 die_task
1600 =
1601 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
1602 (GNUNET_TIME_relative_add
1603 (DEFAULT_GET_TIMEOUT,
1604 all_get_timeout),
1605 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
1606 &end_badly,
1607 "from do gets (count_peers_churn_cb)");
1608 GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
1609 }
1583 else 1610 else
1584 { 1611 {
1585 GNUNET_CONTAINER_multihashmap_iterate (find_peer_context->peer_hash, 1612 die_task
1586 &remove_peer_count, 1613 =
1587 find_peer_context); 1614 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
1588 GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash); 1615 (GNUNET_TIME_relative_add
1589 GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap); 1616 (DEFAULT_GET_TIMEOUT,
1590 GNUNET_free(find_peer_context); 1617 all_get_timeout),
1591 GNUNET_log ( 1618 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
1592 GNUNET_ERROR_TYPE_WARNING, 1619 &end_badly,
1593 "Churn round %u of %llu finished, scheduling next GET round.\n", 1620 "from do gets (count_peers_churn_cb)");
1594 current_churn_round, churn_rounds); 1621 GNUNET_SCHEDULER_add_now (&do_get, all_gets);
1595 if (dhtlog_handle != NULL) 1622 }
1596 {
1597 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1598 topo_ctx->cont = &do_get;
1599 topo_ctx->cls = all_gets;
1600 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
1601 topo_ctx->peers_seen
1602 = GNUNET_CONTAINER_multihashmap_create (num_peers);
1603 die_task
1604 = GNUNET_SCHEDULER_add_delayed (
1605 GNUNET_TIME_relative_add (
1606 GNUNET_TIME_relative_add (
1607 DEFAULT_GET_TIMEOUT,
1608 all_get_timeout),
1609 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
1610 &end_badly,
1611 "from do gets (count_peers_churn_cb)");
1612 GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
1613 }
1614 else
1615 {
1616 die_task
1617 = GNUNET_SCHEDULER_add_delayed (
1618 GNUNET_TIME_relative_add (
1619 GNUNET_TIME_relative_add (
1620 DEFAULT_GET_TIMEOUT,
1621 all_get_timeout),
1622 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
1623 &end_badly,
1624 "from do gets (count_peers_churn_cb)");
1625 GNUNET_SCHEDULER_add_now (&do_get, all_gets);
1626 }
1627 }
1628 } 1623 }
1624 }
1629} 1625}
1630 1626
1631/** 1627/**
@@ -1634,24 +1630,23 @@ count_peers_churn_cb(void *cls, const struct GNUNET_PeerIdentity *first,
1634 * and the time allowed for each one! 1630 * and the time allowed for each one!
1635 */ 1631 */
1636static void 1632static void
1637schedule_churn_find_peer_requests( 1633schedule_churn_find_peer_requests (void *cls,
1638 void *cls, 1634 const struct GNUNET_SCHEDULER_TaskContext
1639 const struct GNUNET_SCHEDULER_TaskContext * tc) 1635 *tc)
1640{ 1636{
1641 struct FindPeerContext *find_peer_ctx = cls; 1637 struct FindPeerContext *find_peer_ctx = cls;
1642 struct TestFindPeer *test_find_peer; 1638 struct TestFindPeer *test_find_peer;
1643 struct PeerCount *peer_count; 1639 struct PeerCount *peer_count;
1644 uint32_t i; 1640 uint32_t i;
1645 1641
1646 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */ 1642 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
1647 find_peer_ctx->total = 1; 1643 find_peer_ctx->total = 1;
1648 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers 1644 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers
1649 < MIN_FIND_PEER_CUTOFF) 1645 < MIN_FIND_PEER_CUTOFF)
1650 find_peer_ctx->total = find_peer_ctx->total / 2; 1646 find_peer_ctx->total = find_peer_ctx->total / 2;
1651 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers 1647 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
1652 > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
1653 find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent 1648 find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent
1654 / 4); 1649 / 4);
1655 else 1650 else
1656 find_peer_ctx->total = find_peer_ctx->last_sent * 4; 1651 find_peer_ctx->total = find_peer_ctx->last_sent * 4;
1657 1652
@@ -1667,62 +1662,61 @@ schedule_churn_find_peer_requests(
1667 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay, 1662 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay,
1668 find_peer_ctx->total); 1663 find_peer_ctx->total);
1669 else 1664 else
1670 { 1665 {
1671 find_peer_ctx->previous_peers = find_peer_ctx->current_peers; 1666 find_peer_ctx->previous_peers = find_peer_ctx->current_peers;
1672 find_peer_ctx->current_peers = 0; 1667 find_peer_ctx->current_peers = 0;
1673 GNUNET_TESTING_get_topology (pg, &count_peers_churn_cb, find_peer_ctx); 1668 GNUNET_TESTING_get_topology (pg, &count_peers_churn_cb, find_peer_ctx);
1674 } 1669 }
1675 1670
1676 for (i = 0; i < find_peer_ctx->total; i++) 1671 for (i = 0; i < find_peer_ctx->total; i++)
1677 { 1672 {
1678 test_find_peer = GNUNET_malloc(sizeof(struct TestFindPeer)); 1673 test_find_peer = GNUNET_malloc (sizeof (struct TestFindPeer));
1679 /* If we have sent requests, choose peers with a low number of connections to send requests from */ 1674 /* If we have sent requests, choose peers with a low number of connections to send requests from */
1680 peer_count 1675 peer_count
1681 = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap); 1676 = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap);
1682 GNUNET_assert(peer_count != NULL); 1677 GNUNET_assert (peer_count != NULL);
1683 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1678 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1684 "Sending find peer request from peer with %u connections\n", 1679 "Sending find peer request from peer with %u connections\n",
1685 peer_count->count); 1680 peer_count->count);
1686 GNUNET_CONTAINER_multihashmap_remove (find_peer_ctx->peer_hash, 1681 GNUNET_CONTAINER_multihashmap_remove (find_peer_ctx->peer_hash,
1687 &peer_count->peer_id.hashPubKey, 1682 &peer_count->peer_id.hashPubKey,
1688 peer_count); 1683 peer_count);
1689 test_find_peer->daemon 1684 test_find_peer->daemon
1690 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id); 1685 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
1691 GNUNET_assert(test_find_peer->daemon != NULL); 1686 GNUNET_assert (test_find_peer->daemon != NULL);
1692 test_find_peer->find_peer_context = find_peer_ctx; 1687 test_find_peer->find_peer_context = find_peer_ctx;
1693 GNUNET_SCHEDULER_add_delayed ( 1688 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1694 GNUNET_TIME_relative_multiply ( 1689 (find_peer_offset, i),
1695 find_peer_offset, 1690 &send_find_peer_request, test_find_peer);
1696 i), 1691 }
1697 &send_find_peer_request, test_find_peer);
1698 }
1699 1692
1700 if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap 1693 if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap
1701 == NULL)) 1694 == NULL))
1702 { 1695 {
1703 find_peer_ctx->peer_hash 1696 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create (num_peers);
1704 = GNUNET_CONTAINER_multihashmap_create (num_peers); 1697 find_peer_ctx->peer_min_heap
1705 find_peer_ctx->peer_min_heap 1698 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1706 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1699 }
1707 }
1708 else 1700 else
1709 { 1701 {
1710 GNUNET_CONTAINER_multihashmap_iterate (find_peer_ctx->peer_hash, 1702 GNUNET_CONTAINER_multihashmap_iterate (find_peer_ctx->peer_hash,
1711 &remove_peer_count, find_peer_ctx); 1703 &remove_peer_count, find_peer_ctx);
1712 GNUNET_CONTAINER_multihashmap_destroy (find_peer_ctx->peer_hash); 1704 GNUNET_CONTAINER_multihashmap_destroy (find_peer_ctx->peer_hash);
1713 find_peer_ctx->peer_hash 1705 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create (num_peers);
1714 = GNUNET_CONTAINER_multihashmap_create (num_peers); 1706 }
1715 }
1716 1707
1717 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(find_peer_ctx->peer_hash)); 1708 GNUNET_assert (0 ==
1718 GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(find_peer_ctx->peer_min_heap)); 1709 GNUNET_CONTAINER_multihashmap_size (find_peer_ctx->peer_hash));
1710 GNUNET_assert (0 ==
1711 GNUNET_CONTAINER_heap_get_size (find_peer_ctx->peer_min_heap));
1719} 1712}
1720 1713
1721static void 1714static void
1722schedule_churn_get_topology(void *cls, 1715schedule_churn_get_topology (void *cls,
1723 const struct GNUNET_SCHEDULER_TaskContext * tc) 1716 const struct GNUNET_SCHEDULER_TaskContext *tc)
1724{ 1717{
1725 struct FindPeerContext *find_peer_context = cls; 1718 struct FindPeerContext *find_peer_context = cls;
1719
1726 GNUNET_TESTING_get_topology (pg, &count_peers_churn_cb, find_peer_context); 1720 GNUNET_TESTING_get_topology (pg, &count_peers_churn_cb, find_peer_context);
1727} 1721}
1728 1722
@@ -1733,7 +1727,7 @@ schedule_churn_get_topology(void *cls,
1733 * @param emsg NULL on success, or a printable error on failure 1727 * @param emsg NULL on success, or a printable error on failure
1734 */ 1728 */
1735static void 1729static void
1736churn_complete(void *cls, const char *emsg) 1730churn_complete (void *cls, const char *emsg)
1737{ 1731{
1738 struct FindPeerContext *find_peer_context = cls; 1732 struct FindPeerContext *find_peer_context = cls;
1739 struct PeerCount *peer_count; 1733 struct PeerCount *peer_count;
@@ -1744,12 +1738,12 @@ churn_complete(void *cls, const char *emsg)
1744 int count_added; 1738 int count_added;
1745 1739
1746 if (emsg != NULL) 1740 if (emsg != NULL)
1747 { 1741 {
1748 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1742 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1749 "Ending test, churning of peers failed with error `%s'", emsg); 1743 "Ending test, churning of peers failed with error `%s'", emsg);
1750 GNUNET_SCHEDULER_add_now (&end_badly, (void *) emsg); 1744 GNUNET_SCHEDULER_add_now (&end_badly, (void *) emsg);
1751 return; 1745 return;
1752 } 1746 }
1753 1747
1754 /** 1748 /**
1755 * If we switched any peers on, we have to somehow force connect the new peer to 1749 * If we switched any peers on, we have to somehow force connect the new peer to
@@ -1757,83 +1751,78 @@ churn_complete(void *cls, const char *emsg)
1757 * with no connections, then choose a random peer for each and connect them. 1751 * with no connections, then choose a random peer for each and connect them.
1758 */ 1752 */
1759 if (find_peer_context != NULL) 1753 if (find_peer_context != NULL)
1754 {
1755 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1756 "We have churned on some peers, so we must schedule find peer requests for them!\n");
1757 count_added = 0;
1758 for (i = 0; i < num_peers; i++)
1760 { 1759 {
1761 GNUNET_log ( 1760 temp_daemon = GNUNET_TESTING_daemon_get (pg, i);
1762 GNUNET_ERROR_TYPE_WARNING, 1761 if (GNUNET_YES == GNUNET_TESTING_daemon_running (temp_daemon))
1763 "We have churned on some peers, so we must schedule find peer requests for them!\n"); 1762 {
1764 count_added = 0; 1763 peer_count = GNUNET_malloc (sizeof (struct PeerCount));
1765 for (i = 0; i < num_peers; i++) 1764 memcpy (&peer_count->peer_id, &temp_daemon->id,
1766 { 1765 sizeof (struct GNUNET_PeerIdentity));
1767 temp_daemon = GNUNET_TESTING_daemon_get (pg, i); 1766 GNUNET_assert (peer_count->count == 0);
1768 if (GNUNET_YES == GNUNET_TESTING_daemon_running (temp_daemon)) 1767 peer_count->heap_node
1769 { 1768 = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
1770 peer_count = GNUNET_malloc (sizeof(struct PeerCount)); 1769 peer_count, peer_count->count);
1771 memcpy (&peer_count->peer_id, &temp_daemon->id, 1770 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
1772 sizeof(struct GNUNET_PeerIdentity)); 1771 &temp_daemon->id.hashPubKey,
1773 GNUNET_assert(peer_count->count == 0); 1772 peer_count,
1774 peer_count->heap_node 1773 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1775 = GNUNET_CONTAINER_heap_insert ( 1774 count_added++;
1776 find_peer_context->peer_min_heap, 1775 }
1777 peer_count, peer_count->count);
1778 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
1779 &temp_daemon->id.hashPubKey,
1780 peer_count,
1781 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1782 count_added++;
1783 }
1784 }
1785 GNUNET_log (
1786 GNUNET_ERROR_TYPE_WARNING,
1787 "Added %d peers to heap, total size %d\n",
1788 count_added,
1789 GNUNET_CONTAINER_heap_get_size (
1790 find_peer_context->peer_min_heap));
1791 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
1792 &schedule_churn_get_topology,
1793 find_peer_context);
1794 } 1776 }
1777 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1778 "Added %d peers to heap, total size %d\n",
1779 count_added,
1780 GNUNET_CONTAINER_heap_get_size
1781 (find_peer_context->peer_min_heap));
1782 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
1783 &schedule_churn_get_topology,
1784 find_peer_context);
1785 }
1795 else 1786 else
1787 {
1788 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1789 "Only churned off peers, no find peer requests, scheduling more gets (after allowing time for peers to disconnect properly!)...\n");
1790 if (dhtlog_handle != NULL)
1796 { 1791 {
1797 GNUNET_log ( 1792 topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
1798 GNUNET_ERROR_TYPE_WARNING, 1793 topo_ctx->cont = &do_get;
1799 "Only churned off peers, no find peer requests, scheduling more gets (after allowing time for peers to disconnect properly!)...\n"); 1794 topo_ctx->cls = all_gets;
1800 if (dhtlog_handle != NULL) 1795 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
1801 { 1796 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
1802 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext)); 1797 calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT,
1803 topo_ctx->cont = &do_get; 1798 all_get_timeout);
1804 topo_ctx->cls = all_gets; 1799 calc_timeout
1805 topo_ctx->timeout = DEFAULT_GET_TIMEOUT; 1800 = GNUNET_TIME_relative_add (calc_timeout,
1806 topo_ctx->peers_seen 1801 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT);
1807 = GNUNET_CONTAINER_multihashmap_create (num_peers); 1802 calc_timeout
1808 calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT, 1803 = GNUNET_TIME_relative_add (calc_timeout,
1809 all_get_timeout); 1804 DEFAULT_PEER_DISCONNECT_TIMEOUT);
1810 calc_timeout 1805 die_task
1811 = GNUNET_TIME_relative_add (calc_timeout, 1806 = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
1812 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT); 1807 "from do gets (churn_complete)");
1813 calc_timeout 1808 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
1814 = GNUNET_TIME_relative_add (calc_timeout, 1809 &capture_current_topology, topo_ctx);
1815 DEFAULT_PEER_DISCONNECT_TIMEOUT); 1810 dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished);
1816 die_task 1811 }
1817 = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly, 1812 else
1818 "from do gets (churn_complete)"); 1813 {
1819 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT, 1814 calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT,
1820 &capture_current_topology, topo_ctx); 1815 all_get_timeout);
1821 dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished); 1816 calc_timeout
1822 } 1817 = GNUNET_TIME_relative_add (calc_timeout,
1823 else 1818 DEFAULT_PEER_DISCONNECT_TIMEOUT);
1824 { 1819 die_task
1825 calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT, 1820 = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
1826 all_get_timeout); 1821 "from do gets (churn_complete)");
1827 calc_timeout 1822 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
1828 = GNUNET_TIME_relative_add (calc_timeout, 1823 &do_get, all_gets);
1829 DEFAULT_PEER_DISCONNECT_TIMEOUT);
1830 die_task
1831 = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
1832 "from do gets (churn_complete)");
1833 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
1834 &do_get, all_gets);
1835 }
1836 } 1824 }
1825 }
1837} 1826}
1838 1827
1839/** 1828/**
@@ -1846,7 +1835,7 @@ churn_complete(void *cls, const char *emsg)
1846 * @param tc task context (unused) 1835 * @param tc task context (unused)
1847 */ 1836 */
1848static void 1837static void
1849churn_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 1838churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1850{ 1839{
1851 unsigned int count_running; 1840 unsigned int count_running;
1852 unsigned int churn_up; 1841 unsigned int churn_up;
@@ -1865,39 +1854,38 @@ churn_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1865 "Not churning any peers, topology unchanged.\n"); 1854 "Not churning any peers, topology unchanged.\n");
1866 1855
1867 if (churn_up > num_peers - count_running) 1856 if (churn_up > num_peers - count_running)
1868 { 1857 {
1869 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1858 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1870 "Churn file specified %u peers (up); only have %u!", 1859 "Churn file specified %u peers (up); only have %u!",
1871 churn_array[current_churn_round], num_peers); 1860 churn_array[current_churn_round], num_peers);
1872 churn_up = num_peers - count_running; 1861 churn_up = num_peers - count_running;
1873 } 1862 }
1874 else if (churn_down > count_running) 1863 else if (churn_down > count_running)
1875 { 1864 {
1876 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1877 "Churn file specified %u peers (down); only have %u!", 1866 "Churn file specified %u peers (down); only have %u!",
1878 churn_array[current_churn_round], count_running); 1867 churn_array[current_churn_round], count_running);
1879 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1868 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1880 "This will leave NO peers running (mistake in churn configuration?)!"); 1869 "This will leave NO peers running (mistake in churn configuration?)!");
1881 churn_down = count_running; 1870 churn_down = count_running;
1882 } 1871 }
1883 //timeout = GNUNET_TIME_relative_multiply(seconds_per_peer_start, churn_up > 0 ? churn_up : churn_down); 1872 //timeout = GNUNET_TIME_relative_multiply(seconds_per_peer_start, churn_up > 0 ? churn_up : churn_down);
1884 //timeout = GNUNET_TIME_relative_multiply (seconds_per_peer_start, churn_up > 0 ? churn_up : churn_down); 1873 //timeout = GNUNET_TIME_relative_multiply (seconds_per_peer_start, churn_up > 0 ? churn_up : churn_down);
1885 timeout = GNUNET_TIME_relative_multiply (DEFAULT_TIMEOUT, 2); /* FIXME: Lack of intelligent choice here */ 1874 timeout = GNUNET_TIME_relative_multiply (DEFAULT_TIMEOUT, 2); /* FIXME: Lack of intelligent choice here */
1886 find_peer_context = NULL; 1875 find_peer_context = NULL;
1887 if (churn_up > 0) /* Only need to do find peer requests if we turned new peers on */ 1876 if (churn_up > 0) /* Only need to do find peer requests if we turned new peers on */
1888 { 1877 {
1889 find_peer_context = GNUNET_malloc(sizeof(struct FindPeerContext)); 1878 find_peer_context = GNUNET_malloc (sizeof (struct FindPeerContext));
1890 find_peer_context->count_peers_cb = &count_peers_churn_cb; 1879 find_peer_context->count_peers_cb = &count_peers_churn_cb;
1891 find_peer_context->previous_peers = 0; 1880 find_peer_context->previous_peers = 0;
1892 find_peer_context->current_peers = 0; 1881 find_peer_context->current_peers = 0;
1893 find_peer_context->endtime = GNUNET_TIME_relative_to_absolute (timeout); 1882 find_peer_context->endtime = GNUNET_TIME_relative_to_absolute (timeout);
1894 find_peer_context->peer_hash 1883 find_peer_context->peer_hash
1895 = GNUNET_CONTAINER_multihashmap_create (num_peers); 1884 = GNUNET_CONTAINER_multihashmap_create (num_peers);
1896 find_peer_context->peer_min_heap 1885 find_peer_context->peer_min_heap
1897 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1886 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1898 } 1887 }
1899 GNUNET_log ( 1888 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1900 GNUNET_ERROR_TYPE_WARNING,
1901 "churn_peers: want %u total, %u running, starting %u, stopping %u\n", 1889 "churn_peers: want %u total, %u running, starting %u, stopping %u\n",
1902 churn_array[current_churn_round], count_running, churn_up, 1890 churn_array[current_churn_round], count_running, churn_up,
1903 churn_down); 1891 churn_down);
@@ -1910,147 +1898,135 @@ churn_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1910 * Task to release DHT handle associated with GET request. 1898 * Task to release DHT handle associated with GET request.
1911 */ 1899 */
1912static void 1900static void
1913get_stop_finished(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 1901get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1914{ 1902{
1915 struct TestGetContext *test_get = cls; 1903 struct TestGetContext *test_get = cls;
1916 struct TopologyIteratorContext *topo_ctx; 1904 struct TopologyIteratorContext *topo_ctx;
1917 1905
1918 /* The dht_handle may be null if this get was scheduled from a down peer */ 1906 /* The dht_handle may be null if this get was scheduled from a down peer */
1919 if (test_get->dht_handle != NULL) 1907 if (test_get->dht_handle != NULL)
1920 { 1908 {
1921 GNUNET_DHT_disconnect (test_get->dht_handle); 1909 GNUNET_DHT_disconnect (test_get->dht_handle);
1922 outstanding_gets--; /* GET is really finished */ 1910 outstanding_gets--; /* GET is really finished */
1923 test_get->dht_handle = NULL; 1911 test_get->dht_handle = NULL;
1924 } 1912 }
1925 1913
1926 /* Reset the uid (which item to search for) and the daemon (which peer to search from) for later get request iterations */ 1914 /* Reset the uid (which item to search for) and the daemon (which peer to search from) for later get request iterations */
1927 if (get_from_same == GNUNET_NO) 1915 if (get_from_same == GNUNET_NO)
1928 { 1916 {
1929 test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1917 test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1930 num_puts); 1918 num_puts);
1931 test_get->daemon 1919 test_get->daemon
1932 = GNUNET_TESTING_daemon_get ( 1920 = GNUNET_TESTING_daemon_get (pg,
1933 pg, 1921 GNUNET_CRYPTO_random_u32
1934 GNUNET_CRYPTO_random_u32 ( 1922 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
1935 GNUNET_CRYPTO_QUALITY_WEAK, 1923 }
1936 num_peers));
1937 }
1938 1924
1939#if VERBOSE > 1 1925#if VERBOSE > 1
1940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed); 1926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n",
1927 gets_completed, gets_failed);
1941#endif 1928#endif
1942 update_meter (get_meter); 1929 update_meter (get_meter);
1943 if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) 1930 if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0))
1944 { 1931 {
1945 fprintf ( 1932 fprintf (stderr,
1946 stderr, 1933 "Canceling die task (get_stop_finished) %llu gets completed, %llu gets failed\n",
1947 "Canceling die task (get_stop_finished) %llu gets completed, %llu gets failed\n", 1934 gets_completed, gets_failed);
1948 gets_completed, gets_failed); 1935 if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle))
1949 if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle)) 1936 dhtlog_handle->insert_round_details (DHT_ROUND_GET, rounds_finished,
1950 dhtlog_handle->insert_round_details (DHT_ROUND_GET, rounds_finished, 1937 num_gets, gets_completed);
1951 num_gets, gets_completed); 1938 GNUNET_SCHEDULER_cancel (die_task);
1952 GNUNET_SCHEDULER_cancel (die_task); 1939 reset_meter (put_meter);
1953 reset_meter (put_meter); 1940 reset_meter (get_meter);
1954 reset_meter (get_meter); 1941 if ((target_completions > 0) && (gets_completed > target_completions))
1955 if ((target_completions > 0) 1942 fprintf (stderr, "Ending test early due to GET success!\n");
1956 && (gets_completed > target_completions))
1957 fprintf(stderr, "Ending test early due to GET success!\n");
1958 /** 1943 /**
1959 * Handle all cases: 1944 * Handle all cases:
1960 * 1) Testing is completely finished, call the topology iteration dealy and die 1945 * 1) Testing is completely finished, call the topology iteration dealy and die
1961 * 2) Testing is not finished, churn the network and do gets again (current_churn_round < churn_rounds) 1946 * 2) Testing is not finished, churn the network and do gets again (current_churn_round < churn_rounds)
1962 * 3) Testing is not finished, reschedule all the PUTS *and* GETS again (num_rounds > 1) 1947 * 3) Testing is not finished, reschedule all the PUTS *and* GETS again (num_rounds > 1)
1963 */ 1948 */
1964 if ((rounds_finished == total_rounds - 1) || ((target_completions > 0) 1949 if ((rounds_finished == total_rounds - 1) || ((target_completions > 0) && (gets_completed > target_completions))) /* Everything is finished, end testing */
1965 && (gets_completed > target_completions))) /* Everything is finished, end testing */ 1950 {
1966 { 1951 if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
1967 if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal)) 1952 {
1968 { 1953 topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
1969 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext)); 1954 topo_ctx->cont = &log_dht_statistics;
1970 topo_ctx->cont = &log_dht_statistics; 1955 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
1971 topo_ctx->peers_seen 1956 GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
1972 = GNUNET_CONTAINER_multihashmap_create (num_peers); 1957 }
1973 GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx); 1958 else
1974 } 1959 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
1975 else 1960 }
1976 GNUNET_SCHEDULER_add_now (&finish_testing, NULL); 1961 else if (current_churn_round < churns_per_round * (rounds_finished + 1)) /* Do next round of churn */
1977 } 1962 {
1978 else if (current_churn_round < churns_per_round * (rounds_finished + 1)) /* Do next round of churn */ 1963 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1979 { 1964 "Current churn round %u, real round %u, scheduling next round of churn.\n",
1980 GNUNET_log ( 1965 current_churn_round, rounds_finished + 1);
1981 GNUNET_ERROR_TYPE_WARNING, 1966 gets_completed = 0;
1982 "Current churn round %u, real round %u, scheduling next round of churn.\n", 1967 gets_failed = 0;
1983 current_churn_round, rounds_finished + 1);
1984 gets_completed = 0;
1985 gets_failed = 0;
1986 1968
1987 if (dhtlog_handle != NULL) 1969 if (dhtlog_handle != NULL)
1988 dhtlog_handle->insert_round (DHT_ROUND_CHURN, rounds_finished); 1970 dhtlog_handle->insert_round (DHT_ROUND_CHURN, rounds_finished);
1989 1971
1990 GNUNET_SCHEDULER_add_now (&churn_peers, NULL); 1972 GNUNET_SCHEDULER_add_now (&churn_peers, NULL);
1991 } 1973 }
1992 else if (rounds_finished < total_rounds - 1) /* Start a new complete round */ 1974 else if (rounds_finished < total_rounds - 1) /* Start a new complete round */
1993 { 1975 {
1994 rounds_finished++; 1976 rounds_finished++;
1995 gets_completed = 0; 1977 gets_completed = 0;
1996 gets_failed = 0; 1978 gets_failed = 0;
1997 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1979 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1998 "Round %u of %llu finished, scheduling next round.\n", 1980 "Round %u of %llu finished, scheduling next round.\n",
1999 rounds_finished, total_rounds); 1981 rounds_finished, total_rounds);
2000 1982
2001 /** We reset the peer daemon for puts and gets on each disconnect, so all we need to do is start another round! */ 1983 /** We reset the peer daemon for puts and gets on each disconnect, so all we need to do is start another round! */
2002 if (GNUNET_YES == in_dht_replication) /* Replication done in DHT, don't redo puts! */ 1984 if (GNUNET_YES == in_dht_replication) /* Replication done in DHT, don't redo puts! */
2003 { 1985 {
2004 if (dhtlog_handle != NULL) 1986 if (dhtlog_handle != NULL)
2005 dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished); 1987 dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished);
2006 1988
2007 die_task 1989 die_task
2008 = GNUNET_SCHEDULER_add_delayed ( 1990 =
2009 GNUNET_TIME_relative_add ( 1991 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
2010 GNUNET_TIME_relative_add ( 1992 (GNUNET_TIME_relative_add
2011 GNUNET_TIME_relative_multiply ( 1993 (GNUNET_TIME_relative_multiply
2012 GNUNET_TIME_UNIT_SECONDS, 1994 (GNUNET_TIME_UNIT_SECONDS,
2013 round_delay), 1995 round_delay), all_get_timeout),
2014 all_get_timeout), 1996 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
2015 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT), 1997 &end_badly,
2016 &end_badly, 1998 "from do gets (next round)");
2017 "from do gets (next round)"); 1999 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2018 GNUNET_SCHEDULER_add_delayed ( 2000 (GNUNET_TIME_UNIT_SECONDS, round_delay),
2019 GNUNET_TIME_relative_multiply ( 2001 &do_get, all_gets);
2020 GNUNET_TIME_UNIT_SECONDS, 2002 }
2021 round_delay), 2003 else
2022 &do_get, all_gets); 2004 {
2023 } 2005 if (dhtlog_handle != NULL)
2024 else 2006 dhtlog_handle->insert_round (DHT_ROUND_NORMAL, rounds_finished);
2025 { 2007 die_task
2026 if (dhtlog_handle != NULL) 2008 =
2027 dhtlog_handle->insert_round (DHT_ROUND_NORMAL, rounds_finished); 2009 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
2028 die_task 2010 (GNUNET_TIME_relative_multiply
2029 = GNUNET_SCHEDULER_add_delayed ( 2011 (GNUNET_TIME_UNIT_SECONDS,
2030 GNUNET_TIME_relative_add ( 2012 round_delay),
2031 GNUNET_TIME_relative_multiply ( 2013 GNUNET_TIME_relative_multiply
2032 GNUNET_TIME_UNIT_SECONDS, 2014 (GNUNET_TIME_UNIT_SECONDS,
2033 round_delay), 2015 num_puts * 2)), &end_badly,
2034 GNUNET_TIME_relative_multiply ( 2016 "from do puts");
2035 GNUNET_TIME_UNIT_SECONDS, 2017 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2036 num_puts 2018 (GNUNET_TIME_UNIT_SECONDS, round_delay),
2037 * 2)), 2019 &do_put, all_puts);
2038 &end_badly, "from do puts"); 2020 }
2039 GNUNET_SCHEDULER_add_delayed (
2040 GNUNET_TIME_relative_multiply (
2041 GNUNET_TIME_UNIT_SECONDS,
2042 round_delay),
2043 &do_put, all_puts);
2044 }
2045 }
2046 } 2021 }
2022 }
2047} 2023}
2048 2024
2049/** 2025/**
2050 * Task to release get handle. 2026 * Task to release get handle.
2051 */ 2027 */
2052static void 2028static void
2053get_stop_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2029get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2054{ 2030{
2055 struct TestGetContext *test_get = cls; 2031 struct TestGetContext *test_get = cls;
2056 2032
@@ -2059,7 +2035,7 @@ get_stop_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2059 else 2035 else
2060 cumulative_successful_gets++; 2036 cumulative_successful_gets++;
2061 2037
2062 GNUNET_assert(test_get->get_handle != NULL); 2038 GNUNET_assert (test_get->get_handle != NULL);
2063 GNUNET_DHT_get_stop (test_get->get_handle); 2039 GNUNET_DHT_get_stop (test_get->get_handle);
2064 test_get->get_handle = NULL; 2040 test_get->get_handle = NULL;
2065 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 2041 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
@@ -2081,28 +2057,28 @@ get_stop_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2081 * @param data pointer to the result data 2057 * @param data pointer to the result data
2082 */ 2058 */
2083static void 2059static void
2084get_result_iterator(void *cls, struct GNUNET_TIME_Absolute exp, 2060get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
2085 const GNUNET_HashCode * key, 2061 const GNUNET_HashCode * key,
2086 const struct GNUNET_PeerIdentity * const *get_path, 2062 const struct GNUNET_PeerIdentity *const *get_path,
2087 const struct GNUNET_PeerIdentity * const *put_path, 2063 const struct GNUNET_PeerIdentity *const *put_path,
2088 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 2064 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
2089{ 2065{
2090 struct TestGetContext *test_get = cls; 2066 struct TestGetContext *test_get = cls;
2091 2067
2092 if (test_get->succeeded == GNUNET_YES) 2068 if (test_get->succeeded == GNUNET_YES)
2093 return; /* Get has already been successful, probably ending now */ 2069 return; /* Get has already been successful, probably ending now */
2094 2070
2095 if (0 != memcmp (&known_keys[test_get->uid], key, sizeof(GNUNET_HashCode))) /* || (0 != memcmp(original_data, data, sizeof(original_data))))*/ 2071 if (0 != memcmp (&known_keys[test_get->uid], key, sizeof (GNUNET_HashCode))) /* || (0 != memcmp(original_data, data, sizeof(original_data)))) */
2096 { 2072 {
2097 gets_completed++; 2073 gets_completed++;
2098 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2074 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2099 "Key or data is not the same as was inserted!\n"); 2075 "Key or data is not the same as was inserted!\n");
2100 } 2076 }
2101 else 2077 else
2102 { 2078 {
2103 gets_completed++; 2079 gets_completed++;
2104 test_get->succeeded = GNUNET_YES; 2080 test_get->succeeded = GNUNET_YES;
2105 } 2081 }
2106#if VERBOSE > 1 2082#if VERBOSE > 1
2107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n"); 2083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
2108#endif 2084#endif
@@ -2115,46 +2091,44 @@ get_result_iterator(void *cls, struct GNUNET_TIME_Absolute exp,
2115 * Set up some data, and call API PUT function 2091 * Set up some data, and call API PUT function
2116 */ 2092 */
2117static void 2093static void
2118do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2094do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2119{ 2095{
2120 struct TestGetContext *test_get = cls; 2096 struct TestGetContext *test_get = cls;
2121 2097
2122 if (num_gets == 0) 2098 if (num_gets == 0)
2123 { 2099 {
2124 GNUNET_SCHEDULER_cancel (die_task); 2100 GNUNET_SCHEDULER_cancel (die_task);
2125 GNUNET_SCHEDULER_add_now (&finish_testing, NULL); 2101 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
2126 } 2102 }
2127 2103
2128 if (test_get == NULL) 2104 if (test_get == NULL)
2129 return; /* End of the list */ 2105 return; /* End of the list */
2130 2106
2131 /* Set this here in case we are re-running gets */ 2107 /* Set this here in case we are re-running gets */
2132 test_get->succeeded = GNUNET_NO; 2108 test_get->succeeded = GNUNET_NO;
2133 2109
2134 if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_get->daemon)) /* If the peer has been churned off, don't try issuing request from it! */ 2110 if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_get->daemon)) /* If the peer has been churned off, don't try issuing request from it! */
2135 { 2111 {
2136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2137 "Peer we should issue get request from is down, skipping.\n"); 2113 "Peer we should issue get request from is down, skipping.\n");
2138 gets_failed++; 2114 gets_failed++;
2139 GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get); 2115 GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
2140 GNUNET_SCHEDULER_add_now (&do_get, test_get->next); 2116 GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
2141 return; 2117 return;
2142 } 2118 }
2143 2119
2144 /* Check if more gets are outstanding than should be */ 2120 /* Check if more gets are outstanding than should be */
2145 if (outstanding_gets > max_outstanding_gets) 2121 if (outstanding_gets > max_outstanding_gets)
2146 { 2122 {
2147 GNUNET_SCHEDULER_add_delayed ( 2123 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2148 GNUNET_TIME_relative_multiply ( 2124 (GNUNET_TIME_UNIT_MILLISECONDS, 200), &do_get,
2149 GNUNET_TIME_UNIT_MILLISECONDS, 2125 test_get);
2150 200), 2126 return;
2151 &do_get, test_get); 2127 }
2152 return;
2153 }
2154 2128
2155 /* Connect to the first peer's DHT */ 2129 /* Connect to the first peer's DHT */
2156 test_get->dht_handle = GNUNET_DHT_connect (test_get->daemon->cfg, 10); 2130 test_get->dht_handle = GNUNET_DHT_connect (test_get->daemon->cfg, 10);
2157 GNUNET_assert(test_get->dht_handle != NULL); 2131 GNUNET_assert (test_get->dht_handle != NULL);
2158 outstanding_gets++; 2132 outstanding_gets++;
2159 2133
2160 cumulative_num_gets++; 2134 cumulative_num_gets++;
@@ -2169,8 +2143,7 @@ do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2169 2143
2170#if VERBOSE > 1 2144#if VERBOSE > 1
2171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n", 2145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
2172 test_get->uid, 2146 test_get->uid, test_get->daemon->shortname);
2173 test_get->daemon->shortname);
2174#endif 2147#endif
2175 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed (get_timeout, 2148 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed (get_timeout,
2176 &get_stop_task, 2149 &get_stop_task,
@@ -2185,10 +2158,11 @@ do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2185 * Schedule the GET request for some time in the future. 2158 * Schedule the GET request for some time in the future.
2186 */ 2159 */
2187static void 2160static void
2188put_finished(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2161put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2189{ 2162{
2190 struct TestPutContext *test_put = cls; 2163 struct TestPutContext *test_put = cls;
2191 struct TopologyIteratorContext *topo_ctx; 2164 struct TopologyIteratorContext *topo_ctx;
2165
2192 outstanding_puts--; 2166 outstanding_puts--;
2193 puts_completed++; 2167 puts_completed++;
2194 2168
@@ -2198,125 +2172,115 @@ put_finished(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2198 /* Reset the daemon (which peer to insert at) for later put request iterations */ 2172 /* Reset the daemon (which peer to insert at) for later put request iterations */
2199 if (replicate_same == GNUNET_NO) 2173 if (replicate_same == GNUNET_NO)
2200 test_put->daemon 2174 test_put->daemon
2201 = GNUNET_TESTING_daemon_get ( 2175 = GNUNET_TESTING_daemon_get (pg,
2202 pg, 2176 GNUNET_CRYPTO_random_u32
2203 GNUNET_CRYPTO_random_u32 ( 2177 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
2204 GNUNET_CRYPTO_QUALITY_WEAK,
2205 num_peers));
2206 2178
2207 GNUNET_SCHEDULER_cancel (test_put->disconnect_task); 2179 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
2208 test_put->disconnect_task = GNUNET_SCHEDULER_add_now (&put_disconnect_task, 2180 test_put->disconnect_task = GNUNET_SCHEDULER_add_now (&put_disconnect_task,
2209 test_put); 2181 test_put);
2210 if (GNUNET_YES == update_meter (put_meter)) 2182 if (GNUNET_YES == update_meter (put_meter))
2183 {
2184 GNUNET_assert (outstanding_puts == 0);
2185 GNUNET_SCHEDULER_cancel (die_task);
2186 if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
2211 { 2187 {
2212 GNUNET_assert(outstanding_puts == 0); 2188 topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
2213 GNUNET_SCHEDULER_cancel (die_task); 2189 topo_ctx->cont = &do_get;
2214 if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal)) 2190 topo_ctx->cls = all_gets;
2215 { 2191 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
2216 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext)); 2192 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
2217 topo_ctx->cont = &do_get; 2193 die_task
2218 topo_ctx->cls = all_gets; 2194 =
2219 topo_ctx->timeout = DEFAULT_GET_TIMEOUT; 2195 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
2220 topo_ctx->peers_seen 2196 (GNUNET_TIME_relative_add
2221 = GNUNET_CONTAINER_multihashmap_create (num_peers); 2197 (DEFAULT_GET_TIMEOUT, all_get_timeout),
2222 die_task 2198 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
2223 = GNUNET_SCHEDULER_add_delayed ( 2199 &end_badly,
2224 GNUNET_TIME_relative_add ( 2200 "from do gets (put finished)");
2225 GNUNET_TIME_relative_add ( 2201 GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
2226 DEFAULT_GET_TIMEOUT, 2202 }
2227 all_get_timeout), 2203 else
2228 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT), 2204 {
2229 &end_badly, 2205 fprintf (stderr, "Scheduling die task (put finished)\n");
2230 "from do gets (put finished)"); 2206 die_task
2231 GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx); 2207 =
2232 } 2208 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
2233 else 2209 (DEFAULT_GET_TIMEOUT, all_get_timeout),
2234 { 2210 &end_badly,
2235 fprintf (stderr, "Scheduling die task (put finished)\n"); 2211 "from do gets (put finished)");
2236 die_task 2212 GNUNET_SCHEDULER_add_delayed (DEFAULT_GET_TIMEOUT, &do_get, all_gets);
2237 = GNUNET_SCHEDULER_add_delayed (
2238 GNUNET_TIME_relative_add (
2239 DEFAULT_GET_TIMEOUT,
2240 all_get_timeout),
2241 &end_badly,
2242 "from do gets (put finished)");
2243 GNUNET_SCHEDULER_add_delayed (DEFAULT_GET_TIMEOUT, &do_get, all_gets);
2244 }
2245 return;
2246 } 2213 }
2214 return;
2215 }
2247} 2216}
2248 2217
2249/** 2218/**
2250 * Set up some data, and call API PUT function 2219 * Set up some data, and call API PUT function
2251 */ 2220 */
2252static void 2221static void
2253do_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2222do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2254{ 2223{
2255 struct TestPutContext *test_put = cls; 2224 struct TestPutContext *test_put = cls;
2256 char data[test_data_size]; /* Made up data to store */ 2225 char data[test_data_size]; /* Made up data to store */
2257 uint32_t rand; 2226 uint32_t rand;
2258 int i; 2227 int i;
2259 2228
2260 if (test_put == NULL) 2229 if (test_put == NULL)
2261 return; /* End of list */ 2230 return; /* End of list */
2262 2231
2263 if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_put->daemon)) /* If the peer has been churned off, don't try issuing request from it! */ 2232 if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_put->daemon)) /* If the peer has been churned off, don't try issuing request from it! */
2264 { 2233 {
2265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2266 "Peer we should issue put request at is down, skipping.\n"); 2235 "Peer we should issue put request at is down, skipping.\n");
2267 update_meter (put_meter); 2236 update_meter (put_meter);
2268 GNUNET_SCHEDULER_add_now (&do_put, test_put->next); 2237 GNUNET_SCHEDULER_add_now (&do_put, test_put->next);
2269 return; 2238 return;
2270 } 2239 }
2271 2240
2272 for (i = 0; i < sizeof(data); i++) 2241 for (i = 0; i < sizeof (data); i++)
2273 { 2242 {
2274 memset (&data[i], GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2243 memset (&data[i], GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2275 UINT32_MAX), 1); 2244 UINT32_MAX), 1);
2276 } 2245 }
2277 2246
2278 if (outstanding_puts > max_outstanding_puts) 2247 if (outstanding_puts > max_outstanding_puts)
2279 { 2248 {
2280 GNUNET_SCHEDULER_add_delayed ( 2249 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2281 GNUNET_TIME_relative_multiply ( 2250 (GNUNET_TIME_UNIT_MILLISECONDS, 200), &do_put,
2282 GNUNET_TIME_UNIT_MILLISECONDS, 2251 test_put);
2283 200), 2252 return;
2284 &do_put, test_put); 2253 }
2285 return;
2286 }
2287 2254
2288#if VERBOSE > 1 2255#if VERBOSE > 1
2289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n", 2256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
2290 test_put->uid, 2257 test_put->uid, test_put->daemon->shortname);
2291 test_put->daemon->shortname);
2292#endif 2258#endif
2293 test_put->dht_handle = GNUNET_DHT_connect (test_put->daemon->cfg, 10); 2259 test_put->dht_handle = GNUNET_DHT_connect (test_put->daemon->cfg, 10);
2294 2260
2295 GNUNET_assert(test_put->dht_handle != NULL); 2261 GNUNET_assert (test_put->dht_handle != NULL);
2296 outstanding_puts++; 2262 outstanding_puts++;
2297 GNUNET_DHT_put (test_put->dht_handle, &known_keys[test_put->uid], 2263 GNUNET_DHT_put (test_put->dht_handle, &known_keys[test_put->uid],
2298 put_replication, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, 2264 put_replication, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST,
2299 sizeof(data), data, GNUNET_TIME_UNIT_FOREVER_ABS, put_delay, 2265 sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, put_delay,
2300 &put_finished, test_put); 2266 &put_finished, test_put);
2301 test_put->disconnect_task 2267 test_put->disconnect_task
2302 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (), 2268 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
2303 &put_disconnect_task, test_put); 2269 &put_disconnect_task, test_put);
2304 rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2); 2270 rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
2305 GNUNET_SCHEDULER_add_delayed ( 2271 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2306 GNUNET_TIME_relative_multiply ( 2272 (GNUNET_TIME_UNIT_SECONDS, rand), &do_put,
2307 GNUNET_TIME_UNIT_SECONDS,
2308 rand), &do_put,
2309 test_put->next); 2273 test_put->next);
2310} 2274}
2311 2275
2312static void 2276static void
2313schedule_find_peer_requests(void *cls, 2277schedule_find_peer_requests (void *cls,
2314 const struct GNUNET_SCHEDULER_TaskContext * tc); 2278 const struct GNUNET_SCHEDULER_TaskContext *tc);
2315 2279
2316#if HAVE_MALICIOUS 2280#if HAVE_MALICIOUS
2317static void 2281static void
2318setup_malicious_peers(void *cls, 2282setup_malicious_peers (void *cls,
2319 const struct GNUNET_SCHEDULER_TaskContext * tc); 2283 const struct GNUNET_SCHEDULER_TaskContext *tc);
2320#endif 2284#endif
2321 2285
2322/** 2286/**
@@ -2324,19 +2288,20 @@ setup_malicious_peers(void *cls,
2324 * connections in a perfect kademlia topology. 2288 * connections in a perfect kademlia topology.
2325 */ 2289 */
2326static unsigned int 2290static unsigned int
2327connection_estimate(unsigned int peer_count, unsigned int bucket_size) 2291connection_estimate (unsigned int peer_count, unsigned int bucket_size)
2328{ 2292{
2329 unsigned int i; 2293 unsigned int i;
2330 unsigned int filled; 2294 unsigned int filled;
2295
2331 i = num_peers; 2296 i = num_peers;
2332 2297
2333 filled = 0; 2298 filled = 0;
2334 while (i >= bucket_size) 2299 while (i >= bucket_size)
2335 { 2300 {
2336 filled++; 2301 filled++;
2337 i = i / 2; 2302 i = i / 2;
2338 } 2303 }
2339 filled++; /* Add one filled bucket to account for one "half full" and some miscellaneous */ 2304 filled++; /* Add one filled bucket to account for one "half full" and some miscellaneous */
2340 return filled * bucket_size * peer_count; 2305 return filled * bucket_size * peer_count;
2341 2306
2342} 2307}
@@ -2345,56 +2310,57 @@ connection_estimate(unsigned int peer_count, unsigned int bucket_size)
2345 * Callback for iterating over all the peer connections of a peer group. 2310 * Callback for iterating over all the peer connections of a peer group.
2346 */ 2311 */
2347static void 2312static void
2348count_peers_cb(void *cls, const struct GNUNET_PeerIdentity *first, 2313count_peers_cb (void *cls, const struct GNUNET_PeerIdentity *first,
2349 const struct GNUNET_PeerIdentity *second, const char *emsg) 2314 const struct GNUNET_PeerIdentity *second, const char *emsg)
2350{ 2315{
2351 struct FindPeerContext *find_peer_context = cls; 2316 struct FindPeerContext *find_peer_context = cls;
2317
2352 if ((first != NULL) && (second != NULL)) 2318 if ((first != NULL) && (second != NULL))
2319 {
2320 add_new_connection (find_peer_context, first, second);
2321 find_peer_context->current_peers++;
2322 }
2323 else
2324 {
2325 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2326 "Peer count finished (%u connections), %u new peers, connection estimate %u (target %u)\n",
2327 find_peer_context->current_peers,
2328 find_peer_context->current_peers
2329 - find_peer_context->previous_peers,
2330 connection_estimate (num_peers, DEFAULT_BUCKET_SIZE),
2331 target_total_connections);
2332
2333 if ((find_peer_context->last_sent < 8)
2334 || ((find_peer_context->current_peers < 2
2335 * connection_estimate (num_peers, DEFAULT_BUCKET_SIZE))
2336 &&
2337 (GNUNET_TIME_absolute_get_remaining
2338 (find_peer_context->endtime).rel_value > 0) &&
2339 (find_peer_context->current_peers < target_total_connections)))
2353 { 2340 {
2354 add_new_connection (find_peer_context, first, second); 2341 GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests,
2355 find_peer_context->current_peers++; 2342 find_peer_context);
2356 } 2343 }
2357 else 2344 else
2358 { 2345 {
2359 GNUNET_log ( 2346 GNUNET_CONTAINER_multihashmap_iterate (find_peer_context->peer_hash,
2360 GNUNET_ERROR_TYPE_WARNING, 2347 &remove_peer_count,
2361 "Peer count finished (%u connections), %u new peers, connection estimate %u (target %u)\n", 2348 find_peer_context);
2362 find_peer_context->current_peers, 2349 GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
2363 find_peer_context->current_peers 2350 GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
2364 - find_peer_context->previous_peers, 2351 GNUNET_free (find_peer_context);
2365 connection_estimate (num_peers, DEFAULT_BUCKET_SIZE), 2352 fprintf (stderr, "Not sending any more find peer requests.\n");
2366 target_total_connections);
2367
2368 if ((find_peer_context->last_sent < 8)
2369 || ((find_peer_context->current_peers < 2
2370 * connection_estimate (num_peers, DEFAULT_BUCKET_SIZE))
2371 && (GNUNET_TIME_absolute_get_remaining (
2372 find_peer_context->endtime).rel_value
2373 > 0) && (find_peer_context->current_peers
2374 < target_total_connections)))
2375 {
2376 GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests,
2377 find_peer_context);
2378 }
2379 else
2380 {
2381 GNUNET_CONTAINER_multihashmap_iterate (find_peer_context->peer_hash,
2382 &remove_peer_count,
2383 find_peer_context);
2384 GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
2385 GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
2386 GNUNET_free(find_peer_context);
2387 fprintf (stderr, "Not sending any more find peer requests.\n");
2388 2353
2389#if HAVE_MALICIOUS 2354#if HAVE_MALICIOUS
2390 if (GNUNET_YES == malicious_after_settle) 2355 if (GNUNET_YES == malicious_after_settle)
2391 { 2356 {
2392 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "calling setup_malicious_peers\n"); 2357 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2393 GNUNET_SCHEDULER_add_now(&setup_malicious_peers, NULL); 2358 "calling setup_malicious_peers\n");
2394 } 2359 GNUNET_SCHEDULER_add_now (&setup_malicious_peers, NULL);
2360 }
2395#endif 2361#endif
2396 }
2397 } 2362 }
2363 }
2398} 2364}
2399 2365
2400/** 2366/**
@@ -2403,8 +2369,8 @@ count_peers_cb(void *cls, const struct GNUNET_PeerIdentity *first,
2403 * and the time allowed for each one! 2369 * and the time allowed for each one!
2404 */ 2370 */
2405static void 2371static void
2406schedule_find_peer_requests(void *cls, 2372schedule_find_peer_requests (void *cls,
2407 const struct GNUNET_SCHEDULER_TaskContext * tc) 2373 const struct GNUNET_SCHEDULER_TaskContext *tc)
2408{ 2374{
2409 struct FindPeerContext *find_peer_ctx = cls; 2375 struct FindPeerContext *find_peer_ctx = cls;
2410 struct TestFindPeer *test_find_peer; 2376 struct TestFindPeer *test_find_peer;
@@ -2412,12 +2378,11 @@ schedule_find_peer_requests(void *cls,
2412 uint32_t i; 2378 uint32_t i;
2413 uint32_t random; 2379 uint32_t random;
2414 2380
2415 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */ 2381 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
2416 find_peer_ctx->total = 1; 2382 find_peer_ctx->total = 1;
2417 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers 2383 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
2418 > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
2419 find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent 2384 find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent
2420 / 8); 2385 / 8);
2421 else 2386 else
2422 find_peer_ctx->total = find_peer_ctx->last_sent * 2; 2387 find_peer_ctx->total = find_peer_ctx->last_sent * 2;
2423 2388
@@ -2435,15 +2400,15 @@ schedule_find_peer_requests(void *cls,
2435 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay, 2400 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay,
2436 find_peer_ctx->total); 2401 find_peer_ctx->total);
2437 for (i = 0; i < find_peer_ctx->total; i++) 2402 for (i = 0; i < find_peer_ctx->total; i++)
2403 {
2404 test_find_peer = GNUNET_malloc (sizeof (struct TestFindPeer));
2405 /* If we haven't sent any requests yet, choose random peers */
2406 /* Also choose random in _half_ of all cases, so we don't
2407 * get stuck choosing topologically restricted peers with
2408 * few connections that will never be able to find any new
2409 * peers! */
2410 if ((find_peer_ctx->previous_peers == 0) || (i % 2 == 0))
2438 { 2411 {
2439 test_find_peer = GNUNET_malloc(sizeof(struct TestFindPeer));
2440 /* If we haven't sent any requests yet, choose random peers */
2441 /* Also choose random in _half_ of all cases, so we don't
2442 * get stuck choosing topologically restricted peers with
2443 * few connections that will never be able to find any new
2444 * peers! */
2445 if ((find_peer_ctx->previous_peers == 0) || (i % 2 == 0))
2446 {
2447 /** 2412 /**
2448 * Attempt to spread find peer requests across even sections of the peer address 2413 * Attempt to spread find peer requests across even sections of the peer address
2449 * space. Choose basically 1 peer in every num_peers / max_outstanding_requests 2414 * space. Choose basically 1 peer in every num_peers / max_outstanding_requests
@@ -2452,56 +2417,57 @@ schedule_find_peer_requests(void *cls,
2452 * For instance, if num_peers is 100 and max_outstanding is 10, first chosen peer 2417 * For instance, if num_peers is 100 and max_outstanding is 10, first chosen peer
2453 * will be between 0 - 10, second between 10 - 20, etc. 2418 * will be between 0 - 10, second between 10 - 20, etc.
2454 */ 2419 */
2455 random = (num_peers / find_peer_ctx->total) * i; 2420 random = (num_peers / find_peer_ctx->total) * i;
2456 random = random 2421 random = random
2457 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2422 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2458 (num_peers / find_peer_ctx->total)); 2423 (num_peers / find_peer_ctx->total));
2459 if (random >= num_peers) 2424 if (random >= num_peers)
2460 { 2425 {
2461 random = random - num_peers; 2426 random = random - num_peers;
2462 } 2427 }
2463#if REAL_RANDOM 2428#if REAL_RANDOM
2464 random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 2429 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2465#endif 2430#endif
2466 test_find_peer->daemon = GNUNET_TESTING_daemon_get (pg, random); 2431 test_find_peer->daemon = GNUNET_TESTING_daemon_get (pg, random);
2467 }
2468 else /* If we have sent requests, choose peers with a low number of connections to send requests from */
2469 {
2470 peer_count
2471 = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap);
2472 GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(find_peer_ctx->peer_hash, &peer_count->peer_id.hashPubKey, peer_count));
2473 test_find_peer->daemon
2474 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
2475 GNUNET_assert(test_find_peer->daemon != NULL);
2476 }
2477
2478 test_find_peer->find_peer_context = find_peer_ctx;
2479 GNUNET_SCHEDULER_add_delayed (
2480 GNUNET_TIME_relative_multiply (
2481 find_peer_offset,
2482 i),
2483 &send_find_peer_request, test_find_peer);
2484 } 2432 }
2485 2433 else /* If we have sent requests, choose peers with a low number of connections to send requests from */
2486 if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap
2487 == NULL))
2488 { 2434 {
2489 find_peer_ctx->peer_hash 2435 peer_count
2490 = GNUNET_CONTAINER_multihashmap_create (num_peers); 2436 = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap);
2491 find_peer_ctx->peer_min_heap 2437 GNUNET_assert (GNUNET_YES ==
2492 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2438 GNUNET_CONTAINER_multihashmap_remove
2439 (find_peer_ctx->peer_hash, &peer_count->peer_id.hashPubKey,
2440 peer_count));
2441 test_find_peer->daemon =
2442 GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
2443 GNUNET_assert (test_find_peer->daemon != NULL);
2493 } 2444 }
2445
2446 test_find_peer->find_peer_context = find_peer_ctx;
2447 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2448 (find_peer_offset, i),
2449 &send_find_peer_request, test_find_peer);
2450 }
2451
2452 if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap
2453 == NULL))
2454 {
2455 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create (num_peers);
2456 find_peer_ctx->peer_min_heap
2457 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2458 }
2494 else 2459 else
2495 { 2460 {
2496 GNUNET_CONTAINER_multihashmap_iterate (find_peer_ctx->peer_hash, 2461 GNUNET_CONTAINER_multihashmap_iterate (find_peer_ctx->peer_hash,
2497 &remove_peer_count, find_peer_ctx); 2462 &remove_peer_count, find_peer_ctx);
2498 GNUNET_CONTAINER_multihashmap_destroy (find_peer_ctx->peer_hash); 2463 GNUNET_CONTAINER_multihashmap_destroy (find_peer_ctx->peer_hash);
2499 find_peer_ctx->peer_hash 2464 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create (num_peers);
2500 = GNUNET_CONTAINER_multihashmap_create (num_peers); 2465 }
2501 }
2502 2466
2503 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(find_peer_ctx->peer_hash)); 2467 GNUNET_assert (0 ==
2504 GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(find_peer_ctx->peer_min_heap)); 2468 GNUNET_CONTAINER_multihashmap_size (find_peer_ctx->peer_hash));
2469 GNUNET_assert (0 ==
2470 GNUNET_CONTAINER_heap_get_size (find_peer_ctx->peer_min_heap));
2505 2471
2506} 2472}
2507 2473
@@ -2512,9 +2478,9 @@ schedule_find_peer_requests(void *cls,
2512 * @param hash set to uid (extended with zeros) 2478 * @param hash set to uid (extended with zeros)
2513 */ 2479 */
2514static void 2480static void
2515hash_from_uid(uint32_t uid, GNUNET_HashCode *hash) 2481hash_from_uid (uint32_t uid, GNUNET_HashCode * hash)
2516{ 2482{
2517 memset (hash, 0, sizeof(GNUNET_HashCode)); 2483 memset (hash, 0, sizeof (GNUNET_HashCode));
2518 *((uint32_t *) hash) = uid; 2484 *((uint32_t *) hash) = uid;
2519} 2485}
2520 2486
@@ -2524,7 +2490,7 @@ hash_from_uid(uint32_t uid, GNUNET_HashCode *hash)
2524 * add to list, then schedule the actual PUT operations. 2490 * add to list, then schedule the actual PUT operations.
2525 */ 2491 */
2526static void 2492static void
2527setup_puts_and_gets(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2493setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2528{ 2494{
2529 int i; 2495 int i;
2530 struct TestPutContext *test_put; 2496 struct TestPutContext *test_put;
@@ -2532,98 +2498,99 @@ setup_puts_and_gets(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2532 uint32_t temp_peer; 2498 uint32_t temp_peer;
2533 GNUNET_HashCode uid_hash; 2499 GNUNET_HashCode uid_hash;
2534 int count; 2500 int count;
2501
2535#if REMEMBER 2502#if REMEMBER
2536 int remember[num_puts][num_peers]; 2503 int remember[num_puts][num_peers];
2537 memset(&remember, 0, sizeof(int) * num_puts * num_peers); 2504
2505 memset (&remember, 0, sizeof (int) * num_puts * num_peers);
2538#endif 2506#endif
2539 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in setup_puts_and_gets\n"); 2507 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in setup_puts_and_gets\n");
2540 known_keys = GNUNET_malloc(sizeof(GNUNET_HashCode) * num_puts); 2508 known_keys = GNUNET_malloc (sizeof (GNUNET_HashCode) * num_puts);
2541 for (i = 0; i < num_puts; i++) 2509 for (i = 0; i < num_puts; i++)
2510 {
2511 test_put = GNUNET_malloc (sizeof (struct TestPutContext));
2512 test_put->uid = i;
2513 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
2514 &known_keys[i]);
2515 /* Set first X bits to match the chosen sybil location if we want to do the sybil attack! */
2516 if (GNUNET_YES == malicious_sybil)
2542 { 2517 {
2543 test_put = GNUNET_malloc(sizeof(struct TestPutContext)); 2518 memcpy (&known_keys[i], &sybil_target, sizeof (GNUNET_HashCode) / 2);
2544 test_put->uid = i; 2519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2545 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 2520 "Distance between sybil location and key is %d\n",
2546 &known_keys[i]); 2521 GNUNET_CRYPTO_hash_matching_bits (&known_keys[i],
2547 /* Set first X bits to match the chosen sybil location if we want to do the sybil attack! */ 2522 &sybil_target));
2548 if (GNUNET_YES == malicious_sybil) 2523 }
2549 { 2524 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2550 memcpy (&known_keys[i], &sybil_target, sizeof(GNUNET_HashCode) / 2); 2525 num_peers);
2551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2526 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2552 "Distance between sybil location and key is %d\n", 2527 /* Don't start PUTs at malicious peers! */
2553 GNUNET_CRYPTO_hash_matching_bits (&known_keys[i], 2528 if (malicious_bloom != NULL)
2554 &sybil_target)); 2529 {
2555 } 2530 count = 0;
2556 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2531 hash_from_uid (temp_peer, &uid_hash);
2557 num_peers); 2532 while ((GNUNET_YES
2558 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2559 /* Don't start PUTs at malicious peers! */
2560 if (malicious_bloom != NULL)
2561 {
2562 count = 0;
2563 hash_from_uid (temp_peer, &uid_hash);
2564 while ((GNUNET_YES
2565 == GNUNET_CONTAINER_bloomfilter_test (malicious_bloom, &uid_hash)) 2533 == GNUNET_CONTAINER_bloomfilter_test (malicious_bloom, &uid_hash))
2566 && (count < num_peers)) 2534 && (count < num_peers))
2567 { 2535 {
2568 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2536 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2569 num_peers); 2537 num_peers);
2570 hash_from_uid (temp_peer, &uid_hash); 2538 hash_from_uid (temp_peer, &uid_hash);
2571 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer); 2539 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2572 count++; 2540 count++;
2573 } 2541 }
2574 if (count == num_peers) 2542 if (count == num_peers)
2575 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2543 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2576 "Couldn't find peer not in malicious bloom to select!\n"); 2544 "Couldn't find peer not in malicious bloom to select!\n");
2577 }
2578
2579 test_put->next = all_puts;
2580 all_puts = test_put;
2581 } 2545 }
2582 2546
2547 test_put->next = all_puts;
2548 all_puts = test_put;
2549 }
2550
2583 for (i = 0; i < num_gets; i++) 2551 for (i = 0; i < num_gets; i++)
2584 { 2552 {
2585 test_get = GNUNET_malloc(sizeof(struct TestGetContext)); 2553 test_get = GNUNET_malloc (sizeof (struct TestGetContext));
2586 test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2554 test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2587 num_puts); 2555 num_puts);
2588#if REMEMBER 2556#if REMEMBER
2589 while (remember[test_get->uid][temp_daemon] == 1) 2557 while (remember[test_get->uid][temp_daemon] == 1)
2590 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 2558 temp_daemon =
2591 remember[test_get->uid][temp_daemon] = 1; 2559 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2560 remember[test_get->uid][temp_daemon] = 1;
2592#endif 2561#endif
2593 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2562 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2594 num_peers); 2563 num_peers);
2595 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer); 2564 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2596 /* Don't start GETs at malicious peers! */ 2565 /* Don't start GETs at malicious peers! */
2597 if (malicious_bloom != NULL) 2566 if (malicious_bloom != NULL)
2598 { 2567 {
2599 hash_from_uid (temp_peer, &uid_hash); 2568 hash_from_uid (temp_peer, &uid_hash);
2600 count = 0; 2569 count = 0;
2601 while ((GNUNET_YES 2570 while ((GNUNET_YES
2602 == GNUNET_CONTAINER_bloomfilter_test (malicious_bloom, &uid_hash)) 2571 == GNUNET_CONTAINER_bloomfilter_test (malicious_bloom, &uid_hash))
2603 && (count < num_peers)) 2572 && (count < num_peers))
2604 { 2573 {
2605 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2574 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2606 num_peers); 2575 num_peers);
2607 hash_from_uid (temp_peer, &uid_hash); 2576 hash_from_uid (temp_peer, &uid_hash);
2608 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer); 2577 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2609 count++; 2578 count++;
2610 } 2579 }
2611 if (count == num_peers) 2580 if (count == num_peers)
2612 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2613 "Couldn't find peer not in malicious bloom to select!\n"); 2582 "Couldn't find peer not in malicious bloom to select!\n");
2614 }
2615 test_get->next = all_gets;
2616 all_gets = test_get;
2617 } 2583 }
2584 test_get->next = all_gets;
2585 all_gets = test_get;
2586 }
2618 2587
2619 /*GNUNET_SCHEDULER_cancel (die_task);*/ 2588 /*GNUNET_SCHEDULER_cancel (die_task); */
2620 die_task 2589 die_task
2621 = GNUNET_SCHEDULER_add_delayed ( 2590 =
2622 GNUNET_TIME_relative_multiply ( 2591 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2623 GNUNET_TIME_UNIT_SECONDS, 2592 (GNUNET_TIME_UNIT_SECONDS, num_puts * 2),
2624 num_puts 2593 &end_badly, "from do puts");
2625 * 2),
2626 &end_badly, "from do puts");
2627 GNUNET_SCHEDULER_add_now (&do_put, all_puts); 2594 GNUNET_SCHEDULER_add_now (&do_put, all_puts);
2628 2595
2629} 2596}
@@ -2634,105 +2601,100 @@ setup_puts_and_gets(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2634 * then call actual insert functions. 2601 * then call actual insert functions.
2635 */ 2602 */
2636static void 2603static void
2637continue_puts_and_gets(void *cls, 2604continue_puts_and_gets (void *cls,
2638 const struct GNUNET_SCHEDULER_TaskContext * tc) 2605 const struct GNUNET_SCHEDULER_TaskContext *tc)
2639{ 2606{
2640 int i; 2607 int i;
2641 int max; 2608 int max;
2642 struct TopologyIteratorContext *topo_ctx; 2609 struct TopologyIteratorContext *topo_ctx;
2643 struct FindPeerContext *find_peer_context; 2610 struct FindPeerContext *find_peer_context;
2611
2644 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "In continue_puts_and_gets\n"); 2612 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "In continue_puts_and_gets\n");
2645 if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal)) 2613 if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
2614 {
2615 if (settle_time >= 180 * 2)
2616 max = (settle_time / 180) - 2;
2617 else
2618 max = 1;
2619 for (i = 1; i < max; i++)
2646 { 2620 {
2647 if (settle_time >= 180 * 2) 2621 topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
2648 max = (settle_time / 180) - 2; 2622 topo_ctx->current_iteration = i;
2649 else 2623 topo_ctx->total_iterations = max;
2650 max = 1;
2651 for (i = 1; i < max; i++)
2652 {
2653 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
2654 topo_ctx->current_iteration = i;
2655 topo_ctx->total_iterations = max;
2656 topo_ctx->peers_seen
2657 = GNUNET_CONTAINER_multihashmap_create (num_peers);
2658 //fprintf(stderr, "scheduled topology iteration in %d minutes\n", i);
2659 GNUNET_SCHEDULER_add_delayed (
2660 GNUNET_TIME_relative_multiply (
2661 GNUNET_TIME_UNIT_MINUTES,
2662 i * 3),
2663 &capture_current_topology, topo_ctx);
2664 }
2665 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
2666 topo_ctx->cont = &setup_puts_and_gets;
2667 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers); 2624 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
2668 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2625 //fprintf(stderr, "scheduled topology iteration in %d minutes\n", i);
2669 "setting setup_puts_and_gets for %d seconds in the future\n", 2626 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2670 settle_time + 10); 2627 (GNUNET_TIME_UNIT_MINUTES, i * 3),
2671 GNUNET_SCHEDULER_add_delayed (
2672 GNUNET_TIME_relative_multiply (
2673 GNUNET_TIME_UNIT_SECONDS,
2674 (settle_time
2675 + 10)),
2676 &capture_current_topology, topo_ctx); 2628 &capture_current_topology, topo_ctx);
2677 } 2629 }
2630 topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
2631 topo_ctx->cont = &setup_puts_and_gets;
2632 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
2633 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2634 "setting setup_puts_and_gets for %d seconds in the future\n",
2635 settle_time + 10);
2636 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2637 (GNUNET_TIME_UNIT_SECONDS,
2638 (settle_time + 10)),
2639 &capture_current_topology, topo_ctx);
2640 }
2678 else 2641 else
2679 GNUNET_SCHEDULER_add_delayed ( 2642 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2680 GNUNET_TIME_relative_multiply ( 2643 (GNUNET_TIME_UNIT_SECONDS,
2681 GNUNET_TIME_UNIT_SECONDS, 2644 (settle_time + 10)), &setup_puts_and_gets,
2682 (settle_time 2645 NULL);
2683 + 10)),
2684 &setup_puts_and_gets, NULL);
2685 2646
2686 if (dhtlog_handle != NULL) 2647 if (dhtlog_handle != NULL)
2687 dhtlog_handle->insert_round (DHT_ROUND_NORMAL, rounds_finished); 2648 dhtlog_handle->insert_round (DHT_ROUND_NORMAL, rounds_finished);
2688 2649
2689#if HAVE_MALICIOUS 2650#if HAVE_MALICIOUS
2690 if ((GNUNET_YES != malicious_after_settle) || (settle_time == 0)) 2651 if ((GNUNET_YES != malicious_after_settle) || (settle_time == 0))
2691 { 2652 {
2692 GNUNET_SCHEDULER_add_now(&setup_malicious_peers, NULL); 2653 GNUNET_SCHEDULER_add_now (&setup_malicious_peers, NULL);
2693 } 2654 }
2694#endif 2655#endif
2695 2656
2696 if ((GNUNET_YES == do_find_peer) && (settle_time > 0)) 2657 if ((GNUNET_YES == do_find_peer) && (settle_time > 0))
2697 { 2658 {
2698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2699 "Scheduling find peer requests during \"settle\" time.\n"); 2660 "Scheduling find peer requests during \"settle\" time.\n");
2700 find_peer_context = GNUNET_malloc(sizeof(struct FindPeerContext)); 2661 find_peer_context = GNUNET_malloc (sizeof (struct FindPeerContext));
2701 find_peer_context->count_peers_cb = &count_peers_cb; 2662 find_peer_context->count_peers_cb = &count_peers_cb;
2702 find_peer_context->endtime 2663 find_peer_context->endtime
2703 = GNUNET_TIME_relative_to_absolute ( 2664 =
2704 GNUNET_TIME_relative_multiply ( 2665 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
2705 GNUNET_TIME_UNIT_SECONDS, 2666 (GNUNET_TIME_UNIT_SECONDS,
2706 settle_time)); 2667 settle_time));
2707 GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests, find_peer_context); 2668 GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests, find_peer_context);
2708 } 2669 }
2709 else 2670 else
2710 { 2671 {
2711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2712 "Assuming automatic DHT find peer requests.\n"); 2673 "Assuming automatic DHT find peer requests.\n");
2713 } 2674 }
2714} 2675}
2715 2676
2716/** 2677/**
2717 * Task to release DHT handles 2678 * Task to release DHT handles
2718 */ 2679 */
2719static void 2680static void
2720malicious_disconnect_task(void *cls, 2681malicious_disconnect_task (void *cls,
2721 const struct GNUNET_SCHEDULER_TaskContext * tc) 2682 const struct GNUNET_SCHEDULER_TaskContext *tc)
2722{ 2683{
2723 struct MaliciousContext *ctx = cls; 2684 struct MaliciousContext *ctx = cls;
2685
2724 outstanding_malicious--; 2686 outstanding_malicious--;
2725 malicious_completed++; 2687 malicious_completed++;
2726 ctx->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 2688 ctx->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
2727 GNUNET_DHT_disconnect (ctx->dht_handle); 2689 GNUNET_DHT_disconnect (ctx->dht_handle);
2728 ctx->dht_handle = NULL; 2690 ctx->dht_handle = NULL;
2729 GNUNET_free(ctx); 2691 GNUNET_free (ctx);
2730 2692
2731 if (malicious_completed == malicious_getters + malicious_putters 2693 if (malicious_completed == malicious_getters + malicious_putters
2732 + malicious_droppers) 2694 + malicious_droppers)
2733 { 2695 {
2734 fprintf (stderr, "Finished setting all malicious peers up!\n"); 2696 fprintf (stderr, "Finished setting all malicious peers up!\n");
2735 } 2697 }
2736} 2698}
2737 2699
2738#if HAVE_MALICIOUS 2700#if HAVE_MALICIOUS
@@ -2740,64 +2702,66 @@ malicious_disconnect_task(void *cls,
2740 * Task to release DHT handles 2702 * Task to release DHT handles
2741 */ 2703 */
2742static void 2704static void
2743malicious_done_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2705malicious_done_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2744 { 2706{
2745 struct MaliciousContext *ctx = cls; 2707 struct MaliciousContext *ctx = cls;
2746 GNUNET_SCHEDULER_cancel (ctx->disconnect_task); 2708
2747 GNUNET_SCHEDULER_add_now (&malicious_disconnect_task, ctx); 2709 GNUNET_SCHEDULER_cancel (ctx->disconnect_task);
2748 } 2710 GNUNET_SCHEDULER_add_now (&malicious_disconnect_task, ctx);
2711}
2749 2712
2750/** 2713/**
2751 * Set up some data, and call API PUT function 2714 * Set up some data, and call API PUT function
2752 */ 2715 */
2753static void 2716static void
2754set_malicious(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2717set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2755 { 2718{
2756 struct MaliciousContext *ctx = cls; 2719 struct MaliciousContext *ctx = cls;
2757 2720
2758 if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS) 2721 if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS)
2759 { 2722 {
2760 GNUNET_SCHEDULER_add_delayed ( 2723 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2761 GNUNET_TIME_relative_multiply ( 2724 (GNUNET_TIME_UNIT_MILLISECONDS, 100),
2762 GNUNET_TIME_UNIT_MILLISECONDS, 2725 &set_malicious, ctx);
2763 100), 2726 return;
2764 &set_malicious, ctx); 2727 }
2765 return;
2766 }
2767 2728
2768 if (ctx->dht_handle == NULL) 2729 if (ctx->dht_handle == NULL)
2769 { 2730 {
2770 ctx->dht_handle = GNUNET_DHT_connect (ctx->daemon->cfg, 1); 2731 ctx->dht_handle = GNUNET_DHT_connect (ctx->daemon->cfg, 1);
2771 outstanding_malicious++; 2732 outstanding_malicious++;
2772 } 2733 }
2773 2734
2774 GNUNET_assert(ctx->dht_handle != NULL); 2735 GNUNET_assert (ctx->dht_handle != NULL);
2775 2736
2776#if VERBOSE > 1 2737#if VERBOSE > 1
2777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting peer %s malicious type %d\n", 2738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting peer %s malicious type %d\n",
2778 ctx->daemon->shortname, ctx->malicious_type); 2739 ctx->daemon->shortname, ctx->malicious_type);
2779#endif 2740#endif
2780 2741
2781 switch (ctx->malicious_type) 2742 switch (ctx->malicious_type)
2782 { 2743 {
2783 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET: 2744 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
2784 GNUNET_DHT_set_malicious_getter (ctx->dht_handle, malicious_get_frequency, &malicious_done_task, ctx); 2745 GNUNET_DHT_set_malicious_getter (ctx->dht_handle, malicious_get_frequency,
2785 break; 2746 &malicious_done_task, ctx);
2786 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT: 2747 break;
2787 GNUNET_DHT_set_malicious_putter (ctx->dht_handle, malicious_put_frequency, &malicious_done_task, ctx); 2748 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
2788 break; 2749 GNUNET_DHT_set_malicious_putter (ctx->dht_handle, malicious_put_frequency,
2789 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP: 2750 &malicious_done_task, ctx);
2790 GNUNET_DHT_set_malicious_dropper (ctx->dht_handle, &malicious_done_task, ctx); 2751 break;
2791 break; 2752 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
2792 default: 2753 GNUNET_DHT_set_malicious_dropper (ctx->dht_handle, &malicious_done_task,
2793 break; 2754 ctx);
2794 } 2755 break;
2795 2756 default:
2796 ctx->disconnect_task 2757 break;
2797 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2798 &malicious_disconnect_task, ctx);
2799 } 2758 }
2800 2759
2760 ctx->disconnect_task
2761 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2762 &malicious_disconnect_task, ctx);
2763}
2764
2801/** 2765/**
2802 * Choose the next peer from the peer group to set as malicious. 2766 * Choose the next peer from the peer group to set as malicious.
2803 * If we are doing a sybil attack, find the nearest peer to the 2767 * If we are doing a sybil attack, find the nearest peer to the
@@ -2809,57 +2773,70 @@ set_malicious(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2809 * chosen to be malicious 2773 * chosen to be malicious
2810 */ 2774 */
2811static uint32_t 2775static uint32_t
2812choose_next_malicious (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_CONTAINER_BloomFilter *bloom) 2776choose_next_malicious (struct GNUNET_TESTING_PeerGroup *pg,
2813 { 2777 struct GNUNET_CONTAINER_BloomFilter *bloom)
2814 int i; 2778{
2815 int nearest; 2779 int i;
2816 int bits_match; 2780 int nearest;
2817 int curr_distance; 2781 int bits_match;
2818 int count; 2782 int curr_distance;
2819 struct GNUNET_TESTING_Daemon *temp_daemon; 2783 int count;
2820 GNUNET_HashCode uid_hash; 2784 struct GNUNET_TESTING_Daemon *temp_daemon;
2821 2785 GNUNET_HashCode uid_hash;
2822 curr_distance = 0;
2823 nearest = 0;
2824 GNUNET_assert (bloom != NULL);
2825 2786
2826 if (GNUNET_YES == malicious_sybil) 2787 curr_distance = 0;
2827 { 2788 nearest = 0;
2828 for (i = 0; i < num_peers; i++) 2789 GNUNET_assert (bloom != NULL);
2829 { 2790
2830 temp_daemon = GNUNET_TESTING_daemon_get(pg, i); 2791 if (GNUNET_YES == malicious_sybil)
2831 hash_from_uid(i, &uid_hash); 2792 {
2832 /* Check if this peer matches the bloomfilter */ 2793 for (i = 0; i < num_peers; i++)
2833 if ((GNUNET_NO == GNUNET_TESTING_daemon_running(temp_daemon)) || (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash))) 2794 {
2834 continue; 2795 temp_daemon = GNUNET_TESTING_daemon_get (pg, i);
2835 2796 hash_from_uid (i, &uid_hash);
2836 bits_match = GNUNET_CRYPTO_hash_matching_bits (&temp_daemon->id.hashPubKey, &sybil_target); 2797 /* Check if this peer matches the bloomfilter */
2837 if (bits_match >= curr_distance) 2798 if ((GNUNET_NO == GNUNET_TESTING_daemon_running (temp_daemon)) ||
2838 { 2799 (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash)))
2839 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found nearer peer %s to %s, old matching bits %d, new %d\n", GNUNET_i2s(&temp_daemon->id), GNUNET_h2s(&sybil_target), curr_distance, bits_match); 2800 continue;
2840 nearest = i; 2801
2841 curr_distance = bits_match; 2802 bits_match =
2842 } 2803 GNUNET_CRYPTO_hash_matching_bits (&temp_daemon->id.hashPubKey,
2843 } 2804 &sybil_target);
2844 } 2805 if (bits_match >= curr_distance)
2845 else
2846 { 2806 {
2847 nearest = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 2807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2848 hash_from_uid(nearest, &uid_hash); 2808 "Found nearer peer %s to %s, old matching bits %d, new %d\n",
2849 count = 0; 2809 GNUNET_i2s (&temp_daemon->id), GNUNET_h2s (&sybil_target),
2850 while ((GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash)) && (count < num_peers)) 2810 curr_distance, bits_match);
2851 { 2811 nearest = i;
2852 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer %d already in bloom (tried %d times)\n", nearest, count); 2812 curr_distance = bits_match;
2853 nearest = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2854 hash_from_uid(nearest, &uid_hash);
2855 count++;
2856 }
2857 if (count == num_peers)
2858 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Tried %d times to find a peer, selecting %d at random!!\n", count, nearest);
2859 } 2813 }
2860 2814 }
2861 return nearest;
2862 } 2815 }
2816 else
2817 {
2818 nearest = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2819 hash_from_uid (nearest, &uid_hash);
2820 count = 0;
2821 while ((GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash))
2822 && (count < num_peers))
2823 {
2824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2825 "Peer %d already in bloom (tried %d times)\n", nearest,
2826 count);
2827 nearest =
2828 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2829 hash_from_uid (nearest, &uid_hash);
2830 count++;
2831 }
2832 if (count == num_peers)
2833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2834 "Tried %d times to find a peer, selecting %d at random!!\n",
2835 count, nearest);
2836 }
2837
2838 return nearest;
2839}
2863 2840
2864/** 2841/**
2865 * Select randomly from set of known peers, 2842 * Select randomly from set of known peers,
@@ -2867,62 +2844,62 @@ choose_next_malicious (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_CONTAI
2867 * proper malicious types. 2844 * proper malicious types.
2868 */ 2845 */
2869static void 2846static void
2870setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2847setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2871 { 2848{
2872 struct MaliciousContext *ctx; 2849 struct MaliciousContext *ctx;
2873 int i; 2850 int i;
2874 uint32_t temp_daemon; 2851 uint32_t temp_daemon;
2875 GNUNET_HashCode uid_hash; 2852 GNUNET_HashCode uid_hash;
2876 2853
2877 for (i = 0; i < malicious_getters; i++) 2854 for (i = 0; i < malicious_getters; i++)
2878 { 2855 {
2879 ctx = GNUNET_malloc(sizeof(struct MaliciousContext)); 2856 ctx = GNUNET_malloc (sizeof (struct MaliciousContext));
2880 temp_daemon = choose_next_malicious(pg, malicious_bloom); 2857 temp_daemon = choose_next_malicious (pg, malicious_bloom);
2881 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon); 2858 ctx->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
2882 hash_from_uid(temp_daemon, &uid_hash); 2859 hash_from_uid (temp_daemon, &uid_hash);
2883 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash); 2860 GNUNET_CONTAINER_bloomfilter_add (malicious_bloom, &uid_hash);
2884 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET; 2861 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET;
2885 GNUNET_SCHEDULER_add_now (&set_malicious, ctx); 2862 GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
2886 2863
2887 } 2864 }
2888 2865
2889 for (i = 0; i < malicious_putters; i++) 2866 for (i = 0; i < malicious_putters; i++)
2890 { 2867 {
2891 ctx = GNUNET_malloc(sizeof(struct MaliciousContext)); 2868 ctx = GNUNET_malloc (sizeof (struct MaliciousContext));
2892 temp_daemon = choose_next_malicious(pg, malicious_bloom); 2869 temp_daemon = choose_next_malicious (pg, malicious_bloom);
2893 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon); 2870 ctx->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
2894 hash_from_uid(temp_daemon, &uid_hash); 2871 hash_from_uid (temp_daemon, &uid_hash);
2895 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash); 2872 GNUNET_CONTAINER_bloomfilter_add (malicious_bloom, &uid_hash);
2896 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT; 2873 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT;
2897 GNUNET_SCHEDULER_add_now (&set_malicious, ctx); 2874 GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
2898 2875
2899 } 2876 }
2900 2877
2901 for (i = 0; i < malicious_droppers; i++) 2878 for (i = 0; i < malicious_droppers; i++)
2902 { 2879 {
2903 ctx = GNUNET_malloc(sizeof(struct MaliciousContext)); 2880 ctx = GNUNET_malloc (sizeof (struct MaliciousContext));
2904 temp_daemon = choose_next_malicious(pg, malicious_bloom); 2881 temp_daemon = choose_next_malicious (pg, malicious_bloom);
2905 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon); 2882 ctx->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
2906 hash_from_uid(temp_daemon, &uid_hash); 2883 hash_from_uid (temp_daemon, &uid_hash);
2907 GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash); 2884 GNUNET_CONTAINER_bloomfilter_add (malicious_bloom, &uid_hash);
2908 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP; 2885 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP;
2909 GNUNET_SCHEDULER_add_now (&set_malicious, ctx); 2886 GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
2910 }
2911 } 2887 }
2888}
2912#endif 2889#endif
2913 2890
2914#if ONLY_TESTING 2891#if ONLY_TESTING
2915/* Forward declaration */ 2892/* Forward declaration */
2916static void 2893static void
2917topology_callback (void *cls, 2894topology_callback (void *cls,
2918 const struct GNUNET_PeerIdentity *first, 2895 const struct GNUNET_PeerIdentity *first,
2919 const struct GNUNET_PeerIdentity *second, 2896 const struct GNUNET_PeerIdentity *second,
2920 uint32_t distance, 2897 uint32_t distance,
2921 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 2898 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
2922 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 2899 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
2923 struct GNUNET_TESTING_Daemon *first_daemon, 2900 struct GNUNET_TESTING_Daemon *first_daemon,
2924 struct GNUNET_TESTING_Daemon *second_daemon, 2901 struct GNUNET_TESTING_Daemon *second_daemon,
2925 const char *emsg); 2902 const char *emsg);
2926 2903
2927/** 2904/**
2928 * Retry connecting two specific peers until they connect, 2905 * Retry connecting two specific peers until they connect,
@@ -2931,19 +2908,24 @@ topology_callback (void *cls,
2931 * debug the reason they are having issues. 2908 * debug the reason they are having issues.
2932 */ 2909 */
2933static void 2910static void
2934repeat_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 2911repeat_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2935 { 2912{
2936
2937 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Repeating connect attempt between %s and %s.\n", repeat_connect_peer1->shortname, repeat_connect_peer2->shortname);
2938 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer 1 configuration `%s'\n", repeat_connect_peer1->cfgfile);
2939 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer 2 configuration `%s'\n", repeat_connect_peer2->cfgfile);
2940 2913
2941 repeat_connect_task = GNUNET_SCHEDULER_NO_TASK; 2914 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2942 GNUNET_TESTING_daemons_connect(repeat_connect_peer1, 2915 "Repeating connect attempt between %s and %s.\n",
2943 repeat_connect_peer2, 2916 repeat_connect_peer1->shortname, repeat_connect_peer2->shortname);
2944 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), 2917 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peer 1 configuration `%s'\n",
2945 2, &topology_callback, NULL); 2918 repeat_connect_peer1->cfgfile);
2946 } 2919 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peer 2 configuration `%s'\n",
2920 repeat_connect_peer2->cfgfile);
2921
2922 repeat_connect_task = GNUNET_SCHEDULER_NO_TASK;
2923 GNUNET_TESTING_daemons_connect (repeat_connect_peer1,
2924 repeat_connect_peer2,
2925 GNUNET_TIME_relative_multiply
2926 (GNUNET_TIME_UNIT_SECONDS, 60), 2,
2927 &topology_callback, NULL);
2928}
2947#endif 2929#endif
2948 2930
2949/** 2931/**
@@ -2956,12 +2938,13 @@ repeat_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2956 * failure (peers failed to connect). 2938 * failure (peers failed to connect).
2957 */ 2939 */
2958static void 2940static void
2959topology_callback(void *cls, const struct GNUNET_PeerIdentity *first, 2941topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
2960 const struct GNUNET_PeerIdentity *second, uint32_t distance, 2942 const struct GNUNET_PeerIdentity *second, uint32_t distance,
2961 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 2943 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
2962 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 2944 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
2963 struct GNUNET_TESTING_Daemon *first_daemon, 2945 struct GNUNET_TESTING_Daemon *first_daemon,
2964 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) 2946 struct GNUNET_TESTING_Daemon *second_daemon,
2947 const char *emsg)
2965{ 2948{
2966 struct TopologyIteratorContext *topo_ctx; 2949 struct TopologyIteratorContext *topo_ctx;
2967 uint64_t duration; 2950 uint64_t duration;
@@ -2978,314 +2961,318 @@ topology_callback(void *cls, const struct GNUNET_PeerIdentity *first,
2978 2961
2979#if ONLY_TESTING 2962#if ONLY_TESTING
2980 if (repeat_connect_mode == GNUNET_YES) 2963 if (repeat_connect_mode == GNUNET_YES)
2964 {
2965 if ((first_daemon == repeat_connect_peer1) &&
2966 (second_daemon == repeat_connect_peer2))
2981 { 2967 {
2982 if ((first_daemon == repeat_connect_peer1) && 2968 if (emsg != NULL) /* Peers failed to connect again! */
2983 (second_daemon == repeat_connect_peer2)) 2969 {
2984 { 2970 GNUNET_assert (repeat_connect_task == GNUNET_SCHEDULER_NO_TASK);
2985 if (emsg != NULL) /* Peers failed to connect again! */ 2971 repeat_connect_task =
2986 { 2972 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2987 GNUNET_assert(repeat_connect_task == GNUNET_SCHEDULER_NO_TASK); 2973 (GNUNET_TIME_UNIT_SECONDS, 60),
2988 repeat_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), &repeat_connect, NULL); 2974 &repeat_connect, NULL);
2989 return; 2975 return;
2990 } 2976 }
2991 else /* Repeat peers actually connected! */ 2977 else /* Repeat peers actually connected! */
2992 { 2978 {
2993 if (repeat_connect_task != GNUNET_SCHEDULER_NO_TASK) 2979 if (repeat_connect_task != GNUNET_SCHEDULER_NO_TASK)
2994 GNUNET_SCHEDULER_cancel(repeat_connect_task); 2980 GNUNET_SCHEDULER_cancel (repeat_connect_task);
2995 repeat_connect_peer1 = NULL; 2981 repeat_connect_peer1 = NULL;
2996 repeat_connect_peer2 = NULL; 2982 repeat_connect_peer2 = NULL;
2997 repeat_connect_mode = GNUNET_NO; 2983 repeat_connect_mode = GNUNET_NO;
2998 GNUNET_TESTING_resume_connections(pg); 2984 GNUNET_TESTING_resume_connections (pg);
2999 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Resuming normal connection mode, debug connection was successful!\n"); 2985 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3000 } 2986 "Resuming normal connection mode, debug connection was successful!\n");
3001 } 2987 }
3002 } 2988 }
2989 }
3003#endif 2990#endif
3004 2991
3005 if (GNUNET_TIME_absolute_get_difference (connect_last_time, 2992 if (GNUNET_TIME_absolute_get_difference (connect_last_time,
3006 GNUNET_TIME_absolute_get ()).rel_value 2993 GNUNET_TIME_absolute_get
3007 > GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2994 ()).rel_value >
3008 CONN_UPDATE_DURATION).rel_value) 2995 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2996 CONN_UPDATE_DURATION).rel_value)
2997 {
2998 /* Get number of new connections */
2999 new_connections = total_connections - previous_connections;
3000
3001 /* Get number of new FAILED connections */
3002 new_failed_connections = failed_connections - previous_failed_connections;
3003
3004 /* Get duration in seconds */
3005 duration
3006 = GNUNET_TIME_absolute_get_difference (connect_last_time,
3007 GNUNET_TIME_absolute_get
3008 ()).rel_value / 1000;
3009 total_duration =
3010 GNUNET_TIME_absolute_get_difference (connect_start_time,
3011 GNUNET_TIME_absolute_get
3012 ()).rel_value / 1000;
3013
3014 failed_conns_per_sec_recent = (double) new_failed_connections
3015 / (double) duration;
3016 failed_conns_per_sec_total = (double) failed_connections
3017 / (double) total_duration;
3018 conns_per_sec_recent = (double) new_connections / (double) duration;
3019 conns_per_sec_total = (double) total_connections / (double) total_duration;
3020 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3021 "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total failed %.2f/s\n",
3022 conns_per_sec_recent, conns_per_sec_total,
3023 failed_conns_per_sec_recent, failed_conns_per_sec_total);
3024 connect_last_time = GNUNET_TIME_absolute_get ();
3025 previous_connections = total_connections;
3026 previous_failed_connections = failed_connections;
3027 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3028 "have %llu total_connections, %llu failed\n",
3029 total_connections, failed_connections);
3030#if ONLY_TESTING
3031 /* These conditions likely mean we've entered the death spiral of doom */
3032 if ((total_connections > 20000) &&
3033 (conns_per_sec_recent < 5.0) &&
3034 (conns_per_sec_total > 10.0) &&
3035 (emsg != NULL) && (repeat_connect_mode == GNUNET_NO))
3009 { 3036 {
3010 /* Get number of new connections */
3011 new_connections = total_connections - previous_connections;
3012
3013 /* Get number of new FAILED connections */
3014 new_failed_connections = failed_connections - previous_failed_connections;
3015
3016 /* Get duration in seconds */
3017 duration
3018 = GNUNET_TIME_absolute_get_difference (connect_last_time,
3019 GNUNET_TIME_absolute_get ()).rel_value
3020 / 1000;
3021 total_duration
3022 = GNUNET_TIME_absolute_get_difference (connect_start_time,
3023 GNUNET_TIME_absolute_get ()).rel_value
3024 / 1000;
3025
3026 failed_conns_per_sec_recent = (double) new_failed_connections
3027 / (double) duration;
3028 failed_conns_per_sec_total = (double) failed_connections
3029 / (double) total_duration;
3030 conns_per_sec_recent = (double) new_connections / (double) duration;
3031 conns_per_sec_total = (double) total_connections
3032 / (double) total_duration;
3033 GNUNET_log (
3034 GNUNET_ERROR_TYPE_WARNING,
3035 "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total failed %.2f/s\n",
3036 conns_per_sec_recent, conns_per_sec_total,
3037 failed_conns_per_sec_recent, failed_conns_per_sec_total);
3038 connect_last_time = GNUNET_TIME_absolute_get ();
3039 previous_connections = total_connections;
3040 previous_failed_connections = failed_connections;
3041 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3037 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3042 "have %llu total_connections, %llu failed\n", 3038 "Entering repeat connection attempt mode!\n");
3043 total_connections, failed_connections); 3039 repeat_connect_peer1 = first_daemon;
3044#if ONLY_TESTING 3040 repeat_connect_peer2 = second_daemon;
3045 /* These conditions likely mean we've entered the death spiral of doom */ 3041 repeat_connect_mode = GNUNET_YES;
3046 if ((total_connections > 20000) && 3042 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3047 (conns_per_sec_recent < 5.0) && 3043 "Stopping NEW connections from being scheduled!\n");
3048 (conns_per_sec_total > 10.0) && 3044 GNUNET_TESTING_stop_connections (pg);
3049 (emsg != NULL) && 3045 repeat_connect_task =
3050 (repeat_connect_mode == GNUNET_NO)) 3046 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
3051 { 3047 (GNUNET_TIME_UNIT_SECONDS, 60),
3052 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Entering repeat connection attempt mode!\n"); 3048 &repeat_connect, NULL);
3053 repeat_connect_peer1 = first_daemon;
3054 repeat_connect_peer2 = second_daemon;
3055 repeat_connect_mode = GNUNET_YES;
3056 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping NEW connections from being scheduled!\n");
3057 GNUNET_TESTING_stop_connections(pg);
3058 repeat_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), &repeat_connect, NULL);
3059 }
3060#endif
3061 } 3049 }
3050#endif
3051 }
3062 3052
3063 if (emsg == NULL) 3053 if (emsg == NULL)
3064 { 3054 {
3065 total_connections++; 3055 total_connections++;
3066#if VERBOSE > 1 3056#if VERBOSE > 1
3067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", 3057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3068 first_daemon->shortname, 3058 "connected peer %s to peer %s, distance %u\n",
3069 second_daemon->shortname, 3059 first_daemon->shortname, second_daemon->shortname, distance);
3070 distance);
3071#endif 3060#endif
3072 } 3061 }
3073 else 3062 else
3074 { 3063 {
3075 failed_connections++; 3064 failed_connections++;
3076#if VERBOSE 3065#if VERBOSE
3077 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peer %s to peer %s with error :\n%s\n", 3066 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3078 first_daemon->shortname, 3067 "Failed to connect peer %s to peer %s with error :\n%s\n",
3079 second_daemon->shortname, emsg); 3068 first_daemon->shortname, second_daemon->shortname, emsg);
3080 3069
3081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", 3070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3082 first_daemon->shortname, 3071 "Failed to connect peer %s to peer %s with error :\n%s\n",
3083 second_daemon->shortname, emsg); 3072 first_daemon->shortname, second_daemon->shortname, emsg);
3084#endif 3073#endif
3085 } 3074 }
3086 3075
3087#if ONLY_TESTING 3076#if ONLY_TESTING
3088 if ((repeat_connect_mode == GNUNET_YES) ) 3077 if ((repeat_connect_mode == GNUNET_YES))
3089 return; 3078 return;
3090#endif 3079#endif
3091 3080
3092 GNUNET_assert(peer_connect_meter != NULL); 3081 GNUNET_assert (peer_connect_meter != NULL);
3093 if (GNUNET_YES == update_meter (peer_connect_meter)) 3082 if (GNUNET_YES == update_meter (peer_connect_meter))
3094 { 3083 {
3095#if VERBOSE 3084#if VERBOSE
3096 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3097 "Created %d total connections, which is our target number! Starting next phase of testing.\n", 3086 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
3098 total_connections); 3087 total_connections);
3099#endif 3088#endif
3100 if (failed_connections > 0) 3089 if (failed_connections > 0)
3101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3090 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3102 "While connecting, had %u failed connections.\n", 3091 "While connecting, had %u failed connections.\n",
3103 failed_connections); 3092 failed_connections);
3104 if (dhtlog_handle != NULL) 3093 if (dhtlog_handle != NULL)
3105 { 3094 {
3106 dhtlog_handle->update_connections (total_connections); 3095 dhtlog_handle->update_connections (total_connections);
3107 dhtlog_handle->insert_topology (expected_connections); 3096 dhtlog_handle->insert_topology (expected_connections);
3108 } 3097 }
3109 3098
3110 total_duration 3099 total_duration
3111 = GNUNET_TIME_absolute_get_difference (connect_start_time, 3100 = GNUNET_TIME_absolute_get_difference (connect_start_time,
3112 GNUNET_TIME_absolute_get ()).rel_value 3101 GNUNET_TIME_absolute_get
3113 / 1000; 3102 ()).rel_value / 1000;
3114 failed_conns_per_sec_total = (long double) failed_connections 3103 failed_conns_per_sec_total =
3115 / total_duration; 3104 (long double) failed_connections / total_duration;
3116 conns_per_sec_total = (long double) total_connections / total_duration; 3105 conns_per_sec_total = (long double) total_connections / total_duration;
3106 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3107 "Overall connection info --- Total: %u, Total Failed %u/s\n",
3108 total_connections, failed_connections);
3109 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3110 "Overall connection info --- Total: %.2f/s, Total Failed %.2f/s\n",
3111 conns_per_sec_total, failed_conns_per_sec_total);
3112
3113 GNUNET_asprintf (&temp_conn_string, "DHT Profiler Connection/s",
3114 trial_to_run);
3115 GNUNET_asprintf (&temp_conn_failed_string,
3116 "DHT Profiler Connection/s failed", trial_to_run);
3117 GNUNET_asprintf (&revision_str, "%llu", revision);
3118
3119 if (GNUNET_YES == insert_gauger_data)
3120 GAUGER_ID ("DHT_TESTING", temp_conn_string,
3121 (long double) conns_per_sec_total, "conns/s", revision_str);
3122 if (GNUNET_YES == insert_gauger_data)
3123 GAUGER_ID ("DHT_TESTING", temp_conn_failed_string,
3124 (long double) failed_conns_per_sec_total, "failed_conns",
3125 revision_str);
3126
3127 GNUNET_free (temp_conn_string);
3128 GNUNET_free (temp_conn_failed_string);
3129 GNUNET_asprintf (&temp_conn_string, "DHT Profiler Total Connections",
3130 trial_to_run);
3131 GNUNET_asprintf (&temp_conn_failed_string,
3132 "DHT Profiler Total Connections failed", trial_to_run);
3133 if (GNUNET_YES == insert_gauger_data)
3134 GAUGER_ID ("DHT_TESTING", temp_conn_string, (double) total_connections,
3135 "conns", revision_str);
3136 if (GNUNET_YES == insert_gauger_data)
3137 GAUGER_ID ("DHT_TESTING", temp_conn_failed_string,
3138 (double) failed_connections, "failed conns", revision_str);
3139 GNUNET_free (temp_conn_string);
3140 GNUNET_free (temp_conn_failed_string);
3141 GNUNET_free (revision_str);
3142
3143 GNUNET_SCHEDULER_cancel (die_task);
3144
3145 if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle))
3146 {
3147 topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
3117 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3148 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3118 "Overall connection info --- Total: %u, Total Failed %u/s\n", 3149 "Setting continue gets and puts as topo_cont\n");
3119 total_connections, failed_connections); 3150 topo_ctx->cont = &continue_puts_and_gets;
3120 GNUNET_log ( 3151 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
3121 GNUNET_ERROR_TYPE_WARNING, 3152 GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
3122 "Overall connection info --- Total: %.2f/s, Total Failed %.2f/s\n",
3123 conns_per_sec_total, failed_conns_per_sec_total);
3124
3125 GNUNET_asprintf (&temp_conn_string, "DHT Profiler Connection/s",
3126 trial_to_run);
3127 GNUNET_asprintf (&temp_conn_failed_string,
3128 "DHT Profiler Connection/s failed", trial_to_run);
3129 GNUNET_asprintf (&revision_str, "%llu", revision);
3130
3131 if (GNUNET_YES == insert_gauger_data)
3132 GAUGER_ID("DHT_TESTING", temp_conn_string, (long double)conns_per_sec_total, "conns/s", revision_str);
3133 if (GNUNET_YES == insert_gauger_data)
3134 GAUGER_ID("DHT_TESTING", temp_conn_failed_string, (long double)failed_conns_per_sec_total, "failed_conns", revision_str);
3135
3136 GNUNET_free(temp_conn_string);
3137 GNUNET_free(temp_conn_failed_string);
3138 GNUNET_asprintf (&temp_conn_string, "DHT Profiler Total Connections",
3139 trial_to_run);
3140 GNUNET_asprintf (&temp_conn_failed_string,
3141 "DHT Profiler Total Connections failed", trial_to_run);
3142 if (GNUNET_YES == insert_gauger_data)
3143 GAUGER_ID("DHT_TESTING", temp_conn_string, (double)total_connections, "conns", revision_str);
3144 if (GNUNET_YES == insert_gauger_data)
3145 GAUGER_ID("DHT_TESTING", temp_conn_failed_string, (double)failed_connections, "failed conns", revision_str);
3146 GNUNET_free(temp_conn_string);
3147 GNUNET_free(temp_conn_failed_string);
3148 GNUNET_free(revision_str);
3149
3150 GNUNET_SCHEDULER_cancel (die_task);
3151
3152 if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle))
3153 {
3154 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
3155 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3156 "Setting continue gets and puts as topo_cont\n");
3157 topo_ctx->cont = &continue_puts_and_gets;
3158 topo_ctx->peers_seen
3159 = GNUNET_CONTAINER_multihashmap_create (num_peers);
3160 GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
3161 }
3162 else
3163 {
3164 GNUNET_log (
3165 GNUNET_ERROR_TYPE_WARNING,
3166 "For some reason, NOT scheduling final topology capture (settle_time %d, dhtlog_handle %s)!\n",
3167 settle_time, dhtlog_handle);
3168 GNUNET_SCHEDULER_add_now (&continue_puts_and_gets, NULL);
3169 }
3170 } 3153 }
3171 else if (total_connections + failed_connections == expected_connections) 3154 else
3172 { 3155 {
3173 GNUNET_SCHEDULER_cancel (die_task); 3156 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3174 die_task 3157 "For some reason, NOT scheduling final topology capture (settle_time %d, dhtlog_handle %s)!\n",
3175 = GNUNET_SCHEDULER_add_now (&end_badly, 3158 settle_time, dhtlog_handle);
3176 "from topology_callback (too many failed connections)"); 3159 GNUNET_SCHEDULER_add_now (&continue_puts_and_gets, NULL);
3177 } 3160 }
3161 }
3162 else if (total_connections + failed_connections == expected_connections)
3163 {
3164 GNUNET_SCHEDULER_cancel (die_task);
3165 die_task
3166 = GNUNET_SCHEDULER_add_now (&end_badly,
3167 "from topology_callback (too many failed connections)");
3168 }
3178} 3169}
3179 3170
3180static void 3171static void
3181peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id, 3172peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
3182 const struct GNUNET_CONFIGURATION_Handle *cfg, 3173 const struct GNUNET_CONFIGURATION_Handle *cfg,
3183 struct GNUNET_TESTING_Daemon *d, const char *emsg) 3174 struct GNUNET_TESTING_Daemon *d, const char *emsg)
3184{ 3175{
3185 char *revision_str; 3176 char *revision_str;
3177
3186 if (emsg != NULL) 3178 if (emsg != NULL)
3187 { 3179 {
3188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3189 "Failed to start daemon with error: `%s'\n", emsg); 3181 "Failed to start daemon with error: `%s'\n", emsg);
3190 return; 3182 return;
3191 } 3183 }
3192 GNUNET_assert (id != NULL); 3184 GNUNET_assert (id != NULL);
3193 3185
3194#if VERBOSE > 1 3186#if VERBOSE > 1
3195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", 3187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
3196 (num_peers - peers_left) + 1, num_peers); 3188 (num_peers - peers_left) + 1, num_peers);
3197#endif 3189#endif
3198 3190
3199 peers_left--; 3191 peers_left--;
3200 3192
3201 if (GNUNET_YES == update_meter (peer_start_meter)) 3193 if (GNUNET_YES == update_meter (peer_start_meter))
3202 { 3194 {
3203#if VERBOSE 3195#if VERBOSE
3204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3205 "All %d daemons started, now connecting peers!\n", 3197 "All %d daemons started, now connecting peers!\n", num_peers);
3206 num_peers);
3207#endif 3198#endif
3208 GNUNET_SCHEDULER_cancel (die_task); 3199 GNUNET_SCHEDULER_cancel (die_task);
3209 3200
3210 GNUNET_asprintf (&revision_str, "%llu", revision); 3201 GNUNET_asprintf (&revision_str, "%llu", revision);
3211 if (GNUNET_YES == insert_gauger_data) 3202 if (GNUNET_YES == insert_gauger_data)
3212 GAUGER_ID("DHT_TESTING", 3203 GAUGER_ID ("DHT_TESTING",
3213 "peer_startup_time", 3204 "peer_startup_time",
3214 GNUNET_TIME_absolute_get_duration(peer_start_time).rel_value / (double)num_peers, 3205 GNUNET_TIME_absolute_get_duration (peer_start_time).rel_value /
3215 "ms/peer", revision_str); 3206 (double) num_peers, "ms/peer", revision_str);
3216 GNUNET_free(revision_str); 3207 GNUNET_free (revision_str);
3217 3208
3218 expected_connections = UINT_MAX; 3209 expected_connections = UINT_MAX;
3219 if ((pg != NULL) && (peers_left == 0)) 3210 if ((pg != NULL) && (peers_left == 0))
3220 { 3211 {
3221 connect_start_time = GNUNET_TIME_absolute_get (); 3212 connect_start_time = GNUNET_TIME_absolute_get ();
3222 expected_connections 3213 expected_connections
3223 = GNUNET_TESTING_connect_topology ( 3214 = GNUNET_TESTING_connect_topology (pg,
3224 pg, 3215 connect_topology,
3225 connect_topology, 3216 connect_topology_option,
3226 connect_topology_option, 3217 connect_topology_option_modifier,
3227 connect_topology_option_modifier, 3218 connect_timeout,
3228 connect_timeout, 3219 connect_attempts, NULL, NULL);
3229 connect_attempts, NULL, NULL); 3220
3230 3221 peer_connect_meter = create_meter (expected_connections,
3231 peer_connect_meter = create_meter (expected_connections, 3222 "Peer connection ", GNUNET_YES);
3232 "Peer connection ", GNUNET_YES); 3223 fprintf (stderr, "Have %d expected connections\n", expected_connections);
3233 fprintf (stderr, "Have %d expected connections\n", 3224 }
3234 expected_connections);
3235 }
3236
3237 if (expected_connections == 0)
3238 {
3239 die_task
3240 = GNUNET_SCHEDULER_add_now (&end_badly,
3241 "from connect topology (bad return)");
3242 }
3243 3225
3226 if (expected_connections == 0)
3227 {
3244 die_task 3228 die_task
3245 = GNUNET_SCHEDULER_add_delayed ( 3229 = GNUNET_SCHEDULER_add_now (&end_badly,
3246 GNUNET_TIME_relative_multiply ( 3230 "from connect topology (bad return)");
3247 GNUNET_TIME_UNIT_SECONDS,
3248 DEFAULT_CONNECT_TIMEOUT
3249 * expected_connections),
3250 &end_badly,
3251 "from connect topology (timeout)");
3252
3253 ok = 0;
3254 } 3231 }
3232
3233 die_task
3234 =
3235 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
3236 (GNUNET_TIME_UNIT_SECONDS,
3237 DEFAULT_CONNECT_TIMEOUT *
3238 expected_connections), &end_badly,
3239 "from connect topology (timeout)");
3240
3241 ok = 0;
3242 }
3255} 3243}
3256 3244
3257static void 3245static void
3258create_topology() 3246create_topology ()
3259{ 3247{
3260 unsigned int create_expected_connections; 3248 unsigned int create_expected_connections;
3261 peers_left = num_peers; /* Reset counter */ 3249
3250 peers_left = num_peers; /* Reset counter */
3262 create_expected_connections 3251 create_expected_connections
3263 = GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, 3252 = GNUNET_TESTING_create_topology (pg, topology, blacklist_topology,
3264 blacklist_transports); 3253 blacklist_transports);
3265 if (create_expected_connections > 0) 3254 if (create_expected_connections > 0)
3266 { 3255 {
3267 GNUNET_log ( 3256 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3268 GNUNET_ERROR_TYPE_WARNING, 3257 "Topology set up, have %u expected connections, now starting peers!\n",
3269 "Topology set up, have %u expected connections, now starting peers!\n", 3258 create_expected_connections);
3270 create_expected_connections); 3259 GNUNET_TESTING_daemons_continue_startup (pg);
3271 GNUNET_TESTING_daemons_continue_startup (pg); 3260 peer_start_time = GNUNET_TIME_absolute_get ();
3272 peer_start_time = GNUNET_TIME_absolute_get (); 3261 }
3273 }
3274 else 3262 else
3275 { 3263 {
3276 GNUNET_SCHEDULER_cancel (die_task); 3264 GNUNET_SCHEDULER_cancel (die_task);
3277 die_task = GNUNET_SCHEDULER_add_now (&end_badly, 3265 die_task = GNUNET_SCHEDULER_add_now (&end_badly,
3278 "from create topology (bad return)"); 3266 "from create topology (bad return)");
3279 } 3267 }
3280 GNUNET_free_non_null(blacklist_transports); 3268 GNUNET_free_non_null (blacklist_transports);
3281 GNUNET_SCHEDULER_cancel (die_task); 3269 GNUNET_SCHEDULER_cancel (die_task);
3282 die_task 3270 die_task
3283 = GNUNET_SCHEDULER_add_delayed ( 3271 =
3284 GNUNET_TIME_relative_multiply ( 3272 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
3285 seconds_per_peer_start, 3273 (seconds_per_peer_start, num_peers),
3286 num_peers), 3274 &end_badly,
3287 &end_badly, 3275 "from continue startup (timeout)");
3288 "from continue startup (timeout)");
3289} 3276}
3290 3277
3291/** 3278/**
@@ -3297,64 +3284,66 @@ create_topology()
3297 * @param emsg non-null on failure 3284 * @param emsg non-null on failure
3298 */ 3285 */
3299static void 3286static void
3300hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, 3287hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
3301 struct GNUNET_TESTING_Daemon *d, const char *emsg) 3288 struct GNUNET_TESTING_Daemon *d, const char *emsg)
3302{ 3289{
3303 char * revision_str; 3290 char *revision_str;
3291
3304 if (emsg != NULL) 3292 if (emsg != NULL)
3305 { 3293 {
3306 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3294 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3307 "Hostkey callback received error: %s\n", emsg); 3295 "Hostkey callback received error: %s\n", emsg);
3308 } 3296 }
3309 3297
3310#if VERBOSE > 1 3298#if VERBOSE > 1
3311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3312 "Hostkey (%d/%d) created for peer `%s'\n", 3300 "Hostkey (%d/%d) created for peer `%s'\n",
3313 num_peers - peers_left, num_peers, GNUNET_i2s(id)); 3301 num_peers - peers_left, num_peers, GNUNET_i2s (id));
3314#endif 3302#endif
3315 3303
3316 peers_left--; 3304 peers_left--;
3317 if (GNUNET_YES == update_meter (hostkey_meter)) 3305 if (GNUNET_YES == update_meter (hostkey_meter))
3318 { 3306 {
3319 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3307 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3320 "All %d hostkeys created, now creating topology!\n", 3308 "All %d hostkeys created, now creating topology!\n", num_peers);
3321 num_peers);
3322 3309
3323 GNUNET_asprintf (&revision_str, "%llu", revision); 3310 GNUNET_asprintf (&revision_str, "%llu", revision);
3324 if (GNUNET_YES == insert_gauger_data) 3311 if (GNUNET_YES == insert_gauger_data)
3325 { 3312 {
3326 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (config, "TESTING", 3313 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (config, "TESTING",
3327 "HOSTKEYSFILE")) 3314 "HOSTKEYSFILE"))
3328 { 3315 {
3329 GAUGER_ID("DHT_TESTING", 3316 GAUGER_ID ("DHT_TESTING",
3330 "HOSTKEY_GENERATION", 3317 "HOSTKEY_GENERATION",
3331 GNUNET_TIME_absolute_get_duration(hostkey_start_time).rel_value / (double)num_peers, 3318 GNUNET_TIME_absolute_get_duration
3332 "ms/hostkey", revision_str); 3319 (hostkey_start_time).rel_value / (double) num_peers,
3333 } 3320 "ms/hostkey", revision_str);
3334 else 3321 }
3335 { 3322 else
3336 GAUGER_ID("DHT_TESTING", 3323 {
3337 "HOSTKEY_GENERATION_REAL", 3324 GAUGER_ID ("DHT_TESTING",
3338 GNUNET_TIME_absolute_get_duration(hostkey_start_time).rel_value / (double)num_peers, 3325 "HOSTKEY_GENERATION_REAL",
3339 "ms/hostkey", revision_str); 3326 GNUNET_TIME_absolute_get_duration
3340 } 3327 (hostkey_start_time).rel_value / (double) num_peers,
3341 } 3328 "ms/hostkey", revision_str);
3329 }
3330 }
3342 3331
3343 GNUNET_free(revision_str); 3332 GNUNET_free (revision_str);
3344 3333
3345 GNUNET_SCHEDULER_cancel (die_task); 3334 GNUNET_SCHEDULER_cancel (die_task);
3346 /* Set up task in case topology creation doesn't finish 3335 /* Set up task in case topology creation doesn't finish
3347 * within a reasonable amount of time */ 3336 * within a reasonable amount of time */
3348 die_task = GNUNET_SCHEDULER_add_delayed (DEFAULT_TOPOLOGY_TIMEOUT, 3337 die_task = GNUNET_SCHEDULER_add_delayed (DEFAULT_TOPOLOGY_TIMEOUT,
3349 &end_badly, 3338 &end_badly,
3350 "from create_topology"); 3339 "from create_topology");
3351 GNUNET_SCHEDULER_add_now (&create_topology, NULL); 3340 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
3352 ok = 0; 3341 ok = 0;
3353 } 3342 }
3354} 3343}
3355 3344
3356static void 3345static void
3357run (void *cls, char * const *args, const char *cfgfile, 3346run (void *cls, char *const *args, const char *cfgfile,
3358 const struct GNUNET_CONFIGURATION_Handle *cfg) 3347 const struct GNUNET_CONFIGURATION_Handle *cfg)
3359{ 3348{
3360 struct stat frstat; 3349 struct stat frstat;
@@ -3388,27 +3377,26 @@ run (void *cls, char * const *args, const char *cfgfile,
3388 3377
3389 config = cfg; 3378 config = cfg;
3390 rounds_finished = 0; 3379 rounds_finished = 0;
3391 memset (&trial_info, 0, sizeof(struct GNUNET_DHTLOG_TrialInfo)); 3380 memset (&trial_info, 0, sizeof (struct GNUNET_DHTLOG_TrialInfo));
3392 /* Get path from configuration file */ 3381 /* Get path from configuration file */
3393 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "paths", 3382 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "paths",
3394 "servicehome", 3383 "servicehome",
3395 &test_directory)) 3384 &test_directory))
3396 { 3385 {
3397 ok = 404; 3386 ok = 404;
3398 return; 3387 return;
3399 } 3388 }
3400 3389
3401 /* Get number of peers to start from configuration */ 3390 /* Get number of peers to start from configuration */
3402 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3391 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
3403 "num_peers", 3392 "num_peers",
3404 &num_peers)) 3393 &num_peers))
3405 { 3394 {
3406 GNUNET_log ( 3395 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3407 GNUNET_ERROR_TYPE_WARNING, 3396 "Number of peers must be specified in section %s option %s\n",
3408 "Number of peers must be specified in section %s option %s\n", 3397 "TESTING", "NUM_PEERS");
3409 "TESTING", "NUM_PEERS"); 3398 }
3410 } 3399 GNUNET_assert (num_peers > 0 && num_peers < ULONG_MAX);
3411 GNUNET_assert(num_peers > 0 && num_peers < ULONG_MAX);
3412 3400
3413 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3401 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
3414 "connect_timeout", 3402 "connect_timeout",
@@ -3416,39 +3404,39 @@ run (void *cls, char * const *args, const char *cfgfile,
3416 connect_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3404 connect_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3417 temp_config_number); 3405 temp_config_number);
3418 else 3406 else
3419 { 3407 {
3420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 3408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
3421 "testing", "connect_timeout"); 3409 "testing", "connect_timeout");
3422 return; 3410 return;
3423 } 3411 }
3424 3412
3425 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3413 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
3426 "connect_attempts", 3414 "connect_attempts",
3427 &connect_attempts)) 3415 &connect_attempts))
3428 { 3416 {
3429 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 3417 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
3430 "testing", "connect_attempts"); 3418 "testing", "connect_attempts");
3431 return; 3419 return;
3432 } 3420 }
3433 3421
3434 if (GNUNET_OK 3422 if (GNUNET_OK
3435 != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3423 != GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
3436 "max_outstanding_connections", 3424 "max_outstanding_connections",
3437 &max_outstanding_connections)) 3425 &max_outstanding_connections))
3438 { 3426 {
3439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 3427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
3440 "testing", "max_outstanding_connections"); 3428 "testing", "max_outstanding_connections");
3441 return; 3429 return;
3442 } 3430 }
3443 3431
3444 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3432 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
3445 "max_concurrent_ssh", 3433 "max_concurrent_ssh",
3446 &max_concurrent_ssh)) 3434 &max_concurrent_ssh))
3447 { 3435 {
3448 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 3436 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
3449 "testing", "max_concurrent_ssh"); 3437 "testing", "max_concurrent_ssh");
3450 return; 3438 return;
3451 } 3439 }
3452 3440
3453 /** 3441 /**
3454 * Get DHT specific testing options. 3442 * Get DHT specific testing options.
@@ -3461,21 +3449,21 @@ run (void *cls, char * const *args, const char *cfgfile,
3461 || (GNUNET_YES 3449 || (GNUNET_YES
3462 == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 3450 == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
3463 "mysql_logging_minimal"))) 3451 "mysql_logging_minimal")))
3464 { 3452 {
3465 if (GNUNET_YES 3453 if (GNUNET_YES
3466 == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 3454 == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
3467 "mysql_logging_minimal")) 3455 "mysql_logging_minimal"))
3468 dhtlog_minimal = GNUNET_YES; 3456 dhtlog_minimal = GNUNET_YES;
3469 3457
3470 dhtlog_handle = GNUNET_DHTLOG_connect (cfg); 3458 dhtlog_handle = GNUNET_DHTLOG_connect (cfg);
3471 if (dhtlog_handle == NULL) 3459 if (dhtlog_handle == NULL)
3472 { 3460 {
3473 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3461 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3474 "Could not connect to mysql server for logging, will NOT log dht operations!"); 3462 "Could not connect to mysql server for logging, will NOT log dht operations!");
3475 ok = 3306; 3463 ok = 3306;
3476 return; 3464 return;
3477 }
3478 } 3465 }
3466 }
3479 3467
3480 stop_closest = GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 3468 stop_closest = GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
3481 "stop_on_closest"); 3469 "stop_on_closest");
@@ -3501,107 +3489,106 @@ run (void *cls, char * const *args, const char *cfgfile,
3501 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", 3489 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing",
3502 "churn_file", 3490 "churn_file",
3503 &churn_filename)) 3491 &churn_filename))
3492 {
3493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Reading churn data from %s\n",
3494 churn_filename);
3495 if (GNUNET_OK != GNUNET_DISK_file_test (churn_filename))
3496 {
3497 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error reading churn file!\n");
3498 GNUNET_free_non_null (trialmessage);
3499 GNUNET_free (churn_filename);
3500 return;
3501 }
3502 if ((0 != STAT (churn_filename, &frstat)) || (frstat.st_size == 0))
3504 { 3503 {
3505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Reading churn data from %s\n", 3504 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3505 "Could not open file specified for churn data, ending test!");
3506 ok = 1119;
3507 GNUNET_free_non_null (trialmessage);
3508 GNUNET_free (churn_filename);
3509 return;
3510 }
3511
3512 churn_data = GNUNET_malloc_large (frstat.st_size);
3513 GNUNET_assert (churn_data != NULL);
3514 if (frstat.st_size != GNUNET_DISK_fn_read (churn_filename, churn_data,
3515 frstat.st_size))
3516 {
3517 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3518 "Could not read file %s specified for churn, ending test!",
3506 churn_filename); 3519 churn_filename);
3507 if (GNUNET_OK != GNUNET_DISK_file_test (churn_filename)) 3520 GNUNET_free (churn_filename);
3508 { 3521 GNUNET_free (churn_data);
3509 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error reading churn file!\n"); 3522 GNUNET_free_non_null (trialmessage);
3510 GNUNET_free_non_null(trialmessage); 3523 return;
3511 GNUNET_free(churn_filename); 3524 }
3512 return; 3525
3513 } 3526 GNUNET_free_non_null (churn_filename);
3514 if ((0 != STAT (churn_filename, &frstat)) || (frstat.st_size == 0))
3515 {
3516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3517 "Could not open file specified for churn data, ending test!");
3518 ok = 1119;
3519 GNUNET_free_non_null(trialmessage);
3520 GNUNET_free(churn_filename);
3521 return;
3522 }
3523 3527
3524 churn_data = GNUNET_malloc_large (frstat.st_size); 3528 buf = churn_data;
3525 GNUNET_assert(churn_data != NULL); 3529 count = 0;
3526 if (frstat.st_size != GNUNET_DISK_fn_read (churn_filename, churn_data, 3530 /* Read the first line */
3527 frstat.st_size)) 3531 while (count < frstat.st_size)
3532 {
3533 count++;
3534 if (((churn_data[count] == '\n')) && (buf != &churn_data[count]))
3535 {
3536 churn_data[count] = '\0';
3537 if (1 != sscanf (buf, "%u", &churn_rounds))
3528 { 3538 {
3529 GNUNET_log ( 3539 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3530 GNUNET_ERROR_TYPE_ERROR, 3540 "Failed to read number of rounds from churn file, ending test!\n");
3531 "Could not read file %s specified for churn, ending test!", 3541 ret = 4200;
3532 churn_filename); 3542 GNUNET_free_non_null (trialmessage);
3533 GNUNET_free (churn_filename); 3543 GNUNET_free_non_null (churn_data);
3534 GNUNET_free (churn_data);
3535 GNUNET_free_non_null(trialmessage);
3536 return; 3544 return;
3537 } 3545 }
3546 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3547 "Read %u rounds from churn file\n", churn_rounds);
3548 buf = &churn_data[count + 1];
3549 churn_array = GNUNET_malloc (sizeof (unsigned int) * churn_rounds);
3550 break; /* Done with this part */
3551 }
3552 }
3538 3553
3539 GNUNET_free_non_null(churn_filename); 3554 if (GNUNET_OK
3555 != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3556 "churns_per_round",
3557 &churns_per_round))
3558 {
3559 churns_per_round = (unsigned long long) churn_rounds;
3560 }
3540 3561
3541 buf = churn_data; 3562 line_number = 0;
3542 count = 0; 3563 while ((count < frstat.st_size) && (line_number < churn_rounds))
3543 /* Read the first line */ 3564 {
3544 while (count < frstat.st_size) 3565 count++;
3545 { 3566 if (((churn_data[count] == '\n')) && (buf != &churn_data[count]))
3546 count++; 3567 {
3547 if (((churn_data[count] == '\n')) && (buf != &churn_data[count])) 3568 churn_data[count] = '\0';
3548 {
3549 churn_data[count] = '\0';
3550 if (1 != sscanf (buf, "%u", &churn_rounds))
3551 {
3552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3553 "Failed to read number of rounds from churn file, ending test!\n");
3554 ret = 4200;
3555 GNUNET_free_non_null(trialmessage);
3556 GNUNET_free_non_null(churn_data);
3557 return;
3558 }
3559 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3560 "Read %u rounds from churn file\n", churn_rounds);
3561 buf = &churn_data[count + 1];
3562 churn_array = GNUNET_malloc(sizeof(unsigned int) * churn_rounds);
3563 break; /* Done with this part */
3564 }
3565 }
3566 3569
3567 if (GNUNET_OK 3570 ret = sscanf (buf, "%u", &churn_array[line_number]);
3568 != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3571 if (1 == ret)
3569 "churns_per_round",
3570 &churns_per_round))
3571 { 3572 {
3572 churns_per_round = (unsigned long long) churn_rounds; 3573 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3574 "Read %u peers in round %u\n",
3575 churn_array[line_number], line_number);
3576 line_number++;
3573 } 3577 }
3574 3578 else
3575 line_number = 0;
3576 while ((count < frstat.st_size) && (line_number < churn_rounds))
3577 { 3579 {
3578 count++; 3580 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3579 if (((churn_data[count] == '\n')) && (buf != &churn_data[count])) 3581 "Error reading line `%s' in hostfile\n", buf);
3580 { 3582 buf = &churn_data[count + 1];
3581 churn_data[count] = '\0'; 3583 continue;
3582
3583 ret = sscanf (buf, "%u", &churn_array[line_number]);
3584 if (1 == ret)
3585 {
3586 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3587 "Read %u peers in round %u\n",
3588 churn_array[line_number], line_number);
3589 line_number++;
3590 }
3591 else
3592 {
3593 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3594 "Error reading line `%s' in hostfile\n", buf);
3595 buf = &churn_data[count + 1];
3596 continue;
3597 }
3598 buf = &churn_data[count + 1];
3599 }
3600 else if (churn_data[count] == '\n') /* Blank line */
3601 buf = &churn_data[count + 1];
3602 } 3584 }
3585 buf = &churn_data[count + 1];
3586 }
3587 else if (churn_data[count] == '\n') /* Blank line */
3588 buf = &churn_data[count + 1];
3603 } 3589 }
3604 GNUNET_free_non_null(churn_data); 3590 }
3591 GNUNET_free_non_null (churn_data);
3605 3592
3606 /* Check for a hostfile containing user@host:port triples */ 3593 /* Check for a hostfile containing user@host:port triples */
3607 if (GNUNET_OK 3594 if (GNUNET_OK
@@ -3613,74 +3600,70 @@ run (void *cls, char * const *args, const char *cfgfile,
3613 temphost = NULL; 3600 temphost = NULL;
3614 data = NULL; 3601 data = NULL;
3615 if (hostfile != NULL) 3602 if (hostfile != NULL)
3603 {
3604 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
3605 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
3606 | GNUNET_DISK_PERM_USER_WRITE);
3607 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
3616 { 3608 {
3617 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) 3609 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3618 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ 3610 "Could not open file specified for host list, ending test!");
3619 | GNUNET_DISK_PERM_USER_WRITE); 3611 ok = 1119;
3620 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) 3612 GNUNET_free_non_null (trialmessage);
3621 { 3613 GNUNET_free (hostfile);
3622 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3614 return;
3623 "Could not open file specified for host list, ending test!"); 3615 }
3624 ok = 1119;
3625 GNUNET_free_non_null(trialmessage);
3626 GNUNET_free(hostfile);
3627 return;
3628 }
3629 3616
3630 data = GNUNET_malloc_large (frstat.st_size); 3617 data = GNUNET_malloc_large (frstat.st_size);
3631 GNUNET_assert(data != NULL); 3618 GNUNET_assert (data != NULL);
3632 if (frstat.st_size 3619 if (frstat.st_size != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
3633 != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) 3620 {
3634 { 3621 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3635 GNUNET_log ( 3622 "Could not read file %s specified for host list, ending test!",
3636 GNUNET_ERROR_TYPE_ERROR, 3623 hostfile);
3637 "Could not read file %s specified for host list, ending test!", 3624 GNUNET_free (hostfile);
3638 hostfile); 3625 GNUNET_free (data);
3639 GNUNET_free (hostfile); 3626 GNUNET_free_non_null (trialmessage);
3640 GNUNET_free (data); 3627 return;
3641 GNUNET_free_non_null(trialmessage); 3628 }
3642 return;
3643 }
3644 3629
3645 GNUNET_free_non_null(hostfile); 3630 GNUNET_free_non_null (hostfile);
3646 3631
3647 buf = data; 3632 buf = data;
3648 count = 0; 3633 count = 0;
3649 while (count < frstat.st_size - 1) 3634 while (count < frstat.st_size - 1)
3635 {
3636 count++;
3637 if (((data[count] == '\n')) && (buf != &data[count]))
3638 {
3639 data[count] = '\0';
3640 temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
3641 ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
3642 &temphost->username, &temphost->hostname,
3643 &temphost->port);
3644 if (3 == ret)
3650 { 3645 {
3651 count++; 3646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3652 if (((data[count] == '\n')) && (buf != &data[count])) 3647 "Successfully read host %s, port %d and user %s from file\n",
3653 { 3648 temphost->hostname, temphost->port, temphost->username);
3654 data[count] = '\0';
3655 temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
3656 ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
3657 &temphost->username, &temphost->hostname,
3658 &temphost->port);
3659 if (3 == ret)
3660 {
3661 GNUNET_log (
3662 GNUNET_ERROR_TYPE_DEBUG,
3663 "Successfully read host %s, port %d and user %s from file\n",
3664 temphost->hostname, temphost->port,
3665 temphost->username);
3666 }
3667 else
3668 {
3669 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3670 "Error reading line `%s' in hostfile\n", buf);
3671 GNUNET_free(temphost);
3672 buf = &data[count + 1];
3673 continue;
3674 }
3675 temphost->next = hosts;
3676 hosts = temphost;
3677 buf = &data[count + 1];
3678 }
3679 else if ((data[count] == '\n') || (data[count] == '\0'))
3680 buf = &data[count + 1];
3681 } 3649 }
3650 else
3651 {
3652 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3653 "Error reading line `%s' in hostfile\n", buf);
3654 GNUNET_free (temphost);
3655 buf = &data[count + 1];
3656 continue;
3657 }
3658 temphost->next = hosts;
3659 hosts = temphost;
3660 buf = &data[count + 1];
3661 }
3662 else if ((data[count] == '\n') || (data[count] == '\0'))
3663 buf = &data[count + 1];
3682 } 3664 }
3683 GNUNET_free_non_null(data); 3665 }
3666 GNUNET_free_non_null (data);
3684 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3667 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3685 "malicious_getters", 3668 "malicious_getters",
3686 &malicious_getters)) 3669 &malicious_getters))
@@ -3814,7 +3797,7 @@ run (void *cls, char * const *args, const char *cfgfile,
3814 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3797 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3815 "target_completions", 3798 "target_completions",
3816 &target_completions)) 3799 &target_completions))
3817 target_completions = 0; /* Not required, on stack */ 3800 target_completions = 0; /* Not required, on stack */
3818 3801
3819 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING", 3802 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING",
3820 "GET_FROM_SAME")) 3803 "GET_FROM_SAME"))
@@ -3839,12 +3822,12 @@ run (void *cls, char * const *args, const char *cfgfile,
3839 3822
3840 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING", 3823 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING",
3841 "MALICIOUS_SYBIL")) 3824 "MALICIOUS_SYBIL"))
3842 { 3825 {
3843 /* Set up the malicious target at random for this round */ 3826 /* Set up the malicious target at random for this round */
3844 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 3827 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
3845 &sybil_target); 3828 &sybil_target);
3846 malicious_sybil = GNUNET_YES; 3829 malicious_sybil = GNUNET_YES;
3847 } 3830 }
3848 3831
3849 /* Create the bloomfilter for choosing which peers to set malicious */ 3832 /* Create the bloomfilter for choosing which peers to set malicious */
3850 3833
@@ -3916,9 +3899,9 @@ run (void *cls, char * const *args, const char *cfgfile,
3916 total_rounds = 1; 3899 total_rounds = 1;
3917 3900
3918 if ((GNUNET_SYSERR 3901 if ((GNUNET_SYSERR
3919 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3902 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3920 "target_total_connections", 3903 "target_total_connections",
3921 &target_total_connections)) 3904 &target_total_connections))
3922 || (target_total_connections == 0)) 3905 || (target_total_connections == 0))
3923 target_total_connections = connection_estimate (num_peers, 3906 target_total_connections = connection_estimate (num_peers,
3924 DEFAULT_BUCKET_SIZE); 3907 DEFAULT_BUCKET_SIZE);
@@ -3928,82 +3911,79 @@ run (void *cls, char * const *args, const char *cfgfile,
3928 "topology", 3911 "topology",
3929 &topology_str)) 3912 &topology_str))
3930 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) 3913 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
3931 { 3914 {
3932 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3915 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3933 "Invalid topology `%s' given for section %s option %s\n", 3916 "Invalid topology `%s' given for section %s option %s\n",
3934 topology_str, "TESTING", "TOPOLOGY"); 3917 topology_str, "TESTING", "TOPOLOGY");
3935 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ 3918 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
3936 } 3919 }
3937 3920
3938 if (GNUNET_OK 3921 if (GNUNET_OK
3939 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage", 3922 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
3940 &topology_percentage_str)) 3923 &topology_percentage_str))
3941 topology_percentage = 0.5; 3924 topology_percentage = 0.5;
3942 else 3925 else
3943 { 3926 {
3944 topology_percentage = atof (topology_percentage_str); 3927 topology_percentage = atof (topology_percentage_str);
3945 GNUNET_free(topology_percentage_str); 3928 GNUNET_free (topology_percentage_str);
3946 } 3929 }
3947 3930
3948 if (GNUNET_OK 3931 if (GNUNET_OK
3949 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability", 3932 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
3950 &topology_probability_str)) 3933 &topology_probability_str))
3951 topology_probability = 0.5; 3934 topology_probability = 0.5;
3952 else 3935 else
3953 { 3936 {
3954 topology_probability = atof (topology_probability_str); 3937 topology_probability = atof (topology_probability_str);
3955 GNUNET_free(topology_probability_str); 3938 GNUNET_free (topology_probability_str);
3956 } 3939 }
3957 3940
3958 if ((GNUNET_YES 3941 if ((GNUNET_YES
3959 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3942 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
3960 "connect_topology", 3943 "connect_topology",
3961 &connect_topology_str)) 3944 &connect_topology_str))
3962 && (GNUNET_NO == GNUNET_TESTING_topology_get (&connect_topology, 3945 && (GNUNET_NO == GNUNET_TESTING_topology_get (&connect_topology,
3963 connect_topology_str))) 3946 connect_topology_str)))
3964 { 3947 {
3965 GNUNET_log ( 3948 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3966 GNUNET_ERROR_TYPE_WARNING, 3949 "Invalid connect topology `%s' given for section %s option %s\n",
3967 "Invalid connect topology `%s' given for section %s option %s\n", 3950 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
3968 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); 3951 }
3969 } 3952 GNUNET_free_non_null (connect_topology_str);
3970 GNUNET_free_non_null(connect_topology_str);
3971 3953
3972 if ((GNUNET_YES 3954 if ((GNUNET_YES
3973 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3955 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
3974 "connect_topology_option", 3956 "connect_topology_option",
3975 &connect_topology_option_str)) 3957 &connect_topology_option_str))
3976 && (GNUNET_NO 3958 && (GNUNET_NO
3977 == GNUNET_TESTING_topology_option_get (&connect_topology_option, 3959 == GNUNET_TESTING_topology_option_get (&connect_topology_option,
3978 connect_topology_option_str))) 3960 connect_topology_option_str)))
3979 { 3961 {
3980 GNUNET_log ( 3962 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3981 GNUNET_ERROR_TYPE_WARNING, 3963 "Invalid connect topology option `%s' given for section %s option %s\n",
3982 "Invalid connect topology option `%s' given for section %s option %s\n", 3964 connect_topology_option_str, "TESTING",
3983 connect_topology_option_str, "TESTING", 3965 "CONNECT_TOPOLOGY_OPTION");
3984 "CONNECT_TOPOLOGY_OPTION"); 3966 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
3985 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ 3967 }
3986 } 3968 GNUNET_free_non_null (connect_topology_option_str);
3987 GNUNET_free_non_null(connect_topology_option_str);
3988 3969
3989 if (GNUNET_YES 3970 if (GNUNET_YES
3990 == GNUNET_CONFIGURATION_get_value_string ( 3971 == GNUNET_CONFIGURATION_get_value_string (cfg,
3991 cfg,
3992 "testing", 3972 "testing",
3993 "connect_topology_option_modifier", 3973 "connect_topology_option_modifier",
3994 &connect_topology_option_modifier_string)) 3974 &connect_topology_option_modifier_string))
3975 {
3976 if (sscanf (connect_topology_option_modifier_string, "%lf",
3977 &connect_topology_option_modifier) != 1)
3995 { 3978 {
3996 if (sscanf (connect_topology_option_modifier_string, "%lf", 3979 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3997 &connect_topology_option_modifier) != 1) 3980 _
3998 { 3981 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
3999 GNUNET_log ( 3982 connect_topology_option_modifier_string,
4000 GNUNET_ERROR_TYPE_WARNING, 3983 "connect_topology_option_modifier", "TESTING");
4001 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
4002 connect_topology_option_modifier_string,
4003 "connect_topology_option_modifier", "TESTING");
4004 }
4005 GNUNET_free (connect_topology_option_modifier_string);
4006 } 3984 }
3985 GNUNET_free (connect_topology_option_modifier_string);
3986 }
4007 3987
4008 if (GNUNET_YES 3988 if (GNUNET_YES
4009 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3989 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -4012,30 +3992,29 @@ run (void *cls, char * const *args, const char *cfgfile,
4012 blacklist_transports = NULL; 3992 blacklist_transports = NULL;
4013 3993
4014 if ((GNUNET_YES 3994 if ((GNUNET_YES
4015 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3995 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
4016 "blacklist_topology", 3996 "blacklist_topology",
4017 &blacklist_topology_str)) 3997 &blacklist_topology_str))
4018 && (GNUNET_NO == GNUNET_TESTING_topology_get (&blacklist_topology, 3998 && (GNUNET_NO == GNUNET_TESTING_topology_get (&blacklist_topology,
4019 blacklist_topology_str))) 3999 blacklist_topology_str)))
4020 { 4000 {
4021 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4001 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4022 "Invalid topology `%s' given for section %s option %s\n", 4002 "Invalid topology `%s' given for section %s option %s\n",
4023 topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); 4003 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
4024 } 4004 }
4025 GNUNET_free_non_null(topology_str); 4005 GNUNET_free_non_null (topology_str);
4026 GNUNET_free_non_null(blacklist_topology_str); 4006 GNUNET_free_non_null (blacklist_topology_str);
4027 4007
4028 /* Set peers_left so we know when all peers started */ 4008 /* Set peers_left so we know when all peers started */
4029 peers_left = num_peers; 4009 peers_left = num_peers;
4030 4010
4031 /* Set up a task to end testing if peer start fails */ 4011 /* Set up a task to end testing if peer start fails */
4032 die_task 4012 die_task
4033 = GNUNET_SCHEDULER_add_delayed ( 4013 =
4034 GNUNET_TIME_relative_multiply ( 4014 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
4035 seconds_per_peer_start, 4015 (seconds_per_peer_start, num_peers),
4036 num_peers), 4016 &end_badly,
4037 &end_badly, 4017 "didn't generate all hostkeys within allowed startup time!");
4038 "didn't generate all hostkeys within allowed startup time!");
4039 4018
4040 if (dhtlog_handle == NULL) 4019 if (dhtlog_handle == NULL)
4041 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "dhtlog_handle is NULL!"); 4020 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "dhtlog_handle is NULL!");
@@ -4072,7 +4051,7 @@ run (void *cls, char * const *args, const char *cfgfile,
4072 if (dhtlog_handle != NULL) 4051 if (dhtlog_handle != NULL)
4073 dhtlog_handle->insert_trial (&trial_info); 4052 dhtlog_handle->insert_trial (&trial_info);
4074 4053
4075 GNUNET_free_non_null(trialmessage); 4054 GNUNET_free_non_null (trialmessage);
4076 4055
4077 hostkey_meter = create_meter (peers_left, "Hostkeys created ", GNUNET_YES); 4056 hostkey_meter = create_meter (peers_left, "Hostkeys created ", GNUNET_YES);
4078 peer_start_meter = create_meter (peers_left, "Peers started ", GNUNET_YES); 4057 peer_start_meter = create_meter (peers_left, "Peers started ", GNUNET_YES);
@@ -4080,36 +4059,34 @@ run (void *cls, char * const *args, const char *cfgfile,
4080 put_meter = create_meter (num_puts, "Puts completed ", GNUNET_YES); 4059 put_meter = create_meter (num_puts, "Puts completed ", GNUNET_YES);
4081 get_meter = create_meter (num_gets, "Gets completed ", GNUNET_YES); 4060 get_meter = create_meter (num_gets, "Gets completed ", GNUNET_YES);
4082 hostkey_start_time = GNUNET_TIME_absolute_get (); 4061 hostkey_start_time = GNUNET_TIME_absolute_get ();
4083 pg 4062 pg = GNUNET_TESTING_daemons_start (cfg,
4084 = GNUNET_TESTING_daemons_start ( 4063 peers_left,
4085 cfg, 4064 max_outstanding_connections,
4086 peers_left, 4065 max_concurrent_ssh,
4087 max_outstanding_connections, 4066 GNUNET_TIME_relative_multiply
4088 max_concurrent_ssh, 4067 (seconds_per_peer_start, num_peers),
4089 GNUNET_TIME_relative_multiply ( 4068 &hostkey_callback, NULL,
4090 seconds_per_peer_start, 4069 &peers_started_callback, NULL,
4091 num_peers), 4070 &topology_callback, NULL, hosts);
4092 &hostkey_callback, NULL,
4093 &peers_started_callback, NULL,
4094 &topology_callback, NULL, hosts);
4095 temphost = hosts; 4071 temphost = hosts;
4096 while (temphost != NULL) 4072 while (temphost != NULL)
4097 { 4073 {
4098 tempnext = temphost->next; 4074 tempnext = temphost->next;
4099 GNUNET_free (temphost->username); 4075 GNUNET_free (temphost->username);
4100 GNUNET_free (temphost->hostname); 4076 GNUNET_free (temphost->hostname);
4101 GNUNET_free (temphost); 4077 GNUNET_free (temphost);
4102 temphost = tempnext; 4078 temphost = tempnext;
4103 } 4079 }
4104} 4080}
4105 4081
4106int 4082int
4107main(int argc, char *argv[]) 4083main (int argc, char *argv[])
4108{ 4084{
4109 int ret; 4085 int ret;
4110 struct GNUNET_GETOPT_CommandLineOption options[] = 4086
4111 { 4087 struct GNUNET_GETOPT_CommandLineOption options[] = {
4112 GNUNET_GETOPT_OPTION_END }; 4088 GNUNET_GETOPT_OPTION_END
4089 };
4113 4090
4114 ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-driver", "nohelp", options, 4091 ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-driver", "nohelp", options,
4115 &run, &ok); 4092 &run, &ok);
@@ -4118,20 +4095,20 @@ main(int argc, char *argv[])
4118 GNUNET_CONTAINER_bloomfilter_free (malicious_bloom); 4095 GNUNET_CONTAINER_bloomfilter_free (malicious_bloom);
4119 4096
4120 if (ret != GNUNET_OK) 4097 if (ret != GNUNET_OK)
4121 { 4098 {
4122 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4099 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4123 "`gnunet-dht-driver': Failed with error code %d\n", ret); 4100 "`gnunet-dht-driver': Failed with error code %d\n", ret);
4124 } 4101 }
4125 4102
4126 /** 4103 /**
4127 * Need to remove base directory, subdirectories taken care 4104 * Need to remove base directory, subdirectories taken care
4128 * of by the testing framework. 4105 * of by the testing framework.
4129 */ 4106 */
4130 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) 4107 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
4131 { 4108 {
4132 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4109 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4133 "Failed to remove testing directory %s\n", test_directory); 4110 "Failed to remove testing directory %s\n", test_directory);
4134 } 4111 }
4135 return ret; 4112 return ret;
4136} 4113}
4137 4114
diff --git a/src/dht/gnunet-dht-get-peer.c b/src/dht/gnunet-dht-get-peer.c
index 8d318efc2..6ca88d232 100644
--- a/src/dht/gnunet-dht-get-peer.c
+++ b/src/dht/gnunet-dht-get-peer.c
@@ -74,29 +74,25 @@ static unsigned int result_count;
74static int ret; 74static int ret;
75 75
76static void 76static void
77shutdown_task (void *cls, 77shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
78 const struct GNUNET_SCHEDULER_TaskContext *tc)
79{ 78{
80 if (dht_handle != NULL) 79 if (dht_handle != NULL)
81 { 80 {
82 GNUNET_DHT_disconnect (dht_handle); 81 GNUNET_DHT_disconnect (dht_handle);
83 dht_handle = NULL; 82 dht_handle = NULL;
84 } 83 }
85 fprintf (stderr, 84 fprintf (stderr, _("Found %u peers\n"), result_count);
86 _("Found %u peers\n"),
87 result_count);
88} 85}
89 86
90 87
91static void 88static void
92cleanup_task (void *cls, 89cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93 const struct GNUNET_SCHEDULER_TaskContext *tc)
94{ 90{
95 if (find_peer_handle != NULL) 91 if (find_peer_handle != NULL)
96 { 92 {
97 GNUNET_DHT_find_peer_stop (find_peer_handle); 93 GNUNET_DHT_find_peer_stop (find_peer_handle);
98 find_peer_handle = NULL; 94 find_peer_handle = NULL;
99 } 95 }
100 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 96 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
101} 97}
102 98
@@ -107,20 +103,17 @@ cleanup_task (void *cls,
107 * @param cls closure (NULL) 103 * @param cls closure (NULL)
108 * @param hello the response message, a HELLO 104 * @param hello the response message, a HELLO
109 */ 105 */
110static void 106static void
111find_peer_processor (void *cls, 107find_peer_processor (void *cls, const struct GNUNET_HELLO_Message *hello)
112 const struct GNUNET_HELLO_Message *hello)
113{ 108{
114 struct GNUNET_PeerIdentity peer; 109 struct GNUNET_PeerIdentity peer;
115 110
116 if (GNUNET_OK == GNUNET_HELLO_get_id(hello, &peer)) 111 if (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer))
117 { 112 {
118 result_count++; 113 result_count++;
119 if (verbose) 114 if (verbose)
120 fprintf (stderr, 115 fprintf (stderr, _("Found peer `%s'\n"), GNUNET_i2s (&peer));
121 _("Found peer `%s'\n"), 116 }
122 GNUNET_i2s (&peer));
123 }
124} 117}
125 118
126 119
@@ -139,32 +132,33 @@ run (void *cls,
139{ 132{
140 struct GNUNET_TIME_Relative timeout; 133 struct GNUNET_TIME_Relative timeout;
141 GNUNET_HashCode key; 134 GNUNET_HashCode key;
135
142 cfg = c; 136 cfg = c;
143 137
144 if (query_key == NULL) 138 if (query_key == NULL)
145 { 139 {
146 if (verbose) 140 if (verbose)
147 fprintf (stderr, "Must provide key for DHT GET!\n"); 141 fprintf (stderr, "Must provide key for DHT GET!\n");
148 ret = 1; 142 ret = 1;
149 return; 143 return;
150 } 144 }
151 145
152 dht_handle = GNUNET_DHT_connect (cfg, 1); 146 dht_handle = GNUNET_DHT_connect (cfg, 1);
153 147
154 if (dht_handle == NULL) 148 if (dht_handle == NULL)
155 { 149 {
156 if (verbose) 150 if (verbose)
157 fprintf (stderr, "Couldn't connect to DHT service!\n"); 151 fprintf (stderr, "Couldn't connect to DHT service!\n");
158 ret = 1; 152 ret = 1;
159 return; 153 return;
160 } 154 }
161 else if (verbose) 155 else if (verbose)
162 fprintf (stderr, "Connected to DHT service!\n"); 156 fprintf (stderr, "Connected to DHT service!\n");
163 157
164 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 158 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
165 159
166 timeout = 160 timeout =
167 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request); 161 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request);
168 absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout); 162 absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout);
169 163
170 if (verbose) 164 if (verbose)
@@ -173,17 +167,15 @@ run (void *cls,
173 find_peer_handle = GNUNET_DHT_find_peer_start (dht_handle, 167 find_peer_handle = GNUNET_DHT_find_peer_start (dht_handle,
174 timeout, 168 timeout,
175 &key, 169 &key,
176 GNUNET_DHT_RO_NONE, 170 GNUNET_DHT_RO_NONE,
177 &find_peer_processor, 171 &find_peer_processor, NULL);
178 NULL);
179 if (NULL == find_peer_handle) 172 if (NULL == find_peer_handle)
180 { 173 {
181 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 174 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
182 return; 175 return;
183 } 176 }
184 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 177 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
185 (absolute_timeout), 178 (absolute_timeout), &cleanup_task, NULL);
186 &cleanup_task, NULL);
187} 179}
188 180
189 181
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index 8bedc269e..b807a798f 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -82,10 +82,10 @@ static void
82shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 82shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
83{ 83{
84 if (dht_handle != NULL) 84 if (dht_handle != NULL)
85 { 85 {
86 GNUNET_DHT_disconnect (dht_handle); 86 GNUNET_DHT_disconnect (dht_handle);
87 dht_handle = NULL; 87 dht_handle = NULL;
88 } 88 }
89} 89}
90 90
91 91
@@ -93,10 +93,10 @@ static void
93cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 93cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94{ 94{
95 if (get_handle != NULL) 95 if (get_handle != NULL)
96 { 96 {
97 GNUNET_DHT_get_stop (get_handle); 97 GNUNET_DHT_get_stop (get_handle);
98 get_handle = NULL; 98 get_handle = NULL;
99 } 99 }
100 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 100 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
101} 101}
102 102
@@ -120,16 +120,12 @@ void
120get_result_iterator (void *cls, 120get_result_iterator (void *cls,
121 struct GNUNET_TIME_Absolute exp, 121 struct GNUNET_TIME_Absolute exp,
122 const GNUNET_HashCode * key, 122 const GNUNET_HashCode * key,
123 const struct GNUNET_PeerIdentity * const *get_path, 123 const struct GNUNET_PeerIdentity *const *get_path,
124 const struct GNUNET_PeerIdentity * const *put_path, 124 const struct GNUNET_PeerIdentity *const *put_path,
125 enum GNUNET_BLOCK_Type type, 125 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
126 size_t size,
127 const void *data)
128{ 126{
129 fprintf (stdout, "Result %d, type %d:\n%.*s\n", 127 fprintf (stdout, "Result %d, type %d:\n%.*s\n",
130 result_count, type, 128 result_count, type, (unsigned int) size, (char *) data);
131 (unsigned int) size,
132 (char *) data);
133 result_count++; 129 result_count++;
134} 130}
135 131
@@ -149,50 +145,50 @@ run (void *cls,
149{ 145{
150 struct GNUNET_TIME_Relative timeout; 146 struct GNUNET_TIME_Relative timeout;
151 GNUNET_HashCode key; 147 GNUNET_HashCode key;
148
152 cfg = c; 149 cfg = c;
153 150
154 if (query_key == NULL) 151 if (query_key == NULL)
155 { 152 {
156 if (verbose) 153 if (verbose)
157 fprintf (stderr, "Must provide key for DHT GET!\n"); 154 fprintf (stderr, "Must provide key for DHT GET!\n");
158 ret = 1; 155 ret = 1;
159 return; 156 return;
160 } 157 }
161 158
162 dht_handle = GNUNET_DHT_connect (cfg, 1); 159 dht_handle = GNUNET_DHT_connect (cfg, 1);
163 160
164 if (dht_handle == NULL) 161 if (dht_handle == NULL)
165 { 162 {
166 if (verbose) 163 if (verbose)
167 fprintf (stderr, "Couldn't connect to DHT service!\n"); 164 fprintf (stderr, "Couldn't connect to DHT service!\n");
168 ret = 1; 165 ret = 1;
169 return; 166 return;
170 } 167 }
171 else if (verbose) 168 else if (verbose)
172 fprintf (stderr, "Connected to DHT service!\n"); 169 fprintf (stderr, "Connected to DHT service!\n");
173 170
174 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */ 171 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
175 query_type = GNUNET_BLOCK_TYPE_TEST; 172 query_type = GNUNET_BLOCK_TYPE_TEST;
176 173
177 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 174 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
178 175
179 timeout = 176 timeout =
180 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request); 177 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request);
181 absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout); 178 absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout);
182 179
183 if (verbose) 180 if (verbose)
184 fprintf (stderr, "Issuing GET request for %s!\n", query_key); 181 fprintf (stderr, "Issuing GET request for %s!\n", query_key);
185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 182 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
186 (absolute_timeout), &cleanup_task, NULL); 183 (absolute_timeout), &cleanup_task, NULL);
187 get_handle = GNUNET_DHT_get_start (dht_handle, 184 get_handle = GNUNET_DHT_get_start (dht_handle,
188 timeout, 185 timeout,
189 query_type, 186 query_type,
190 &key, 187 &key,
191 DEFAULT_GET_REPLICATION, 188 DEFAULT_GET_REPLICATION,
192 GNUNET_DHT_RO_NONE, 189 GNUNET_DHT_RO_NONE,
193 NULL, 0, 190 NULL, 0,
194 NULL, 0, 191 NULL, 0, &get_result_iterator, NULL);
195 &get_result_iterator, NULL);
196 192
197} 193}
198 194
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c
index 02a4fc217..b76b92c2b 100644
--- a/src/dht/gnunet-dht-put.c
+++ b/src/dht/gnunet-dht-put.c
@@ -76,10 +76,10 @@ static void
76shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 76shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
77{ 77{
78 if (dht_handle != NULL) 78 if (dht_handle != NULL)
79 { 79 {
80 GNUNET_DHT_disconnect (dht_handle); 80 GNUNET_DHT_disconnect (dht_handle);
81 dht_handle = NULL; 81 dht_handle = NULL;
82 } 82 }
83} 83}
84 84
85/** 85/**
@@ -92,8 +92,7 @@ void
92message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 92message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93{ 93{
94 if (verbose) 94 if (verbose)
95 fprintf (stderr, 95 fprintf (stderr, _("PUT request sent!\n"));
96 _("PUT request sent!\n"));
97 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 96 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
98} 97}
99 98
@@ -113,40 +112,37 @@ run (void *cls,
113 struct GNUNET_TIME_Relative timeout; 112 struct GNUNET_TIME_Relative timeout;
114 struct GNUNET_TIME_Absolute expiration; 113 struct GNUNET_TIME_Absolute expiration;
115 GNUNET_HashCode key; 114 GNUNET_HashCode key;
115
116 cfg = c; 116 cfg = c;
117 117
118 if ( (query_key == NULL) || (data == NULL) ) 118 if ((query_key == NULL) || (data == NULL))
119 { 119 {
120 fprintf (stderr, 120 fprintf (stderr, _("Must provide KEY and DATA for DHT put!\n"));
121 _("Must provide KEY and DATA for DHT put!\n")); 121 ret = 1;
122 ret = 1; 122 return;
123 return; 123 }
124 }
125 124
126 dht_handle = GNUNET_DHT_connect (cfg, 1); 125 dht_handle = GNUNET_DHT_connect (cfg, 1);
127 if (dht_handle == NULL) 126 if (dht_handle == NULL)
128 { 127 {
129 fprintf (stderr, 128 fprintf (stderr, _("Could not connect to %s service!\n"), "DHT");
130 _("Could not connect to %s service!\n"), 129 ret = 1;
131 "DHT"); 130 return;
132 ret = 1; 131 }
133 return;
134 }
135 else if (verbose) 132 else if (verbose)
136 fprintf (stderr, 133 fprintf (stderr, _("Connected to %s service!\n"), "DHT");
137 _("Connected to %s service!\n"), "DHT");
138 134
139 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */ 135 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
140 query_type = GNUNET_BLOCK_TYPE_TEST; 136 query_type = GNUNET_BLOCK_TYPE_TEST;
141 137
142 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 138 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
143 139
144 timeout = 140 timeout =
145 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request); 141 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request);
146 expiration = 142 expiration =
147 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply 143 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
148 (GNUNET_TIME_UNIT_SECONDS, 144 (GNUNET_TIME_UNIT_SECONDS,
149 expiration_seconds)); 145 expiration_seconds));
150 146
151 if (verbose) 147 if (verbose)
152 fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"), 148 fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"),
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 83cb84c9c..19250d07b 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -967,20 +967,21 @@ get_average_send_delay ()
967 unsigned int i; 967 unsigned int i;
968 unsigned int divisor; 968 unsigned int divisor;
969 struct GNUNET_TIME_Relative average_time; 969 struct GNUNET_TIME_Relative average_time;
970
970 average_time = GNUNET_TIME_relative_get_zero (); 971 average_time = GNUNET_TIME_relative_get_zero ();
971 divisor = 0; 972 divisor = 0;
972 for (i = 0; i < MAX_REPLY_TIMES; i++) 973 for (i = 0; i < MAX_REPLY_TIMES; i++)
973 { 974 {
974 average_time = GNUNET_TIME_relative_add (average_time, reply_times[i]); 975 average_time = GNUNET_TIME_relative_add (average_time, reply_times[i]);
975 if (reply_times[i].abs_value == (uint64_t) 0) 976 if (reply_times[i].abs_value == (uint64_t) 0)
976 continue; 977 continue;
977 else 978 else
978 divisor++; 979 divisor++;
979 } 980 }
980 if (divisor == 0) 981 if (divisor == 0)
981 { 982 {
982 return average_time; 983 return average_time;
983 } 984 }
984 985
985 average_time = GNUNET_TIME_relative_divide (average_time, divisor); 986 average_time = GNUNET_TIME_relative_divide (average_time, divisor);
986 fprintf (stderr, 987 fprintf (stderr,
@@ -999,14 +1000,15 @@ static void
999decrease_max_send_delay (struct GNUNET_TIME_Relative max_time) 1000decrease_max_send_delay (struct GNUNET_TIME_Relative max_time)
1000{ 1001{
1001 unsigned int i; 1002 unsigned int i;
1003
1002 for (i = 0; i < MAX_REPLY_TIMES; i++) 1004 for (i = 0; i < MAX_REPLY_TIMES; i++)
1005 {
1006 if (reply_times[i].rel_value == max_time.rel_value)
1003 { 1007 {
1004 if (reply_times[i].rel_value == max_time.rel_value) 1008 reply_times[i].rel_value = reply_times[i].rel_value / 2;
1005 { 1009 return;
1006 reply_times[i].rel_value = reply_times[i].rel_value / 2;
1007 return;
1008 }
1009 } 1010 }
1011 }
1010} 1012}
1011 1013
1012/** 1014/**
@@ -1020,13 +1022,14 @@ get_max_send_delay ()
1020{ 1022{
1021 unsigned int i; 1023 unsigned int i;
1022 struct GNUNET_TIME_Relative max_time; 1024 struct GNUNET_TIME_Relative max_time;
1025
1023 max_time = GNUNET_TIME_relative_get_zero (); 1026 max_time = GNUNET_TIME_relative_get_zero ();
1024 1027
1025 for (i = 0; i < MAX_REPLY_TIMES; i++) 1028 for (i = 0; i < MAX_REPLY_TIMES; i++)
1026 { 1029 {
1027 if (reply_times[i].rel_value > max_time.rel_value) 1030 if (reply_times[i].rel_value > max_time.rel_value)
1028 max_time.rel_value = reply_times[i].rel_value; 1031 max_time.rel_value = reply_times[i].rel_value;
1029 } 1032 }
1030#if DEBUG_DHT 1033#if DEBUG_DHT
1031 if (max_time.rel_value > MAX_REQUEST_TIME.rel_value) 1034 if (max_time.rel_value > MAX_REQUEST_TIME.rel_value)
1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Max send delay was %llu\n", 1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Max send delay was %llu\n",
@@ -1039,18 +1042,18 @@ static void
1039increment_stats (const char *value) 1042increment_stats (const char *value)
1040{ 1043{
1041 if (stats != NULL) 1044 if (stats != NULL)
1042 { 1045 {
1043 GNUNET_STATISTICS_update (stats, value, 1, GNUNET_NO); 1046 GNUNET_STATISTICS_update (stats, value, 1, GNUNET_NO);
1044 } 1047 }
1045} 1048}
1046 1049
1047static void 1050static void
1048decrement_stats (const char *value) 1051decrement_stats (const char *value)
1049{ 1052{
1050 if (stats != NULL) 1053 if (stats != NULL)
1051 { 1054 {
1052 GNUNET_STATISTICS_update (stats, value, -1, GNUNET_NO); 1055 GNUNET_STATISTICS_update (stats, value, -1, GNUNET_NO);
1053 } 1056 }
1054} 1057}
1055 1058
1056/** 1059/**
@@ -1065,7 +1068,7 @@ try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1065 1068
1066 peer->send_task = GNUNET_SCHEDULER_NO_TASK; 1069 peer->send_task = GNUNET_SCHEDULER_NO_TASK;
1067 1070
1068 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 1071 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1069 return; 1072 return;
1070 1073
1071 if (peer->th != NULL) 1074 if (peer->th != NULL)
@@ -1073,26 +1076,26 @@ try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1073 1076
1074 pending = peer->head; 1077 pending = peer->head;
1075 if (pending != NULL) 1078 if (pending != NULL)
1076 { 1079 {
1077 ssize = ntohs (pending->msg->size); 1080 ssize = ntohs (pending->msg->size);
1078#if DEBUG_DHT > 1 1081#if DEBUG_DHT > 1
1079 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1080 "`%s:%s': Calling notify_transmit_ready with size %d for peer %s\n", 1083 "`%s:%s': Calling notify_transmit_ready with size %d for peer %s\n",
1081 my_short_id, "DHT", ssize, GNUNET_i2s (&peer->id)); 1084 my_short_id, "DHT", ssize, GNUNET_i2s (&peer->id));
1082#endif 1085#endif
1083 pending->scheduled = GNUNET_TIME_absolute_get (); 1086 pending->scheduled = GNUNET_TIME_absolute_get ();
1084 reply_counter++; 1087 reply_counter++;
1085 if (reply_counter >= MAX_REPLY_TIMES) 1088 if (reply_counter >= MAX_REPLY_TIMES)
1086 reply_counter = 0; 1089 reply_counter = 0;
1087 peer->th = 1090 peer->th =
1088 GNUNET_CORE_notify_transmit_ready (coreAPI, 1091 GNUNET_CORE_notify_transmit_ready (coreAPI,
1089 GNUNET_YES, 1092 GNUNET_YES,
1090 pending->importance, 1093 pending->importance,
1091 pending->timeout, &peer->id, ssize, 1094 pending->timeout, &peer->id, ssize,
1092 &core_transmit_notify, peer); 1095 &core_transmit_notify, peer);
1093 if (peer->th == NULL) 1096 if (peer->th == NULL)
1094 increment_stats ("# notify transmit ready failed"); 1097 increment_stats ("# notify transmit ready failed");
1095 } 1098 }
1096} 1099}
1097 1100
1098/** 1101/**
@@ -1115,13 +1118,15 @@ forward_result_message (const struct GNUNET_MessageHeader *msg,
1115 size_t psize; 1118 size_t psize;
1116 char *path_start; 1119 char *path_start;
1117 char *path_offset; 1120 char *path_offset;
1121
1118#if DEBUG_PATH 1122#if DEBUG_PATH
1119 unsigned int i; 1123 unsigned int i;
1120#endif 1124#endif
1121 1125
1122 increment_stats (STAT_RESULT_FORWARDS); 1126 increment_stats (STAT_RESULT_FORWARDS);
1123 msize = 1127 msize =
1124 sizeof (struct GNUNET_DHT_P2PRouteResultMessage) + ntohs (msg->size) + (sizeof(struct GNUNET_PeerIdentity) * msg_ctx->path_history_len); 1128 sizeof (struct GNUNET_DHT_P2PRouteResultMessage) + ntohs (msg->size) +
1129 (sizeof (struct GNUNET_PeerIdentity) * msg_ctx->path_history_len);
1125 GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); 1130 GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
1126 psize = sizeof (struct P2PPendingMessage) + msize; 1131 psize = sizeof (struct P2PPendingMessage) + msize;
1127 pending = GNUNET_malloc (psize); 1132 pending = GNUNET_malloc (psize);
@@ -1131,23 +1136,28 @@ forward_result_message (const struct GNUNET_MessageHeader *msg,
1131 result_message = (struct GNUNET_DHT_P2PRouteResultMessage *) pending->msg; 1136 result_message = (struct GNUNET_DHT_P2PRouteResultMessage *) pending->msg;
1132 result_message->header.size = htons (msize); 1137 result_message->header.size = htons (msize);
1133 result_message->header.type = 1138 result_message->header.type =
1134 htons (GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT); 1139 htons (GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT);
1135 result_message->outgoing_path_length = htonl (msg_ctx->path_history_len); 1140 result_message->outgoing_path_length = htonl (msg_ctx->path_history_len);
1136 if (msg_ctx->path_history_len > 0) 1141 if (msg_ctx->path_history_len > 0)
1137 { 1142 {
1138 /* End of pending is where enc_msg starts */ 1143 /* End of pending is where enc_msg starts */
1139 path_start = (char *)&pending[1]; 1144 path_start = (char *) &pending[1];
1140 /* Offset by the size of the enc_msg */ 1145 /* Offset by the size of the enc_msg */
1141 path_start += ntohs (msg->size); 1146 path_start += ntohs (msg->size);
1142 memcpy(path_start, msg_ctx->path_history, msg_ctx->path_history_len * (sizeof(struct GNUNET_PeerIdentity))); 1147 memcpy (path_start, msg_ctx->path_history,
1148 msg_ctx->path_history_len * (sizeof (struct GNUNET_PeerIdentity)));
1143#if DEBUG_PATH 1149#if DEBUG_PATH
1144 for (i = 0; i < msg_ctx->path_history_len; i++) 1150 for (i = 0; i < msg_ctx->path_history_len; i++)
1145 { 1151 {
1146 path_offset = &msg_ctx->path_history[i * sizeof(struct GNUNET_PeerIdentity)]; 1152 path_offset =
1147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(forward_result) Key %s Found peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); 1153 &msg_ctx->path_history[i * sizeof (struct GNUNET_PeerIdentity)];
1148 } 1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1149#endif 1155 "(forward_result) Key %s Found peer %d:%s\n",
1156 GNUNET_h2s (&msg_ctx->key), i,
1157 GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
1150 } 1158 }
1159#endif
1160 }
1151 result_message->options = htonl (msg_ctx->msg_options); 1161 result_message->options = htonl (msg_ctx->msg_options);
1152 result_message->hop_count = htonl (msg_ctx->hop_count + 1); 1162 result_message->hop_count = htonl (msg_ctx->hop_count + 1);
1153 GNUNET_assert (GNUNET_OK == 1163 GNUNET_assert (GNUNET_OK ==
@@ -1159,11 +1169,12 @@ forward_result_message (const struct GNUNET_MessageHeader *msg,
1159 memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 1169 memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
1160 /* Copy the enc_msg, then the path history as well! */ 1170 /* Copy the enc_msg, then the path history as well! */
1161 memcpy (&result_message[1], msg, ntohs (msg->size)); 1171 memcpy (&result_message[1], msg, ntohs (msg->size));
1162 path_offset = (char *)&result_message[1]; 1172 path_offset = (char *) &result_message[1];
1163 path_offset += ntohs (msg->size); 1173 path_offset += ntohs (msg->size);
1164 /* If we have path history, copy it to the end of the whole thing */ 1174 /* If we have path history, copy it to the end of the whole thing */
1165 if (msg_ctx->path_history_len > 0) 1175 if (msg_ctx->path_history_len > 0)
1166 memcpy(path_offset, msg_ctx->path_history, msg_ctx->path_history_len * (sizeof(struct GNUNET_PeerIdentity))); 1176 memcpy (path_offset, msg_ctx->path_history,
1177 msg_ctx->path_history_len * (sizeof (struct GNUNET_PeerIdentity)));
1167#if DEBUG_DHT > 1 1178#if DEBUG_DHT > 1
1168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1169 "%s:%s Adding pending message size %d for peer %s\n", 1180 "%s:%s Adding pending message size %d for peer %s\n",
@@ -1196,16 +1207,17 @@ core_transmit_notify (void *cls, size_t size, void *buf)
1196 1207
1197 size_t off; 1208 size_t off;
1198 size_t msize; 1209 size_t msize;
1210
1199 peer->th = NULL; 1211 peer->th = NULL;
1200 if (buf == NULL) 1212 if (buf == NULL)
1201 { 1213 {
1202 /* client disconnected */ 1214 /* client disconnected */
1203#if DEBUG_DHT 1215#if DEBUG_DHT
1204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': buffer was NULL\n", 1216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': buffer was NULL\n",
1205 my_short_id, "DHT"); 1217 my_short_id, "DHT");
1206#endif 1218#endif
1207 return 0; 1219 return 0;
1208 } 1220 }
1209 1221
1210 if (peer->head == NULL) 1222 if (peer->head == NULL)
1211 return 0; 1223 return 0;
@@ -1214,31 +1226,31 @@ core_transmit_notify (void *cls, size_t size, void *buf)
1214 pending = peer->head; 1226 pending = peer->head;
1215#if DUMB 1227#if DUMB
1216 reply_times[reply_counter] = 1228 reply_times[reply_counter] =
1217 GNUNET_TIME_absolute_get_difference (pending->scheduled, 1229 GNUNET_TIME_absolute_get_difference (pending->scheduled,
1218 GNUNET_TIME_absolute_get ()); 1230 GNUNET_TIME_absolute_get ());
1219 msize = ntohs (pending->msg->size); 1231 msize = ntohs (pending->msg->size);
1220 if (msize <= size) 1232 if (msize <= size)
1221 { 1233 {
1222 off = msize; 1234 off = msize;
1223 memcpy (cbuf, pending->msg, msize); 1235 memcpy (cbuf, pending->msg, msize);
1224 peer->pending_count--; 1236 peer->pending_count--;
1225 increment_stats ("# pending messages sent"); 1237 increment_stats ("# pending messages sent");
1226 GNUNET_assert (peer->pending_count >= 0); 1238 GNUNET_assert (peer->pending_count >= 0);
1227 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); 1239 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
1228 GNUNET_free (pending); 1240 GNUNET_free (pending);
1229 } 1241 }
1230#else 1242#else
1231 while (NULL != pending && 1243 while (NULL != pending &&
1232 (size - off >= (msize = ntohs (pending->msg->size)))) 1244 (size - off >= (msize = ntohs (pending->msg->size))))
1233 { 1245 {
1234 memcpy (&cbuf[off], pending->msg, msize); 1246 memcpy (&cbuf[off], pending->msg, msize);
1235 off += msize; 1247 off += msize;
1236 peer->pending_count--; 1248 peer->pending_count--;
1237 increment_stats ("# pending messages sent"); 1249 increment_stats ("# pending messages sent");
1238 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); 1250 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
1239 GNUNET_free (pending); 1251 GNUNET_free (pending);
1240 pending = peer->head; 1252 pending = peer->head;
1241 } 1253 }
1242#endif 1254#endif
1243 if ((peer->head != NULL) && (peer->send_task == GNUNET_SCHEDULER_NO_TASK)) 1255 if ((peer->head != NULL) && (peer->send_task == GNUNET_SCHEDULER_NO_TASK))
1244 peer->send_task = GNUNET_SCHEDULER_add_now (&try_core_send, peer); 1256 peer->send_task = GNUNET_SCHEDULER_add_now (&try_core_send, peer);
@@ -1265,43 +1277,43 @@ distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have)
1265 unsigned int i; 1277 unsigned int i;
1266 1278
1267 /* We have to represent the distance between two 2^9 (=512)-bit 1279 /* We have to represent the distance between two 2^9 (=512)-bit
1268 numbers as a 2^5 (=32)-bit number with "0" being used for the 1280 * numbers as a 2^5 (=32)-bit number with "0" being used for the
1269 two numbers being identical; furthermore, we need to 1281 * two numbers being identical; furthermore, we need to
1270 guarantee that a difference in the number of matching 1282 * guarantee that a difference in the number of matching
1271 bits is always represented in the result. 1283 * bits is always represented in the result.
1272 1284 *
1273 We use 2^32/2^9 numerical values to distinguish between 1285 * We use 2^32/2^9 numerical values to distinguish between
1274 hash codes that have the same LSB bit distance and 1286 * hash codes that have the same LSB bit distance and
1275 use the highest 2^9 bits of the result to signify the 1287 * use the highest 2^9 bits of the result to signify the
1276 number of (mis)matching LSB bits; if we have 0 matching 1288 * number of (mis)matching LSB bits; if we have 0 matching
1277 and hence 512 mismatching LSB bits we return -1 (since 1289 * and hence 512 mismatching LSB bits we return -1 (since
1278 512 itself cannot be represented with 9 bits) */ 1290 * 512 itself cannot be represented with 9 bits) */
1279 1291
1280 /* first, calculate the most significant 9 bits of our 1292 /* first, calculate the most significant 9 bits of our
1281 result, aka the number of LSBs */ 1293 * result, aka the number of LSBs */
1282 bucket = GNUNET_CRYPTO_hash_matching_bits (target, have); 1294 bucket = GNUNET_CRYPTO_hash_matching_bits (target, have);
1283 /* bucket is now a value between 0 and 512 */ 1295 /* bucket is now a value between 0 and 512 */
1284 if (bucket == 512) 1296 if (bucket == 512)
1285 return 0; /* perfect match */ 1297 return 0; /* perfect match */
1286 if (bucket == 0) 1298 if (bucket == 0)
1287 return (unsigned int) -1; /* LSB differs; use max (if we did the bit-shifting 1299 return (unsigned int) -1; /* LSB differs; use max (if we did the bit-shifting
1288 below, we'd end up with max+1 (overflow)) */ 1300 * below, we'd end up with max+1 (overflow)) */
1289 1301
1290 /* calculate the most significant bits of the final result */ 1302 /* calculate the most significant bits of the final result */
1291 msb = (512 - bucket) << (32 - 9); 1303 msb = (512 - bucket) << (32 - 9);
1292 /* calculate the 32-9 least significant bits of the final result by 1304 /* calculate the 32-9 least significant bits of the final result by
1293 looking at the differences in the 32-9 bits following the 1305 * looking at the differences in the 32-9 bits following the
1294 mismatching bit at 'bucket' */ 1306 * mismatching bit at 'bucket' */
1295 lsb = 0; 1307 lsb = 0;
1296 for (i = bucket + 1; 1308 for (i = bucket + 1;
1297 (i < sizeof (GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); i++) 1309 (i < sizeof (GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); i++)
1298 { 1310 {
1299 if (GNUNET_CRYPTO_hash_get_bit (target, i) != 1311 if (GNUNET_CRYPTO_hash_get_bit (target, i) !=
1300 GNUNET_CRYPTO_hash_get_bit (have, i)) 1312 GNUNET_CRYPTO_hash_get_bit (have, i))
1301 lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, 1313 lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10,
1302 last bit set will be 31 -- if 1314 * last bit set will be 31 -- if
1303 i does not reach 512 first... */ 1315 * i does not reach 512 first... */
1304 } 1316 }
1305 return msb | lsb; 1317 return msb | lsb;
1306} 1318}
1307 1319
@@ -1313,8 +1325,7 @@ distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have)
1313 * Must fudge the value if NO bits match. 1325 * Must fudge the value if NO bits match.
1314 */ 1326 */
1315static unsigned int 1327static unsigned int
1316inverse_distance (const GNUNET_HashCode * target, 1328inverse_distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have)
1317 const GNUNET_HashCode * have)
1318{ 1329{
1319 if (GNUNET_CRYPTO_hash_matching_bits (target, have) == 0) 1330 if (GNUNET_CRYPTO_hash_matching_bits (target, have) == 0)
1320 return 1; /* Never return 0! */ 1331 return 1; /* Never return 0! */
@@ -1359,11 +1370,11 @@ static int
1359find_current_bucket (const GNUNET_HashCode * hc) 1370find_current_bucket (const GNUNET_HashCode * hc)
1360{ 1371{
1361 int actual_bucket; 1372 int actual_bucket;
1362 1373
1363 actual_bucket = find_bucket (hc); 1374 actual_bucket = find_bucket (hc);
1364 if (actual_bucket == GNUNET_SYSERR) /* hc and our peer identity match! */ 1375 if (actual_bucket == GNUNET_SYSERR) /* hc and our peer identity match! */
1365 return lowest_bucket; 1376 return lowest_bucket;
1366 if (actual_bucket < lowest_bucket) /* actual_bucket not yet used */ 1377 if (actual_bucket < lowest_bucket) /* actual_bucket not yet used */
1367 return lowest_bucket; 1378 return lowest_bucket;
1368 return actual_bucket; 1379 return actual_bucket;
1369} 1380}
@@ -1383,15 +1394,15 @@ find_bucket_by_peer (const struct PeerInfo *peer)
1383 struct PeerInfo *pos; 1394 struct PeerInfo *pos;
1384 1395
1385 for (bucket = lowest_bucket; bucket < MAX_BUCKETS - 1; bucket++) 1396 for (bucket = lowest_bucket; bucket < MAX_BUCKETS - 1; bucket++)
1397 {
1398 pos = k_buckets[bucket].head;
1399 while (pos != NULL)
1386 { 1400 {
1387 pos = k_buckets[bucket].head; 1401 if (peer == pos)
1388 while (pos != NULL) 1402 return bucket;
1389 { 1403 pos = pos->next;
1390 if (peer == pos)
1391 return bucket;
1392 pos = pos->next;
1393 }
1394 } 1404 }
1405 }
1395 1406
1396 return GNUNET_SYSERR; /* No such peer. */ 1407 return GNUNET_SYSERR; /* No such peer. */
1397} 1408}
@@ -1408,30 +1419,30 @@ print_routing_table ()
1408 struct PeerInfo *pos; 1419 struct PeerInfo *pos;
1409 char char_buf[30000]; 1420 char char_buf[30000];
1410 int char_pos; 1421 int char_pos;
1422
1411 memset (char_buf, 0, sizeof (char_buf)); 1423 memset (char_buf, 0, sizeof (char_buf));
1412 char_pos = 0; 1424 char_pos = 0;
1413 char_pos += 1425 char_pos +=
1414 sprintf (&char_buf[char_pos], "Printing routing table for peer %s\n", 1426 sprintf (&char_buf[char_pos], "Printing routing table for peer %s\n",
1415 my_short_id); 1427 my_short_id);
1416 //fprintf(stderr, "Printing routing table for peer %s\n", my_short_id); 1428 //fprintf(stderr, "Printing routing table for peer %s\n", my_short_id);
1417 for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++) 1429 for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++)
1418 { 1430 {
1419 pos = k_buckets[bucket].head; 1431 pos = k_buckets[bucket].head;
1420 char_pos += sprintf (&char_buf[char_pos], "Bucket %d:\n", bucket); 1432 char_pos += sprintf (&char_buf[char_pos], "Bucket %d:\n", bucket);
1421 //fprintf(stderr, "Bucket %d:\n", bucket); 1433 //fprintf(stderr, "Bucket %d:\n", bucket);
1422 while (pos != NULL) 1434 while (pos != NULL)
1423 { 1435 {
1424 //fprintf(stderr, "\tPeer %s, best bucket %d, %d bits match\n", GNUNET_i2s(&pos->id), find_bucket(&pos->id.hashPubKey), GNUNET_CRYPTO_hash_matching_bits(&pos->id.hashPubKey, &my_identity.hashPubKey)); 1436 //fprintf(stderr, "\tPeer %s, best bucket %d, %d bits match\n", GNUNET_i2s(&pos->id), find_bucket(&pos->id.hashPubKey), GNUNET_CRYPTO_hash_matching_bits(&pos->id.hashPubKey, &my_identity.hashPubKey));
1425 char_pos += 1437 char_pos +=
1426 sprintf (&char_buf[char_pos], 1438 sprintf (&char_buf[char_pos],
1427 "\tPeer %s, best bucket %d, %d bits match\n", 1439 "\tPeer %s, best bucket %d, %d bits match\n",
1428 GNUNET_i2s (&pos->id), find_bucket (&pos->id.hashPubKey), 1440 GNUNET_i2s (&pos->id), find_bucket (&pos->id.hashPubKey),
1429 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, 1441 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
1430 &my_identity. 1442 &my_identity.hashPubKey));
1431 hashPubKey)); 1443 pos = pos->next;
1432 pos = pos->next;
1433 }
1434 } 1444 }
1445 }
1435 fprintf (stderr, "%s", char_buf); 1446 fprintf (stderr, "%s", char_buf);
1436 fflush (stderr); 1447 fflush (stderr);
1437} 1448}
@@ -1449,6 +1460,7 @@ find_peer_by_id (const struct GNUNET_PeerIdentity *peer)
1449{ 1460{
1450 int bucket; 1461 int bucket;
1451 struct PeerInfo *pos; 1462 struct PeerInfo *pos;
1463
1452 bucket = find_current_bucket (&peer->hashPubKey); 1464 bucket = find_current_bucket (&peer->hashPubKey);
1453 1465
1454 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 1466 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
@@ -1456,11 +1468,11 @@ find_peer_by_id (const struct GNUNET_PeerIdentity *peer)
1456 1468
1457 pos = k_buckets[bucket].head; 1469 pos = k_buckets[bucket].head;
1458 while (pos != NULL) 1470 while (pos != NULL)
1459 { 1471 {
1460 if (0 == memcmp (&pos->id, peer, sizeof (struct GNUNET_PeerIdentity))) 1472 if (0 == memcmp (&pos->id, peer, sizeof (struct GNUNET_PeerIdentity)))
1461 return pos; 1473 return pos;
1462 pos = pos->next; 1474 pos = pos->next;
1463 } 1475 }
1464 return NULL; /* No such peer. */ 1476 return NULL; /* No such peer. */
1465} 1477}
1466 1478
@@ -1484,9 +1496,9 @@ static void
1484update_core_preference_finish (void *cls, 1496update_core_preference_finish (void *cls,
1485 const struct GNUNET_PeerIdentity *peer, 1497 const struct GNUNET_PeerIdentity *peer,
1486 struct GNUNET_BANDWIDTH_Value32NBO bpm_out, 1498 struct GNUNET_BANDWIDTH_Value32NBO bpm_out,
1487 int32_t amount, 1499 int32_t amount,
1488 struct GNUNET_TIME_Relative res_delay, 1500 struct GNUNET_TIME_Relative res_delay,
1489 uint64_t preference) 1501 uint64_t preference)
1490{ 1502{
1491 struct PeerInfo *peer_info = cls; 1503 struct PeerInfo *peer_info = cls;
1492 1504
@@ -1502,28 +1514,29 @@ update_core_preference (void *cls,
1502 struct PeerInfo *peer = cls; 1514 struct PeerInfo *peer = cls;
1503 uint64_t preference; 1515 uint64_t preference;
1504 unsigned int matching; 1516 unsigned int matching;
1505 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 1517
1506 { 1518 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1507 return; 1519 {
1508 } 1520 return;
1521 }
1509 matching = 1522 matching =
1510 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, 1523 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
1511 &peer->id.hashPubKey); 1524 &peer->id.hashPubKey);
1512 if (matching >= 64) 1525 if (matching >= 64)
1513 { 1526 {
1514#if DEBUG_DHT 1527#if DEBUG_DHT
1515 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1528 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1516 "Peer identifier matches by %u bits, only shifting as much as we can!\n", 1529 "Peer identifier matches by %u bits, only shifting as much as we can!\n",
1517 matching); 1530 matching);
1518#endif 1531#endif
1519 matching = 63; 1532 matching = 63;
1520 } 1533 }
1521 preference = 1LL << matching; 1534 preference = 1LL << matching;
1522 peer->info_ctx = GNUNET_CORE_peer_change_preference (coreAPI, 1535 peer->info_ctx = GNUNET_CORE_peer_change_preference (coreAPI,
1523 &peer->id, 1536 &peer->id,
1524 GNUNET_TIME_UNIT_FOREVER_REL, 1537 GNUNET_TIME_UNIT_FOREVER_REL,
1525 GNUNET_BANDWIDTH_VALUE_MAX, 1538 GNUNET_BANDWIDTH_VALUE_MAX,
1526 0, 1539 0,
1527 preference, 1540 preference,
1528 &update_core_preference_finish, 1541 &update_core_preference_finish,
1529 peer); 1542 peer);
@@ -1566,6 +1579,7 @@ delete_peer (struct PeerInfo *peer, unsigned int bucket)
1566{ 1579{
1567 struct P2PPendingMessage *pos; 1580 struct P2PPendingMessage *pos;
1568 struct P2PPendingMessage *next; 1581 struct P2PPendingMessage *next;
1582
1569#if EXTRA_CHECKS 1583#if EXTRA_CHECKS
1570 struct PeerInfo *peer_pos; 1584 struct PeerInfo *peer_pos;
1571 1585
@@ -1573,16 +1587,16 @@ delete_peer (struct PeerInfo *peer, unsigned int bucket)
1573 while ((peer_pos != NULL) && (peer_pos != peer)) 1587 while ((peer_pos != NULL) && (peer_pos != peer))
1574 peer_pos = peer_pos->next; 1588 peer_pos = peer_pos->next;
1575 if (peer_pos == NULL) 1589 if (peer_pos == NULL)
1576 { 1590 {
1577 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1591 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1578 "%s:%s: Expected peer `%s' in bucket %d\n", my_short_id, 1592 "%s:%s: Expected peer `%s' in bucket %d\n", my_short_id,
1579 "DHT", GNUNET_i2s (&peer->id), bucket); 1593 "DHT", GNUNET_i2s (&peer->id), bucket);
1580 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1581 "%s:%s: Lowest bucket: %d, find_current_bucket: %d, peer resides in bucket: %d\n", 1595 "%s:%s: Lowest bucket: %d, find_current_bucket: %d, peer resides in bucket: %d\n",
1582 my_short_id, "DHT", lowest_bucket, 1596 my_short_id, "DHT", lowest_bucket,
1583 find_current_bucket (&peer->id.hashPubKey), 1597 find_current_bucket (&peer->id.hashPubKey),
1584 find_bucket_by_peer (peer)); 1598 find_bucket_by_peer (peer));
1585 } 1599 }
1586 GNUNET_assert (peer_pos != NULL); 1600 GNUNET_assert (peer_pos != NULL);
1587#endif 1601#endif
1588 remove_peer (peer, bucket); /* First remove the peer from its bucket */ 1602 remove_peer (peer, bucket); /* First remove the peer from its bucket */
@@ -1594,13 +1608,13 @@ delete_peer (struct PeerInfo *peer, unsigned int bucket)
1594 1608
1595 pos = peer->head; 1609 pos = peer->head;
1596 while (pos != NULL) /* Remove any pending messages for this peer */ 1610 while (pos != NULL) /* Remove any pending messages for this peer */
1597 { 1611 {
1598 increment_stats 1612 increment_stats
1599 ("# dht pending messages discarded (due to disconnect/shutdown)"); 1613 ("# dht pending messages discarded (due to disconnect/shutdown)");
1600 next = pos->next; 1614 next = pos->next;
1601 GNUNET_free (pos); 1615 GNUNET_free (pos);
1602 pos = next; 1616 pos = next;
1603 } 1617 }
1604 1618
1605 GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains 1619 GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains
1606 (all_known_peers, &peer->id.hashPubKey)); 1620 (all_known_peers, &peer->id.hashPubKey));
@@ -1609,7 +1623,7 @@ delete_peer (struct PeerInfo *peer, unsigned int bucket)
1609 &peer->id.hashPubKey, 1623 &peer->id.hashPubKey,
1610 peer)); 1624 peer));
1611 GNUNET_free (peer); 1625 GNUNET_free (peer);
1612 decrement_stats(STAT_PEERS_KNOWN); 1626 decrement_stats (STAT_PEERS_KNOWN);
1613} 1627}
1614 1628
1615 1629
@@ -1650,6 +1664,7 @@ enable_next_bucket ()
1650{ 1664{
1651 struct GNUNET_CONTAINER_MultiHashMap *to_remove; 1665 struct GNUNET_CONTAINER_MultiHashMap *to_remove;
1652 struct PeerInfo *pos; 1666 struct PeerInfo *pos;
1667
1653 GNUNET_assert (lowest_bucket > 0); 1668 GNUNET_assert (lowest_bucket > 0);
1654 to_remove = GNUNET_CONTAINER_multihashmap_create (bucket_size); 1669 to_remove = GNUNET_CONTAINER_multihashmap_create (bucket_size);
1655 pos = k_buckets[lowest_bucket].head; 1670 pos = k_buckets[lowest_bucket].head;
@@ -1660,17 +1675,16 @@ enable_next_bucket ()
1660#endif 1675#endif
1661 /* Populate the array of peers which should be in the next lowest bucket */ 1676 /* Populate the array of peers which should be in the next lowest bucket */
1662 while (pos != NULL) 1677 while (pos != NULL)
1663 { 1678 {
1664 if (find_bucket (&pos->id.hashPubKey) < lowest_bucket) 1679 if (find_bucket (&pos->id.hashPubKey) < lowest_bucket)
1665 GNUNET_CONTAINER_multihashmap_put (to_remove, &pos->id.hashPubKey, 1680 GNUNET_CONTAINER_multihashmap_put (to_remove, &pos->id.hashPubKey,
1666 pos, 1681 pos,
1667 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1682 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1668 pos = pos->next; 1683 pos = pos->next;
1669 } 1684 }
1670 1685
1671 /* Remove peers from lowest bucket, insert into next lowest bucket */ 1686 /* Remove peers from lowest bucket, insert into next lowest bucket */
1672 GNUNET_CONTAINER_multihashmap_iterate (to_remove, &move_lowest_bucket, 1687 GNUNET_CONTAINER_multihashmap_iterate (to_remove, &move_lowest_bucket, NULL);
1673 NULL);
1674 GNUNET_CONTAINER_multihashmap_destroy (to_remove); 1688 GNUNET_CONTAINER_multihashmap_destroy (to_remove);
1675 lowest_bucket = lowest_bucket - 1; 1689 lowest_bucket = lowest_bucket - 1;
1676#if PRINT_TABLES 1690#if PRINT_TABLES
@@ -1703,21 +1717,21 @@ find_closest_peer (const GNUNET_HashCode * hc)
1703 1717
1704 current_closest = NULL; 1718 current_closest = NULL;
1705 for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++) 1719 for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++)
1706 { 1720 {
1707 pos = k_buckets[bucket].head; 1721 pos = k_buckets[bucket].head;
1708 count = 0; 1722 count = 0;
1709 while ((pos != NULL) && (count < bucket_size)) 1723 while ((pos != NULL) && (count < bucket_size))
1710 { 1724 {
1711 temp_distance = distance (&pos->id.hashPubKey, hc); 1725 temp_distance = distance (&pos->id.hashPubKey, hc);
1712 if (temp_distance <= lowest_distance) 1726 if (temp_distance <= lowest_distance)
1713 { 1727 {
1714 lowest_distance = temp_distance; 1728 lowest_distance = temp_distance;
1715 current_closest = pos; 1729 current_closest = pos;
1716 } 1730 }
1717 pos = pos->next; 1731 pos = pos->next;
1718 count++; 1732 count++;
1719 }
1720 } 1733 }
1734 }
1721 GNUNET_assert (current_closest != NULL); 1735 GNUNET_assert (current_closest != NULL);
1722 return current_closest; 1736 return current_closest;
1723} 1737}
@@ -1748,7 +1762,9 @@ forward_message (const struct GNUNET_MessageHeader *msg,
1748 && (peer == find_closest_peer (&msg_ctx->key))) 1762 && (peer == find_closest_peer (&msg_ctx->key)))
1749 increment_stats (STAT_ROUTE_FORWARDS_CLOSEST); 1763 increment_stats (STAT_ROUTE_FORWARDS_CLOSEST);
1750 1764
1751 msize = sizeof (struct GNUNET_DHT_P2PRouteMessage) + ntohs (msg->size) + (msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); 1765 msize =
1766 sizeof (struct GNUNET_DHT_P2PRouteMessage) + ntohs (msg->size) +
1767 (msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
1752 GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); 1768 GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
1753 psize = sizeof (struct P2PPendingMessage) + msize; 1769 psize = sizeof (struct P2PPendingMessage) + msize;
1754 pending = GNUNET_malloc (psize); 1770 pending = GNUNET_malloc (psize);
@@ -1771,16 +1787,18 @@ forward_message (const struct GNUNET_MessageHeader *msg,
1771 DHT_BLOOM_SIZE)); 1787 DHT_BLOOM_SIZE));
1772 memcpy (&route_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 1788 memcpy (&route_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
1773 memcpy (&route_message[1], msg, ntohs (msg->size)); 1789 memcpy (&route_message[1], msg, ntohs (msg->size));
1774 if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) 1790 if (GNUNET_DHT_RO_RECORD_ROUTE ==
1775 { 1791 (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
1776 route_message->outgoing_path_length = htonl(msg_ctx->path_history_len); 1792 {
1777 /* Set pointer to start of enc_msg */ 1793 route_message->outgoing_path_length = htonl (msg_ctx->path_history_len);
1778 route_path = (char *)&route_message[1]; 1794 /* Set pointer to start of enc_msg */
1779 /* Offset to the end of the enc_msg */ 1795 route_path = (char *) &route_message[1];
1780 route_path += ntohs (msg->size); 1796 /* Offset to the end of the enc_msg */
1781 /* Copy the route_path after enc_msg */ 1797 route_path += ntohs (msg->size);
1782 memcpy (route_path, msg_ctx->path_history, msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); 1798 /* Copy the route_path after enc_msg */
1783 } 1799 memcpy (route_path, msg_ctx->path_history,
1800 msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
1801 }
1784#if DEBUG_DHT > 1 1802#if DEBUG_DHT > 1
1785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1786 "%s:%s Adding pending message size %d for peer %s\n", 1804 "%s:%s Adding pending message size %d for peer %s\n",
@@ -1809,7 +1827,7 @@ periodic_ping_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1809 struct GNUNET_MessageHeader ping_message; 1827 struct GNUNET_MessageHeader ping_message;
1810 struct DHT_MessageContext msg_ctx; 1828 struct DHT_MessageContext msg_ctx;
1811 1829
1812 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 1830 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1813 return; 1831 return;
1814 1832
1815 ping_message.size = htons (sizeof (struct GNUNET_MessageHeader)); 1833 ping_message.size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -1823,8 +1841,8 @@ periodic_ping_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1823#endif 1841#endif
1824 forward_message (&ping_message, peer, &msg_ctx); 1842 forward_message (&ping_message, peer, &msg_ctx);
1825 peer->ping_task = 1843 peer->ping_task =
1826 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PING_DELAY, &periodic_ping_task, 1844 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PING_DELAY, &periodic_ping_task,
1827 peer); 1845 peer);
1828} 1846}
1829 1847
1830/** 1848/**
@@ -1837,25 +1855,25 @@ schedule_ping_messages ()
1837 unsigned int bucket; 1855 unsigned int bucket;
1838 unsigned int count; 1856 unsigned int count;
1839 struct PeerInfo *pos; 1857 struct PeerInfo *pos;
1858
1840 for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++) 1859 for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++)
1841 { 1860 {
1842 pos = k_buckets[bucket].head; 1861 pos = k_buckets[bucket].head;
1843 count = 0; 1862 count = 0;
1844 while (pos != NULL) 1863 while (pos != NULL)
1845 { 1864 {
1846 if ((count < bucket_size) 1865 if ((count < bucket_size) && (pos->ping_task == GNUNET_SCHEDULER_NO_TASK))
1847 && (pos->ping_task == GNUNET_SCHEDULER_NO_TASK)) 1866 GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos);
1848 GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos); 1867 else if ((count >= bucket_size)
1849 else if ((count >= bucket_size) 1868 && (pos->ping_task != GNUNET_SCHEDULER_NO_TASK))
1850 && (pos->ping_task != GNUNET_SCHEDULER_NO_TASK)) 1869 {
1851 { 1870 GNUNET_SCHEDULER_cancel (pos->ping_task);
1852 GNUNET_SCHEDULER_cancel (pos->ping_task); 1871 pos->ping_task = GNUNET_SCHEDULER_NO_TASK;
1853 pos->ping_task = GNUNET_SCHEDULER_NO_TASK; 1872 }
1854 } 1873 pos = pos->next;
1855 pos = pos->next; 1874 count++;
1856 count++;
1857 }
1858 } 1875 }
1876 }
1859} 1877}
1860#endif 1878#endif
1861 1879
@@ -1874,11 +1892,11 @@ process_pending_messages (struct ClientList *client)
1874 return; 1892 return;
1875 1893
1876 client->transmit_handle = 1894 client->transmit_handle =
1877 GNUNET_SERVER_notify_transmit_ready (client->client_handle, 1895 GNUNET_SERVER_notify_transmit_ready (client->client_handle,
1878 ntohs (client->pending_head-> 1896 ntohs (client->pending_head->
1879 msg->size), 1897 msg->size),
1880 GNUNET_TIME_UNIT_FOREVER_REL, 1898 GNUNET_TIME_UNIT_FOREVER_REL,
1881 &send_generic_reply, client); 1899 &send_generic_reply, client);
1882} 1900}
1883 1901
1884/** 1902/**
@@ -1904,20 +1922,20 @@ send_generic_reply (void *cls, size_t size, void *buf)
1904 1922
1905 client->transmit_handle = NULL; 1923 client->transmit_handle = NULL;
1906 if (buf == NULL) 1924 if (buf == NULL)
1907 { 1925 {
1908 /* client disconnected */ 1926 /* client disconnected */
1909 return 0; 1927 return 0;
1910 } 1928 }
1911 off = 0; 1929 off = 0;
1912 while ((NULL != (reply = client->pending_head)) && 1930 while ((NULL != (reply = client->pending_head)) &&
1913 (size >= off + (msize = ntohs (reply->msg->size)))) 1931 (size >= off + (msize = ntohs (reply->msg->size))))
1914 { 1932 {
1915 GNUNET_CONTAINER_DLL_remove (client->pending_head, 1933 GNUNET_CONTAINER_DLL_remove (client->pending_head,
1916 client->pending_tail, reply); 1934 client->pending_tail, reply);
1917 memcpy (&cbuf[off], reply->msg, msize); 1935 memcpy (&cbuf[off], reply->msg, msize);
1918 GNUNET_free (reply); 1936 GNUNET_free (reply);
1919 off += msize; 1937 off += msize;
1920 } 1938 }
1921 process_pending_messages (client); 1939 process_pending_messages (client);
1922#if DEBUG_DHT 1940#if DEBUG_DHT
1923 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1963,6 +1981,7 @@ send_reply_to_client (struct ClientList *client,
1963 uint16_t msize; 1981 uint16_t msize;
1964 size_t tsize; 1982 size_t tsize;
1965 char *reply_offset; 1983 char *reply_offset;
1984
1966#if DEBUG_PATH 1985#if DEBUG_PATH
1967 char *path_offset; 1986 char *path_offset;
1968 unsigned int i; 1987 unsigned int i;
@@ -1972,34 +1991,41 @@ send_reply_to_client (struct ClientList *client,
1972 "`%s:%s': Sending reply to client.\n", my_short_id, "DHT"); 1991 "`%s:%s': Sending reply to client.\n", my_short_id, "DHT");
1973#endif 1992#endif
1974 msize = ntohs (message->size); 1993 msize = ntohs (message->size);
1975 tsize = sizeof (struct GNUNET_DHT_RouteResultMessage) + msize + (msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); 1994 tsize =
1995 sizeof (struct GNUNET_DHT_RouteResultMessage) + msize +
1996 (msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
1976 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1997 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1977 { 1998 {
1978 GNUNET_break_op (0); 1999 GNUNET_break_op (0);
1979 return; 2000 return;
1980 } 2001 }
1981 pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + tsize); 2002 pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + tsize);
1982 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1]; 2003 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
1983 reply = (struct GNUNET_DHT_RouteResultMessage *) &pending_message[1]; 2004 reply = (struct GNUNET_DHT_RouteResultMessage *) &pending_message[1];
1984 reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT); 2005 reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT);
1985 reply->header.size = htons (tsize); 2006 reply->header.size = htons (tsize);
1986 reply->outgoing_path_length = htonl(msg_ctx->path_history_len); 2007 reply->outgoing_path_length = htonl (msg_ctx->path_history_len);
1987 reply->unique_id = GNUNET_htonll (msg_ctx->unique_id); 2008 reply->unique_id = GNUNET_htonll (msg_ctx->unique_id);
1988 memcpy (&reply->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 2009 memcpy (&reply->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
1989 reply_offset = (char *)&reply[1]; 2010 reply_offset = (char *) &reply[1];
1990 memcpy (&reply[1], message, msize); 2011 memcpy (&reply[1], message, msize);
1991 if (msg_ctx->path_history_len > 0) 2012 if (msg_ctx->path_history_len > 0)
1992 { 2013 {
1993 reply_offset += msize; 2014 reply_offset += msize;
1994 memcpy(reply_offset, msg_ctx->path_history, msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); 2015 memcpy (reply_offset, msg_ctx->path_history,
1995 } 2016 msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
2017 }
1996#if DEBUG_PATH 2018#if DEBUG_PATH
1997 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Returning message with outgoing path length %d\n", msg_ctx->path_history_len); 2019 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2020 "Returning message with outgoing path length %d\n",
2021 msg_ctx->path_history_len);
1998 for (i = 0; i < msg_ctx->path_history_len; i++) 2022 for (i = 0; i < msg_ctx->path_history_len; i++)
1999 { 2023 {
2000 path_offset = &msg_ctx->path_history[i * sizeof(struct GNUNET_PeerIdentity)]; 2024 path_offset =
2001 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found peer %d:%s\n", i, GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); 2025 &msg_ctx->path_history[i * sizeof (struct GNUNET_PeerIdentity)];
2002 } 2026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found peer %d:%s\n", i,
2027 GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
2028 }
2003#endif 2029#endif
2004 add_pending_message (client, pending_message); 2030 add_pending_message (client, pending_message);
2005} 2031}
@@ -2045,23 +2071,22 @@ consider_peer (struct GNUNET_PeerIdentity *peer)
2045 * @param tc context, reason, etc. 2071 * @param tc context, reason, etc.
2046 */ 2072 */
2047static void 2073static void
2048remove_forward_entry (void *cls, 2074remove_forward_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2049 const struct GNUNET_SCHEDULER_TaskContext *tc)
2050{ 2075{
2051 struct DHTRouteSource *source_info = cls; 2076 struct DHTRouteSource *source_info = cls;
2052 struct DHTQueryRecord *record; 2077 struct DHTQueryRecord *record;
2053 source_info = 2078
2054 GNUNET_CONTAINER_heap_remove_node (source_info->hnode); 2079 source_info = GNUNET_CONTAINER_heap_remove_node (source_info->hnode);
2055 record = source_info->record; 2080 record = source_info->record;
2056 GNUNET_CONTAINER_DLL_remove (record->head, record->tail, source_info); 2081 GNUNET_CONTAINER_DLL_remove (record->head, record->tail, source_info);
2057 2082
2058 if (record->head == NULL) /* No more entries in DLL */ 2083 if (record->head == NULL) /* No more entries in DLL */
2059 { 2084 {
2060 GNUNET_assert (GNUNET_YES == 2085 GNUNET_assert (GNUNET_YES ==
2061 GNUNET_CONTAINER_multihashmap_remove 2086 GNUNET_CONTAINER_multihashmap_remove
2062 (forward_list.hashmap, &record->key, record)); 2087 (forward_list.hashmap, &record->key, record));
2063 GNUNET_free (record); 2088 GNUNET_free (record);
2064 } 2089 }
2065 if (source_info->find_peers_responded != NULL) 2090 if (source_info->find_peers_responded != NULL)
2066 GNUNET_CONTAINER_bloomfilter_free (source_info->find_peers_responded); 2091 GNUNET_CONTAINER_bloomfilter_free (source_info->find_peers_responded);
2067 GNUNET_free (source_info); 2092 GNUNET_free (source_info);
@@ -2086,6 +2111,7 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2086 struct DHTRouteSource *pos; 2111 struct DHTRouteSource *pos;
2087 struct PeerInfo *peer_info; 2112 struct PeerInfo *peer_info;
2088 const struct GNUNET_MessageHeader *hello_msg; 2113 const struct GNUNET_MessageHeader *hello_msg;
2114
2089#if DEBUG_DHT > 1 2115#if DEBUG_DHT > 1
2090 unsigned int i; 2116 unsigned int i;
2091#endif 2117#endif
@@ -2096,188 +2122,186 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2096 * HELLO for another peer, offer it to the transport service. 2122 * HELLO for another peer, offer it to the transport service.
2097 */ 2123 */
2098 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT) 2124 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT)
2125 {
2126 if (ntohs (msg->size) <= sizeof (struct GNUNET_MessageHeader))
2127 GNUNET_break_op (0);
2128
2129 hello_msg = &msg[1];
2130 if ((ntohs (hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO)
2131 || (GNUNET_SYSERR ==
2132 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
2133 hello_msg, &new_peer)))
2099 { 2134 {
2100 if (ntohs (msg->size) <= sizeof (struct GNUNET_MessageHeader)) 2135 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2101 GNUNET_break_op (0); 2136 "%s:%s Received non-HELLO message type in find peer result message!\n",
2102 2137 my_short_id, "DHT");
2103 hello_msg = &msg[1]; 2138 GNUNET_break_op (0);
2104 if ((ntohs (hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO) 2139 return GNUNET_NO;
2105 || (GNUNET_SYSERR == 2140 }
2106 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 2141 else /* We have a valid hello, and peer id stored in new_peer */
2107 hello_msg, &new_peer))) 2142 {
2108 { 2143 find_peer_context.count++;
2109 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2144 increment_stats (STAT_FIND_PEER_REPLY);
2110 "%s:%s Received non-HELLO message type in find peer result message!\n", 2145 if (GNUNET_YES == consider_peer (&new_peer))
2111 my_short_id, "DHT"); 2146 {
2112 GNUNET_break_op (0); 2147 increment_stats (STAT_HELLOS_PROVIDED);
2113 return GNUNET_NO; 2148 GNUNET_TRANSPORT_offer_hello (transport_handle, hello_msg, NULL, NULL);
2114 } 2149 GNUNET_CORE_peer_request_connect (coreAPI, &new_peer, NULL, NULL);
2115 else /* We have a valid hello, and peer id stored in new_peer */ 2150 }
2116 {
2117 find_peer_context.count++;
2118 increment_stats (STAT_FIND_PEER_REPLY);
2119 if (GNUNET_YES == consider_peer (&new_peer))
2120 {
2121 increment_stats (STAT_HELLOS_PROVIDED);
2122 GNUNET_TRANSPORT_offer_hello (transport_handle, hello_msg, NULL, NULL);
2123 GNUNET_CORE_peer_request_connect (coreAPI,
2124 &new_peer, NULL, NULL);
2125 }
2126 }
2127 } 2151 }
2152 }
2128 2153
2129 if (malicious_dropper == GNUNET_YES) 2154 if (malicious_dropper == GNUNET_YES)
2130 record = NULL; 2155 record = NULL;
2131 else 2156 else
2132 record = 2157 record =
2133 GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, &msg_ctx->key); 2158 GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, &msg_ctx->key);
2134 2159
2135 if (record == NULL) /* No record of this message! */ 2160 if (record == NULL) /* No record of this message! */
2136 { 2161 {
2137#if DEBUG_DHT 2162#if DEBUG_DHT
2138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2139 "`%s:%s': Have no record of response key %s uid %llu\n", 2164 "`%s:%s': Have no record of response key %s uid %llu\n",
2140 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 2165 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
2141 msg_ctx->unique_id); 2166 msg_ctx->unique_id);
2142#endif 2167#endif
2143#if DEBUG_DHT_ROUTING 2168#if DEBUG_DHT_ROUTING
2144 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2169 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2145 { 2170 {
2146 dhtlog_handle->insert_route (NULL, 2171 dhtlog_handle->insert_route (NULL,
2147 msg_ctx->unique_id, 2172 msg_ctx->unique_id,
2148 DHTLOG_RESULT, 2173 DHTLOG_RESULT,
2149 msg_ctx->hop_count, 2174 msg_ctx->hop_count,
2150 GNUNET_SYSERR, 2175 GNUNET_SYSERR,
2151 &my_identity, 2176 &my_identity,
2152 &msg_ctx->key, msg_ctx->peer, NULL); 2177 &msg_ctx->key, msg_ctx->peer, NULL);
2153 } 2178 }
2154#endif 2179#endif
2155 if (msg_ctx->bloom != NULL) 2180 if (msg_ctx->bloom != NULL)
2156 { 2181 {
2157 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom); 2182 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
2158 msg_ctx->bloom = NULL; 2183 msg_ctx->bloom = NULL;
2159 }
2160 return 0;
2161 } 2184 }
2185 return 0;
2186 }
2162 2187
2163 pos = record->head; 2188 pos = record->head;
2164 while (pos != NULL) 2189 while (pos != NULL)
2165 { 2190 {
2166#if STRICT_FORWARDING 2191#if STRICT_FORWARDING
2167 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT) /* If we have already forwarded this peer id, don't do it again! */ 2192 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT) /* If we have already forwarded this peer id, don't do it again! */
2168 { 2193 {
2169 if (GNUNET_YES == 2194 if (GNUNET_YES ==
2170 GNUNET_CONTAINER_bloomfilter_test (pos->find_peers_responded, 2195 GNUNET_CONTAINER_bloomfilter_test (pos->find_peers_responded,
2171 &new_peer.hashPubKey)) 2196 &new_peer.hashPubKey))
2172 { 2197 {
2173 increment_stats 2198 increment_stats ("# find peer responses NOT forwarded (bloom match)");
2174 ("# find peer responses NOT forwarded (bloom match)"); 2199 pos = pos->next;
2175 pos = pos->next; 2200 continue;
2176 continue; 2201 }
2177 } 2202 else
2178 else 2203 GNUNET_CONTAINER_bloomfilter_add (pos->find_peers_responded,
2179 GNUNET_CONTAINER_bloomfilter_add (pos->find_peers_responded, 2204 &new_peer.hashPubKey);
2180 &new_peer.hashPubKey); 2205 }
2181 }
2182#endif 2206#endif
2183 2207
2184 if (0 == memcmp (&pos->source, &my_identity, sizeof (struct GNUNET_PeerIdentity))) /* Local client (or DHT) initiated request! */ 2208 if (0 == memcmp (&pos->source, &my_identity, sizeof (struct GNUNET_PeerIdentity))) /* Local client (or DHT) initiated request! */
2185 { 2209 {
2186#if DEBUG_DHT 2210#if DEBUG_DHT
2187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2188 "`%s:%s': Sending response key %s uid %llu to client\n", 2212 "`%s:%s': Sending response key %s uid %llu to client\n",
2189 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 2213 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
2190 msg_ctx->unique_id); 2214 msg_ctx->unique_id);
2191#endif 2215#endif
2192#if DEBUG_DHT_ROUTING 2216#if DEBUG_DHT_ROUTING
2193 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2217 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2194 { 2218 {
2195 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 2219 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
2196 DHTLOG_RESULT, msg_ctx->hop_count, 2220 DHTLOG_RESULT, msg_ctx->hop_count,
2197 GNUNET_YES, &my_identity, 2221 GNUNET_YES, &my_identity,
2198 &msg_ctx->key, msg_ctx->peer, 2222 &msg_ctx->key, msg_ctx->peer, NULL);
2199 NULL); 2223 }
2200 }
2201#endif 2224#endif
2202 increment_stats (STAT_RESULTS_TO_CLIENT); 2225 increment_stats (STAT_RESULTS_TO_CLIENT);
2203 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) 2226 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT)
2204 increment_stats (STAT_GET_REPLY); 2227 increment_stats (STAT_GET_REPLY);
2205#if DEBUG_DHT > 1 2228#if DEBUG_DHT > 1
2206 for (i = 0; i < msg_ctx->path_history_len; i++) 2229 for (i = 0; i < msg_ctx->path_history_len; i++)
2207 { 2230 {
2208 char *path_offset; 2231 char *path_offset;
2209 2232
2210 path_offset = &msg_ctx->path_history[i * sizeof(struct GNUNET_PeerIdentity)]; 2233 path_offset =
2211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2234 &msg_ctx->path_history[i * sizeof (struct GNUNET_PeerIdentity)];
2212 "(before client) Key %s Found peer %d:%s\n", 2235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2213 GNUNET_h2s(&msg_ctx->key), i, 2236 "(before client) Key %s Found peer %d:%s\n",
2214 GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); 2237 GNUNET_h2s (&msg_ctx->key), i,
2215 } 2238 GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
2239 }
2216#endif 2240#endif
2217 send_reply_to_client (pos->client, msg, msg_ctx); 2241 send_reply_to_client (pos->client, msg, msg_ctx);
2218 } 2242 }
2219 else /* Send to peer */ 2243 else /* Send to peer */
2220 { 2244 {
2221 peer_info = find_peer_by_id (&pos->source); 2245 peer_info = find_peer_by_id (&pos->source);
2222 if (peer_info == NULL) /* Didn't find the peer in our routing table, perhaps peer disconnected! */ 2246 if (peer_info == NULL) /* Didn't find the peer in our routing table, perhaps peer disconnected! */
2223 { 2247 {
2224 pos = pos->next; 2248 pos = pos->next;
2225 continue; 2249 continue;
2226 } 2250 }
2227 2251
2228 if (msg_ctx->bloom == NULL) 2252 if (msg_ctx->bloom == NULL)
2229 msg_ctx->bloom = 2253 msg_ctx->bloom =
2230 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, 2254 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
2231 DHT_BLOOM_K); 2255 DHT_BLOOM_K);
2232 GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom, 2256 GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom,
2233 &my_identity.hashPubKey); 2257 &my_identity.hashPubKey);
2234 if ((GNUNET_NO == 2258 if ((GNUNET_NO ==
2235 GNUNET_CONTAINER_bloomfilter_test (msg_ctx->bloom, 2259 GNUNET_CONTAINER_bloomfilter_test (msg_ctx->bloom,
2236 &peer_info->id.hashPubKey))) 2260 &peer_info->id.hashPubKey)))
2237 { 2261 {
2238#if DEBUG_DHT 2262#if DEBUG_DHT
2239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2240 "`%s:%s': Forwarding response key %s uid %llu to peer %s\n", 2264 "`%s:%s': Forwarding response key %s uid %llu to peer %s\n",
2241 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 2265 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
2242 msg_ctx->unique_id, GNUNET_i2s (&peer_info->id)); 2266 msg_ctx->unique_id, GNUNET_i2s (&peer_info->id));
2243#endif 2267#endif
2244#if DEBUG_DHT_ROUTING 2268#if DEBUG_DHT_ROUTING
2245 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2269 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2246 { 2270 {
2247 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 2271 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
2248 DHTLOG_RESULT, 2272 DHTLOG_RESULT,
2249 msg_ctx->hop_count, 2273 msg_ctx->hop_count,
2250 GNUNET_NO, &my_identity, 2274 GNUNET_NO, &my_identity,
2251 &msg_ctx->key, msg_ctx->peer, 2275 &msg_ctx->key, msg_ctx->peer,
2252 &pos->source); 2276 &pos->source);
2253 } 2277 }
2254#endif 2278#endif
2255 forward_result_message (msg, peer_info, msg_ctx); 2279 forward_result_message (msg, peer_info, msg_ctx);
2256 /* Try removing forward entries after sending once, only allows ONE response per request */ 2280 /* Try removing forward entries after sending once, only allows ONE response per request */
2257 if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK) 2281 if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
2258 { 2282 {
2259 GNUNET_SCHEDULER_cancel (pos->delete_task); 2283 GNUNET_SCHEDULER_cancel (pos->delete_task);
2260 pos->delete_task = 2284 pos->delete_task =
2261 GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos); 2285 GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos);
2262 } 2286 }
2263 } 2287 }
2264 else 2288 else
2265 { 2289 {
2266#if DEBUG_DHT 2290#if DEBUG_DHT
2267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2268 "`%s:%s': NOT Forwarding response (bloom match) key %s uid %llu to peer %s\n", 2292 "`%s:%s': NOT Forwarding response (bloom match) key %s uid %llu to peer %s\n",
2269 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 2293 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
2270 msg_ctx->unique_id, GNUNET_i2s (&peer_info->id)); 2294 msg_ctx->unique_id, GNUNET_i2s (&peer_info->id));
2271#endif 2295#endif
2272 } 2296 }
2273 }
2274 pos = pos->next;
2275 } 2297 }
2298 pos = pos->next;
2299 }
2276 if (msg_ctx->bloom != NULL) 2300 if (msg_ctx->bloom != NULL)
2277 { 2301 {
2278 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom); 2302 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
2279 msg_ctx->bloom = NULL; 2303 msg_ctx->bloom = NULL;
2280 } 2304 }
2281 return 0; 2305 return 0;
2282} 2306}
2283 2307
@@ -2309,6 +2333,7 @@ datacache_get_iterator (void *cls,
2309 const struct DHTPutEntry *put_entry; 2333 const struct DHTPutEntry *put_entry;
2310 int get_size; 2334 int get_size;
2311 char *path_offset; 2335 char *path_offset;
2336
2312#if DEBUG_PATH 2337#if DEBUG_PATH
2313 unsigned int i; 2338 unsigned int i;
2314#endif 2339#endif
@@ -2319,114 +2344,129 @@ datacache_get_iterator (void *cls,
2319 "DHT", "GET"); 2344 "DHT", "GET");
2320#endif 2345#endif
2321 2346
2322 put_entry = (const struct DHTPutEntry *)data; 2347 put_entry = (const struct DHTPutEntry *) data;
2323
2324 if (size != sizeof(struct DHTPutEntry) +
2325 put_entry->data_size +
2326 (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity)))
2327 {
2328 GNUNET_log(
2329 GNUNET_ERROR_TYPE_WARNING,
2330 "Path + data size doesn't add up for data inserted into datacache!\nData size %d, path length %d, expected %d, got %d\n",
2331 put_entry->data_size, put_entry->path_length,
2332 sizeof(struct DHTPutEntry) + put_entry->data_size
2333 + (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity)),
2334 size);
2335 msg_ctx->do_forward = GNUNET_NO;
2336 return GNUNET_OK;
2337 }
2338 2348
2339 eval = GNUNET_BLOCK_evaluate (block_context, 2349 if (size != sizeof (struct DHTPutEntry) +
2340 type, 2350 put_entry->data_size +
2341 key, 2351 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)))
2342 &msg_ctx->reply_bf, 2352 {
2343 msg_ctx->reply_bf_mutator, 2353 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2344 msg_ctx->xquery, 2354 "Path + data size doesn't add up for data inserted into datacache!\nData size %d, path length %d, expected %d, got %d\n",
2345 msg_ctx->xquery_size, &put_entry[1], put_entry->data_size); 2355 put_entry->data_size, put_entry->path_length,
2356 sizeof (struct DHTPutEntry) + put_entry->data_size
2357 +
2358 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)),
2359 size);
2360 msg_ctx->do_forward = GNUNET_NO;
2361 return GNUNET_OK;
2362 }
2363
2364 eval = GNUNET_BLOCK_evaluate (block_context,
2365 type,
2366 key,
2367 &msg_ctx->reply_bf,
2368 msg_ctx->reply_bf_mutator,
2369 msg_ctx->xquery,
2370 msg_ctx->xquery_size, &put_entry[1],
2371 put_entry->data_size);
2346 2372
2347 switch (eval) 2373 switch (eval)
2374 {
2375 case GNUNET_BLOCK_EVALUATION_OK_LAST:
2376 msg_ctx->do_forward = GNUNET_NO;
2377 case GNUNET_BLOCK_EVALUATION_OK_MORE:
2378 new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext));
2379 memcpy (new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext));
2380 if (GNUNET_DHT_RO_RECORD_ROUTE ==
2381 (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
2348 { 2382 {
2349 case GNUNET_BLOCK_EVALUATION_OK_LAST: 2383 new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE;
2350 msg_ctx->do_forward = GNUNET_NO; 2384 new_msg_ctx->path_history_len = msg_ctx->path_history_len;
2351 case GNUNET_BLOCK_EVALUATION_OK_MORE: 2385 /* Assign to previous msg_ctx path history, caller should free after our return */
2352 new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext)); 2386 new_msg_ctx->path_history = msg_ctx->path_history;
2353 memcpy (new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext));
2354 if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
2355 {
2356 new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE;
2357 new_msg_ctx->path_history_len = msg_ctx->path_history_len;
2358 /* Assign to previous msg_ctx path history, caller should free after our return */
2359 new_msg_ctx->path_history = msg_ctx->path_history;
2360#if DEBUG_PATH 2387#if DEBUG_PATH
2361 for (i = 0; i < new_msg_ctx->path_history_len; i++) 2388 for (i = 0; i < new_msg_ctx->path_history_len; i++)
2362 { 2389 {
2363 path_offset = &new_msg_ctx->path_history[i * sizeof(struct GNUNET_PeerIdentity)]; 2390 path_offset =
2364 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(get_iterator) Key %s Found peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); 2391 &new_msg_ctx->path_history[i * sizeof (struct GNUNET_PeerIdentity)];
2365 } 2392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2393 "(get_iterator) Key %s Found peer %d:%s\n",
2394 GNUNET_h2s (&msg_ctx->key), i,
2395 GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
2396 }
2366#endif 2397#endif
2367 } 2398 }
2368 2399
2369 get_size = sizeof (struct GNUNET_DHT_GetResultMessage) + put_entry->data_size + (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity)); 2400 get_size =
2370 get_result = GNUNET_malloc (get_size); 2401 sizeof (struct GNUNET_DHT_GetResultMessage) + put_entry->data_size +
2371 get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT); 2402 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity));
2372 get_result->header.size = htons (get_size); 2403 get_result = GNUNET_malloc (get_size);
2373 get_result->expiration = GNUNET_TIME_absolute_hton (exp); 2404 get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT);
2374 get_result->type = htons (type); 2405 get_result->header.size = htons (get_size);
2375 get_result->put_path_length = htons(put_entry->path_length); 2406 get_result->expiration = GNUNET_TIME_absolute_hton (exp);
2376 path_offset = (char *)&put_entry[1]; 2407 get_result->type = htons (type);
2377 path_offset += put_entry->data_size; 2408 get_result->put_path_length = htons (put_entry->path_length);
2409 path_offset = (char *) &put_entry[1];
2410 path_offset += put_entry->data_size;
2378#if DEBUG_PATH 2411#if DEBUG_PATH
2379 for (i = 0; i < put_entry->path_length; i++) 2412 for (i = 0; i < put_entry->path_length; i++)
2380 { 2413 {
2381 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(get_iterator PUT path) Key %s Found peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct GNUNET_PeerIdentity *)&path_offset[i * sizeof(struct GNUNET_PeerIdentity)])); 2414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2382 } 2415 "(get_iterator PUT path) Key %s Found peer %d:%s\n",
2416 GNUNET_h2s (&msg_ctx->key), i,
2417 GNUNET_i2s ((struct GNUNET_PeerIdentity *)
2418 &path_offset[i *
2419 sizeof (struct
2420 GNUNET_PeerIdentity)]));
2421 }
2383#endif 2422#endif
2384 /* Copy the actual data and the path_history to the end of the get result */ 2423 /* Copy the actual data and the path_history to the end of the get result */
2385 memcpy (&get_result[1], &put_entry[1], put_entry->data_size + (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity))); 2424 memcpy (&get_result[1], &put_entry[1],
2386 new_msg_ctx->peer = &my_identity; 2425 put_entry->data_size +
2387 new_msg_ctx->bloom = 2426 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)));
2427 new_msg_ctx->peer = &my_identity;
2428 new_msg_ctx->bloom =
2388 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 2429 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
2389 new_msg_ctx->hop_count = 0; 2430 new_msg_ctx->hop_count = 0;
2390 new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result routing a higher priority */ 2431 new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result routing a higher priority */
2391 new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; 2432 new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
2392 increment_stats (STAT_GET_RESPONSE_START); 2433 increment_stats (STAT_GET_RESPONSE_START);
2393 route_result_message (&get_result->header, new_msg_ctx); 2434 route_result_message (&get_result->header, new_msg_ctx);
2394 GNUNET_free (new_msg_ctx); 2435 GNUNET_free (new_msg_ctx);
2395 GNUNET_free (get_result); 2436 GNUNET_free (get_result);
2396 break; 2437 break;
2397 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 2438 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
2398#if DEBUG_DHT 2439#if DEBUG_DHT
2399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2400 "`%s:%s': Duplicate block error\n", my_short_id, "DHT"); 2441 "`%s:%s': Duplicate block error\n", my_short_id, "DHT");
2401#endif 2442#endif
2402 break; 2443 break;
2403 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 2444 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
2404#if DEBUG_DHT 2445#if DEBUG_DHT
2405 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2446 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2406 "`%s:%s': Invalid request error\n", my_short_id, "DHT"); 2447 "`%s:%s': Invalid request error\n", my_short_id, "DHT");
2407#endif 2448#endif
2408 break; 2449 break;
2409 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 2450 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
2410#if DEBUG_DHT 2451#if DEBUG_DHT
2411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2412 "`%s:%s': Valid request, no results.\n", my_short_id, 2453 "`%s:%s': Valid request, no results.\n", my_short_id, "DHT");
2413 "DHT");
2414#endif 2454#endif
2415 GNUNET_break (0); 2455 GNUNET_break (0);
2416 break; 2456 break;
2417 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: 2457 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
2418 GNUNET_break_op (0); 2458 GNUNET_break_op (0);
2419 msg_ctx->do_forward = GNUNET_NO; 2459 msg_ctx->do_forward = GNUNET_NO;
2420 break; 2460 break;
2421 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 2461 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
2422#if DEBUG_DHT 2462#if DEBUG_DHT
2423 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2463 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2424 "`%s:%s': Unsupported block type (%u) in response!\n", 2464 "`%s:%s': Unsupported block type (%u) in response!\n",
2425 my_short_id, "DHT", type); 2465 my_short_id, "DHT", type);
2426#endif 2466#endif
2427 /* msg_ctx->do_forward = GNUNET_NO; // not sure... */ 2467 /* msg_ctx->do_forward = GNUNET_NO; // not sure... */
2428 break; 2468 break;
2429 } 2469 }
2430 return GNUNET_OK; 2470 return GNUNET_OK;
2431} 2471}
2432 2472
@@ -2465,40 +2505,40 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2465 2505
2466 msize = ntohs (msg->size); 2506 msize = ntohs (msg->size);
2467 if (msize < sizeof (struct GNUNET_DHT_GetMessage)) 2507 if (msize < sizeof (struct GNUNET_DHT_GetMessage))
2468 { 2508 {
2469 GNUNET_break (0); 2509 GNUNET_break (0);
2470 return 0; 2510 return 0;
2471 } 2511 }
2472 get_msg = (const struct GNUNET_DHT_GetMessage *) msg; 2512 get_msg = (const struct GNUNET_DHT_GetMessage *) msg;
2473 bf_size = ntohs (get_msg->bf_size); 2513 bf_size = ntohs (get_msg->bf_size);
2474 msg_ctx->xquery_size = ntohs (get_msg->xquery_size); 2514 msg_ctx->xquery_size = ntohs (get_msg->xquery_size);
2475 msg_ctx->reply_bf_mutator = get_msg->bf_mutator; /* FIXME: ntohl? */ 2515 msg_ctx->reply_bf_mutator = get_msg->bf_mutator; /* FIXME: ntohl? */
2476 if (msize != 2516 if (msize !=
2477 sizeof (struct GNUNET_DHT_GetMessage) + bf_size + msg_ctx->xquery_size) 2517 sizeof (struct GNUNET_DHT_GetMessage) + bf_size + msg_ctx->xquery_size)
2478 { 2518 {
2479 GNUNET_break (0); 2519 GNUNET_break (0);
2480 return 0; 2520 return 0;
2481 } 2521 }
2482 end = (const char *) &get_msg[1]; 2522 end = (const char *) &get_msg[1];
2483 if (msg_ctx->xquery_size == 0) 2523 if (msg_ctx->xquery_size == 0)
2484 { 2524 {
2485 msg_ctx->xquery = NULL; 2525 msg_ctx->xquery = NULL;
2486 } 2526 }
2487 else 2527 else
2488 { 2528 {
2489 msg_ctx->xquery = (const void *) end; 2529 msg_ctx->xquery = (const void *) end;
2490 end += msg_ctx->xquery_size; 2530 end += msg_ctx->xquery_size;
2491 } 2531 }
2492 if (bf_size == 0) 2532 if (bf_size == 0)
2493 { 2533 {
2494 msg_ctx->reply_bf = NULL; 2534 msg_ctx->reply_bf = NULL;
2495 } 2535 }
2496 else 2536 else
2497 { 2537 {
2498 msg_ctx->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end, 2538 msg_ctx->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end,
2499 bf_size, 2539 bf_size,
2500 GNUNET_DHT_GET_BLOOMFILTER_K); 2540 GNUNET_DHT_GET_BLOOMFILTER_K);
2501 } 2541 }
2502 type = (enum GNUNET_BLOCK_Type) ntohl (get_msg->type); 2542 type = (enum GNUNET_BLOCK_Type) ntohl (get_msg->type);
2503#if DEBUG_DHT 2543#if DEBUG_DHT
2504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2511,69 +2551,69 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2511 results = 0; 2551 results = 0;
2512#if HAVE_MALICIOUS 2552#if HAVE_MALICIOUS
2513 if (type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE) 2553 if (type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE)
2514 { 2554 {
2515 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf); 2555 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf);
2516 return results; 2556 return results;
2517 } 2557 }
2518#endif 2558#endif
2519 msg_ctx->do_forward = GNUNET_YES; 2559 msg_ctx->do_forward = GNUNET_YES;
2520 if (datacache != NULL) 2560 if (datacache != NULL)
2521 results 2561 results
2522 = GNUNET_DATACACHE_get (datacache, 2562 = GNUNET_DATACACHE_get (datacache,
2523 &msg_ctx->key, type, 2563 &msg_ctx->key, type,
2524 &datacache_get_iterator, msg_ctx); 2564 &datacache_get_iterator, msg_ctx);
2525#if DEBUG_DHT 2565#if DEBUG_DHT
2526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2527 "`%s:%s': Found %d results for `%s' request uid %llu\n", 2567 "`%s:%s': Found %d results for `%s' request uid %llu\n",
2528 my_short_id, "DHT", results, "GET", msg_ctx->unique_id); 2568 my_short_id, "DHT", results, "GET", msg_ctx->unique_id);
2529#endif 2569#endif
2530 if (results >= 1) 2570 if (results >= 1)
2531 { 2571 {
2532#if DEBUG_DHT_ROUTING 2572#if DEBUG_DHT_ROUTING
2533 if ((debug_routes) && (dhtlog_handle != NULL)) 2573 if ((debug_routes) && (dhtlog_handle != NULL))
2534 { 2574 {
2535 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET, 2575 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
2536 msg_ctx->hop_count, GNUNET_YES, 2576 msg_ctx->hop_count, GNUNET_YES,
2537 &my_identity, &msg_ctx->key); 2577 &my_identity, &msg_ctx->key);
2538 } 2578 }
2539 2579
2540 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2580 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2541 { 2581 {
2542 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2582 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2543 msg_ctx->hop_count, GNUNET_YES, 2583 msg_ctx->hop_count, GNUNET_YES,
2544 &my_identity, &msg_ctx->key, 2584 &my_identity, &msg_ctx->key,
2545 msg_ctx->peer, NULL); 2585 msg_ctx->peer, NULL);
2546 }
2547#endif
2548 } 2586 }
2587#endif
2588 }
2549 else 2589 else
2590 {
2591 /* check query valid */
2592 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID
2593 == GNUNET_BLOCK_evaluate (block_context,
2594 type,
2595 &msg_ctx->key,
2596 &msg_ctx->reply_bf,
2597 msg_ctx->reply_bf_mutator,
2598 msg_ctx->xquery,
2599 msg_ctx->xquery_size, NULL, 0))
2550 { 2600 {
2551 /* check query valid */ 2601 GNUNET_break_op (0);
2552 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID 2602 msg_ctx->do_forward = GNUNET_NO;
2553 == GNUNET_BLOCK_evaluate (block_context,
2554 type,
2555 &msg_ctx->key,
2556 &msg_ctx->reply_bf,
2557 msg_ctx->reply_bf_mutator,
2558 msg_ctx->xquery,
2559 msg_ctx->xquery_size, NULL, 0))
2560 {
2561 GNUNET_break_op (0);
2562 msg_ctx->do_forward = GNUNET_NO;
2563 }
2564 } 2603 }
2604 }
2565 2605
2566 if (msg_ctx->hop_count == 0) /* Locally initiated request */ 2606 if (msg_ctx->hop_count == 0) /* Locally initiated request */
2567 { 2607 {
2568#if DEBUG_DHT_ROUTING 2608#if DEBUG_DHT_ROUTING
2569 if ((debug_routes) && (dhtlog_handle != NULL)) 2609 if ((debug_routes) && (dhtlog_handle != NULL))
2570 { 2610 {
2571 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET, 2611 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
2572 msg_ctx->hop_count, GNUNET_NO, 2612 msg_ctx->hop_count, GNUNET_NO,
2573 &my_identity, &msg_ctx->key); 2613 &my_identity, &msg_ctx->key);
2574 }
2575#endif
2576 } 2614 }
2615#endif
2616 }
2577 if (msg_ctx->do_forward == GNUNET_YES) 2617 if (msg_ctx->do_forward == GNUNET_YES)
2578 route_message (msg, msg_ctx); 2618 route_message (msg, msg_ctx);
2579 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf); 2619 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf);
@@ -2622,41 +2662,40 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2622 other_hello = NULL; 2662 other_hello = NULL;
2623 other_hello_size = 0; 2663 other_hello_size = 0;
2624 if (ntohs (find_msg->size) > sizeof (struct GNUNET_DHT_FindPeerMessage)) 2664 if (ntohs (find_msg->size) > sizeof (struct GNUNET_DHT_FindPeerMessage))
2625 { 2665 {
2626 other_hello_size = 2666 other_hello_size =
2627 ntohs (find_msg->size) - sizeof (struct GNUNET_DHT_FindPeerMessage); 2667 ntohs (find_msg->size) - sizeof (struct GNUNET_DHT_FindPeerMessage);
2628 other_hello = GNUNET_malloc (other_hello_size); 2668 other_hello = GNUNET_malloc (other_hello_size);
2629 memcpy (other_hello, &find_peer_message[1], other_hello_size); 2669 memcpy (other_hello, &find_peer_message[1], other_hello_size);
2630 if ((GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) other_hello) == 2670 if ((GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) other_hello) ==
2631 0) 2671 0)
2632 || (GNUNET_OK != 2672 || (GNUNET_OK !=
2633 GNUNET_HELLO_get_id ((struct GNUNET_HELLO_Message *) 2673 GNUNET_HELLO_get_id ((struct GNUNET_HELLO_Message *)
2634 other_hello, &peer_id))) 2674 other_hello, &peer_id)))
2635 { 2675 {
2636 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2676 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2637 "Received invalid HELLO message in find peer request!\n"); 2677 "Received invalid HELLO message in find peer request!\n");
2638 GNUNET_free (other_hello); 2678 GNUNET_free (other_hello);
2639 return; 2679 return;
2640 } 2680 }
2641#if FIND_PEER_WITH_HELLO 2681#if FIND_PEER_WITH_HELLO
2642 if (GNUNET_YES == consider_peer (&peer_id)) 2682 if (GNUNET_YES == consider_peer (&peer_id))
2643 { 2683 {
2644 increment_stats (STAT_HELLOS_PROVIDED); 2684 increment_stats (STAT_HELLOS_PROVIDED);
2645 GNUNET_TRANSPORT_offer_hello (transport_handle, other_hello, NULL, NULL); 2685 GNUNET_TRANSPORT_offer_hello (transport_handle, other_hello, NULL, NULL);
2646 GNUNET_CORE_peer_request_connect (coreAPI, 2686 GNUNET_CORE_peer_request_connect (coreAPI, &peer_id, NULL, NULL);
2647 &peer_id, NULL, NULL); 2687 route_message (find_msg, msg_ctx);
2648 route_message (find_msg, msg_ctx); 2688 GNUNET_free (other_hello);
2649 GNUNET_free (other_hello); 2689 return;
2650 return; 2690 }
2651 } 2691 else /* We don't want this peer! */
2652 else /* We don't want this peer! */ 2692 {
2653 { 2693 route_message (find_msg, msg_ctx);
2654 route_message (find_msg, msg_ctx); 2694 GNUNET_free (other_hello);
2655 GNUNET_free (other_hello); 2695 return;
2656 return;
2657 }
2658#endif
2659 } 2696 }
2697#endif
2698 }
2660 2699
2661#if DEBUG_DHT 2700#if DEBUG_DHT
2662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2665,29 +2704,29 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2665 ntohs (find_msg->size), sizeof (struct GNUNET_MessageHeader)); 2704 ntohs (find_msg->size), sizeof (struct GNUNET_MessageHeader));
2666#endif 2705#endif
2667 if (my_hello == NULL) 2706 if (my_hello == NULL)
2668 { 2707 {
2669#if DEBUG_DHT 2708#if DEBUG_DHT
2670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2671 "`%s': Our HELLO is null, can't return.\n", "DHT"); 2710 "`%s': Our HELLO is null, can't return.\n", "DHT");
2672#endif 2711#endif
2673 GNUNET_free_non_null (other_hello); 2712 GNUNET_free_non_null (other_hello);
2674 route_message (find_msg, msg_ctx); 2713 route_message (find_msg, msg_ctx);
2675 return; 2714 return;
2676 } 2715 }
2677 2716
2678 incoming_bloom = 2717 incoming_bloom =
2679 GNUNET_CONTAINER_bloomfilter_init (find_peer_message->bloomfilter, 2718 GNUNET_CONTAINER_bloomfilter_init (find_peer_message->bloomfilter,
2680 DHT_BLOOM_SIZE, DHT_BLOOM_K); 2719 DHT_BLOOM_SIZE, DHT_BLOOM_K);
2681 if (GNUNET_YES == 2720 if (GNUNET_YES ==
2682 GNUNET_CONTAINER_bloomfilter_test (incoming_bloom, 2721 GNUNET_CONTAINER_bloomfilter_test (incoming_bloom,
2683 &my_identity.hashPubKey)) 2722 &my_identity.hashPubKey))
2684 { 2723 {
2685 increment_stats (STAT_BLOOM_FIND_PEER); 2724 increment_stats (STAT_BLOOM_FIND_PEER);
2686 GNUNET_CONTAINER_bloomfilter_free (incoming_bloom); 2725 GNUNET_CONTAINER_bloomfilter_free (incoming_bloom);
2687 GNUNET_free_non_null (other_hello); 2726 GNUNET_free_non_null (other_hello);
2688 route_message (find_msg, msg_ctx); 2727 route_message (find_msg, msg_ctx);
2689 return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!) */ 2728 return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!) */
2690 } 2729 }
2691 GNUNET_CONTAINER_bloomfilter_free (incoming_bloom); 2730 GNUNET_CONTAINER_bloomfilter_free (incoming_bloom);
2692 2731
2693#if RESTRICT_FIND_PEER 2732#if RESTRICT_FIND_PEER
@@ -2696,11 +2735,11 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2696 * Ignore any find peer requests from a peer we have seen very recently. 2735 * Ignore any find peer requests from a peer we have seen very recently.
2697 */ 2736 */
2698 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (recent_find_peer_requests, &msg_ctx->key)) /* We have recently responded to a find peer request for this peer! */ 2737 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (recent_find_peer_requests, &msg_ctx->key)) /* We have recently responded to a find peer request for this peer! */
2699 { 2738 {
2700 increment_stats ("# dht find peer requests ignored (recently seen!)"); 2739 increment_stats ("# dht find peer requests ignored (recently seen!)");
2701 GNUNET_free_non_null (other_hello); 2740 GNUNET_free_non_null (other_hello);
2702 return; 2741 return;
2703 } 2742 }
2704 2743
2705 /** 2744 /**
2706 * Use this check to only allow the peer to respond to find peer requests if 2745 * Use this check to only allow the peer to respond to find peer requests if
@@ -2712,12 +2751,12 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2712 */ 2751 */
2713 memcpy (&peer_id.hashPubKey, &msg_ctx->key, sizeof (GNUNET_HashCode)); 2752 memcpy (&peer_id.hashPubKey, &msg_ctx->key, sizeof (GNUNET_HashCode));
2714 if (GNUNET_NO == consider_peer (&peer_id)) 2753 if (GNUNET_NO == consider_peer (&peer_id))
2715 { 2754 {
2716 increment_stats ("# dht find peer requests ignored (do not need!)"); 2755 increment_stats ("# dht find peer requests ignored (do not need!)");
2717 GNUNET_free_non_null (other_hello); 2756 GNUNET_free_non_null (other_hello);
2718 route_message (find_msg, msg_ctx); 2757 route_message (find_msg, msg_ctx);
2719 return; 2758 return;
2720 } 2759 }
2721#endif 2760#endif
2722 2761
2723 recent_hash = GNUNET_malloc (sizeof (GNUNET_HashCode)); 2762 recent_hash = GNUNET_malloc (sizeof (GNUNET_HashCode));
@@ -2726,36 +2765,36 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2726 GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, 2765 GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests,
2727 &msg_ctx->key, NULL, 2766 &msg_ctx->key, NULL,
2728 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 2767 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
2729 { 2768 {
2730#if DEBUG_DHT 2769#if DEBUG_DHT
2731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2732 "Adding recent remove task for key `%s`!\n", 2771 "Adding recent remove task for key `%s`!\n",
2733 GNUNET_h2s (&msg_ctx->key)); 2772 GNUNET_h2s (&msg_ctx->key));
2734#endif 2773#endif
2735 /* Only add a task if there wasn't one for this key already! */ 2774 /* Only add a task if there wasn't one for this key already! */
2736 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 2775 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2737 (GNUNET_TIME_UNIT_SECONDS, 30), 2776 (GNUNET_TIME_UNIT_SECONDS, 30),
2738 &remove_recent_find_peer, recent_hash); 2777 &remove_recent_find_peer, recent_hash);
2739 } 2778 }
2740 else 2779 else
2741 { 2780 {
2742 GNUNET_free (recent_hash); 2781 GNUNET_free (recent_hash);
2743#if DEBUG_DHT 2782#if DEBUG_DHT
2744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2745 "Received duplicate find peer request too soon!\n"); 2784 "Received duplicate find peer request too soon!\n");
2746#endif 2785#endif
2747 } 2786 }
2748 2787
2749 /* Simplistic find_peer functionality, always return our hello */ 2788 /* Simplistic find_peer functionality, always return our hello */
2750 hello_size = ntohs (my_hello->size); 2789 hello_size = ntohs (my_hello->size);
2751 tsize = hello_size + sizeof (struct GNUNET_MessageHeader); 2790 tsize = hello_size + sizeof (struct GNUNET_MessageHeader);
2752 2791
2753 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 2792 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
2754 { 2793 {
2755 GNUNET_break_op (0); 2794 GNUNET_break_op (0);
2756 GNUNET_free_non_null (other_hello); 2795 GNUNET_free_non_null (other_hello);
2757 return; 2796 return;
2758 } 2797 }
2759 2798
2760 find_peer_result = GNUNET_malloc (tsize); 2799 find_peer_result = GNUNET_malloc (tsize);
2761 find_peer_result->type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT); 2800 find_peer_result->type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT);
@@ -2771,27 +2810,28 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2771 memcpy (new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext)); 2810 memcpy (new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext));
2772 new_msg_ctx->peer = &my_identity; 2811 new_msg_ctx->peer = &my_identity;
2773 new_msg_ctx->bloom = 2812 new_msg_ctx->bloom =
2774 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 2813 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
2775 new_msg_ctx->hop_count = 0; 2814 new_msg_ctx->hop_count = 0;
2776 new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make find peer requests a higher priority */ 2815 new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make find peer requests a higher priority */
2777 new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; 2816 new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
2778 increment_stats (STAT_FIND_PEER_ANSWER); 2817 increment_stats (STAT_FIND_PEER_ANSWER);
2779 if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) 2818 if (GNUNET_DHT_RO_RECORD_ROUTE ==
2780 { 2819 (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
2781 new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE; 2820 {
2782 new_msg_ctx->path_history_len = msg_ctx->path_history_len; 2821 new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE;
2783 /* Assign to previous msg_ctx path history, caller should free after our return */ 2822 new_msg_ctx->path_history_len = msg_ctx->path_history_len;
2784 new_msg_ctx->path_history = msg_ctx->path_history; 2823 /* Assign to previous msg_ctx path history, caller should free after our return */
2785 } 2824 new_msg_ctx->path_history = msg_ctx->path_history;
2825 }
2786 route_result_message (find_peer_result, new_msg_ctx); 2826 route_result_message (find_peer_result, new_msg_ctx);
2787 GNUNET_free (new_msg_ctx); 2827 GNUNET_free (new_msg_ctx);
2788#if DEBUG_DHT_ROUTING 2828#if DEBUG_DHT_ROUTING
2789 if ((debug_routes) && (dhtlog_handle != NULL)) 2829 if ((debug_routes) && (dhtlog_handle != NULL))
2790 { 2830 {
2791 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER, 2831 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER,
2792 msg_ctx->hop_count, GNUNET_YES, 2832 msg_ctx->hop_count, GNUNET_YES,
2793 &my_identity, &msg_ctx->key); 2833 &my_identity, &msg_ctx->key);
2794 } 2834 }
2795#endif 2835#endif
2796 GNUNET_free_non_null (other_hello); 2836 GNUNET_free_non_null (other_hello);
2797 GNUNET_free (find_peer_result); 2837 GNUNET_free (find_peer_result);
@@ -2834,58 +2874,58 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2834 put_type = (enum GNUNET_BLOCK_Type) ntohl (put_msg->type); 2874 put_type = (enum GNUNET_BLOCK_Type) ntohl (put_msg->type);
2835#if HAVE_MALICIOUS 2875#if HAVE_MALICIOUS
2836 if (put_type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE) 2876 if (put_type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE)
2837 { 2877 {
2838#if DEBUG_DHT_ROUTING 2878#if DEBUG_DHT_ROUTING
2839 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2879 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2840 { 2880 {
2841 /** Log routes that die due to high load! */ 2881 /** Log routes that die due to high load! */
2842 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2882 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2843 msg_ctx->hop_count, GNUNET_SYSERR, 2883 msg_ctx->hop_count, GNUNET_SYSERR,
2844 &my_identity, &msg_ctx->key, 2884 &my_identity, &msg_ctx->key,
2845 msg_ctx->peer, NULL); 2885 msg_ctx->peer, NULL);
2846 }
2847#endif
2848 return;
2849 } 2886 }
2850#endif 2887#endif
2888 return;
2889 }
2890#endif
2851 data_size = 2891 data_size =
2852 ntohs (put_msg->header.size) - sizeof (struct GNUNET_DHT_PutMessage); 2892 ntohs (put_msg->header.size) - sizeof (struct GNUNET_DHT_PutMessage);
2853 ret = 2893 ret =
2854 GNUNET_BLOCK_get_key (block_context, put_type, &put_msg[1], data_size, 2894 GNUNET_BLOCK_get_key (block_context, put_type, &put_msg[1], data_size,
2855 &key); 2895 &key);
2856 if (GNUNET_NO == ret) 2896 if (GNUNET_NO == ret)
2857 { 2897 {
2858#if DEBUG_DHT_ROUTING 2898#if DEBUG_DHT_ROUTING
2859 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2899 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2860 { 2900 {
2861 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2901 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2862 msg_ctx->hop_count, GNUNET_SYSERR, 2902 msg_ctx->hop_count, GNUNET_SYSERR,
2863 &my_identity, &msg_ctx->key, 2903 &my_identity, &msg_ctx->key,
2864 msg_ctx->peer, NULL); 2904 msg_ctx->peer, NULL);
2865 }
2866#endif
2867 /* invalid reply */
2868 GNUNET_break_op (0);
2869 return;
2870 } 2905 }
2906#endif
2907 /* invalid reply */
2908 GNUNET_break_op (0);
2909 return;
2910 }
2871 if ((GNUNET_YES == ret) && 2911 if ((GNUNET_YES == ret) &&
2872 (0 != memcmp (&key, &msg_ctx->key, sizeof (GNUNET_HashCode)))) 2912 (0 != memcmp (&key, &msg_ctx->key, sizeof (GNUNET_HashCode))))
2873 { 2913 {
2874#if DEBUG_DHT_ROUTING 2914#if DEBUG_DHT_ROUTING
2875 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2915 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2876 { 2916 {
2877 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2917 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2878 msg_ctx->hop_count, GNUNET_SYSERR, 2918 msg_ctx->hop_count, GNUNET_SYSERR,
2879 &my_identity, &msg_ctx->key, 2919 &my_identity, &msg_ctx->key,
2880 msg_ctx->peer, NULL); 2920 msg_ctx->peer, NULL);
2881 }
2882#endif
2883 /* invalid wrapper: key mismatch! */
2884 GNUNET_break_op (0);
2885 return;
2886 } 2921 }
2922#endif
2923 /* invalid wrapper: key mismatch! */
2924 GNUNET_break_op (0);
2925 return;
2926 }
2887 /* ret == GNUNET_SYSERR means that there is no known relationship between 2927 /* ret == GNUNET_SYSERR means that there is no known relationship between
2888 data and the key, so we cannot check it */ 2928 * data and the key, so we cannot check it */
2889#if DEBUG_DHT 2929#if DEBUG_DHT
2890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2891 "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n", 2931 "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n",
@@ -2894,21 +2934,21 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2894#endif 2934#endif
2895#if DEBUG_DHT_ROUTING 2935#if DEBUG_DHT_ROUTING
2896 if (msg_ctx->hop_count == 0) /* Locally initiated request */ 2936 if (msg_ctx->hop_count == 0) /* Locally initiated request */
2937 {
2938 if ((debug_routes) && (dhtlog_handle != NULL))
2897 { 2939 {
2898 if ((debug_routes) && (dhtlog_handle != NULL)) 2940 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
2899 { 2941 msg_ctx->hop_count, GNUNET_NO,
2900 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT, 2942 &my_identity, &msg_ctx->key);
2901 msg_ctx->hop_count, GNUNET_NO,
2902 &my_identity, &msg_ctx->key);
2903 }
2904 } 2943 }
2944 }
2905#endif 2945#endif
2906 2946
2907 if (msg_ctx->closest != GNUNET_YES) 2947 if (msg_ctx->closest != GNUNET_YES)
2908 { 2948 {
2909 route_message (msg, msg_ctx); 2949 route_message (msg, msg_ctx);
2910 return; 2950 return;
2911 } 2951 }
2912 2952
2913#if DEBUG_DHT 2953#if DEBUG_DHT
2914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2919,54 +2959,57 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2919 2959
2920#if DEBUG_DHT_ROUTING 2960#if DEBUG_DHT_ROUTING
2921 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2961 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2922 { 2962 {
2923 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2963 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2924 msg_ctx->hop_count, GNUNET_YES, 2964 msg_ctx->hop_count, GNUNET_YES,
2925 &my_identity, &msg_ctx->key, msg_ctx->peer, 2965 &my_identity, &msg_ctx->key, msg_ctx->peer,
2926 NULL); 2966 NULL);
2927 } 2967 }
2928 2968
2929 if ((debug_routes) && (dhtlog_handle != NULL)) 2969 if ((debug_routes) && (dhtlog_handle != NULL))
2930 { 2970 {
2931 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT, 2971 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
2932 msg_ctx->hop_count, GNUNET_YES, 2972 msg_ctx->hop_count, GNUNET_YES,
2933 &my_identity, &msg_ctx->key); 2973 &my_identity, &msg_ctx->key);
2934 } 2974 }
2935#endif 2975#endif
2936 2976
2937 increment_stats (STAT_PUTS_INSERTED); 2977 increment_stats (STAT_PUTS_INSERTED);
2938 if (datacache != NULL) 2978 if (datacache != NULL)
2939 { 2979 {
2940 /* Put size is actual data size plus struct overhead plus path length (if any) */ 2980 /* Put size is actual data size plus struct overhead plus path length (if any) */
2941 put_size = data_size + sizeof(struct DHTPutEntry) + (msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); 2981 put_size =
2942 put_entry = GNUNET_malloc(put_size); 2982 data_size + sizeof (struct DHTPutEntry) +
2943 put_entry->data_size = data_size; 2983 (msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
2944 put_entry->path_length = msg_ctx->path_history_len; 2984 put_entry = GNUNET_malloc (put_size);
2945 /* Copy data to end of put entry */ 2985 put_entry->data_size = data_size;
2946 memcpy(&put_entry[1], &put_msg[1], data_size); 2986 put_entry->path_length = msg_ctx->path_history_len;
2947 if (msg_ctx->path_history_len > 0) 2987 /* Copy data to end of put entry */
2948 { 2988 memcpy (&put_entry[1], &put_msg[1], data_size);
2949 /* Copy path after data */ 2989 if (msg_ctx->path_history_len > 0)
2950 path_offset = (char *)&put_entry[1]; 2990 {
2951 path_offset += data_size; 2991 /* Copy path after data */
2952 memcpy(path_offset, msg_ctx->path_history, msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); 2992 path_offset = (char *) &put_entry[1];
2953 } 2993 path_offset += data_size;
2954 2994 memcpy (path_offset, msg_ctx->path_history,
2955 ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size, 2995 msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
2956 (const char *) put_entry, put_type, 2996 }
2957 GNUNET_TIME_absolute_ntoh 2997
2958 (put_msg->expiration)); 2998 ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size,
2959 GNUNET_free (put_entry); 2999 (const char *) put_entry, put_type,
2960 3000 GNUNET_TIME_absolute_ntoh
2961 if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES)) 3001 (put_msg->expiration));
2962 { 3002 GNUNET_free (put_entry);
2963 put_context = GNUNET_malloc (sizeof (struct RepublishContext)); 3003
2964 memcpy (&put_context->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 3004 if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES))
2965 put_context->type = put_type; 3005 {
2966 GNUNET_SCHEDULER_add_delayed (dht_republish_frequency, 3006 put_context = GNUNET_malloc (sizeof (struct RepublishContext));
2967 &republish_content, put_context); 3007 memcpy (&put_context->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
2968 } 3008 put_context->type = put_type;
2969 } 3009 GNUNET_SCHEDULER_add_delayed (dht_republish_frequency,
3010 &republish_content, put_context);
3011 }
3012 }
2970 else 3013 else
2971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2972 "`%s:%s': %s request received, but have no datacache!\n", 3015 "`%s:%s': %s request received, but have no datacache!\n",
@@ -3027,70 +3070,75 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
3027 * but then only send to 1 or 0 peers based strictly on the number of hops. 3070 * but then only send to 1 or 0 peers based strictly on the number of hops.
3028 */ 3071 */
3029 if (strict_kademlia == GNUNET_YES) 3072 if (strict_kademlia == GNUNET_YES)
3030 { 3073 {
3031 if (hop_count == 0) 3074 if (hop_count == 0)
3032 return kademlia_replication; 3075 return kademlia_replication;
3033 else if (hop_count < max_hops) 3076 else if (hop_count < max_hops)
3034 return 1; 3077 return 1;
3035 else 3078 else
3036 return 0; 3079 return 0;
3037 } 3080 }
3038 3081
3039 /* FIXME: the smaller we think the network is the more lenient we should be for 3082 /* FIXME: the smaller we think the network is the more lenient we should be for
3040 * routing right? The estimation below only works if we think we have reasonably 3083 * routing right? The estimation below only works if we think we have reasonably
3041 * full routing tables, which for our RR topologies may not be the case! 3084 * full routing tables, which for our RR topologies may not be the case!
3042 */ 3085 */
3043 if (hop_count > max_hops) 3086 if (hop_count > max_hops)
3044 { 3087 {
3045#if DEBUG_DHT 3088#if DEBUG_DHT
3046 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3047 "`%s:%s': Hop count too high (est %d, lowest %d), NOT Forwarding request\n", 3090 "`%s:%s': Hop count too high (est %d, lowest %d), NOT Forwarding request\n",
3048 my_short_id, "DHT", estimate_diameter (), lowest_bucket); 3091 my_short_id, "DHT", estimate_diameter (), lowest_bucket);
3049#endif 3092#endif
3050 /* FIXME: does this work as intended, isn't the decision to forward or not made based on closeness as well? */ 3093 /* FIXME: does this work as intended, isn't the decision to forward or not made based on closeness as well? */
3051 if (GNUNET_YES == paper_forwarding) /* Once we have reached our ideal number of hops, don't stop forwarding! */ 3094 if (GNUNET_YES == paper_forwarding) /* Once we have reached our ideal number of hops, don't stop forwarding! */
3052 { 3095 {
3053 return 1; 3096 return 1;
3054 }
3055
3056 return 0;
3057 } 3097 }
3058 3098
3099 return 0;
3100 }
3101
3059 if (GNUNET_YES == paper_forwarding) 3102 if (GNUNET_YES == paper_forwarding)
3103 {
3104 /* FIXME: re-run replication trials with this formula */
3105 target_value = 1 + (target_replication - 1.0) / (diameter
3106 +
3107 ((float)
3108 (target_replication -
3109 1.0) * hop_count));
3110 /* Set forward count to floor of target_value */
3111 forward_count = (unsigned int) target_value;
3112 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
3113 target_value = target_value - forward_count;
3114 random_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
3115 UINT32_MAX);
3116
3117 if (random_value < (target_value * UINT32_MAX))
3118 forward_count += 1;
3119 }
3120 else
3121 {
3122 random_value = 0;
3123 forward_count = 1;
3124 target_value = target_replication / (diameter
3125 +
3126 ((float) target_replication *
3127 hop_count));
3128 if (target_value > 1)
3060 { 3129 {
3061 /* FIXME: re-run replication trials with this formula */
3062 target_value = 1 + (target_replication - 1.0) / (diameter
3063 + ((float) (target_replication - 1.0) * hop_count));
3064 /* Set forward count to floor of target_value */ 3130 /* Set forward count to floor of target_value */
3065 forward_count = (unsigned int) target_value; 3131 forward_count = (unsigned int) target_value;
3066 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ 3132 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
3067 target_value = target_value - forward_count; 3133 target_value = target_value - forward_count;
3068 random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG,
3069 UINT32_MAX);
3070
3071 if (random_value < (target_value * UINT32_MAX))
3072 forward_count += 1;
3073 } 3134 }
3074 else 3135 else
3075 { 3136 random_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
3076 random_value = 0; 3137 UINT32_MAX);
3077 forward_count = 1;
3078 target_value = target_replication / (diameter
3079 + ((float) target_replication * hop_count));
3080 if (target_value > 1)
3081 {
3082 /* Set forward count to floor of target_value */
3083 forward_count = (unsigned int) target_value;
3084 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
3085 target_value = target_value - forward_count;
3086 }
3087 else
3088 random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG,
3089 UINT32_MAX);
3090 3138
3091 if (random_value < (target_value * UINT32_MAX)) 3139 if (random_value < (target_value * UINT32_MAX))
3092 forward_count += 1; 3140 forward_count += 1;
3093 } 3141 }
3094 3142
3095 return forward_count; 3143 return forward_count;
3096} 3144}
@@ -3127,28 +3175,27 @@ am_closest_peer (const GNUNET_HashCode * target,
3127 pos = k_buckets[bucket_num].head; 3175 pos = k_buckets[bucket_num].head;
3128 count = 0; 3176 count = 0;
3129 while ((pos != NULL) && (count < bucket_size)) 3177 while ((pos != NULL) && (count < bucket_size))
3178 {
3179 if ((bloom != NULL)
3180 && (GNUNET_YES ==
3181 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
3130 { 3182 {
3131 if ((bloom != NULL) 3183 pos = pos->next;
3132 && (GNUNET_YES == 3184 continue; /* Skip already checked entries */
3133 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) 3185 }
3134 {
3135 pos = pos->next;
3136 continue; /* Skip already checked entries */
3137 }
3138 3186
3139 other_bits = 3187 other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, target);
3140 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, target); 3188 if (other_bits > bits)
3141 if (other_bits > bits) 3189 return GNUNET_NO;
3190 else if (other_bits == bits) /* We match the same number of bits */
3191 {
3192 if (strict_kademlia != GNUNET_YES) /* Return that we at as close as any other peer */
3193 return GNUNET_YES;
3194 else if (distance (&pos->id.hashPubKey, target) < my_distance) /* Check all known peers, only return if we are the true closest */
3142 return GNUNET_NO; 3195 return GNUNET_NO;
3143 else if (other_bits == bits) /* We match the same number of bits */
3144 {
3145 if (strict_kademlia != GNUNET_YES) /* Return that we at as close as any other peer */
3146 return GNUNET_YES;
3147 else if (distance (&pos->id.hashPubKey, target) < my_distance) /* Check all known peers, only return if we are the true closest */
3148 return GNUNET_NO;
3149 }
3150 pos = pos->next;
3151 } 3196 }
3197 pos = pos->next;
3198 }
3152 3199
3153 /* No peers closer, we are the closest! */ 3200 /* No peers closer, we are the closest! */
3154 return GNUNET_YES; 3201 return GNUNET_YES;
@@ -3188,42 +3235,42 @@ converge_distance (const GNUNET_HashCode * target,
3188 if (converge_modifier > 0) 3235 if (converge_modifier > 0)
3189 temp_modifier = converge_modifier * base_converge_modifier; 3236 temp_modifier = converge_modifier * base_converge_modifier;
3190 else 3237 else
3191 { 3238 {
3192 temp_modifier = base_converge_modifier; 3239 temp_modifier = base_converge_modifier;
3193 base_converge_modifier = 0.0; 3240 base_converge_modifier = 0.0;
3194 } 3241 }
3195 3242
3196 GNUNET_assert (temp_modifier > 0); 3243 GNUNET_assert (temp_modifier > 0);
3197 3244
3198 other_matching_bits = 3245 other_matching_bits =
3199 GNUNET_CRYPTO_hash_matching_bits (target, &peer->id.hashPubKey); 3246 GNUNET_CRYPTO_hash_matching_bits (target, &peer->id.hashPubKey);
3200 3247
3201 switch (converge_option) 3248 switch (converge_option)
3202 { 3249 {
3203 case DHT_CONVERGE_RANDOM: 3250 case DHT_CONVERGE_RANDOM:
3204 return 1; /* Always return 1, choose equally among all peers */ 3251 return 1; /* Always return 1, choose equally among all peers */
3205 case DHT_CONVERGE_LINEAR: 3252 case DHT_CONVERGE_LINEAR:
3206 calc_value = hops * curr_max_hops * temp_modifier; 3253 calc_value = hops * curr_max_hops * temp_modifier;
3207 break; 3254 break;
3208 case DHT_CONVERGE_SQUARE: 3255 case DHT_CONVERGE_SQUARE:
3209 /** 3256 /**
3210 * Simple square based curve. 3257 * Simple square based curve.
3211 */ 3258 */
3212 calc_value = 3259 calc_value =
3213 (sqrt (hops) / sqrt (curr_max_hops)) * (curr_max_hops / 3260 (sqrt (hops) / sqrt (curr_max_hops)) * (curr_max_hops /
3214 (curr_max_hops * 3261 (curr_max_hops *
3215 temp_modifier)); 3262 temp_modifier));
3216 break; 3263 break;
3217 case DHT_CONVERGE_EXPONENTIAL: 3264 case DHT_CONVERGE_EXPONENTIAL:
3218 /** 3265 /**
3219 * Simple exponential curve. 3266 * Simple exponential curve.
3220 */ 3267 */
3221 if (base_converge_modifier > 0) 3268 if (base_converge_modifier > 0)
3222 calc_value = (temp_modifier * hops * hops) / curr_max_hops; 3269 calc_value = (temp_modifier * hops * hops) / curr_max_hops;
3223 else 3270 else
3224 calc_value = (hops * hops) / curr_max_hops; 3271 calc_value = (hops * hops) / curr_max_hops;
3225 break; 3272 break;
3226 case DHT_CONVERGE_BINARY: 3273 case DHT_CONVERGE_BINARY:
3227 /** 3274 /**
3228 * If below the cutoff, route randomly (return 1), 3275 * If below the cutoff, route randomly (return 1),
3229 * If above the cutoff, return the maximum possible 3276 * If above the cutoff, return the maximum possible
@@ -3231,14 +3278,14 @@ converge_distance (const GNUNET_HashCode * target,
3231 * they are sorted.) 3278 * they are sorted.)
3232 */ 3279 */
3233 3280
3234 if (hops >= converge_modifier) /* Past cutoff */ 3281 if (hops >= converge_modifier) /* Past cutoff */
3235 { 3282 {
3236 return ULLONG_MAX; 3283 return ULLONG_MAX;
3237 }
3238 /* Fall through */
3239 default:
3240 return 1;
3241 } 3284 }
3285 /* Fall through */
3286 default:
3287 return 1;
3288 }
3242 3289
3243 /* Take the log (base e) of the number of bits matching the other peer */ 3290 /* Take the log (base e) of the number of bits matching the other peer */
3244 exponent = log (other_matching_bits); 3291 exponent = log (other_matching_bits);
@@ -3253,15 +3300,15 @@ converge_distance (const GNUNET_HashCode * target,
3253 ret = (unsigned long long) pow (other_matching_bits, calc_value); 3300 ret = (unsigned long long) pow (other_matching_bits, calc_value);
3254 if ((errno != 0) || fetestexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | 3301 if ((errno != 0) || fetestexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW |
3255 FE_UNDERFLOW)) 3302 FE_UNDERFLOW))
3256 { 3303 {
3257 if (0 != fetestexcept (FE_OVERFLOW)) 3304 if (0 != fetestexcept (FE_OVERFLOW))
3258 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_OVERFLOW\n"); 3305 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_OVERFLOW\n");
3259 if (0 != fetestexcept (FE_INVALID)) 3306 if (0 != fetestexcept (FE_INVALID))
3260 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_INVALID\n"); 3307 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_INVALID\n");
3261 if (0 != fetestexcept (FE_UNDERFLOW)) 3308 if (0 != fetestexcept (FE_UNDERFLOW))
3262 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_UNDERFLOW\n"); 3309 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_UNDERFLOW\n");
3263 return 0; 3310 return 0;
3264 } 3311 }
3265 else 3312 else
3266 return ret; 3313 return ret;
3267} 3314}
@@ -3322,6 +3369,7 @@ select_peer (const GNUNET_HashCode * target,
3322 unsigned long long temp_converge_distance; 3369 unsigned long long temp_converge_distance;
3323 unsigned long long total_distance; 3370 unsigned long long total_distance;
3324 unsigned long long selected; 3371 unsigned long long selected;
3372
3325#if DEBUG_DHT > 1 3373#if DEBUG_DHT > 1
3326 unsigned long long stats_total_distance; 3374 unsigned long long stats_total_distance;
3327 double sum; 3375 double sum;
@@ -3334,44 +3382,42 @@ select_peer (const GNUNET_HashCode * target,
3334 total_distance = 0; 3382 total_distance = 0;
3335 /** If we are doing kademlia routing, or converge is binary (saves some cycles) */ 3383 /** If we are doing kademlia routing, or converge is binary (saves some cycles) */
3336 if ((strict_kademlia == GNUNET_YES) || 3384 if ((strict_kademlia == GNUNET_YES) ||
3337 ((converge_option == DHT_CONVERGE_BINARY) 3385 ((converge_option == DHT_CONVERGE_BINARY) && (hops >= converge_modifier)))
3338 && (hops >= converge_modifier))) 3386 {
3387 largest_distance = 0;
3388 chosen = NULL;
3389 for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++)
3339 { 3390 {
3340 largest_distance = 0; 3391 pos = k_buckets[bc].head;
3341 chosen = NULL; 3392 count = 0;
3342 for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++) 3393 while ((pos != NULL) && (count < bucket_size))
3394 {
3395 /* If we are doing strict Kademlia routing, then checking the bloomfilter is basically cheating! */
3396 if (GNUNET_NO ==
3397 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3343 { 3398 {
3344 pos = k_buckets[bc].head; 3399 distance = inverse_distance (target, &pos->id.hashPubKey);
3345 count = 0; 3400 if (distance > largest_distance)
3346 while ((pos != NULL) && (count < bucket_size)) 3401 {
3347 { 3402 chosen = pos;
3348 /* If we are doing strict Kademlia routing, then checking the bloomfilter is basically cheating! */ 3403 largest_distance = distance;
3349 if (GNUNET_NO == 3404 }
3350 GNUNET_CONTAINER_bloomfilter_test (bloom,
3351 &pos->id.hashPubKey))
3352 {
3353 distance = inverse_distance (target, &pos->id.hashPubKey);
3354 if (distance > largest_distance)
3355 {
3356 chosen = pos;
3357 largest_distance = distance;
3358 }
3359 }
3360 count++;
3361 pos = pos->next;
3362 }
3363 } 3405 }
3406 count++;
3407 pos = pos->next;
3408 }
3409 }
3364 3410
3365 if ((largest_distance > 0) && (chosen != NULL)) 3411 if ((largest_distance > 0) && (chosen != NULL))
3366 { 3412 {
3367 GNUNET_CONTAINER_bloomfilter_add (bloom, &chosen->id.hashPubKey); 3413 GNUNET_CONTAINER_bloomfilter_add (bloom, &chosen->id.hashPubKey);
3368 return chosen; 3414 return chosen;
3369 }
3370 else
3371 {
3372 return NULL;
3373 }
3374 } 3415 }
3416 else
3417 {
3418 return NULL;
3419 }
3420 }
3375 3421
3376 /* GNUnet-style */ 3422 /* GNUnet-style */
3377 total_distance = 0; 3423 total_distance = 0;
@@ -3388,21 +3434,21 @@ select_peer (const GNUNET_HashCode * target,
3388 memset (sorted_closest, 0, sizeof (sorted_closest)); 3434 memset (sorted_closest, 0, sizeof (sorted_closest));
3389 /* Put any peers in the closest bucket in the sorting array */ 3435 /* Put any peers in the closest bucket in the sorting array */
3390 while ((pos != NULL) && (count < bucket_size)) 3436 while ((pos != NULL) && (count < bucket_size))
3437 {
3438 if (GNUNET_YES ==
3439 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3391 { 3440 {
3392 if (GNUNET_YES ==
3393 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3394 {
3395 count++;
3396 pos = pos->next;
3397 continue; /* Ignore bloomfiltered peers */
3398 }
3399 pos->matching_bits =
3400 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, target);
3401 sorted_closest[offset] = pos;
3402 pos = pos->next;
3403 offset++;
3404 count++; 3441 count++;
3442 pos = pos->next;
3443 continue; /* Ignore bloomfiltered peers */
3405 } 3444 }
3445 pos->matching_bits =
3446 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, target);
3447 sorted_closest[offset] = pos;
3448 pos = pos->next;
3449 offset++;
3450 count++;
3451 }
3406 3452
3407 /* Sort the peers in descending order */ 3453 /* Sort the peers in descending order */
3408 qsort (&sorted_closest[0], offset, sizeof (struct PeerInfo *), 3454 qsort (&sorted_closest[0], offset, sizeof (struct PeerInfo *),
@@ -3410,73 +3456,72 @@ select_peer (const GNUNET_HashCode * target,
3410 3456
3411 /* Put the sorted closest peers into the possible bins first, in case of overflow. */ 3457 /* Put the sorted closest peers into the possible bins first, in case of overflow. */
3412 for (i = 0; i < offset; i++) 3458 for (i = 0; i < offset; i++)
3413 { 3459 {
3414 temp_converge_distance = 3460 temp_converge_distance =
3415 converge_distance (target, sorted_closest[i], hops); 3461 converge_distance (target, sorted_closest[i], hops);
3416 if (GNUNET_YES == 3462 if (GNUNET_YES ==
3417 GNUNET_CONTAINER_bloomfilter_test (bloom, 3463 GNUNET_CONTAINER_bloomfilter_test (bloom,
3418 &sorted_closest[i]->id. 3464 &sorted_closest[i]->id.hashPubKey))
3419 hashPubKey)) 3465 break; /* Ignore bloomfiltered peers */
3420 break; /* Ignore bloomfiltered peers */ 3466 if (total_distance + temp_converge_distance > total_distance) /* Handle largest case and overflow */
3421 if (total_distance + temp_converge_distance > total_distance) /* Handle largest case and overflow */ 3467 total_distance += temp_converge_distance;
3422 total_distance += temp_converge_distance; 3468 else
3423 else 3469 break; /* overflow case */
3424 break; /* overflow case */ 3470 }
3425 }
3426 3471
3427 /* Now handle peers in lower buckets (matches same # of bits as target) */ 3472 /* Now handle peers in lower buckets (matches same # of bits as target) */
3428 for (bc = lowest_bucket; bc < closest_bucket; bc++) 3473 for (bc = lowest_bucket; bc < closest_bucket; bc++)
3474 {
3475 pos = k_buckets[bc].head;
3476 count = 0;
3477 while ((pos != NULL) && (count < bucket_size))
3429 { 3478 {
3430 pos = k_buckets[bc].head; 3479 if (GNUNET_YES ==
3431 count = 0; 3480 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3432 while ((pos != NULL) && (count < bucket_size)) 3481 {
3433 { 3482 count++;
3434 if (GNUNET_YES == 3483 pos = pos->next;
3435 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) 3484 continue; /* Ignore bloomfiltered peers */
3436 { 3485 }
3437 count++; 3486 temp_converge_distance = converge_distance (target, pos, hops);
3438 pos = pos->next; 3487 if (total_distance + temp_converge_distance > total_distance) /* Handle largest case and overflow */
3439 continue; /* Ignore bloomfiltered peers */ 3488 total_distance += temp_converge_distance;
3440 } 3489 else
3441 temp_converge_distance = converge_distance (target, pos, hops); 3490 break; /* overflow case */
3442 if (total_distance + temp_converge_distance > total_distance) /* Handle largest case and overflow */ 3491 pos = pos->next;
3443 total_distance += temp_converge_distance; 3492 count++;
3444 else
3445 break; /* overflow case */
3446 pos = pos->next;
3447 count++;
3448 }
3449 } 3493 }
3494 }
3450 3495
3451 /* Now handle all the further away peers */ 3496 /* Now handle all the further away peers */
3452 for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++) 3497 for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++)
3498 {
3499 pos = k_buckets[bc].head;
3500 count = 0;
3501 while ((pos != NULL) && (count < bucket_size))
3453 { 3502 {
3454 pos = k_buckets[bc].head; 3503 if (GNUNET_YES ==
3455 count = 0; 3504 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3456 while ((pos != NULL) && (count < bucket_size)) 3505 {
3457 { 3506 count++;
3458 if (GNUNET_YES == 3507 pos = pos->next;
3459 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) 3508 continue; /* Ignore bloomfiltered peers */
3460 { 3509 }
3461 count++; 3510 temp_converge_distance = converge_distance (target, pos, hops);
3462 pos = pos->next; 3511 if (total_distance + temp_converge_distance > total_distance) /* Handle largest case and overflow */
3463 continue; /* Ignore bloomfiltered peers */ 3512 total_distance += temp_converge_distance;
3464 } 3513 else
3465 temp_converge_distance = converge_distance (target, pos, hops); 3514 break; /* overflow case */
3466 if (total_distance + temp_converge_distance > total_distance) /* Handle largest case and overflow */ 3515 pos = pos->next;
3467 total_distance += temp_converge_distance; 3516 count++;
3468 else
3469 break; /* overflow case */
3470 pos = pos->next;
3471 count++;
3472 }
3473 } 3517 }
3518 }
3474 3519
3475 if (total_distance == 0) /* No peers to select from! */ 3520 if (total_distance == 0) /* No peers to select from! */
3476 { 3521 {
3477 increment_stats ("# failed to select peer"); 3522 increment_stats ("# failed to select peer");
3478 return NULL; 3523 return NULL;
3479 } 3524 }
3480 3525
3481#if DEBUG_DHT_ROUTING > 1 3526#if DEBUG_DHT_ROUTING > 1
3482 sum = 0.0; 3527 sum = 0.0;
@@ -3484,164 +3529,160 @@ select_peer (const GNUNET_HashCode * target,
3484 /* Put the sorted closest peers into the possible bins first, in case of overflow. */ 3529 /* Put the sorted closest peers into the possible bins first, in case of overflow. */
3485 stats_total_distance = 0; 3530 stats_total_distance = 0;
3486 for (i = 0; i < offset; i++) 3531 for (i = 0; i < offset; i++)
3532 {
3533 if (GNUNET_YES ==
3534 GNUNET_CONTAINER_bloomfilter_test (bloom,
3535 &sorted_closest[i]->id.hashPubKey))
3536 break; /* Ignore bloomfiltered peers */
3537 temp_converge_distance =
3538 converge_distance (target, sorted_closest[i], hops);
3539 if (stats_total_distance + temp_converge_distance > stats_total_distance) /* Handle largest case and overflow */
3540 stats_total_distance += temp_converge_distance;
3541 else
3542 break; /* overflow case */
3543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3544 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n",
3545 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id.
3546 hashPubKey, target),
3547 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id.
3548 hashPubKey,
3549 &my_identity.hashPubKey),
3550 (temp_converge_distance / (double) total_distance) * 100,
3551 temp_converge_distance);
3552 }
3553
3554 /* Now handle peers in lower buckets (matches same # of bits as target) */
3555 for (bc = lowest_bucket; bc < closest_bucket; bc++)
3556 {
3557 pos = k_buckets[bc].head;
3558 count = 0;
3559 while ((pos != NULL) && (count < bucket_size))
3487 { 3560 {
3488 if (GNUNET_YES == 3561 if (GNUNET_YES ==
3489 GNUNET_CONTAINER_bloomfilter_test (bloom, 3562 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3490 &sorted_closest[i]->id. 3563 {
3491 hashPubKey)) 3564 count++;
3492 break; /* Ignore bloomfiltered peers */ 3565 pos = pos->next;
3493 temp_converge_distance = 3566 continue; /* Ignore bloomfiltered peers */
3494 converge_distance (target, sorted_closest[i], hops); 3567 }
3495 if (stats_total_distance + temp_converge_distance > stats_total_distance) /* Handle largest case and overflow */ 3568 temp_converge_distance = converge_distance (target, pos, hops);
3569 if (stats_total_distance + temp_converge_distance > stats_total_distance) /* Handle largest case and overflow */
3496 stats_total_distance += temp_converge_distance; 3570 stats_total_distance += temp_converge_distance;
3497 else 3571 else
3498 break; /* overflow case */ 3572 break; /* overflow case */
3499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3500 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n", 3574 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n",
3501 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id. 3575 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3502 hashPubKey, target), 3576 target),
3503 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id. 3577 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3504 hashPubKey,
3505 &my_identity.hashPubKey), 3578 &my_identity.hashPubKey),
3506 (temp_converge_distance / (double) total_distance) * 100, 3579 (temp_converge_distance / (double) total_distance) *
3507 temp_converge_distance); 3580 100, temp_converge_distance);
3508 } 3581 pos = pos->next;
3509 3582 count++;
3510 /* Now handle peers in lower buckets (matches same # of bits as target) */
3511 for (bc = lowest_bucket; bc < closest_bucket; bc++)
3512 {
3513 pos = k_buckets[bc].head;
3514 count = 0;
3515 while ((pos != NULL) && (count < bucket_size))
3516 {
3517 if (GNUNET_YES ==
3518 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3519 {
3520 count++;
3521 pos = pos->next;
3522 continue; /* Ignore bloomfiltered peers */
3523 }
3524 temp_converge_distance = converge_distance (target, pos, hops);
3525 if (stats_total_distance + temp_converge_distance > stats_total_distance) /* Handle largest case and overflow */
3526 stats_total_distance += temp_converge_distance;
3527 else
3528 break; /* overflow case */
3529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3530 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n",
3531 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3532 target),
3533 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3534 &my_identity.
3535 hashPubKey),
3536 (temp_converge_distance / (double) total_distance) *
3537 100, temp_converge_distance);
3538 pos = pos->next;
3539 count++;
3540 }
3541 } 3583 }
3584 }
3542 3585
3543 /* Now handle all the further away peers */ 3586 /* Now handle all the further away peers */
3544 for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++) 3587 for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++)
3588 {
3589 pos = k_buckets[bc].head;
3590 count = 0;
3591 while ((pos != NULL) && (count < bucket_size))
3545 { 3592 {
3546 pos = k_buckets[bc].head; 3593 if (GNUNET_YES ==
3547 count = 0; 3594 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3548 while ((pos != NULL) && (count < bucket_size)) 3595 {
3549 { 3596 count++;
3550 if (GNUNET_YES == 3597 pos = pos->next;
3551 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) 3598 continue; /* Ignore bloomfiltered peers */
3552 { 3599 }
3553 count++; 3600 temp_converge_distance = converge_distance (target, pos, hops);
3554 pos = pos->next; 3601 if (stats_total_distance + temp_converge_distance > stats_total_distance) /* Handle largest case and overflow */
3555 continue; /* Ignore bloomfiltered peers */ 3602 stats_total_distance += temp_converge_distance;
3556 } 3603 else
3557 temp_converge_distance = converge_distance (target, pos, hops); 3604 break; /* overflow case */
3558 if (stats_total_distance + temp_converge_distance > stats_total_distance) /* Handle largest case and overflow */ 3605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3559 stats_total_distance += temp_converge_distance; 3606 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n",
3560 else 3607 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3561 break; /* overflow case */ 3608 target),
3562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3609 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3563 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n", 3610 &my_identity.hashPubKey),
3564 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, 3611 (temp_converge_distance / (double) total_distance) *
3565 target), 3612 100, temp_converge_distance);
3566 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, 3613 pos = pos->next;
3567 &my_identity. 3614 count++;
3568 hashPubKey),
3569 (temp_converge_distance / (double) total_distance) *
3570 100, temp_converge_distance);
3571 pos = pos->next;
3572 count++;
3573 }
3574 } 3615 }
3616 }
3575 /* END PRINT STATS */ 3617 /* END PRINT STATS */
3576#endif 3618#endif
3577 3619
3578 /* Now actually choose a peer */ 3620 /* Now actually choose a peer */
3579 selected = 3621 selected =
3580 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, total_distance); 3622 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, total_distance);
3581 3623
3582 /* Go over closest sorted peers. */ 3624 /* Go over closest sorted peers. */
3583 for (i = 0; i < offset; i++) 3625 for (i = 0; i < offset; i++)
3584 { 3626 {
3585 if (GNUNET_YES == 3627 if (GNUNET_YES ==
3586 GNUNET_CONTAINER_bloomfilter_test (bloom, 3628 GNUNET_CONTAINER_bloomfilter_test (bloom,
3587 &sorted_closest[i]->id. 3629 &sorted_closest[i]->id.hashPubKey))
3588 hashPubKey)) 3630 break; /* Ignore bloomfiltered peers */
3589 break; /* Ignore bloomfiltered peers */ 3631 temp_converge_distance =
3590 temp_converge_distance =
3591 converge_distance (target, sorted_closest[i], hops); 3632 converge_distance (target, sorted_closest[i], hops);
3592 if (temp_converge_distance >= selected) 3633 if (temp_converge_distance >= selected)
3593 return sorted_closest[i]; 3634 return sorted_closest[i];
3594 else 3635 else
3595 selected -= temp_converge_distance; 3636 selected -= temp_converge_distance;
3596 } 3637 }
3597 3638
3598 /* Now handle peers in lower buckets (matches same # of bits as target) */ 3639 /* Now handle peers in lower buckets (matches same # of bits as target) */
3599 for (bc = lowest_bucket; bc < closest_bucket; bc++) 3640 for (bc = lowest_bucket; bc < closest_bucket; bc++)
3641 {
3642 pos = k_buckets[bc].head;
3643 count = 0;
3644 while ((pos != NULL) && (count < bucket_size))
3600 { 3645 {
3601 pos = k_buckets[bc].head; 3646 if (GNUNET_YES ==
3602 count = 0; 3647 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3603 while ((pos != NULL) && (count < bucket_size)) 3648 {
3604 { 3649 count++;
3605 if (GNUNET_YES == 3650 pos = pos->next;
3606 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) 3651 continue; /* Ignore bloomfiltered peers */
3607 { 3652 }
3608 count++; 3653 temp_converge_distance = converge_distance (target, pos, hops);
3609 pos = pos->next; 3654 if (temp_converge_distance >= selected)
3610 continue; /* Ignore bloomfiltered peers */ 3655 return pos;
3611 } 3656 else
3612 temp_converge_distance = converge_distance (target, pos, hops); 3657 selected -= temp_converge_distance;
3613 if (temp_converge_distance >= selected) 3658 pos = pos->next;
3614 return pos; 3659 count++;
3615 else
3616 selected -= temp_converge_distance;
3617 pos = pos->next;
3618 count++;
3619 }
3620 } 3660 }
3661 }
3621 3662
3622 /* Now handle all the further away peers */ 3663 /* Now handle all the further away peers */
3623 for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++) 3664 for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++)
3665 {
3666 pos = k_buckets[bc].head;
3667 count = 0;
3668 while ((pos != NULL) && (count < bucket_size))
3624 { 3669 {
3625 pos = k_buckets[bc].head; 3670 if (GNUNET_YES ==
3626 count = 0; 3671 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
3627 while ((pos != NULL) && (count < bucket_size)) 3672 {
3628 { 3673 count++;
3629 if (GNUNET_YES == 3674 pos = pos->next;
3630 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) 3675 continue; /* Ignore bloomfiltered peers */
3631 { 3676 }
3632 count++; 3677 temp_converge_distance = converge_distance (target, pos, hops);
3633 pos = pos->next; 3678 if (temp_converge_distance >= selected)
3634 continue; /* Ignore bloomfiltered peers */ 3679 return pos;
3635 } 3680 else
3636 temp_converge_distance = converge_distance (target, pos, hops); 3681 selected -= temp_converge_distance;
3637 if (temp_converge_distance >= selected) 3682 pos = pos->next;
3638 return pos; 3683 count++;
3639 else
3640 selected -= temp_converge_distance;
3641 pos = pos->next;
3642 count++;
3643 }
3644 } 3684 }
3685 }
3645 3686
3646 increment_stats ("# failed to select peer"); 3687 increment_stats ("# failed to select peer");
3647 return NULL; 3688 return NULL;
@@ -3671,11 +3712,11 @@ remove_recent (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3671 GNUNET_free (req); 3712 GNUNET_free (req);
3672 3713
3673 /* 3714 /*
3674 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) && (0 == GNUNET_CONTAINER_multihashmap_size(recent.hashmap)) && (0 == GNUNET_CONTAINER_heap_get_size(recent.minHeap))) 3715 * if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) && (0 == GNUNET_CONTAINER_multihashmap_size(recent.hashmap)) && (0 == GNUNET_CONTAINER_heap_get_size(recent.minHeap)))
3675 { 3716 * {
3676 GNUNET_CONTAINER_multihashmap_destroy(recent.hashmap); 3717 * GNUNET_CONTAINER_multihashmap_destroy(recent.hashmap);
3677 GNUNET_CONTAINER_heap_destroy(recent.minHeap); 3718 * GNUNET_CONTAINER_heap_destroy(recent.minHeap);
3678 } 3719 * }
3679 */ 3720 */
3680} 3721}
3681 3722
@@ -3701,29 +3742,28 @@ cache_response (struct DHT_MessageContext *msg_ctx)
3701 3742
3702#if DELETE_WHEN_FULL 3743#if DELETE_WHEN_FULL
3703 while (current_size >= MAX_OUTSTANDING_FORWARDS) 3744 while (current_size >= MAX_OUTSTANDING_FORWARDS)
3745 {
3746 source_info = GNUNET_CONTAINER_heap_remove_root (forward_list.minHeap);
3747 GNUNET_assert (source_info != NULL);
3748 record = source_info->record;
3749 GNUNET_CONTAINER_DLL_remove (record->head, record->tail, source_info);
3750 if (record->head == NULL) /* No more entries in DLL */
3704 { 3751 {
3705 source_info = GNUNET_CONTAINER_heap_remove_root (forward_list.minHeap); 3752 GNUNET_assert (GNUNET_YES ==
3706 GNUNET_assert (source_info != NULL); 3753 GNUNET_CONTAINER_multihashmap_remove
3707 record = source_info->record; 3754 (forward_list.hashmap, &record->key, record));
3708 GNUNET_CONTAINER_DLL_remove (record->head, record->tail, source_info); 3755 GNUNET_free (record);
3709 if (record->head == NULL) /* No more entries in DLL */
3710 {
3711 GNUNET_assert (GNUNET_YES ==
3712 GNUNET_CONTAINER_multihashmap_remove
3713 (forward_list.hashmap, &record->key, record));
3714 GNUNET_free (record);
3715 }
3716 if (source_info->delete_task != GNUNET_SCHEDULER_NO_TASK)
3717 {
3718 GNUNET_SCHEDULER_cancel (source_info->delete_task);
3719 source_info->delete_task = GNUNET_SCHEDULER_NO_TASK;
3720 }
3721 if (source_info->find_peers_responded != NULL)
3722 GNUNET_CONTAINER_bloomfilter_free (source_info->find_peers_responded);
3723 GNUNET_free (source_info);
3724 current_size =
3725 GNUNET_CONTAINER_multihashmap_size (forward_list.hashmap);
3726 } 3756 }
3757 if (source_info->delete_task != GNUNET_SCHEDULER_NO_TASK)
3758 {
3759 GNUNET_SCHEDULER_cancel (source_info->delete_task);
3760 source_info->delete_task = GNUNET_SCHEDULER_NO_TASK;
3761 }
3762 if (source_info->find_peers_responded != NULL)
3763 GNUNET_CONTAINER_bloomfilter_free (source_info->find_peers_responded);
3764 GNUNET_free (source_info);
3765 current_size = GNUNET_CONTAINER_multihashmap_size (forward_list.hashmap);
3766 }
3727#endif 3767#endif
3728 /** Non-local request and have too many outstanding forwards, discard! */ 3768 /** Non-local request and have too many outstanding forwards, discard! */
3729 if ((current_size >= MAX_OUTSTANDING_FORWARDS) && (msg_ctx->client == NULL)) 3769 if ((current_size >= MAX_OUTSTANDING_FORWARDS) && (msg_ctx->client == NULL))
@@ -3731,54 +3771,54 @@ cache_response (struct DHT_MessageContext *msg_ctx)
3731 3771
3732 now = GNUNET_TIME_absolute_get (); 3772 now = GNUNET_TIME_absolute_get ();
3733 record = 3773 record =
3734 GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, &msg_ctx->key); 3774 GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, &msg_ctx->key);
3735 if (record != NULL) /* Already know this request! */ 3775 if (record != NULL) /* Already know this request! */
3736 { 3776 {
3737 pos = record->head; 3777 pos = record->head;
3738 while (pos != NULL) 3778 while (pos != NULL)
3739 { 3779 {
3740 if (0 == 3780 if (0 ==
3741 memcmp (msg_ctx->peer, &pos->source, 3781 memcmp (msg_ctx->peer, &pos->source,
3742 sizeof (struct GNUNET_PeerIdentity))) 3782 sizeof (struct GNUNET_PeerIdentity)))
3743 break; /* Already have this peer in reply list! */ 3783 break; /* Already have this peer in reply list! */
3744 pos = pos->next; 3784 pos = pos->next;
3745 }
3746 if ((pos != NULL) && (pos->client == msg_ctx->client)) /* Seen this already */
3747 {
3748 GNUNET_CONTAINER_heap_update_cost (forward_list.minHeap, pos->hnode,
3749 now.abs_value);
3750 return GNUNET_NO;
3751 }
3752 } 3785 }
3753 else 3786 if ((pos != NULL) && (pos->client == msg_ctx->client)) /* Seen this already */
3754 { 3787 {
3755 record = GNUNET_malloc (sizeof (struct DHTQueryRecord)); 3788 GNUNET_CONTAINER_heap_update_cost (forward_list.minHeap, pos->hnode,
3756 GNUNET_assert (GNUNET_OK == 3789 now.abs_value);
3757 GNUNET_CONTAINER_multihashmap_put (forward_list.hashmap, 3790 return GNUNET_NO;
3758 &msg_ctx->key, record,
3759 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
3760 memcpy (&record->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
3761 } 3791 }
3792 }
3793 else
3794 {
3795 record = GNUNET_malloc (sizeof (struct DHTQueryRecord));
3796 GNUNET_assert (GNUNET_OK ==
3797 GNUNET_CONTAINER_multihashmap_put (forward_list.hashmap,
3798 &msg_ctx->key, record,
3799 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
3800 memcpy (&record->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
3801 }
3762 3802
3763 source_info = GNUNET_malloc (sizeof (struct DHTRouteSource)); 3803 source_info = GNUNET_malloc (sizeof (struct DHTRouteSource));
3764 source_info->record = record; 3804 source_info->record = record;
3765 source_info->delete_task = 3805 source_info->delete_task =
3766 GNUNET_SCHEDULER_add_delayed (DHT_FORWARD_TIMEOUT, &remove_forward_entry, 3806 GNUNET_SCHEDULER_add_delayed (DHT_FORWARD_TIMEOUT, &remove_forward_entry,
3767 source_info); 3807 source_info);
3768 source_info->find_peers_responded = 3808 source_info->find_peers_responded =
3769 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 3809 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
3770 memcpy (&source_info->source, msg_ctx->peer, 3810 memcpy (&source_info->source, msg_ctx->peer,
3771 sizeof (struct GNUNET_PeerIdentity)); 3811 sizeof (struct GNUNET_PeerIdentity));
3772 GNUNET_CONTAINER_DLL_insert_after (record->head, record->tail, record->tail, 3812 GNUNET_CONTAINER_DLL_insert_after (record->head, record->tail, record->tail,
3773 source_info); 3813 source_info);
3774 if (msg_ctx->client != NULL) /* For local request, set timeout so high it effectively never gets pushed out */ 3814 if (msg_ctx->client != NULL) /* For local request, set timeout so high it effectively never gets pushed out */
3775 { 3815 {
3776 source_info->client = msg_ctx->client; 3816 source_info->client = msg_ctx->client;
3777 now = GNUNET_TIME_absolute_get_forever (); 3817 now = GNUNET_TIME_absolute_get_forever ();
3778 } 3818 }
3779 source_info->hnode = 3819 source_info->hnode =
3780 GNUNET_CONTAINER_heap_insert (forward_list.minHeap, source_info, 3820 GNUNET_CONTAINER_heap_insert (forward_list.minHeap, source_info,
3781 now.abs_value); 3821 now.abs_value);
3782#if DEBUG_DHT > 1 3822#if DEBUG_DHT > 1
3783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3784 "`%s:%s': Created new forward source info for %s uid %llu\n", 3824 "`%s:%s': Created new forward source info for %s uid %llu\n",
@@ -3802,6 +3842,7 @@ route_message (const struct GNUNET_MessageHeader *msg,
3802{ 3842{
3803 int i; 3843 int i;
3804 struct PeerInfo *selected; 3844 struct PeerInfo *selected;
3845
3805#if DEBUG_DHT_ROUTING > 1 3846#if DEBUG_DHT_ROUTING > 1
3806 struct PeerInfo *nearest; 3847 struct PeerInfo *nearest;
3807#endif 3848#endif
@@ -3811,39 +3852,40 @@ route_message (const struct GNUNET_MessageHeader *msg,
3811 GNUNET_HashCode unique_hash; 3852 GNUNET_HashCode unique_hash;
3812 char *stat_forward_count; 3853 char *stat_forward_count;
3813 char *temp_stat_str; 3854 char *temp_stat_str;
3855
3814#if DEBUG_DHT_ROUTING 3856#if DEBUG_DHT_ROUTING
3815 int ret; 3857 int ret;
3816#endif 3858#endif
3817 3859
3818 if (malicious_dropper == GNUNET_YES) 3860 if (malicious_dropper == GNUNET_YES)
3819 { 3861 {
3820#if DEBUG_DHT_ROUTING 3862#if DEBUG_DHT_ROUTING
3821 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 3863 if ((debug_routes_extended) && (dhtlog_handle != NULL))
3822 { 3864 {
3823 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 3865 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
3824 msg_ctx->hop_count, GNUNET_SYSERR, 3866 msg_ctx->hop_count, GNUNET_SYSERR,
3825 &my_identity, &msg_ctx->key, 3867 &my_identity, &msg_ctx->key,
3826 msg_ctx->peer, NULL); 3868 msg_ctx->peer, NULL);
3827 } 3869 }
3828#endif 3870#endif
3829 if (msg_ctx->bloom != NULL) 3871 if (msg_ctx->bloom != NULL)
3830 { 3872 {
3831 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom); 3873 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
3832 msg_ctx->bloom = NULL; 3874 msg_ctx->bloom = NULL;
3833 }
3834 return;
3835 } 3875 }
3876 return;
3877 }
3836 3878
3837 increment_stats (STAT_ROUTES); 3879 increment_stats (STAT_ROUTES);
3838 target_forward_count = 3880 target_forward_count =
3839 get_forward_count (msg_ctx->hop_count, msg_ctx->replication); 3881 get_forward_count (msg_ctx->hop_count, msg_ctx->replication);
3840 GNUNET_asprintf (&stat_forward_count, "# forward counts of %d", 3882 GNUNET_asprintf (&stat_forward_count, "# forward counts of %d",
3841 target_forward_count); 3883 target_forward_count);
3842 increment_stats (stat_forward_count); 3884 increment_stats (stat_forward_count);
3843 GNUNET_free (stat_forward_count); 3885 GNUNET_free (stat_forward_count);
3844 if (msg_ctx->bloom == NULL) 3886 if (msg_ctx->bloom == NULL)
3845 msg_ctx->bloom = 3887 msg_ctx->bloom =
3846 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 3888 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
3847 3889
3848 if ((stop_on_closest == GNUNET_YES) && (msg_ctx->closest == GNUNET_YES) 3890 if ((stop_on_closest == GNUNET_YES) && (msg_ctx->closest == GNUNET_YES)
3849 && (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) 3891 && (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT))
@@ -3874,109 +3916,106 @@ route_message (const struct GNUNET_MessageHeader *msg,
3874 hash_from_uid (msg_ctx->unique_id, &unique_hash); 3916 hash_from_uid (msg_ctx->unique_id, &unique_hash);
3875 if (GNUNET_YES == 3917 if (GNUNET_YES ==
3876 GNUNET_CONTAINER_multihashmap_contains (recent.hashmap, &unique_hash)) 3918 GNUNET_CONTAINER_multihashmap_contains (recent.hashmap, &unique_hash))
3877 { 3919 {
3878 recent_req = 3920 recent_req =
3879 GNUNET_CONTAINER_multihashmap_get (recent.hashmap, &unique_hash); 3921 GNUNET_CONTAINER_multihashmap_get (recent.hashmap, &unique_hash);
3880 GNUNET_assert (recent_req != NULL); 3922 GNUNET_assert (recent_req != NULL);
3881 if (0 != 3923 if (0 != memcmp (&recent_req->key, &msg_ctx->key, sizeof (GNUNET_HashCode)))
3882 memcmp (&recent_req->key, &msg_ctx->key, sizeof (GNUNET_HashCode))) 3924 increment_stats (STAT_DUPLICATE_UID);
3883 increment_stats (STAT_DUPLICATE_UID); 3925 else
3884 else 3926 {
3885 { 3927 increment_stats (STAT_RECENT_SEEN);
3886 increment_stats (STAT_RECENT_SEEN); 3928 GNUNET_CONTAINER_bloomfilter_or2 (msg_ctx->bloom, recent_req->bloom,
3887 GNUNET_CONTAINER_bloomfilter_or2 (msg_ctx->bloom, recent_req->bloom, 3929 DHT_BLOOM_SIZE);
3888 DHT_BLOOM_SIZE);
3889 }
3890 } 3930 }
3931 }
3891 else 3932 else
3892 { 3933 {
3893 recent_req = GNUNET_malloc (sizeof (struct RecentRequest)); 3934 recent_req = GNUNET_malloc (sizeof (struct RecentRequest));
3894 recent_req->uid = msg_ctx->unique_id; 3935 recent_req->uid = msg_ctx->unique_id;
3895 memcpy (&recent_req->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 3936 memcpy (&recent_req->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
3896 recent_req->remove_task = 3937 recent_req->remove_task =
3897 GNUNET_SCHEDULER_add_delayed (DEFAULT_RECENT_REMOVAL, &remove_recent, 3938 GNUNET_SCHEDULER_add_delayed (DEFAULT_RECENT_REMOVAL, &remove_recent,
3898 recent_req); 3939 recent_req);
3899 recent_req->heap_node = 3940 recent_req->heap_node =
3900 GNUNET_CONTAINER_heap_insert (recent.minHeap, recent_req, 3941 GNUNET_CONTAINER_heap_insert (recent.minHeap, recent_req,
3901 GNUNET_TIME_absolute_get ().abs_value); 3942 GNUNET_TIME_absolute_get ().abs_value);
3902 recent_req->bloom = 3943 recent_req->bloom =
3903 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 3944 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
3904 GNUNET_CONTAINER_multihashmap_put (recent.hashmap, &unique_hash, 3945 GNUNET_CONTAINER_multihashmap_put (recent.hashmap, &unique_hash,
3905 recent_req, 3946 recent_req,
3906 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 3947 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
3907 } 3948 }
3908 3949
3909 if (GNUNET_CONTAINER_multihashmap_size (recent.hashmap) > DHT_MAX_RECENT) 3950 if (GNUNET_CONTAINER_multihashmap_size (recent.hashmap) > DHT_MAX_RECENT)
3910 { 3951 {
3911 recent_req = GNUNET_CONTAINER_heap_peek (recent.minHeap); 3952 recent_req = GNUNET_CONTAINER_heap_peek (recent.minHeap);
3912 GNUNET_assert (recent_req != NULL); 3953 GNUNET_assert (recent_req != NULL);
3913 GNUNET_SCHEDULER_cancel (recent_req->remove_task); 3954 GNUNET_SCHEDULER_cancel (recent_req->remove_task);
3914 GNUNET_SCHEDULER_add_now (&remove_recent, recent_req); 3955 GNUNET_SCHEDULER_add_now (&remove_recent, recent_req);
3915 } 3956 }
3916 3957
3917 forward_count = 0; 3958 forward_count = 0;
3918 for (i = 0; i < target_forward_count; i++) 3959 for (i = 0; i < target_forward_count; i++)
3919 { 3960 {
3920 selected = 3961 selected = select_peer (&msg_ctx->key, msg_ctx->bloom, msg_ctx->hop_count);
3921 select_peer (&msg_ctx->key, msg_ctx->bloom, msg_ctx->hop_count); 3962
3922 3963 if (selected != NULL)
3923 if (selected != NULL) 3964 {
3924 { 3965 forward_count++;
3925 forward_count++; 3966 if (GNUNET_CRYPTO_hash_matching_bits
3926 if (GNUNET_CRYPTO_hash_matching_bits 3967 (&selected->id.hashPubKey,
3927 (&selected->id.hashPubKey, 3968 &msg_ctx->key) >=
3928 &msg_ctx->key) >= 3969 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
3929 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, 3970 &msg_ctx->key))
3930 &msg_ctx->key)) 3971 GNUNET_asprintf (&temp_stat_str,
3931 GNUNET_asprintf (&temp_stat_str, 3972 "# requests routed to close(r) peer hop %u",
3932 "# requests routed to close(r) peer hop %u", 3973 msg_ctx->hop_count);
3933 msg_ctx->hop_count); 3974 else
3934 else 3975 GNUNET_asprintf (&temp_stat_str,
3935 GNUNET_asprintf (&temp_stat_str, 3976 "# requests routed to less close peer hop %u",
3936 "# requests routed to less close peer hop %u", 3977 msg_ctx->hop_count);
3937 msg_ctx->hop_count); 3978 if (temp_stat_str != NULL)
3938 if (temp_stat_str != NULL) 3979 {
3939 { 3980 increment_stats (temp_stat_str);
3940 increment_stats (temp_stat_str); 3981 GNUNET_free (temp_stat_str);
3941 GNUNET_free (temp_stat_str); 3982 }
3942 } 3983 GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom,
3943 GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom, 3984 &selected->id.hashPubKey);
3944 &selected->id.hashPubKey);
3945#if DEBUG_DHT_ROUTING > 1 3985#if DEBUG_DHT_ROUTING > 1
3946 nearest = find_closest_peer (&msg_ctx->key); 3986 nearest = find_closest_peer (&msg_ctx->key);
3947 nearest_buf = GNUNET_strdup (GNUNET_i2s (&nearest->id)); 3987 nearest_buf = GNUNET_strdup (GNUNET_i2s (&nearest->id));
3948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3949 "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n", 3989 "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n",
3950 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 3990 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
3951 msg_ctx->unique_id, GNUNET_i2s (&selected->id), 3991 msg_ctx->unique_id, GNUNET_i2s (&selected->id),
3952 nearest_buf, 3992 nearest_buf,
3953 GNUNET_CRYPTO_hash_matching_bits (&nearest->id. 3993 GNUNET_CRYPTO_hash_matching_bits (&nearest->id.hashPubKey,
3954 hashPubKey, 3994 msg_ctx->key),
3955 msg_ctx->key), 3995 distance (&nearest->id.hashPubKey, msg_ctx->key));
3956 distance (&nearest->id.hashPubKey, msg_ctx->key)); 3996 GNUNET_free (nearest_buf);
3957 GNUNET_free (nearest_buf);
3958#endif 3997#endif
3959#if DEBUG_DHT_ROUTING 3998#if DEBUG_DHT_ROUTING
3960 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 3999 if ((debug_routes_extended) && (dhtlog_handle != NULL))
3961 { 4000 {
3962 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 4001 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
3963 DHTLOG_ROUTE, msg_ctx->hop_count, 4002 DHTLOG_ROUTE, msg_ctx->hop_count,
3964 GNUNET_NO, &my_identity, 4003 GNUNET_NO, &my_identity,
3965 &msg_ctx->key, msg_ctx->peer, 4004 &msg_ctx->key, msg_ctx->peer,
3966 &selected->id); 4005 &selected->id);
3967 } 4006 }
3968#endif 4007#endif
3969 forward_message (msg, selected, msg_ctx); 4008 forward_message (msg, selected, msg_ctx);
3970 }
3971 } 4009 }
4010 }
3972 4011
3973 if (msg_ctx->bloom != NULL) 4012 if (msg_ctx->bloom != NULL)
3974 { 4013 {
3975 GNUNET_CONTAINER_bloomfilter_or2 (recent_req->bloom, msg_ctx->bloom, 4014 GNUNET_CONTAINER_bloomfilter_or2 (recent_req->bloom, msg_ctx->bloom,
3976 DHT_BLOOM_SIZE); 4015 DHT_BLOOM_SIZE);
3977 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom); 4016 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
3978 msg_ctx->bloom = NULL; 4017 msg_ctx->bloom = NULL;
3979 } 4018 }
3980 4019
3981#if DEBUG_DHT_ROUTING 4020#if DEBUG_DHT_ROUTING
3982 if (forward_count == 0) 4021 if (forward_count == 0)
@@ -3985,12 +4024,12 @@ route_message (const struct GNUNET_MessageHeader *msg,
3985 ret = GNUNET_NO; 4024 ret = GNUNET_NO;
3986 4025
3987 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4026 if ((debug_routes_extended) && (dhtlog_handle != NULL))
3988 { 4027 {
3989 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 4028 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
3990 msg_ctx->hop_count, ret, 4029 msg_ctx->hop_count, ret,
3991 &my_identity, &msg_ctx->key, msg_ctx->peer, 4030 &my_identity, &msg_ctx->key, msg_ctx->peer,
3992 NULL); 4031 NULL);
3993 } 4032 }
3994#endif 4033#endif
3995} 4034}
3996 4035
@@ -4011,51 +4050,50 @@ demultiplex_message (const struct GNUNET_MessageHeader *msg,
4011 msg_ctx->closest = am_closest_peer (&msg_ctx->key, msg_ctx->bloom); 4050 msg_ctx->closest = am_closest_peer (&msg_ctx->key, msg_ctx->bloom);
4012 4051
4013 switch (ntohs (msg->type)) 4052 switch (ntohs (msg->type))
4053 {
4054 case GNUNET_MESSAGE_TYPE_DHT_GET: /* Add to hashmap of requests seen, search for data (always) */
4055 cache_response (msg_ctx);
4056 handle_dht_get (msg, msg_ctx);
4057 break;
4058 case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. */
4059 increment_stats (STAT_PUTS);
4060 handle_dht_put (msg, msg_ctx);
4061 break;
4062 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */
4063 increment_stats (STAT_FIND_PEER);
4064 if (((msg_ctx->hop_count > 0)
4065 && (0 !=
4066 memcmp (msg_ctx->peer, &my_identity,
4067 sizeof (struct GNUNET_PeerIdentity))))
4068 || (msg_ctx->client != NULL))
4014 { 4069 {
4015 case GNUNET_MESSAGE_TYPE_DHT_GET: /* Add to hashmap of requests seen, search for data (always) */
4016 cache_response (msg_ctx); 4070 cache_response (msg_ctx);
4017 handle_dht_get (msg, msg_ctx); 4071 if ((msg_ctx->closest == GNUNET_YES)
4018 break; 4072 || (msg_ctx->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE))
4019 case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. */ 4073 handle_dht_find_peer (msg, msg_ctx);
4020 increment_stats (STAT_PUTS); 4074 }
4021 handle_dht_put (msg, msg_ctx); 4075 else
4022 break;
4023 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */
4024 increment_stats (STAT_FIND_PEER);
4025 if (((msg_ctx->hop_count > 0)
4026 && (0 !=
4027 memcmp (msg_ctx->peer, &my_identity,
4028 sizeof (struct GNUNET_PeerIdentity))))
4029 || (msg_ctx->client != NULL))
4030 {
4031 cache_response (msg_ctx);
4032 if ((msg_ctx->closest == GNUNET_YES)
4033 || (msg_ctx->msg_options ==
4034 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE))
4035 handle_dht_find_peer (msg, msg_ctx);
4036 }
4037 else
4038 route_message (msg, msg_ctx);
4039#if DEBUG_DHT_ROUTING
4040 if (msg_ctx->hop_count == 0) /* Locally initiated request */
4041 {
4042 if ((debug_routes) && (dhtlog_handle != NULL))
4043 {
4044 dhtlog_handle->insert_dhtkey (NULL, &msg_ctx->key);
4045 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id,
4046 DHTLOG_FIND_PEER,
4047 msg_ctx->hop_count, GNUNET_NO,
4048 &my_identity, &msg_ctx->key);
4049 }
4050 }
4051#endif
4052 break;
4053 default:
4054 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4055 "`%s': Message type (%d) not handled, forwarding anyway!\n",
4056 "DHT", ntohs (msg->type));
4057 route_message (msg, msg_ctx); 4076 route_message (msg, msg_ctx);
4077#if DEBUG_DHT_ROUTING
4078 if (msg_ctx->hop_count == 0) /* Locally initiated request */
4079 {
4080 if ((debug_routes) && (dhtlog_handle != NULL))
4081 {
4082 dhtlog_handle->insert_dhtkey (NULL, &msg_ctx->key);
4083 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id,
4084 DHTLOG_FIND_PEER,
4085 msg_ctx->hop_count, GNUNET_NO,
4086 &my_identity, &msg_ctx->key);
4087 }
4058 } 4088 }
4089#endif
4090 break;
4091 default:
4092 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4093 "`%s': Message type (%d) not handled, forwarding anyway!\n",
4094 "DHT", ntohs (msg->type));
4095 route_message (msg, msg_ctx);
4096 }
4059} 4097}
4060 4098
4061 4099
@@ -4083,6 +4121,7 @@ republish_content_iterator (void *cls,
4083 4121
4084 struct DHT_MessageContext *new_msg_ctx; 4122 struct DHT_MessageContext *new_msg_ctx;
4085 struct GNUNET_DHT_PutMessage *put_msg; 4123 struct GNUNET_DHT_PutMessage *put_msg;
4124
4086#if DEBUG_DHT 4125#if DEBUG_DHT
4087 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4088 "`%s:%s': Received `%s' response from datacache\n", my_short_id, 4127 "`%s:%s': Received `%s' response from datacache\n", my_short_id,
@@ -4097,14 +4136,14 @@ republish_content_iterator (void *cls,
4097 put_msg->type = htons (type); 4136 put_msg->type = htons (type);
4098 memcpy (&put_msg[1], data, size); 4137 memcpy (&put_msg[1], data, size);
4099 new_msg_ctx->unique_id = 4138 new_msg_ctx->unique_id =
4100 GNUNET_ntohll (GNUNET_CRYPTO_random_u64 4139 GNUNET_ntohll (GNUNET_CRYPTO_random_u64
4101 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX)); 4140 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
4102 new_msg_ctx->replication = ntohl (DEFAULT_PUT_REPLICATION); 4141 new_msg_ctx->replication = ntohl (DEFAULT_PUT_REPLICATION);
4103 new_msg_ctx->msg_options = ntohl (0); 4142 new_msg_ctx->msg_options = ntohl (0);
4104 new_msg_ctx->network_size = estimate_diameter (); 4143 new_msg_ctx->network_size = estimate_diameter ();
4105 new_msg_ctx->peer = &my_identity; 4144 new_msg_ctx->peer = &my_identity;
4106 new_msg_ctx->bloom = 4145 new_msg_ctx->bloom =
4107 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 4146 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
4108 new_msg_ctx->hop_count = 0; 4147 new_msg_ctx->hop_count = 0;
4109 new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE; 4148 new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE;
4110 new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; 4149 new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
@@ -4129,16 +4168,16 @@ republish_content (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4129 4168
4130 unsigned int results; 4169 unsigned int results;
4131 4170
4132 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 4171 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
4133 { 4172 {
4134 GNUNET_free (put_context); 4173 GNUNET_free (put_context);
4135 return; 4174 return;
4136 } 4175 }
4137 4176
4138 GNUNET_assert (datacache != NULL); /* If we have no datacache we never should have scheduled this! */ 4177 GNUNET_assert (datacache != NULL); /* If we have no datacache we never should have scheduled this! */
4139 results = 4178 results =
4140 GNUNET_DATACACHE_get (datacache, &put_context->key, put_context->type, 4179 GNUNET_DATACACHE_get (datacache, &put_context->key, put_context->type,
4141 &republish_content_iterator, NULL); 4180 &republish_content_iterator, NULL);
4142 if (results == 0) /* Data must have expired */ 4181 if (results == 0) /* Data must have expired */
4143 GNUNET_free (put_context); 4182 GNUNET_free (put_context);
4144 else /* Reschedule task for next time period */ 4183 else /* Reschedule task for next time period */
@@ -4164,33 +4203,34 @@ find_client_records (void *cls, const GNUNET_HashCode * key, void *value)
4164 struct ClientList *client = cls; 4203 struct ClientList *client = cls;
4165 struct DHTQueryRecord *record = value; 4204 struct DHTQueryRecord *record = value;
4166 struct DHTRouteSource *pos; 4205 struct DHTRouteSource *pos;
4206
4167 pos = record->head; 4207 pos = record->head;
4168 while (pos != NULL) 4208 while (pos != NULL)
4169 { 4209 {
4170 if (pos->client == client) 4210 if (pos->client == client)
4171 break; 4211 break;
4172 pos = pos->next; 4212 pos = pos->next;
4173 } 4213 }
4174 if (pos != NULL) 4214 if (pos != NULL)
4175 { 4215 {
4176 GNUNET_CONTAINER_DLL_remove (record->head, record->tail, pos); 4216 GNUNET_CONTAINER_DLL_remove (record->head, record->tail, pos);
4177 GNUNET_CONTAINER_heap_remove_node (pos->hnode); 4217 GNUNET_CONTAINER_heap_remove_node (pos->hnode);
4178 if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK) 4218 if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
4179 { 4219 {
4180 GNUNET_SCHEDULER_cancel (pos->delete_task); 4220 GNUNET_SCHEDULER_cancel (pos->delete_task);
4181 pos->delete_task = GNUNET_SCHEDULER_NO_TASK; 4221 pos->delete_task = GNUNET_SCHEDULER_NO_TASK;
4182 } 4222 }
4183 if (pos->find_peers_responded != NULL) 4223 if (pos->find_peers_responded != NULL)
4184 GNUNET_CONTAINER_bloomfilter_free (pos->find_peers_responded); 4224 GNUNET_CONTAINER_bloomfilter_free (pos->find_peers_responded);
4185 GNUNET_free (pos); 4225 GNUNET_free (pos);
4186 } 4226 }
4187 if (record->head == NULL) /* No more entries in DLL */ 4227 if (record->head == NULL) /* No more entries in DLL */
4188 { 4228 {
4189 GNUNET_assert (GNUNET_YES == 4229 GNUNET_assert (GNUNET_YES ==
4190 GNUNET_CONTAINER_multihashmap_remove 4230 GNUNET_CONTAINER_multihashmap_remove
4191 (forward_list.hashmap, &record->key, record)); 4231 (forward_list.hashmap, &record->key, record));
4192 GNUNET_free (record); 4232 GNUNET_free (record);
4193 } 4233 }
4194 return GNUNET_YES; 4234 return GNUNET_YES;
4195} 4235}
4196 4236
@@ -4213,36 +4253,35 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
4213 prev = NULL; 4253 prev = NULL;
4214 found = NULL; 4254 found = NULL;
4215 while (pos != NULL) 4255 while (pos != NULL)
4256 {
4257 if (pos->client_handle == client)
4216 { 4258 {
4217 if (pos->client_handle == client) 4259 if (prev != NULL)
4218 { 4260 prev->next = pos->next;
4219 if (prev != NULL) 4261 else
4220 prev->next = pos->next; 4262 client_list = pos->next;
4221 else 4263 found = pos;
4222 client_list = pos->next; 4264 break;
4223 found = pos;
4224 break;
4225 }
4226 prev = pos;
4227 pos = pos->next;
4228 } 4265 }
4266 prev = pos;
4267 pos = pos->next;
4268 }
4229 4269
4230 if (found != NULL) 4270 if (found != NULL)
4231 { 4271 {
4232 if (found->transmit_handle != NULL) 4272 if (found->transmit_handle != NULL)
4233 GNUNET_CONNECTION_notify_transmit_ready_cancel 4273 GNUNET_CONNECTION_notify_transmit_ready_cancel (found->transmit_handle);
4234 (found->transmit_handle);
4235 4274
4236 while (NULL != (reply = found->pending_head)) 4275 while (NULL != (reply = found->pending_head))
4237 { 4276 {
4238 GNUNET_CONTAINER_DLL_remove (found->pending_head, 4277 GNUNET_CONTAINER_DLL_remove (found->pending_head,
4239 found->pending_tail, reply); 4278 found->pending_tail, reply);
4240 GNUNET_free (reply); 4279 GNUNET_free (reply);
4241 }
4242 GNUNET_CONTAINER_multihashmap_iterate (forward_list.hashmap,
4243 &find_client_records, found);
4244 GNUNET_free (found);
4245 } 4280 }
4281 GNUNET_CONTAINER_multihashmap_iterate (forward_list.hashmap,
4282 &find_client_records, found);
4283 GNUNET_free (found);
4284 }
4246} 4285}
4247 4286
4248/** 4287/**
@@ -4259,11 +4298,11 @@ find_active_client (struct GNUNET_SERVER_Client *client)
4259 struct ClientList *ret; 4298 struct ClientList *ret;
4260 4299
4261 while (pos != NULL) 4300 while (pos != NULL)
4262 { 4301 {
4263 if (pos->client_handle == client) 4302 if (pos->client_handle == client)
4264 return pos; 4303 return pos;
4265 pos = pos->next; 4304 pos = pos->next;
4266 } 4305 }
4267 4306
4268 ret = GNUNET_malloc (sizeof (struct ClientList)); 4307 ret = GNUNET_malloc (sizeof (struct ClientList));
4269 ret->client_handle = client; 4308 ret->client_handle = client;
@@ -4288,21 +4327,21 @@ malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4288 static GNUNET_HashCode key; 4327 static GNUNET_HashCode key;
4289 uint32_t random_key; 4328 uint32_t random_key;
4290 4329
4291 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 4330 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
4292 return; 4331 return;
4293 put_message.header.size = htons (sizeof (struct GNUNET_DHT_PutMessage)); 4332 put_message.header.size = htons (sizeof (struct GNUNET_DHT_PutMessage));
4294 put_message.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_PUT); 4333 put_message.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_PUT);
4295 put_message.type = htonl (GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE); 4334 put_message.type = htonl (GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE);
4296 put_message.expiration = 4335 put_message.expiration =
4297 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_forever ()); 4336 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_forever ());
4298 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 4337 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
4299 random_key = 4338 random_key =
4300 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 4339 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
4301 GNUNET_CRYPTO_hash (&random_key, sizeof (uint32_t), &key); 4340 GNUNET_CRYPTO_hash (&random_key, sizeof (uint32_t), &key);
4302 memcpy (&msg_ctx.key, &key, sizeof (GNUNET_HashCode)); 4341 memcpy (&msg_ctx.key, &key, sizeof (GNUNET_HashCode));
4303 msg_ctx.unique_id = 4342 msg_ctx.unique_id =
4304 GNUNET_ntohll (GNUNET_CRYPTO_random_u64 4343 GNUNET_ntohll (GNUNET_CRYPTO_random_u64
4305 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX)); 4344 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
4306 msg_ctx.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION); 4345 msg_ctx.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION);
4307 msg_ctx.msg_options = ntohl (0); 4346 msg_ctx.msg_options = ntohl (0);
4308 msg_ctx.network_size = estimate_diameter (); 4347 msg_ctx.network_size = estimate_diameter ();
@@ -4339,7 +4378,7 @@ malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4339 static GNUNET_HashCode key; 4378 static GNUNET_HashCode key;
4340 uint32_t random_key; 4379 uint32_t random_key;
4341 4380
4342 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 4381 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
4343 return; 4382 return;
4344 4383
4345 get_message.header.size = htons (sizeof (struct GNUNET_DHT_GetMessage)); 4384 get_message.header.size = htons (sizeof (struct GNUNET_DHT_GetMessage));
@@ -4347,12 +4386,12 @@ malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4347 get_message.type = htonl (GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE); 4386 get_message.type = htonl (GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE);
4348 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 4387 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
4349 random_key = 4388 random_key =
4350 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 4389 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
4351 GNUNET_CRYPTO_hash (&random_key, sizeof (uint32_t), &key); 4390 GNUNET_CRYPTO_hash (&random_key, sizeof (uint32_t), &key);
4352 memcpy (&msg_ctx.key, &key, sizeof (GNUNET_HashCode)); 4391 memcpy (&msg_ctx.key, &key, sizeof (GNUNET_HashCode));
4353 msg_ctx.unique_id = 4392 msg_ctx.unique_id =
4354 GNUNET_ntohll (GNUNET_CRYPTO_random_u64 4393 GNUNET_ntohll (GNUNET_CRYPTO_random_u64
4355 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX)); 4394 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
4356 msg_ctx.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION); 4395 msg_ctx.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION);
4357 msg_ctx.msg_options = ntohl (0); 4396 msg_ctx.msg_options = ntohl (0);
4358 msg_ctx.network_size = estimate_diameter (); 4397 msg_ctx.network_size = estimate_diameter ();
@@ -4390,6 +4429,7 @@ static int
4390add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value) 4429add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value)
4391{ 4430{
4392 struct GNUNET_CONTAINER_BloomFilter *bloom = cls; 4431 struct GNUNET_CONTAINER_BloomFilter *bloom = cls;
4432
4393 GNUNET_CONTAINER_bloomfilter_add (bloom, key); 4433 GNUNET_CONTAINER_bloomfilter_add (bloom, key);
4394 return GNUNET_YES; 4434 return GNUNET_YES;
4395} 4435}
@@ -4410,62 +4450,63 @@ send_find_peer_message (void *cls,
4410 struct DHT_MessageContext msg_ctx; 4450 struct DHT_MessageContext msg_ctx;
4411 struct GNUNET_TIME_Relative next_send_time; 4451 struct GNUNET_TIME_Relative next_send_time;
4412 struct GNUNET_CONTAINER_BloomFilter *temp_bloom; 4452 struct GNUNET_CONTAINER_BloomFilter *temp_bloom;
4453
4413#if COUNT_INTERVAL 4454#if COUNT_INTERVAL
4414 struct GNUNET_TIME_Relative time_diff; 4455 struct GNUNET_TIME_Relative time_diff;
4415 struct GNUNET_TIME_Absolute end; 4456 struct GNUNET_TIME_Absolute end;
4416 double multiplier; 4457 double multiplier;
4417 double count_per_interval; 4458 double count_per_interval;
4418#endif 4459#endif
4419 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 4460 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
4420 return; 4461 return;
4421 4462
4422 if ((newly_found_peers > bucket_size) && (GNUNET_YES == do_find_peer)) /* If we are finding peers already, no need to send out our request right now! */ 4463 if ((newly_found_peers > bucket_size) && (GNUNET_YES == do_find_peer)) /* If we are finding peers already, no need to send out our request right now! */
4423 { 4464 {
4424 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4465 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4425 "Have %d newly found peers since last find peer message sent!\n", 4466 "Have %d newly found peers since last find peer message sent!\n",
4426 newly_found_peers); 4467 newly_found_peers);
4427 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 4468 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
4428 &send_find_peer_message, NULL); 4469 &send_find_peer_message, NULL);
4429 newly_found_peers = 0; 4470 newly_found_peers = 0;
4430 return; 4471 return;
4431 } 4472 }
4432 4473
4433 increment_stats (STAT_FIND_PEER_START); 4474 increment_stats (STAT_FIND_PEER_START);
4434#if COUNT_INTERVAL 4475#if COUNT_INTERVAL
4435 end = GNUNET_TIME_absolute_get (); 4476 end = GNUNET_TIME_absolute_get ();
4436 time_diff = 4477 time_diff =
4437 GNUNET_TIME_absolute_get_difference (find_peer_context.start, end); 4478 GNUNET_TIME_absolute_get_difference (find_peer_context.start, end);
4438 4479
4439 if (time_diff.abs_value > FIND_PEER_CALC_INTERVAL.abs_value) 4480 if (time_diff.abs_value > FIND_PEER_CALC_INTERVAL.abs_value)
4440 { 4481 {
4441 multiplier = time_diff.abs_value / FIND_PEER_CALC_INTERVAL.abs_value; 4482 multiplier = time_diff.abs_value / FIND_PEER_CALC_INTERVAL.abs_value;
4442 count_per_interval = find_peer_context.count / multiplier; 4483 count_per_interval = find_peer_context.count / multiplier;
4443 } 4484 }
4444 else 4485 else
4445 { 4486 {
4446 multiplier = FIND_PEER_CALC_INTERVAL.abs_value / time_diff.abs_value; 4487 multiplier = FIND_PEER_CALC_INTERVAL.abs_value / time_diff.abs_value;
4447 count_per_interval = find_peer_context.count * multiplier; 4488 count_per_interval = find_peer_context.count * multiplier;
4448 } 4489 }
4449#endif 4490#endif
4450 4491
4451#if FIND_PEER_WITH_HELLO 4492#if FIND_PEER_WITH_HELLO
4452 find_peer_msg = 4493 find_peer_msg =
4453 GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerMessage) + 4494 GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerMessage) +
4454 GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) 4495 GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *)
4455 my_hello)); 4496 my_hello));
4456 find_peer_msg->header.size = 4497 find_peer_msg->header.size =
4457 htons (sizeof (struct GNUNET_DHT_FindPeerMessage) + 4498 htons (sizeof (struct GNUNET_DHT_FindPeerMessage) +
4458 GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) my_hello)); 4499 GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) my_hello));
4459 memcpy (&find_peer_msg[1], my_hello, 4500 memcpy (&find_peer_msg[1], my_hello,
4460 GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) my_hello)); 4501 GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) my_hello));
4461#else 4502#else
4462 find_peer_msg = GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerMessage)); 4503 find_peer_msg = GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerMessage));
4463 find_peer_msg->header.size = 4504 find_peer_msg->header.size =
4464 htons (sizeof (struct GNUNET_DHT_FindPeerMessage)); 4505 htons (sizeof (struct GNUNET_DHT_FindPeerMessage));
4465#endif 4506#endif
4466 find_peer_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); 4507 find_peer_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER);
4467 temp_bloom = 4508 temp_bloom =
4468 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 4509 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
4469 GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom, 4510 GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom,
4470 temp_bloom); 4511 temp_bloom);
4471 GNUNET_assert (GNUNET_OK == 4512 GNUNET_assert (GNUNET_OK ==
@@ -4477,8 +4518,8 @@ send_find_peer_message (void *cls,
4477 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 4518 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
4478 memcpy (&msg_ctx.key, &my_identity.hashPubKey, sizeof (GNUNET_HashCode)); 4519 memcpy (&msg_ctx.key, &my_identity.hashPubKey, sizeof (GNUNET_HashCode));
4479 msg_ctx.unique_id = 4520 msg_ctx.unique_id =
4480 GNUNET_ntohll (GNUNET_CRYPTO_random_u64 4521 GNUNET_ntohll (GNUNET_CRYPTO_random_u64
4481 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX)); 4522 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX));
4482 msg_ctx.replication = DHT_DEFAULT_FIND_PEER_REPLICATION; 4523 msg_ctx.replication = DHT_DEFAULT_FIND_PEER_REPLICATION;
4483 msg_ctx.msg_options = DHT_DEFAULT_FIND_PEER_OPTIONS; 4524 msg_ctx.msg_options = DHT_DEFAULT_FIND_PEER_OPTIONS;
4484 msg_ctx.network_size = estimate_diameter (); 4525 msg_ctx.network_size = estimate_diameter ();
@@ -4492,30 +4533,29 @@ send_find_peer_message (void *cls,
4492 "`%s:%s': Sent `%s' request to some (?) peers\n", my_short_id, 4533 "`%s:%s': Sent `%s' request to some (?) peers\n", my_short_id,
4493 "DHT", "FIND PEER"); 4534 "DHT", "FIND PEER");
4494 if (newly_found_peers < bucket_size) 4535 if (newly_found_peers < bucket_size)
4495 { 4536 {
4496 next_send_time.rel_value = 4537 next_send_time.rel_value =
4497 (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2) + 4538 (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2) +
4498 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, 4539 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
4499 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 4540 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2);
4500 2); 4541 }
4501 }
4502 else 4542 else
4503 { 4543 {
4504 next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 4544 next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
4505 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, 4545 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
4506 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value - 4546 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value -
4507 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value); 4547 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
4508 } 4548 }
4509 4549
4510 GNUNET_assert (next_send_time.rel_value != 0); 4550 GNUNET_assert (next_send_time.rel_value != 0);
4511 find_peer_context.count = 0; 4551 find_peer_context.count = 0;
4512 newly_found_peers = 0; 4552 newly_found_peers = 0;
4513 find_peer_context.start = GNUNET_TIME_absolute_get (); 4553 find_peer_context.start = GNUNET_TIME_absolute_get ();
4514 if (GNUNET_YES == do_find_peer) 4554 if (GNUNET_YES == do_find_peer)
4515 { 4555 {
4516 GNUNET_SCHEDULER_add_delayed (next_send_time, 4556 GNUNET_SCHEDULER_add_delayed (next_send_time,
4517 &send_find_peer_message, NULL); 4557 &send_find_peer_message, NULL);
4518 } 4558 }
4519} 4559}
4520 4560
4521/** 4561/**
@@ -4533,7 +4573,7 @@ handle_dht_local_route_request (void *cls,
4533 const struct GNUNET_MessageHeader *message) 4573 const struct GNUNET_MessageHeader *message)
4534{ 4574{
4535 const struct GNUNET_DHT_RouteMessage *dht_msg = 4575 const struct GNUNET_DHT_RouteMessage *dht_msg =
4536 (const struct GNUNET_DHT_RouteMessage *) message; 4576 (const struct GNUNET_DHT_RouteMessage *) message;
4537 const struct GNUNET_MessageHeader *enc_msg; 4577 const struct GNUNET_MessageHeader *enc_msg;
4538 struct DHT_MessageContext msg_ctx; 4578 struct DHT_MessageContext msg_ctx;
4539 4579
@@ -4558,12 +4598,14 @@ handle_dht_local_route_request (void *cls,
4558 msg_ctx.unique_id = GNUNET_ntohll (dht_msg->unique_id); 4598 msg_ctx.unique_id = GNUNET_ntohll (dht_msg->unique_id);
4559 msg_ctx.replication = ntohl (dht_msg->desired_replication_level); 4599 msg_ctx.replication = ntohl (dht_msg->desired_replication_level);
4560 msg_ctx.msg_options = ntohl (dht_msg->options); 4600 msg_ctx.msg_options = ntohl (dht_msg->options);
4561 if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx.msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) 4601 if (GNUNET_DHT_RO_RECORD_ROUTE ==
4562 { 4602 (msg_ctx.msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
4563 msg_ctx.path_history = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 4603 {
4564 memcpy(msg_ctx.path_history, &my_identity, sizeof(struct GNUNET_PeerIdentity)); 4604 msg_ctx.path_history = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
4565 msg_ctx.path_history_len = 1; 4605 memcpy (msg_ctx.path_history, &my_identity,
4566 } 4606 sizeof (struct GNUNET_PeerIdentity));
4607 msg_ctx.path_history_len = 1;
4608 }
4567 msg_ctx.network_size = estimate_diameter (); 4609 msg_ctx.network_size = estimate_diameter ();
4568 msg_ctx.peer = &my_identity; 4610 msg_ctx.peer = &my_identity;
4569 msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 4; /* Make local routing a higher priority */ 4611 msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 4; /* Make local routing a higher priority */
@@ -4577,35 +4619,33 @@ handle_dht_local_route_request (void *cls,
4577 increment_stats (STAT_FIND_PEER_START); 4619 increment_stats (STAT_FIND_PEER_START);
4578 4620
4579 if (GNUNET_YES == malicious_dropper) 4621 if (GNUNET_YES == malicious_dropper)
4622 {
4623 if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET)
4580 { 4624 {
4581 if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET)
4582 {
4583#if DEBUG_DHT_ROUTING 4625#if DEBUG_DHT_ROUTING
4584 if ((debug_routes) && (dhtlog_handle != NULL)) 4626 if ((debug_routes) && (dhtlog_handle != NULL))
4585 { 4627 {
4586 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, 4628 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id,
4587 DHTLOG_GET, msg_ctx.hop_count, 4629 DHTLOG_GET, msg_ctx.hop_count,
4588 GNUNET_NO, &my_identity, 4630 GNUNET_NO, &my_identity, &msg_ctx.key);
4589 &msg_ctx.key); 4631 }
4590 }
4591#endif 4632#endif
4592 } 4633 }
4593 else if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT) 4634 else if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)
4594 { 4635 {
4595#if DEBUG_DHT_ROUTING 4636#if DEBUG_DHT_ROUTING
4596 if ((debug_routes) && (dhtlog_handle != NULL)) 4637 if ((debug_routes) && (dhtlog_handle != NULL))
4597 { 4638 {
4598 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, 4639 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id,
4599 DHTLOG_PUT, msg_ctx.hop_count, 4640 DHTLOG_PUT, msg_ctx.hop_count,
4600 GNUNET_NO, &my_identity, 4641 GNUNET_NO, &my_identity, &msg_ctx.key);
4601 &msg_ctx.key); 4642 }
4602 }
4603#endif 4643#endif
4604 }
4605 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4606 GNUNET_free_non_null(msg_ctx.path_history);
4607 return;
4608 } 4644 }
4645 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4646 GNUNET_free_non_null (msg_ctx.path_history);
4647 return;
4648 }
4609 4649
4610 demultiplex_message (enc_msg, &msg_ctx); 4650 demultiplex_message (enc_msg, &msg_ctx);
4611 GNUNET_SERVER_receive_done (client, GNUNET_OK); 4651 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -4626,64 +4666,63 @@ handle_dht_control_message (void *cls, struct GNUNET_SERVER_Client *client,
4626 const struct GNUNET_MessageHeader *message) 4666 const struct GNUNET_MessageHeader *message)
4627{ 4667{
4628 const struct GNUNET_DHT_ControlMessage *dht_control_msg = 4668 const struct GNUNET_DHT_ControlMessage *dht_control_msg =
4629 (const struct GNUNET_DHT_ControlMessage *) message; 4669 (const struct GNUNET_DHT_ControlMessage *) message;
4630 4670
4631#if DEBUG_DHT 4671#if DEBUG_DHT
4632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4633 "`%s:%s': Received `%s' request from client, command %d\n", 4673 "`%s:%s': Received `%s' request from client, command %d\n",
4634 my_short_id, "DHT", "CONTROL", 4674 my_short_id, "DHT", "CONTROL", ntohs (dht_control_msg->command));
4635 ntohs (dht_control_msg->command));
4636#endif 4675#endif
4637 4676
4638 switch (ntohs (dht_control_msg->command)) 4677 switch (ntohs (dht_control_msg->command))
4639 { 4678 {
4640 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: 4679 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER:
4641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4642 "Sending self seeking find peer request!\n"); 4681 "Sending self seeking find peer request!\n");
4643 GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL); 4682 GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL);
4644 break; 4683 break;
4645#if HAVE_MALICIOUS 4684#if HAVE_MALICIOUS
4646 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET: 4685 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
4647 if (ntohs (dht_control_msg->variable) > 0) 4686 if (ntohs (dht_control_msg->variable) > 0)
4648 malicious_get_frequency = ntohs (dht_control_msg->variable); 4687 malicious_get_frequency = ntohs (dht_control_msg->variable);
4649 if (malicious_get_frequency == 0) 4688 if (malicious_get_frequency == 0)
4650 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; 4689 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
4651 if (malicious_getter != GNUNET_YES) 4690 if (malicious_getter != GNUNET_YES)
4652 GNUNET_SCHEDULER_add_now (&malicious_get_task, NULL); 4691 GNUNET_SCHEDULER_add_now (&malicious_get_task, NULL);
4653 malicious_getter = GNUNET_YES; 4692 malicious_getter = GNUNET_YES;
4654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4655 "%s:%s Initiating malicious GET behavior, frequency %d\n", 4694 "%s:%s Initiating malicious GET behavior, frequency %d\n",
4656 my_short_id, "DHT", malicious_get_frequency); 4695 my_short_id, "DHT", malicious_get_frequency);
4657 break; 4696 break;
4658 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT: 4697 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
4659 if (ntohs (dht_control_msg->variable) > 0) 4698 if (ntohs (dht_control_msg->variable) > 0)
4660 malicious_put_frequency = ntohs (dht_control_msg->variable); 4699 malicious_put_frequency = ntohs (dht_control_msg->variable);
4661 if (malicious_put_frequency == 0) 4700 if (malicious_put_frequency == 0)
4662 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; 4701 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
4663 if (malicious_putter != GNUNET_YES) 4702 if (malicious_putter != GNUNET_YES)
4664 GNUNET_SCHEDULER_add_now (&malicious_put_task, NULL); 4703 GNUNET_SCHEDULER_add_now (&malicious_put_task, NULL);
4665 malicious_putter = GNUNET_YES; 4704 malicious_putter = GNUNET_YES;
4666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4667 "%s:%s Initiating malicious PUT behavior, frequency %d\n", 4706 "%s:%s Initiating malicious PUT behavior, frequency %d\n",
4668 my_short_id, "DHT", malicious_put_frequency); 4707 my_short_id, "DHT", malicious_put_frequency);
4669 break; 4708 break;
4670 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP: 4709 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
4671#if DEBUG_DHT_ROUTING 4710#if DEBUG_DHT_ROUTING
4672 if ((malicious_dropper != GNUNET_YES) && (dhtlog_handle != NULL)) 4711 if ((malicious_dropper != GNUNET_YES) && (dhtlog_handle != NULL))
4673 dhtlog_handle->set_malicious (&my_identity); 4712 dhtlog_handle->set_malicious (&my_identity);
4674#endif 4713#endif
4675 malicious_dropper = GNUNET_YES; 4714 malicious_dropper = GNUNET_YES;
4676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4677 "%s:%s Initiating malicious DROP behavior\n", my_short_id, 4716 "%s:%s Initiating malicious DROP behavior\n", my_short_id,
4678 "DHT"); 4717 "DHT");
4679 break; 4718 break;
4680#endif 4719#endif
4681 default: 4720 default:
4682 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4721 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4683 "%s:%s Unknown control command type `%d'!\n", 4722 "%s:%s Unknown control command type `%d'!\n",
4684 my_short_id, "DHT", ntohs (dht_control_msg->command)); 4723 my_short_id, "DHT", ntohs (dht_control_msg->command));
4685 break; 4724 break;
4686 } 4725 }
4687 4726
4688 GNUNET_SERVER_receive_done (client, GNUNET_OK); 4727 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4689} 4728}
@@ -4703,9 +4742,10 @@ handle_dht_local_route_stop (void *cls, struct GNUNET_SERVER_Client *client,
4703{ 4742{
4704 4743
4705 const struct GNUNET_DHT_StopMessage *dht_stop_msg = 4744 const struct GNUNET_DHT_StopMessage *dht_stop_msg =
4706 (const struct GNUNET_DHT_StopMessage *) message; 4745 (const struct GNUNET_DHT_StopMessage *) message;
4707 struct DHTQueryRecord *record; 4746 struct DHTQueryRecord *record;
4708 struct DHTRouteSource *pos; 4747 struct DHTRouteSource *pos;
4748
4709#if DEBUG_DHT 4749#if DEBUG_DHT
4710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4711 "`%s:%s': Received `%s' request from client, uid %llu\n", 4751 "`%s:%s': Received `%s' request from client, uid %llu\n",
@@ -4713,24 +4753,25 @@ handle_dht_local_route_stop (void *cls, struct GNUNET_SERVER_Client *client,
4713 GNUNET_ntohll (dht_stop_msg->unique_id)); 4753 GNUNET_ntohll (dht_stop_msg->unique_id));
4714#endif 4754#endif
4715 record = 4755 record =
4716 GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, 4756 GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap,
4717 &dht_stop_msg->key); 4757 &dht_stop_msg->key);
4718 if (record != NULL) 4758 if (record != NULL)
4719 { 4759 {
4720 pos = record->head; 4760 pos = record->head;
4721 4761
4722 while (pos != NULL) 4762 while (pos != NULL)
4723 { 4763 {
4724 /* If the client is non-null (local request) and the client matches the requesting client, remove the entry. */ 4764 /* If the client is non-null (local request) and the client matches the requesting client, remove the entry. */
4725 if ((pos->client != NULL) && (pos->client->client_handle == client)) 4765 if ((pos->client != NULL) && (pos->client->client_handle == client))
4726 { 4766 {
4727 if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK) 4767 if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
4728 GNUNET_SCHEDULER_cancel (pos->delete_task); 4768 GNUNET_SCHEDULER_cancel (pos->delete_task);
4729 pos->delete_task = GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos); 4769 pos->delete_task =
4730 } 4770 GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos);
4731 pos = pos->next; 4771 }
4732 } 4772 pos = pos->next;
4733 } 4773 }
4774 }
4734 4775
4735 GNUNET_SERVER_receive_done (client, GNUNET_OK); 4776 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4736} 4777}
@@ -4758,99 +4799,103 @@ handle_dht_p2p_route_request (void *cls,
4758 "DHT", GNUNET_i2s (peer)); 4799 "DHT", GNUNET_i2s (peer));
4759#endif 4800#endif
4760 struct GNUNET_DHT_P2PRouteMessage *incoming = 4801 struct GNUNET_DHT_P2PRouteMessage *incoming =
4761 (struct GNUNET_DHT_P2PRouteMessage *) message; 4802 (struct GNUNET_DHT_P2PRouteMessage *) message;
4762 struct GNUNET_MessageHeader *enc_msg = 4803 struct GNUNET_MessageHeader *enc_msg =
4763 (struct GNUNET_MessageHeader *) &incoming[1]; 4804 (struct GNUNET_MessageHeader *) &incoming[1];
4764 struct DHT_MessageContext *msg_ctx; 4805 struct DHT_MessageContext *msg_ctx;
4765 char *route_path; 4806 char *route_path;
4766 int path_size; 4807 int path_size;
4767 4808
4768 if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_P2P_PING) /* Throw these away. FIXME: Don't throw these away? (reply) */ 4809 if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_P2P_PING) /* Throw these away. FIXME: Don't throw these away? (reply) */
4769 { 4810 {
4770#if DEBUG_PING 4811#if DEBUG_PING
4771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4772 "%s:%s Received P2P Ping message.\n", my_short_id, "DHT"); 4813 "%s:%s Received P2P Ping message.\n", my_short_id, "DHT");
4773#endif 4814#endif
4774 return GNUNET_YES; 4815 return GNUNET_YES;
4775 } 4816 }
4776 4817
4777 if (ntohs (enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1) 4818 if (ntohs (enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1)
4778 { 4819 {
4779 GNUNET_break_op (0); 4820 GNUNET_break_op (0);
4780 return GNUNET_YES; 4821 return GNUNET_YES;
4781 } 4822 }
4782 4823
4783 if (malicious_dropper == GNUNET_YES) 4824 if (malicious_dropper == GNUNET_YES)
4784 { 4825 {
4785#if DEBUG_DHT_ROUTING 4826#if DEBUG_DHT_ROUTING
4786 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4827 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4787 { 4828 {
4788 /** Log routes that die due to high load! */ 4829 /** Log routes that die due to high load! */
4789 dhtlog_handle->insert_route (NULL, 4830 dhtlog_handle->insert_route (NULL,
4790 GNUNET_ntohll (incoming->unique_id), 4831 GNUNET_ntohll (incoming->unique_id),
4791 DHTLOG_ROUTE, 4832 DHTLOG_ROUTE,
4792 ntohl (incoming->hop_count), 4833 ntohl (incoming->hop_count),
4793 GNUNET_SYSERR, &my_identity, 4834 GNUNET_SYSERR, &my_identity,
4794 &incoming->key, peer, NULL); 4835 &incoming->key, peer, NULL);
4795 }
4796#endif
4797 return GNUNET_YES;
4798 } 4836 }
4837#endif
4838 return GNUNET_YES;
4839 }
4799 4840
4800 if (get_max_send_delay ().rel_value > MAX_REQUEST_TIME.rel_value) 4841 if (get_max_send_delay ().rel_value > MAX_REQUEST_TIME.rel_value)
4801 { 4842 {
4802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4803 "Sending of previous replies took too long, backing off!\n"); 4844 "Sending of previous replies took too long, backing off!\n");
4804 increment_stats ("# route requests dropped due to high load"); 4845 increment_stats ("# route requests dropped due to high load");
4805 decrease_max_send_delay (get_max_send_delay ()); 4846 decrease_max_send_delay (get_max_send_delay ());
4806#if DEBUG_DHT_ROUTING 4847#if DEBUG_DHT_ROUTING
4807 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4848 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4808 { 4849 {
4809 /** Log routes that die due to high load! */ 4850 /** Log routes that die due to high load! */
4810 dhtlog_handle->insert_route (NULL, 4851 dhtlog_handle->insert_route (NULL,
4811 GNUNET_ntohll (incoming->unique_id), 4852 GNUNET_ntohll (incoming->unique_id),
4812 DHTLOG_ROUTE, 4853 DHTLOG_ROUTE,
4813 ntohl (incoming->hop_count), 4854 ntohl (incoming->hop_count),
4814 GNUNET_SYSERR, &my_identity, 4855 GNUNET_SYSERR, &my_identity,
4815 &incoming->key, peer, NULL); 4856 &incoming->key, peer, NULL);
4816 }
4817#endif
4818 return GNUNET_YES;
4819 } 4857 }
4858#endif
4859 return GNUNET_YES;
4860 }
4820 msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext)); 4861 msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext));
4821 msg_ctx->bloom = 4862 msg_ctx->bloom =
4822 GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE, 4863 GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE,
4823 DHT_BLOOM_K); 4864 DHT_BLOOM_K);
4824 GNUNET_assert (msg_ctx->bloom != NULL); 4865 GNUNET_assert (msg_ctx->bloom != NULL);
4825 msg_ctx->hop_count = ntohl (incoming->hop_count); 4866 msg_ctx->hop_count = ntohl (incoming->hop_count);
4826 memcpy (&msg_ctx->key, &incoming->key, sizeof (GNUNET_HashCode)); 4867 memcpy (&msg_ctx->key, &incoming->key, sizeof (GNUNET_HashCode));
4827 msg_ctx->replication = ntohl (incoming->desired_replication_level); 4868 msg_ctx->replication = ntohl (incoming->desired_replication_level);
4828 msg_ctx->unique_id = GNUNET_ntohll (incoming->unique_id); 4869 msg_ctx->unique_id = GNUNET_ntohll (incoming->unique_id);
4829 msg_ctx->msg_options = ntohl (incoming->options); 4870 msg_ctx->msg_options = ntohl (incoming->options);
4830 if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) 4871 if (GNUNET_DHT_RO_RECORD_ROUTE ==
4831 { 4872 (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
4832 path_size = ntohl(incoming->outgoing_path_length) * sizeof(struct GNUNET_PeerIdentity); 4873 {
4833 GNUNET_assert(ntohs(message->size) == 4874 path_size =
4834 (sizeof(struct GNUNET_DHT_P2PRouteMessage) + 4875 ntohl (incoming->outgoing_path_length) *
4835 ntohs(enc_msg->size) + 4876 sizeof (struct GNUNET_PeerIdentity);
4836 path_size)); 4877 GNUNET_assert (ntohs (message->size) ==
4837 route_path = (char *)&incoming[1]; 4878 (sizeof (struct GNUNET_DHT_P2PRouteMessage) +
4838 route_path = route_path + ntohs(enc_msg->size); 4879 ntohs (enc_msg->size) + path_size));
4839 msg_ctx->path_history = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity) + path_size); 4880 route_path = (char *) &incoming[1];
4840 memcpy(msg_ctx->path_history, route_path, path_size); 4881 route_path = route_path + ntohs (enc_msg->size);
4841 memcpy(&msg_ctx->path_history[path_size], &my_identity, sizeof(struct GNUNET_PeerIdentity)); 4882 msg_ctx->path_history =
4842 msg_ctx->path_history_len = ntohl(incoming->outgoing_path_length) + 1; 4883 GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) + path_size);
4843 } 4884 memcpy (msg_ctx->path_history, route_path, path_size);
4885 memcpy (&msg_ctx->path_history[path_size], &my_identity,
4886 sizeof (struct GNUNET_PeerIdentity));
4887 msg_ctx->path_history_len = ntohl (incoming->outgoing_path_length) + 1;
4888 }
4844 msg_ctx->network_size = ntohl (incoming->network_size); 4889 msg_ctx->network_size = ntohl (incoming->network_size);
4845 msg_ctx->peer = peer; 4890 msg_ctx->peer = peer;
4846 msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE; 4891 msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE;
4847 msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; 4892 msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
4848 demultiplex_message (enc_msg, msg_ctx); 4893 demultiplex_message (enc_msg, msg_ctx);
4849 if (msg_ctx->bloom != NULL) 4894 if (msg_ctx->bloom != NULL)
4850 { 4895 {
4851 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom); 4896 GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
4852 msg_ctx->bloom = NULL; 4897 msg_ctx->bloom = NULL;
4853 } 4898 }
4854 GNUNET_free (msg_ctx); 4899 GNUNET_free (msg_ctx);
4855 return GNUNET_YES; 4900 return GNUNET_YES;
4856} 4901}
@@ -4878,36 +4923,37 @@ handle_dht_p2p_route_result (void *cls,
4878 GNUNET_i2s (peer)); 4923 GNUNET_i2s (peer));
4879#endif 4924#endif
4880 struct GNUNET_DHT_P2PRouteResultMessage *incoming = 4925 struct GNUNET_DHT_P2PRouteResultMessage *incoming =
4881 (struct GNUNET_DHT_P2PRouteResultMessage *) message; 4926 (struct GNUNET_DHT_P2PRouteResultMessage *) message;
4882 struct GNUNET_MessageHeader *enc_msg = 4927 struct GNUNET_MessageHeader *enc_msg =
4883 (struct GNUNET_MessageHeader *) &incoming[1]; 4928 (struct GNUNET_MessageHeader *) &incoming[1];
4884 struct DHT_MessageContext msg_ctx; 4929 struct DHT_MessageContext msg_ctx;
4930
4885#if DEBUG_PATH 4931#if DEBUG_PATH
4886 char *path_offset; 4932 char *path_offset;
4887 unsigned int i; 4933 unsigned int i;
4888#endif 4934#endif
4889 if (ntohs (enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1) 4935 if (ntohs (enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1)
4890 { 4936 {
4891 GNUNET_break_op (0); 4937 GNUNET_break_op (0);
4892 return GNUNET_YES; 4938 return GNUNET_YES;
4893 } 4939 }
4894 4940
4895 if (malicious_dropper == GNUNET_YES) 4941 if (malicious_dropper == GNUNET_YES)
4896 { 4942 {
4897#if DEBUG_DHT_ROUTING 4943#if DEBUG_DHT_ROUTING
4898 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4944 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4899 { 4945 {
4900 /** Log routes that die due to high load! */ 4946 /** Log routes that die due to high load! */
4901 dhtlog_handle->insert_route (NULL, 4947 dhtlog_handle->insert_route (NULL,
4902 GNUNET_ntohll (incoming->unique_id), 4948 GNUNET_ntohll (incoming->unique_id),
4903 DHTLOG_ROUTE, 4949 DHTLOG_ROUTE,
4904 ntohl (incoming->hop_count), 4950 ntohl (incoming->hop_count),
4905 GNUNET_SYSERR, &my_identity, 4951 GNUNET_SYSERR, &my_identity,
4906 &incoming->key, peer, NULL); 4952 &incoming->key, peer, NULL);
4907 }
4908#endif
4909 return GNUNET_YES;
4910 } 4953 }
4954#endif
4955 return GNUNET_YES;
4956 }
4911 4957
4912 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 4958 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
4913 // FIXME: call GNUNET_BLOCK_evaluate (...) -- instead of doing your own bloomfilter! 4959 // FIXME: call GNUNET_BLOCK_evaluate (...) -- instead of doing your own bloomfilter!
@@ -4918,40 +4964,48 @@ handle_dht_p2p_route_result (void *cls,
4918 msg_ctx.peer = peer; 4964 msg_ctx.peer = peer;
4919 msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result routing a higher priority */ 4965 msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result routing a higher priority */
4920 msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT; 4966 msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT;
4921 if ((GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx.msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) && (ntohl (incoming->outgoing_path_length) > 0)) 4967 if ((GNUNET_DHT_RO_RECORD_ROUTE ==
4968 (msg_ctx.msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) &&
4969 (ntohl (incoming->outgoing_path_length) > 0))
4970 {
4971 if (ntohs (message->size) -
4972 sizeof (struct GNUNET_DHT_P2PRouteResultMessage) -
4973 ntohs (enc_msg->size) !=
4974 ntohl (incoming->outgoing_path_length) *
4975 sizeof (struct GNUNET_PeerIdentity))
4922 { 4976 {
4923 if (ntohs(message->size) - sizeof(struct GNUNET_DHT_P2PRouteResultMessage) - ntohs(enc_msg->size) !=
4924 ntohl (incoming->outgoing_path_length) * sizeof(struct GNUNET_PeerIdentity))
4925 {
4926#if DEBUG_DHT 4977#if DEBUG_DHT
4927 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4928 "Return message indicated a path was included, but sizes are wrong: Total size %d, enc size %d, left %d, expected %d\n", 4979 "Return message indicated a path was included, but sizes are wrong: Total size %d, enc size %d, left %d, expected %d\n",
4929 ntohs(message->size), 4980 ntohs (message->size),
4930 ntohs(enc_msg->size), 4981 ntohs (enc_msg->size),
4931 ntohs(message->size) - sizeof(struct GNUNET_DHT_P2PRouteResultMessage) - ntohs(enc_msg->size), 4982 ntohs (message->size) -
4932 ntohl(incoming->outgoing_path_length) * sizeof(struct GNUNET_PeerIdentity)); 4983 sizeof (struct GNUNET_DHT_P2PRouteResultMessage) -
4984 ntohs (enc_msg->size),
4985 ntohl (incoming->outgoing_path_length) *
4986 sizeof (struct GNUNET_PeerIdentity));
4933#endif 4987#endif
4934 GNUNET_break_op (0); 4988 GNUNET_break_op (0);
4935 return GNUNET_NO; 4989 return GNUNET_NO;
4936 } 4990 }
4937 msg_ctx.path_history = (char *)&incoming[1]; 4991 msg_ctx.path_history = (char *) &incoming[1];
4938 msg_ctx.path_history += ntohs(enc_msg->size); 4992 msg_ctx.path_history += ntohs (enc_msg->size);
4939 msg_ctx.path_history_len = ntohl (incoming->outgoing_path_length); 4993 msg_ctx.path_history_len = ntohl (incoming->outgoing_path_length);
4940#if DEBUG_PATH 4994#if DEBUG_PATH
4941 for (i = 0; i < msg_ctx.path_history_len; i++) 4995 for (i = 0; i < msg_ctx.path_history_len; i++)
4942 { 4996 {
4943 path_offset = &msg_ctx.path_history[i * sizeof(struct GNUNET_PeerIdentity)]; 4997 path_offset =
4944 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4998 &msg_ctx.path_history[i * sizeof (struct GNUNET_PeerIdentity)];
4945 "(handle_p2p_route_result) Key %s Found peer %d:%s\n", 4999 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4946 GNUNET_h2s(&msg_ctx.key), 5000 "(handle_p2p_route_result) Key %s Found peer %d:%s\n",
4947 i, 5001 GNUNET_h2s (&msg_ctx.key), i,
4948 GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset)); 5002 GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
4949 }
4950#endif
4951 } 5003 }
5004#endif
5005 }
4952 msg_ctx.bloom = 5006 msg_ctx.bloom =
4953 GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE, 5007 GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE,
4954 DHT_BLOOM_K); 5008 DHT_BLOOM_K);
4955 GNUNET_assert (msg_ctx.bloom != NULL); 5009 GNUNET_assert (msg_ctx.bloom != NULL);
4956 route_result_message (enc_msg, &msg_ctx); 5010 route_result_message (enc_msg, &msg_ctx);
4957 return GNUNET_YES; 5011 return GNUNET_YES;
@@ -4993,59 +5047,57 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4993 struct PeerInfo *pos; 5047 struct PeerInfo *pos;
4994 5048
4995 if (transport_handle != NULL) 5049 if (transport_handle != NULL)
4996 { 5050 {
4997 GNUNET_free_non_null (my_hello); 5051 GNUNET_free_non_null (my_hello);
4998 GNUNET_TRANSPORT_get_hello_cancel (transport_handle, &process_hello, 5052 GNUNET_TRANSPORT_get_hello_cancel (transport_handle, &process_hello, NULL);
4999 NULL); 5053 GNUNET_TRANSPORT_disconnect (transport_handle);
5000 GNUNET_TRANSPORT_disconnect (transport_handle); 5054 }
5001 }
5002 if (coreAPI != NULL) 5055 if (coreAPI != NULL)
5003 { 5056 {
5004#if DEBUG_DHT 5057#if DEBUG_DHT
5005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5006 "%s:%s Disconnecting core!\n", my_short_id, "DHT"); 5059 "%s:%s Disconnecting core!\n", my_short_id, "DHT");
5007#endif 5060#endif
5008 GNUNET_CORE_disconnect (coreAPI); 5061 GNUNET_CORE_disconnect (coreAPI);
5009 coreAPI = NULL; 5062 coreAPI = NULL;
5010 } 5063 }
5011 for (bucket_count = lowest_bucket; bucket_count < MAX_BUCKETS; 5064 for (bucket_count = lowest_bucket; bucket_count < MAX_BUCKETS; bucket_count++)
5012 bucket_count++) 5065 {
5013 { 5066 while (k_buckets[bucket_count].head != NULL)
5014 while (k_buckets[bucket_count].head != NULL) 5067 {
5015 { 5068 pos = k_buckets[bucket_count].head;
5016 pos = k_buckets[bucket_count].head;
5017#if DEBUG_DHT 5069#if DEBUG_DHT
5018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5019 "%s:%s Removing peer %s from bucket %d!\n", my_short_id, 5071 "%s:%s Removing peer %s from bucket %d!\n", my_short_id,
5020 "DHT", GNUNET_i2s (&pos->id), bucket_count); 5072 "DHT", GNUNET_i2s (&pos->id), bucket_count);
5021#endif 5073#endif
5022 delete_peer (pos, bucket_count); 5074 delete_peer (pos, bucket_count);
5023 }
5024 } 5075 }
5076 }
5025 if (datacache != NULL) 5077 if (datacache != NULL)
5026 { 5078 {
5027#if DEBUG_DHT 5079#if DEBUG_DHT
5028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5029 "%s:%s Destroying datacache!\n", my_short_id, "DHT"); 5081 "%s:%s Destroying datacache!\n", my_short_id, "DHT");
5030#endif 5082#endif
5031 GNUNET_DATACACHE_destroy (datacache); 5083 GNUNET_DATACACHE_destroy (datacache);
5032 datacache = NULL; 5084 datacache = NULL;
5033 } 5085 }
5034 if (stats != NULL) 5086 if (stats != NULL)
5035 { 5087 {
5036 GNUNET_STATISTICS_destroy (stats, GNUNET_YES); 5088 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
5037 stats = NULL; 5089 stats = NULL;
5038 } 5090 }
5039 if (dhtlog_handle != NULL) 5091 if (dhtlog_handle != NULL)
5040 { 5092 {
5041 GNUNET_DHTLOG_disconnect (dhtlog_handle); 5093 GNUNET_DHTLOG_disconnect (dhtlog_handle);
5042 dhtlog_handle = NULL; 5094 dhtlog_handle = NULL;
5043 } 5095 }
5044 if (block_context != NULL) 5096 if (block_context != NULL)
5045 { 5097 {
5046 GNUNET_BLOCK_context_destroy (block_context); 5098 GNUNET_BLOCK_context_destroy (block_context);
5047 block_context = NULL; 5099 block_context = NULL;
5048 } 5100 }
5049 GNUNET_free_non_null (my_short_id); 5101 GNUNET_free_non_null (my_short_id);
5050 my_short_id = NULL; 5102 my_short_id = NULL;
5051} 5103}
@@ -5067,16 +5119,16 @@ core_init (void *cls,
5067{ 5119{
5068 5120
5069 if (server == NULL) 5121 if (server == NULL)
5070 { 5122 {
5071#if DEBUG_DHT 5123#if DEBUG_DHT
5072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5073 "%s: Connection to core FAILED!\n", "dht", 5125 "%s: Connection to core FAILED!\n", "dht",
5074 GNUNET_i2s (identity)); 5126 GNUNET_i2s (identity));
5075#endif 5127#endif
5076 GNUNET_SCHEDULER_cancel (cleanup_task); 5128 GNUNET_SCHEDULER_cancel (cleanup_task);
5077 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 5129 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
5078 return; 5130 return;
5079 } 5131 }
5080#if DEBUG_DHT 5132#if DEBUG_DHT
5081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5082 "%s: Core connection initialized, I am peer: %s\n", "dht", 5134 "%s: Core connection initialized, I am peer: %s\n", "dht",
@@ -5132,7 +5184,7 @@ handle_core_connect (void *cls,
5132 int peer_bucket; 5184 int peer_bucket;
5133 5185
5134 /* Check for connect to self message */ 5186 /* Check for connect to self message */
5135 if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) 5187 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
5136 return; 5188 return;
5137 5189
5138#if DEBUG_DHT 5190#if DEBUG_DHT
@@ -5144,30 +5196,34 @@ handle_core_connect (void *cls,
5144 if (GNUNET_YES == 5196 if (GNUNET_YES ==
5145 GNUNET_CONTAINER_multihashmap_contains (all_known_peers, 5197 GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
5146 &peer->hashPubKey)) 5198 &peer->hashPubKey))
5147 { 5199 {
5148#if DEBUG_DHT 5200#if DEBUG_DHT
5149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5150 "%s:%s Received %s message for peer %s, but already have peer in RT!", 5202 "%s:%s Received %s message for peer %s, but already have peer in RT!",
5151 my_short_id, "DHT", "CORE CONNECT", GNUNET_i2s (peer)); 5203 my_short_id, "DHT", "CORE CONNECT", GNUNET_i2s (peer));
5152#endif 5204#endif
5153 GNUNET_break (0); 5205 GNUNET_break (0);
5154 return; 5206 return;
5155 } 5207 }
5156 5208
5157 if ((datacache != NULL) && (GNUNET_YES == put_peer_identities)) 5209 if ((datacache != NULL) && (GNUNET_YES == put_peer_identities))
5158 { 5210 {
5159 put_entry = GNUNET_malloc(sizeof(struct DHTPutEntry) + sizeof (struct GNUNET_PeerIdentity)); 5211 put_entry =
5160 put_entry->path_length = 0; 5212 GNUNET_malloc (sizeof (struct DHTPutEntry) +
5161 put_entry->data_size = sizeof (struct GNUNET_PeerIdentity); 5213 sizeof (struct GNUNET_PeerIdentity));
5162 memcpy(&put_entry[1], peer, sizeof (struct GNUNET_PeerIdentity)); 5214 put_entry->path_length = 0;
5163 GNUNET_DATACACHE_put (datacache, &peer->hashPubKey, 5215 put_entry->data_size = sizeof (struct GNUNET_PeerIdentity);
5164 sizeof(struct DHTPutEntry) + sizeof (struct GNUNET_PeerIdentity), 5216 memcpy (&put_entry[1], peer, sizeof (struct GNUNET_PeerIdentity));
5165 (char *)put_entry, GNUNET_BLOCK_TYPE_DHT_HELLO, 5217 GNUNET_DATACACHE_put (datacache, &peer->hashPubKey,
5166 GNUNET_TIME_absolute_get_forever ()); 5218 sizeof (struct DHTPutEntry) +
5167 GNUNET_free (put_entry); 5219 sizeof (struct GNUNET_PeerIdentity),
5168 } 5220 (char *) put_entry, GNUNET_BLOCK_TYPE_DHT_HELLO,
5221 GNUNET_TIME_absolute_get_forever ());
5222 GNUNET_free (put_entry);
5223 }
5169 else if (datacache == NULL) 5224 else if (datacache == NULL)
5170 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DHT has no connection to datacache!\n"); 5225 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5226 "DHT has no connection to datacache!\n");
5171 5227
5172 peer_bucket = find_current_bucket (&peer->hashPubKey); 5228 peer_bucket = find_current_bucket (&peer->hashPubKey);
5173 GNUNET_assert (peer_bucket >= lowest_bucket); 5229 GNUNET_assert (peer_bucket >= lowest_bucket);
@@ -5180,15 +5236,14 @@ handle_core_connect (void *cls,
5180 ret->id = *peer; 5236 ret->id = *peer;
5181 GNUNET_CONTAINER_DLL_insert_after (k_buckets[peer_bucket].head, 5237 GNUNET_CONTAINER_DLL_insert_after (k_buckets[peer_bucket].head,
5182 k_buckets[peer_bucket].tail, 5238 k_buckets[peer_bucket].tail,
5183 k_buckets[peer_bucket].tail, 5239 k_buckets[peer_bucket].tail, ret);
5184 ret);
5185 k_buckets[peer_bucket].peers_size++; 5240 k_buckets[peer_bucket].peers_size++;
5186#if DO_UPDATE_PREFERENCE 5241#if DO_UPDATE_PREFERENCE
5187 if ( (GNUNET_CRYPTO_hash_matching_bits 5242 if ((GNUNET_CRYPTO_hash_matching_bits
5188 (&my_identity.hashPubKey, &peer->hashPubKey) > 0) && 5243 (&my_identity.hashPubKey, &peer->hashPubKey) > 0) &&
5189 (k_buckets[peer_bucket].peers_size <= bucket_size) ) 5244 (k_buckets[peer_bucket].peers_size <= bucket_size))
5190 ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, 5245 ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference,
5191 ret); 5246 ret);
5192#endif 5247#endif
5193 if ((k_buckets[lowest_bucket].peers_size) >= bucket_size) 5248 if ((k_buckets[lowest_bucket].peers_size) >= bucket_size)
5194 enable_next_bucket (); 5249 enable_next_bucket ();
@@ -5197,9 +5252,9 @@ handle_core_connect (void *cls,
5197#endif 5252#endif
5198 newly_found_peers++; 5253 newly_found_peers++;
5199 GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey, 5254 GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey,
5200 ret, 5255 ret,
5201 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 5256 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
5202 increment_stats (STAT_PEERS_KNOWN); 5257 increment_stats (STAT_PEERS_KNOWN);
5203 5258
5204#if DEBUG_DHT 5259#if DEBUG_DHT
5205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5222,7 +5277,7 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
5222 int current_bucket; 5277 int current_bucket;
5223 5278
5224 /* Check for disconnect from self message */ 5279 /* Check for disconnect from self message */
5225 if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) 5280 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
5226 return; 5281 return;
5227#if DEBUG_DHT 5282#if DEBUG_DHT
5228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5233,26 +5288,26 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
5233 if (GNUNET_YES != 5288 if (GNUNET_YES !=
5234 GNUNET_CONTAINER_multihashmap_contains (all_known_peers, 5289 GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
5235 &peer->hashPubKey)) 5290 &peer->hashPubKey))
5236 { 5291 {
5237 GNUNET_break (0); 5292 GNUNET_break (0);
5238#if DEBUG_DHT 5293#if DEBUG_DHT
5239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5240 "%s:%s: do not have peer `%s' in RT, can't disconnect!\n", 5295 "%s:%s: do not have peer `%s' in RT, can't disconnect!\n",
5241 my_short_id, "DHT", GNUNET_i2s (peer)); 5296 my_short_id, "DHT", GNUNET_i2s (peer));
5242#endif 5297#endif
5243 return; 5298 return;
5244 } 5299 }
5245 increment_stats (STAT_DISCONNECTS); 5300 increment_stats (STAT_DISCONNECTS);
5246 GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains 5301 GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains
5247 (all_known_peers, &peer->hashPubKey)); 5302 (all_known_peers, &peer->hashPubKey));
5248 to_remove = 5303 to_remove =
5249 GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey); 5304 GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey);
5250 GNUNET_assert (to_remove != NULL); 5305 GNUNET_assert (to_remove != NULL);
5251 if (NULL != to_remove->info_ctx) 5306 if (NULL != to_remove->info_ctx)
5252 { 5307 {
5253 GNUNET_CORE_peer_change_preference_cancel (to_remove->info_ctx); 5308 GNUNET_CORE_peer_change_preference_cancel (to_remove->info_ctx);
5254 to_remove->info_ctx = NULL; 5309 to_remove->info_ctx = NULL;
5255 } 5310 }
5256 GNUNET_assert (0 == 5311 GNUNET_assert (0 ==
5257 memcmp (peer, &to_remove->id, 5312 memcmp (peer, &to_remove->id,
5258 sizeof (struct GNUNET_PeerIdentity))); 5313 sizeof (struct GNUNET_PeerIdentity)));
@@ -5306,101 +5361,101 @@ run (void *cls,
5306 block_context = GNUNET_BLOCK_context_create (cfg); 5361 block_context = GNUNET_BLOCK_context_create (cfg);
5307 lowest_bucket = MAX_BUCKETS - 1; 5362 lowest_bucket = MAX_BUCKETS - 1;
5308 forward_list.hashmap = 5363 forward_list.hashmap =
5309 GNUNET_CONTAINER_multihashmap_create (MAX_OUTSTANDING_FORWARDS / 10); 5364 GNUNET_CONTAINER_multihashmap_create (MAX_OUTSTANDING_FORWARDS / 10);
5310 forward_list.minHeap = 5365 forward_list.minHeap =
5311 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 5366 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
5312 all_known_peers = GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8); 5367 all_known_peers = GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8);
5313 recent_find_peer_requests = 5368 recent_find_peer_requests =
5314 GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8); 5369 GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8);
5315 GNUNET_assert (all_known_peers != NULL); 5370 GNUNET_assert (all_known_peers != NULL);
5316 if (GNUNET_YES == 5371 if (GNUNET_YES ==
5317 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 5372 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
5318 "mysql_logging")) 5373 "mysql_logging"))
5319 { 5374 {
5320 debug_routes = GNUNET_YES; 5375 debug_routes = GNUNET_YES;
5321 } 5376 }
5322 5377
5323 if (GNUNET_YES == 5378 if (GNUNET_YES ==
5324 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "strict_kademlia")) 5379 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "strict_kademlia"))
5325 { 5380 {
5326 strict_kademlia = GNUNET_YES; 5381 strict_kademlia = GNUNET_YES;
5327 } 5382 }
5328 5383
5329 if (GNUNET_YES == 5384 if (GNUNET_YES ==
5330 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "stop_on_closest")) 5385 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "stop_on_closest"))
5331 { 5386 {
5332 stop_on_closest = GNUNET_YES; 5387 stop_on_closest = GNUNET_YES;
5333 } 5388 }
5334 5389
5335 if (GNUNET_YES == 5390 if (GNUNET_YES ==
5336 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "stop_found")) 5391 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "stop_found"))
5337 { 5392 {
5338 stop_on_found = GNUNET_YES; 5393 stop_on_found = GNUNET_YES;
5339 } 5394 }
5340 5395
5341 if (GNUNET_YES == 5396 if (GNUNET_YES ==
5342 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_getter")) 5397 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_getter"))
5343 { 5398 {
5344 malicious_getter = GNUNET_YES; 5399 malicious_getter = GNUNET_YES;
5345 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5400 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
5346 "MALICIOUS_GET_FREQUENCY", 5401 "MALICIOUS_GET_FREQUENCY",
5347 &malicious_get_frequency)) 5402 &malicious_get_frequency))
5348 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; 5403 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
5349 } 5404 }
5350 5405
5351 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5406 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
5352 "MAX_HOPS", 5407 "MAX_HOPS",
5353 &max_hops)) 5408 &max_hops))
5354 { 5409 {
5355 max_hops = DEFAULT_MAX_HOPS; 5410 max_hops = DEFAULT_MAX_HOPS;
5356 } 5411 }
5357 5412
5358 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", 5413 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT",
5359 "USE_MAX_HOPS")) 5414 "USE_MAX_HOPS"))
5360 { 5415 {
5361 use_max_hops = GNUNET_YES; 5416 use_max_hops = GNUNET_YES;
5362 } 5417 }
5363 5418
5364 if (GNUNET_YES == 5419 if (GNUNET_YES ==
5365 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_putter")) 5420 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_putter"))
5366 { 5421 {
5367 malicious_putter = GNUNET_YES; 5422 malicious_putter = GNUNET_YES;
5368 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5423 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
5369 "MALICIOUS_PUT_FREQUENCY", 5424 "MALICIOUS_PUT_FREQUENCY",
5370 &malicious_put_frequency)) 5425 &malicious_put_frequency))
5371 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; 5426 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
5372 } 5427 }
5373 5428
5374 dht_republish_frequency = GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY; 5429 dht_republish_frequency = GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY;
5375 if (GNUNET_OK == 5430 if (GNUNET_OK ==
5376 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5431 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
5377 "REPLICATION_FREQUENCY", 5432 "REPLICATION_FREQUENCY",
5378 &temp_config_num)) 5433 &temp_config_num))
5379 { 5434 {
5380 dht_republish_frequency = 5435 dht_republish_frequency =
5381 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5436 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES,
5382 temp_config_num); 5437 temp_config_num);
5383 } 5438 }
5384 5439
5385 if (GNUNET_OK == 5440 if (GNUNET_OK ==
5386 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "bucket_size", 5441 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "bucket_size",
5387 &temp_config_num)) 5442 &temp_config_num))
5388 { 5443 {
5389 bucket_size = (unsigned int) temp_config_num; 5444 bucket_size = (unsigned int) temp_config_num;
5390 } 5445 }
5391 5446
5392 if (GNUNET_OK != 5447 if (GNUNET_OK !=
5393 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "kad_alpha", 5448 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "kad_alpha",
5394 &kademlia_replication)) 5449 &kademlia_replication))
5395 { 5450 {
5396 kademlia_replication = DEFAULT_KADEMLIA_REPLICATION; 5451 kademlia_replication = DEFAULT_KADEMLIA_REPLICATION;
5397 } 5452 }
5398 5453
5399 if (GNUNET_YES == 5454 if (GNUNET_YES ==
5400 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_dropper")) 5455 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_dropper"))
5401 { 5456 {
5402 malicious_dropper = GNUNET_YES; 5457 malicious_dropper = GNUNET_YES;
5403 } 5458 }
5404 5459
5405 if (GNUNET_YES == 5460 if (GNUNET_YES ==
5406 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "republish")) 5461 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "republish"))
@@ -5408,9 +5463,9 @@ run (void *cls,
5408 5463
5409 if (GNUNET_NO == 5464 if (GNUNET_NO ==
5410 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "do_find_peer")) 5465 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "do_find_peer"))
5411 { 5466 {
5412 do_find_peer = GNUNET_NO; 5467 do_find_peer = GNUNET_NO;
5413 } 5468 }
5414 else 5469 else
5415 do_find_peer = GNUNET_YES; 5470 do_find_peer = GNUNET_YES;
5416 5471
@@ -5421,113 +5476,109 @@ run (void *cls,
5421 if (GNUNET_YES == 5476 if (GNUNET_YES ==
5422 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 5477 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
5423 "mysql_logging_extended")) 5478 "mysql_logging_extended"))
5424 { 5479 {
5425 debug_routes = GNUNET_YES; 5480 debug_routes = GNUNET_YES;
5426 debug_routes_extended = GNUNET_YES; 5481 debug_routes_extended = GNUNET_YES;
5427 } 5482 }
5428 5483
5429#if DEBUG_DHT_ROUTING 5484#if DEBUG_DHT_ROUTING
5430 if (GNUNET_YES == debug_routes) 5485 if (GNUNET_YES == debug_routes)
5486 {
5487 dhtlog_handle = GNUNET_DHTLOG_connect (cfg);
5488 if (dhtlog_handle == NULL)
5431 { 5489 {
5432 dhtlog_handle = GNUNET_DHTLOG_connect (cfg); 5490 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5433 if (dhtlog_handle == NULL) 5491 "Could not connect to mysql logging server, logging will not happen!");
5434 {
5435 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5436 "Could not connect to mysql logging server, logging will not happen!");
5437 }
5438 } 5492 }
5493 }
5439#endif 5494#endif
5440 5495
5441 converge_option = DHT_CONVERGE_BINARY; 5496 converge_option = DHT_CONVERGE_BINARY;
5442 if (GNUNET_YES == 5497 if (GNUNET_YES ==
5443 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "converge_linear")) 5498 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "converge_linear"))
5444 { 5499 {
5445 converge_option = DHT_CONVERGE_LINEAR; 5500 converge_option = DHT_CONVERGE_LINEAR;
5446 } 5501 }
5447 else if (GNUNET_YES == 5502 else if (GNUNET_YES ==
5448 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 5503 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
5449 "converge_exponential")) 5504 "converge_exponential"))
5450 { 5505 {
5451 converge_option = DHT_CONVERGE_EXPONENTIAL; 5506 converge_option = DHT_CONVERGE_EXPONENTIAL;
5452 } 5507 }
5453 else if (GNUNET_YES == 5508 else if (GNUNET_YES ==
5454 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 5509 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "converge_random"))
5455 "converge_random")) 5510 {
5456 { 5511 converge_option = DHT_CONVERGE_RANDOM;
5457 converge_option = DHT_CONVERGE_RANDOM; 5512 }
5458 }
5459 else if (GNUNET_YES == 5513 else if (GNUNET_YES ==
5460 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 5514 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "converge_binary"))
5461 "converge_binary")) 5515 {
5462 { 5516 converge_option = DHT_CONVERGE_BINARY;
5463 converge_option = DHT_CONVERGE_BINARY; 5517 }
5464 }
5465 5518
5466 converge_modifier = 4.0; 5519 converge_modifier = 4.0;
5467 if (GNUNET_OK == 5520 if (GNUNET_OK ==
5468 GNUNET_CONFIGURATION_get_value_string (cfg, "dht", "converge_modifier", 5521 GNUNET_CONFIGURATION_get_value_string (cfg, "dht", "converge_modifier",
5469 &converge_modifier_buf)) 5522 &converge_modifier_buf))
5523 {
5524 if (1 != sscanf (converge_modifier_buf, "%f", &converge_modifier))
5470 { 5525 {
5471 if (1 != sscanf (converge_modifier_buf, "%f", &converge_modifier)) 5526 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5472 { 5527 "Failed to read decimal value for %s from `%s'\n",
5473 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 5528 "CONVERGE_MODIFIER", converge_modifier_buf);
5474 "Failed to read decimal value for %s from `%s'\n", 5529 converge_modifier = 0.0;
5475 "CONVERGE_MODIFIER", converge_modifier_buf);
5476 converge_modifier = 0.0;
5477 }
5478 GNUNET_free (converge_modifier_buf);
5479 } 5530 }
5531 GNUNET_free (converge_modifier_buf);
5532 }
5480 5533
5481 if (GNUNET_YES == 5534 if (GNUNET_YES ==
5482 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "paper_forwarding")) 5535 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "paper_forwarding"))
5483 paper_forwarding = GNUNET_YES; 5536 paper_forwarding = GNUNET_YES;
5484 5537
5485 if (GNUNET_YES == 5538 if (GNUNET_YES ==
5486 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "put_peer_identities")) 5539 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "put_peer_identities"))
5487 put_peer_identities = GNUNET_YES; 5540 put_peer_identities = GNUNET_YES;
5488 5541
5489 stats = GNUNET_STATISTICS_create ("dht", cfg); 5542 stats = GNUNET_STATISTICS_create ("dht", cfg);
5490 5543
5491 if (stats != NULL) 5544 if (stats != NULL)
5492 { 5545 {
5493 GNUNET_STATISTICS_set (stats, STAT_ROUTES, 0, GNUNET_NO); 5546 GNUNET_STATISTICS_set (stats, STAT_ROUTES, 0, GNUNET_NO);
5494 GNUNET_STATISTICS_set (stats, STAT_ROUTE_FORWARDS, 0, GNUNET_NO); 5547 GNUNET_STATISTICS_set (stats, STAT_ROUTE_FORWARDS, 0, GNUNET_NO);
5495 GNUNET_STATISTICS_set (stats, STAT_ROUTE_FORWARDS_CLOSEST, 0, 5548 GNUNET_STATISTICS_set (stats, STAT_ROUTE_FORWARDS_CLOSEST, 0, GNUNET_NO);
5496 GNUNET_NO); 5549 GNUNET_STATISTICS_set (stats, STAT_RESULTS, 0, GNUNET_NO);
5497 GNUNET_STATISTICS_set (stats, STAT_RESULTS, 0, GNUNET_NO); 5550 GNUNET_STATISTICS_set (stats, STAT_RESULTS_TO_CLIENT, 0, GNUNET_NO);
5498 GNUNET_STATISTICS_set (stats, STAT_RESULTS_TO_CLIENT, 0, GNUNET_NO); 5551 GNUNET_STATISTICS_set (stats, STAT_RESULT_FORWARDS, 0, GNUNET_NO);
5499 GNUNET_STATISTICS_set (stats, STAT_RESULT_FORWARDS, 0, GNUNET_NO); 5552 GNUNET_STATISTICS_set (stats, STAT_GETS, 0, GNUNET_NO);
5500 GNUNET_STATISTICS_set (stats, STAT_GETS, 0, GNUNET_NO); 5553 GNUNET_STATISTICS_set (stats, STAT_PUTS, 0, GNUNET_NO);
5501 GNUNET_STATISTICS_set (stats, STAT_PUTS, 0, GNUNET_NO); 5554 GNUNET_STATISTICS_set (stats, STAT_PUTS_INSERTED, 0, GNUNET_NO);
5502 GNUNET_STATISTICS_set (stats, STAT_PUTS_INSERTED, 0, GNUNET_NO); 5555 GNUNET_STATISTICS_set (stats, STAT_FIND_PEER, 0, GNUNET_NO);
5503 GNUNET_STATISTICS_set (stats, STAT_FIND_PEER, 0, GNUNET_NO); 5556 GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_START, 0, GNUNET_NO);
5504 GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_START, 0, GNUNET_NO); 5557 GNUNET_STATISTICS_set (stats, STAT_GET_START, 0, GNUNET_NO);
5505 GNUNET_STATISTICS_set (stats, STAT_GET_START, 0, GNUNET_NO); 5558 GNUNET_STATISTICS_set (stats, STAT_PUT_START, 0, GNUNET_NO);
5506 GNUNET_STATISTICS_set (stats, STAT_PUT_START, 0, GNUNET_NO); 5559 GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_REPLY, 0, GNUNET_NO);
5507 GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_REPLY, 0, GNUNET_NO); 5560 GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_ANSWER, 0, GNUNET_NO);
5508 GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_ANSWER, 0, GNUNET_NO); 5561 GNUNET_STATISTICS_set (stats, STAT_BLOOM_FIND_PEER, 0, GNUNET_NO);
5509 GNUNET_STATISTICS_set (stats, STAT_BLOOM_FIND_PEER, 0, GNUNET_NO); 5562 GNUNET_STATISTICS_set (stats, STAT_GET_REPLY, 0, GNUNET_NO);
5510 GNUNET_STATISTICS_set (stats, STAT_GET_REPLY, 0, GNUNET_NO); 5563 GNUNET_STATISTICS_set (stats, STAT_GET_RESPONSE_START, 0, GNUNET_NO);
5511 GNUNET_STATISTICS_set (stats, STAT_GET_RESPONSE_START, 0, GNUNET_NO); 5564 GNUNET_STATISTICS_set (stats, STAT_HELLOS_PROVIDED, 0, GNUNET_NO);
5512 GNUNET_STATISTICS_set (stats, STAT_HELLOS_PROVIDED, 0, GNUNET_NO); 5565 GNUNET_STATISTICS_set (stats, STAT_DISCONNECTS, 0, GNUNET_NO);
5513 GNUNET_STATISTICS_set (stats, STAT_DISCONNECTS, 0, GNUNET_NO); 5566 }
5514 }
5515 /* FIXME: if there are no recent requests then these never get freed, but alternative is _annoying_! */ 5567 /* FIXME: if there are no recent requests then these never get freed, but alternative is _annoying_! */
5516 recent.hashmap = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT / 2); 5568 recent.hashmap = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT / 2);
5517 recent.minHeap = 5569 recent.minHeap =
5518 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 5570 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
5519 if (GNUNET_YES == do_find_peer) 5571 if (GNUNET_YES == do_find_peer)
5520 { 5572 {
5521 next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 5573 next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
5522 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, 5574 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
5523 (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 5575 (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
5524 2) - 5576 2) -
5525 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value); 5577 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
5526 find_peer_context.start = GNUNET_TIME_absolute_get (); 5578 find_peer_context.start = GNUNET_TIME_absolute_get ();
5527 GNUNET_SCHEDULER_add_delayed (next_send_time, 5579 GNUNET_SCHEDULER_add_delayed (next_send_time,
5528 &send_find_peer_message, 5580 &send_find_peer_message, &find_peer_context);
5529 &find_peer_context); 5581 }
5530 }
5531 5582
5532 /* Scheduled the task to clean up when shutdown is called */ 5583 /* Scheduled the task to clean up when shutdown is called */
5533 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 5584 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -5552,21 +5603,21 @@ main (int argc, char *const *argv)
5552 "dht", 5603 "dht",
5553 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 5604 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
5554 if (NULL != recent.hashmap) 5605 if (NULL != recent.hashmap)
5555 { 5606 {
5556 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap)); 5607 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap));
5557 GNUNET_CONTAINER_multihashmap_destroy (recent.hashmap); 5608 GNUNET_CONTAINER_multihashmap_destroy (recent.hashmap);
5558 recent.hashmap = NULL; 5609 recent.hashmap = NULL;
5559 } 5610 }
5560 if (NULL != recent.minHeap) 5611 if (NULL != recent.minHeap)
5561 { 5612 {
5562 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent.minHeap)); 5613 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent.minHeap));
5563 GNUNET_CONTAINER_heap_destroy (recent.minHeap); 5614 GNUNET_CONTAINER_heap_destroy (recent.minHeap);
5564 recent.minHeap = NULL; 5615 recent.minHeap = NULL;
5565 } 5616 }
5566 if (NULL != recent_find_peer_requests) 5617 if (NULL != recent_find_peer_requests)
5567 { 5618 {
5568 GNUNET_CONTAINER_multihashmap_destroy (recent_find_peer_requests); 5619 GNUNET_CONTAINER_multihashmap_destroy (recent_find_peer_requests);
5569 recent_find_peer_requests = NULL; 5620 recent_find_peer_requests = NULL;
5570 } 5621 }
5571 return ret; 5622 return ret;
5572} 5623}
diff --git a/src/dht/plugin_dhtlog_dummy.c b/src/dht/plugin_dhtlog_dummy.c
index 0a7091030..2250c0330 100644
--- a/src/dht/plugin_dhtlog_dummy.c
+++ b/src/dht/plugin_dhtlog_dummy.c
@@ -39,7 +39,8 @@
39 * 39 *
40 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 40 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
41 */ 41 */
42int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) 42int
43add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
43{ 44{
44 return GNUNET_OK; 45 return GNUNET_OK;
45} 46}
@@ -52,7 +53,8 @@ int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
52 * 53 *
53 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 54 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
54 */ 55 */
55int add_round (unsigned int round_type, unsigned int round_count) 56int
57add_round (unsigned int round_type, unsigned int round_count)
56{ 58{
57 return GNUNET_OK; 59 return GNUNET_OK;
58} 60}
@@ -68,8 +70,10 @@ int add_round (unsigned int round_type, unsigned int round_count)
68 * 70 *
69 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 71 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
70 */ 72 */
71int add_round_details (unsigned int round_type, unsigned int round_count, 73int
72 unsigned int num_messages, unsigned int num_messages_succeded) 74add_round_details (unsigned int round_type, unsigned int round_count,
75 unsigned int num_messages,
76 unsigned int num_messages_succeded)
73{ 77{
74 return GNUNET_OK; 78 return GNUNET_OK;
75} 79}
@@ -100,7 +104,7 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
100 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 104 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
101 */ 105 */
102int 106int
103add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) 107add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
104{ 108{
105 *nodeuid = 1337; 109 *nodeuid = 1337;
106 return GNUNET_OK; 110 return GNUNET_OK;
@@ -132,8 +136,7 @@ update_trials (unsigned int gets_succeeded)
132 */ 136 */
133int 137int
134add_generic_stat (const struct GNUNET_PeerIdentity *peer, 138add_generic_stat (const struct GNUNET_PeerIdentity *peer,
135 const char *name, 139 const char *name, const char *section, uint64_t value)
136 const char *section, uint64_t value)
137{ 140{
138 return GNUNET_OK; 141 return GNUNET_OK;
139} 142}
@@ -167,7 +170,7 @@ add_connections (unsigned int totalConnections)
167int 170int
168add_query (unsigned long long *sqlqueryuid, unsigned long long queryid, 171add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
169 unsigned int type, unsigned int hops, int succeeded, 172 unsigned int type, unsigned int hops, int succeeded,
170 const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode * key) 173 const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key)
171{ 174{
172 *sqlqueryuid = 17; 175 *sqlqueryuid = 17;
173 return GNUNET_OK; 176 return GNUNET_OK;
@@ -191,9 +194,10 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
191int 194int
192add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, 195add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
193 unsigned int type, unsigned int hops, 196 unsigned int type, unsigned int hops,
194 int succeeded, const struct GNUNET_PeerIdentity * node, 197 int succeeded, const struct GNUNET_PeerIdentity *node,
195 const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity * from_node, 198 const GNUNET_HashCode * key,
196 const struct GNUNET_PeerIdentity * to_node) 199 const struct GNUNET_PeerIdentity *from_node,
200 const struct GNUNET_PeerIdentity *to_node)
197{ 201{
198 *sqlqueryuid = 18; 202 *sqlqueryuid = 18;
199 return GNUNET_OK; 203 return GNUNET_OK;
@@ -222,7 +226,8 @@ add_topology (int num_connections)
222 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 226 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
223 */ 227 */
224int 228int
225add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second) 229add_extended_topology (const struct GNUNET_PeerIdentity *first,
230 const struct GNUNET_PeerIdentity *second)
226{ 231{
227 return GNUNET_OK; 232 return GNUNET_OK;
228} 233}
@@ -278,15 +283,15 @@ set_malicious (struct GNUNET_PeerIdentity *peer)
278 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 283 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
279 */ 284 */
280int insert_stat 285int insert_stat
281 (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests, 286 (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
282 unsigned int route_forwards, unsigned int result_requests, 287 unsigned int route_forwards, unsigned int result_requests,
283 unsigned int client_requests, unsigned int result_forwards, 288 unsigned int client_requests, unsigned int result_forwards,
284 unsigned int gets, unsigned int puts, 289 unsigned int gets, unsigned int puts,
285 unsigned int data_inserts, unsigned int find_peer_requests, 290 unsigned int data_inserts, unsigned int find_peer_requests,
286 unsigned int find_peers_started, unsigned int gets_started, 291 unsigned int find_peers_started, unsigned int gets_started,
287 unsigned int puts_started, unsigned int find_peer_responses_received, 292 unsigned int puts_started, unsigned int find_peer_responses_received,
288 unsigned int get_responses_received, unsigned int find_peer_responses_sent, 293 unsigned int get_responses_received, unsigned int find_peer_responses_sent,
289 unsigned int get_responses_sent) 294 unsigned int get_responses_sent)
290{ 295{
291 return GNUNET_OK; 296 return GNUNET_OK;
292} 297}
@@ -299,14 +304,15 @@ int insert_stat
299 * @return the handle to the server, or NULL on error 304 * @return the handle to the server, or NULL on error
300 */ 305 */
301void * 306void *
302libgnunet_plugin_dhtlog_dummy_init (void * cls) 307libgnunet_plugin_dhtlog_dummy_init (void *cls)
303{ 308{
304 struct GNUNET_DHTLOG_Plugin *plugin = cls; 309 struct GNUNET_DHTLOG_Plugin *plugin = cls;
310
305#if DEBUG_DHTLOG 311#if DEBUG_DHTLOG
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DUMMY DHT Logger: initializing.\n"); 312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DUMMY DHT Logger: initializing.\n");
307#endif 313#endif
308 GNUNET_assert(plugin->dhtlog_api == NULL); 314 GNUNET_assert (plugin->dhtlog_api == NULL);
309 plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle)); 315 plugin->dhtlog_api = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Handle));
310 plugin->dhtlog_api->add_generic_stat = &add_generic_stat; 316 plugin->dhtlog_api->add_generic_stat = &add_generic_stat;
311 plugin->dhtlog_api->insert_round = &add_round; 317 plugin->dhtlog_api->insert_round = &add_round;
312 plugin->dhtlog_api->insert_round_details = &add_round_details; 318 plugin->dhtlog_api->insert_round_details = &add_round_details;
@@ -329,11 +335,10 @@ libgnunet_plugin_dhtlog_dummy_init (void * cls)
329 * Shutdown the plugin. 335 * Shutdown the plugin.
330 */ 336 */
331void * 337void *
332libgnunet_plugin_dhtlog_dummy_done (void * cls) 338libgnunet_plugin_dhtlog_dummy_done (void *cls)
333{ 339{
334#if DEBUG_DHTLOG 340#if DEBUG_DHTLOG
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DUMMY DHT Logger: shutdown\n");
336 "DUMMY DHT Logger: shutdown\n");
337#endif 342#endif
338 return NULL; 343 return NULL;
339} 344}
diff --git a/src/dht/plugin_dhtlog_mysql.c b/src/dht/plugin_dhtlog_mysql.c
index 8e4357b1c..c653f912a 100644
--- a/src/dht/plugin_dhtlog_mysql.c
+++ b/src/dht/plugin_dhtlog_mysql.c
@@ -188,11 +188,10 @@ run_statement (const char *statement)
188{ 188{
189 mysql_query (conn, statement); 189 mysql_query (conn, statement);
190 if (mysql_error (conn)[0]) 190 if (mysql_error (conn)[0])
191 { 191 {
192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mysql_query");
193 "mysql_query"); 193 return GNUNET_SYSERR;
194 return GNUNET_SYSERR; 194 }
195 }
196 return GNUNET_OK; 195 return GNUNET_OK;
197} 196}
198 197
@@ -253,46 +252,46 @@ itable ()
253 return GNUNET_SYSERR; 252 return GNUNET_SYSERR;
254 253
255 if (MRUNS ("CREATE TABLE IF NOT EXISTS `trials` (" 254 if (MRUNS ("CREATE TABLE IF NOT EXISTS `trials` ("
256 "`trialuid` int(10) unsigned NOT NULL auto_increment," 255 "`trialuid` int(10) unsigned NOT NULL auto_increment,"
257 "`other_trial_identifier` int(10) unsigned NOT NULL default '0'," 256 "`other_trial_identifier` int(10) unsigned NOT NULL default '0',"
258 "`numnodes` int(10) unsigned NOT NULL," 257 "`numnodes` int(10) unsigned NOT NULL,"
259 "`topology` int(10) NOT NULL," 258 "`topology` int(10) NOT NULL,"
260 "`blacklist_topology` int(11) NOT NULL," 259 "`blacklist_topology` int(11) NOT NULL,"
261 "`connect_topology` int(11) NOT NULL," 260 "`connect_topology` int(11) NOT NULL,"
262 "`connect_topology_option` int(11) NOT NULL," 261 "`connect_topology_option` int(11) NOT NULL,"
263 "`topology_percentage` float NOT NULL," 262 "`topology_percentage` float NOT NULL,"
264 "`topology_probability` float NOT NULL," 263 "`topology_probability` float NOT NULL,"
265 "`connect_topology_option_modifier` float NOT NULL," 264 "`connect_topology_option_modifier` float NOT NULL,"
266 "`starttime` datetime NOT NULL," 265 "`starttime` datetime NOT NULL,"
267 "`endtime` datetime NOT NULL," 266 "`endtime` datetime NOT NULL,"
268 "`puts` int(10) unsigned NOT NULL," 267 "`puts` int(10) unsigned NOT NULL,"
269 "`gets` int(10) unsigned NOT NULL," 268 "`gets` int(10) unsigned NOT NULL,"
270 "`concurrent` int(10) unsigned NOT NULL," 269 "`concurrent` int(10) unsigned NOT NULL,"
271 "`settle_time` int(10) unsigned NOT NULL," 270 "`settle_time` int(10) unsigned NOT NULL,"
272 "`totalConnections` int(10) unsigned NOT NULL," 271 "`totalConnections` int(10) unsigned NOT NULL,"
273 "`message` text NOT NULL," 272 "`message` text NOT NULL,"
274 "`num_rounds` int(10) unsigned NOT NULL," 273 "`num_rounds` int(10) unsigned NOT NULL,"
275 "`malicious_getters` int(10) unsigned NOT NULL," 274 "`malicious_getters` int(10) unsigned NOT NULL,"
276 "`malicious_putters` int(10) unsigned NOT NULL," 275 "`malicious_putters` int(10) unsigned NOT NULL,"
277 "`malicious_droppers` int(10) unsigned NOT NULL," 276 "`malicious_droppers` int(10) unsigned NOT NULL,"
278 "`topology_modifier` double NOT NULL," 277 "`topology_modifier` double NOT NULL,"
279 "`malicious_get_frequency` int(10) unsigned NOT NULL," 278 "`malicious_get_frequency` int(10) unsigned NOT NULL,"
280 "`malicious_put_frequency` int(10) unsigned NOT NULL," 279 "`malicious_put_frequency` int(10) unsigned NOT NULL,"
281 "`stop_closest` int(10) unsigned NOT NULL," 280 "`stop_closest` int(10) unsigned NOT NULL,"
282 "`stop_found` int(10) unsigned NOT NULL," 281 "`stop_found` int(10) unsigned NOT NULL,"
283 "`strict_kademlia` int(10) unsigned NOT NULL," 282 "`strict_kademlia` int(10) unsigned NOT NULL,"
284 "`gets_succeeded` int(10) unsigned NOT NULL," 283 "`gets_succeeded` int(10) unsigned NOT NULL,"
285 "PRIMARY KEY (`trialuid`)," 284 "PRIMARY KEY (`trialuid`),"
286 "UNIQUE KEY `trialuid` (`trialuid`)" 285 "UNIQUE KEY `trialuid` (`trialuid`)"
287 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1")) 286 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
288 return GNUNET_SYSERR; 287 return GNUNET_SYSERR;
289 288
290 if (MRUNS ("CREATE TABLE IF NOT EXISTS `topology` (" 289 if (MRUNS ("CREATE TABLE IF NOT EXISTS `topology` ("
291 "`topology_uid` int(10) unsigned NOT NULL AUTO_INCREMENT," 290 "`topology_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
292 "`trialuid` int(10) unsigned NOT NULL," 291 "`trialuid` int(10) unsigned NOT NULL,"
293 "`date` datetime NOT NULL," 292 "`date` datetime NOT NULL,"
294 "`connections` int(10) unsigned NOT NULL," 293 "`connections` int(10) unsigned NOT NULL,"
295 "PRIMARY KEY (`topology_uid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1")) 294 "PRIMARY KEY (`topology_uid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
296 return GNUNET_SYSERR; 295 return GNUNET_SYSERR;
297 296
298 if (MRUNS ("CREATE TABLE IF NOT EXISTS `extended_topology` (" 297 if (MRUNS ("CREATE TABLE IF NOT EXISTS `extended_topology` ("
@@ -305,27 +304,27 @@ itable ()
305 return GNUNET_SYSERR; 304 return GNUNET_SYSERR;
306 305
307 if (MRUNS ("CREATE TABLE IF NOT EXISTS `node_statistics` (" 306 if (MRUNS ("CREATE TABLE IF NOT EXISTS `node_statistics` ("
308 "`stat_uid` int(10) unsigned NOT NULL AUTO_INCREMENT," 307 "`stat_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
309 "`trialuid` int(10) unsigned NOT NULL," 308 "`trialuid` int(10) unsigned NOT NULL,"
310 "`nodeuid` int(10) unsigned NOT NULL," 309 "`nodeuid` int(10) unsigned NOT NULL,"
311 "`route_requests` int(10) unsigned NOT NULL," 310 "`route_requests` int(10) unsigned NOT NULL,"
312 "`route_forwards` int(10) unsigned NOT NULL," 311 "`route_forwards` int(10) unsigned NOT NULL,"
313 "`result_requests` int(10) unsigned NOT NULL," 312 "`result_requests` int(10) unsigned NOT NULL,"
314 "`client_results` int(10) unsigned NOT NULL," 313 "`client_results` int(10) unsigned NOT NULL,"
315 "`result_forwards` int(10) unsigned NOT NULL," 314 "`result_forwards` int(10) unsigned NOT NULL,"
316 "`gets` int(10) unsigned NOT NULL," 315 "`gets` int(10) unsigned NOT NULL,"
317 "`puts` int(10) unsigned NOT NULL," 316 "`puts` int(10) unsigned NOT NULL,"
318 "`data_inserts` int(10) unsigned NOT NULL," 317 "`data_inserts` int(10) unsigned NOT NULL,"
319 "`find_peer_requests` int(10) unsigned NOT NULL," 318 "`find_peer_requests` int(10) unsigned NOT NULL,"
320 "`find_peers_started` int(10) unsigned NOT NULL," 319 "`find_peers_started` int(10) unsigned NOT NULL,"
321 "`gets_started` int(10) unsigned NOT NULL," 320 "`gets_started` int(10) unsigned NOT NULL,"
322 "`puts_started` int(10) unsigned NOT NULL," 321 "`puts_started` int(10) unsigned NOT NULL,"
323 "`find_peer_responses_received` int(10) unsigned NOT NULL," 322 "`find_peer_responses_received` int(10) unsigned NOT NULL,"
324 "`get_responses_received` int(10) unsigned NOT NULL," 323 "`get_responses_received` int(10) unsigned NOT NULL,"
325 "`find_peer_responses_sent` int(10) unsigned NOT NULL," 324 "`find_peer_responses_sent` int(10) unsigned NOT NULL,"
326 "`get_responses_sent` int(10) unsigned NOT NULL," 325 "`get_responses_sent` int(10) unsigned NOT NULL,"
327 "PRIMARY KEY (`stat_uid`)" 326 "PRIMARY KEY (`stat_uid`)"
328 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;")) 327 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"))
329 return GNUNET_SYSERR; 328 return GNUNET_SYSERR;
330 329
331 if (MRUNS ("SET AUTOCOMMIT = 1")) 330 if (MRUNS ("SET AUTOCOMMIT = 1"))
@@ -359,15 +358,15 @@ void
359prepared_statement_close (struct StatementHandle *s) 358prepared_statement_close (struct StatementHandle *s)
360{ 359{
361 if (s == NULL) 360 if (s == NULL)
362 { 361 {
363 return; 362 return;
364 } 363 }
365 364
366 GNUNET_free_non_null(s->query); 365 GNUNET_free_non_null (s->query);
367 366
368 if (s->valid == GNUNET_YES) 367 if (s->valid == GNUNET_YES)
369 mysql_stmt_close(s->statement); 368 mysql_stmt_close (s->statement);
370 GNUNET_free(s); 369 GNUNET_free (s);
371} 370}
372 371
373/* 372/*
@@ -390,61 +389,65 @@ iopen (struct GNUNET_DHTLOG_Plugin *plugin)
390 return GNUNET_SYSERR; 389 return GNUNET_SYSERR;
391 390
392 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 391 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
393 "MYSQL", "DATABASE", 392 "MYSQL", "DATABASE",
394 &database)) 393 &database))
395 { 394 {
396 database = GNUNET_strdup("gnunet"); 395 database = GNUNET_strdup ("gnunet");
397 } 396 }
398 397
399 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 398 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
400 "MYSQL", "USER", &user)) 399 "MYSQL", "USER",
401 { 400 &user))
402 user = GNUNET_strdup("dht"); 401 {
403 } 402 user = GNUNET_strdup ("dht");
403 }
404 404
405 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 405 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
406 "MYSQL", "PASSWORD", &password)) 406 "MYSQL", "PASSWORD",
407 { 407 &password))
408 password = GNUNET_strdup("dhttest**"); 408 {
409 } 409 password = GNUNET_strdup ("dhttest**");
410 }
410 411
411 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 412 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
412 "MYSQL", "SERVER", &server)) 413 "MYSQL", "SERVER",
413 { 414 &server))
414 server = GNUNET_strdup("localhost"); 415 {
415 } 416 server = GNUNET_strdup ("localhost");
417 }
416 418
417 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->cfg, 419 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->cfg,
418 "MYSQL", "MYSQL_PORT", &port)) 420 "MYSQL", "MYSQL_PORT",
419 { 421 &port))
420 port = 0; 422 {
421 } 423 port = 0;
424 }
422 425
423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mysql with: user %s, pass %s, server %s, database %s, port %d\n", 426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427 "Connecting to mysql with: user %s, pass %s, server %s, database %s, port %d\n",
424 user, password, server, database, port); 428 user, password, server, database, port);
425 429
426 reconnect = 0; 430 reconnect = 0;
427 timeout = 60; /* in seconds */ 431 timeout = 60; /* in seconds */
428 mysql_options (conn, MYSQL_OPT_RECONNECT, &reconnect); 432 mysql_options (conn, MYSQL_OPT_RECONNECT, &reconnect);
429 mysql_options (conn, 433 mysql_options (conn, MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
430 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); 434 mysql_options (conn, MYSQL_SET_CHARSET_NAME, "UTF8");
431 mysql_options(conn, MYSQL_SET_CHARSET_NAME, "UTF8");
432 mysql_options (conn, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); 435 mysql_options (conn, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
433 mysql_options (conn, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 436 mysql_options (conn, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
434 mysql_real_connect (conn, server, user, password, 437 mysql_real_connect (conn, server, user, password,
435 database, (unsigned int) port, NULL, CLIENT_IGNORE_SIGPIPE); 438 database, (unsigned int) port, NULL,
439 CLIENT_IGNORE_SIGPIPE);
436 440
437 GNUNET_free_non_null(server); 441 GNUNET_free_non_null (server);
438 GNUNET_free_non_null(password); 442 GNUNET_free_non_null (password);
439 GNUNET_free_non_null(user); 443 GNUNET_free_non_null (user);
440 GNUNET_free_non_null(database); 444 GNUNET_free_non_null (database);
441 445
442 if (mysql_error (conn)[0]) 446 if (mysql_error (conn)[0])
443 { 447 {
444 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 448 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect");
445 "mysql_real_connect"); 449 return GNUNET_SYSERR;
446 return GNUNET_SYSERR; 450 }
447 }
448 451
449#if OLD 452#if OLD
450 db = GNUNET_MYSQL_database_open (coreAPI->ectx, coreAPI->cfg); 453 db = GNUNET_MYSQL_database_open (coreAPI->ectx, coreAPI->cfg);
@@ -473,10 +476,10 @@ iopen (struct GNUNET_DHTLOG_Plugin *plugin)
473 PINIT (insert_topology, INSERT_TOPOLOGY_STMT) || 476 PINIT (insert_topology, INSERT_TOPOLOGY_STMT) ||
474 PINIT (update_topology, UPDATE_TOPOLOGY_STMT) || 477 PINIT (update_topology, UPDATE_TOPOLOGY_STMT) ||
475 PINIT (extend_topology, EXTEND_TOPOLOGY_STMT) || 478 PINIT (extend_topology, EXTEND_TOPOLOGY_STMT) ||
476 PINIT (update_node_malicious, SET_MALICIOUS_STMT) ) 479 PINIT (update_node_malicious, SET_MALICIOUS_STMT))
477 { 480 {
478 return GNUNET_SYSERR; 481 return GNUNET_SYSERR;
479 } 482 }
480#undef PINIT 483#undef PINIT
481 484
482 return ret; 485 return ret;
@@ -504,13 +507,13 @@ prepare_statement (struct StatementHandle *ret)
504 return GNUNET_SYSERR; 507 return GNUNET_SYSERR;
505 508
506 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query))) 509 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
507 { 510 {
508 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
509 "mysql_stmt_prepare `%s', %s", ret->query, mysql_error(conn)); 512 "mysql_stmt_prepare `%s', %s", ret->query, mysql_error (conn));
510 mysql_stmt_close (ret->statement); 513 mysql_stmt_close (ret->statement);
511 ret->statement = NULL; 514 ret->statement = NULL;
512 return GNUNET_SYSERR; 515 return GNUNET_SYSERR;
513 } 516 }
514 ret->valid = GNUNET_YES; 517 ret->valid = GNUNET_YES;
515 return GNUNET_OK; 518 return GNUNET_OK;
516} 519}
@@ -533,67 +536,71 @@ init_params (struct StatementHandle *s, va_list ap)
533 536
534 pc = mysql_stmt_param_count (s->statement); 537 pc = mysql_stmt_param_count (s->statement);
535 if (pc > MAX_PARAM) 538 if (pc > MAX_PARAM)
536 { 539 {
537 /* increase internal constant! */ 540 /* increase internal constant! */
538 GNUNET_break (0); 541 GNUNET_break (0);
539 return GNUNET_SYSERR; 542 return GNUNET_SYSERR;
540 } 543 }
541 memset (qbind, 0, sizeof (qbind)); 544 memset (qbind, 0, sizeof (qbind));
542 off = 0; 545 off = 0;
543 ft = 0; 546 ft = 0;
544 while ((pc > 0) && (-1 != (ft = va_arg (ap, enum enum_field_types)))) 547 while ((pc > 0) && (-1 != (ft = va_arg (ap, enum enum_field_types))))
548 {
549 qbind[off].buffer_type = ft;
550 switch (ft)
545 { 551 {
546 qbind[off].buffer_type = ft; 552 case MYSQL_TYPE_FLOAT:
547 switch (ft) 553 qbind[off].buffer = va_arg (ap, float *);
548 { 554
549 case MYSQL_TYPE_FLOAT: 555 break;
550 qbind[off].buffer = va_arg (ap, float *); 556 case MYSQL_TYPE_LONGLONG:
551 break; 557 qbind[off].buffer = va_arg (ap, unsigned long long *);
552 case MYSQL_TYPE_LONGLONG: 558 qbind[off].is_unsigned = va_arg (ap, int);
553 qbind[off].buffer = va_arg (ap, unsigned long long *); 559
554 qbind[off].is_unsigned = va_arg (ap, int); 560 break;
555 break; 561 case MYSQL_TYPE_LONG:
556 case MYSQL_TYPE_LONG: 562 qbind[off].buffer = va_arg (ap, unsigned int *);
557 qbind[off].buffer = va_arg (ap, unsigned int *); 563 qbind[off].is_unsigned = va_arg (ap, int);
558 qbind[off].is_unsigned = va_arg (ap, int); 564
559 break; 565 break;
560 case MYSQL_TYPE_VAR_STRING: 566 case MYSQL_TYPE_VAR_STRING:
561 case MYSQL_TYPE_STRING: 567 case MYSQL_TYPE_STRING:
562 case MYSQL_TYPE_BLOB: 568 case MYSQL_TYPE_BLOB:
563 qbind[off].buffer = va_arg (ap, void *); 569 qbind[off].buffer = va_arg (ap, void *);
564 qbind[off].buffer_length = va_arg (ap, unsigned long); 570 qbind[off].buffer_length = va_arg (ap, unsigned long);
565 qbind[off].length = va_arg (ap, unsigned long *); 571 qbind[off].length = va_arg (ap, unsigned long *);
566 break; 572
567 default: 573 break;
568 /* unsupported type */ 574 default:
569 GNUNET_break (0); 575 /* unsupported type */
570 return GNUNET_SYSERR;
571 }
572 pc--;
573 off++;
574 }
575 if (!((pc == 0) && (ft != -1) && (va_arg (ap, int) == -1)))
576 {
577 GNUNET_break (0); 576 GNUNET_break (0);
578 return GNUNET_SYSERR; 577 return GNUNET_SYSERR;
579 } 578 }
579 pc--;
580 off++;
581 }
582 if (!((pc == 0) && (ft != -1) && (va_arg (ap, int) == -1)))
583 {
584 GNUNET_break (0);
585 return GNUNET_SYSERR;
586 }
580 if (mysql_stmt_bind_param (s->statement, qbind)) 587 if (mysql_stmt_bind_param (s->statement, qbind))
581 { 588 {
582 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 589 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
583 _("`%s' failed at %s:%d with error: %s\n"), 590 _("`%s' failed at %s:%d with error: %s\n"),
584 "mysql_stmt_bind_param", 591 "mysql_stmt_bind_param",
585 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 592 __FILE__, __LINE__, mysql_stmt_error (s->statement));
586 return GNUNET_SYSERR; 593 return GNUNET_SYSERR;
587 } 594 }
588 595
589 if (mysql_stmt_execute (s->statement)) 596 if (mysql_stmt_execute (s->statement))
590 { 597 {
591 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
592 _("`%s' failed at %s:%d with error: %s\n"), 599 _("`%s' failed at %s:%d with error: %s\n"),
593 "mysql_stmt_execute", 600 "mysql_stmt_execute",
594 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 601 __FILE__, __LINE__, mysql_stmt_error (s->statement));
595 return GNUNET_SYSERR; 602 return GNUNET_SYSERR;
596 } 603 }
597 604
598 return GNUNET_OK; 605 return GNUNET_OK;
599} 606}
@@ -619,8 +626,7 @@ prepared_statement_run_select (struct StatementHandle *s,
619 unsigned int result_size, 626 unsigned int result_size,
620 MYSQL_BIND * results, 627 MYSQL_BIND * results,
621 GNUNET_MysqlDataProcessor 628 GNUNET_MysqlDataProcessor
622 processor, void *processor_cls, 629 processor, void *processor_cls, ...)
623 ...)
624{ 630{
625 va_list ap; 631 va_list ap;
626 int ret; 632 int ret;
@@ -628,52 +634,52 @@ prepared_statement_run_select (struct StatementHandle *s,
628 int total; 634 int total;
629 635
630 if (GNUNET_OK != prepare_statement (s)) 636 if (GNUNET_OK != prepare_statement (s))
631 { 637 {
632 GNUNET_break (0); 638 GNUNET_break (0);
633 return GNUNET_SYSERR; 639 return GNUNET_SYSERR;
634 } 640 }
635 va_start (ap, processor_cls); 641 va_start (ap, processor_cls);
636 if (GNUNET_OK != init_params (s, ap)) 642 if (GNUNET_OK != init_params (s, ap))
637 { 643 {
638 GNUNET_break (0); 644 GNUNET_break (0);
639 va_end (ap); 645 va_end (ap);
640 return GNUNET_SYSERR; 646 return GNUNET_SYSERR;
641 } 647 }
642 va_end (ap); 648 va_end (ap);
643 rsize = mysql_stmt_field_count (s->statement); 649 rsize = mysql_stmt_field_count (s->statement);
644 if (rsize > result_size) 650 if (rsize > result_size)
645 { 651 {
646 GNUNET_break (0); 652 GNUNET_break (0);
647 return GNUNET_SYSERR; 653 return GNUNET_SYSERR;
648 } 654 }
649 if (mysql_stmt_bind_result (s->statement, results)) 655 if (mysql_stmt_bind_result (s->statement, results))
656 {
657 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
658 _("`%s' failed at %s:%d with error: %s\n"),
659 "mysql_stmt_bind_result",
660 __FILE__, __LINE__, mysql_stmt_error (s->statement));
661 return GNUNET_SYSERR;
662 }
663
664 total = 0;
665 while (1)
666 {
667 ret = mysql_stmt_fetch (s->statement);
668 if (ret == MYSQL_NO_DATA)
669 break;
670 if (ret != 0)
650 { 671 {
651 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
652 _("`%s' failed at %s:%d with error: %s\n"), 673 _("`%s' failed at %s:%d with error: %s\n"),
653 "mysql_stmt_bind_result", 674 "mysql_stmt_fetch",
654 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 675 __FILE__, __LINE__, mysql_stmt_error (s->statement));
655 return GNUNET_SYSERR; 676 return GNUNET_SYSERR;
656 } 677 }
657 678 if (processor != NULL)
658 total = 0; 679 if (GNUNET_OK != processor (processor_cls, rsize, results))
659 while (1)
660 {
661 ret = mysql_stmt_fetch (s->statement);
662 if (ret == MYSQL_NO_DATA)
663 break; 680 break;
664 if (ret != 0) 681 total++;
665 { 682 }
666 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
667 _("`%s' failed at %s:%d with error: %s\n"),
668 "mysql_stmt_fetch",
669 __FILE__, __LINE__, mysql_stmt_error (s->statement));
670 return GNUNET_SYSERR;
671 }
672 if (processor != NULL)
673 if (GNUNET_OK != processor (processor_cls, rsize, results))
674 break;
675 total++;
676 }
677 mysql_stmt_reset (s->statement); 683 mysql_stmt_reset (s->statement);
678 return total; 684 return total;
679} 685}
@@ -695,23 +701,22 @@ get_node_uid (unsigned long long *nodeuid, const GNUNET_HashCode * peerHash)
695 p_len = strlen ((char *) &encPeer); 701 p_len = strlen ((char *) &encPeer);
696 702
697 if (1 != prepared_statement_run_select (get_nodeuid, 703 if (1 != prepared_statement_run_select (get_nodeuid,
698 1, 704 1,
699 rbind, 705 rbind,
700 return_ok, 706 return_ok,
701 NULL, 707 NULL,
702 MYSQL_TYPE_LONGLONG, 708 MYSQL_TYPE_LONGLONG,
703 &current_trial, 709 &current_trial,
704 GNUNET_YES, 710 GNUNET_YES,
705 MYSQL_TYPE_VAR_STRING, 711 MYSQL_TYPE_VAR_STRING,
706 &encPeer, 712 &encPeer,
707 max_varchar_len, 713 max_varchar_len, &p_len, -1))
708 &p_len, -1)) 714 {
709 {
710#if DEBUG_DHTLOG 715#if DEBUG_DHTLOG
711 fprintf (stderr, "FAILED\n"); 716 fprintf (stderr, "FAILED\n");
712#endif 717#endif
713 return GNUNET_SYSERR; 718 return GNUNET_SYSERR;
714 } 719 }
715 return GNUNET_OK; 720 return GNUNET_OK;
716} 721}
717 722
@@ -727,12 +732,10 @@ get_current_trial (unsigned long long *trialuid)
727 732
728 if ((GNUNET_OK != 733 if ((GNUNET_OK !=
729 prepared_statement_run_select (get_trial, 734 prepared_statement_run_select (get_trial,
730 1, 735 1, rbind, return_ok, NULL, -1)))
731 rbind, 736 {
732 return_ok, NULL, -1))) 737 return GNUNET_SYSERR;
733 { 738 }
734 return GNUNET_SYSERR;
735 }
736 739
737 return GNUNET_OK; 740 return GNUNET_OK;
738} 741}
@@ -749,12 +752,10 @@ get_current_topology (unsigned long long *topologyuid)
749 752
750 if ((GNUNET_OK != 753 if ((GNUNET_OK !=
751 prepared_statement_run_select (get_topology, 754 prepared_statement_run_select (get_topology,
752 1, 755 1, rbind, return_ok, NULL, -1)))
753 rbind, 756 {
754 return_ok, NULL, -1))) 757 return GNUNET_SYSERR;
755 { 758 }
756 return GNUNET_SYSERR;
757 }
758 759
759 return GNUNET_OK; 760 return GNUNET_OK;
760} 761}
@@ -765,6 +766,7 @@ get_dhtkey_uid (unsigned long long *dhtkeyuid, const GNUNET_HashCode * key)
765 MYSQL_BIND rbind[1]; 766 MYSQL_BIND rbind[1];
766 struct GNUNET_CRYPTO_HashAsciiEncoded encKey; 767 struct GNUNET_CRYPTO_HashAsciiEncoded encKey;
767 unsigned long long k_len; 768 unsigned long long k_len;
769
768 memset (rbind, 0, sizeof (rbind)); 770 memset (rbind, 0, sizeof (rbind));
769 rbind[0].buffer_type = MYSQL_TYPE_LONG; 771 rbind[0].buffer_type = MYSQL_TYPE_LONG;
770 rbind[0].is_unsigned = 1; 772 rbind[0].is_unsigned = 1;
@@ -772,7 +774,9 @@ get_dhtkey_uid (unsigned long long *dhtkeyuid, const GNUNET_HashCode * key)
772 GNUNET_CRYPTO_hash_to_enc (key, &encKey); 774 GNUNET_CRYPTO_hash_to_enc (key, &encKey);
773 k_len = strlen ((char *) &encKey); 775 k_len = strlen ((char *) &encKey);
774#if DEBUG_DHTLOG 776#if DEBUG_DHTLOG
775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Searching for dhtkey `%s' in trial %llu\n", GNUNET_h2s(key), current_trial); 777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "Searching for dhtkey `%s' in trial %llu\n", GNUNET_h2s (key),
779 current_trial);
776#endif 780#endif
777 if ((GNUNET_OK != 781 if ((GNUNET_OK !=
778 prepared_statement_run_select (get_dhtkeyuid, 782 prepared_statement_run_select (get_dhtkeyuid,
@@ -784,11 +788,10 @@ get_dhtkey_uid (unsigned long long *dhtkeyuid, const GNUNET_HashCode * key)
784 max_varchar_len, 788 max_varchar_len,
785 &k_len, 789 &k_len,
786 MYSQL_TYPE_LONGLONG, 790 MYSQL_TYPE_LONGLONG,
787 &current_trial, 791 &current_trial, GNUNET_YES, -1)))
788 GNUNET_YES, -1))) 792 {
789 { 793 return GNUNET_SYSERR;
790 return GNUNET_SYSERR; 794 }
791 }
792 795
793 return GNUNET_OK; 796 return GNUNET_OK;
794} 797}
@@ -813,22 +816,22 @@ prepared_statement_run (struct StatementHandle *s,
813 va_list ap; 816 va_list ap;
814 int affected; 817 int affected;
815 818
816 if (GNUNET_OK != prepare_statement(s)) 819 if (GNUNET_OK != prepare_statement (s))
817 { 820 {
818 GNUNET_break(0); 821 GNUNET_break (0);
819 return GNUNET_SYSERR; 822 return GNUNET_SYSERR;
820 } 823 }
821 GNUNET_assert(s->valid == GNUNET_YES); 824 GNUNET_assert (s->valid == GNUNET_YES);
822 if (s->statement == NULL) 825 if (s->statement == NULL)
823 return GNUNET_SYSERR; 826 return GNUNET_SYSERR;
824 827
825 va_start (ap, insert_id); 828 va_start (ap, insert_id);
826 829
827 if (GNUNET_OK != init_params (s, ap)) 830 if (GNUNET_OK != init_params (s, ap))
828 { 831 {
829 va_end (ap); 832 va_end (ap);
830 return GNUNET_SYSERR; 833 return GNUNET_SYSERR;
831 } 834 }
832 835
833 va_end (ap); 836 va_end (ap);
834 affected = mysql_stmt_affected_rows (s->statement); 837 affected = mysql_stmt_affected_rows (s->statement);
@@ -846,53 +849,73 @@ prepared_statement_run (struct StatementHandle *s,
846 * 849 *
847 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 850 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
848 */ 851 */
849int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) 852int
853add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
850{ 854{
851 MYSQL_STMT *stmt; 855 MYSQL_STMT *stmt;
852 int ret; 856 int ret;
853 unsigned long long m_len; 857 unsigned long long m_len;
858
854 m_len = strlen (trial_info->message); 859 m_len = strlen (trial_info->message);
855 860
856 stmt = mysql_stmt_init(conn); 861 stmt = mysql_stmt_init (conn);
857 if (GNUNET_OK != 862 if (GNUNET_OK !=
858 (ret = prepared_statement_run (insert_trial, &current_trial, 863 (ret = prepared_statement_run (insert_trial, &current_trial,
859 MYSQL_TYPE_LONG, &trial_info->other_identifier, GNUNET_YES, 864 MYSQL_TYPE_LONG,
860 MYSQL_TYPE_LONG, &trial_info->num_nodes, GNUNET_YES, 865 &trial_info->other_identifier, GNUNET_YES,
861 MYSQL_TYPE_LONG, &trial_info->topology, GNUNET_YES, 866 MYSQL_TYPE_LONG, &trial_info->num_nodes,
862 MYSQL_TYPE_FLOAT, &trial_info->topology_percentage, 867 GNUNET_YES, MYSQL_TYPE_LONG,
863 MYSQL_TYPE_FLOAT, &trial_info->topology_probability, 868 &trial_info->topology, GNUNET_YES,
864 MYSQL_TYPE_LONG, &trial_info->blacklist_topology, GNUNET_YES, 869 MYSQL_TYPE_FLOAT,
865 MYSQL_TYPE_LONG, &trial_info->connect_topology, GNUNET_YES, 870 &trial_info->topology_percentage,
866 MYSQL_TYPE_LONG, &trial_info->connect_topology_option, GNUNET_YES, 871 MYSQL_TYPE_FLOAT,
867 MYSQL_TYPE_FLOAT, &trial_info->connect_topology_option_modifier, 872 &trial_info->topology_probability,
868 MYSQL_TYPE_LONG, &trial_info->puts, GNUNET_YES, 873 MYSQL_TYPE_LONG,
869 MYSQL_TYPE_LONG, &trial_info->gets, GNUNET_YES, 874 &trial_info->blacklist_topology,
870 MYSQL_TYPE_LONG, &trial_info->concurrent, GNUNET_YES, 875 GNUNET_YES, MYSQL_TYPE_LONG,
871 MYSQL_TYPE_LONG, &trial_info->settle_time, GNUNET_YES, 876 &trial_info->connect_topology, GNUNET_YES,
872 MYSQL_TYPE_LONG, &trial_info->num_rounds, GNUNET_YES, 877 MYSQL_TYPE_LONG,
873 MYSQL_TYPE_LONG, &trial_info->malicious_getters, GNUNET_YES, 878 &trial_info->connect_topology_option,
874 MYSQL_TYPE_LONG, &trial_info->malicious_putters, GNUNET_YES, 879 GNUNET_YES, MYSQL_TYPE_FLOAT,
875 MYSQL_TYPE_LONG, &trial_info->malicious_droppers, GNUNET_YES, 880 &trial_info->connect_topology_option_modifier,
876 MYSQL_TYPE_LONG, &trial_info->malicious_get_frequency, GNUNET_YES, 881 MYSQL_TYPE_LONG, &trial_info->puts,
877 MYSQL_TYPE_LONG, &trial_info->malicious_put_frequency, GNUNET_YES, 882 GNUNET_YES, MYSQL_TYPE_LONG,
878 MYSQL_TYPE_LONG, &trial_info->stop_closest, GNUNET_YES, 883 &trial_info->gets, GNUNET_YES,
879 MYSQL_TYPE_LONG, &trial_info->stop_found, GNUNET_YES, 884 MYSQL_TYPE_LONG, &trial_info->concurrent,
880 MYSQL_TYPE_LONG, &trial_info->strict_kademlia, GNUNET_YES, 885 GNUNET_YES, MYSQL_TYPE_LONG,
881 MYSQL_TYPE_LONG, &trial_info->gets_succeeded, GNUNET_YES, 886 &trial_info->settle_time, GNUNET_YES,
882 MYSQL_TYPE_BLOB, trial_info->message, max_varchar_len + 887 MYSQL_TYPE_LONG, &trial_info->num_rounds,
883 max_varchar_len, &m_len, 888 GNUNET_YES, MYSQL_TYPE_LONG,
884 -1))) 889 &trial_info->malicious_getters, GNUNET_YES,
890 MYSQL_TYPE_LONG,
891 &trial_info->malicious_putters, GNUNET_YES,
892 MYSQL_TYPE_LONG,
893 &trial_info->malicious_droppers,
894 GNUNET_YES, MYSQL_TYPE_LONG,
895 &trial_info->malicious_get_frequency,
896 GNUNET_YES, MYSQL_TYPE_LONG,
897 &trial_info->malicious_put_frequency,
898 GNUNET_YES, MYSQL_TYPE_LONG,
899 &trial_info->stop_closest, GNUNET_YES,
900 MYSQL_TYPE_LONG, &trial_info->stop_found,
901 GNUNET_YES, MYSQL_TYPE_LONG,
902 &trial_info->strict_kademlia, GNUNET_YES,
903 MYSQL_TYPE_LONG,
904 &trial_info->gets_succeeded, GNUNET_YES,
905 MYSQL_TYPE_BLOB, trial_info->message,
906 max_varchar_len + max_varchar_len, &m_len,
907 -1)))
908 {
909 if (ret == GNUNET_SYSERR)
885 { 910 {
886 if (ret == GNUNET_SYSERR) 911 mysql_stmt_close (stmt);
887 { 912 return GNUNET_SYSERR;
888 mysql_stmt_close(stmt);
889 return GNUNET_SYSERR;
890 }
891 } 913 }
914 }
892 915
893 get_current_trial (&current_trial); 916 get_current_trial (&current_trial);
894 917
895 mysql_stmt_close(stmt); 918 mysql_stmt_close (stmt);
896 return GNUNET_OK; 919 return GNUNET_OK;
897} 920}
898 921
@@ -904,19 +927,20 @@ int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
904 * 927 *
905 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 928 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
906 */ 929 */
907int add_round (unsigned int round_type, unsigned int round_count) 930int
931add_round (unsigned int round_type, unsigned int round_count)
908{ 932{
909 933
910 MYSQL_STMT *stmt; 934 MYSQL_STMT *stmt;
911 int ret; 935 int ret;
912 936
913 stmt = mysql_stmt_init(conn); 937 stmt = mysql_stmt_init (conn);
914 ret = prepared_statement_run (insert_round, 938 ret = prepared_statement_run (insert_round,
915 NULL, 939 NULL,
916 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 940 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES,
917 MYSQL_TYPE_LONG, &round_type, GNUNET_YES, 941 MYSQL_TYPE_LONG, &round_type, GNUNET_YES,
918 MYSQL_TYPE_LONG, &round_count, GNUNET_YES, -1); 942 MYSQL_TYPE_LONG, &round_count, GNUNET_YES, -1);
919 mysql_stmt_close(stmt); 943 mysql_stmt_close (stmt);
920 if (ret != GNUNET_OK) 944 if (ret != GNUNET_OK)
921 return GNUNET_SYSERR; 945 return GNUNET_SYSERR;
922 return ret; 946 return ret;
@@ -933,22 +957,24 @@ int add_round (unsigned int round_type, unsigned int round_count)
933 * 957 *
934 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 958 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
935 */ 959 */
936int add_round_details (unsigned int round_type, unsigned int round_count, 960int
937 unsigned int num_messages, unsigned int num_messages_succeeded) 961add_round_details (unsigned int round_type, unsigned int round_count,
962 unsigned int num_messages,
963 unsigned int num_messages_succeeded)
938{ 964{
939 MYSQL_STMT *stmt; 965 MYSQL_STMT *stmt;
940 int ret; 966 int ret;
941 967
942 stmt = mysql_stmt_init(conn); 968 stmt = mysql_stmt_init (conn);
943 ret = prepared_statement_run (insert_round_details, 969 ret = prepared_statement_run (insert_round_details,
944 NULL, 970 NULL,
945 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 971 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES,
946 MYSQL_TYPE_LONG, &round_type, GNUNET_YES, 972 MYSQL_TYPE_LONG, &round_type, GNUNET_YES,
947 MYSQL_TYPE_LONG, &round_count, GNUNET_YES, 973 MYSQL_TYPE_LONG, &round_count, GNUNET_YES,
948 MYSQL_TYPE_LONG, &num_messages, GNUNET_YES, 974 MYSQL_TYPE_LONG, &num_messages, GNUNET_YES,
949 MYSQL_TYPE_LONG, &num_messages_succeeded, GNUNET_YES, 975 MYSQL_TYPE_LONG, &num_messages_succeeded,
950 -1); 976 GNUNET_YES, -1);
951 mysql_stmt_close(stmt); 977 mysql_stmt_close (stmt);
952 if (ret != GNUNET_OK) 978 if (ret != GNUNET_OK)
953 return GNUNET_SYSERR; 979 return GNUNET_SYSERR;
954 return ret; 980 return ret;
@@ -985,53 +1011,61 @@ add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
985 unsigned int data_inserts, unsigned int find_peer_requests, 1011 unsigned int data_inserts, unsigned int find_peer_requests,
986 unsigned int find_peers_started, unsigned int gets_started, 1012 unsigned int find_peers_started, unsigned int gets_started,
987 unsigned int puts_started, unsigned int find_peer_responses_received, 1013 unsigned int puts_started, unsigned int find_peer_responses_received,
988 unsigned int get_responses_received, unsigned int find_peer_responses_sent, 1014 unsigned int get_responses_received,
1015 unsigned int find_peer_responses_sent,
989 unsigned int get_responses_sent) 1016 unsigned int get_responses_sent)
990{ 1017{
991 MYSQL_STMT *stmt; 1018 MYSQL_STMT *stmt;
992 int ret; 1019 int ret;
993 unsigned long long peer_uid; 1020 unsigned long long peer_uid;
994 unsigned long long return_uid; 1021 unsigned long long return_uid;
1022
995 if (peer == NULL) 1023 if (peer == NULL)
996 return GNUNET_SYSERR; 1024 return GNUNET_SYSERR;
997 1025
998 if (GNUNET_OK != get_node_uid (&peer_uid, &peer->hashPubKey)) 1026 if (GNUNET_OK != get_node_uid (&peer_uid, &peer->hashPubKey))
999 { 1027 {
1000 return GNUNET_SYSERR; 1028 return GNUNET_SYSERR;
1001 } 1029 }
1002 1030
1003 stmt = mysql_stmt_init(conn); 1031 stmt = mysql_stmt_init (conn);
1004 if (GNUNET_OK != 1032 if (GNUNET_OK !=
1005 (ret = prepared_statement_run (insert_stat, 1033 (ret = prepared_statement_run (insert_stat,
1006 &return_uid, 1034 &return_uid,
1007 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 1035 MYSQL_TYPE_LONGLONG, &current_trial,
1008 MYSQL_TYPE_LONGLONG, &peer_uid, GNUNET_YES, 1036 GNUNET_YES, MYSQL_TYPE_LONGLONG, &peer_uid,
1009 MYSQL_TYPE_LONG, &route_requests, GNUNET_YES, 1037 GNUNET_YES, MYSQL_TYPE_LONG,
1010 MYSQL_TYPE_LONG, &route_forwards, GNUNET_YES, 1038 &route_requests, GNUNET_YES,
1011 MYSQL_TYPE_LONG, &result_requests, GNUNET_YES, 1039 MYSQL_TYPE_LONG, &route_forwards,
1012 MYSQL_TYPE_LONG, &client_requests, GNUNET_YES, 1040 GNUNET_YES, MYSQL_TYPE_LONG,
1013 MYSQL_TYPE_LONG, &result_forwards, GNUNET_YES, 1041 &result_requests, GNUNET_YES,
1042 MYSQL_TYPE_LONG, &client_requests,
1043 GNUNET_YES, MYSQL_TYPE_LONG,
1044 &result_forwards, GNUNET_YES,
1014 MYSQL_TYPE_LONG, &gets, GNUNET_YES, 1045 MYSQL_TYPE_LONG, &gets, GNUNET_YES,
1015 MYSQL_TYPE_LONG, &puts, GNUNET_YES, 1046 MYSQL_TYPE_LONG, &puts, GNUNET_YES,
1016 MYSQL_TYPE_LONG, &data_inserts, GNUNET_YES, 1047 MYSQL_TYPE_LONG, &data_inserts, GNUNET_YES,
1017 MYSQL_TYPE_LONG, &find_peer_requests, GNUNET_YES, 1048 MYSQL_TYPE_LONG, &find_peer_requests,
1018 MYSQL_TYPE_LONG, &find_peers_started, GNUNET_YES, 1049 GNUNET_YES, MYSQL_TYPE_LONG,
1050 &find_peers_started, GNUNET_YES,
1019 MYSQL_TYPE_LONG, &gets_started, GNUNET_YES, 1051 MYSQL_TYPE_LONG, &gets_started, GNUNET_YES,
1020 MYSQL_TYPE_LONG, &puts_started, GNUNET_YES, 1052 MYSQL_TYPE_LONG, &puts_started, GNUNET_YES,
1021 MYSQL_TYPE_LONG, &find_peer_responses_received, GNUNET_YES, 1053 MYSQL_TYPE_LONG,
1022 MYSQL_TYPE_LONG, &get_responses_received, GNUNET_YES, 1054 &find_peer_responses_received, GNUNET_YES,
1023 MYSQL_TYPE_LONG, &find_peer_responses_sent, GNUNET_YES, 1055 MYSQL_TYPE_LONG, &get_responses_received,
1024 MYSQL_TYPE_LONG, &get_responses_sent, GNUNET_YES, 1056 GNUNET_YES, MYSQL_TYPE_LONG,
1025 -1))) 1057 &find_peer_responses_sent, GNUNET_YES,
1058 MYSQL_TYPE_LONG, &get_responses_sent,
1059 GNUNET_YES, -1)))
1060 {
1061 if (ret == GNUNET_SYSERR)
1026 { 1062 {
1027 if (ret == GNUNET_SYSERR) 1063 mysql_stmt_close (stmt);
1028 { 1064 return GNUNET_SYSERR;
1029 mysql_stmt_close(stmt);
1030 return GNUNET_SYSERR;
1031 }
1032 } 1065 }
1066 }
1033 1067
1034 mysql_stmt_close(stmt); 1068 mysql_stmt_close (stmt);
1035 return GNUNET_OK; 1069 return GNUNET_OK;
1036} 1070}
1037 1071
@@ -1047,39 +1081,41 @@ add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
1047 */ 1081 */
1048int 1082int
1049add_generic_stat (const struct GNUNET_PeerIdentity *peer, 1083add_generic_stat (const struct GNUNET_PeerIdentity *peer,
1050 const char *name, 1084 const char *name, const char *section, uint64_t value)
1051 const char *section, uint64_t value)
1052{ 1085{
1053 unsigned long long peer_uid; 1086 unsigned long long peer_uid;
1054 unsigned long long section_len; 1087 unsigned long long section_len;
1055 unsigned long long name_len; 1088 unsigned long long name_len;
1056 int ret; 1089 int ret;
1090
1057 if (peer == NULL) 1091 if (peer == NULL)
1058 return GNUNET_SYSERR; 1092 return GNUNET_SYSERR;
1059 1093
1060 if (GNUNET_OK != get_node_uid (&peer_uid, &peer->hashPubKey)) 1094 if (GNUNET_OK != get_node_uid (&peer_uid, &peer->hashPubKey))
1061 { 1095 {
1062 return GNUNET_SYSERR; 1096 return GNUNET_SYSERR;
1063 } 1097 }
1064 1098
1065 section_len = strlen(section); 1099 section_len = strlen (section);
1066 name_len = strlen(name); 1100 name_len = strlen (name);
1067 1101
1068 if (GNUNET_OK != 1102 if (GNUNET_OK !=
1069 (ret = prepared_statement_run (insert_generic_stat, 1103 (ret = prepared_statement_run (insert_generic_stat,
1070 NULL, 1104 NULL,
1071 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 1105 MYSQL_TYPE_LONGLONG, &current_trial,
1072 MYSQL_TYPE_LONGLONG, &peer_uid, GNUNET_YES, 1106 GNUNET_YES, MYSQL_TYPE_LONGLONG, &peer_uid,
1073 MYSQL_TYPE_VAR_STRING, &section, max_varchar_len, &section_len, 1107 GNUNET_YES, MYSQL_TYPE_VAR_STRING,
1074 MYSQL_TYPE_VAR_STRING, &name, max_varchar_len, &name_len, 1108 &section, max_varchar_len, &section_len,
1109 MYSQL_TYPE_VAR_STRING, &name,
1110 max_varchar_len, &name_len,
1075 MYSQL_TYPE_LONGLONG, &value, GNUNET_YES, 1111 MYSQL_TYPE_LONGLONG, &value, GNUNET_YES,
1076 -1))) 1112 -1)))
1113 {
1114 if (ret == GNUNET_SYSERR)
1077 { 1115 {
1078 if (ret == GNUNET_SYSERR) 1116 return GNUNET_SYSERR;
1079 {
1080 return GNUNET_SYSERR;
1081 }
1082 } 1117 }
1118 }
1083 return GNUNET_OK; 1119 return GNUNET_OK;
1084} 1120}
1085 1121
@@ -1101,23 +1137,24 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
1101 unsigned long long k_len; 1137 unsigned long long k_len;
1102 unsigned long long h_len; 1138 unsigned long long h_len;
1103 unsigned long long curr_dhtkeyuid; 1139 unsigned long long curr_dhtkeyuid;
1140
1104 GNUNET_CRYPTO_hash_to_enc (dhtkey, &encKey); 1141 GNUNET_CRYPTO_hash_to_enc (dhtkey, &encKey);
1105 k_len = strlen ((char *) &encKey); 1142 k_len = strlen ((char *) &encKey);
1106 h_len = sizeof (GNUNET_HashCode); 1143 h_len = sizeof (GNUNET_HashCode);
1107 curr_dhtkeyuid = 0; 1144 curr_dhtkeyuid = 0;
1108 ret = get_dhtkey_uid(&curr_dhtkeyuid, dhtkey); 1145 ret = get_dhtkey_uid (&curr_dhtkeyuid, dhtkey);
1109 if (curr_dhtkeyuid != 0) /* dhtkey already exists */ 1146 if (curr_dhtkeyuid != 0) /* dhtkey already exists */
1110 { 1147 {
1111 if (dhtkeyuid != NULL) 1148 if (dhtkeyuid != NULL)
1112 *dhtkeyuid = curr_dhtkeyuid; 1149 *dhtkeyuid = curr_dhtkeyuid;
1113 return GNUNET_OK; 1150 return GNUNET_OK;
1114 } 1151 }
1115 else if (ret == GNUNET_SYSERR) 1152 else if (ret == GNUNET_SYSERR)
1116 { 1153 {
1117#if DEBUG_DHTLOG 1154#if DEBUG_DHTLOG
1118 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to get dhtkeyuid!\n"); 1155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to get dhtkeyuid!\n");
1119#endif 1156#endif
1120 } 1157 }
1121 1158
1122 if (GNUNET_OK != 1159 if (GNUNET_OK !=
1123 (ret = prepared_statement_run (insert_dhtkey, 1160 (ret = prepared_statement_run (insert_dhtkey,
@@ -1131,14 +1168,13 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
1131 GNUNET_YES, 1168 GNUNET_YES,
1132 MYSQL_TYPE_BLOB, 1169 MYSQL_TYPE_BLOB,
1133 dhtkey, 1170 dhtkey,
1134 sizeof (GNUNET_HashCode), 1171 sizeof (GNUNET_HashCode), &h_len, -1)))
1135 &h_len, -1))) 1172 {
1173 if (ret == GNUNET_SYSERR)
1136 { 1174 {
1137 if (ret == GNUNET_SYSERR) 1175 return GNUNET_SYSERR;
1138 {
1139 return GNUNET_SYSERR;
1140 }
1141 } 1176 }
1177 }
1142 1178
1143 return GNUNET_OK; 1179 return GNUNET_OK;
1144} 1180}
@@ -1154,7 +1190,7 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
1154 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 1190 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1155 */ 1191 */
1156int 1192int
1157add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) 1193add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
1158{ 1194{
1159 struct GNUNET_CRYPTO_HashAsciiEncoded encPeer; 1195 struct GNUNET_CRYPTO_HashAsciiEncoded encPeer;
1160 unsigned long p_len; 1196 unsigned long p_len;
@@ -1170,16 +1206,17 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
1170 if (GNUNET_OK != 1206 if (GNUNET_OK !=
1171 (ret = prepared_statement_run (insert_node, 1207 (ret = prepared_statement_run (insert_node,
1172 nodeuid, 1208 nodeuid,
1173 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 1209 MYSQL_TYPE_LONGLONG, &current_trial,
1174 MYSQL_TYPE_VAR_STRING, &encPeer, max_varchar_len, &p_len, 1210 GNUNET_YES, MYSQL_TYPE_VAR_STRING,
1175 MYSQL_TYPE_BLOB, &node->hashPubKey, sizeof (GNUNET_HashCode), 1211 &encPeer, max_varchar_len, &p_len,
1176 &h_len, -1))) 1212 MYSQL_TYPE_BLOB, &node->hashPubKey,
1213 sizeof (GNUNET_HashCode), &h_len, -1)))
1214 {
1215 if (ret == GNUNET_SYSERR)
1177 { 1216 {
1178 if (ret == GNUNET_SYSERR) 1217 return GNUNET_SYSERR;
1179 {
1180 return GNUNET_SYSERR;
1181 }
1182 } 1218 }
1219 }
1183 return GNUNET_OK; 1220 return GNUNET_OK;
1184} 1221}
1185 1222
@@ -1197,16 +1234,16 @@ update_trials (unsigned int gets_succeeded)
1197 1234
1198 if (GNUNET_OK != 1235 if (GNUNET_OK !=
1199 (ret = prepared_statement_run (update_trial, 1236 (ret = prepared_statement_run (update_trial,
1200 NULL, 1237 NULL,
1201 MYSQL_TYPE_LONG, &gets_succeeded, GNUNET_YES, 1238 MYSQL_TYPE_LONG, &gets_succeeded,
1202 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 1239 GNUNET_YES, MYSQL_TYPE_LONGLONG,
1203 -1))) 1240 &current_trial, GNUNET_YES, -1)))
1241 {
1242 if (ret == GNUNET_SYSERR)
1204 { 1243 {
1205 if (ret == GNUNET_SYSERR) 1244 return GNUNET_SYSERR;
1206 {
1207 return GNUNET_SYSERR;
1208 }
1209 } 1245 }
1246 }
1210 if (ret > 0) 1247 if (ret > 0)
1211 return GNUNET_OK; 1248 return GNUNET_OK;
1212 else 1249 else
@@ -1222,27 +1259,28 @@ update_trials (unsigned int gets_succeeded)
1222 * 1259 *
1223 * @return GNUNET_OK on success, GNUNET_SYSERR on failure. 1260 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
1224 */ 1261 */
1225int set_malicious (struct GNUNET_PeerIdentity *peer) 1262int
1263set_malicious (struct GNUNET_PeerIdentity *peer)
1226{ 1264{
1227 unsigned long long p_len; 1265 unsigned long long p_len;
1228 int ret; 1266 int ret;
1229 char *temp_str; 1267 char *temp_str;
1230 1268
1231 temp_str = GNUNET_strdup(GNUNET_h2s_full(&peer->hashPubKey)); 1269 temp_str = GNUNET_strdup (GNUNET_h2s_full (&peer->hashPubKey));
1232 p_len = strlen(temp_str); 1270 p_len = strlen (temp_str);
1233 1271
1234 if (GNUNET_OK != 1272 if (GNUNET_OK !=
1235 (ret = prepared_statement_run (update_node_malicious, 1273 (ret = prepared_statement_run (update_node_malicious,
1236 NULL, 1274 NULL,
1237 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 1275 MYSQL_TYPE_LONGLONG, &current_trial,
1238 MYSQL_TYPE_VAR_STRING, temp_str, max_varchar_len, &p_len, 1276 GNUNET_YES, MYSQL_TYPE_VAR_STRING,
1239 -1))) 1277 temp_str, max_varchar_len, &p_len, -1)))
1278 {
1279 if (ret == GNUNET_SYSERR)
1240 { 1280 {
1241 if (ret == GNUNET_SYSERR) 1281 return GNUNET_SYSERR;
1242 {
1243 return GNUNET_SYSERR;
1244 }
1245 } 1282 }
1283 }
1246 return GNUNET_OK; 1284 return GNUNET_OK;
1247} 1285}
1248 1286
@@ -1261,18 +1299,18 @@ add_connections (unsigned int totalConnections)
1261 1299
1262 if (GNUNET_OK != 1300 if (GNUNET_OK !=
1263 (ret = prepared_statement_run (update_connection, 1301 (ret = prepared_statement_run (update_connection,
1264 NULL, 1302 NULL,
1265 MYSQL_TYPE_LONG, 1303 MYSQL_TYPE_LONG,
1266 &totalConnections, 1304 &totalConnections,
1267 GNUNET_YES, 1305 GNUNET_YES,
1268 MYSQL_TYPE_LONGLONG, 1306 MYSQL_TYPE_LONGLONG,
1269 &current_trial, GNUNET_YES, -1))) 1307 &current_trial, GNUNET_YES, -1)))
1308 {
1309 if (ret == GNUNET_SYSERR)
1270 { 1310 {
1271 if (ret == GNUNET_SYSERR) 1311 return GNUNET_SYSERR;
1272 {
1273 return GNUNET_SYSERR;
1274 }
1275 } 1312 }
1313 }
1276 if (ret > 0) 1314 if (ret > 0)
1277 return GNUNET_OK; 1315 return GNUNET_OK;
1278 else 1316 else
@@ -1295,65 +1333,66 @@ add_connections (unsigned int totalConnections)
1295int 1333int
1296add_query (unsigned long long *sqlqueryuid, unsigned long long queryid, 1334add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
1297 unsigned int type, unsigned int hops, int succeeded, 1335 unsigned int type, unsigned int hops, int succeeded,
1298 const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode * key) 1336 const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key)
1299{ 1337{
1300 int ret; 1338 int ret;
1301 unsigned long long peer_uid, key_uid; 1339 unsigned long long peer_uid, key_uid;
1340
1302 peer_uid = 0; 1341 peer_uid = 0;
1303 key_uid = 0; 1342 key_uid = 0;
1304 1343
1305 if ((node != NULL) 1344 if ((node != NULL)
1306 && (GNUNET_OK == get_node_uid (&peer_uid, &node->hashPubKey))) 1345 && (GNUNET_OK == get_node_uid (&peer_uid, &node->hashPubKey)))
1307 { 1346 {
1308 1347
1309 } 1348 }
1310 else 1349 else
1311 { 1350 {
1312 return GNUNET_SYSERR; 1351 return GNUNET_SYSERR;
1313 } 1352 }
1314 1353
1315 if ((key != NULL) && (GNUNET_OK == get_dhtkey_uid (&key_uid, key))) 1354 if ((key != NULL) && (GNUNET_OK == get_dhtkey_uid (&key_uid, key)))
1316 { 1355 {
1317 1356
1318 } 1357 }
1319 else if ((key != NULL) && (key->bits[(512 / 8 / sizeof (unsigned int)) - 1] == 42)) /* Malicious marker */ 1358 else if ((key != NULL) && (key->bits[(512 / 8 / sizeof (unsigned int)) - 1] == 42)) /* Malicious marker */
1320 { 1359 {
1321 key_uid = 0; 1360 key_uid = 0;
1322 } 1361 }
1323 else 1362 else
1324 { 1363 {
1325 return GNUNET_SYSERR; 1364 return GNUNET_SYSERR;
1326 } 1365 }
1327 1366
1328 if (GNUNET_OK != 1367 if (GNUNET_OK !=
1329 (ret = prepared_statement_run (insert_query, 1368 (ret = prepared_statement_run (insert_query,
1330 sqlqueryuid, 1369 sqlqueryuid,
1331 MYSQL_TYPE_LONGLONG, 1370 MYSQL_TYPE_LONGLONG,
1332 &current_trial, 1371 &current_trial,
1333 GNUNET_YES, 1372 GNUNET_YES,
1334 MYSQL_TYPE_LONG, 1373 MYSQL_TYPE_LONG,
1335 &type, 1374 &type,
1336 GNUNET_NO, 1375 GNUNET_NO,
1337 MYSQL_TYPE_LONG, 1376 MYSQL_TYPE_LONG,
1338 &hops, 1377 &hops,
1339 GNUNET_YES, 1378 GNUNET_YES,
1340 MYSQL_TYPE_LONGLONG, 1379 MYSQL_TYPE_LONGLONG,
1341 &key_uid, 1380 &key_uid,
1342 GNUNET_YES, 1381 GNUNET_YES,
1343 MYSQL_TYPE_LONGLONG, 1382 MYSQL_TYPE_LONGLONG,
1344 &queryid, 1383 &queryid,
1345 GNUNET_YES, 1384 GNUNET_YES,
1346 MYSQL_TYPE_LONG, 1385 MYSQL_TYPE_LONG,
1347 &succeeded, 1386 &succeeded,
1348 GNUNET_NO, 1387 GNUNET_NO,
1349 MYSQL_TYPE_LONGLONG, 1388 MYSQL_TYPE_LONGLONG,
1350 &peer_uid, GNUNET_YES, -1))) 1389 &peer_uid, GNUNET_YES, -1)))
1390 {
1391 if (ret == GNUNET_SYSERR)
1351 { 1392 {
1352 if (ret == GNUNET_SYSERR) 1393 return GNUNET_SYSERR;
1353 {
1354 return GNUNET_SYSERR;
1355 }
1356 } 1394 }
1395 }
1357 if (ret > 0) 1396 if (ret > 0)
1358 return GNUNET_OK; 1397 return GNUNET_OK;
1359 else 1398 else
@@ -1378,9 +1417,10 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
1378int 1417int
1379add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, 1418add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
1380 unsigned int type, unsigned int hops, 1419 unsigned int type, unsigned int hops,
1381 int succeeded, const struct GNUNET_PeerIdentity * node, 1420 int succeeded, const struct GNUNET_PeerIdentity *node,
1382 const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity * from_node, 1421 const GNUNET_HashCode * key,
1383 const struct GNUNET_PeerIdentity * to_node) 1422 const struct GNUNET_PeerIdentity *from_node,
1423 const struct GNUNET_PeerIdentity *to_node)
1384{ 1424{
1385 unsigned long long peer_uid = 0; 1425 unsigned long long peer_uid = 0;
1386 unsigned long long key_uid = 0; 1426 unsigned long long key_uid = 0;
@@ -1397,60 +1437,60 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
1397 to_uid = 0; 1437 to_uid = 0;
1398 1438
1399 if ((node != NULL)) 1439 if ((node != NULL))
1440 {
1441 if (1 != get_node_uid (&peer_uid, &node->hashPubKey))
1400 { 1442 {
1401 if (1 != get_node_uid (&peer_uid, &node->hashPubKey)) 1443 return GNUNET_SYSERR;
1402 {
1403 return GNUNET_SYSERR;
1404 }
1405 } 1444 }
1445 }
1406 else 1446 else
1407 return GNUNET_SYSERR; 1447 return GNUNET_SYSERR;
1408 1448
1409 if ((key != NULL)) 1449 if ((key != NULL))
1450 {
1451 if (1 != get_dhtkey_uid (&key_uid, key))
1410 { 1452 {
1411 if (1 != get_dhtkey_uid (&key_uid, key)) 1453 return GNUNET_SYSERR;
1412 {
1413 return GNUNET_SYSERR;
1414 }
1415 } 1454 }
1455 }
1416 else 1456 else
1417 return GNUNET_SYSERR; 1457 return GNUNET_SYSERR;
1418 1458
1419 if (GNUNET_OK != 1459 if (GNUNET_OK !=
1420 (ret = prepared_statement_run (insert_route, 1460 (ret = prepared_statement_run (insert_route,
1421 sqlqueryuid, 1461 sqlqueryuid,
1422 MYSQL_TYPE_LONGLONG, 1462 MYSQL_TYPE_LONGLONG,
1423 &current_trial, 1463 &current_trial,
1424 GNUNET_YES, 1464 GNUNET_YES,
1425 MYSQL_TYPE_LONG, 1465 MYSQL_TYPE_LONG,
1426 &type, 1466 &type,
1427 GNUNET_NO, 1467 GNUNET_NO,
1428 MYSQL_TYPE_LONG, 1468 MYSQL_TYPE_LONG,
1429 &hops, 1469 &hops,
1430 GNUNET_YES, 1470 GNUNET_YES,
1431 MYSQL_TYPE_LONGLONG, 1471 MYSQL_TYPE_LONGLONG,
1432 &key_uid, 1472 &key_uid,
1433 GNUNET_YES, 1473 GNUNET_YES,
1434 MYSQL_TYPE_LONGLONG, 1474 MYSQL_TYPE_LONGLONG,
1435 &queryid, 1475 &queryid,
1436 GNUNET_YES, 1476 GNUNET_YES,
1437 MYSQL_TYPE_LONG, 1477 MYSQL_TYPE_LONG,
1438 &succeeded, 1478 &succeeded,
1439 GNUNET_NO, 1479 GNUNET_NO,
1440 MYSQL_TYPE_LONGLONG, 1480 MYSQL_TYPE_LONGLONG,
1441 &peer_uid, 1481 &peer_uid,
1442 GNUNET_YES, 1482 GNUNET_YES,
1443 MYSQL_TYPE_LONGLONG, 1483 MYSQL_TYPE_LONGLONG,
1444 &from_uid, 1484 &from_uid,
1445 GNUNET_YES, 1485 GNUNET_YES,
1446 MYSQL_TYPE_LONGLONG, 1486 MYSQL_TYPE_LONGLONG,
1447 &to_uid, GNUNET_YES, -1))) 1487 &to_uid, GNUNET_YES, -1)))
1488 {
1489 if (ret == GNUNET_SYSERR)
1448 { 1490 {
1449 if (ret == GNUNET_SYSERR) 1491 return GNUNET_SYSERR;
1450 {
1451 return GNUNET_SYSERR;
1452 }
1453 } 1492 }
1493 }
1454 if (ret > 0) 1494 if (ret > 0)
1455 return GNUNET_OK; 1495 return GNUNET_OK;
1456 else 1496 else
@@ -1470,7 +1510,7 @@ update_current_topology (unsigned int connections)
1470 int ret; 1510 int ret;
1471 unsigned long long topologyuid; 1511 unsigned long long topologyuid;
1472 1512
1473 get_current_topology(&topologyuid); 1513 get_current_topology (&topologyuid);
1474 1514
1475 if (GNUNET_OK != 1515 if (GNUNET_OK !=
1476 (ret = prepared_statement_run (update_topology, 1516 (ret = prepared_statement_run (update_topology,
@@ -1480,12 +1520,12 @@ update_current_topology (unsigned int connections)
1480 GNUNET_YES, 1520 GNUNET_YES,
1481 MYSQL_TYPE_LONGLONG, 1521 MYSQL_TYPE_LONGLONG,
1482 &topologyuid, GNUNET_YES, -1))) 1522 &topologyuid, GNUNET_YES, -1)))
1523 {
1524 if (ret == GNUNET_SYSERR)
1483 { 1525 {
1484 if (ret == GNUNET_SYSERR) 1526 return GNUNET_SYSERR;
1485 {
1486 return GNUNET_SYSERR;
1487 }
1488 } 1527 }
1528 }
1489 if (ret > 0) 1529 if (ret > 0)
1490 return GNUNET_OK; 1530 return GNUNET_OK;
1491 return GNUNET_SYSERR; 1531 return GNUNET_SYSERR;
@@ -1507,15 +1547,15 @@ add_topology (int num_connections)
1507 if (GNUNET_OK != 1547 if (GNUNET_OK !=
1508 (ret = prepared_statement_run (insert_topology, 1548 (ret = prepared_statement_run (insert_topology,
1509 NULL, 1549 NULL,
1510 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 1550 MYSQL_TYPE_LONGLONG, &current_trial,
1511 MYSQL_TYPE_LONG, &num_connections, GNUNET_YES, 1551 GNUNET_YES, MYSQL_TYPE_LONG,
1512 -1))) 1552 &num_connections, GNUNET_YES, -1)))
1553 {
1554 if (ret == GNUNET_SYSERR)
1513 { 1555 {
1514 if (ret == GNUNET_SYSERR) 1556 return GNUNET_SYSERR;
1515 {
1516 return GNUNET_SYSERR;
1517 }
1518 } 1557 }
1558 }
1519 if (ret > 0) 1559 if (ret > 0)
1520 return GNUNET_OK; 1560 return GNUNET_OK;
1521 return GNUNET_SYSERR; 1561 return GNUNET_SYSERR;
@@ -1530,18 +1570,19 @@ add_topology (int num_connections)
1530 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 1570 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1531 */ 1571 */
1532int 1572int
1533add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second) 1573add_extended_topology (const struct GNUNET_PeerIdentity *first,
1574 const struct GNUNET_PeerIdentity *second)
1534{ 1575{
1535 int ret; 1576 int ret;
1536 unsigned long long first_uid; 1577 unsigned long long first_uid;
1537 unsigned long long second_uid; 1578 unsigned long long second_uid;
1538 unsigned long long topologyuid; 1579 unsigned long long topologyuid;
1539 1580
1540 if (GNUNET_OK != get_current_topology(&topologyuid)) 1581 if (GNUNET_OK != get_current_topology (&topologyuid))
1541 return GNUNET_SYSERR; 1582 return GNUNET_SYSERR;
1542 if (GNUNET_OK != get_node_uid(&first_uid, &first->hashPubKey)) 1583 if (GNUNET_OK != get_node_uid (&first_uid, &first->hashPubKey))
1543 return GNUNET_SYSERR; 1584 return GNUNET_SYSERR;
1544 if (GNUNET_OK != get_node_uid(&second_uid, &second->hashPubKey)) 1585 if (GNUNET_OK != get_node_uid (&second_uid, &second->hashPubKey))
1545 return GNUNET_SYSERR; 1586 return GNUNET_SYSERR;
1546 1587
1547 if (GNUNET_OK != 1588 if (GNUNET_OK !=
@@ -1554,14 +1595,13 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNU
1554 &first_uid, 1595 &first_uid,
1555 GNUNET_YES, 1596 GNUNET_YES,
1556 MYSQL_TYPE_LONGLONG, 1597 MYSQL_TYPE_LONGLONG,
1557 &second_uid, 1598 &second_uid, GNUNET_YES, -1)))
1558 GNUNET_YES,-1))) 1599 {
1600 if (ret == GNUNET_SYSERR)
1559 { 1601 {
1560 if (ret == GNUNET_SYSERR) 1602 return GNUNET_SYSERR;
1561 {
1562 return GNUNET_SYSERR;
1563 }
1564 } 1603 }
1604 }
1565 if (ret > 0) 1605 if (ret > 0)
1566 return GNUNET_OK; 1606 return GNUNET_OK;
1567 return GNUNET_SYSERR; 1607 return GNUNET_SYSERR;
@@ -1576,25 +1616,27 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNU
1576 * @return the handle to the server, or NULL on error 1616 * @return the handle to the server, or NULL on error
1577 */ 1617 */
1578void * 1618void *
1579libgnunet_plugin_dhtlog_mysql_init (void * cls) 1619libgnunet_plugin_dhtlog_mysql_init (void *cls)
1580{ 1620{
1581 struct GNUNET_DHTLOG_Plugin *plugin = cls; 1621 struct GNUNET_DHTLOG_Plugin *plugin = cls;
1582 1622
1583 cfg = plugin->cfg; 1623 cfg = plugin->cfg;
1584 max_varchar_len = 255; 1624 max_varchar_len = 255;
1585#if DEBUG_DHTLOG 1625#if DEBUG_DHTLOG
1586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: initializing database\n"); 1626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1627 "MySQL DHT Logger: initializing database\n");
1587#endif 1628#endif
1588 1629
1589 if (iopen (plugin) != GNUNET_OK) 1630 if (iopen (plugin) != GNUNET_OK)
1590 { 1631 {
1591 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1632 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1592 _("Failed to initialize MySQL database connection for dhtlog.\n")); 1633 _
1593 return NULL; 1634 ("Failed to initialize MySQL database connection for dhtlog.\n"));
1594 } 1635 return NULL;
1595 1636 }
1596 GNUNET_assert(plugin->dhtlog_api == NULL); 1637
1597 plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle)); 1638 GNUNET_assert (plugin->dhtlog_api == NULL);
1639 plugin->dhtlog_api = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Handle));
1598 plugin->dhtlog_api->insert_trial = &add_trial; 1640 plugin->dhtlog_api->insert_trial = &add_trial;
1599 plugin->dhtlog_api->insert_stat = &add_stat; 1641 plugin->dhtlog_api->insert_stat = &add_stat;
1600 plugin->dhtlog_api->insert_round = &add_round; 1642 plugin->dhtlog_api->insert_round = &add_round;
@@ -1619,36 +1661,35 @@ libgnunet_plugin_dhtlog_mysql_init (void * cls)
1619 * Shutdown the plugin. 1661 * Shutdown the plugin.
1620 */ 1662 */
1621void * 1663void *
1622libgnunet_plugin_dhtlog_mysql_done (void * cls) 1664libgnunet_plugin_dhtlog_mysql_done (void *cls)
1623{ 1665{
1624 struct GNUNET_DHTLOG_Handle *dhtlog_api = cls; 1666 struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
1625 1667
1626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database shutdown\n");
1627 "MySQL DHT Logger: database shutdown\n"); 1669 GNUNET_assert (dhtlog_api != NULL);
1628 GNUNET_assert(dhtlog_api != NULL); 1670 prepared_statement_close (insert_query);
1629 prepared_statement_close(insert_query); 1671 prepared_statement_close (insert_route);
1630 prepared_statement_close(insert_route); 1672 prepared_statement_close (insert_trial);
1631 prepared_statement_close(insert_trial); 1673 prepared_statement_close (insert_round);
1632 prepared_statement_close(insert_round); 1674 prepared_statement_close (insert_round_details);
1633 prepared_statement_close(insert_round_details); 1675 prepared_statement_close (insert_node);
1634 prepared_statement_close(insert_node); 1676 prepared_statement_close (insert_dhtkey);
1635 prepared_statement_close(insert_dhtkey); 1677 prepared_statement_close (update_trial);
1636 prepared_statement_close(update_trial); 1678 prepared_statement_close (get_dhtkeyuid);
1637 prepared_statement_close(get_dhtkeyuid); 1679 prepared_statement_close (get_nodeuid);
1638 prepared_statement_close(get_nodeuid); 1680 prepared_statement_close (update_connection);
1639 prepared_statement_close(update_connection); 1681 prepared_statement_close (get_trial);
1640 prepared_statement_close(get_trial); 1682 prepared_statement_close (get_topology);
1641 prepared_statement_close(get_topology); 1683 prepared_statement_close (insert_topology);
1642 prepared_statement_close(insert_topology); 1684 prepared_statement_close (update_topology);
1643 prepared_statement_close(update_topology); 1685 prepared_statement_close (extend_topology);
1644 prepared_statement_close(extend_topology); 1686 prepared_statement_close (update_node_malicious);
1645 prepared_statement_close(update_node_malicious);
1646 1687
1647 if (conn != NULL) 1688 if (conn != NULL)
1648 mysql_close (conn); 1689 mysql_close (conn);
1649 conn = NULL; 1690 conn = NULL;
1650 mysql_library_end(); 1691 mysql_library_end ();
1651 GNUNET_free(dhtlog_api); 1692 GNUNET_free (dhtlog_api);
1652 return NULL; 1693 return NULL;
1653} 1694}
1654 1695
diff --git a/src/dht/plugin_dhtlog_mysql_dump.c b/src/dht/plugin_dhtlog_mysql_dump.c
index 90485a59d..25958044c 100644
--- a/src/dht/plugin_dhtlog_mysql_dump.c
+++ b/src/dht/plugin_dhtlog_mysql_dump.c
@@ -124,7 +124,7 @@ FILE *outfile;
124 124
125 125
126static char * 126static char *
127get_sql_time() 127get_sql_time ()
128{ 128{
129 static char date[DATE_STR_SIZE]; 129 static char date[DATE_STR_SIZE];
130 time_t timetmp; 130 time_t timetmp;
@@ -149,7 +149,7 @@ get_sql_time()
149static int 149static int
150prepared_statement_create (const char *statement) 150prepared_statement_create (const char *statement)
151{ 151{
152 if (fprintf(outfile, "%s;\n", statement) > 0) 152 if (fprintf (outfile, "%s;\n", statement) > 0)
153 return GNUNET_OK; 153 return GNUNET_OK;
154 154
155 return GNUNET_SYSERR; 155 return GNUNET_SYSERR;
@@ -179,11 +179,10 @@ iopen ()
179 PINIT (INSERT_TOPOLOGY_STMT) || 179 PINIT (INSERT_TOPOLOGY_STMT) ||
180 PINIT (EXTEND_TOPOLOGY_STMT) || 180 PINIT (EXTEND_TOPOLOGY_STMT) ||
181 PINIT (UPDATE_TOPOLOGY_STMT) || 181 PINIT (UPDATE_TOPOLOGY_STMT) ||
182 PINIT (GET_TRIAL_STMT) || 182 PINIT (GET_TRIAL_STMT) || PINIT (GET_TOPOLOGY_STMT))
183 PINIT (GET_TOPOLOGY_STMT)) 183 {
184 { 184 return GNUNET_SYSERR;
185 return GNUNET_SYSERR; 185 }
186 }
187#undef PINIT 186#undef PINIT
188 187
189 return GNUNET_OK; 188 return GNUNET_OK;
@@ -197,17 +196,22 @@ iopen ()
197 * 196 *
198 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 197 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
199 */ 198 */
200int add_round (unsigned int round_type, unsigned int round_count) 199int
200add_round (unsigned int round_type, unsigned int round_count)
201{ 201{
202 int ret; 202 int ret;
203
203 if (outfile == NULL) 204 if (outfile == NULL)
204 return GNUNET_SYSERR; 205 return GNUNET_SYSERR;
205 206
206 ret = fprintf(outfile, "set @curr_time = \"%s\", @rtype = \"%u\", @rcount = \"%u\";\n", get_sql_time(), round_type, round_count); 207 ret =
208 fprintf (outfile,
209 "set @curr_time = \"%s\", @rtype = \"%u\", @rcount = \"%u\";\n",
210 get_sql_time (), round_type, round_count);
207 211
208 if (ret < 0) 212 if (ret < 0)
209 return GNUNET_SYSERR; 213 return GNUNET_SYSERR;
210 ret = fprintf(outfile, "execute insert_round;\n"); 214 ret = fprintf (outfile, "execute insert_round;\n");
211 215
212 if (ret >= 0) 216 if (ret >= 0)
213 return GNUNET_OK; 217 return GNUNET_OK;
@@ -225,19 +229,25 @@ int add_round (unsigned int round_type, unsigned int round_count)
225 * 229 *
226 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 230 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
227 */ 231 */
228int add_round_details (unsigned int round_type, unsigned int round_count, 232int
229 unsigned int num_messages, unsigned int num_messages_succeeded) 233add_round_details (unsigned int round_type, unsigned int round_count,
234 unsigned int num_messages,
235 unsigned int num_messages_succeeded)
230{ 236{
231 int ret; 237 int ret;
238
232 if (outfile == NULL) 239 if (outfile == NULL)
233 return GNUNET_SYSERR; 240 return GNUNET_SYSERR;
234 241
235 ret = fprintf(outfile, "set @curr_time = \"%s\", @rtype = \"%u\", @rcount = \"%u\", @totalmsgs = \"%u\", @msgssucceeded = \"%u\";\n", 242 ret =
236 get_sql_time(), round_type, round_count, num_messages, num_messages_succeeded); 243 fprintf (outfile,
244 "set @curr_time = \"%s\", @rtype = \"%u\", @rcount = \"%u\", @totalmsgs = \"%u\", @msgssucceeded = \"%u\";\n",
245 get_sql_time (), round_type, round_count, num_messages,
246 num_messages_succeeded);
237 247
238 if (ret < 0) 248 if (ret < 0)
239 return GNUNET_SYSERR; 249 return GNUNET_SYSERR;
240 ret = fprintf(outfile, "execute insert_round_details;\n"); 250 ret = fprintf (outfile, "execute insert_round_details;\n");
241 251
242 if (ret >= 0) 252 if (ret >= 0)
243 return GNUNET_OK; 253 return GNUNET_OK;
@@ -255,19 +265,21 @@ int
255add_topology (int num_connections) 265add_topology (int num_connections)
256{ 266{
257 int ret; 267 int ret;
268
258 if (outfile == NULL) 269 if (outfile == NULL)
259 return GNUNET_SYSERR; 270 return GNUNET_SYSERR;
260 271
261 ret = fprintf(outfile, "set @date = \"%s\", @num = %d;\n", get_sql_time(), num_connections); 272 ret =
273 fprintf (outfile, "set @date = \"%s\", @num = %d;\n", get_sql_time (),
274 num_connections);
262 275
263 if (ret < 0) 276 if (ret < 0)
264 return GNUNET_SYSERR; 277 return GNUNET_SYSERR;
265 ret = fprintf(outfile, "execute insert_topology using " 278 ret = fprintf (outfile, "execute insert_topology using " "@date, @num;\n");
266 "@date, @num;\n");
267 if (ret < 0) 279 if (ret < 0)
268 return GNUNET_SYSERR; 280 return GNUNET_SYSERR;
269 281
270 ret = fprintf(outfile, "execute select_topology;\n"); 282 ret = fprintf (outfile, "execute select_topology;\n");
271 283
272 if (ret >= 0) 284 if (ret >= 0)
273 return GNUNET_OK; 285 return GNUNET_OK;
@@ -283,30 +295,38 @@ add_topology (int num_connections)
283 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 295 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
284 */ 296 */
285int 297int
286add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second) 298add_extended_topology (const struct GNUNET_PeerIdentity *first,
299 const struct GNUNET_PeerIdentity *second)
287{ 300{
288 int ret; 301 int ret;
302
289 if (outfile == NULL) 303 if (outfile == NULL)
290 return GNUNET_SYSERR; 304 return GNUNET_SYSERR;
291 305
292 if (first != NULL) 306 if (first != NULL)
293 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_first_node;\n", GNUNET_h2s_full(&first->hashPubKey)); 307 ret =
308 fprintf (outfile,
309 "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_first_node;\n",
310 GNUNET_h2s_full (&first->hashPubKey));
294 else 311 else
295 ret = fprintf(outfile, "set @temp_first_node = 0;\n"); 312 ret = fprintf (outfile, "set @temp_first_node = 0;\n");
296 313
297 if (ret < 0) 314 if (ret < 0)
298 return GNUNET_SYSERR; 315 return GNUNET_SYSERR;
299 316
300 if (second != NULL) 317 if (second != NULL)
301 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_second_node;\n", GNUNET_h2s_full(&second->hashPubKey)); 318 ret =
319 fprintf (outfile,
320 "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_second_node;\n",
321 GNUNET_h2s_full (&second->hashPubKey));
302 else 322 else
303 ret = fprintf(outfile, "set @temp_second_node = 0;\n"); 323 ret = fprintf (outfile, "set @temp_second_node = 0;\n");
304 324
305 if (ret < 0) 325 if (ret < 0)
306 return GNUNET_SYSERR; 326 return GNUNET_SYSERR;
307 327
308 ret = fprintf(outfile, "execute extend_topology using " 328 ret = fprintf (outfile, "execute extend_topology using "
309 "@temp_first_node, @temp_second_node;\n"); 329 "@temp_first_node, @temp_second_node;\n");
310 330
311 if (ret >= 0) 331 if (ret >= 0)
312 return GNUNET_OK; 332 return GNUNET_OK;
@@ -321,42 +341,51 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNU
321 * 341 *
322 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 342 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
323 */ 343 */
324int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) 344int
345add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
325{ 346{
326 int ret; 347 int ret;
327 348
328 if (outfile == NULL) 349 if (outfile == NULL)
329 return GNUNET_SYSERR; 350 return GNUNET_SYSERR;
330 351
331 ret = fprintf(outfile, "set @date = \"%s\", @oid = %u, @num = %u, @topology = %u, @bl = %u, " 352 ret =
332 "@connect = %u, @c_t_o = %u, @c_t_o_m = %f, @t_p = %f, " 353 fprintf (outfile,
333 "@t_pr = %f, @puts = %u, @gets = %u, " 354 "set @date = \"%s\", @oid = %u, @num = %u, @topology = %u, @bl = %u, "
334 "@concurrent = %u, @settle = %u, @rounds = %u, " 355 "@connect = %u, @c_t_o = %u, @c_t_o_m = %f, @t_p = %f, "
335 "@m_gets = %u, @m_puts = %u, @m_drops = %u, " 356 "@t_pr = %f, @puts = %u, @gets = %u, "
336 "@m_g_f = %u, @m_p_f = %u, @s_c = %u, @s_f = %u," 357 "@concurrent = %u, @settle = %u, @rounds = %u, "
337 "@s_k = %u, @g_s = %u, @message = \"%s\";\n", 358 "@m_gets = %u, @m_puts = %u, @m_drops = %u, "
338 get_sql_time(), trial_info->other_identifier, trial_info->num_nodes, trial_info->topology, 359 "@m_g_f = %u, @m_p_f = %u, @s_c = %u, @s_f = %u,"
339 trial_info->blacklist_topology, trial_info->connect_topology, 360 "@s_k = %u, @g_s = %u, @message = \"%s\";\n", get_sql_time (),
340 trial_info->connect_topology_option, trial_info->connect_topology_option_modifier, 361 trial_info->other_identifier, trial_info->num_nodes,
341 trial_info->topology_percentage, trial_info->topology_probability, 362 trial_info->topology, trial_info->blacklist_topology,
342 trial_info->puts, trial_info->gets, trial_info->concurrent, trial_info->settle_time, 363 trial_info->connect_topology,
343 trial_info->num_rounds, trial_info->malicious_getters, trial_info->malicious_putters, 364 trial_info->connect_topology_option,
344 trial_info->malicious_droppers, trial_info->malicious_get_frequency, trial_info->malicious_put_frequency, 365 trial_info->connect_topology_option_modifier,
345 trial_info->stop_closest, trial_info->stop_found, trial_info->strict_kademlia, trial_info->gets_succeeded, trial_info->message); 366 trial_info->topology_percentage,
367 trial_info->topology_probability, trial_info->puts,
368 trial_info->gets, trial_info->concurrent,
369 trial_info->settle_time, trial_info->num_rounds,
370 trial_info->malicious_getters, trial_info->malicious_putters,
371 trial_info->malicious_droppers,
372 trial_info->malicious_get_frequency,
373 trial_info->malicious_put_frequency, trial_info->stop_closest,
374 trial_info->stop_found, trial_info->strict_kademlia,
375 trial_info->gets_succeeded, trial_info->message);
346 376
347 if (ret < 0) 377 if (ret < 0)
348 return GNUNET_SYSERR; 378 return GNUNET_SYSERR;
349 ret = fprintf(outfile, "execute insert_trial using " 379 ret = fprintf (outfile, "execute insert_trial using "
350 "@date, @oid, @num, @topology, @t_p, @t_pr," 380 "@date, @oid, @num, @topology, @t_p, @t_pr,"
351 " @bl, @connect, @c_t_o," 381 " @bl, @connect, @c_t_o,"
352 "@c_t_o_m, @puts, @gets," 382 "@c_t_o_m, @puts, @gets,"
353 "@concurrent, @settle, @rounds," 383 "@concurrent, @settle, @rounds,"
354 "@m_gets, @m_puts, @m_drops," 384 "@m_gets, @m_puts, @m_drops,"
355 "@m_g_f, @m_p_f, @s_c, @s_f," 385 "@m_g_f, @m_p_f, @s_c, @s_f," "@s_k, @g_s, @message;\n");
356 "@s_k, @g_s, @message;\n");
357 if (ret < 0) 386 if (ret < 0)
358 return GNUNET_SYSERR; 387 return GNUNET_SYSERR;
359 ret = fprintf(outfile, "execute select_trial;\n"); 388 ret = fprintf (outfile, "execute select_trial;\n");
360 389
361 if (ret >= 0) 390 if (ret >= 0)
362 return GNUNET_OK; 391 return GNUNET_OK;
@@ -376,28 +405,33 @@ int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
376 */ 405 */
377int 406int
378add_generic_stat (const struct GNUNET_PeerIdentity *peer, 407add_generic_stat (const struct GNUNET_PeerIdentity *peer,
379 const char *name, 408 const char *name, const char *section, uint64_t value)
380 const char *section, uint64_t value)
381{ 409{
382 int ret; 410 int ret;
411
383 if (outfile == NULL) 412 if (outfile == NULL)
384 return GNUNET_SYSERR; 413 return GNUNET_SYSERR;
385 414
386 if (peer != NULL) 415 if (peer != NULL)
387 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&peer->hashPubKey)); 416 ret =
417 fprintf (outfile,
418 "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n",
419 GNUNET_h2s_full (&peer->hashPubKey));
388 else 420 else
389 ret = fprintf(outfile, "set @temp_node = 0;\n"); 421 ret = fprintf (outfile, "set @temp_node = 0;\n");
390 422
391 if (ret < 0) 423 if (ret < 0)
392 return GNUNET_SYSERR; 424 return GNUNET_SYSERR;
393 425
394 ret = fprintf(outfile, "set @temp_section = \"%s\", @temp_stat = \"%s\", @temp_value = %llu;\n", 426 ret =
395 section, name, (unsigned long long)value); 427 fprintf (outfile,
428 "set @temp_section = \"%s\", @temp_stat = \"%s\", @temp_value = %llu;\n",
429 section, name, (unsigned long long) value);
396 430
397 if (ret < 0) 431 if (ret < 0)
398 return GNUNET_SYSERR; 432 return GNUNET_SYSERR;
399 433
400 ret = fprintf(outfile, "execute insert_generic_stat;\n"); 434 ret = fprintf (outfile, "execute insert_generic_stat;\n");
401 435
402 if (ret < 0) 436 if (ret < 0)
403 return GNUNET_SYSERR; 437 return GNUNET_SYSERR;
@@ -436,43 +470,49 @@ add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
436 unsigned int data_inserts, unsigned int find_peer_requests, 470 unsigned int data_inserts, unsigned int find_peer_requests,
437 unsigned int find_peers_started, unsigned int gets_started, 471 unsigned int find_peers_started, unsigned int gets_started,
438 unsigned int puts_started, unsigned int find_peer_responses_received, 472 unsigned int puts_started, unsigned int find_peer_responses_received,
439 unsigned int get_responses_received, unsigned int find_peer_responses_sent, 473 unsigned int get_responses_received,
474 unsigned int find_peer_responses_sent,
440 unsigned int get_responses_sent) 475 unsigned int get_responses_sent)
441{ 476{
442 int ret; 477 int ret;
478
443 if (outfile == NULL) 479 if (outfile == NULL)
444 return GNUNET_SYSERR; 480 return GNUNET_SYSERR;
445 481
446 if (peer != NULL) 482 if (peer != NULL)
447 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&peer->hashPubKey)); 483 ret =
484 fprintf (outfile,
485 "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n",
486 GNUNET_h2s_full (&peer->hashPubKey));
448 else 487 else
449 ret = fprintf(outfile, "set @temp_node = 0;\n"); 488 ret = fprintf (outfile, "set @temp_node = 0;\n");
450 if (ret < 0) 489 if (ret < 0)
451 return GNUNET_SYSERR; 490 return GNUNET_SYSERR;
452 491
453 ret = fprintf(outfile, "set @r_r = %u, @r_f = %u, @res_r = %u, @c_r = %u, " 492 ret = fprintf (outfile, "set @r_r = %u, @r_f = %u, @res_r = %u, @c_r = %u, "
454 "@res_f = %u, @gets = %u, @puts = %u, @d_i = %u, " 493 "@res_f = %u, @gets = %u, @puts = %u, @d_i = %u, "
455 "@f_p_r = %u, @f_p_s = %u, @g_s = %u, @p_s = %u, " 494 "@f_p_r = %u, @f_p_s = %u, @g_s = %u, @p_s = %u, "
456 "@f_p_r_r = %u, @g_r_r = %u, @f_p_r_s = %u, @g_r_s = %u;\n", 495 "@f_p_r_r = %u, @g_r_r = %u, @f_p_r_s = %u, @g_r_s = %u;\n",
457 route_requests, route_forwards, result_requests, 496 route_requests, route_forwards, result_requests,
458 client_requests, result_forwards, gets, puts, 497 client_requests, result_forwards, gets, puts,
459 data_inserts, find_peer_requests, find_peers_started, 498 data_inserts, find_peer_requests, find_peers_started,
460 gets_started, puts_started, find_peer_responses_received, 499 gets_started, puts_started, find_peer_responses_received,
461 get_responses_received, find_peer_responses_sent, 500 get_responses_received, find_peer_responses_sent,
462 get_responses_sent); 501 get_responses_sent);
463 502
464 if (ret < 0) 503 if (ret < 0)
465 return GNUNET_SYSERR; 504 return GNUNET_SYSERR;
466 505
467 ret = fprintf(outfile, "execute insert_stat using " 506 ret = fprintf (outfile, "execute insert_stat using "
468 "@temp_trial, @temp_node, @r_r, @r_f, @res_r, @c_r, " 507 "@temp_trial, @temp_node, @r_r, @r_f, @res_r, @c_r, "
469 "@res_f, @gets, @puts, @d_i, " 508 "@res_f, @gets, @puts, @d_i, "
470 "@f_p_r, @f_p_s, @g_s, @p_s, " 509 "@f_p_r, @f_p_s, @g_s, @p_s, "
471 "@f_p_r_r, @g_r_r, @f_p_r_s, @g_r_s;\n"); 510 "@f_p_r_r, @g_r_r, @f_p_r_s, @g_r_s;\n");
472 if (ret < 0) 511 if (ret < 0)
473 return GNUNET_SYSERR; 512 return GNUNET_SYSERR;
474 return GNUNET_OK; 513 return GNUNET_OK;
475} 514}
515
476/* 516/*
477 * Inserts the specified dhtkey into the dhttests.dhtkeys table, 517 * Inserts the specified dhtkey into the dhttests.dhtkeys table,
478 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid 518 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
@@ -486,6 +526,7 @@ int
486add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey) 526add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
487{ 527{
488 int ret; 528 int ret;
529
489 if (dhtkeyuid != NULL) 530 if (dhtkeyuid != NULL)
490 *dhtkeyuid = 0; 531 *dhtkeyuid = 0;
491 532
@@ -493,13 +534,14 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
493 return GNUNET_SYSERR; 534 return GNUNET_SYSERR;
494 535
495 if (dhtkey != NULL) 536 if (dhtkey != NULL)
496 ret = fprintf(outfile, "set @dhtkey = \"%s\";\n", GNUNET_h2s_full(dhtkey)); 537 ret =
538 fprintf (outfile, "set @dhtkey = \"%s\";\n", GNUNET_h2s_full (dhtkey));
497 else 539 else
498 ret = fprintf(outfile, "set @dhtkey = XXXXX;\n"); 540 ret = fprintf (outfile, "set @dhtkey = XXXXX;\n");
499 541
500 if (ret < 0) 542 if (ret < 0)
501 return GNUNET_SYSERR; 543 return GNUNET_SYSERR;
502 ret = fprintf(outfile, "execute insert_dhtkey using @dhtkey;\n"); 544 ret = fprintf (outfile, "execute insert_dhtkey using @dhtkey;\n");
503 545
504 if (ret >= 0) 546 if (ret >= 0)
505 return GNUNET_OK; 547 return GNUNET_OK;
@@ -515,7 +557,7 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
515 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 557 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
516 */ 558 */
517int 559int
518add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) 560add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
519{ 561{
520 int ret; 562 int ret;
521 563
@@ -525,12 +567,14 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
525 if (outfile == NULL) 567 if (outfile == NULL)
526 return GNUNET_SYSERR; 568 return GNUNET_SYSERR;
527 569
528 ret = fprintf(outfile, "set @node = \"%s\";\n", GNUNET_h2s_full(&node->hashPubKey)); 570 ret =
571 fprintf (outfile, "set @node = \"%s\";\n",
572 GNUNET_h2s_full (&node->hashPubKey));
529 573
530 if (ret < 0) 574 if (ret < 0)
531 return GNUNET_SYSERR; 575 return GNUNET_SYSERR;
532 576
533 ret = fprintf(outfile, "execute insert_node using @node;\n"); 577 ret = fprintf (outfile, "execute insert_node using @node;\n");
534 578
535 if (ret >= 0) 579 if (ret >= 0)
536 return GNUNET_OK; 580 return GNUNET_OK;
@@ -552,12 +596,14 @@ update_trials (unsigned int gets_succeeded)
552 if (outfile == NULL) 596 if (outfile == NULL)
553 return GNUNET_SYSERR; 597 return GNUNET_SYSERR;
554 598
555 ret = fprintf(outfile, "set @date = \"%s\", @g_s = %u;\n", get_sql_time(), gets_succeeded); 599 ret =
600 fprintf (outfile, "set @date = \"%s\", @g_s = %u;\n", get_sql_time (),
601 gets_succeeded);
556 602
557 if (ret < 0) 603 if (ret < 0)
558 return GNUNET_SYSERR; 604 return GNUNET_SYSERR;
559 605
560 ret = fprintf(outfile, "execute update_trial using @date, @g_s;\n"); 606 ret = fprintf (outfile, "execute update_trial using @date, @g_s;\n");
561 607
562 if (ret >= 0) 608 if (ret >= 0)
563 return GNUNET_OK; 609 return GNUNET_OK;
@@ -582,12 +628,14 @@ set_malicious (struct GNUNET_PeerIdentity *peer)
582 if (outfile == NULL) 628 if (outfile == NULL)
583 return GNUNET_SYSERR; 629 return GNUNET_SYSERR;
584 630
585 ret = fprintf(outfile, "set @temp_node = \"%s\";\n", GNUNET_h2s_full(&peer->hashPubKey)); 631 ret =
632 fprintf (outfile, "set @temp_node = \"%s\";\n",
633 GNUNET_h2s_full (&peer->hashPubKey));
586 634
587 if (ret < 0) 635 if (ret < 0)
588 return GNUNET_SYSERR; 636 return GNUNET_SYSERR;
589 637
590 ret = fprintf(outfile, "execute set_malicious;\n"); 638 ret = fprintf (outfile, "execute set_malicious;\n");
591 639
592 if (ret >= 0) 640 if (ret >= 0)
593 return GNUNET_OK; 641 return GNUNET_OK;
@@ -611,12 +659,12 @@ add_connections (unsigned int totalConnections)
611 if (outfile == NULL) 659 if (outfile == NULL)
612 return GNUNET_SYSERR; 660 return GNUNET_SYSERR;
613 661
614 ret = fprintf(outfile, "set @conns = %u;\n", totalConnections); 662 ret = fprintf (outfile, "set @conns = %u;\n", totalConnections);
615 663
616 if (ret < 0) 664 if (ret < 0)
617 return GNUNET_SYSERR; 665 return GNUNET_SYSERR;
618 666
619 ret = fprintf(outfile, "execute update_conn using @conns;\n"); 667 ret = fprintf (outfile, "execute update_conn using @conns;\n");
620 668
621 if (ret >= 0) 669 if (ret >= 0)
622 return GNUNET_OK; 670 return GNUNET_OK;
@@ -636,15 +684,16 @@ int
636update_topology (unsigned int connections) 684update_topology (unsigned int connections)
637{ 685{
638 int ret; 686 int ret;
687
639 if (outfile == NULL) 688 if (outfile == NULL)
640 return GNUNET_SYSERR; 689 return GNUNET_SYSERR;
641 690
642 ret = fprintf(outfile, "set @temp_conns = %u;\n", connections); 691 ret = fprintf (outfile, "set @temp_conns = %u;\n", connections);
643 692
644 if (ret < 0) 693 if (ret < 0)
645 return GNUNET_SYSERR; 694 return GNUNET_SYSERR;
646 695
647 ret = fprintf(outfile, "execute update_topology using @temp_conns;\n"); 696 ret = fprintf (outfile, "execute update_topology using @temp_conns;\n");
648 697
649 if (ret >= 0) 698 if (ret >= 0)
650 return GNUNET_OK; 699 return GNUNET_OK;
@@ -668,7 +717,7 @@ update_topology (unsigned int connections)
668int 717int
669add_query (unsigned long long *sqlqueryuid, unsigned long long queryid, 718add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
670 unsigned int type, unsigned int hops, int succeeded, 719 unsigned int type, unsigned int hops, int succeeded,
671 const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode * key) 720 const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key)
672{ 721{
673 int ret; 722 int ret;
674 723
@@ -679,27 +728,38 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
679 *sqlqueryuid = 0; 728 *sqlqueryuid = 0;
680 729
681 if (key != NULL) 730 if (key != NULL)
682 ret = fprintf(outfile, "select dhtkeyuid from dhtkeys where trialuid = @temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n", GNUNET_h2s_full(key)); 731 ret =
732 fprintf (outfile,
733 "select dhtkeyuid from dhtkeys where trialuid = @temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n",
734 GNUNET_h2s_full (key));
683 else 735 else
684 ret = fprintf(outfile, "set @temp_dhtkey = 0;\n"); 736 ret = fprintf (outfile, "set @temp_dhtkey = 0;\n");
685 737
686 if (ret < 0) 738 if (ret < 0)
687 return GNUNET_SYSERR; 739 return GNUNET_SYSERR;
688 740
689 if (node != NULL) 741 if (node != NULL)
690 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&node->hashPubKey)); 742 ret =
743 fprintf (outfile,
744 "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n",
745 GNUNET_h2s_full (&node->hashPubKey));
691 else 746 else
692 ret = fprintf(outfile, "set @temp_node = 0;\n"); 747 ret = fprintf (outfile, "set @temp_node = 0;\n");
693 748
694 if (ret < 0) 749 if (ret < 0)
695 return GNUNET_SYSERR; 750 return GNUNET_SYSERR;
696 751
697 ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d, @time = \"%s\";\n", queryid, type, hops, succeeded, get_sql_time()); 752 ret =
753 fprintf (outfile,
754 "set @qid = %llu, @type = %u, @hops = %u, @succ = %d, @time = \"%s\";\n",
755 queryid, type, hops, succeeded, get_sql_time ());
698 756
699 if (ret < 0) 757 if (ret < 0)
700 return GNUNET_SYSERR; 758 return GNUNET_SYSERR;
701 759
702 ret = fprintf(outfile, "execute insert_query using @type, @hops, @temp_dhtkey, @qid, @succ, @temp_node, @time;\n"); 760 ret =
761 fprintf (outfile,
762 "execute insert_query using @type, @hops, @temp_dhtkey, @qid, @succ, @temp_node, @time;\n");
703 763
704 if (ret >= 0) 764 if (ret >= 0)
705 return GNUNET_OK; 765 return GNUNET_OK;
@@ -725,9 +785,10 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
725int 785int
726add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, 786add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
727 unsigned int type, unsigned int hops, 787 unsigned int type, unsigned int hops,
728 int succeeded, const struct GNUNET_PeerIdentity * node, 788 int succeeded, const struct GNUNET_PeerIdentity *node,
729 const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity * from_node, 789 const GNUNET_HashCode * key,
730 const struct GNUNET_PeerIdentity * to_node) 790 const struct GNUNET_PeerIdentity *from_node,
791 const struct GNUNET_PeerIdentity *to_node)
731{ 792{
732 int ret; 793 int ret;
733 794
@@ -738,43 +799,60 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
738 *sqlqueryuid = 0; 799 *sqlqueryuid = 0;
739 800
740 if (key != NULL) 801 if (key != NULL)
741 ret = fprintf(outfile, "select dhtkeyuid from dhtkeys where trialuid = @temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n", GNUNET_h2s_full(key)); 802 ret =
803 fprintf (outfile,
804 "select dhtkeyuid from dhtkeys where trialuid = @temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n",
805 GNUNET_h2s_full (key));
742 else 806 else
743 ret = fprintf(outfile, "set @temp_dhtkey = 0;\n"); 807 ret = fprintf (outfile, "set @temp_dhtkey = 0;\n");
744 808
745 if (ret < 0) 809 if (ret < 0)
746 return GNUNET_SYSERR; 810 return GNUNET_SYSERR;
747 811
748 if (node != NULL) 812 if (node != NULL)
749 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&node->hashPubKey)); 813 ret =
814 fprintf (outfile,
815 "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n",
816 GNUNET_h2s_full (&node->hashPubKey));
750 else 817 else
751 ret = fprintf(outfile, "set @temp_node = 0;\n"); 818 ret = fprintf (outfile, "set @temp_node = 0;\n");
752 819
753 if (ret < 0) 820 if (ret < 0)
754 return GNUNET_SYSERR; 821 return GNUNET_SYSERR;
755 822
756 if (from_node != NULL) 823 if (from_node != NULL)
757 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_from_node;\n", GNUNET_h2s_full(&from_node->hashPubKey)); 824 ret =
825 fprintf (outfile,
826 "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_from_node;\n",
827 GNUNET_h2s_full (&from_node->hashPubKey));
758 else 828 else
759 ret = fprintf(outfile, "set @temp_from_node = 0;\n"); 829 ret = fprintf (outfile, "set @temp_from_node = 0;\n");
760 830
761 if (ret < 0) 831 if (ret < 0)
762 return GNUNET_SYSERR; 832 return GNUNET_SYSERR;
763 833
764 if (to_node != NULL) 834 if (to_node != NULL)
765 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_to_node;\n", GNUNET_h2s_full(&to_node->hashPubKey)); 835 ret =
836 fprintf (outfile,
837 "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_to_node;\n",
838 GNUNET_h2s_full (&to_node->hashPubKey));
766 else 839 else
767 ret = fprintf(outfile, "set @temp_to_node = 0;\n"); 840 ret = fprintf (outfile, "set @temp_to_node = 0;\n");
768 841
769 if (ret < 0) 842 if (ret < 0)
770 return GNUNET_SYSERR; 843 return GNUNET_SYSERR;
771 844
772 ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n", queryid, type, hops, succeeded); 845 ret =
846 fprintf (outfile,
847 "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n",
848 queryid, type, hops, succeeded);
773 849
774 if (ret < 0) 850 if (ret < 0)
775 return GNUNET_SYSERR; 851 return GNUNET_SYSERR;
776 852
777 ret = fprintf(outfile, "execute insert_route using @type, @hops, @temp_dhtkey, @qid, @succ, @temp_node, @temp_from_node, @temp_to_node;\n"); 853 ret =
854 fprintf (outfile,
855 "execute insert_route using @type, @hops, @temp_dhtkey, @qid, @succ, @temp_node, @temp_from_node, @temp_to_node;\n");
778 856
779 if (ret >= 0) 857 if (ret >= 0)
780 return GNUNET_OK; 858 return GNUNET_OK;
@@ -790,7 +868,7 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
790 * @return the handle to the server, or NULL on error 868 * @return the handle to the server, or NULL on error
791 */ 869 */
792void * 870void *
793libgnunet_plugin_dhtlog_mysql_dump_init (void * cls) 871libgnunet_plugin_dhtlog_mysql_dump_init (void *cls)
794{ 872{
795 struct GNUNET_DHTLOG_Plugin *plugin = cls; 873 struct GNUNET_DHTLOG_Plugin *plugin = cls;
796 char *outfile_name; 874 char *outfile_name;
@@ -801,60 +879,59 @@ libgnunet_plugin_dhtlog_mysql_dump_init (void * cls)
801 cfg = plugin->cfg; 879 cfg = plugin->cfg;
802 max_varchar_len = 255; 880 max_varchar_len = 255;
803 881
804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL (DUMP) DHT Logger: initializing\n"); 882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
883 "MySQL (DUMP) DHT Logger: initializing\n");
805 884
806 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 885 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
807 "MYSQLDUMP", "PATH", 886 "MYSQLDUMP", "PATH",
808 &outfile_path)) 887 &outfile_path))
809 { 888 {
810 outfile_path = GNUNET_strdup(""); 889 outfile_path = GNUNET_strdup ("");
811 } 890 }
812 891
813 GNUNET_asprintf (&outfile_name, 892 GNUNET_asprintf (&outfile_name,
814 "%s%s-%d", 893 "%s%s-%d", outfile_path, "mysqldump", getpid ());
815 outfile_path,
816 "mysqldump",
817 getpid());
818 894
819 fn = GNUNET_STRINGS_filename_expand (outfile_name); 895 fn = GNUNET_STRINGS_filename_expand (outfile_name);
820 896
821 if (fn == NULL) 897 if (fn == NULL)
822 { 898 {
823 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 899 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
824 GNUNET_free(outfile_path); 900 _("Failed to get full path for `%s'\n"), outfile_name);
825 GNUNET_free(outfile_name); 901 GNUNET_free (outfile_path);
826 return NULL; 902 GNUNET_free (outfile_name);
827 } 903 return NULL;
828 904 }
829 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 905
906 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
830 outfile = FOPEN (fn, "w"); 907 outfile = FOPEN (fn, "w");
831 908
832 if (outfile == NULL) 909 if (outfile == NULL)
833 { 910 {
834 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 911 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
835 if (dirwarn) 912 if (dirwarn)
836 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 913 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
837 _("Failed to create or access directory for log file `%s'\n"), 914 _("Failed to create or access directory for log file `%s'\n"),
838 fn); 915 fn);
839 GNUNET_free(outfile_path); 916 GNUNET_free (outfile_path);
840 GNUNET_free(outfile_name); 917 GNUNET_free (outfile_name);
841 GNUNET_free (fn); 918 GNUNET_free (fn);
842 return NULL; 919 return NULL;
843 } 920 }
844 921
845 GNUNET_free (outfile_path); 922 GNUNET_free (outfile_path);
846 GNUNET_free (outfile_name); 923 GNUNET_free (outfile_name);
847 GNUNET_free (fn); 924 GNUNET_free (fn);
848 925
849 if (iopen () != GNUNET_OK) 926 if (iopen () != GNUNET_OK)
850 { 927 {
851 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 928 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
852 _("Failed to create file for dhtlog.\n")); 929 _("Failed to create file for dhtlog.\n"));
853 fclose (outfile); 930 fclose (outfile);
854 return NULL; 931 return NULL;
855 } 932 }
856 GNUNET_assert(plugin->dhtlog_api == NULL); 933 GNUNET_assert (plugin->dhtlog_api == NULL);
857 plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle)); 934 plugin->dhtlog_api = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Handle));
858 plugin->dhtlog_api->insert_trial = &add_trial; 935 plugin->dhtlog_api->insert_trial = &add_trial;
859 plugin->dhtlog_api->insert_round = &add_round; 936 plugin->dhtlog_api->insert_round = &add_round;
860 plugin->dhtlog_api->insert_round_details = &add_round_details; 937 plugin->dhtlog_api->insert_round_details = &add_round_details;
@@ -878,14 +955,14 @@ libgnunet_plugin_dhtlog_mysql_dump_init (void * cls)
878 * Shutdown the plugin. 955 * Shutdown the plugin.
879 */ 956 */
880void * 957void *
881libgnunet_plugin_dhtlog_mysql_dump_done (void * cls) 958libgnunet_plugin_dhtlog_mysql_dump_done (void *cls)
882{ 959{
883 struct GNUNET_DHTLOG_Handle *dhtlog_api = cls; 960 struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
885 "MySQL DHT Logger: database shutdown\n");
886 GNUNET_assert(dhtlog_api != NULL);
887 961
888 GNUNET_free(dhtlog_api); 962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database shutdown\n");
963 GNUNET_assert (dhtlog_api != NULL);
964
965 GNUNET_free (dhtlog_api);
889 return NULL; 966 return NULL;
890} 967}
891 968
diff --git a/src/dht/plugin_dhtlog_mysql_dump_load.c b/src/dht/plugin_dhtlog_mysql_dump_load.c
index 956af6bdd..7c3f67942 100644
--- a/src/dht/plugin_dhtlog_mysql_dump_load.c
+++ b/src/dht/plugin_dhtlog_mysql_dump_load.c
@@ -69,7 +69,7 @@ FILE *dhtkey_outfile;
69FILE *extended_topology_outfile; 69FILE *extended_topology_outfile;
70 70
71static char * 71static char *
72get_sql_time() 72get_sql_time ()
73{ 73{
74 static char date[DATE_STR_SIZE]; 74 static char date[DATE_STR_SIZE];
75 time_t timetmp; 75 time_t timetmp;
@@ -97,13 +97,19 @@ int
97add_topology (int num_connections) 97add_topology (int num_connections)
98{ 98{
99 int ret; 99 int ret;
100
100 if (outfile == NULL) 101 if (outfile == NULL)
101 return GNUNET_SYSERR; 102 return GNUNET_SYSERR;
102 103
103 ret = fprintf(outfile, "insert into topology (trialuid, date, connections) values (@temp_trial, \"%s\", %d);\n", get_sql_time(), num_connections); 104 ret =
105 fprintf (outfile,
106 "insert into topology (trialuid, date, connections) values (@temp_trial, \"%s\", %d);\n",
107 get_sql_time (), num_connections);
104 if (ret < 0) 108 if (ret < 0)
105 return GNUNET_SYSERR; 109 return GNUNET_SYSERR;
106 ret = fprintf(outfile, "select max(topology_uid) from topology into @temp_topology;\n"); 110 ret =
111 fprintf (outfile,
112 "select max(topology_uid) from topology into @temp_topology;\n");
107 if (ret >= 0) 113 if (ret >= 0)
108 return GNUNET_OK; 114 return GNUNET_OK;
109 return GNUNET_SYSERR; 115 return GNUNET_SYSERR;
@@ -117,13 +123,18 @@ add_topology (int num_connections)
117 * 123 *
118 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 124 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
119 */ 125 */
120int add_round (unsigned int round_type, unsigned int round_count) 126int
127add_round (unsigned int round_type, unsigned int round_count)
121{ 128{
122 int ret; 129 int ret;
130
123 if (outfile == NULL) 131 if (outfile == NULL)
124 return GNUNET_SYSERR; 132 return GNUNET_SYSERR;
125 133
126 ret = fprintf(outfile, "insert into rounds (trialuid, round_type, round_count, starttime) values (@temp_trial, \"%u\", \"%u\", \"%s\");\n", round_type, round_count, get_sql_time()); 134 ret =
135 fprintf (outfile,
136 "insert into rounds (trialuid, round_type, round_count, starttime) values (@temp_trial, \"%u\", \"%u\", \"%s\");\n",
137 round_type, round_count, get_sql_time ());
127 138
128 if (ret >= 0) 139 if (ret >= 0)
129 return GNUNET_OK; 140 return GNUNET_OK;
@@ -142,15 +153,21 @@ int add_round (unsigned int round_type, unsigned int round_count)
142 * 153 *
143 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 154 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
144 */ 155 */
145int add_round_details (unsigned int round_type, unsigned int round_count, 156int
146 unsigned int num_messages, unsigned int num_messages_succeeded) 157add_round_details (unsigned int round_type, unsigned int round_count,
158 unsigned int num_messages,
159 unsigned int num_messages_succeeded)
147{ 160{
148 int ret; 161 int ret;
162
149 if (outfile == NULL) 163 if (outfile == NULL)
150 return GNUNET_SYSERR; 164 return GNUNET_SYSERR;
151 165
152 ret = fprintf(outfile, "insert into processed_trial_rounds (trialuid, round_type, round_count, starttime, endtime, num_messages, num_messages_succeeded) values (@temp_trial, \"%u\", \"%u\", \"%s\", \"%s\", \"%u\", \"%u\");\n", 166 ret =
153 round_type, round_count, get_sql_time(), get_sql_time(), num_messages, num_messages_succeeded); 167 fprintf (outfile,
168 "insert into processed_trial_rounds (trialuid, round_type, round_count, starttime, endtime, num_messages, num_messages_succeeded) values (@temp_trial, \"%u\", \"%u\", \"%s\", \"%s\", \"%u\", \"%u\");\n",
169 round_type, round_count, get_sql_time (), get_sql_time (),
170 num_messages, num_messages_succeeded);
154 171
155 if (ret >= 0) 172 if (ret >= 0)
156 return GNUNET_OK; 173 return GNUNET_OK;
@@ -166,16 +183,23 @@ int add_round_details (unsigned int round_type, unsigned int round_count,
166 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 183 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
167 */ 184 */
168int 185int
169add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second) 186add_extended_topology (const struct GNUNET_PeerIdentity *first,
187 const struct GNUNET_PeerIdentity *second)
170{ 188{
171 int ret; 189 int ret;
190
172 if (outfile == NULL) 191 if (outfile == NULL)
173 return GNUNET_SYSERR; 192 return GNUNET_SYSERR;
174 193
175 ret = fprintf(extended_topology_outfile, "insert into extended_topology (topology_uid, uid_first, uid_second) values (%u, %s,", topology_count, GNUNET_h2s_full(&first->hashPubKey)); 194 ret =
195 fprintf (extended_topology_outfile,
196 "insert into extended_topology (topology_uid, uid_first, uid_second) values (%u, %s,",
197 topology_count, GNUNET_h2s_full (&first->hashPubKey));
176 if (ret < 0) 198 if (ret < 0)
177 return GNUNET_SYSERR; 199 return GNUNET_SYSERR;
178 ret = fprintf(extended_topology_outfile, "%s);\n", GNUNET_h2s_full(&second->hashPubKey)); 200 ret =
201 fprintf (extended_topology_outfile, "%s);\n",
202 GNUNET_h2s_full (&second->hashPubKey));
179 203
180 if (ret >= 0) 204 if (ret >= 0)
181 return GNUNET_OK; 205 return GNUNET_OK;
@@ -190,35 +214,46 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNU
190 * 214 *
191 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 215 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
192 */ 216 */
193int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) 217int
218add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
194{ 219{
195 int ret; 220 int ret;
221
196 if (outfile == NULL) 222 if (outfile == NULL)
197 return GNUNET_SYSERR; 223 return GNUNET_SYSERR;
198 224
199 ret = fprintf(outfile, "INSERT INTO trials " 225 ret = fprintf (outfile, "INSERT INTO trials "
200 "(starttime, other_trial_identifier, numnodes, topology," 226 "(starttime, other_trial_identifier, numnodes, topology,"
201 "blacklist_topology, connect_topology, connect_topology_option," 227 "blacklist_topology, connect_topology, connect_topology_option,"
202 "connect_topology_option_modifier, topology_percentage, topology_probability," 228 "connect_topology_option_modifier, topology_percentage, topology_probability,"
203 "puts, gets, " 229 "puts, gets, "
204 "concurrent, settle_time, num_rounds, malicious_getters," 230 "concurrent, settle_time, num_rounds, malicious_getters,"
205 "malicious_putters, malicious_droppers, malicious_get_frequency," 231 "malicious_putters, malicious_droppers, malicious_get_frequency,"
206 "malicious_put_frequency, stop_closest, stop_found, strict_kademlia, " 232 "malicious_put_frequency, stop_closest, stop_found, strict_kademlia, "
207 "gets_succeeded, message) " 233 "gets_succeeded, message) "
208 "VALUES (\"%s\", %u, %u, %u, %u, %u, %u, %f, %f, %f, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, \"%s\");\n", 234 "VALUES (\"%s\", %u, %u, %u, %u, %u, %u, %f, %f, %f, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, \"%s\");\n",
209 get_sql_time(), trial_info->other_identifier, trial_info->num_nodes, trial_info->topology, 235 get_sql_time (), trial_info->other_identifier,
210 trial_info->blacklist_topology, trial_info->connect_topology, 236 trial_info->num_nodes, trial_info->topology,
211 trial_info->connect_topology_option, trial_info->connect_topology_option_modifier, 237 trial_info->blacklist_topology, trial_info->connect_topology,
212 trial_info->topology_percentage, trial_info->topology_probability, 238 trial_info->connect_topology_option,
213 trial_info->puts, trial_info->gets, trial_info->concurrent, trial_info->settle_time, 239 trial_info->connect_topology_option_modifier,
214 trial_info->num_rounds, trial_info->malicious_getters, trial_info->malicious_putters, 240 trial_info->topology_percentage,
215 trial_info->malicious_droppers, trial_info->malicious_get_frequency, trial_info->malicious_put_frequency, 241 trial_info->topology_probability, trial_info->puts,
216 trial_info->stop_closest, trial_info->stop_found, trial_info->strict_kademlia, trial_info->gets_succeeded, trial_info->message); 242 trial_info->gets, trial_info->concurrent,
243 trial_info->settle_time, trial_info->num_rounds,
244 trial_info->malicious_getters, trial_info->malicious_putters,
245 trial_info->malicious_droppers,
246 trial_info->malicious_get_frequency,
247 trial_info->malicious_put_frequency, trial_info->stop_closest,
248 trial_info->stop_found, trial_info->strict_kademlia,
249 trial_info->gets_succeeded, trial_info->message);
217 250
218 if (ret < 0) 251 if (ret < 0)
219 return GNUNET_SYSERR; 252 return GNUNET_SYSERR;
220 253
221 ret = fprintf(outfile, "SELECT MAX( trialuid ) FROM trials into @temp_trial;\n"); 254 ret =
255 fprintf (outfile,
256 "SELECT MAX( trialuid ) FROM trials into @temp_trial;\n");
222 257
223 if (ret >= 0) 258 if (ret >= 0)
224 return GNUNET_OK; 259 return GNUNET_OK;
@@ -239,14 +274,15 @@ int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
239 */ 274 */
240int 275int
241add_generic_stat (const struct GNUNET_PeerIdentity *peer, 276add_generic_stat (const struct GNUNET_PeerIdentity *peer,
242 const char *name, 277 const char *name, const char *section, uint64_t value)
243 const char *section, uint64_t value)
244{ 278{
245 if (outfile == NULL) 279 if (outfile == NULL)
246 return GNUNET_SYSERR; 280 return GNUNET_SYSERR;
247 281
248 if (peer != NULL) 282 if (peer != NULL)
249 fprintf(generic_stat_outfile, "TRIALUID\t%s\t%s\t%s\t%llu\n", GNUNET_h2s_full(&peer->hashPubKey), section, name, (unsigned long long)value); 283 fprintf (generic_stat_outfile, "TRIALUID\t%s\t%s\t%s\t%llu\n",
284 GNUNET_h2s_full (&peer->hashPubKey), section, name,
285 (unsigned long long) value);
250 286
251 return GNUNET_OK; 287 return GNUNET_OK;
252} 288}
@@ -283,22 +319,25 @@ add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
283 unsigned int data_inserts, unsigned int find_peer_requests, 319 unsigned int data_inserts, unsigned int find_peer_requests,
284 unsigned int find_peers_started, unsigned int gets_started, 320 unsigned int find_peers_started, unsigned int gets_started,
285 unsigned int puts_started, unsigned int find_peer_responses_received, 321 unsigned int puts_started, unsigned int find_peer_responses_received,
286 unsigned int get_responses_received, unsigned int find_peer_responses_sent, 322 unsigned int get_responses_received,
323 unsigned int find_peer_responses_sent,
287 unsigned int get_responses_sent) 324 unsigned int get_responses_sent)
288{ 325{
289 int ret; 326 int ret;
327
290 if (outfile == NULL) 328 if (outfile == NULL)
291 return GNUNET_SYSERR; 329 return GNUNET_SYSERR;
292 330
293 if (peer != NULL) 331 if (peer != NULL)
294 ret = fprintf(stat_outfile, "TRIALUID\t%s\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\n", 332 ret =
295 GNUNET_h2s_full(&peer->hashPubKey), 333 fprintf (stat_outfile,
296 route_requests, route_forwards, result_requests, 334 "TRIALUID\t%s\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\n",
297 client_requests, result_forwards, gets, puts, 335 GNUNET_h2s_full (&peer->hashPubKey), route_requests,
298 data_inserts, find_peer_requests, find_peers_started, 336 route_forwards, result_requests, client_requests,
299 gets_started, puts_started, find_peer_responses_received, 337 result_forwards, gets, puts, data_inserts, find_peer_requests,
300 get_responses_received, find_peer_responses_sent, 338 find_peers_started, gets_started, puts_started,
301 get_responses_sent); 339 find_peer_responses_received, get_responses_received,
340 find_peer_responses_sent, get_responses_sent);
302 341
303 else 342 else
304 return GNUNET_SYSERR; 343 return GNUNET_SYSERR;
@@ -308,6 +347,7 @@ add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
308 else 347 else
309 return GNUNET_SYSERR; 348 return GNUNET_SYSERR;
310} 349}
350
311/* 351/*
312 * Inserts the specified dhtkey into the dhttests.dhtkeys table, 352 * Inserts the specified dhtkey into the dhttests.dhtkeys table,
313 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid 353 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
@@ -321,13 +361,14 @@ int
321add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey) 361add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
322{ 362{
323 int ret; 363 int ret;
364
324 if (dhtkeyuid != NULL) 365 if (dhtkeyuid != NULL)
325 *dhtkeyuid = 0; 366 *dhtkeyuid = 0;
326 367
327 if ((dhtkey_outfile == NULL) || (dhtkey == NULL)) 368 if ((dhtkey_outfile == NULL) || (dhtkey == NULL))
328 return GNUNET_SYSERR; 369 return GNUNET_SYSERR;
329 370
330 ret = fprintf(dhtkey_outfile, "TRIALUID\t%s\n", GNUNET_h2s_full(dhtkey)); 371 ret = fprintf (dhtkey_outfile, "TRIALUID\t%s\n", GNUNET_h2s_full (dhtkey));
331 372
332 if (ret >= 0) 373 if (ret >= 0)
333 return GNUNET_OK; 374 return GNUNET_OK;
@@ -344,15 +385,17 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
344 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 385 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
345 */ 386 */
346int 387int
347add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) 388add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
348{ 389{
349 int ret; 390 int ret;
350 391
351 if ((node == NULL) || (node_outfile == NULL)) 392 if ((node == NULL) || (node_outfile == NULL))
352 return GNUNET_SYSERR; 393 return GNUNET_SYSERR;
353 394
354 ret = fprintf(node_outfile, "TRIALUID\t%s\n", GNUNET_h2s_full(&node->hashPubKey)); 395 ret =
355 fflush(node_outfile); 396 fprintf (node_outfile, "TRIALUID\t%s\n",
397 GNUNET_h2s_full (&node->hashPubKey));
398 fflush (node_outfile);
356 if (ret >= 0) 399 if (ret >= 0)
357 return GNUNET_OK; 400 return GNUNET_OK;
358 return GNUNET_SYSERR; 401 return GNUNET_SYSERR;
@@ -373,8 +416,11 @@ update_trials (unsigned int gets_succeeded)
373 if (outfile == NULL) 416 if (outfile == NULL)
374 return GNUNET_SYSERR; 417 return GNUNET_SYSERR;
375 418
376 ret = fprintf(outfile, "update trials set endtime=\"%s\", gets_succeeded=%u where trialuid = @temp_trial;\n", get_sql_time(), gets_succeeded); 419 ret =
377 fflush(node_outfile); 420 fprintf (outfile,
421 "update trials set endtime=\"%s\", gets_succeeded=%u where trialuid = @temp_trial;\n",
422 get_sql_time (), gets_succeeded);
423 fflush (node_outfile);
378 if (ret >= 0) 424 if (ret >= 0)
379 return GNUNET_OK; 425 return GNUNET_OK;
380 else 426 else
@@ -398,8 +444,11 @@ set_malicious (struct GNUNET_PeerIdentity *peer)
398 if (outfile == NULL) 444 if (outfile == NULL)
399 return GNUNET_SYSERR; 445 return GNUNET_SYSERR;
400 446
401 ret = fprintf(outfile, "update nodes set malicious_dropper = 1 where trialuid = @temp_trial and nodeid = \"%s\";\n", GNUNET_h2s_full(&peer->hashPubKey)); 447 ret =
402 fflush(node_outfile); 448 fprintf (outfile,
449 "update nodes set malicious_dropper = 1 where trialuid = @temp_trial and nodeid = \"%s\";\n",
450 GNUNET_h2s_full (&peer->hashPubKey));
451 fflush (node_outfile);
403 if (ret >= 0) 452 if (ret >= 0)
404 return GNUNET_OK; 453 return GNUNET_OK;
405 else 454 else
@@ -422,8 +471,11 @@ add_connections (unsigned int totalConnections)
422 if (outfile == NULL) 471 if (outfile == NULL)
423 return GNUNET_SYSERR; 472 return GNUNET_SYSERR;
424 473
425 ret = fprintf(outfile, "update trials set totalConnections = %u where trialuid = @temp_trial;\n", totalConnections); 474 ret =
426 fflush(node_outfile); 475 fprintf (outfile,
476 "update trials set totalConnections = %u where trialuid = @temp_trial;\n",
477 totalConnections);
478 fflush (node_outfile);
427 if (ret >= 0) 479 if (ret >= 0)
428 return GNUNET_OK; 480 return GNUNET_OK;
429 else 481 else
@@ -442,10 +494,14 @@ int
442update_topology (unsigned int connections) 494update_topology (unsigned int connections)
443{ 495{
444 int ret; 496 int ret;
497
445 if (outfile == NULL) 498 if (outfile == NULL)
446 return GNUNET_SYSERR; 499 return GNUNET_SYSERR;
447 500
448 ret = fprintf(outfile, "update topology set connections = %u where topology_uid = @temp_topology;\n", connections); 501 ret =
502 fprintf (outfile,
503 "update topology set connections = %u where topology_uid = @temp_topology;\n",
504 connections);
449 topology_count++; 505 topology_count++;
450 if (ret >= 0) 506 if (ret >= 0)
451 return GNUNET_OK; 507 return GNUNET_OK;
@@ -469,7 +525,7 @@ update_topology (unsigned int connections)
469int 525int
470add_query (unsigned long long *sqlqueryuid, unsigned long long queryid, 526add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
471 unsigned int type, unsigned int hops, int succeeded, 527 unsigned int type, unsigned int hops, int succeeded,
472 const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode * key) 528 const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key)
473{ 529{
474 int ret; 530 int ret;
475 531
@@ -479,12 +535,15 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
479 if (sqlqueryuid != NULL) 535 if (sqlqueryuid != NULL)
480 *sqlqueryuid = 0; 536 *sqlqueryuid = 0;
481 537
482 ret = fprintf(query_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full(key)); 538 ret = fprintf (query_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full (key));
483 539
484 if (ret < 0) 540 if (ret < 0)
485 return GNUNET_SYSERR; 541 return GNUNET_SYSERR;
486 542
487 ret = fprintf(query_outfile, "%s\t%llu\t%u\t%u\t%u\t%s\n", GNUNET_h2s_full(&node->hashPubKey), queryid, type, hops, succeeded, get_sql_time()); 543 ret =
544 fprintf (query_outfile, "%s\t%llu\t%u\t%u\t%u\t%s\n",
545 GNUNET_h2s_full (&node->hashPubKey), queryid, type, hops,
546 succeeded, get_sql_time ());
488 547
489 if (ret >= 0) 548 if (ret >= 0)
490 return GNUNET_OK; 549 return GNUNET_OK;
@@ -510,9 +569,10 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
510int 569int
511add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, 570add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
512 unsigned int type, unsigned int hops, 571 unsigned int type, unsigned int hops,
513 int succeeded, const struct GNUNET_PeerIdentity * node, 572 int succeeded, const struct GNUNET_PeerIdentity *node,
514 const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity * from_node, 573 const GNUNET_HashCode * key,
515 const struct GNUNET_PeerIdentity * to_node) 574 const struct GNUNET_PeerIdentity *from_node,
575 const struct GNUNET_PeerIdentity *to_node)
516{ 576{
517 int ret; 577 int ret;
518 578
@@ -522,24 +582,31 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
522 if (sqlqueryuid != NULL) 582 if (sqlqueryuid != NULL)
523 *sqlqueryuid = 0; 583 *sqlqueryuid = 0;
524 584
525 ret = fprintf(route_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full(key)); 585 ret = fprintf (route_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full (key));
526 if (ret < 0) 586 if (ret < 0)
527 return GNUNET_SYSERR; 587 return GNUNET_SYSERR;
528 588
529 ret = fprintf(route_outfile, "%s\t", GNUNET_h2s_full(&node->hashPubKey)); 589 ret = fprintf (route_outfile, "%s\t", GNUNET_h2s_full (&node->hashPubKey));
530 if (ret < 0) 590 if (ret < 0)
531 return GNUNET_SYSERR; 591 return GNUNET_SYSERR;
532 if (from_node == NULL) 592 if (from_node == NULL)
533 ret = fprintf(route_outfile, "0\t"); 593 ret = fprintf (route_outfile, "0\t");
534 else 594 else
535 ret = fprintf(route_outfile, "%s\t", GNUNET_h2s_full(&from_node->hashPubKey)); 595 ret =
596 fprintf (route_outfile, "%s\t",
597 GNUNET_h2s_full (&from_node->hashPubKey));
536 if (ret < 0) 598 if (ret < 0)
537 return GNUNET_SYSERR; 599 return GNUNET_SYSERR;
538 600
539 if (to_node == NULL) 601 if (to_node == NULL)
540 ret = fprintf(route_outfile, "0\t%llu\t%u\t%u\t%d\n", queryid, type, hops, succeeded); 602 ret =
603 fprintf (route_outfile, "0\t%llu\t%u\t%u\t%d\n", queryid, type, hops,
604 succeeded);
541 else 605 else
542 ret = fprintf(route_outfile, "%s\t%llu\t%u\t%u\t%d\n", GNUNET_h2s_full(&to_node->hashPubKey), queryid, type, hops, succeeded); 606 ret =
607 fprintf (route_outfile, "%s\t%llu\t%u\t%u\t%d\n",
608 GNUNET_h2s_full (&to_node->hashPubKey), queryid, type, hops,
609 succeeded);
543 610
544 if (ret >= 0) 611 if (ret >= 0)
545 return GNUNET_OK; 612 return GNUNET_OK;
@@ -555,7 +622,7 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
555 * @return the handle to the server, or NULL on error 622 * @return the handle to the server, or NULL on error
556 */ 623 */
557void * 624void *
558libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls) 625libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
559{ 626{
560 struct GNUNET_DHTLOG_Plugin *plugin = cls; 627 struct GNUNET_DHTLOG_Plugin *plugin = cls;
561 char *outfile_name; 628 char *outfile_name;
@@ -566,287 +633,274 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
566 cfg = plugin->cfg; 633 cfg = plugin->cfg;
567 max_varchar_len = 255; 634 max_varchar_len = 255;
568 635
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL (DUMP) DHT Logger: initializing\n"); 636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
637 "MySQL (DUMP) DHT Logger: initializing\n");
570 638
571 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 639 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
572 "MYSQLDUMP", "PATH", 640 "MYSQLDUMP", "PATH",
573 &outfile_path)) 641 &outfile_path))
574 { 642 {
575 outfile_path = GNUNET_strdup(""); 643 outfile_path = GNUNET_strdup ("");
576 } 644 }
577 645
578 GNUNET_asprintf (&outfile_name, 646 GNUNET_asprintf (&outfile_name,
579 "%s%s-%d", 647 "%s%s-%d", outfile_path, "mysqldump", getpid ());
580 outfile_path,
581 "mysqldump",
582 getpid());
583 648
584 fn = GNUNET_STRINGS_filename_expand (outfile_name); 649 fn = GNUNET_STRINGS_filename_expand (outfile_name);
585 650
586 if (fn == NULL) 651 if (fn == NULL)
587 { 652 {
588 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 653 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
589 GNUNET_free(outfile_path); 654 _("Failed to get full path for `%s'\n"), outfile_name);
590 GNUNET_free(outfile_name); 655 GNUNET_free (outfile_path);
591 return NULL; 656 GNUNET_free (outfile_name);
592 } 657 return NULL;
593 658 }
594 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 659
660 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
595 outfile = FOPEN (fn, "w"); 661 outfile = FOPEN (fn, "w");
596 662
597 if (outfile == NULL) 663 if (outfile == NULL)
598 { 664 {
599 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 665 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
600 if (dirwarn) 666 if (dirwarn)
601 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 667 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
602 _("Failed to create or access directory for log file `%s'\n"), 668 _("Failed to create or access directory for log file `%s'\n"),
603 fn); 669 fn);
604 GNUNET_free(outfile_path); 670 GNUNET_free (outfile_path);
605 GNUNET_free(outfile_name); 671 GNUNET_free (outfile_name);
606 GNUNET_free (fn); 672 GNUNET_free (fn);
607 return NULL; 673 return NULL;
608 } 674 }
609 675
610 GNUNET_free(outfile_name); 676 GNUNET_free (outfile_name);
611 GNUNET_asprintf (&outfile_name, 677 GNUNET_asprintf (&outfile_name,
612 "%s%s-%d", 678 "%s%s-%d", outfile_path, "mysqldump_nodes", getpid ());
613 outfile_path, 679 GNUNET_free (fn);
614 "mysqldump_nodes",
615 getpid());
616 GNUNET_free(fn);
617 fn = GNUNET_STRINGS_filename_expand (outfile_name); 680 fn = GNUNET_STRINGS_filename_expand (outfile_name);
618 681
619 if (fn == NULL) 682 if (fn == NULL)
620 { 683 {
621 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 684 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
622 GNUNET_free(outfile_path); 685 _("Failed to get full path for `%s'\n"), outfile_name);
623 GNUNET_free(outfile_name); 686 GNUNET_free (outfile_path);
624 return NULL; 687 GNUNET_free (outfile_name);
625 } 688 return NULL;
626 689 }
627 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 690
691 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
628 node_outfile = FOPEN (fn, "w"); 692 node_outfile = FOPEN (fn, "w");
629 693
630 if (node_outfile == NULL) 694 if (node_outfile == NULL)
631 { 695 {
632 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 696 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
633 if (dirwarn) 697 if (dirwarn)
634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 698 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
635 _("Failed to create or access directory for log file `%s'\n"), 699 _("Failed to create or access directory for log file `%s'\n"),
636 fn); 700 fn);
637 GNUNET_free(outfile_path); 701 GNUNET_free (outfile_path);
638 GNUNET_free(outfile_name); 702 GNUNET_free (outfile_name);
639 GNUNET_free (fn); 703 GNUNET_free (fn);
640 return NULL; 704 return NULL;
641 } 705 }
642 706
643 GNUNET_free(outfile_name); 707 GNUNET_free (outfile_name);
644 GNUNET_asprintf (&outfile_name, 708 GNUNET_asprintf (&outfile_name,
645 "%s%s-%d", 709 "%s%s-%d", outfile_path, "mysqldump_routes", getpid ());
646 outfile_path,
647 "mysqldump_routes",
648 getpid());
649 710
650 GNUNET_free(fn); 711 GNUNET_free (fn);
651 fn = GNUNET_STRINGS_filename_expand (outfile_name); 712 fn = GNUNET_STRINGS_filename_expand (outfile_name);
652 713
653 if (fn == NULL) 714 if (fn == NULL)
654 { 715 {
655 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 716 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
656 GNUNET_free(outfile_path); 717 _("Failed to get full path for `%s'\n"), outfile_name);
657 GNUNET_free(outfile_name); 718 GNUNET_free (outfile_path);
658 return NULL; 719 GNUNET_free (outfile_name);
659 } 720 return NULL;
660 721 }
661 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 722
723 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
662 route_outfile = FOPEN (fn, "w"); 724 route_outfile = FOPEN (fn, "w");
663 725
664 if (route_outfile == NULL) 726 if (route_outfile == NULL)
665 { 727 {
666 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 728 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
667 if (dirwarn) 729 if (dirwarn)
668 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 730 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
669 _("Failed to create or access directory for log file `%s'\n"), 731 _("Failed to create or access directory for log file `%s'\n"),
670 fn); 732 fn);
671 GNUNET_free(outfile_path); 733 GNUNET_free (outfile_path);
672 GNUNET_free(outfile_name); 734 GNUNET_free (outfile_name);
673 GNUNET_free (fn); 735 GNUNET_free (fn);
674 return NULL; 736 return NULL;
675 } 737 }
676 738
677 GNUNET_free(outfile_name); 739 GNUNET_free (outfile_name);
678 GNUNET_asprintf (&outfile_name, 740 GNUNET_asprintf (&outfile_name,
679 "%s%s-%d", 741 "%s%s-%d", outfile_path, "mysqldump_queries", getpid ());
680 outfile_path,
681 "mysqldump_queries",
682 getpid());
683 742
684 GNUNET_free(fn); 743 GNUNET_free (fn);
685 fn = GNUNET_STRINGS_filename_expand (outfile_name); 744 fn = GNUNET_STRINGS_filename_expand (outfile_name);
686 745
687 if (fn == NULL) 746 if (fn == NULL)
688 { 747 {
689 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 748 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
690 GNUNET_free(outfile_path); 749 _("Failed to get full path for `%s'\n"), outfile_name);
691 GNUNET_free(outfile_name); 750 GNUNET_free (outfile_path);
692 return NULL; 751 GNUNET_free (outfile_name);
693 } 752 return NULL;
694 753 }
695 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 754
755 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
696 query_outfile = FOPEN (fn, "w"); 756 query_outfile = FOPEN (fn, "w");
697 757
698 if (query_outfile == NULL) 758 if (query_outfile == NULL)
699 { 759 {
700 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 760 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
701 if (dirwarn) 761 if (dirwarn)
702 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 762 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
703 _("Failed to create or access directory for log file `%s'\n"), 763 _("Failed to create or access directory for log file `%s'\n"),
704 fn); 764 fn);
705 GNUNET_free(outfile_path); 765 GNUNET_free (outfile_path);
706 GNUNET_free(outfile_name); 766 GNUNET_free (outfile_name);
707 GNUNET_free (fn); 767 GNUNET_free (fn);
708 return NULL; 768 return NULL;
709 } 769 }
710 770
711 GNUNET_free(outfile_name); 771 GNUNET_free (outfile_name);
712 GNUNET_asprintf (&outfile_name, 772 GNUNET_asprintf (&outfile_name,
713 "%s%s-%d", 773 "%s%s-%d", outfile_path, "mysqldump_stats", getpid ());
714 outfile_path,
715 "mysqldump_stats",
716 getpid());
717 774
718 GNUNET_free(fn); 775 GNUNET_free (fn);
719 fn = GNUNET_STRINGS_filename_expand (outfile_name); 776 fn = GNUNET_STRINGS_filename_expand (outfile_name);
720 777
721 if (fn == NULL) 778 if (fn == NULL)
722 { 779 {
723 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 780 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
724 GNUNET_free(outfile_path); 781 _("Failed to get full path for `%s'\n"), outfile_name);
725 GNUNET_free(outfile_name); 782 GNUNET_free (outfile_path);
726 return NULL; 783 GNUNET_free (outfile_name);
727 } 784 return NULL;
728 785 }
729 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 786
787 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
730 stat_outfile = FOPEN (fn, "w"); 788 stat_outfile = FOPEN (fn, "w");
731 789
732 if (stat_outfile == NULL) 790 if (stat_outfile == NULL)
733 { 791 {
734 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 792 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
735 if (dirwarn) 793 if (dirwarn)
736 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 794 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
737 _("Failed to create or access directory for log file `%s'\n"), 795 _("Failed to create or access directory for log file `%s'\n"),
738 fn); 796 fn);
739 GNUNET_free(outfile_path); 797 GNUNET_free (outfile_path);
740 GNUNET_free(outfile_name); 798 GNUNET_free (outfile_name);
741 GNUNET_free (fn); 799 GNUNET_free (fn);
742 return NULL; 800 return NULL;
743 } 801 }
744 802
745 GNUNET_free(outfile_name); 803 GNUNET_free (outfile_name);
746 GNUNET_asprintf (&outfile_name, 804 GNUNET_asprintf (&outfile_name,
747 "%s%s-%d", 805 "%s%s-%d",
748 outfile_path, 806 outfile_path, "mysqldump_generic_stats", getpid ());
749 "mysqldump_generic_stats", 807 GNUNET_free (fn);
750 getpid());
751 GNUNET_free(fn);
752 fn = GNUNET_STRINGS_filename_expand (outfile_name); 808 fn = GNUNET_STRINGS_filename_expand (outfile_name);
753 809
754 if (fn == NULL) 810 if (fn == NULL)
755 { 811 {
756 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 812 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
757 GNUNET_free(outfile_path); 813 _("Failed to get full path for `%s'\n"), outfile_name);
758 GNUNET_free(outfile_name); 814 GNUNET_free (outfile_path);
759 return NULL; 815 GNUNET_free (outfile_name);
760 } 816 return NULL;
761 817 }
762 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 818
819 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
763 generic_stat_outfile = FOPEN (fn, "w"); 820 generic_stat_outfile = FOPEN (fn, "w");
764 821
765 if (generic_stat_outfile == NULL) 822 if (generic_stat_outfile == NULL)
766 { 823 {
767 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 824 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
768 if (dirwarn) 825 if (dirwarn)
769 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 826 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
770 _("Failed to create or access directory for log file `%s'\n"), 827 _("Failed to create or access directory for log file `%s'\n"),
771 fn); 828 fn);
772 GNUNET_free(outfile_path); 829 GNUNET_free (outfile_path);
773 GNUNET_free(outfile_name); 830 GNUNET_free (outfile_name);
774 GNUNET_free (fn); 831 GNUNET_free (fn);
775 return NULL; 832 return NULL;
776 } 833 }
777 834
778 GNUNET_free(outfile_name); 835 GNUNET_free (outfile_name);
779 GNUNET_asprintf (&outfile_name, 836 GNUNET_asprintf (&outfile_name,
780 "%s%s-%d", 837 "%s%s-%d", outfile_path, "mysqldump_dhtkey", getpid ());
781 outfile_path, 838 GNUNET_free (fn);
782 "mysqldump_dhtkey",
783 getpid());
784 GNUNET_free(fn);
785 fn = GNUNET_STRINGS_filename_expand (outfile_name); 839 fn = GNUNET_STRINGS_filename_expand (outfile_name);
786 840
787 if (fn == NULL) 841 if (fn == NULL)
788 { 842 {
789 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 843 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
790 GNUNET_free(outfile_path); 844 _("Failed to get full path for `%s'\n"), outfile_name);
791 GNUNET_free(outfile_name); 845 GNUNET_free (outfile_path);
792 return NULL; 846 GNUNET_free (outfile_name);
793 } 847 return NULL;
794 848 }
795 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 849
850 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
796 dhtkey_outfile = FOPEN (fn, "w"); 851 dhtkey_outfile = FOPEN (fn, "w");
797 852
798 if (dhtkey_outfile == NULL) 853 if (dhtkey_outfile == NULL)
799 { 854 {
800 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 855 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
801 if (dirwarn) 856 if (dirwarn)
802 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 857 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
803 _("Failed to create or access directory for log file `%s'\n"), 858 _("Failed to create or access directory for log file `%s'\n"),
804 fn); 859 fn);
805 GNUNET_free(outfile_path); 860 GNUNET_free (outfile_path);
806 GNUNET_free(outfile_name); 861 GNUNET_free (outfile_name);
807 GNUNET_free (fn); 862 GNUNET_free (fn);
808 return NULL; 863 return NULL;
809 } 864 }
810 865
811 GNUNET_free(outfile_name); 866 GNUNET_free (outfile_name);
812 GNUNET_asprintf (&outfile_name, 867 GNUNET_asprintf (&outfile_name,
813 "%s%s-%d", 868 "%s%s-%d",
814 outfile_path, 869 outfile_path, "mysqldump_extended_topology", getpid ());
815 "mysqldump_extended_topology", 870 GNUNET_free (fn);
816 getpid());
817 GNUNET_free(fn);
818 fn = GNUNET_STRINGS_filename_expand (outfile_name); 871 fn = GNUNET_STRINGS_filename_expand (outfile_name);
819 872
820 if (fn == NULL) 873 if (fn == NULL)
821 { 874 {
822 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name); 875 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
823 GNUNET_free(outfile_path); 876 _("Failed to get full path for `%s'\n"), outfile_name);
824 GNUNET_free(outfile_name); 877 GNUNET_free (outfile_path);
825 return NULL; 878 GNUNET_free (outfile_name);
826 } 879 return NULL;
827 880 }
828 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 881
882 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
829 extended_topology_outfile = FOPEN (fn, "w"); 883 extended_topology_outfile = FOPEN (fn, "w");
830 884
831 if (extended_topology_outfile == NULL) 885 if (extended_topology_outfile == NULL)
832 { 886 {
833 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 887 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
834 if (dirwarn) 888 if (dirwarn)
835 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 889 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
836 _("Failed to create or access directory for log file `%s'\n"), 890 _("Failed to create or access directory for log file `%s'\n"),
837 fn); 891 fn);
838 GNUNET_free(outfile_path); 892 GNUNET_free (outfile_path);
839 GNUNET_free(outfile_name); 893 GNUNET_free (outfile_name);
840 GNUNET_free (fn); 894 GNUNET_free (fn);
841 return NULL; 895 return NULL;
842 } 896 }
843 897
844 GNUNET_free (outfile_path); 898 GNUNET_free (outfile_path);
845 GNUNET_free (outfile_name); 899 GNUNET_free (outfile_name);
846 GNUNET_free (fn); 900 GNUNET_free (fn);
847 901
848 GNUNET_assert(plugin->dhtlog_api == NULL); 902 GNUNET_assert (plugin->dhtlog_api == NULL);
849 plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle)); 903 plugin->dhtlog_api = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Handle));
850 plugin->dhtlog_api->insert_trial = &add_trial; 904 plugin->dhtlog_api->insert_trial = &add_trial;
851 plugin->dhtlog_api->insert_stat = &add_stat; 905 plugin->dhtlog_api->insert_stat = &add_stat;
852 plugin->dhtlog_api->insert_round = &add_round; 906 plugin->dhtlog_api->insert_round = &add_round;
@@ -870,21 +924,21 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
870 * Shutdown the plugin. 924 * Shutdown the plugin.
871 */ 925 */
872void * 926void *
873libgnunet_plugin_dhtlog_mysql_dump_load_done (void * cls) 927libgnunet_plugin_dhtlog_mysql_dump_load_done (void *cls)
874{ 928{
875 struct GNUNET_DHTLOG_Handle *dhtlog_api = cls; 929 struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 930
877 "MySQL DHT Logger: database shutdown\n"); 931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database shutdown\n");
878 GNUNET_assert(dhtlog_api != NULL); 932 GNUNET_assert (dhtlog_api != NULL);
879 933
880 fclose(outfile); 934 fclose (outfile);
881 fclose(node_outfile); 935 fclose (node_outfile);
882 fclose(query_outfile); 936 fclose (query_outfile);
883 fclose(route_outfile); 937 fclose (route_outfile);
884 fclose(stat_outfile); 938 fclose (stat_outfile);
885 fclose(generic_stat_outfile); 939 fclose (generic_stat_outfile);
886 fclose(extended_topology_outfile); 940 fclose (extended_topology_outfile);
887 GNUNET_free(dhtlog_api); 941 GNUNET_free (dhtlog_api);
888 return NULL; 942 return NULL;
889} 943}
890 944
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index 4450cb653..407e2279b 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -112,7 +112,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
112 die_task = GNUNET_SCHEDULER_NO_TASK; 112 die_task = GNUNET_SCHEDULER_NO_TASK;
113 GNUNET_DHT_disconnect (p1.dht_handle); 113 GNUNET_DHT_disconnect (p1.dht_handle);
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
115 "DHT disconnected, returning success!\n"); 115 "DHT disconnected, returning success!\n");
116 ok = 0; 116 ok = 0;
117} 117}
118 118
@@ -138,20 +138,20 @@ end_badly ()
138 fprintf (stderr, "Ending on an unhappy note.\n"); 138 fprintf (stderr, "Ending on an unhappy note.\n");
139#endif 139#endif
140 140
141 if ( (retry_context.peer_ctx != NULL) && 141 if ((retry_context.peer_ctx != NULL) &&
142 (retry_context.peer_ctx->find_peer_handle != NULL) ) 142 (retry_context.peer_ctx->find_peer_handle != NULL))
143 { 143 {
144 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping find peer request!\n"); 144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping find peer request!\n");
145 GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle); 145 GNUNET_DHT_find_peer_stop (retry_context.peer_ctx->find_peer_handle);
146 } 146 }
147 if ( (retry_context.peer_ctx != NULL) && 147 if ((retry_context.peer_ctx != NULL) &&
148 (retry_context.peer_ctx->get_handle != NULL) ) 148 (retry_context.peer_ctx->get_handle != NULL))
149 { 149 {
150 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping get request!\n"); 150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping get request!\n");
151 GNUNET_DHT_get_stop (retry_context.peer_ctx->get_handle); 151 GNUNET_DHT_get_stop (retry_context.peer_ctx->get_handle);
152 } 152 }
153 if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK) 153 if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK)
154 GNUNET_SCHEDULER_cancel(retry_context.retry_task); 154 GNUNET_SCHEDULER_cancel (retry_context.retry_task);
155 GNUNET_DHT_disconnect (p1.dht_handle); 155 GNUNET_DHT_disconnect (p1.dht_handle);
156 ok = 1; 156 ok = 1;
157} 157}
@@ -169,13 +169,13 @@ test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169 struct PeerContext *peer = cls; 169 struct PeerContext *peer = cls;
170 170
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); 171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n");
172 if ( (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) 172 if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
173 { 173 {
174 GNUNET_break (0); 174 GNUNET_break (0);
175 GNUNET_SCHEDULER_cancel (die_task); 175 GNUNET_SCHEDULER_cancel (die_task);
176 GNUNET_SCHEDULER_add_now (&end_badly, NULL); 176 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
177 return; 177 return;
178 } 178 }
179 179
180 GNUNET_assert (peer->dht_handle != NULL); 180 GNUNET_assert (peer->dht_handle != NULL);
181 181
@@ -183,12 +183,14 @@ test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183 peer->find_peer_handle = NULL; 183 peer->find_peer_handle = NULL;
184 184
185#if HAVE_MALICIOUS 185#if HAVE_MALICIOUS
186 GNUNET_DHT_set_malicious_getter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS, NULL, NULL); 186 GNUNET_DHT_set_malicious_getter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS,
187 GNUNET_DHT_set_malicious_putter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS, NULL, NULL); 187 NULL, NULL);
188 GNUNET_DHT_set_malicious_putter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS,
189 NULL, NULL);
188 GNUNET_DHT_set_malicious_dropper (peer->dht_handle, NULL, NULL); 190 GNUNET_DHT_set_malicious_dropper (peer->dht_handle, NULL, NULL);
189#endif 191#endif
190 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), 192 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
191 &end, &p1); 193 (GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1);
192} 194}
193 195
194 196
@@ -200,32 +202,33 @@ test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
200 * @param peer the peer we learned about 202 * @param peer the peer we learned about
201 * @param reply response 203 * @param reply response
202 */ 204 */
203void test_find_peer_processor (void *cls, 205void
204 const struct GNUNET_HELLO_Message *hello) 206test_find_peer_processor (void *cls, const struct GNUNET_HELLO_Message *hello)
205{ 207{
206 struct RetryContext *retry_ctx = cls; 208 struct RetryContext *retry_ctx = cls;
207 struct GNUNET_PeerIdentity peer; 209 struct GNUNET_PeerIdentity peer;
208 210
209 if (GNUNET_OK == GNUNET_HELLO_get_id(hello, &peer)) 211 if (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer))
210 { 212 {
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "test_find_peer_processor called (peer `%s'), stopping find peer request!\n", GNUNET_i2s(&peer)); 214 "test_find_peer_processor called (peer `%s'), stopping find peer request!\n",
213 215 GNUNET_i2s (&peer));
214 if (retry_ctx->retry_task != GNUNET_SCHEDULER_NO_TASK)
215 {
216 GNUNET_SCHEDULER_cancel(retry_ctx->retry_task);
217 retry_ctx->retry_task = GNUNET_SCHEDULER_NO_TASK;
218 }
219 216
220 GNUNET_SCHEDULER_add_continuation (&test_find_peer_stop, &p1, 217 if (retry_ctx->retry_task != GNUNET_SCHEDULER_NO_TASK)
221 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
222 }
223 else
224 { 218 {
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 219 GNUNET_SCHEDULER_cancel (retry_ctx->retry_task);
226 "received find peer request, but hello_get_id failed!\n"); 220 retry_ctx->retry_task = GNUNET_SCHEDULER_NO_TASK;
227 } 221 }
228 222
223 GNUNET_SCHEDULER_add_continuation (&test_find_peer_stop, &p1,
224 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
225 }
226 else
227 {
228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
229 "received find peer request, but hello_get_id failed!\n");
230 }
231
229} 232}
230 233
231/** 234/**
@@ -248,35 +251,40 @@ retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
248{ 251{
249 struct RetryContext *retry_ctx = cls; 252 struct RetryContext *retry_ctx = cls;
250 GNUNET_HashCode hash; 253 GNUNET_HashCode hash;
254
251 memset (&hash, 42, sizeof (GNUNET_HashCode)); 255 memset (&hash, 42, sizeof (GNUNET_HashCode));
252 256
253 if (GNUNET_TIME_absolute_get_remaining(retry_ctx->real_timeout).rel_value > 0) 257 if (GNUNET_TIME_absolute_get_remaining (retry_ctx->real_timeout).rel_value >
254 { 258 0)
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 259 {
256 "test_find_peer timed out, retrying!\n"); 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
257 retry_ctx->next_timeout = GNUNET_TIME_relative_multiply(retry_ctx->next_timeout, 2); 261 "test_find_peer timed out, retrying!\n");
258 retry_ctx->peer_ctx->find_peer_handle 262 retry_ctx->next_timeout =
259 = GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle, 263 GNUNET_TIME_relative_multiply (retry_ctx->next_timeout, 2);
260 retry_ctx->next_timeout, &hash, 264 retry_ctx->peer_ctx->find_peer_handle =
261 GNUNET_DHT_RO_NONE, 265 GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle,
262 &test_find_peer_processor, retry_ctx); 266 retry_ctx->next_timeout, &hash,
263 } 267 GNUNET_DHT_RO_NONE,
268 &test_find_peer_processor, retry_ctx);
269 }
264 else 270 else
265 { 271 {
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
267 "test_find_peer timed out for good, failing!\n"); 273 "test_find_peer timed out for good, failing!\n");
268 274
269 retry_ctx->peer_ctx->find_peer_handle = NULL; 275 retry_ctx->peer_ctx->find_peer_handle = NULL;
270 } 276 }
271 277
272 if (retry_ctx->peer_ctx->find_peer_handle == NULL) 278 if (retry_ctx->peer_ctx->find_peer_handle == NULL)
273 { 279 {
274 GNUNET_break (0); 280 GNUNET_break (0);
275 GNUNET_SCHEDULER_cancel (die_task); 281 GNUNET_SCHEDULER_cancel (die_task);
276 GNUNET_SCHEDULER_add_now (&end_badly, &p1); 282 GNUNET_SCHEDULER_add_now (&end_badly, &p1);
277 return; 283 return;
278 } 284 }
279 retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(retry_ctx->next_timeout, &retry_find_peer_stop, retry_ctx); 285 retry_ctx->retry_task =
286 GNUNET_SCHEDULER_add_delayed (retry_ctx->next_timeout,
287 &retry_find_peer_stop, retry_ctx);
280} 288}
281 289
282/** 290/**
@@ -290,13 +298,14 @@ retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
290{ 298{
291 struct RetryContext *retry_ctx = cls; 299 struct RetryContext *retry_ctx = cls;
292 GNUNET_HashCode hash; 300 GNUNET_HashCode hash;
301
293 memset (&hash, 42, sizeof (GNUNET_HashCode)); 302 memset (&hash, 42, sizeof (GNUNET_HashCode));
294 303
295 if (retry_ctx->peer_ctx->find_peer_handle != NULL) 304 if (retry_ctx->peer_ctx->find_peer_handle != NULL)
296 { 305 {
297 GNUNET_DHT_find_peer_stop(retry_ctx->peer_ctx->find_peer_handle); 306 GNUNET_DHT_find_peer_stop (retry_ctx->peer_ctx->find_peer_handle);
298 retry_ctx->peer_ctx->find_peer_handle = NULL; 307 retry_ctx->peer_ctx->find_peer_handle = NULL;
299 } 308 }
300 GNUNET_SCHEDULER_add_now (&retry_find_peer, retry_ctx); 309 GNUNET_SCHEDULER_add_now (&retry_find_peer, retry_ctx);
301} 310}
302 311
@@ -311,29 +320,32 @@ test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
311{ 320{
312 struct PeerContext *peer = cls; 321 struct PeerContext *peer = cls;
313 GNUNET_HashCode hash; 322 GNUNET_HashCode hash;
323
314 memset (&hash, 42, sizeof (GNUNET_HashCode)); 324 memset (&hash, 42, sizeof (GNUNET_HashCode));
315 325
316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n"); 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n");
317 GNUNET_assert (peer->dht_handle != NULL); 327 GNUNET_assert (peer->dht_handle != NULL);
318 328
319 retry_context.real_timeout = GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT); 329 retry_context.real_timeout = GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT);
320 retry_context.next_timeout = BASE_TIMEOUT; 330 retry_context.next_timeout = BASE_TIMEOUT;
321 retry_context.peer_ctx = peer; 331 retry_context.peer_ctx = peer;
322 332
323 peer->find_peer_handle 333 peer->find_peer_handle
324 = GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout, 334 =
325 &hash, 335 GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout,
326 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 336 &hash, GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
327 &test_find_peer_processor, &retry_context); 337 &test_find_peer_processor, &retry_context);
328 338
329 if (peer->find_peer_handle == NULL) 339 if (peer->find_peer_handle == NULL)
330 { 340 {
331 GNUNET_break (0); 341 GNUNET_break (0);
332 GNUNET_SCHEDULER_cancel (die_task); 342 GNUNET_SCHEDULER_cancel (die_task);
333 GNUNET_SCHEDULER_add_now (&end_badly, &p1); 343 GNUNET_SCHEDULER_add_now (&end_badly, &p1);
334 return; 344 return;
335 } 345 }
336 retry_context.retry_task = GNUNET_SCHEDULER_add_delayed(retry_context.next_timeout, &retry_find_peer_stop, &retry_context); 346 retry_context.retry_task =
347 GNUNET_SCHEDULER_add_delayed (retry_context.next_timeout,
348 &retry_find_peer_stop, &retry_context);
337} 349}
338 350
339/** 351/**
@@ -348,28 +360,26 @@ test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
348 struct PeerContext *peer = cls; 360 struct PeerContext *peer = cls;
349 361
350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); 362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n");
351 if ( (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) 363 if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
352 { 364 {
353 GNUNET_break (0); 365 GNUNET_break (0);
354 GNUNET_SCHEDULER_cancel (die_task); 366 GNUNET_SCHEDULER_cancel (die_task);
355 GNUNET_SCHEDULER_add_now (&end_badly, NULL); 367 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
356 return; 368 return;
357 } 369 }
358 GNUNET_assert (peer->dht_handle != NULL); 370 GNUNET_assert (peer->dht_handle != NULL);
359 GNUNET_DHT_get_stop (peer->get_handle); 371 GNUNET_DHT_get_stop (peer->get_handle);
360 peer->get_handle = NULL; 372 peer->get_handle = NULL;
361 GNUNET_SCHEDULER_add_now(&test_find_peer, 373 GNUNET_SCHEDULER_add_now (&test_find_peer, &p1);
362 &p1);
363} 374}
364 375
365void 376void
366test_get_iterator (void *cls, 377test_get_iterator (void *cls,
367 struct GNUNET_TIME_Absolute exp, 378 struct GNUNET_TIME_Absolute exp,
368 const GNUNET_HashCode * key, 379 const GNUNET_HashCode * key,
369 const struct GNUNET_PeerIdentity * const *get_path, 380 const struct GNUNET_PeerIdentity *const *get_path,
370 const struct GNUNET_PeerIdentity * const *put_path, 381 const struct GNUNET_PeerIdentity *const *put_path,
371 enum GNUNET_BLOCK_Type type, 382 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
372 size_t size, const void *data)
373{ 383{
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "test_get_iterator called (we got a result), stopping get request!\n"); 385 "test_get_iterator called (we got a result), stopping get request!\n");
@@ -389,32 +399,31 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
389{ 399{
390 struct PeerContext *peer = cls; 400 struct PeerContext *peer = cls;
391 GNUNET_HashCode hash; 401 GNUNET_HashCode hash;
402
392 memset (&hash, 42, sizeof (GNUNET_HashCode)); 403 memset (&hash, 42, sizeof (GNUNET_HashCode));
393 404
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get!\n"); 405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get!\n");
395 406
396 GNUNET_assert (peer->dht_handle != NULL); 407 GNUNET_assert (peer->dht_handle != NULL);
397 retry_context.real_timeout = GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT); 408 retry_context.real_timeout = GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT);
398 retry_context.next_timeout = BASE_TIMEOUT; 409 retry_context.next_timeout = BASE_TIMEOUT;
399 410
400 peer->get_handle = 411 peer->get_handle =
401 GNUNET_DHT_get_start (peer->dht_handle, 412 GNUNET_DHT_get_start (peer->dht_handle,
402 TOTAL_TIMEOUT, 413 TOTAL_TIMEOUT,
403 GNUNET_BLOCK_TYPE_TEST, 414 GNUNET_BLOCK_TYPE_TEST,
404 &hash, 415 &hash,
405 DEFAULT_GET_REPLICATION, 416 DEFAULT_GET_REPLICATION,
406 GNUNET_DHT_RO_NONE, 417 GNUNET_DHT_RO_NONE,
407 NULL, 0, 418 NULL, 0, NULL, 0, &test_get_iterator, NULL);
408 NULL, 0,
409 &test_get_iterator, NULL);
410 419
411 if (peer->get_handle == NULL) 420 if (peer->get_handle == NULL)
412 { 421 {
413 GNUNET_break (0); 422 GNUNET_break (0);
414 GNUNET_SCHEDULER_cancel (die_task); 423 GNUNET_SCHEDULER_cancel (die_task);
415 GNUNET_SCHEDULER_add_now (&end_badly, &p1); 424 GNUNET_SCHEDULER_add_now (&end_badly, &p1);
416 return; 425 return;
417 } 426 }
418 427
419 retry_context.peer_ctx = peer; 428 retry_context.peer_ctx = peer;
420} 429}
@@ -432,6 +441,7 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
432 GNUNET_HashCode hash; 441 GNUNET_HashCode hash;
433 char *data; 442 char *data;
434 size_t data_size = 42; 443 size_t data_size = 42;
444
435 memset (&hash, 42, sizeof (GNUNET_HashCode)); 445 memset (&hash, 42, sizeof (GNUNET_HashCode));
436 data = GNUNET_malloc (data_size); 446 data = GNUNET_malloc (data_size);
437 memset (data, 43, data_size); 447 memset (data, 43, data_size);
@@ -440,15 +450,14 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
440 450
441 GNUNET_assert (peer->dht_handle != NULL); 451 GNUNET_assert (peer->dht_handle != NULL);
442 452
443 GNUNET_DHT_put (peer->dht_handle, &hash, 453 GNUNET_DHT_put (peer->dht_handle, &hash,
444 DEFAULT_PUT_REPLICATION, 454 DEFAULT_PUT_REPLICATION,
445 GNUNET_DHT_RO_NONE, 455 GNUNET_DHT_RO_NONE,
446 GNUNET_BLOCK_TYPE_TEST, 456 GNUNET_BLOCK_TYPE_TEST,
447 data_size, data, 457 data_size, data,
448 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), 458 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT),
449 TOTAL_TIMEOUT, 459 TOTAL_TIMEOUT, &test_get, &p1);
450 &test_get, &p1); 460 GNUNET_free (data);
451 GNUNET_free(data);
452} 461}
453 462
454static void 463static void
@@ -457,11 +466,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
457 p->cfg = GNUNET_CONFIGURATION_create (); 466 p->cfg = GNUNET_CONFIGURATION_create ();
458#if START_ARM 467#if START_ARM
459 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 468 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
460 "gnunet-service-arm", 469 "gnunet-service-arm",
461#if VERBOSE_ARM 470#if VERBOSE_ARM
462 "-L", "DEBUG", 471 "-L", "DEBUG",
463#endif 472#endif
464 "-c", cfgname, NULL); 473 "-c", cfgname, NULL);
465#endif 474#endif
466 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 475 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
467 476
@@ -482,8 +491,7 @@ run (void *cls,
482 setup_peer (&p1, "test_dht_api_peer1.conf"); 491 setup_peer (&p1, "test_dht_api_peer1.conf");
483 492
484 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 493 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
485 (GNUNET_TIME_UNIT_SECONDS, 1), &test_put, 494 (GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
486 &p1);
487} 495}
488 496
489static int 497static int
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c
index d05901a2a..3bbf44be1 100644
--- a/src/dht/test_dht_multipeer.c
+++ b/src/dht/test_dht_multipeer.c
@@ -217,11 +217,12 @@ static char *blacklist_transports;
217 217
218static enum GNUNET_TESTING_Topology topology; 218static enum GNUNET_TESTING_Topology topology;
219 219
220static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */ 220static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
221 221
222static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ 222static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
223 223
224static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; 224static enum GNUNET_TESTING_TopologyOption connect_topology_option =
225 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
225 226
226static double connect_topology_option_modifier = 0.0; 227static double connect_topology_option_modifier = 0.0;
227 228
@@ -231,25 +232,26 @@ static int ok;
231/** 232/**
232 * Check whether peers successfully shut down. 233 * Check whether peers successfully shut down.
233 */ 234 */
234void shutdown_callback (void *cls, 235void
235 const char *emsg) 236shutdown_callback (void *cls, const char *emsg)
236{ 237{
237 if (emsg != NULL) 238 if (emsg != NULL)
238 { 239 {
239 if (ok == 0) 240 if (ok == 0)
240 ok = 2; 241 ok = 2;
241 } 242 }
242} 243}
243 244
244/** 245/**
245 * Task to release DHT handles for PUT 246 * Task to release DHT handles for PUT
246 */ 247 */
247static void 248static void
248put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 249put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
249{ 250{
250 struct TestPutContext *test_put = cls; 251 struct TestPutContext *test_put = cls;
252
251 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 253 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
252 GNUNET_DHT_disconnect(test_put->dht_handle); 254 GNUNET_DHT_disconnect (test_put->dht_handle);
253 test_put->dht_handle = NULL; 255 test_put->dht_handle = NULL;
254} 256}
255 257
@@ -258,31 +260,31 @@ put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
258 * testcase. 260 * testcase.
259 */ 261 */
260static void 262static void
261finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 263finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
262{ 264{
263 GNUNET_assert (pg != NULL); 265 GNUNET_assert (pg != NULL);
264 struct TestPutContext *test_put = all_puts; 266 struct TestPutContext *test_put = all_puts;
265 struct TestGetContext *test_get = all_gets; 267 struct TestGetContext *test_get = all_gets;
266 268
267 while (test_put != NULL) 269 while (test_put != NULL)
268 { 270 {
269 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 271 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
270 GNUNET_SCHEDULER_cancel(test_put->disconnect_task); 272 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
271 if (test_put->dht_handle != NULL) 273 if (test_put->dht_handle != NULL)
272 GNUNET_DHT_disconnect(test_put->dht_handle); 274 GNUNET_DHT_disconnect (test_put->dht_handle);
273 test_put = test_put->next; 275 test_put = test_put->next;
274 } 276 }
275 277
276 while (test_get != NULL) 278 while (test_get != NULL)
277 { 279 {
278 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 280 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
279 GNUNET_SCHEDULER_cancel(test_get->disconnect_task); 281 GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
280 if (test_get->get_handle != NULL) 282 if (test_get->get_handle != NULL)
281 GNUNET_DHT_get_stop(test_get->get_handle); 283 GNUNET_DHT_get_stop (test_get->get_handle);
282 if (test_get->dht_handle != NULL) 284 if (test_get->dht_handle != NULL)
283 GNUNET_DHT_disconnect(test_get->dht_handle); 285 GNUNET_DHT_disconnect (test_get->dht_handle);
284 test_get = test_get->next; 286 test_get = test_get->next;
285 } 287 }
286 288
287 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 289 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
288 ok = 0; 290 ok = 0;
@@ -295,32 +297,33 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
295 * test. 297 * test.
296 */ 298 */
297static void 299static void
298end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 300end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
299{ 301{
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n", (char *)cls); 302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
303 (char *) cls);
301 304
302 struct TestPutContext *test_put = all_puts; 305 struct TestPutContext *test_put = all_puts;
303 struct TestGetContext *test_get = all_gets; 306 struct TestGetContext *test_get = all_gets;
304 307
305 while (test_put != NULL) 308 while (test_put != NULL)
306 { 309 {
307 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 310 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
308 GNUNET_SCHEDULER_cancel(test_put->disconnect_task); 311 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
309 if (test_put->dht_handle != NULL) 312 if (test_put->dht_handle != NULL)
310 GNUNET_DHT_disconnect(test_put->dht_handle); 313 GNUNET_DHT_disconnect (test_put->dht_handle);
311 test_put = test_put->next; 314 test_put = test_put->next;
312 } 315 }
313 316
314 while (test_get != NULL) 317 while (test_get != NULL)
315 { 318 {
316 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 319 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
317 GNUNET_SCHEDULER_cancel(test_get->disconnect_task); 320 GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
318 if (test_get->get_handle != NULL) 321 if (test_get->get_handle != NULL)
319 GNUNET_DHT_get_stop(test_get->get_handle); 322 GNUNET_DHT_get_stop (test_get->get_handle);
320 if (test_get->dht_handle != NULL) 323 if (test_get->dht_handle != NULL)
321 GNUNET_DHT_disconnect(test_get->dht_handle); 324 GNUNET_DHT_disconnect (test_get->dht_handle);
322 test_get = test_get->next; 325 test_get = test_get->next;
323 } 326 }
324 327
325 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 328 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
326 ok = 1; 329 ok = 1;
@@ -330,47 +333,51 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
330 * Task to release DHT handle associated with GET request. 333 * Task to release DHT handle associated with GET request.
331 */ 334 */
332static void 335static void
333get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 336get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
334{ 337{
335 struct TestGetContext *test_get = cls; 338 struct TestGetContext *test_get = cls;
336 outstanding_gets--; /* GET is really finished */ 339
337 GNUNET_DHT_disconnect(test_get->dht_handle); 340 outstanding_gets--; /* GET is really finished */
341 GNUNET_DHT_disconnect (test_get->dht_handle);
338 test_get->dht_handle = NULL; 342 test_get->dht_handle = NULL;
339 343
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed); 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n",
341 if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */ 345 gets_completed, gets_failed);
342 { 346 if ((gets_completed == num_gets) && (outstanding_gets == 0)) /* All gets successful */
343 GNUNET_SCHEDULER_cancel (die_task); 347 {
344 //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL); 348 GNUNET_SCHEDULER_cancel (die_task);
345 GNUNET_SCHEDULER_add_now(&finish_testing, NULL); 349 //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL);
346 } 350 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
347 else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */ 351 }
348 { 352 else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */
349 GNUNET_SCHEDULER_cancel(die_task); 353 {
350 GNUNET_SCHEDULER_add_now(&end_badly, "not all gets succeeded!\n"); 354 GNUNET_SCHEDULER_cancel (die_task);
351 } 355 GNUNET_SCHEDULER_add_now (&end_badly, "not all gets succeeded!\n");
356 }
352} 357}
353 358
354/** 359/**
355 * Task to release get handle. 360 * Task to release get handle.
356 */ 361 */
357static void 362static void
358get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 363get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
359{ 364{
360 struct TestGetContext *test_get = cls; 365 struct TestGetContext *test_get = cls;
361 GNUNET_HashCode search_key; /* Key stored under */ 366 GNUNET_HashCode search_key; /* Key stored under */
362 char original_data[TEST_DATA_SIZE]; /* Made up data to store */ 367 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
363 368
364 memset(original_data, test_get->uid, sizeof(original_data)); 369 memset (original_data, test_get->uid, sizeof (original_data));
365 GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key); 370 GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key);
366 371
367 if ( (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) 372 if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
368 { 373 {
369 gets_failed++; 374 gets_failed++;
370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get from peer %s for key %s failed!\n", test_get->daemon->shortname, GNUNET_h2s(&search_key)); 375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
371 } 376 "Get from peer %s for key %s failed!\n",
372 GNUNET_assert(test_get->get_handle != NULL); 377 test_get->daemon->shortname, GNUNET_h2s (&search_key));
373 GNUNET_DHT_get_stop(test_get->get_handle); 378 }
379 GNUNET_assert (test_get->get_handle != NULL);
380 GNUNET_DHT_get_stop (test_get->get_handle);
374 GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get); 381 GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
375 test_get->get_handle = NULL; 382 test_get->get_handle = NULL;
376 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 383 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
@@ -386,55 +393,58 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
386 * @param size number of bytes in data 393 * @param size number of bytes in data
387 * @param data pointer to the result data 394 * @param data pointer to the result data
388 */ 395 */
389void get_result_iterator (void *cls, 396void
390 struct GNUNET_TIME_Absolute exp, 397get_result_iterator (void *cls,
391 const GNUNET_HashCode * key, 398 struct GNUNET_TIME_Absolute exp,
392 const struct GNUNET_PeerIdentity * const *get_path, 399 const GNUNET_HashCode * key,
393 const struct GNUNET_PeerIdentity * const *put_path, 400 const struct GNUNET_PeerIdentity *const *get_path,
394 enum GNUNET_BLOCK_Type type, 401 const struct GNUNET_PeerIdentity *const *put_path,
395 size_t size, 402 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
396 const void *data)
397{ 403{
398 struct TestGetContext *test_get = cls; 404 struct TestGetContext *test_get = cls;
399 GNUNET_HashCode search_key; /* Key stored under */ 405 GNUNET_HashCode search_key; /* Key stored under */
400 char original_data[TEST_DATA_SIZE]; /* Made up data to store */ 406 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
401 unsigned int i; 407 unsigned int i;
402 memset(original_data, test_get->uid, sizeof(original_data)); 408
403 GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key); 409 memset (original_data, test_get->uid, sizeof (original_data));
410 GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key);
404 411
405 if (test_get->succeeded == GNUNET_YES) 412 if (test_get->succeeded == GNUNET_YES)
406 return; /* Get has already been successful, probably ending now */ 413 return; /* Get has already been successful, probably ending now */
407 414
408#if PATH_TRACKING 415#if PATH_TRACKING
409 if (put_path != NULL) 416 if (put_path != NULL)
410 { 417 {
411 fprintf(stderr, "PUT Path: "); 418 fprintf (stderr, "PUT Path: ");
412 for (i = 0; put_path[i] != NULL; i++) 419 for (i = 0; put_path[i] != NULL; i++)
413 fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(put_path[i])); 420 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (put_path[i]));
414 fprintf(stderr, "\n"); 421 fprintf (stderr, "\n");
415 } 422 }
416 if (get_path != NULL) 423 if (get_path != NULL)
417 { 424 {
418 fprintf(stderr, "GET Path: "); 425 fprintf (stderr, "GET Path: ");
419 for (i = 0; get_path[i] != NULL; i++) 426 for (i = 0; get_path[i] != NULL; i++)
420 fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(get_path[i])); 427 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (get_path[i]));
421 fprintf(stderr, "\n"); 428 fprintf (stderr, "\n");
422 } 429 }
423#endif 430#endif
424 431
425 if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data)))) 432 if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) ||
426 { 433 (0 != memcmp (original_data, data, sizeof (original_data))))
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n"); 434 {
428 } 435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
436 "Key or data is not the same as was inserted!\n");
437 }
429 else 438 else
430 { 439 {
431 gets_completed++; 440 gets_completed++;
432 test_get->succeeded = GNUNET_YES; 441 test_get->succeeded = GNUNET_YES;
433 } 442 }
434 443
435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n"); 444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
436 GNUNET_SCHEDULER_cancel(test_get->disconnect_task); 445 GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
437 GNUNET_SCHEDULER_add_continuation(&get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 446 GNUNET_SCHEDULER_add_continuation (&get_stop_task, test_get,
447 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
438} 448}
439 449
440 450
@@ -442,43 +452,42 @@ void get_result_iterator (void *cls,
442 * Set up some data, and call API PUT function 452 * Set up some data, and call API PUT function
443 */ 453 */
444static void 454static void
445do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 455do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
446{ 456{
447 struct TestGetContext *test_get = cls; 457 struct TestGetContext *test_get = cls;
448 GNUNET_HashCode key; /* Made up key to store data under */ 458 GNUNET_HashCode key; /* Made up key to store data under */
449 char data[TEST_DATA_SIZE]; /* Made up data to store */ 459 char data[TEST_DATA_SIZE]; /* Made up data to store */
450 460
451 if (test_get == NULL) 461 if (test_get == NULL)
452 return; /* End of the list */ 462 return; /* End of the list */
453 memset(data, test_get->uid, sizeof(data)); 463 memset (data, test_get->uid, sizeof (data));
454 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key); 464 GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key);
455 465
456 if (outstanding_gets > MAX_OUTSTANDING_GETS) 466 if (outstanding_gets > MAX_OUTSTANDING_GETS)
457 { 467 {
458 GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); 468 GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
459 return; 469 return;
460 } 470 }
461 471
462 test_get->dht_handle = GNUNET_DHT_connect(test_get->daemon->cfg, 10); 472 test_get->dht_handle = GNUNET_DHT_connect (test_get->daemon->cfg, 10);
463 /* Insert the data at the first peer */ 473 /* Insert the data at the first peer */
464 GNUNET_assert(test_get->dht_handle != NULL); 474 GNUNET_assert (test_get->dht_handle != NULL);
465 outstanding_gets++; 475 outstanding_gets++;
466 test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle, 476 test_get->get_handle = GNUNET_DHT_get_start (test_get->dht_handle,
467 GNUNET_TIME_UNIT_FOREVER_REL, 477 GNUNET_TIME_UNIT_FOREVER_REL,
468 GNUNET_BLOCK_TYPE_TEST, 478 GNUNET_BLOCK_TYPE_TEST,
469 &key, 479 &key,
470 DEFAULT_GET_REPLICATION, 480 DEFAULT_GET_REPLICATION,
471 route_option, 481 route_option,
472 NULL, 0, 482 NULL, 0,
473 NULL, 0, 483 NULL, 0,
474 &get_result_iterator, 484 &get_result_iterator, test_get);
475 test_get);
476#if VERBOSE 485#if VERBOSE
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n", 486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
478 test_get->uid, 487 test_get->uid, test_get->daemon->shortname);
479 test_get->daemon->shortname);
480#endif 488#endif
481 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, &get_stop_task, test_get); 489 test_get->disconnect_task =
490 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get);
482 GNUNET_SCHEDULER_add_now (&do_get, test_get->next); 491 GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
483} 492}
484 493
@@ -487,64 +496,68 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
487 * Schedule the GET request for some time in the future. 496 * Schedule the GET request for some time in the future.
488 */ 497 */
489static void 498static void
490put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 499put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
491{ 500{
492 struct TestPutContext *test_put = cls; 501 struct TestPutContext *test_put = cls;
502
493 outstanding_puts--; 503 outstanding_puts--;
494 puts_completed++; 504 puts_completed++;
495 505
496 GNUNET_SCHEDULER_cancel(test_put->disconnect_task); 506 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
497 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(&put_disconnect_task, test_put); 507 test_put->disconnect_task =
508 GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put);
498 if (puts_completed == num_puts) 509 if (puts_completed == num_puts)
499 { 510 {
500 GNUNET_assert(outstanding_puts == 0); 511 GNUNET_assert (outstanding_puts == 0);
501 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, all_gets); 512 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
502 return; 513 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get,
503 } 514 all_gets);
515 return;
516 }
504} 517}
505 518
506/** 519/**
507 * Set up some data, and call API PUT function 520 * Set up some data, and call API PUT function
508 */ 521 */
509static void 522static void
510do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 523do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
511{ 524{
512 struct TestPutContext *test_put = cls; 525 struct TestPutContext *test_put = cls;
513 GNUNET_HashCode key; /* Made up key to store data under */ 526 GNUNET_HashCode key; /* Made up key to store data under */
514 char data[TEST_DATA_SIZE]; /* Made up data to store */ 527 char data[TEST_DATA_SIZE]; /* Made up data to store */
515 528
516 if (test_put == NULL) 529 if (test_put == NULL)
517 return; /* End of list */ 530 return; /* End of list */
518 531
519 memset(data, test_put->uid, sizeof(data)); 532 memset (data, test_put->uid, sizeof (data));
520 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key); 533 GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key);
521 534
522 if (outstanding_puts > MAX_OUTSTANDING_PUTS) 535 if (outstanding_puts > MAX_OUTSTANDING_PUTS)
523 { 536 {
524 GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); 537 GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
525 return; 538 return;
526 } 539 }
527 540
528#if VERBOSE 541#if VERBOSE
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n", 542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
530 test_put->uid, 543 test_put->uid, test_put->daemon->shortname);
531 test_put->daemon->shortname);
532#endif 544#endif
533 test_put->dht_handle = GNUNET_DHT_connect(test_put->daemon->cfg, 10); 545 test_put->dht_handle = GNUNET_DHT_connect (test_put->daemon->cfg, 10);
534 546
535 GNUNET_assert(test_put->dht_handle != NULL); 547 GNUNET_assert (test_put->dht_handle != NULL);
536 outstanding_puts++; 548 outstanding_puts++;
537 GNUNET_DHT_put(test_put->dht_handle, 549 GNUNET_DHT_put (test_put->dht_handle,
538 &key, 550 &key,
539 DEFAULT_PUT_REPLICATION, 551 DEFAULT_PUT_REPLICATION,
540 route_option, 552 route_option,
541 GNUNET_BLOCK_TYPE_TEST, 553 GNUNET_BLOCK_TYPE_TEST,
542 sizeof(data), data, 554 sizeof (data), data,
543 GNUNET_TIME_UNIT_FOREVER_ABS, 555 GNUNET_TIME_UNIT_FOREVER_ABS,
544 GNUNET_TIME_UNIT_FOREVER_REL, 556 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, test_put);
545 &put_finished, test_put); 557 test_put->disconnect_task =
546 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put); 558 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
547 GNUNET_SCHEDULER_add_now(&do_put, test_put->next); 559 &put_disconnect_task, test_put);
560 GNUNET_SCHEDULER_add_now (&do_put, test_put->next);
548} 561}
549 562
550 563
@@ -554,7 +567,7 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
554 * then call actual insert functions. 567 * then call actual insert functions.
555 */ 568 */
556static void 569static void
557setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 570setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
558{ 571{
559 int i; 572 int i;
560 uint32_t temp_daemon; 573 uint32_t temp_daemon;
@@ -563,27 +576,31 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
563 int remember[num_puts][num_peers]; 576 int remember[num_puts][num_peers];
564 577
565 for (i = 0; i < num_puts; i++) 578 for (i = 0; i < num_puts; i++)
566 { 579 {
567 test_put = GNUNET_malloc(sizeof(struct TestPutContext)); 580 test_put = GNUNET_malloc (sizeof (struct TestPutContext));
568 test_put->uid = i; 581 test_put->uid = i;
569 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 582 temp_daemon =
570 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon); 583 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
571 test_put->next = all_puts; 584 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
572 all_puts = test_put; 585 test_put->next = all_puts;
573 } 586 all_puts = test_put;
587 }
574 588
575 for (i = 0; i < num_gets; i++) 589 for (i = 0; i < num_gets; i++)
576 { 590 {
577 test_get = GNUNET_malloc(sizeof(struct TestGetContext)); 591 test_get = GNUNET_malloc (sizeof (struct TestGetContext));
578 test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts); 592 test_get->uid =
579 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 593 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
580 while (remember[test_get->uid][temp_daemon] == 1) 594 temp_daemon =
581 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 595 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
582 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon); 596 while (remember[test_get->uid][temp_daemon] == 1)
583 remember[test_get->uid][temp_daemon] = 1; 597 temp_daemon =
584 test_get->next = all_gets; 598 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
585 all_gets = test_get; 599 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
586 } 600 remember[test_get->uid][temp_daemon] = 1;
601 test_get->next = all_gets;
602 all_gets = test_get;
603 }
587 604
588 GNUNET_SCHEDULER_add_now (&do_put, all_puts); 605 GNUNET_SCHEDULER_add_now (&do_put, all_puts);
589} 606}
@@ -610,57 +627,61 @@ topology_callback (void *cls,
610 const char *emsg) 627 const char *emsg)
611{ 628{
612 if (emsg == NULL) 629 if (emsg == NULL)
613 { 630 {
614 total_connections++; 631 total_connections++;
615#if VERBOSE > 1 632#if VERBOSE > 1
616 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", 633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
617 first_daemon->shortname, 634 "connected peer %s to peer %s, distance %u\n",
618 second_daemon->shortname, 635 first_daemon->shortname, second_daemon->shortname, distance);
619 distance);
620#endif 636#endif
621 } 637 }
622#if VERBOSE 638#if VERBOSE
623 else 639 else
624 { 640 {
625 failed_connections++; 641 failed_connections++;
626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", 642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
627 first_daemon->shortname, 643 "Failed to connect peer %s to peer %s with error :\n%s\n",
628 second_daemon->shortname, emsg); 644 first_daemon->shortname, second_daemon->shortname, emsg);
629 } 645 }
630#endif 646#endif
631 647
632 if (total_connections == expected_connections) 648 if (total_connections == expected_connections)
633 { 649 {
634#if VERBOSE 650#if VERBOSE
635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 "Created %d total connections, which is our target number! Starting next phase of testing.\n", 652 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
637 total_connections); 653 total_connections);
638#endif 654#endif
639 GNUNET_SCHEDULER_cancel (die_task); 655 GNUNET_SCHEDULER_cancel (die_task);
640 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 656 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
641 &end_badly, "from setup puts/gets"); 657 &end_badly,
642 658 "from setup puts/gets");
643 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &setup_puts_and_gets, NULL); 659
644 } 660 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
661 (GNUNET_TIME_UNIT_SECONDS, 2),
662 &setup_puts_and_gets, NULL);
663 }
645 else if (total_connections + failed_connections == expected_connections) 664 else if (total_connections + failed_connections == expected_connections)
646 { 665 {
647 GNUNET_SCHEDULER_cancel (die_task); 666 GNUNET_SCHEDULER_cancel (die_task);
648 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); 667 die_task =
649 } 668 GNUNET_SCHEDULER_add_now (&end_badly,
669 "from topology_callback (too many failed connections)");
670 }
650} 671}
651 672
652static void 673static void
653peers_started_callback (void *cls, 674peers_started_callback (void *cls,
654 const struct GNUNET_PeerIdentity *id, 675 const struct GNUNET_PeerIdentity *id,
655 const struct GNUNET_CONFIGURATION_Handle *cfg, 676 const struct GNUNET_CONFIGURATION_Handle *cfg,
656 struct GNUNET_TESTING_Daemon *d, const char *emsg) 677 struct GNUNET_TESTING_Daemon *d, const char *emsg)
657{ 678{
658 if (emsg != NULL) 679 if (emsg != NULL)
659 { 680 {
660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", 681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
661 emsg); 682 "Failed to start daemon with error: `%s'\n", emsg);
662 return; 683 return;
663 } 684 }
664 GNUNET_assert (id != NULL); 685 GNUNET_assert (id != NULL);
665 686
666#if VERBOSE 687#if VERBOSE
@@ -670,63 +691,69 @@ peers_started_callback (void *cls,
670 691
671 peers_left--; 692 peers_left--;
672 if (peers_left == 0) 693 if (peers_left == 0)
673 { 694 {
674 695
675#if VERBOSE 696#if VERBOSE
676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
677 "All %d daemons started, now connecting peers!\n", 698 "All %d daemons started, now connecting peers!\n", num_peers);
678 num_peers);
679#endif 699#endif
680 GNUNET_SCHEDULER_cancel (die_task); 700 GNUNET_SCHEDULER_cancel (die_task);
681 701
682 expected_connections = -1; 702 expected_connections = -1;
683 if ((pg != NULL) && (peers_left == 0)) 703 if ((pg != NULL) && (peers_left == 0))
684 { 704 {
685 expected_connections = GNUNET_TESTING_connect_topology (pg, 705 expected_connections = GNUNET_TESTING_connect_topology (pg,
686 connection_topology, 706 connection_topology,
687 connect_topology_option, 707 connect_topology_option,
688 connect_topology_option_modifier, 708 connect_topology_option_modifier,
689 TIMEOUT, 709 TIMEOUT,
690 num_peers, 710 num_peers,
691 NULL, NULL); 711 NULL, NULL);
692#if VERBOSE 712#if VERBOSE
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
694 "Have %d expected connections\n", expected_connections); 714 "Have %d expected connections\n", expected_connections);
695#endif 715#endif
696 } 716 }
697 717
698 if (expected_connections == GNUNET_SYSERR) 718 if (expected_connections == GNUNET_SYSERR)
699 { 719 {
700 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); 720 die_task =
701 } 721 GNUNET_SCHEDULER_add_now (&end_badly,
722 "from connect topology (bad return)");
723 }
702 724
703 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 725 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
704 &end_badly, "from connect topology (timeout)"); 726 &end_badly,
727 "from connect topology (timeout)");
705 728
706 ok = 0; 729 ok = 0;
707 } 730 }
708} 731}
709 732
710static void 733static void
711create_topology () 734create_topology ()
712{ 735{
713 peers_left = num_peers; /* Reset counter */ 736 peers_left = num_peers; /* Reset counter */
714 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) 737 if (GNUNET_TESTING_create_topology
715 { 738 (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
739 {
716#if VERBOSE 740#if VERBOSE
717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
718 "Topology set up, now starting peers!\n"); 742 "Topology set up, now starting peers!\n");
719#endif 743#endif
720 GNUNET_TESTING_daemons_continue_startup(pg); 744 GNUNET_TESTING_daemons_continue_startup (pg);
721 } 745 }
722 else 746 else
723 { 747 {
724 GNUNET_SCHEDULER_cancel (die_task); 748 GNUNET_SCHEDULER_cancel (die_task);
725 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)"); 749 die_task =
726 } 750 GNUNET_SCHEDULER_add_now (&end_badly,
751 "from create topology (bad return)");
752 }
727 GNUNET_SCHEDULER_cancel (die_task); 753 GNUNET_SCHEDULER_cancel (die_task);
728 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 754 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
729 &end_badly, "from continue startup (timeout)"); 755 &end_badly,
756 "from continue startup (timeout)");
730} 757}
731 758
732/** 759/**
@@ -737,39 +764,40 @@ create_topology ()
737 * @param d the daemon handle (pretty useless at this point, remove?) 764 * @param d the daemon handle (pretty useless at this point, remove?)
738 * @param emsg non-null on failure 765 * @param emsg non-null on failure
739 */ 766 */
740void hostkey_callback (void *cls, 767void
741 const struct GNUNET_PeerIdentity *id, 768hostkey_callback (void *cls,
742 struct GNUNET_TESTING_Daemon *d, 769 const struct GNUNET_PeerIdentity *id,
743 const char *emsg) 770 struct GNUNET_TESTING_Daemon *d, const char *emsg)
744{ 771{
745 if (emsg != NULL) 772 if (emsg != NULL)
746 { 773 {
747 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg); 774 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
748 } 775 "Hostkey callback received error: %s\n", emsg);
776 }
749 777
750#if VERBOSE > 1 778#if VERBOSE > 1
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Hostkey (%d/%d) created for peer `%s'\n", 780 "Hostkey (%d/%d) created for peer `%s'\n",
753 num_peers - peers_left, num_peers, GNUNET_i2s(id)); 781 num_peers - peers_left, num_peers, GNUNET_i2s (id));
754#endif 782#endif
755 783
756 784
757 peers_left--; 785 peers_left--;
758 if (peers_left == 0) 786 if (peers_left == 0)
759 { 787 {
760#if VERBOSE 788#if VERBOSE
761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
762 "All %d hostkeys created, now creating topology!\n", 790 "All %d hostkeys created, now creating topology!\n", num_peers);
763 num_peers);
764#endif 791#endif
765 GNUNET_SCHEDULER_cancel (die_task); 792 GNUNET_SCHEDULER_cancel (die_task);
766 /* Set up task in case topology creation doesn't finish 793 /* Set up task in case topology creation doesn't finish
767 * within a reasonable amount of time */ 794 * within a reasonable amount of time */
768 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 795 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
769 &end_badly, "from create_topology"); 796 &end_badly,
770 GNUNET_SCHEDULER_add_now(&create_topology, NULL); 797 "from create_topology");
771 ok = 0; 798 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
772 } 799 ok = 0;
800 }
773} 801}
774 802
775 803
@@ -778,11 +806,11 @@ run (void *cls,
778 char *const *args, 806 char *const *args,
779 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 807 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
780{ 808{
781 char * topology_str; 809 char *topology_str;
782 char * connect_topology_str; 810 char *connect_topology_str;
783 char * blacklist_topology_str; 811 char *blacklist_topology_str;
784 char * connect_topology_option_str; 812 char *connect_topology_option_str;
785 char * connect_topology_option_modifier_string; 813 char *connect_topology_option_modifier_string;
786 814
787#if PATH_TRACKING 815#if PATH_TRACKING
788 route_option = GNUNET_DHT_RO_RECORD_ROUTE; 816 route_option = GNUNET_DHT_RO_RECORD_ROUTE;
@@ -791,66 +819,91 @@ run (void *cls,
791#endif 819#endif
792 820
793 /* Get path from configuration file */ 821 /* Get path from configuration file */
794 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 822 if (GNUNET_YES !=
795 { 823 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
796 ok = 404; 824 &test_directory))
797 return; 825 {
798 } 826 ok = 404;
827 return;
828 }
799 829
800 if ((GNUNET_YES == 830 if ((GNUNET_YES ==
801 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology", 831 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
802 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str))) 832 &topology_str)) &&
803 { 833 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
804 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 834 {
805 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY"); 835 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
806 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ 836 "Invalid topology `%s' given for section %s option %s\n",
807 } 837 topology_str, "TESTING", "TOPOLOGY");
838 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
839 }
808 840
809 if ((GNUNET_YES == 841 if ((GNUNET_YES ==
810 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology", 842 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
811 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str))) 843 "connect_topology",
812 { 844 &connect_topology_str)) &&
813 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 845 (GNUNET_NO ==
814 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); 846 GNUNET_TESTING_topology_get (&connection_topology,
815 } 847 connect_topology_str)))
816 GNUNET_free_non_null(connect_topology_str); 848 {
849 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
850 "Invalid connect topology `%s' given for section %s option %s\n",
851 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
852 }
853 GNUNET_free_non_null (connect_topology_str);
817 if ((GNUNET_YES == 854 if ((GNUNET_YES ==
818 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option", 855 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
819 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str))) 856 "connect_topology_option",
820 { 857 &connect_topology_option_str)) &&
821 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 858 (GNUNET_NO ==
822 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION"); 859 GNUNET_TESTING_topology_option_get (&connect_topology_option,
823 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ 860 connect_topology_option_str)))
824 } 861 {
825 GNUNET_free_non_null(connect_topology_option_str); 862 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
863 "Invalid connect topology option `%s' given for section %s option %s\n",
864 connect_topology_option_str, "TESTING",
865 "CONNECT_TOPOLOGY_OPTION");
866 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
867 }
868 GNUNET_free_non_null (connect_topology_option_str);
826 if (GNUNET_YES == 869 if (GNUNET_YES ==
827 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier", 870 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
828 &connect_topology_option_modifier_string)) 871 "connect_topology_option_modifier",
872 &connect_topology_option_modifier_string))
873 {
874 if (sscanf
875 (connect_topology_option_modifier_string, "%lf",
876 &connect_topology_option_modifier) != 1)
829 { 877 {
830 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1) 878 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
831 { 879 _
832 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 880 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
833 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), 881 connect_topology_option_modifier_string,
834 connect_topology_option_modifier_string, 882 "connect_topology_option_modifier", "TESTING");
835 "connect_topology_option_modifier", 883 }
836 "TESTING"); 884 GNUNET_free (connect_topology_option_modifier_string);
837 } 885 }
838 GNUNET_free (connect_topology_option_modifier_string); 886
839 } 887 if (GNUNET_YES !=
840 888 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
841 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports", 889 "blacklist_transports",
842 &blacklist_transports)) 890 &blacklist_transports))
843 blacklist_transports = NULL; 891 blacklist_transports = NULL;
844 892
845 if ((GNUNET_YES == 893 if ((GNUNET_YES ==
846 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology", 894 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
847 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str))) 895 "blacklist_topology",
848 { 896 &blacklist_topology_str)) &&
849 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 897 (GNUNET_NO ==
850 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); 898 GNUNET_TESTING_topology_get (&blacklist_topology,
851 } 899 blacklist_topology_str)))
852 GNUNET_free_non_null(topology_str); 900 {
853 GNUNET_free_non_null(blacklist_topology_str); 901 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
902 "Invalid topology `%s' given for section %s option %s\n",
903 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
904 }
905 GNUNET_free_non_null (topology_str);
906 GNUNET_free_non_null (blacklist_topology_str);
854 907
855 /* Get number of peers to start from configuration */ 908 /* Get number of peers to start from configuration */
856 if (GNUNET_SYSERR == 909 if (GNUNET_SYSERR ==
@@ -872,21 +925,22 @@ run (void *cls,
872 peers_left = num_peers; 925 peers_left = num_peers;
873 926
874 /* Set up a task to end testing if peer start fails */ 927 /* Set up a task to end testing if peer start fails */
875 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), 928 die_task =
876 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!"); 929 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
877 930 (GNUNET_TIME_UNIT_SECONDS,
878 pg = GNUNET_TESTING_daemons_start (cfg, 931 SECONDS_PER_PEER_START * num_peers),
879 peers_left, /* Total number of peers */ 932 &end_badly,
880 peers_left, /* Number of outstanding connections */ 933 "didn't generate all hostkeys within a reasonable amount of time!!!");
881 peers_left, /* Number of parallel ssh connections, or peers being started at once */ 934
882 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), 935 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
883 &hostkey_callback, 936 peers_left, /* Number of outstanding connections */
884 NULL, 937 peers_left, /* Number of parallel ssh connections, or peers being started at once */
885 &peers_started_callback, 938 GNUNET_TIME_relative_multiply
886 NULL, 939 (GNUNET_TIME_UNIT_SECONDS,
887 &topology_callback, 940 SECONDS_PER_PEER_START * num_peers),
888 NULL, 941 &hostkey_callback, NULL,
889 NULL); 942 &peers_started_callback, NULL,
943 &topology_callback, NULL, NULL);
890 944
891} 945}
892 946
@@ -894,10 +948,11 @@ static int
894check () 948check ()
895{ 949{
896 int ret; 950 int ret;
951
897 /* Arguments for GNUNET_PROGRAM_run */ 952 /* Arguments for GNUNET_PROGRAM_run */
898 char *const argv[] = {"test-dht-multipeer", /* Name to give running binary */ 953 char *const argv[] = { "test-dht-multipeer", /* Name to give running binary */
899 "-c", 954 "-c",
900 "test_dht_multipeer_data.conf", /* Config file to use */ 955 "test_dht_multipeer_data.conf", /* Config file to use */
901#if VERBOSE 956#if VERBOSE
902 "-L", "DEBUG", 957 "-L", "DEBUG",
903#endif 958#endif
@@ -908,12 +963,13 @@ check ()
908 }; 963 };
909 /* Run the run function as a new program */ 964 /* Run the run function as a new program */
910 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 965 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
911 argv, "test-dht-multipeer", "nohelp", 966 argv, "test-dht-multipeer", "nohelp",
912 options, &run, &ok); 967 options, &run, &ok);
913 if (ret != GNUNET_OK) 968 if (ret != GNUNET_OK)
914 { 969 {
915 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-multipeer': Failed with error code %d\n", ret); 970 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
916 } 971 "`test-dht-multipeer': Failed with error code %d\n", ret);
972 }
917 return ok; 973 return ok;
918} 974}
919 975
@@ -935,9 +991,10 @@ main (int argc, char *argv[])
935 * of by the testing framework. 991 * of by the testing framework.
936 */ 992 */
937 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) 993 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
938 { 994 {
939 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); 995 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
940 } 996 "Failed to remove testing directory %s\n", test_directory);
997 }
941 return ret; 998 return ret;
942} 999}
943 1000
diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c
index 8c373d365..6ba3799dc 100644
--- a/src/dht/test_dht_twopeer.c
+++ b/src/dht/test_dht_twopeer.c
@@ -87,53 +87,53 @@ static struct GNUNET_DHT_Handle *peer2dht;
87/** 87/**
88 * Check whether peers successfully shut down. 88 * Check whether peers successfully shut down.
89 */ 89 */
90void shutdown_callback (void *cls, 90void
91 const char *emsg) 91shutdown_callback (void *cls, const char *emsg)
92{ 92{
93 if (emsg != NULL) 93 if (emsg != NULL)
94 { 94 {
95 if (ok == 0) 95 if (ok == 0)
96 ok = 2; 96 ok = 2;
97 } 97 }
98} 98}
99 99
100static void 100static void
101finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 101finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
102{ 102{
103 GNUNET_assert (pg != NULL); 103 GNUNET_assert (pg != NULL);
104 GNUNET_assert (peer1dht != NULL); 104 GNUNET_assert (peer1dht != NULL);
105 GNUNET_assert (peer2dht != NULL); 105 GNUNET_assert (peer2dht != NULL);
106 GNUNET_DHT_disconnect(peer1dht); 106 GNUNET_DHT_disconnect (peer1dht);
107 GNUNET_DHT_disconnect(peer2dht); 107 GNUNET_DHT_disconnect (peer2dht);
108 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 108 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
109 ok = 0; 109 ok = 0;
110} 110}
111 111
112static void 112static void
113end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 113end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
114{ 114{
115 if (peer1dht != NULL) 115 if (peer1dht != NULL)
116 GNUNET_DHT_disconnect(peer1dht); 116 GNUNET_DHT_disconnect (peer1dht);
117 117
118 if (peer2dht != NULL) 118 if (peer2dht != NULL)
119 GNUNET_DHT_disconnect(peer2dht); 119 GNUNET_DHT_disconnect (peer2dht);
120 120
121 if (pg != NULL) 121 if (pg != NULL)
122 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 122 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
123 123
124 if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) 124 if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
125 GNUNET_SCHEDULER_cancel(curr_get_ctx.retry_task); 125 GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
126} 126}
127 127
128static void 128static void
129end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 129end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
130{ 130{
131 if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) 131 if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
132 GNUNET_SCHEDULER_cancel(curr_get_ctx.retry_task); 132 GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
133 133
134 if (curr_get_ctx.get_handle != NULL) 134 if (curr_get_ctx.get_handle != NULL)
135 { 135 {
136 GNUNET_DHT_get_stop(curr_get_ctx.get_handle); 136 GNUNET_DHT_get_stop (curr_get_ctx.get_handle);
137 } 137 }
138 138
139 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL); 139 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
@@ -141,8 +141,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
141} 141}
142 142
143/* Forward declaration */ 143/* Forward declaration */
144static void 144static void do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
145do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
146 145
147/** 146/**
148 * Iterator called on each result obtained for a DHT 147 * Iterator called on each result obtained for a DHT
@@ -155,108 +154,122 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
155 * @param size number of bytes in data 154 * @param size number of bytes in data
156 * @param data pointer to the result data 155 * @param data pointer to the result data
157 */ 156 */
158void get_result_iterator (void *cls, 157void
159 struct GNUNET_TIME_Absolute exp, 158get_result_iterator (void *cls,
160 const GNUNET_HashCode * key, 159 struct GNUNET_TIME_Absolute exp,
161 const struct GNUNET_PeerIdentity * const *get_path, 160 const GNUNET_HashCode * key,
162 const struct GNUNET_PeerIdentity * const *put_path, 161 const struct GNUNET_PeerIdentity *const *get_path,
163 enum GNUNET_BLOCK_Type type, 162 const struct GNUNET_PeerIdentity *const *put_path,
164 size_t size, 163 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
165 const void *data)
166{ 164{
167 struct PeerGetContext *get_context = cls; 165 struct PeerGetContext *get_context = cls;
168 166
169 if (0 != memcmp(&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode))) 167 if (0 !=
168 memcmp (&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode)))
170 { 169 {
171 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key returned is not the same key as was searched for!\n"); 170 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
172 GNUNET_SCHEDULER_cancel(die_task); 171 "Key returned is not the same key as was searched for!\n");
173 GNUNET_SCHEDULER_add_now(&end_badly, "key mismatch in get response!\n"); 172 GNUNET_SCHEDULER_cancel (die_task);
173 GNUNET_SCHEDULER_add_now (&end_badly, "key mismatch in get response!\n");
174 return; 174 return;
175 } 175 }
176 176
177 if (get_context->retry_task != GNUNET_SCHEDULER_NO_TASK) 177 if (get_context->retry_task != GNUNET_SCHEDULER_NO_TASK)
178 { 178 {
179 GNUNET_SCHEDULER_cancel(get_context->retry_task); 179 GNUNET_SCHEDULER_cancel (get_context->retry_task);
180 get_context->retry_task = GNUNET_SCHEDULER_NO_TASK; 180 get_context->retry_task = GNUNET_SCHEDULER_NO_TASK;
181 } 181 }
182 182
183 if (get_context->peer == &peer2id) 183 if (get_context->peer == &peer2id)
184 { 184 {
185 get_context->peer = &peer1id; 185 get_context->peer = &peer1id;
186 get_context->dht_handle = peer2dht; 186 get_context->dht_handle = peer2dht;
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received first correct GET request response!\n"); 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 GNUNET_DHT_get_stop(get_context->get_handle); 188 "Received first correct GET request response!\n");
189 GNUNET_DHT_get_stop (get_context->get_handle);
189 GNUNET_SCHEDULER_add_now (&do_get, get_context); 190 GNUNET_SCHEDULER_add_now (&do_get, get_context);
190 } 191 }
191 else 192 else
192 { 193 {
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received second correct GET request response!\n"); 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 GNUNET_SCHEDULER_cancel(die_task); 195 "Received second correct GET request response!\n");
195 GNUNET_DHT_get_stop(get_context->get_handle); 196 GNUNET_SCHEDULER_cancel (die_task);
197 GNUNET_DHT_get_stop (get_context->get_handle);
196 GNUNET_SCHEDULER_add_now (&finish_testing, NULL); 198 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
197 } 199 }
198 200
199} 201}
200 202
201static void 203static void
202stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); 204stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
203 205
204static void 206static void
205get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 207get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
206{ 208{
207 struct PeerGetContext *get_context = cls; 209 struct PeerGetContext *get_context = cls;
208 210
209 if (get_context->get_attempts < MAX_GET_ATTEMPTS) 211 if (get_context->get_attempts < MAX_GET_ATTEMPTS)
210 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Get attempt %u failed, retrying request!\n", get_context->get_attempts); 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "Get attempt %u failed, retrying request!\n",
214 get_context->get_attempts);
211 else 215 else
212 { 216 {
213 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Too many attempts failed, ending test!\n", get_context->get_attempts); 217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 GNUNET_SCHEDULER_cancel(die_task); 218 "Too many attempts failed, ending test!\n",
215 GNUNET_SCHEDULER_add_now(&end_badly, "key mismatch in get response!\n"); 219 get_context->get_attempts);
216 return; 220 GNUNET_SCHEDULER_cancel (die_task);
217 } 221 GNUNET_SCHEDULER_add_now (&end_badly, "key mismatch in get response!\n");
222 return;
223 }
218 get_context->get_attempts++; 224 get_context->get_attempts++;
219 get_context->retry_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), 225 get_context->retry_task =
220 &stop_retry_get, get_context); 226 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
221 get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, 227 (GNUNET_TIME_UNIT_SECONDS, 10),
222 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 228 &stop_retry_get, get_context);
223 GNUNET_BLOCK_TYPE_DHT_HELLO, 229 get_context->get_handle =
224 &get_context->peer->hashPubKey, 230 GNUNET_DHT_get_start (get_context->dht_handle,
225 DEFAULT_GET_REPLICATION, 231 GNUNET_TIME_relative_multiply
226 GNUNET_DHT_RO_NONE, 232 (GNUNET_TIME_UNIT_SECONDS, 5),
227 NULL, 0, 233 GNUNET_BLOCK_TYPE_DHT_HELLO,
228 NULL, 0, 234 &get_context->peer->hashPubKey,
229 &get_result_iterator, get_context); 235 DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
236 0, NULL, 0, &get_result_iterator, get_context);
230} 237}
231 238
232static void 239static void
233stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 240stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
234{ 241{
235 struct PeerGetContext *get_context = cls; 242 struct PeerGetContext *get_context = cls;
243
236 get_context->retry_task = GNUNET_SCHEDULER_NO_TASK; 244 get_context->retry_task = GNUNET_SCHEDULER_NO_TASK;
237 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Get attempt %u failed, canceling request!\n", get_context->get_attempts); 245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
238 GNUNET_DHT_get_stop(get_context->get_handle); 246 "Get attempt %u failed, canceling request!\n",
247 get_context->get_attempts);
248 GNUNET_DHT_get_stop (get_context->get_handle);
239 get_context->get_handle = NULL; 249 get_context->get_handle = NULL;
240 GNUNET_SCHEDULER_add_now(&get_stop_finished, get_context); 250 GNUNET_SCHEDULER_add_now (&get_stop_finished, get_context);
241} 251}
242 252
243static void 253static void
244do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 254do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
245{ 255{
246 struct PeerGetContext *get_context = cls; 256 struct PeerGetContext *get_context = cls;
247 257
248 get_context->retry_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), 258 get_context->retry_task =
249 &stop_retry_get, get_context); 259 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
250 260 (GNUNET_TIME_UNIT_SECONDS, 10),
251 get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, 261 &stop_retry_get, get_context);
252 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 262
253 GNUNET_BLOCK_TYPE_DHT_HELLO, 263 get_context->get_handle = GNUNET_DHT_get_start (get_context->dht_handle,
254 &get_context->peer->hashPubKey, 264 GNUNET_TIME_relative_multiply
255 DEFAULT_GET_REPLICATION, 265 (GNUNET_TIME_UNIT_SECONDS, 5),
256 GNUNET_DHT_RO_NONE, 266 GNUNET_BLOCK_TYPE_DHT_HELLO,
257 NULL, 0, 267 &get_context->
258 NULL, 0, 268 peer->hashPubKey,
259 &get_result_iterator, get_context); 269 DEFAULT_GET_REPLICATION,
270 GNUNET_DHT_RO_NONE, NULL, 0,
271 NULL, 0, &get_result_iterator,
272 get_context);
260} 273}
261 274
262 275
@@ -272,49 +285,52 @@ topology_callback (void *cls,
272 const char *emsg) 285 const char *emsg)
273{ 286{
274 if (emsg == NULL) 287 if (emsg == NULL)
275 { 288 {
276 total_connections++; 289 total_connections++;
277#if VERBOSE 290#if VERBOSE
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
279 first_daemon->shortname, 292 "connected peer %s to peer %s, distance %u\n",
280 second_daemon->shortname, 293 first_daemon->shortname, second_daemon->shortname, distance);
281 distance);
282#endif 294#endif
283 } 295 }
284#if VERBOSE 296#if VERBOSE
285 else 297 else
286 { 298 {
287 failed_connections++; 299 failed_connections++;
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", 300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
289 first_daemon->shortname, 301 "Failed to connect peer %s to peer %s with error :\n%s\n",
290 second_daemon->shortname, emsg); 302 first_daemon->shortname, second_daemon->shortname, emsg);
291 } 303 }
292#endif 304#endif
293 305
294 if (total_connections == expected_connections) 306 if (total_connections == expected_connections)
295 { 307 {
296#if VERBOSE 308#if VERBOSE
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
298 "Created %d total connections, which is our target number! Starting next phase of testing.\n", 310 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
299 total_connections); 311 total_connections);
300#endif 312#endif
301 GNUNET_SCHEDULER_cancel (die_task); 313 GNUNET_SCHEDULER_cancel (die_task);
302 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 314 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
303 &end_badly, "from test gets"); 315 &end_badly, "from test gets");
304 316
305 curr_get_ctx.dht_handle = peer1dht; 317 curr_get_ctx.dht_handle = peer1dht;
306 curr_get_ctx.peer = &peer2id; 318 curr_get_ctx.peer = &peer2id;
307 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_get, &curr_get_ctx); 319 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
308 } 320 (GNUNET_TIME_UNIT_SECONDS, 2), &do_get,
321 &curr_get_ctx);
322 }
309 else if (total_connections + failed_connections == expected_connections) 323 else if (total_connections + failed_connections == expected_connections)
310 { 324 {
311 GNUNET_SCHEDULER_cancel (die_task); 325 GNUNET_SCHEDULER_cancel (die_task);
312 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); 326 die_task =
313 } 327 GNUNET_SCHEDULER_add_now (&end_badly,
328 "from topology_callback (too many failed connections)");
329 }
314} 330}
315 331
316static void 332static void
317connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 333connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
318{ 334{
319 expected_connections = -1; 335 expected_connections = -1;
320 if ((pg != NULL) && (peers_left == 0)) 336 if ((pg != NULL) && (peers_left == 0))
@@ -322,48 +338,52 @@ connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
322 GNUNET_TESTING_TOPOLOGY_CLIQUE, 338 GNUNET_TESTING_TOPOLOGY_CLIQUE,
323 GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 339 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
324 0.0, 340 0.0,
325 TIMEOUT, 12, NULL, NULL); 341 TIMEOUT, 12, NULL,
342 NULL);
326 343
327 GNUNET_SCHEDULER_cancel (die_task); 344 GNUNET_SCHEDULER_cancel (die_task);
328 if (expected_connections == GNUNET_SYSERR) 345 if (expected_connections == GNUNET_SYSERR)
329 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); 346 die_task =
347 GNUNET_SCHEDULER_add_now (&end_badly,
348 "from connect topology (bad return)");
330 349
331 350
332 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 351 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
333 &end_badly, "from connect topology (timeout)"); 352 &end_badly,
353 "from connect topology (timeout)");
334} 354}
335 355
336static void 356static void
337peers_started_callback (void *cls, 357peers_started_callback (void *cls,
338 const struct GNUNET_PeerIdentity *id, 358 const struct GNUNET_PeerIdentity *id,
339 const struct GNUNET_CONFIGURATION_Handle *cfg, 359 const struct GNUNET_CONFIGURATION_Handle *cfg,
340 struct GNUNET_TESTING_Daemon *d, const char *emsg) 360 struct GNUNET_TESTING_Daemon *d, const char *emsg)
341{ 361{
342 if (emsg != NULL) 362 if (emsg != NULL)
343 { 363 {
344 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with error: `%s'\n", 364 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
345 emsg); 365 "Failed to start daemon with error: `%s'\n", emsg);
346 return; 366 return;
347 } 367 }
348 GNUNET_assert (id != NULL); 368 GNUNET_assert (id != NULL);
349 if (peers_left == num_peers) 369 if (peers_left == num_peers)
350 { 370 {
351 memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); 371 memcpy (&peer1id, id, sizeof (struct GNUNET_PeerIdentity));
352 peer1dht = GNUNET_DHT_connect(cfg, 100); 372 peer1dht = GNUNET_DHT_connect (cfg, 100);
353 if (peer1dht == NULL) 373 if (peer1dht == NULL)
354 { 374 {
355 GNUNET_SCHEDULER_cancel (die_task); 375 GNUNET_SCHEDULER_cancel (die_task);
356 GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); 376 GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
357 } 377 }
358 } 378 }
359 else 379 else
360 { 380 {
361 memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); 381 memcpy (&peer2id, id, sizeof (struct GNUNET_PeerIdentity));
362 peer2dht = GNUNET_DHT_connect(cfg, 100); 382 peer2dht = GNUNET_DHT_connect (cfg, 100);
363 if (peer2dht == NULL) 383 if (peer2dht == NULL)
364 { 384 {
365 GNUNET_SCHEDULER_cancel (die_task); 385 GNUNET_SCHEDULER_cancel (die_task);
366 GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); 386 GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
367 } 387 }
368 } 388 }
369 389
@@ -371,21 +391,21 @@ peers_started_callback (void *cls,
371 peers_left--; 391 peers_left--;
372 392
373 if (peers_left == 0) 393 if (peers_left == 0)
374 { 394 {
375#if VERBOSE 395#if VERBOSE
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
377 "All %d daemons started, now connecting peers!\n", 397 "All %d daemons started, now connecting peers!\n", num_peers);
378 num_peers);
379#endif 398#endif
380 GNUNET_SCHEDULER_cancel (die_task); 399 GNUNET_SCHEDULER_cancel (die_task);
381 /* Set up task in case topology creation doesn't finish 400 /* Set up task in case topology creation doesn't finish
382 * within a reasonable amount of time */ 401 * within a reasonable amount of time */
383 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 402 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
384 &end_badly, "from peers_started_callback"); 403 &end_badly,
385 404 "from peers_started_callback");
386 GNUNET_SCHEDULER_add_now(&connect_topology, NULL); 405
387 ok = 0; 406 GNUNET_SCHEDULER_add_now (&connect_topology, NULL);
388 } 407 ok = 0;
408 }
389} 409}
390 410
391static void 411static void
@@ -394,11 +414,13 @@ run (void *cls,
394 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 414 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
395{ 415{
396 416
397 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 417 if (GNUNET_YES !=
398 { 418 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
399 ok = 404; 419 &test_directory))
400 return; 420 {
401 } 421 ok = 404;
422 return;
423 }
402 424
403 if (GNUNET_SYSERR == 425 if (GNUNET_SYSERR ==
404 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", 426 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
@@ -410,7 +432,8 @@ run (void *cls,
410 gets_succeeded = 0; 432 gets_succeeded = 0;
411 /* Set up a task to end testing if peer start fails */ 433 /* Set up a task to end testing if peer start fails */
412 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 434 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
413 &end_badly, "didn't start all daemons in reasonable amount of time!!!"); 435 &end_badly,
436 "didn't start all daemons in reasonable amount of time!!!");
414 437
415 pg = GNUNET_TESTING_daemons_start (cfg, 438 pg = GNUNET_TESTING_daemons_start (cfg,
416 num_peers, 439 num_peers,
@@ -419,8 +442,7 @@ run (void *cls,
419 TIMEOUT, 442 TIMEOUT,
420 NULL, NULL, 443 NULL, NULL,
421 &peers_started_callback, 444 &peers_started_callback,
422 NULL, 445 NULL, &topology_callback, NULL, NULL);
423 &topology_callback, NULL, NULL);
424 446
425} 447}
426 448
@@ -428,7 +450,8 @@ static int
428check () 450check ()
429{ 451{
430 int ret; 452 int ret;
431 char *const argv[] = {"test-dht-twopeer", 453
454 char *const argv[] = { "test-dht-twopeer",
432 "-c", 455 "-c",
433 "test_dht_twopeer_data.conf", 456 "test_dht_twopeer_data.conf",
434#if VERBOSE 457#if VERBOSE
@@ -440,12 +463,13 @@ check ()
440 GNUNET_GETOPT_OPTION_END 463 GNUNET_GETOPT_OPTION_END
441 }; 464 };
442 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 465 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
443 argv, "test-dht-twopeer", "nohelp", 466 argv, "test-dht-twopeer", "nohelp",
444 options, &run, &ok); 467 options, &run, &ok);
445 if (ret != GNUNET_OK) 468 if (ret != GNUNET_OK)
446 { 469 {
447 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-twopeer': Failed with error code %d\n", ret); 470 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
448 } 471 "`test-dht-twopeer': Failed with error code %d\n", ret);
472 }
449 return ok; 473 return ok;
450} 474}
451 475
@@ -467,9 +491,10 @@ main (int argc, char *argv[])
467 * of by the testing framework. 491 * of by the testing framework.
468 */ 492 */
469 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) 493 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
470 { 494 {
471 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); 495 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
472 } 496 "Failed to remove testing directory %s\n", test_directory);
497 }
473 return ret; 498 return ret;
474} 499}
475 500
diff --git a/src/dht/test_dht_twopeer_path_tracking.c b/src/dht/test_dht_twopeer_path_tracking.c
index d4e5a1332..ab0b1edd2 100644
--- a/src/dht/test_dht_twopeer_path_tracking.c
+++ b/src/dht/test_dht_twopeer_path_tracking.c
@@ -115,14 +115,14 @@ static struct GNUNET_DHT_Handle *peer2dht;
115/** 115/**
116 * Check whether peers successfully shut down. 116 * Check whether peers successfully shut down.
117 */ 117 */
118void shutdown_callback (void *cls, 118void
119 const char *emsg) 119shutdown_callback (void *cls, const char *emsg)
120{ 120{
121 if (emsg != NULL) 121 if (emsg != NULL)
122 { 122 {
123 if (ok == 0) 123 if (ok == 0)
124 ok = 2; 124 ok = 2;
125 } 125 }
126} 126}
127 127
128/** 128/**
@@ -130,13 +130,13 @@ void shutdown_callback (void *cls,
130 * testcase. Specifically, called when our get request completes. 130 * testcase. Specifically, called when our get request completes.
131 */ 131 */
132static void 132static void
133finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 133finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
134{ 134{
135 GNUNET_assert (pg != NULL); 135 GNUNET_assert (pg != NULL);
136 GNUNET_assert (peer1dht != NULL); 136 GNUNET_assert (peer1dht != NULL);
137 GNUNET_assert (peer2dht != NULL); 137 GNUNET_assert (peer2dht != NULL);
138 GNUNET_DHT_disconnect(peer1dht); 138 GNUNET_DHT_disconnect (peer1dht);
139 GNUNET_DHT_disconnect(peer2dht); 139 GNUNET_DHT_disconnect (peer2dht);
140 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 140 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
141 ok = 0; 141 ok = 0;
142} 142}
@@ -146,13 +146,13 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
146 * down the peers without freeing memory associated with GET request. 146 * down the peers without freeing memory associated with GET request.
147 */ 147 */
148static void 148static void
149end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 149end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
150{ 150{
151 if (peer1dht != NULL) 151 if (peer1dht != NULL)
152 GNUNET_DHT_disconnect(peer1dht); 152 GNUNET_DHT_disconnect (peer1dht);
153 153
154 if (peer2dht != NULL) 154 if (peer2dht != NULL)
155 GNUNET_DHT_disconnect(peer2dht); 155 GNUNET_DHT_disconnect (peer2dht);
156 156
157 if (pg != NULL) 157 if (pg != NULL)
158 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 158 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -164,15 +164,16 @@ end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
164 * test. 164 * test.
165 */ 165 */
166static void 166static void
167end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 167end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168{ 168{
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n", (char *)cls); 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
170 (char *) cls);
170 if (global_get_handle != NULL) 171 if (global_get_handle != NULL)
171 { 172 {
172 GNUNET_DHT_get_stop(global_get_handle); 173 GNUNET_DHT_get_stop (global_get_handle);
173 global_get_handle = NULL; 174 global_get_handle = NULL;
174 } 175 }
175 GNUNET_SCHEDULER_add_now(&end_badly_cont, NULL); 176 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
176 ok = 1; 177 ok = 1;
177} 178}
178 179
@@ -186,51 +187,54 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
186 * @param size number of bytes in data 187 * @param size number of bytes in data
187 * @param data pointer to the result data 188 * @param data pointer to the result data
188 */ 189 */
189void get_result_iterator (void *cls, 190void
190 struct GNUNET_TIME_Absolute exp, 191get_result_iterator (void *cls,
191 const GNUNET_HashCode * key, 192 struct GNUNET_TIME_Absolute exp,
192 const struct GNUNET_PeerIdentity * const *get_path, 193 const GNUNET_HashCode * key,
193 const struct GNUNET_PeerIdentity * const *put_path, 194 const struct GNUNET_PeerIdentity *const *get_path,
194 enum GNUNET_BLOCK_Type type, 195 const struct GNUNET_PeerIdentity *const *put_path,
195 size_t size, 196 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
196 const void *data)
197{ 197{
198 GNUNET_HashCode original_key; /* Key data was stored data under */ 198 GNUNET_HashCode original_key; /* Key data was stored data under */
199 char original_data[4]; /* Made up data that was stored */ 199 char original_data[4]; /* Made up data that was stored */
200 memset(&original_key, 42, sizeof(GNUNET_HashCode)); /* Set the key to what it was set to previously */ 200
201 memset(original_data, 43, sizeof(original_data)); 201 memset (&original_key, 42, sizeof (GNUNET_HashCode)); /* Set the key to what it was set to previously */
202 memset (original_data, 43, sizeof (original_data));
202#if VERBOSE 203#if VERBOSE
203 unsigned int i; 204 unsigned int i;
204#endif 205#endif
205 206
206 if ((0 != memcmp(&original_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data)))) 207 if ((0 != memcmp (&original_key, key, sizeof (GNUNET_HashCode))) ||
208 (0 != memcmp (original_data, data, sizeof (original_data))))
207 { 209 {
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n"); 210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
209 GNUNET_SCHEDULER_cancel(die_task); 211 "Key or data is not the same as was inserted!\n");
210 GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get response!\n"); 212 GNUNET_SCHEDULER_cancel (die_task);
213 GNUNET_SCHEDULER_add_now (&end_badly,
214 "key or data mismatch in get response!\n");
211 return; 215 return;
212 } 216 }
213 217
214#if VERBOSE 218#if VERBOSE
215 if (put_path != NULL) 219 if (put_path != NULL)
216 { 220 {
217 fprintf(stderr, "PUT Path: "); 221 fprintf (stderr, "PUT Path: ");
218 for (i = 0; put_path[i] != NULL; i++) 222 for (i = 0; put_path[i] != NULL; i++)
219 fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(put_path[i])); 223 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (put_path[i]));
220 fprintf(stderr, "\n"); 224 fprintf (stderr, "\n");
221 } 225 }
222 if (get_path != NULL) 226 if (get_path != NULL)
223 { 227 {
224 fprintf(stderr, "GET Path: "); 228 fprintf (stderr, "GET Path: ");
225 for (i = 0; get_path[i] != NULL; i++) 229 for (i = 0; get_path[i] != NULL; i++)
226 fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(get_path[i])); 230 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (get_path[i]));
227 fprintf(stderr, "\n"); 231 fprintf (stderr, "\n");
228 } 232 }
229#endif 233#endif
230 234
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n"); 235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
232 GNUNET_SCHEDULER_cancel(die_task); 236 GNUNET_SCHEDULER_cancel (die_task);
233 GNUNET_DHT_get_stop(global_get_handle); 237 GNUNET_DHT_get_stop (global_get_handle);
234 GNUNET_SCHEDULER_add_now (&finish_testing, NULL); 238 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
235} 239}
236 240
@@ -238,18 +242,16 @@ void get_result_iterator (void *cls,
238 * Start the GET request for the same key/data that was inserted. 242 * Start the GET request for the same key/data that was inserted.
239 */ 243 */
240static void 244static void
241do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 245do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
242{ 246{
243 GNUNET_HashCode key; /* Key for data lookup */ 247 GNUNET_HashCode key; /* Key for data lookup */
244 memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ 248
245 global_get_handle = GNUNET_DHT_get_start(peer2dht, GNUNET_TIME_relative_get_forever(), 249 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
246 GNUNET_BLOCK_TYPE_TEST, 250 global_get_handle =
247 &key, 251 GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (),
248 DEFAULT_GET_REPLICATION, 252 GNUNET_BLOCK_TYPE_TEST, &key,
249 GNUNET_DHT_RO_RECORD_ROUTE, 253 DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_RECORD_ROUTE,
250 NULL, 0, 254 NULL, 0, NULL, 0, &get_result_iterator, NULL);
251 NULL, 0,
252 &get_result_iterator, NULL);
253} 255}
254 256
255/** 257/**
@@ -257,35 +259,37 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
257 * Schedule the GET request for some time in the future. 259 * Schedule the GET request for some time in the future.
258 */ 260 */
259static void 261static void
260put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 262put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
261{ 263{
262 GNUNET_SCHEDULER_cancel (die_task); 264 GNUNET_SCHEDULER_cancel (die_task);
263 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, 265 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
264 &end_badly, "waiting for get response (data not found)"); 266 &end_badly,
265 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); 267 "waiting for get response (data not found)");
268 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
269 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
266} 270}
267 271
268/** 272/**
269 * Set up some data, and call API PUT function 273 * Set up some data, and call API PUT function
270 */ 274 */
271static void 275static void
272do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 276do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
273{ 277{
274 GNUNET_HashCode key; /* Made up key to store data under */ 278 GNUNET_HashCode key; /* Made up key to store data under */
275 char data[4]; /* Made up data to store */ 279 char data[4]; /* Made up data to store */
276 memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to something simple so we can issue GET request */ 280
277 memset(data, 43, sizeof(data)); 281 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to something simple so we can issue GET request */
282 memset (data, 43, sizeof (data));
278 283
279 /* Insert the data at the first peer */ 284 /* Insert the data at the first peer */
280 GNUNET_DHT_put(peer1dht, 285 GNUNET_DHT_put (peer1dht,
281 &key, 286 &key,
282 DEFAULT_PUT_REPLICATION, 287 DEFAULT_PUT_REPLICATION,
283 GNUNET_DHT_RO_RECORD_ROUTE, 288 GNUNET_DHT_RO_RECORD_ROUTE,
284 GNUNET_BLOCK_TYPE_TEST, 289 GNUNET_BLOCK_TYPE_TEST,
285 sizeof(data), data, 290 sizeof (data), data,
286 GNUNET_TIME_UNIT_FOREVER_ABS, 291 GNUNET_TIME_UNIT_FOREVER_ABS,
287 GNUNET_TIME_UNIT_FOREVER_REL, 292 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
288 &put_finished, NULL);
289} 293}
290 294
291/** 295/**
@@ -309,43 +313,45 @@ topology_callback (void *cls,
309 const char *emsg) 313 const char *emsg)
310{ 314{
311 if (emsg == NULL) 315 if (emsg == NULL)
312 { 316 {
313 total_connections++; 317 total_connections++;
314#if VERBOSE 318#if VERBOSE
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", 319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316 first_daemon->shortname, 320 "connected peer %s to peer %s, distance %u\n",
317 second_daemon->shortname, 321 first_daemon->shortname, second_daemon->shortname, distance);
318 distance);
319#endif 322#endif
320 } 323 }
321#if VERBOSE 324#if VERBOSE
322 else 325 else
323 { 326 {
324 failed_connections++; 327 failed_connections++;
325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
326 first_daemon->shortname, 329 "Failed to connect peer %s to peer %s with error :\n%s\n",
327 second_daemon->shortname, emsg); 330 first_daemon->shortname, second_daemon->shortname, emsg);
328 } 331 }
329#endif 332#endif
330 333
331 if (total_connections == expected_connections) 334 if (total_connections == expected_connections)
332 { 335 {
333#if VERBOSE 336#if VERBOSE
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
335 "Created %d total connections, which is our target number! Starting next phase of testing.\n", 338 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
336 total_connections); 339 total_connections);
337#endif 340#endif
338 GNUNET_SCHEDULER_cancel (die_task); 341 GNUNET_SCHEDULER_cancel (die_task);
339 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 342 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
340 &end_badly, "from test gets"); 343 &end_badly, "from test gets");
341 344
342 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL); 345 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
343 } 346 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
347 }
344 else if (total_connections + failed_connections == expected_connections) 348 else if (total_connections + failed_connections == expected_connections)
345 { 349 {
346 GNUNET_SCHEDULER_cancel (die_task); 350 GNUNET_SCHEDULER_cancel (die_task);
347 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); 351 die_task =
348 } 352 GNUNET_SCHEDULER_add_now (&end_badly,
353 "from topology_callback (too many failed connections)");
354 }
349} 355}
350 356
351 357
@@ -362,74 +368,74 @@ topology_callback (void *cls,
362 */ 368 */
363static void 369static void
364peers_started_callback (void *cls, 370peers_started_callback (void *cls,
365 const struct GNUNET_PeerIdentity *id, 371 const struct GNUNET_PeerIdentity *id,
366 const struct GNUNET_CONFIGURATION_Handle *cfg, 372 const struct GNUNET_CONFIGURATION_Handle *cfg,
367 struct GNUNET_TESTING_Daemon *d, const char *emsg) 373 struct GNUNET_TESTING_Daemon *d, const char *emsg)
368{ 374{
369 if (emsg != NULL) 375 if (emsg != NULL)
370 { 376 {
371 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with error: `%s'\n", 377 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
372 emsg); 378 "Failed to start daemon with error: `%s'\n", emsg);
373 return; 379 return;
374 } 380 }
375 GNUNET_assert (id != NULL); 381 GNUNET_assert (id != NULL);
376 382
377 /* This is the first peer started */ 383 /* This is the first peer started */
378 if (peers_left == num_peers) 384 if (peers_left == num_peers)
379 { 385 {
380 memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); /* Save the peer id */ 386 memcpy (&peer1id, id, sizeof (struct GNUNET_PeerIdentity)); /* Save the peer id */
381 peer1dht = GNUNET_DHT_connect(cfg, 100); /* Connect to the first peers DHT service */ 387 peer1dht = GNUNET_DHT_connect (cfg, 100); /* Connect to the first peers DHT service */
382 if (peer1dht == NULL) /* If DHT connect failed */ 388 if (peer1dht == NULL) /* If DHT connect failed */
383 { 389 {
384 GNUNET_SCHEDULER_cancel (die_task); 390 GNUNET_SCHEDULER_cancel (die_task);
385 GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); 391 GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
386 } 392 }
387 } 393 }
388 else /* This is the second peer started */ 394 else /* This is the second peer started */
389 { 395 {
390 memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); /* Same as for first peer... */ 396 memcpy (&peer2id, id, sizeof (struct GNUNET_PeerIdentity)); /* Same as for first peer... */
391 peer2dht = GNUNET_DHT_connect(cfg, 100); 397 peer2dht = GNUNET_DHT_connect (cfg, 100);
392 if (peer2dht == NULL) 398 if (peer2dht == NULL)
393 { 399 {
394 GNUNET_SCHEDULER_cancel (die_task); 400 GNUNET_SCHEDULER_cancel (die_task);
395 GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); 401 GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
396 } 402 }
397 } 403 }
398 404
399 /* Decrement number of peers left to start */ 405 /* Decrement number of peers left to start */
400 peers_left--; 406 peers_left--;
401 407
402 if (peers_left == 0) /* Indicates all peers started */ 408 if (peers_left == 0) /* Indicates all peers started */
403 { 409 {
404#if VERBOSE 410#if VERBOSE
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
406 "All %d daemons started, now connecting peers!\n", 412 "All %d daemons started, now connecting peers!\n", num_peers);
407 num_peers);
408#endif 413#endif
409 expected_connections = -1; 414 expected_connections = -1;
410 if ((pg != NULL)) /* Sanity check */ 415 if ((pg != NULL)) /* Sanity check */
411 { 416 {
412 /* Connect peers in a "straight line" topology, return the number of expected connections */ 417 /* Connect peers in a "straight line" topology, return the number of expected connections */
413 expected_connections = GNUNET_TESTING_connect_topology (pg, 418 expected_connections = GNUNET_TESTING_connect_topology (pg,
414 GNUNET_TESTING_TOPOLOGY_LINE, 419 GNUNET_TESTING_TOPOLOGY_LINE,
415 GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 420 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
416 0.0, 421 0.0,
417 TIMEOUT, 422 TIMEOUT,
418 2, 423 2, NULL, NULL);
419 NULL,
420 NULL);
421 }
422
423 /* Cancel current timeout fail task */
424 GNUNET_SCHEDULER_cancel (die_task);
425 if (expected_connections == GNUNET_SYSERR) /* Some error happened */
426 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)");
427
428 /* Schedule timeout on failure task */
429 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
430 &end_badly, "from connect topology (timeout)");
431 ok = 0;
432 } 424 }
425
426 /* Cancel current timeout fail task */
427 GNUNET_SCHEDULER_cancel (die_task);
428 if (expected_connections == GNUNET_SYSERR) /* Some error happened */
429 die_task =
430 GNUNET_SCHEDULER_add_now (&end_badly,
431 "from connect topology (bad return)");
432
433 /* Schedule timeout on failure task */
434 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
435 &end_badly,
436 "from connect topology (timeout)");
437 ok = 0;
438 }
433} 439}
434 440
435static void 441static void
@@ -439,11 +445,13 @@ run (void *cls,
439{ 445{
440 446
441 /* Get path from configuration file */ 447 /* Get path from configuration file */
442 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 448 if (GNUNET_YES !=
443 { 449 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
444 ok = 404; 450 &test_directory))
445 return; 451 {
446 } 452 ok = 404;
453 return;
454 }
447 455
448 /* Get number of peers to start from configuration (should be two) */ 456 /* Get number of peers to start from configuration (should be two) */
449 if (GNUNET_SYSERR == 457 if (GNUNET_SYSERR ==
@@ -456,22 +464,19 @@ run (void *cls,
456 464
457 /* Set up a task to end testing if peer start fails */ 465 /* Set up a task to end testing if peer start fails */
458 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 466 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
459 &end_badly, "didn't start all daemons in reasonable amount of time!!!"); 467 &end_badly,
468 "didn't start all daemons in reasonable amount of time!!!");
460 469
461 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */ 470 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */
462 /* Read the API documentation for other parameters! */ 471 /* Read the API documentation for other parameters! */
463 pg = GNUNET_TESTING_daemons_start (cfg, 472 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
464 peers_left, /* Total number of peers */ 473 peers_left, /* Number of outstanding connections */
465 peers_left, /* Number of outstanding connections */ 474 peers_left, /* Number of parallel ssh connections, or peers being started at once */
466 peers_left, /* Number of parallel ssh connections, or peers being started at once */
467 TIMEOUT, 475 TIMEOUT,
468 NULL, 476 NULL,
469 NULL, 477 NULL,
470 &peers_started_callback, 478 &peers_started_callback,
471 NULL, 479 NULL, &topology_callback, NULL, NULL);
472 &topology_callback,
473 NULL,
474 NULL);
475 480
476} 481}
477 482
@@ -479,10 +484,11 @@ static int
479check () 484check ()
480{ 485{
481 int ret; 486 int ret;
487
482 /* Arguments for GNUNET_PROGRAM_run */ 488 /* Arguments for GNUNET_PROGRAM_run */
483 char *const argv[] = {"test-dht-twopeer-put-get", /* Name to give running binary */ 489 char *const argv[] = { "test-dht-twopeer-put-get", /* Name to give running binary */
484 "-c", 490 "-c",
485 "test_dht_twopeer_data.conf", /* Config file to use */ 491 "test_dht_twopeer_data.conf", /* Config file to use */
486#if VERBOSE 492#if VERBOSE
487 "-L", "DEBUG", 493 "-L", "DEBUG",
488#endif 494#endif
@@ -493,12 +499,13 @@ check ()
493 }; 499 };
494 /* Run the run function as a new program */ 500 /* Run the run function as a new program */
495 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 501 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
496 argv, "test-dht-twopeer-put-get", "nohelp", 502 argv, "test-dht-twopeer-put-get", "nohelp",
497 options, &run, &ok); 503 options, &run, &ok);
498 if (ret != GNUNET_OK) 504 if (ret != GNUNET_OK)
499 { 505 {
500 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-twopeer': Failed with error code %d\n", ret); 506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
501 } 507 "`test-dht-twopeer': Failed with error code %d\n", ret);
508 }
502 return ok; 509 return ok;
503} 510}
504 511
@@ -520,9 +527,10 @@ main (int argc, char *argv[])
520 * of by the testing framework. 527 * of by the testing framework.
521 */ 528 */
522 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) 529 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
523 { 530 {
524 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); 531 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
525 } 532 "Failed to remove testing directory %s\n", test_directory);
533 }
526 return ret; 534 return ret;
527} 535}
528 536
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c
index 40a165236..9db0ca385 100644
--- a/src/dht/test_dht_twopeer_put_get.c
+++ b/src/dht/test_dht_twopeer_put_get.c
@@ -137,14 +137,14 @@ static struct GNUNET_DHT_Handle *peer2dht;
137/** 137/**
138 * Check whether peers successfully shut down. 138 * Check whether peers successfully shut down.
139 */ 139 */
140void shutdown_callback (void *cls, 140void
141 const char *emsg) 141shutdown_callback (void *cls, const char *emsg)
142{ 142{
143 if (emsg != NULL) 143 if (emsg != NULL)
144 { 144 {
145 if (ok == 0) 145 if (ok == 0)
146 ok = 2; 146 ok = 2;
147 } 147 }
148} 148}
149 149
150/** 150/**
@@ -152,13 +152,13 @@ void shutdown_callback (void *cls,
152 * testcase. Specifically, called when our get request completes. 152 * testcase. Specifically, called when our get request completes.
153 */ 153 */
154static void 154static void
155finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 155finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156{ 156{
157 GNUNET_assert (pg != NULL); 157 GNUNET_assert (pg != NULL);
158 GNUNET_assert (peer1dht != NULL); 158 GNUNET_assert (peer1dht != NULL);
159 GNUNET_assert (peer2dht != NULL); 159 GNUNET_assert (peer2dht != NULL);
160 GNUNET_DHT_disconnect(peer1dht); 160 GNUNET_DHT_disconnect (peer1dht);
161 GNUNET_DHT_disconnect(peer2dht); 161 GNUNET_DHT_disconnect (peer2dht);
162 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 162 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
163 ok = 0; 163 ok = 0;
164} 164}
@@ -168,13 +168,13 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
168 * down the peers without freeing memory associated with GET request. 168 * down the peers without freeing memory associated with GET request.
169 */ 169 */
170static void 170static void
171end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 171end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
172{ 172{
173 if (peer1dht != NULL) 173 if (peer1dht != NULL)
174 GNUNET_DHT_disconnect(peer1dht); 174 GNUNET_DHT_disconnect (peer1dht);
175 175
176 if (peer2dht != NULL) 176 if (peer2dht != NULL)
177 GNUNET_DHT_disconnect(peer2dht); 177 GNUNET_DHT_disconnect (peer2dht);
178 178
179 if (pg != NULL) 179 if (pg != NULL)
180 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 180 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -186,15 +186,16 @@ end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
186 * test. 186 * test.
187 */ 187 */
188static void 188static void
189end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 189end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
190{ 190{
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n", (char *)cls); 191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
192 (char *) cls);
192 if (global_get_handle != NULL) 193 if (global_get_handle != NULL)
193 { 194 {
194 GNUNET_DHT_get_stop(global_get_handle); 195 GNUNET_DHT_get_stop (global_get_handle);
195 global_get_handle = NULL; 196 global_get_handle = NULL;
196 } 197 }
197 GNUNET_SCHEDULER_add_now(&end_badly_cont, NULL); 198 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
198 ok = 1; 199 ok = 1;
199} 200}
200 201
@@ -208,40 +209,47 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
208 * @param size number of bytes in data 209 * @param size number of bytes in data
209 * @param data pointer to the result data 210 * @param data pointer to the result data
210 */ 211 */
211void get_result_iterator (void *cls, 212void
212 struct GNUNET_TIME_Absolute exp, 213get_result_iterator (void *cls,
213 const GNUNET_HashCode * key, 214 struct GNUNET_TIME_Absolute exp,
214 const struct GNUNET_PeerIdentity * const *get_path, 215 const GNUNET_HashCode * key,
215 const struct GNUNET_PeerIdentity * const *put_path, 216 const struct GNUNET_PeerIdentity *const *get_path,
216 enum GNUNET_BLOCK_Type type, 217 const struct GNUNET_PeerIdentity *const *put_path,
217 size_t size, 218 enum GNUNET_BLOCK_Type type,
218 const void *result_data) 219 size_t size, const void *result_data)
219{ 220{
220 GNUNET_HashCode original_key; /* Key data was stored data under */ 221 GNUNET_HashCode original_key; /* Key data was stored data under */
221 char original_data[4]; /* Made up data that was stored */ 222 char original_data[4]; /* Made up data that was stored */
222 memset(&original_key, 42, sizeof(GNUNET_HashCode)); /* Set the key to what it was set to previously */ 223
223 memset(original_data, 43, sizeof(original_data)); 224 memset (&original_key, 42, sizeof (GNUNET_HashCode)); /* Set the key to what it was set to previously */
225 memset (original_data, 43, sizeof (original_data));
224 226
225#if DNS 227#if DNS
226 if ((0 != memcmp(&data.service_descriptor, key, sizeof (GNUNET_HashCode))) || (0 != memcmp((char *)&data, result_data, sizeof(original_data)))) 228 if ((0 != memcmp (&data.service_descriptor, key, sizeof (GNUNET_HashCode))) ||
227 { 229 (0 != memcmp ((char *) &data, result_data, sizeof (original_data))))
228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key or data is not the same as was inserted!\n"); 230 {
229 GNUNET_SCHEDULER_cancel(die_task); 231 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
230 GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get response!\n"); 232 "Key or data is not the same as was inserted!\n");
231 return; 233 GNUNET_SCHEDULER_cancel (die_task);
232 } 234 GNUNET_SCHEDULER_add_now (&end_badly,
235 "key or data mismatch in get response!\n");
236 return;
237 }
233#else 238#else
234 if ((0 != memcmp(&original_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, result_data, sizeof(original_data)))) 239 if ((0 != memcmp (&original_key, key, sizeof (GNUNET_HashCode))) ||
240 (0 != memcmp (original_data, result_data, sizeof (original_data))))
235 { 241 {
236 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key or data is not the same as was inserted!\n"); 242 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
237 GNUNET_SCHEDULER_cancel(die_task); 243 "Key or data is not the same as was inserted!\n");
238 GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get response!\n"); 244 GNUNET_SCHEDULER_cancel (die_task);
245 GNUNET_SCHEDULER_add_now (&end_badly,
246 "key or data mismatch in get response!\n");
239 return; 247 return;
240 } 248 }
241#endif 249#endif
242 250
243 GNUNET_SCHEDULER_cancel(die_task); 251 GNUNET_SCHEDULER_cancel (die_task);
244 GNUNET_DHT_get_stop(global_get_handle); 252 GNUNET_DHT_get_stop (global_get_handle);
245 GNUNET_SCHEDULER_add_now (&finish_testing, NULL); 253 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
246} 254}
247 255
@@ -249,26 +257,26 @@ void get_result_iterator (void *cls,
249 * Start the GET request for the same key/data that was inserted. 257 * Start the GET request for the same key/data that was inserted.
250 */ 258 */
251static void 259static void
252do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 260do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
253{ 261{
254 GNUNET_HashCode key; /* Key for data lookup */ 262 GNUNET_HashCode key; /* Key for data lookup */
263
255#if DNS 264#if DNS
256 memcpy(&key, &data.service_descriptor, sizeof(GNUNET_HashCode)); 265 memcpy (&key, &data.service_descriptor, sizeof (GNUNET_HashCode));
257#else 266#else
258 memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ 267 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
259#endif 268#endif
260 global_get_handle = GNUNET_DHT_get_start(peer2dht, GNUNET_TIME_relative_get_forever(), 269 global_get_handle =
270 GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (),
261#if DNS 271#if DNS
262 GNUNET_BLOCK_TYPE_DNS, 272 GNUNET_BLOCK_TYPE_DNS,
263#else 273#else
264 GNUNET_BLOCK_TYPE_TEST, 274 GNUNET_BLOCK_TYPE_TEST,
265#endif 275#endif
266 &key, 276 &key,
267 DEFAULT_GET_REPLICATION, 277 DEFAULT_GET_REPLICATION,
268 GNUNET_DHT_RO_NONE, 278 GNUNET_DHT_RO_NONE,
269 NULL, 0, 279 NULL, 0, NULL, 0, &get_result_iterator, NULL);
270 NULL, 0,
271 &get_result_iterator, NULL);
272} 280}
273 281
274/** 282/**
@@ -276,12 +284,14 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
276 * Schedule the GET request for some time in the future. 284 * Schedule the GET request for some time in the future.
277 */ 285 */
278static void 286static void
279put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 287put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
280{ 288{
281 GNUNET_SCHEDULER_cancel (die_task); 289 GNUNET_SCHEDULER_cancel (die_task);
282 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, 290 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
283 &end_badly, "waiting for get response (data not found)"); 291 &end_badly,
284 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); 292 "waiting for get response (data not found)");
293 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
294 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
285} 295}
286 296
287 297
@@ -290,23 +300,23 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
290 * Set up some data, and call API PUT function 300 * Set up some data, and call API PUT function
291 */ 301 */
292static void 302static void
293do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 303do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
294{ 304{
295 GNUNET_HashCode key; /* Made up key to store data under */ 305 GNUNET_HashCode key; /* Made up key to store data under */
296 char data[4]; /* Made up data to store */ 306 char data[4]; /* Made up data to store */
297 memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to something simple so we can issue GET request */ 307
298 memset(data, 43, sizeof(data)); 308 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to something simple so we can issue GET request */
309 memset (data, 43, sizeof (data));
299 310
300 /* Insert the data at the first peer */ 311 /* Insert the data at the first peer */
301 GNUNET_DHT_put(peer1dht, 312 GNUNET_DHT_put (peer1dht,
302 &key, 313 &key,
303 DEFAULT_PUT_REPLICATION, 314 DEFAULT_PUT_REPLICATION,
304 GNUNET_DHT_RO_NONE, 315 GNUNET_DHT_RO_NONE,
305 GNUNET_BLOCK_TYPE_TEST, 316 GNUNET_BLOCK_TYPE_TEST,
306 sizeof(data), data, 317 sizeof (data), data,
307 GNUNET_TIME_UNIT_FOREVER_ABS, 318 GNUNET_TIME_UNIT_FOREVER_ABS,
308 GNUNET_TIME_UNIT_FOREVER_REL, 319 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
309 &put_finished, NULL);
310} 320}
311#else 321#else
312 322
@@ -314,55 +324,56 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
314 * Set up some data, and call API PUT function 324 * Set up some data, and call API PUT function
315 */ 325 */
316static void 326static void
317do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 327do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
318{ 328{
319 char* name = "philipptoelke.gnunet."; 329 char *name = "philipptoelke.gnunet.";
320 size_t size = sizeof(struct GNUNET_DNS_Record); 330 size_t size = sizeof (struct GNUNET_DNS_Record);
321 memset(&data, 0, size); 331
332 memset (&data, 0, size);
322 333
323 data.purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_RsaSignature)); 334 data.purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
324 data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD; 335 data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD;
325 336
326 GNUNET_CRYPTO_hash(name, strlen(name)+1, &data.service_descriptor); 337 GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor);
338
339 data.service_type = htonl (GNUNET_DNS_SERVICE_TYPE_UDP);
340 data.ports = htons (69);
327 341
328 data.service_type = htonl(GNUNET_DNS_SERVICE_TYPE_UDP); 342 char *keyfile;
329 data.ports = htons(69);
330 343
331 char* keyfile; 344 GNUNET_asprintf (&keyfile, "/tmp/test_dns_data_key");
332 GNUNET_asprintf(&keyfile, "/tmp/test_dns_data_key"); 345 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key =
333 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file(keyfile); 346 GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
334 GNUNET_free(keyfile); 347 GNUNET_free (keyfile);
335 GNUNET_assert(my_private_key != NULL); 348 GNUNET_assert (my_private_key != NULL);
336 349
337 GNUNET_CRYPTO_rsa_key_get_public(my_private_key, &data.peer); 350 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
338 351
339 data.expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS); 352 data.expiration_time =
353 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
340 354
341 /* Sign the block */ 355 /* Sign the block */
342 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign(my_private_key, 356 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key,
343 &data.purpose, 357 &data.purpose, &data.signature))
344 &data.signature)) 358 {
345 { 359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
346 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); 360 return;
347 return; 361 }
348 } 362 GNUNET_CRYPTO_rsa_key_free (my_private_key);
349 GNUNET_CRYPTO_rsa_key_free(my_private_key); 363
350 364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 365 "Putting with key %08x\n",
352 "Putting with key %08x\n", 366 *((unsigned int *) &data.service_descriptor));
353 *((unsigned int*)&data.service_descriptor)); 367
354 368 GNUNET_DHT_put (peer1dht,
355 GNUNET_DHT_put(peer1dht, 369 &data.service_descriptor,
356 &data.service_descriptor, 370 DEFAULT_PUT_REPLICATION,
357 DEFAULT_PUT_REPLICATION, 371 GNUNET_DHT_RO_NONE,
358 GNUNET_DHT_RO_NONE, 372 GNUNET_BLOCK_TYPE_DNS,
359 GNUNET_BLOCK_TYPE_DNS, 373 size,
360 size, 374 (char *) &data,
361 (char*)&data, 375 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
362 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS), 376 GNUNET_TIME_UNIT_MINUTES, &put_finished, NULL);
363 GNUNET_TIME_UNIT_MINUTES,
364 &put_finished,
365 NULL);
366} 377}
367#endif 378#endif
368 379
@@ -387,43 +398,45 @@ topology_callback (void *cls,
387 const char *emsg) 398 const char *emsg)
388{ 399{
389 if (emsg == NULL) 400 if (emsg == NULL)
390 { 401 {
391 total_connections++; 402 total_connections++;
392#if VERBOSE 403#if VERBOSE
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", 404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 first_daemon->shortname, 405 "connected peer %s to peer %s, distance %u\n",
395 second_daemon->shortname, 406 first_daemon->shortname, second_daemon->shortname, distance);
396 distance);
397#endif 407#endif
398 } 408 }
399#if VERBOSE 409#if VERBOSE
400 else 410 else
401 { 411 {
402 failed_connections++; 412 failed_connections++;
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", 413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 first_daemon->shortname, 414 "Failed to connect peer %s to peer %s with error :\n%s\n",
405 second_daemon->shortname, emsg); 415 first_daemon->shortname, second_daemon->shortname, emsg);
406 } 416 }
407#endif 417#endif
408 418
409 if (total_connections == expected_connections) 419 if (total_connections == expected_connections)
410 { 420 {
411#if VERBOSE 421#if VERBOSE
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "Created %d total connections, which is our target number! Starting next phase of testing.\n", 423 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
414 total_connections); 424 total_connections);
415#endif 425#endif
416 GNUNET_SCHEDULER_cancel (die_task); 426 GNUNET_SCHEDULER_cancel (die_task);
417 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 427 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
418 &end_badly, "from test gets"); 428 &end_badly, "from test gets");
419 429
420 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL); 430 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
421 } 431 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
432 }
422 else if (total_connections + failed_connections == expected_connections) 433 else if (total_connections + failed_connections == expected_connections)
423 { 434 {
424 GNUNET_SCHEDULER_cancel (die_task); 435 GNUNET_SCHEDULER_cancel (die_task);
425 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); 436 die_task =
426 } 437 GNUNET_SCHEDULER_add_now (&end_badly,
438 "from topology_callback (too many failed connections)");
439 }
427} 440}
428 441
429 442
@@ -440,73 +453,74 @@ topology_callback (void *cls,
440 */ 453 */
441static void 454static void
442peers_started_callback (void *cls, 455peers_started_callback (void *cls,
443 const struct GNUNET_PeerIdentity *id, 456 const struct GNUNET_PeerIdentity *id,
444 const struct GNUNET_CONFIGURATION_Handle *cfg, 457 const struct GNUNET_CONFIGURATION_Handle *cfg,
445 struct GNUNET_TESTING_Daemon *d, const char *emsg) 458 struct GNUNET_TESTING_Daemon *d, const char *emsg)
446{ 459{
447 if (emsg != NULL) 460 if (emsg != NULL)
448 { 461 {
449 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with error: `%s'\n", 462 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
450 emsg); 463 "Failed to start daemon with error: `%s'\n", emsg);
451 return; 464 return;
452 } 465 }
453 GNUNET_assert (id != NULL); 466 GNUNET_assert (id != NULL);
454 467
455 /* This is the first peer started */ 468 /* This is the first peer started */
456 if (peers_left == num_peers) 469 if (peers_left == num_peers)
457 { 470 {
458 memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); /* Save the peer id */ 471 memcpy (&peer1id, id, sizeof (struct GNUNET_PeerIdentity)); /* Save the peer id */
459 peer1dht = GNUNET_DHT_connect(cfg, 100); /* Connect to the first peers DHT service */ 472 peer1dht = GNUNET_DHT_connect (cfg, 100); /* Connect to the first peers DHT service */
460 if (peer1dht == NULL) /* If DHT connect failed */ 473 if (peer1dht == NULL) /* If DHT connect failed */
461 { 474 {
462 GNUNET_SCHEDULER_cancel (die_task); 475 GNUNET_SCHEDULER_cancel (die_task);
463 GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); 476 GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
464 } 477 }
465 } 478 }
466 else /* This is the second peer started */ 479 else /* This is the second peer started */
467 { 480 {
468 memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); /* Same as for first peer... */ 481 memcpy (&peer2id, id, sizeof (struct GNUNET_PeerIdentity)); /* Same as for first peer... */
469 peer2dht = GNUNET_DHT_connect(cfg, 100); 482 peer2dht = GNUNET_DHT_connect (cfg, 100);
470 if (peer2dht == NULL) 483 if (peer2dht == NULL)
471 { 484 {
472 GNUNET_SCHEDULER_cancel (die_task); 485 GNUNET_SCHEDULER_cancel (die_task);
473 GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); 486 GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
474 } 487 }
475 } 488 }
476 489
477 /* Decrement number of peers left to start */ 490 /* Decrement number of peers left to start */
478 peers_left--; 491 peers_left--;
479 492
480 if (peers_left == 0) /* Indicates all peers started */ 493 if (peers_left == 0) /* Indicates all peers started */
481 { 494 {
482#if VERBOSE 495#if VERBOSE
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
484 "All %d daemons started, now connecting peers!\n", 497 "All %d daemons started, now connecting peers!\n", num_peers);
485 num_peers);
486#endif 498#endif
487 expected_connections = -1; 499 expected_connections = -1;
488 if ((pg != NULL)) /* Sanity check */ 500 if ((pg != NULL)) /* Sanity check */
489 { 501 {
490 /* Connect peers in a "straight line" topology, return the number of expected connections */ 502 /* Connect peers in a "straight line" topology, return the number of expected connections */
491 expected_connections = GNUNET_TESTING_connect_topology (pg, 503 expected_connections = GNUNET_TESTING_connect_topology (pg,
492 GNUNET_TESTING_TOPOLOGY_LINE, 504 GNUNET_TESTING_TOPOLOGY_LINE,
493 GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 505 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
494 0.0, 506 0.0,
495 TIMEOUT, 507 TIMEOUT,
496 12, 508 12, NULL, NULL);
497 NULL, NULL);
498 }
499
500 /* Cancel current timeout fail task */
501 GNUNET_SCHEDULER_cancel (die_task);
502 if (expected_connections == GNUNET_SYSERR) /* Some error happened */
503 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)");
504
505 /* Schedule timeout on failure task */
506 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
507 &end_badly, "from connect topology (timeout)");
508 ok = 0;
509 } 509 }
510
511 /* Cancel current timeout fail task */
512 GNUNET_SCHEDULER_cancel (die_task);
513 if (expected_connections == GNUNET_SYSERR) /* Some error happened */
514 die_task =
515 GNUNET_SCHEDULER_add_now (&end_badly,
516 "from connect topology (bad return)");
517
518 /* Schedule timeout on failure task */
519 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
520 &end_badly,
521 "from connect topology (timeout)");
522 ok = 0;
523 }
510} 524}
511 525
512static void 526static void
@@ -516,11 +530,13 @@ run (void *cls,
516{ 530{
517 531
518 /* Get path from configuration file */ 532 /* Get path from configuration file */
519 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 533 if (GNUNET_YES !=
520 { 534 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
521 ok = 404; 535 &test_directory))
522 return; 536 {
523 } 537 ok = 404;
538 return;
539 }
524 540
525 /* Get number of peers to start from configuration (should be two) */ 541 /* Get number of peers to start from configuration (should be two) */
526 if (GNUNET_SYSERR == 542 if (GNUNET_SYSERR ==
@@ -533,7 +549,8 @@ run (void *cls,
533 549
534 /* Set up a task to end testing if peer start fails */ 550 /* Set up a task to end testing if peer start fails */
535 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 551 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
536 &end_badly, "didn't start all daemons in reasonable amount of time!!!"); 552 &end_badly,
553 "didn't start all daemons in reasonable amount of time!!!");
537 554
538 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */ 555 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */
539 /* Read the API documentation for other parameters! */ 556 /* Read the API documentation for other parameters! */
@@ -545,10 +562,7 @@ run (void *cls,
545 NULL, 562 NULL,
546 NULL, 563 NULL,
547 &peers_started_callback, 564 &peers_started_callback,
548 NULL, 565 NULL, &topology_callback, NULL, NULL);
549 &topology_callback,
550 NULL,
551 NULL);
552 566
553} 567}
554 568
@@ -556,10 +570,11 @@ static int
556check () 570check ()
557{ 571{
558 int ret; 572 int ret;
573
559 /* Arguments for GNUNET_PROGRAM_run */ 574 /* Arguments for GNUNET_PROGRAM_run */
560 char *const argv[] = {"test-dht-twopeer-put-get", /* Name to give running binary */ 575 char *const argv[] = { "test-dht-twopeer-put-get", /* Name to give running binary */
561 "-c", 576 "-c",
562 "test_dht_twopeer_data.conf", /* Config file to use */ 577 "test_dht_twopeer_data.conf", /* Config file to use */
563#if VERBOSE 578#if VERBOSE
564 "-L", "DEBUG", 579 "-L", "DEBUG",
565#endif 580#endif
@@ -570,12 +585,13 @@ check ()
570 }; 585 };
571 /* Run the run function as a new program */ 586 /* Run the run function as a new program */
572 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 587 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
573 argv, "test-dht-twopeer-put-get", "nohelp", 588 argv, "test-dht-twopeer-put-get", "nohelp",
574 options, &run, &ok); 589 options, &run, &ok);
575 if (ret != GNUNET_OK) 590 if (ret != GNUNET_OK)
576 { 591 {
577 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-twopeer': Failed with error code %d\n", ret); 592 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
578 } 593 "`test-dht-twopeer': Failed with error code %d\n", ret);
594 }
579 return ok; 595 return ok;
580} 596}
581 597
@@ -597,9 +613,10 @@ main (int argc, char *argv[])
597 * of by the testing framework. 613 * of by the testing framework.
598 */ 614 */
599 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) 615 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
600 { 616 {
601 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); 617 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
602 } 618 "Failed to remove testing directory %s\n", test_directory);
619 }
603 return ret; 620 return ret;
604} 621}
605 622
diff --git a/src/dht/test_dhtlog.c b/src/dht/test_dhtlog.c
index 5c6d5c578..4021f5db5 100644
--- a/src/dht/test_dhtlog.c
+++ b/src/dht/test_dhtlog.c
@@ -37,7 +37,7 @@ static int ok;
37 * Actual test of the service operations 37 * Actual test of the service operations
38 */ 38 */
39static int 39static int
40test (struct GNUNET_DHTLOG_Handle * api) 40test (struct GNUNET_DHTLOG_Handle *api)
41{ 41{
42 struct GNUNET_PeerIdentity p1; 42 struct GNUNET_PeerIdentity p1;
43 struct GNUNET_PeerIdentity p2; 43 struct GNUNET_PeerIdentity p2;
@@ -53,6 +53,7 @@ test (struct GNUNET_DHTLOG_Handle * api)
53 unsigned long long nodeuid = 0; 53 unsigned long long nodeuid = 0;
54 unsigned long long internaluid = 1010223344LL; 54 unsigned long long internaluid = 1010223344LL;
55 unsigned long long dhtkeyuid = 0; 55 unsigned long long dhtkeyuid = 0;
56
56 memset (&p1.hashPubKey, 3, sizeof (GNUNET_HashCode)); 57 memset (&p1.hashPubKey, 3, sizeof (GNUNET_HashCode));
57 memset (&p2.hashPubKey, 4, sizeof (GNUNET_HashCode)); 58 memset (&p2.hashPubKey, 4, sizeof (GNUNET_HashCode));
58 memset (&p3.hashPubKey, 5, sizeof (GNUNET_HashCode)); 59 memset (&p3.hashPubKey, 5, sizeof (GNUNET_HashCode));
@@ -60,7 +61,7 @@ test (struct GNUNET_DHTLOG_Handle * api)
60 61
61 memset (&k1, 0, sizeof (GNUNET_HashCode)); 62 memset (&k1, 0, sizeof (GNUNET_HashCode));
62 memset (&k2, 1, sizeof (GNUNET_HashCode)); 63 memset (&k2, 1, sizeof (GNUNET_HashCode));
63 memset(&trial_info, 0, sizeof(struct GNUNET_DHTLOG_TrialInfo)); 64 memset (&trial_info, 0, sizeof (struct GNUNET_DHTLOG_TrialInfo));
64 trial_info.other_identifier = 777; 65 trial_info.other_identifier = 777;
65 trial_info.num_nodes = i; 66 trial_info.num_nodes = i;
66 trial_info.topology = 5; 67 trial_info.topology = 5;
@@ -83,107 +84,110 @@ test (struct GNUNET_DHTLOG_Handle * api)
83 trial_info.stop_closest = 1; 84 trial_info.stop_closest = 1;
84 trial_info.stop_found = 0; 85 trial_info.stop_found = 0;
85 trial_info.strict_kademlia = 1; 86 trial_info.strict_kademlia = 1;
86 trial_info.message = GNUNET_strdup("TEST INSERT_TRIAL"); 87 trial_info.message = GNUNET_strdup ("TEST INSERT_TRIAL");
87 ret = 88 ret = api->insert_trial (&trial_info);
88 api->insert_trial (&trial_info); 89 GNUNET_free (trial_info.message);
89 GNUNET_free(trial_info.message); 90 CHECK (ret);
90 CHECK(ret);
91#if VERBOSE 91#if VERBOSE
92 fprintf(stderr, "Insert trial succeeded!\n"); 92 fprintf (stderr, "Insert trial succeeded!\n");
93#endif 93#endif
94 ret = api->insert_topology(500); 94 ret = api->insert_topology (500);
95 CHECK(ret); 95 CHECK (ret);
96#if VERBOSE 96#if VERBOSE
97 fprintf(stderr, "Insert topology succeeded!\n"); 97 fprintf (stderr, "Insert topology succeeded!\n");
98#endif 98#endif
99 ret = api->insert_node (&nodeuid, &p1); 99 ret = api->insert_node (&nodeuid, &p1);
100 CHECK(ret); 100 CHECK (ret);
101 ret = api->insert_node (&nodeuid, &p2); 101 ret = api->insert_node (&nodeuid, &p2);
102 CHECK(ret); 102 CHECK (ret);
103 ret = api->insert_node (&nodeuid, &p3); 103 ret = api->insert_node (&nodeuid, &p3);
104 CHECK(ret); 104 CHECK (ret);
105 ret = api->insert_node (&nodeuid, &p4); 105 ret = api->insert_node (&nodeuid, &p4);
106 CHECK(ret); 106 CHECK (ret);
107#if VERBOSE 107#if VERBOSE
108 fprintf(stderr, "Insert node succeeded!\n"); 108 fprintf (stderr, "Insert node succeeded!\n");
109#endif 109#endif
110 ret = api->set_malicious(&p1); 110 ret = api->set_malicious (&p1);
111 CHECK(ret); 111 CHECK (ret);
112#if VERBOSE 112#if VERBOSE
113 fprintf(stderr, "Set malicious succeeded!\n"); 113 fprintf (stderr, "Set malicious succeeded!\n");
114#endif 114#endif
115 ret = api->insert_topology(0); 115 ret = api->insert_topology (0);
116 CHECK(ret); 116 CHECK (ret);
117#if VERBOSE 117#if VERBOSE
118 fprintf(stderr, "Insert topology succeeded!\n"); 118 fprintf (stderr, "Insert topology succeeded!\n");
119#endif 119#endif
120 ret = api->insert_extended_topology(&p1, &p2); 120 ret = api->insert_extended_topology (&p1, &p2);
121 CHECK(ret); 121 CHECK (ret);
122 ret = api->insert_extended_topology(&p3, &p4); 122 ret = api->insert_extended_topology (&p3, &p4);
123 CHECK(ret); 123 CHECK (ret);
124#if VERBOSE 124#if VERBOSE
125 fprintf(stderr, "Insert extended topology succeeded!\n"); 125 fprintf (stderr, "Insert extended topology succeeded!\n");
126#endif 126#endif
127 ret = api->update_topology(101); 127 ret = api->update_topology (101);
128 CHECK(ret); 128 CHECK (ret);
129#if VERBOSE 129#if VERBOSE
130 fprintf(stderr, "Update topology succeeded!\n"); 130 fprintf (stderr, "Update topology succeeded!\n");
131#endif 131#endif
132 ret = api->insert_dhtkey (&dhtkeyuid, &k1); 132 ret = api->insert_dhtkey (&dhtkeyuid, &k1);
133 CHECK(ret); 133 CHECK (ret);
134 ret = api->insert_dhtkey (&dhtkeyuid, &k2); 134 ret = api->insert_dhtkey (&dhtkeyuid, &k2);
135 CHECK(ret); 135 CHECK (ret);
136#if VERBOSE 136#if VERBOSE
137 fprintf(stderr, "Insert dhtkey succeeded!\n"); 137 fprintf (stderr, "Insert dhtkey succeeded!\n");
138#endif 138#endif
139 ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1); 139 ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1);
140 CHECK(ret); 140 CHECK (ret);
141#if VERBOSE 141#if VERBOSE
142 fprintf(stderr, "Insert query succeeded!\n"); 142 fprintf (stderr, "Insert query succeeded!\n");
143#endif 143#endif
144 ret = 144 ret =
145 api->insert_route (&sqlrouteuid, sqlqueryuid, 1, 1, DHTLOG_GET, &p1, &k2, 145 api->insert_route (&sqlrouteuid, sqlqueryuid, 1, 1, DHTLOG_GET, &p1, &k2,
146 &p4, &p3); 146 &p4, &p3);
147 CHECK(ret); 147 CHECK (ret);
148 ret = 148 ret =
149 api->insert_route (&sqlrouteuid, sqlqueryuid, 2, 0, DHTLOG_PUT, &p3, &k1, 149 api->insert_route (&sqlrouteuid, sqlqueryuid, 2, 0, DHTLOG_PUT, &p3, &k1,
150 &p4, &p2); 150 &p4, &p2);
151 CHECK(ret); 151 CHECK (ret);
152 ret = 152 ret =
153 api->insert_route (&sqlrouteuid, sqlqueryuid, 3, 1, DHTLOG_ROUTE, &p3, &k2, 153 api->insert_route (&sqlrouteuid, sqlqueryuid, 3, 1, DHTLOG_ROUTE, &p3,
154 &p2, NULL); 154 &k2, &p2, NULL);
155 CHECK(ret); 155 CHECK (ret);
156 ret = 156 ret =
157 api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3, &k2, 157 api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3,
158 NULL, NULL); 158 &k2, NULL, NULL);
159 CHECK(ret); 159 CHECK (ret);
160#if VERBOSE 160#if VERBOSE
161 fprintf(stderr, "Insert route succeeded!\n"); 161 fprintf (stderr, "Insert route succeeded!\n");
162#endif 162#endif
163 sleep (1); 163 sleep (1);
164 ret = api->insert_stat(&p1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); 164 ret =
165 CHECK(ret); 165 api->insert_stat (&p1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
166 ret = api->insert_stat(&p2, 12, 23, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); 166 17);
167 CHECK(ret); 167 CHECK (ret);
168 ret =
169 api->insert_stat (&p2, 12, 23, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
170 25, 26, 27);
171 CHECK (ret);
168#if VERBOSE 172#if VERBOSE
169 fprintf(stderr, "Insert stat succeeded!\n"); 173 fprintf (stderr, "Insert stat succeeded!\n");
170#endif 174#endif
171 ret = api->update_trial (787); 175 ret = api->update_trial (787);
172 CHECK(ret); 176 CHECK (ret);
173#if VERBOSE 177#if VERBOSE
174 fprintf(stderr, "Update trial succeeded!\n"); 178 fprintf (stderr, "Update trial succeeded!\n");
175#endif 179#endif
176 ret = api->add_generic_stat (&p2, "nonsense", "section", 77765); 180 ret = api->add_generic_stat (&p2, "nonsense", "section", 77765);
177 CHECK(ret); 181 CHECK (ret);
178#if VERBOSE 182#if VERBOSE
179 fprintf(stderr, "Insert generic stat succeeded!\n"); 183 fprintf (stderr, "Insert generic stat succeeded!\n");
180#endif 184#endif
181 ret = api->insert_round(401, 507); 185 ret = api->insert_round (401, 507);
182 CHECK(ret); 186 CHECK (ret);
183 ret = api->insert_round_details(402, 507, 1123, 985); 187 ret = api->insert_round_details (402, 507, 1123, 985);
184 CHECK(ret); 188 CHECK (ret);
185#if VERBOSE 189#if VERBOSE
186 fprintf(stderr, "Insert round succeeded!\n"); 190 fprintf (stderr, "Insert round succeeded!\n");
187#endif 191#endif
188 return 0; 192 return 0;
189} 193}
@@ -193,21 +197,21 @@ test (struct GNUNET_DHTLOG_Handle * api)
193static void 197static void
194run (void *cls, 198run (void *cls,
195 char *const *args, 199 char *const *args,
196 const char *cfgfile, 200 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
197 const struct GNUNET_CONFIGURATION_Handle *cfg)
198{ 201{
199 struct GNUNET_DHTLOG_Handle *api; 202 struct GNUNET_DHTLOG_Handle *api;
203
200 ok = 0; 204 ok = 0;
201 api = GNUNET_DHTLOG_connect (cfg); 205 api = GNUNET_DHTLOG_connect (cfg);
202 206
203 if (api == NULL) 207 if (api == NULL)
204 { 208 {
205 ok = 1; 209 ok = 1;
206 return; 210 return;
207 } 211 }
208 ok = test(api); 212 ok = test (api);
209 213
210 GNUNET_DHTLOG_disconnect(api); 214 GNUNET_DHTLOG_disconnect (api);
211} 215}
212 216
213 217
@@ -226,8 +230,7 @@ check ()
226 GNUNET_GETOPT_OPTION_END 230 GNUNET_GETOPT_OPTION_END
227 }; 231 };
228 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 232 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
229 argv, "test-dhtlog-api", "nohelp", 233 argv, "test-dhtlog-api", "nohelp", options, &run, NULL);
230 options, &run, NULL);
231 if (ok != 0) 234 if (ok != 0)
232 fprintf (stderr, "Test failed with error code: %d\n", ok); 235 fprintf (stderr, "Test failed with error code: %d\n", ok);
233 return ok; 236 return ok;