Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
example s4u-platform-properties: test thehost->get_englobing_zone and diplay its...
[simgrid.git] / examples / s4u / dht-kademlia / answer.hpp
1 /* Copyright (c) 2012-2019. 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 bool sortbydistance(const std::pair<unsigned int, unsigned int>& a, const std::pair<unsigned int, unsigned int>& b);
16
17 /* Node query answer. contains the elements closest to the id given. */
18 class Answer {
19   unsigned int destination_id_;
20   unsigned int size_ = 0;
21
22 public:
23   std::vector<std::pair<unsigned int, unsigned int>> nodes;
24   explicit Answer(unsigned int destination_id) : destination_id_(destination_id) {}
25   virtual ~Answer() = default;
26   unsigned int getDestinationId() { return destination_id_; }
27   unsigned int getSize() { return size_; }
28   void print();
29   unsigned int merge(Answer* a);
30   void trim();
31   bool destinationFound();
32   void addBucket(const kademlia::Bucket* bucket);
33 };
34 }
35
36 #endif