Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
72283129aec11c9788f256989f75ecab22e6e193
[simgrid.git] / examples / cpp / dht-kademlia / answer.hpp
1 /* Copyright (c) 2012-2021. 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_ANSWER_HPP_
8 #define _KADEMLIA_ANSWER_HPP_
9
10 #include "node.hpp"
11 #include "routing_table.hpp"
12 #include <set>
13
14 namespace kademlia {
15 /* Node query answer. contains the elements closest to the id given. */
16 class Answer {
17   unsigned int destination_id_;
18   std::vector<std::pair<unsigned int, unsigned int>> nodes_;
19
20 public:
21   explicit Answer(unsigned int destination_id) : destination_id_(destination_id) {}
22   unsigned int getDestinationId() const { return destination_id_; }
23   size_t getSize() const { return nodes_.size(); }
24   const std::vector<std::pair<unsigned int, unsigned int>>& getNodes() const { return nodes_; }
25   void print() const;
26   unsigned int merge(const Answer* a);
27   void trim();
28   bool destinationFound() const;
29   void addBucket(const kademlia::Bucket* bucket);
30 };
31 } // namespace kademlia
32
33 #endif