Guest User

Untitled

a guest
Feb 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. // need #include <ctime>
  2.  
  3. NetworkProximityDaemon * pickCommunicationPeer(NetworkProximityDaemon * sender) {
  4. std::string network_service_type = this->getPropertyValueAsString(
  5. "NETWORK_PROXIMITY_SERVICE_TYPE");
  6.  
  7. // will hash this since it is unique to daemon
  8. std:: string sender_mailbox = sender->mailbox_name;
  9.  
  10. NetworkProximityDaemon * chosen_peer;
  11. if (boost::iequals(network_service_type, "alltoall")) {
  12. // TODO add alltoall stuff
  13. }
  14. else {
  15. double coverage = this->getPropertyValueAsDouble("NETWORK_DAEMON_COMMUNICATION_COVERAGE");
  16. int max_pool_size = this->network_daemons.size();
  17. int pool_size = std::ceil(coverage * max_pool_size);
  18.  
  19. std::hash<std::string> hash_func;
  20. std::default_random_engine sender_rng, master_rng;
  21. std::uniform_int_distribution<unsigned> s_udist, m_udist(0, pool_size - 1);
  22.  
  23. master_rng.seed(time(0));
  24. sender_rng.seed(hash_func(sender_mailbox));
  25.  
  26. int pool_current_index = 0;
  27. int pool_target_peer_index = m_udist(master_rng);
  28.  
  29. for (int i = 0; i < max_pool_size; ++i) {
  30. if (s_udist(sender_rng) % (max_pool_size - i) < communication_pool_size) {
  31. if (pool_target_peer_index = pool_current_index) {
  32. chosen_peer = this->network_daemons.at(i);
  33. break;
  34. }
  35. ++pool_current_index;
  36. --communication_pool_size;
  37. }
  38. }
  39. }
  40.  
  41. return chosen_peer;
  42. }
Add Comment
Please, Sign In to add comment