X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/18e10c8748bc9c49dadbb9f59d188614f5ac196f..b58b0ba2f6b92efa234677e19dd998346113504d:/examples/c/dht-pastry/dht-pastry.c diff --git a/examples/c/dht-pastry/dht-pastry.c b/examples/c/dht-pastry/dht-pastry.c index 0e9c6dd23e..c50c6a4fbb 100644 --- a/examples/c/dht-pastry/dht-pastry.c +++ b/examples/c/dht-pastry/dht-pastry.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-2023. 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. */ @@ -9,11 +9,11 @@ #include "simgrid/mailbox.h" #include "xbt/dynar.h" +#include "xbt/ex.h" #include "xbt/log.h" #include "xbt/str.h" #include "xbt/sysdep.h" -#include #include XBT_LOG_NEW_DEFAULT_CATEGORY(pastry, "Messages specific for this example"); @@ -83,7 +83,7 @@ unsigned int domain_mask = 0; static int domain(unsigned int a, unsigned int level) { if (domain_mask == 0) - domain_mask = pow(2, DOMAIN_SIZE) - 1; + domain_mask = (1U << DOMAIN_SIZE) - 1; unsigned int shift = (LEVELS_COUNT - level - 1) * DOMAIN_SIZE; return (a >> shift) & domain_mask; } @@ -183,7 +183,7 @@ static state_t node_get_state(const_node_t node) static void print_node_id(const_node_t node) { - XBT_INFO(" Id: %i '%08x' ", node->id, (unsigned)node->id); + XBT_INFO(" Id: %i '%08x'", node->id, (unsigned)node->id); } /* Print the node namespace set */ @@ -236,7 +236,8 @@ static void handle_message(node_t node, pastry_message_t message) err = sg_comm_wait_for(comm, timeout); if (err == SG_ERROR_TIMEOUT) { XBT_DEBUG("Timeout expired when forwarding join to next %d", next); - message_free(message); + xbt_free(request); + break; } type = JOIN_REPLY; } @@ -250,7 +251,7 @@ static void handle_message(node_t node, pastry_message_t message) err = sg_comm_wait_for(comm, timeout); if (err == SG_ERROR_TIMEOUT) { XBT_DEBUG("Timeout expired when sending back the current node state to the joining node to %d", node->id); - message_free(message); + message_free(request); } break; /* Join reply from all the node touched by the join */ @@ -264,7 +265,7 @@ static void handle_message(node_t node, pastry_message_t message) } node->namespace_set[NAMESPACE_SIZE / 2 + j] = message->sender_id; node->ready += message->steps + 1; - /* no break */ + /* fallthrough */ case JOIN_REPLY: XBT_DEBUG("Joining Reply"); @@ -313,6 +314,7 @@ static void handle_message(node_t node, pastry_message_t message) if (err == SG_ERROR_TIMEOUT) { XBT_DEBUG("Timeout expired when sending update to %d", j); message_free(request); + break; } } } @@ -393,6 +395,7 @@ static void handle_message(node_t node, pastry_message_t message) /* Update routing table */ for (i = shl(node->id, message->state->id); i < LEVELS_COUNT; i++) { for (j = 0; j < LEVEL_SIZE; j++) { + // FIXME: this is a no-op! if (node->routing_table[i][j] == -1 && message->state->routing_table[i][j] == -1) node->routing_table[i][j] = message->state->routing_table[i][j]; } @@ -422,6 +425,7 @@ static int join(const_node_t node) if (err == SG_ERROR_TIMEOUT) { XBT_DEBUG("Timeout expired when joining ring with node %d", node->known_id); message_free(request); + return 0; } return 1; @@ -443,7 +447,7 @@ static void node(int argc, char* argv[]) double deadline; xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node"); s_node_t node = {0}; - node.id = xbt_str_parse_int(argv[1], "Invalid ID: %s"); + node.id = (int)xbt_str_parse_int(argv[1], "Invalid ID"); node.known_id = -1; node.ready = -1; node.pending_messages = xbt_dynar_new(sizeof(pastry_message_t), NULL); @@ -465,14 +469,14 @@ static void node(int argc, char* argv[]) if (argc == 3) { // first ring XBT_DEBUG("Hey! Let's create the system."); - deadline = xbt_str_parse_double(argv[2], "Invalid deadline: %s"); + deadline = xbt_str_parse_double(argv[2], "Invalid deadline"); node.ready = 0; XBT_DEBUG("Create a new Pastry ring..."); join_success = 1; } else { - node.known_id = xbt_str_parse_int(argv[2], "Invalid known ID: %s"); - double sleep_time = xbt_str_parse_double(argv[3], "Invalid sleep time: %s"); - deadline = xbt_str_parse_double(argv[4], "Invalid deadline: %s"); + node.known_id = (int)xbt_str_parse_int(argv[2], "Invalid known ID"); + double sleep_time = xbt_str_parse_double(argv[3], "Invalid sleep time"); + deadline = xbt_str_parse_double(argv[4], "Invalid deadline"); // sleep before starting XBT_DEBUG("Let's sleep during %f", sleep_time); @@ -511,23 +515,21 @@ int main(int argc, char* argv[]) simgrid_init(&argc, argv); xbt_assert(argc > 2, "Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n" - "\tExample: %s ../msg_platform.xml pastry10.xml\n", + "\tExample: %s ../platform.xml pastry10.xml\n", argv[0], argv[0]); char** options = &argv[1]; while (!strncmp(options[0], "-", 1)) { - int length = strlen("-nb_bits="); + size_t length = strlen("-nb_bits="); if (!strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) { - nb_bits = xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter: %s"); + nb_bits = (int)xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter"); XBT_DEBUG("Set nb_bits to %d", nb_bits); } else { length = strlen("-timeout="); - if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) { - timeout = xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s"); - XBT_DEBUG("Set timeout to %d", timeout); - } else { - xbt_die("Invalid pastry option '%s'", options[0]); - } + xbt_assert(strncmp(options[0], "-timeout=", length) == 0 && strlen(options[0]) > length, + "Invalid pastry option '%s'", options[0]); + timeout = (int)xbt_str_parse_int(options[0] + length, "Invalid timeout parameter"); + XBT_DEBUG("Set timeout to %d", timeout); } options++; }