X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c076aa56c88595b4f625df015a02aa870ab3947d..39c935d6d5ee86d153f6f7e6a10d723ae7c57f6f:/examples/s4u/dht-kademlia/node.hpp diff --git a/examples/s4u/dht-kademlia/node.hpp b/examples/s4u/dht-kademlia/node.hpp index 0aa8d80310..44063d2697 100644 --- a/examples/s4u/dht-kademlia/node.hpp +++ b/examples/s4u/dht-kademlia/node.hpp @@ -1,43 +1,46 @@ -/* Copyright (c) 2012-2019. The SimGrid Team. +/* Copyright (c) 2012-2021. The SimGrid Team. * All rights reserved. */ /* 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. */ -#ifndef _KADEMLIA_NODE_HPP -#define _KADEMLIA_NODE_HPP +#ifndef KADEMLIA_NODE_HPP +#define KADEMLIA_NODE_HPP #include "answer.hpp" #include "message.hpp" #include "routing_table.hpp" #include "s4u-dht-kademlia.hpp" +#include + namespace kademlia { class Node { unsigned int id_; // node id - 160 bits RoutingTable table; // node routing table -public: - simgrid::s4u::CommPtr receive_comm; - void* received_msg = nullptr; unsigned int find_node_success = 0; // Number of find_node which have succeeded. unsigned int find_node_failed = 0; // Number of find_node which have failed. - explicit Node(unsigned int node_id) : id_(node_id), table(node_id), receive_comm(nullptr) {} +public: + simgrid::s4u::CommPtr receive_comm = nullptr; + Message* received_msg = nullptr; + explicit Node(unsigned int node_id) : id_(node_id), table(node_id) {} Node(const Node&) = delete; Node& operator=(const Node&) = delete; - unsigned int getId() { return id_; } + unsigned int getId() const { return id_; } bool join(unsigned int known_id); - void sendFindNode(unsigned int id, unsigned int destination); - unsigned int sendFindNodeToBest(Answer* node_list); + void sendFindNode(unsigned int id, unsigned int destination) const; + unsigned int sendFindNodeToBest(const Answer* node_list) const; void routingTableUpdate(unsigned int id); - Answer* findClosest(unsigned int destination_id); + std::unique_ptr findClosest(unsigned int destination_id); bool findNode(unsigned int id_to_find, bool count_in_stats); void randomLookup(); - void handleFindNode(Message* msg); + void handleFindNode(const Message* msg); + void displaySuccessRate() const; }; -} +} // namespace kademlia // identifier functions unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix); unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits); -#endif /* _MSG_EXAMPLES_ROUTING_H */ +#endif /* KADEMLIA_NODE_HPP */