1 /* Copyright (c) 2012-2022. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef _KADEMLIA_ROUTING_TABLE_HPP
8 #define _KADEMLIA_ROUTING_TABLE_HPP
9 #include "s4u-dht-kademlia.hpp"
15 /* Routing table bucket */
18 const unsigned int id_; // bucket id
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 // Use rule-of-three, and implicitely disable the move constructor which cannot be 'noexcept' (as required by C++ Core
23 // Guidelines), due to the std::deque member.
24 Bucket(const Bucket&) = default;
28 /* Node routing table */
30 unsigned int id_; // node id of the client's routing table
31 std::vector<Bucket> buckets_; // Node bucket list
33 explicit RoutingTable(unsigned int node_id);
34 RoutingTable(const RoutingTable&) = delete;
35 RoutingTable& operator=(const RoutingTable&) = delete;
37 Bucket* findBucket(unsigned int id);
38 const Bucket& getBucketAt(unsigned int pos) const { return buckets_[pos]; }
39 bool contains(unsigned int node_id);
41 } // namespace kademlia