diff options
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 98 |
1 files changed, 85 insertions, 13 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index 2b4ea6007..f851ac965 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -102,6 +102,13 @@ struct RPS_SamplerElement | |||
102 | * How many times this sampler changed the peer_id. | 102 | * How many times this sampler changed the peer_id. |
103 | */ | 103 | */ |
104 | uint32_t num_change; | 104 | uint32_t num_change; |
105 | |||
106 | /** | ||
107 | * The file name this sampler element should log to | ||
108 | */ | ||
109 | #ifdef TO_FILE | ||
110 | char *file_name; | ||
111 | #endif /* TO_FILE */ | ||
105 | }; | 112 | }; |
106 | 113 | ||
107 | 114 | ||
@@ -362,6 +369,42 @@ RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_el) | |||
362 | &(sampler_el->auth_key.key), | 369 | &(sampler_el->auth_key.key), |
363 | GNUNET_CRYPTO_HASH_LENGTH); | 370 | GNUNET_CRYPTO_HASH_LENGTH); |
364 | 371 | ||
372 | #ifdef TO_FILE | ||
373 | /* Create a file(-name) to store internals to */ | ||
374 | int size; | ||
375 | char *end; | ||
376 | char *buf; | ||
377 | char name_buf[512]; | ||
378 | size_t keylen = (sizeof (struct GNUNET_CRYPTO_AuthKey)) * 8; | ||
379 | |||
380 | if (keylen % 5 > 0) | ||
381 | keylen += 5 - keylen % 5; | ||
382 | keylen /= 5; | ||
383 | buf = GNUNET_malloc (keylen + 1); | ||
384 | |||
385 | end = GNUNET_STRINGS_data_to_string (&(sampler_el->auth_key.key), | ||
386 | sizeof (struct GNUNET_CRYPTO_AuthKey), | ||
387 | buf, | ||
388 | keylen); | ||
389 | |||
390 | if (NULL == end) | ||
391 | { | ||
392 | GNUNET_free (buf); | ||
393 | GNUNET_break (0); | ||
394 | } | ||
395 | else | ||
396 | { | ||
397 | *end = '\0'; | ||
398 | } | ||
399 | |||
400 | size = GNUNET_snprintf (name_buf, sizeof (name_buf), "sampler_el-%s-", buf); | ||
401 | if (0 > size) | ||
402 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); | ||
403 | |||
404 | if (NULL == (sampler_el->file_name = GNUNET_DISK_mktemp (name_buf))) | ||
405 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); | ||
406 | #endif /* TO_FILE */ | ||
407 | |||
365 | sampler_el->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS; | 408 | sampler_el->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS; |
366 | 409 | ||
367 | sampler_el->birth = GNUNET_TIME_absolute_get (); | 410 | sampler_el->birth = GNUNET_TIME_absolute_get (); |
@@ -406,6 +449,12 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, | |||
406 | 449 | ||
407 | s_elem->num_peers++; | 450 | s_elem->num_peers++; |
408 | 451 | ||
452 | #ifdef TO_FILE | ||
453 | to_file (s_elem->file_name, | ||
454 | "Got id %s", | ||
455 | GNUNET_i2s_full (other)); | ||
456 | #endif /* TO_FILE */ | ||
457 | |||
409 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id))) | 458 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id))) |
410 | { | 459 | { |
411 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Got PeerID %s\n", | 460 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Got PeerID %s\n", |
@@ -450,6 +499,11 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, | |||
450 | } | 499 | } |
451 | } | 500 | } |
452 | s_elem->is_empty = NOT_EMPTY; | 501 | s_elem->is_empty = NOT_EMPTY; |
502 | #ifdef TO_FILE | ||
503 | to_file (s_elem->file_name, | ||
504 | "Now holding %s", | ||
505 | GNUNET_i2s_full (&s_elem->peer_id)); | ||
506 | #endif /* TO_FILE */ | ||
453 | } | 507 | } |
454 | 508 | ||
455 | 509 | ||
@@ -492,9 +546,17 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
492 | new_size); | 546 | new_size); |
493 | #ifdef TO_FILE | 547 | #ifdef TO_FILE |
494 | to_file (sampler->file_name, | 548 | to_file (sampler->file_name, |
495 | "Shrinking sampler %d -> %d\n", | 549 | "Shrinking sampler %d -> %d", |
496 | old_size, | 550 | old_size, |
497 | new_size); | 551 | new_size); |
552 | |||
553 | for (i = new_size ; i < old_size ; i++) | ||
554 | { | ||
555 | to_file (sampler->file_name, | ||
556 | "-%" PRIu32 ": %s", | ||
557 | i, | ||
558 | sampler->sampler_elements[i]->file_name); | ||
559 | } | ||
498 | #endif /* TO_FILE */ | 560 | #endif /* TO_FILE */ |
499 | GNUNET_array_grow (sampler->sampler_elements, | 561 | GNUNET_array_grow (sampler->sampler_elements, |
500 | sampler->sampler_size, | 562 | sampler->sampler_size, |
@@ -512,7 +574,7 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
512 | new_size); | 574 | new_size); |
513 | #ifdef TO_FILE | 575 | #ifdef TO_FILE |
514 | to_file (sampler->file_name, | 576 | to_file (sampler->file_name, |
515 | "Growing sampler %d -> %d\n", | 577 | "Growing sampler %d -> %d", |
516 | old_size, | 578 | old_size, |
517 | new_size); | 579 | new_size); |
518 | #endif /* TO_FILE */ | 580 | #endif /* TO_FILE */ |
@@ -525,10 +587,9 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
525 | sampler->sampler_elements[i] = RPS_sampler_elem_create (); | 587 | sampler->sampler_elements[i] = RPS_sampler_elem_create (); |
526 | #ifdef TO_FILE | 588 | #ifdef TO_FILE |
527 | to_file (sampler->file_name, | 589 | to_file (sampler->file_name, |
528 | "%" PRIu32 ": Initialised empty sampler element\n", | 590 | "+%" PRIu32 ": %s", |
529 | i); | 591 | i, |
530 | //"New sampler with key %s\n", | 592 | sampler->sampler_elements[i]->file_name); |
531 | //GNUNET_h2s_full (sampler->sampler_elements[i]->auth_key)); | ||
532 | #endif /* TO_FILE */ | 593 | #endif /* TO_FILE */ |
533 | } | 594 | } |
534 | } | 595 | } |
@@ -626,17 +687,17 @@ RPS_sampler_update (struct RPS_Sampler *sampler, | |||
626 | { | 687 | { |
627 | uint32_t i; | 688 | uint32_t i; |
628 | 689 | ||
690 | #ifdef TO_FILE | ||
691 | to_file (sampler->file_name, | ||
692 | "Got %s", | ||
693 | GNUNET_i2s_full (id)); | ||
694 | #endif /* TO_FILE */ | ||
695 | |||
629 | for (i = 0 ; i < sampler->sampler_size ; i++) | 696 | for (i = 0 ; i < sampler->sampler_size ; i++) |
630 | { | 697 | { |
631 | RPS_sampler_elem_next (sampler->sampler_elements[i], | 698 | RPS_sampler_elem_next (sampler->sampler_elements[i], |
632 | sampler, | 699 | sampler, |
633 | id); | 700 | id); |
634 | #ifdef TO_FILE | ||
635 | to_file (sampler->file_name, | ||
636 | "%" PRIu32 ": Now contains %s\n", | ||
637 | i, | ||
638 | GNUNET_i2s_full (&sampler->sampler_elements[i]->peer_id)); | ||
639 | #endif /* TO_FILE */ | ||
640 | } | 701 | } |
641 | } | 702 | } |
642 | 703 | ||
@@ -849,7 +910,18 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | |||
849 | if (GNUNET_NO == for_client) | 910 | if (GNUNET_NO == for_client) |
850 | { | 911 | { |
851 | to_file (sampler->file_name, | 912 | to_file (sampler->file_name, |
852 | "This sampler is probably for Brahms itself\n"); | 913 | "This sampler is probably for Brahms itself"); |
914 | } | ||
915 | else if (GNUNET_YES == for_client) | ||
916 | { | ||
917 | to_file (sampler->file_name, | ||
918 | "This sampler is probably for the client"); | ||
919 | } | ||
920 | else | ||
921 | { | ||
922 | to_file (sampler->file_name, | ||
923 | "This shouldn't happen: for_client is %i", | ||
924 | for_client); | ||
853 | } | 925 | } |
854 | #endif /* TO_FILE */ | 926 | #endif /* TO_FILE */ |
855 | 927 | ||