* @param end upper bound
* @return true if id in in [start, end]
*/
-static bool is_in_interval(int id, int start, int end)
+bool Node::is_in_interval(int id, int start, int end)
{
int i = id % nb_keys;
int s = start % nb_keys;
return i <= e;
}
+void Node::set_parameters(int nb_bits, int nb_keys, int timeout)
+{
+ Node::nb_bits = nb_bits;
+ Node::nb_keys = nb_keys;
+ Node::timeout = timeout;
+}
+
void ChordMessage::destroy(void* message)
{
delete static_cast<ChordMessage*>(message);
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_chord, "Messages specific for this s4u example");
-int nb_bits = 24;
-int nb_keys = 0;
-int timeout = 50;
-
int main(int argc, char* argv[])
{
simgrid::s4u::Engine e(&argc, argv);
argv[0], argv[0]);
std::string platform_file(argv[argc - 2]);
std::string deployment_file(argv[argc - 1]);
+ int nb_bits = 24;
+ int timeout = 50;
for (const auto& option : std::vector<std::string>(argv + 1, argv + argc - 2)) {
if (option.rfind("-nb_bits=", 0) == 0) {
nb_bits = std::stoi(option.substr(option.find('=') + 1));
xbt_die("Invalid chord option '%s'", option.c_str());
}
}
+ int nb_keys = 1U << nb_bits;
+ XBT_DEBUG("Sets nb_keys to %d", nb_keys);
e.load_platform(platform_file);
/* Global initialization of the Chord simulation. */
- nb_keys = 1U << nb_bits;
- XBT_DEBUG("Sets nb_keys to %d", nb_keys);
+ Node::set_parameters(nb_bits, nb_keys, timeout);
e.register_actor<Node>("node");
e.load_deployment(deployment_file);
constexpr double PERIODIC_LOOKUP_DELAY = 10;
constexpr double SLEEP_DELAY = 4.9999;
-extern int nb_bits;
-extern int nb_keys;
-extern int timeout;
-
/* Types of tasks exchanged between nodes. */
enum class MessageType {
FIND_SUCCESSOR,
};
class Node {
+ inline static int nb_bits;
+ inline static int nb_keys;
+ inline static int timeout;
+
int known_id_ = -1;
double start_time_ = -1;
double deadline_ = -1;
std::vector<int> fingers_; // finger table,(fingers[0] is my successor)
int next_finger_to_fix; // index of the next finger to fix in fix_fingers()
+ static bool is_in_interval(int id, int start, int end);
+
public:
+ static void set_parameters(int nb_bits, int nb_keys, int timeout);
+
explicit Node(std::vector<std::string> args);
Node(const Node&) = delete;
Node& operator=(const Node&) = delete;