-/* Copyright (c) 2012-2020. 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
* @param the ID of the person I know in the system (or not)
* @param Time before I leave the system because I'm bored
*/
-static void node(int argc, char* argv[])
+static void node(std::vector<std::string> args)
{
bool join_success = true;
double deadline;
- xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments");
+ xbt_assert(args.size() == 3 || args.size() == 4, "Wrong number of arguments");
/* Node initialization */
- auto node_id = static_cast<unsigned int>(strtoul(argv[1], nullptr, 0));
+ auto node_id = static_cast<unsigned int>(std::stoul(args[1], 0, 0));
kademlia::Node node(node_id);
- if (argc == 4) {
+ if (args.size() == 4) {
XBT_INFO("Hi, I'm going to join the network with id %u", node.getId());
- auto known_id = static_cast<unsigned int>(strtoul(argv[2], nullptr, 0));
+ auto known_id = static_cast<unsigned int>(std::stoul(args[2], 0, 0));
join_success = node.join(known_id);
- deadline = std::stod(argv[3]);
+ deadline = std::stod(args[3]);
} else {
- deadline = std::stod(argv[2]);
+ deadline = std::stod(args[2]);
XBT_INFO("Hi, I'm going to create the network with id %u", node.getId());
node.routingTableUpdate(node.getId());
}
while (simgrid::s4u::Engine::get_clock() < deadline) {
if (node.receive_comm == nullptr)
- node.receive_comm = mailbox->get_async(&node.received_msg);
+ node.receive_comm = mailbox->get_async<kademlia::Message>(&node.received_msg);
if (node.receive_comm->test()) {
// There has been a message, we need to handle it !
- const auto* msg = static_cast<kademlia::Message*>(node.received_msg);
- if (msg) {
- node.handleFindNode(msg);
- delete msg->answer_;
- delete msg;
+ if (node.received_msg) {
+ node.handleFindNode(node.received_msg);
+ delete node.received_msg;
node.receive_comm = nullptr;
} else
simgrid::s4u::this_actor::sleep_for(1);