X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/96cedde3cdbc0b8ffc3f096a1b65d021b0226f99..691d7c891da0352a6fa38507a482b287c7e086de:/examples/s4u/dht-kademlia/node.cpp diff --git a/examples/s4u/dht-kademlia/node.cpp b/examples/s4u/dht-kademlia/node.cpp index a760100d79..2f7a7567d3 100644 --- a/examples/s4u/dht-kademlia/node.cpp +++ b/examples/s4u/dht-kademlia/node.cpp @@ -33,7 +33,7 @@ bool Node::join(unsigned int known_id) /* First step: Send a "FIND_NODE" request to the node we know */ sendFindNode(known_id, id_); - simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_)); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_)); do { if (receive_comm == nullptr) receive_comm = mailbox->get_async(&received_msg); @@ -57,14 +57,14 @@ bool Node::join(unsigned int known_id) } while (not got_answer); /* Second step: Send a FIND_NODE to a a random node in buckets */ - unsigned int bucket_id = table->findBucket(known_id)->getId(); - xbt_assert(bucket_id <= identifier_size); - for (i = 0; ((bucket_id > i) || (bucket_id + i) <= identifier_size) && i < JOIN_BUCKETS_QUERIES; i++) { + unsigned int bucket_id = table.findBucket(known_id)->getId(); + xbt_assert(bucket_id <= IDENTIFIER_SIZE); + for (i = 0; ((bucket_id > i) || (bucket_id + i) <= IDENTIFIER_SIZE) && i < JOIN_BUCKETS_QUERIES; i++) { if (bucket_id > i) { unsigned int id_in_bucket = get_id_in_prefix(id_, bucket_id - i); findNode(id_in_bucket, false); } - if (bucket_id + i <= identifier_size) { + if (bucket_id + i <= IDENTIFIER_SIZE) { unsigned int id_in_bucket = get_id_in_prefix(id_, bucket_id + i); findNode(id_in_bucket, false); } @@ -79,7 +79,7 @@ bool Node::join(unsigned int known_id) void Node::sendFindNode(unsigned int id, unsigned int destination) { /* Gets the mailbox to send to */ - simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id)); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id)); /* Build the task */ Message* msg = new Message(id_, destination, simgrid::s4u::Mailbox::by_name(std::to_string(id_)), simgrid::s4u::Host::current()->get_cname()); @@ -90,7 +90,7 @@ void Node::sendFindNode(unsigned int id, unsigned int destination) } /** - * Sends to the best "kademlia_alpha" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best + * Sends to the best "KADEMLIA_ALPHA" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best * nodes */ unsigned int Node::sendFindNodeToBest(Answer* node_list) @@ -99,14 +99,14 @@ unsigned int Node::sendFindNodeToBest(Answer* node_list) unsigned int j = 0; unsigned int destination = node_list->getDestinationId(); for (auto node_to_query : node_list->nodes) { - /* We need to have at most "kademlia_alpha" requests each time, according to the protocol */ + /* We need to have at most "KADEMLIA_ALPHA" requests each time, according to the protocol */ /* Gets the node we want to send the query to */ if (node_to_query.first != id_) { /* No need to query ourselves */ sendFindNode(node_to_query.first, destination); j++; } i++; - if (j == kademlia_alpha) + if (j == KADEMLIA_ALPHA) break; } return i; @@ -118,7 +118,7 @@ unsigned int Node::sendFindNodeToBest(Answer* node_list) void Node::routingTableUpdate(unsigned int id) { // retrieval of the bucket in which the should be - Bucket* bucket = table->findBucket(id); + Bucket* bucket = table.findBucket(id); // check if the id is already in the bucket. auto id_pos = std::find(bucket->nodes.begin(), bucket->nodes.end(), id); @@ -146,28 +146,28 @@ Answer* Node::findClosest(unsigned int destination_id) { Answer* answer = new Answer(destination_id); /* We find the corresponding bucket for the id */ - Bucket* bucket = table->findBucket(destination_id); + const Bucket* bucket = table.findBucket(destination_id); int bucket_id = bucket->getId(); - xbt_assert((bucket_id <= identifier_size), "Bucket found has a wrong identifier"); + xbt_assert((bucket_id <= IDENTIFIER_SIZE), "Bucket found has a wrong identifier"); /* So, we copy the contents of the bucket unsigned into our answer */ answer->addBucket(bucket); - /* However, if we don't have enough elements in our bucket, we NEED to include at least "bucket_size" elements - * (if, of course, we know at least "bucket_size" elements. So we're going to look unsigned into the other buckets. + /* However, if we don't have enough elements in our bucket, we NEED to include at least "BUCKET_SIZE" elements + * (if, of course, we know at least "BUCKET_SIZE" elements. So we're going to look unsigned into the other buckets. */ - for (int i = 1; answer->getSize() < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < identifier_size)); i++) { + for (int i = 1; answer->getSize() < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < IDENTIFIER_SIZE)); i++) { /* We check the previous buckets */ if (bucket_id - i >= 0) { - Bucket* bucket_p = table->buckets[bucket_id - i]; + const Bucket* bucket_p = &table.buckets[bucket_id - i]; answer->addBucket(bucket_p); } /* We check the next buckets */ - if (bucket_id + i <= identifier_size) { - Bucket* bucket_n = table->buckets[bucket_id + i]; + if (bucket_id + i <= IDENTIFIER_SIZE) { + const Bucket* bucket_n = &table.buckets[bucket_id + i]; answer->addBucket(bucket_n); } } - /* We trim the array to have only bucket_size or less elements */ + /* We trim the array to have only BUCKET_SIZE or less elements */ std::sort(answer->nodes.begin(), answer->nodes.end(), sortbydistance); answer->trim(); @@ -183,7 +183,7 @@ bool Node::findNode(unsigned int id_to_find, bool count_in_stats) unsigned int answers; bool destination_found = false; unsigned int nodes_added = 0; - double global_timeout = simgrid::s4u::Engine::get_clock() + find_node_global_timeout; + double global_timeout = simgrid::s4u::Engine::get_clock() + FIND_NODE_GLOBAL_TIMEOUT; unsigned int steps = 0; /* First we build a list of who we already know */ @@ -196,11 +196,11 @@ bool Node::findNode(unsigned int id_to_find, bool count_in_stats) answers = 0; queries = sendFindNodeToBest(node_list); nodes_added = 0; - double timeout = simgrid::s4u::Engine::get_clock() + find_node_timeout; + double timeout = simgrid::s4u::Engine::get_clock() + FIND_NODE_TIMEOUT; steps++; double time_beginreceive = simgrid::s4u::Engine::get_clock(); - simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_)); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_)); do { if (receive_comm == nullptr) receive_comm = mailbox->get_async(&received_msg); @@ -217,7 +217,7 @@ bool Node::findNode(unsigned int id_to_find, bool count_in_stats) nodes_added = node_list->merge(msg->answer_); XBT_DEBUG("Received an answer from %s (%s) with %zu nodes on it", msg->answer_to_->get_cname(), - msg->issuer_host_name_, msg->answer_->nodes.size()); + msg->issuer_host_name_.c_str(), msg->answer_->nodes.size()); } else { if (msg->answer_) { routingTableUpdate(msg->sender_id_); @@ -272,7 +272,7 @@ void Node::handleFindNode(Message* msg) { routingTableUpdate(msg->sender_id_); XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x", msg->answer_to_->get_cname(), - msg->issuer_host_name_, msg->destination_id_); + msg->issuer_host_name_.c_str(), msg->destination_id_); // Building the answer to the request Message* answer = new Message(id_, msg->destination_id_, findClosest(msg->destination_id_),