Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c77b216d75249adad8a565f15d545f182d55ba8f
[simgrid.git] / examples / s4u / dht-kademlia / routing_table.hpp
1 /* Copyright (c) 2012-2020. 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_ROUTING_TABLE_HPP
8 #define _KADEMLIA_ROUTING_TABLE_HPP
9 #include "s4u-dht-kademlia.hpp"
10 #include <deque>
11 #include <vector>
12
13 namespace kademlia {
14
15 /* Routing table bucket */
16 class Bucket {
17   unsigned int id_; // bucket id
18 public:
19   std::deque<unsigned int> nodes; // Nodes in the bucket.
20   unsigned int getId() const { return id_; }
21   explicit Bucket(unsigned int id) : id_(id) {}
22 };
23
24 /* Node routing table */
25 class RoutingTable {
26   unsigned int id_; // node id of the client's routing table
27 public:
28   std::vector<Bucket> buckets; // Node bucket list - 160 sized.
29   explicit RoutingTable(unsigned int node_id);
30   RoutingTable(const RoutingTable&) = delete;
31   RoutingTable& operator=(const RoutingTable&) = delete;
32   void print() const;
33   Bucket* findBucket(unsigned int id);
34   bool contains(unsigned int node_id);
35 };
36 }
37
38 #endif