Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // need #include <ctime>
- NetworkProximityDaemon * pickCommunicationPeer(NetworkProximityDaemon * sender) {
- std::string network_service_type = this->getPropertyValueAsString(
- "NETWORK_PROXIMITY_SERVICE_TYPE");
- // will hash this since it is unique to daemon
- std:: string sender_mailbox = sender->mailbox_name;
- NetworkProximityDaemon * chosen_peer;
- if (boost::iequals(network_service_type, "alltoall")) {
- // TODO add alltoall stuff
- }
- else {
- double coverage = this->getPropertyValueAsDouble("NETWORK_DAEMON_COMMUNICATION_COVERAGE");
- int max_pool_size = this->network_daemons.size();
- int pool_size = std::ceil(coverage * max_pool_size);
- std::hash<std::string> hash_func;
- std::default_random_engine sender_rng, master_rng;
- std::uniform_int_distribution<unsigned> s_udist, m_udist(0, pool_size - 1);
- master_rng.seed(time(0));
- sender_rng.seed(hash_func(sender_mailbox));
- int pool_current_index = 0;
- int pool_target_peer_index = m_udist(master_rng);
- for (int i = 0; i < max_pool_size; ++i) {
- if (s_udist(sender_rng) % (max_pool_size - i) < communication_pool_size) {
- if (pool_target_peer_index = pool_current_index) {
- chosen_peer = this->network_daemons.at(i);
- break;
- }
- ++pool_current_index;
- --communication_pool_size;
- }
- }
- }
- return chosen_peer;
- }
Add Comment
Please, Sign In to add comment