Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bbe7128dc233ddad050d2b1de42a3f5765a92319
[simgrid.git] / examples / s4u / dht-kademlia / routing_table.hpp
1 /* Copyright (c) 2012, 2014, 2017-2018. 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
12 namespace kademlia {
13
14 /* Routing table bucket */
15 class Bucket {
16   unsigned int id_; // bucket id
17 public:
18   std::deque<unsigned int> nodes; // Nodes in the bucket.
19   unsigned int getId() { return id_; }
20   explicit Bucket(unsigned int id) : id_(id) {}
21   ~Bucket() = default;
22 };
23
24 /* Node routing table */
25 class RoutingTable {
26   unsigned int id_; // node id of the client's routing table
27 public:
28   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   ~RoutingTable();
33   void print();
34   Bucket* findBucket(unsigned int id);
35   bool contains(unsigned int node_id);
36 };
37 }
38
39 #endif