aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-01-07 14:00:13 +0000
committerJulius Bünger <buenger@mytum.de>2015-01-07 14:00:13 +0000
commit6a08ce6a247df3247a9e89500a6381c9ca205bac (patch)
tree50793c79141c38d0787e517fe86e5ca71f008252 /src/rps
parentc1fc2480f5e95ff937a1bf0f67410701465ed698 (diff)
downloadgnunet-6a08ce6a247df3247a9e89500a6381c9ca205bac.tar.gz
gnunet-6a08ce6a247df3247a9e89500a6381c9ca205bac.zip
moved part of _resize() from _sampler.c to -rps.c
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c42
-rw-r--r--src/rps/gnunet-service-rps_sampler.c29
2 files changed, 39 insertions, 32 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 2d103ff1a..e1af57391 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -411,20 +411,39 @@ get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_Peer
411nse_callback(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev) 411nse_callback(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
412{ 412{
413 double estimate; 413 double estimate;
414 unsigned int old_est;
414 //double scale; // TODO this might go gloabal/config 415 //double scale; // TODO this might go gloabal/config
415 416
416 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received a ns estimate - logest: %f, std_dev: %f\n", logestimate, std_dev); 417 old_est = est_size;
418
419 LOG (GNUNET_ERROR_TYPE_DEBUG,
420 "Received a ns estimate - logest: %f, std_dev: %f (old_est: %f)\n",
421 logestimate, std_dev, old_est);
417 //scale = .01; 422 //scale = .01;
418 estimate = GNUNET_NSE_log_estimate_to_n(logestimate); 423 estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
419 // GNUNET_NSE_log_estimate_to_n (logestimate); 424 // GNUNET_NSE_log_estimate_to_n (logestimate);
420 estimate = pow(estimate, 1./3); 425 estimate = pow (estimate, 1./3);
421 // TODO add if std_dev is a number 426 // TODO add if std_dev is a number
422 // estimate += (std_dev * scale); 427 // estimate += (std_dev * scale);
423 if ( 0 < estimate ) { 428 if ( 0 < estimate ) {
424 LOG(GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); 429 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate);
425 est_size = estimate; 430 est_size = estimate;
426 } else 431 } else
427 LOG(GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); 432 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate);
433
434 /* If the NSE has changed adapt the lists accordingly */
435 // TODO respect the request rate, min, max
436 if (old_est > est_size*4)
437 { /* Shrinking */
438 RPS_sampler_resize (old_est/2);
439 }
440 else if (old_est < est_size)
441 { /* Growing */
442 if (est_size < old_est*2)
443 RPS_sampler_resize (old_est*2);
444 else
445 RPS_sampler_resize (est_size);
446 }
428} 447}
429 448
430/** 449/**
@@ -641,12 +660,13 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
641 //n_arr = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, (unsigned int) gossip_list_size); 660 //n_arr = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, (unsigned int) gossip_list_size);
642 LOG(GNUNET_ERROR_TYPE_DEBUG, "Going to send pushes to %f (%f * %u) peers.\n", 661 LOG(GNUNET_ERROR_TYPE_DEBUG, "Going to send pushes to %f (%f * %u) peers.\n",
643 alpha * gossip_list_size, alpha, gossip_list_size); 662 alpha * gossip_list_size, alpha, gossip_list_size);
663 // TODO send to at least one
644 for ( i = 0 ; i < alpha * gossip_list_size ; i++ ) 664 for ( i = 0 ; i < alpha * gossip_list_size ; i++ )
645 { // TODO compute length 665 { // TODO compute length
646 peer = get_rand_peer(gossip_list, gossip_list_size); 666 peer = get_rand_peer (gossip_list, gossip_list_size);
647 if (own_identity != peer) 667 if (own_identity != peer)
648 { // FIXME if this fails schedule/loop this for later 668 { // FIXME if this fails schedule/loop this for later
649 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending PUSH to peer %s of gossiped list.\n", GNUNET_i2s(peer)); 669 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PUSH to peer %s of gossiped list.\n", GNUNET_i2s (peer));
650 670
651 ev = GNUNET_MQ_msg (push_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); 671 ev = GNUNET_MQ_msg (push_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
652 //ev = GNUNET_MQ_msg_extra(); 672 //ev = GNUNET_MQ_msg_extra();
@@ -664,14 +684,15 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
664 684
665 /* Send PULL requests */ 685 /* Send PULL requests */
666 //n_arr = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, (unsigned int) sampler_list->size); 686 //n_arr = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, (unsigned int) sampler_list->size);
667 LOG(GNUNET_ERROR_TYPE_DEBUG, "Going to send pulls to %f (%f * %u) peers.\n", 687 LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to send pulls to %f (%f * %u) peers.\n",
668 beta * gossip_list_size, beta, gossip_list_size); 688 beta * gossip_list_size, beta, gossip_list_size);
689 // TODO send to at least one
669 for ( i = 0 ; i < beta * gossip_list_size ; i++ ) 690 for ( i = 0 ; i < beta * gossip_list_size ; i++ )
670 { // TODO compute length 691 { // TODO compute length
671 peer = get_rand_peer(gossip_list, gossip_list_size); 692 peer = get_rand_peer(gossip_list, gossip_list_size);
672 if (own_identity != peer) 693 if (own_identity != peer)
673 { // FIXME if this fails schedule/loop this for later 694 { // FIXME if this fails schedule/loop this for later
674 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of gossiped list.\n", GNUNET_i2s(peer)); 695 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of gossiped list.\n", GNUNET_i2s (peer));
675 696
676 ev = GNUNET_MQ_msg(pull_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); 697 ev = GNUNET_MQ_msg(pull_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
677 //ev = GNUNET_MQ_msg_extra(); 698 //ev = GNUNET_MQ_msg_extra();
@@ -684,9 +705,6 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
684 } 705 }
685 706
686 707
687 /* If the NSE has changed adapt the lists accordingly */
688 RPS_sampler_resize(est_size);
689
690 GNUNET_array_grow(gossip_list, gossip_list_size, est_size); 708 GNUNET_array_grow(gossip_list, gossip_list_size, est_size);
691 709
692 710
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index f80a70108..66a9ec4e9 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -156,7 +156,7 @@ static size_t extra_size;
156/** 156/**
157 * Inedex to the sampler element that is the next to be returned 157 * Inedex to the sampler element that is the next to be returned
158 */ 158 */
159static struct RPS_SamplerElement **extended_samplers_index; 159static uint64_t extended_samplers_index;
160 160
161/** 161/**
162 * Request counter. 162 * Request counter.
@@ -349,17 +349,13 @@ RPS_sampler_resize (unsigned int new_size)
349 349
350 old_size = sampler->sampler_size; 350 old_size = sampler->sampler_size;
351 351
352 if (old_size > new_size*4 && 352 if (old_size > new_size)
353 extra_size > new_size*4)
354 { /* Shrinking */ 353 { /* Shrinking */
355
356 new_size /= 2;
357
358 /* Temporary store those to properly call the removeCB on those later */ 354 /* Temporary store those to properly call the removeCB on those later */
359 rem_list = GNUNET_malloc ((old_size - new_size) * sizeof (struct RPS_SamplerElement *)); 355 rem_list = GNUNET_malloc ((old_size - new_size) * sizeof (struct RPS_SamplerElement *));
360 memcpy (rem_list, 356 memcpy (rem_list,
361 &sampler->sampler_elements[new_size], 357 &sampler->sampler_elements[new_size],
362 (old_size - new_size) * sizeof(struct RPS_SamplerElement *)); 358 (old_size - new_size) * sizeof (struct RPS_SamplerElement *));
363 359
364 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Shrinking sampler %d -> %d\n", old_size, new_size); 360 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Shrinking sampler %d -> %d\n", old_size, new_size);
365 GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size); 361 GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size);
@@ -367,7 +363,6 @@ RPS_sampler_resize (unsigned int new_size)
367 "SAMPLER: sampler->sampler_elements now points to %p\n", 363 "SAMPLER: sampler->sampler_elements now points to %p\n",
368 sampler->sampler_elements); 364 sampler->sampler_elements);
369 365
370 // TODO move extended_samplers_index
371 for (i = new_size ; i < old_size ; i++) 366 for (i = new_size ; i < old_size ; i++)
372 {/* Remove unneeded rest */ 367 {/* Remove unneeded rest */
373 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX64 ". sampler\n", i); 368 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX64 ". sampler\n", i);
@@ -376,19 +371,14 @@ RPS_sampler_resize (unsigned int new_size)
376 GNUNET_free (rem_list[i]); 371 GNUNET_free (rem_list[i]);
377 } 372 }
378 } 373 }
379 else if (old_size < new_size)// || 374 else if (old_size < new_size)
380 //extra_size < new_size) // needed?
381 { /* Growing */ 375 { /* Growing */
382 new_size *= 2; // TODO check overflow
383
384 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Growing sampler %d -> %d\n", old_size, new_size); 376 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Growing sampler %d -> %d\n", old_size, new_size);
385 GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size); 377 GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size);
386 LOG (GNUNET_ERROR_TYPE_DEBUG, 378 LOG (GNUNET_ERROR_TYPE_DEBUG,
387 "SAMPLER: sampler->sampler_elements now points to %p\n", 379 "SAMPLER: sampler->sampler_elements now points to %p\n",
388 sampler->sampler_elements); 380 sampler->sampler_elements);
389 381
390 // TODO move extended_samplers_index
391
392 for ( i = old_size ; i < new_size ; i++ ) 382 for ( i = old_size ; i < new_size ; i++ )
393 { /* Add new sampler elements */ 383 { /* Add new sampler elements */
394 sampler->sampler_elements[i] = RPS_sampler_elem_create (); 384 sampler->sampler_elements[i] = RPS_sampler_elem_create ();
@@ -447,7 +437,7 @@ RPS_sampler_init (size_t init_size, const struct GNUNET_PeerIdentity *id,
447 RPS_sampler_resize (init_size); 437 RPS_sampler_resize (init_size);
448 RPS_sampler_update_list (id); // no super nice desing but ok for the moment 438 RPS_sampler_update_list (id); // no super nice desing but ok for the moment
449 439
450 extended_samplers_index = sampler->sampler_elements; 440 extended_samplers_index = 0;
451 441
452 //GNUNET_assert (init_size == sampler->sampler_size); 442 //GNUNET_assert (init_size == sampler->sampler_size);
453} 443}
@@ -591,13 +581,12 @@ RPS_sampler_get_rand_peer ()
591 581
592 // use _get_rand_peer_ ? 582 // use _get_rand_peer_ ?
593 peer = GNUNET_new (struct GNUNET_PeerIdentity); 583 peer = GNUNET_new (struct GNUNET_PeerIdentity);
594 *peer = (*extended_samplers_index)->peer_id; 584 *peer = sampler->sampler_elements[extended_samplers_index]->peer_id;
595 RPS_sampler_elem_reinit (*extended_samplers_index); 585 RPS_sampler_elem_reinit (sampler->sampler_elements[extended_samplers_index]);
596 if ( extended_samplers_index == &sampler->sampler_elements[sampler->sampler_size -1] ) 586 if ( extended_samplers_index == sampler->sampler_size )
597 extended_samplers_index = &sampler->sampler_elements[0]; 587 extended_samplers_index = 0;
598 else 588 else
599 extended_samplers_index++; 589 extended_samplers_index++;
600 // TODO
601 return peer; 590 return peer;
602} 591}
603 592