File: routing_table.hpp

package info (click to toggle)
simgrid 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 38,980 kB
  • sloc: cpp: 123,583; ansic: 66,779; python: 8,358; java: 6,406; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,337; perl: 1,436; makefile: 105; lisp: 49; javascript: 7; sed: 6
file content (42 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Copyright (c) 2012-2025. The SimGrid Team. All rights reserved.          */

/* This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package. */

#ifndef _KADEMLIA_ROUTING_TABLE_HPP
#define _KADEMLIA_ROUTING_TABLE_HPP
#include "s4u-dht-kademlia.hpp"
#include <deque>
#include <vector>

namespace kademlia {

/* Routing table bucket */
class Bucket {
public:
  const unsigned int id_;          // bucket id
  std::deque<unsigned int> nodes_; // Nodes in the bucket.
  unsigned int getId() const { return id_; }
  explicit Bucket(unsigned int id) : id_(id) {}
  // Use rule-of-three, and implicitely disable the move constructor which cannot be 'noexcept' (as required by C++ Core
  // Guidelines), due to the std::deque member.
  Bucket(const Bucket&) = default;
  ~Bucket()             = default;
};

/* Node routing table */
class RoutingTable {
  unsigned int id_; // node id of the client's routing table
  std::vector<Bucket> buckets_; // Node bucket list
public:
  explicit RoutingTable(unsigned int node_id);
  RoutingTable(const RoutingTable&) = delete;
  RoutingTable& operator=(const RoutingTable&) = delete;
  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