Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update .mailmap.
[simgrid.git] / examples / cpp / dht-kademlia / message.hpp
1 /* Copyright (c) 2012-2023. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _KADEMLIA_TASK_HPP_
8 #define _KADEMLIA_TASK_HPP_
9 #include "answer.hpp"
10 #include "s4u-dht-kademlia.hpp"
11 #include "simgrid/s4u.hpp"
12
13 #include <memory>
14 #include <string>
15
16 namespace kademlia {
17
18 class Message {
19 public:
20   unsigned int sender_id_             = 0;       // Id of the guy who sent the task
21   unsigned int destination_id_        = 0;       // Id we are trying to find, if needed.
22   std::unique_ptr<Answer> answer_     = nullptr; // Answer to the request made, if needed.
23   simgrid::s4u::Mailbox* answer_to_   = nullptr; // mailbox to send the answer to (if not an answer).
24   std::string issuer_host_name_;                 // used for logging
25
26   explicit Message(unsigned int sender_id, unsigned int destination_id, std::unique_ptr<Answer> answer,
27                    simgrid::s4u::Mailbox* mailbox, const char* hostname)
28       : sender_id_(sender_id)
29       , destination_id_(destination_id)
30       , answer_(std::move(answer))
31       , answer_to_(mailbox)
32       , issuer_host_name_(hostname)
33   {
34   }
35   explicit Message(unsigned int sender_id, unsigned int destination_id, simgrid::s4u::Mailbox* mailbox,
36                    const char* hostname)
37       : Message(sender_id, destination_id, nullptr, mailbox, hostname)
38   {
39   }
40   Message(const Message&) = delete;
41   Message& operator=(const Message&) = delete;
42 };
43 } // namespace kademlia
44 #endif