Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into fix/execute_benched
[simgrid.git] / examples / s4u / dht-chord / node.cpp
index d97b6b1..4a73c0f 100644 (file)
@@ -3,7 +3,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "s4u_dht-chord.hpp"
+#include "s4u-dht-chord.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(s4u_chord);
 
@@ -40,6 +40,11 @@ static int is_in_interval(int id, int start, int end)
   return i <= e;
 }
 
+void ChordMessage::destroy(void* message)
+{
+  delete static_cast<ChordMessage*>(message);
+}
+
 /* Initializes the current node as the first one of the system */
 Node::Node(std::vector<std::string> args)
 {
@@ -230,7 +235,7 @@ void Node::checkPredecessor()
   }
   // receive the answer
   XBT_DEBUG("Sent 'Predecessor Alive' request to %d, waiting for the answer on my mailbox '%s'", pred_id_,
-            message->answer_to->getName());
+            message->answer_to->getCname());
   simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data);
 
   try {
@@ -275,7 +280,7 @@ int Node::remoteGetPredecessor(int ask_to)
 
   // receive the answer
   XBT_DEBUG("Sent 'Get Predecessor' request to %d, waiting for the answer on my mailbox '%s'", ask_to,
-            message->answer_to->getName());
+            message->answer_to->getCname());
   simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data);
 
   try {
@@ -389,7 +394,7 @@ void Node::remoteNotify(int notify_id, int predecessor_candidate_id)
   // send a "Notify" request to notify_id
   XBT_DEBUG("Sending a 'Notify' request to %d", notify_id);
   simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::to_string(notify_id));
-  mailbox->put_init(message, 10)->detach();
+  mailbox->put_init(message, 10)->detach(ChordMessage::destroy);
 }
 
 /* This function is called periodically. It checks the immediate successor of the current node. */
@@ -427,16 +432,16 @@ void Node::handleMessage(ChordMessage* message)
       message->type = FIND_SUCCESSOR_ANSWER;
       message->answer_id = fingers_[0];
       XBT_DEBUG("Sending back a 'Find Successor Answer' to %s (mailbox %s): the successor of %d is %d",
-                message->issuer_host_name.c_str(), message->answer_to->getName(), message->request_id,
+                message->issuer_host_name.c_str(), message->answer_to->getCname(), message->request_id,
                 message->answer_id);
-      message->answer_to->put_init(message, 10)->detach();
+      message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     } else {
       // otherwise, forward the request to the closest preceding finger in my table
       int closest = closestPrecedingFinger(message->request_id);
       XBT_DEBUG("Forwarding the 'Find Successor' request for id %d to my closest preceding finger %d",
           message->request_id, closest);
       simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::to_string(closest));
-      mailbox->put_init(message, 10)->detach();
+      mailbox->put_init(message, 10)->detach(ChordMessage::destroy);
     }
     break;
 
@@ -445,8 +450,8 @@ void Node::handleMessage(ChordMessage* message)
     message->type = GET_PREDECESSOR_ANSWER;
     message->answer_id = pred_id_;
     XBT_DEBUG("Sending back a 'Get Predecessor Answer' to %s via mailbox '%s': my predecessor is %d",
-              message->issuer_host_name.c_str(), message->answer_to->getName(), message->answer_id);
-    message->answer_to->put_init(message, 10)->detach();
+              message->issuer_host_name.c_str(), message->answer_to->getCname(), message->answer_id);
+    message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     break;
 
   case NOTIFY:
@@ -483,8 +488,8 @@ void Node::handleMessage(ChordMessage* message)
     XBT_DEBUG("Receiving a 'Predecessor Alive' request from %s", message->issuer_host_name.c_str());
     message->type = PREDECESSOR_ALIVE_ANSWER;
     XBT_DEBUG("Sending back a 'Predecessor Alive Answer' to %s (mailbox %s)", message->issuer_host_name.c_str(),
-              message->answer_to->getName());
-    message->answer_to->put_init(message, 10)->detach();
+              message->answer_to->getCname());
+    message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     break;
 
   default: