-/* Copyright (c) 2012-2019. The SimGrid Team.
+/* Copyright (c) 2012-2021. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#define _KADEMLIA_ROUTING_TABLE_HPP
#include "s4u-dht-kademlia.hpp"
#include <deque>
+#include <vector>
namespace kademlia {
class Bucket {
unsigned int id_; // bucket id
public:
- std::deque<unsigned int> nodes; // Nodes in the bucket.
- unsigned int getId() { return id_; }
- explicit Bucket(unsigned int id) : id_(id) {}
- ~Bucket() = default;
+ std::deque<unsigned int> nodes_; // Nodes in the bucket.
+ unsigned int getId() const { return id_; }
+ explicit Bucket(unsigned int id) noexcept : id_(id) {}
};
/* Node routing table */
class RoutingTable {
unsigned int id_; // node id of the client's routing table
+ std::vector<Bucket> buckets_; // Node bucket list
public:
- Bucket** buckets; // Node bucket list - 160 sized.
explicit RoutingTable(unsigned int node_id);
RoutingTable(const RoutingTable&) = delete;
RoutingTable& operator=(const RoutingTable&) = delete;
- ~RoutingTable();
- void print();
+ void print() const;
Bucket* findBucket(unsigned int id);
+ const Bucket& getBucketAt(unsigned int pos) const { return buckets_[pos]; }
bool contains(unsigned int node_id);
};
-}
+} // namespace kademlia
#endif