X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b02538071ffda15d09efbe85f1459e2c4688f68d..9caf173e476622d309cc5653a83d224d05787cc7:/examples/s4u/app-bittorrent/s4u-peer.cpp diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index 8f57ee9942..d91a7450b5 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -3,6 +3,7 @@ /* 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. */ +#include #include #include @@ -20,7 +21,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_bt_peer, "Messages specific for the peers"); #define BLOCK_SIZE 16384 /** Number of blocks asked by each request */ -#define BLOCKS_REQUESTED 2 +#define BLOCKS_REQUESTED 2UL #define ENABLE_END_GAME_MODE 1 #define SLEEP_DURATION 1 @@ -128,13 +129,13 @@ void Peer::sendHandshakeToAllPeers() void Peer::sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size) { const char* type_names[6] = {"HANDSHAKE", "CHOKE", "UNCHOKE", "INTERESTED", "NOTINTERESTED", "CANCEL"}; - XBT_DEBUG("Sending %s to %s", type_names[type], mailbox->getName()); + XBT_DEBUG("Sending %s to %s", type_names[type], mailbox->get_cname()); mailbox->put_init(new Message(type, id, bitfield_, mailbox_), size)->detach(); } void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox) { - XBT_DEBUG("Sending a BITFIELD to %s", mailbox->getName()); + XBT_DEBUG("Sending a BITFIELD to %s", mailbox->get_cname()); mailbox ->put_init(new Message(MESSAGE_BITFIELD, id, bitfield_, mailbox_), MESSAGE_BITFIELD_SIZE + BITS_TO_BYTES(FILE_PIECES)) @@ -144,7 +145,7 @@ void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox) void Peer::sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length) { xbt_assert(not hasNotPiece(piece), "Tried to send a unavailable piece."); - XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->getName()); + XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->get_cname()); mailbox->put_init(new Message(MESSAGE_PIECE, id, mailbox_, piece, block_index, block_length), BLOCK_SIZE)->detach(); } @@ -163,8 +164,8 @@ void Peer::sendRequestTo(Connection* remote_peer, unsigned int piece) xbt_assert(remote_peer->hasPiece(piece)); int block_index = getFirstMissingBlockFrom(piece); if (block_index != -1) { - int block_length = MIN(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index); - XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->getName(), piece, block_index, + int block_length = std::min(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index); + XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->get_cname(), piece, block_index, block_length); remote_peer->mailbox_ ->put_init(new Message(MESSAGE_REQUEST, id, mailbox_, piece, block_index, block_length), MESSAGE_REQUEST_SIZE) @@ -233,7 +234,7 @@ void Peer::leech() /* Send a "handshake" message to all the peers it got (since it couldn't have gotten more than 50 peers) */ sendHandshakeToAllPeers(); - XBT_DEBUG("Starting main leech loop listening on mailbox: %s", mailbox_->getName()); + XBT_DEBUG("Starting main leech loop listening on mailbox: %s", mailbox_->get_cname()); void* data = nullptr; while (simgrid::s4u::Engine::getClock() < deadline && countPieces(bitfield_) < FILE_PIECES) { @@ -299,7 +300,7 @@ void Peer::handleMessage() const char* type_names[10] = {"HANDSHAKE", "CHOKE", "UNCHOKE", "INTERESTED", "NOTINTERESTED", "HAVE", "BITFIELD", "REQUEST", "PIECE", "CANCEL"}; - XBT_DEBUG("Received a %s message from %s", type_names[message->type], message->return_mailbox->getName()); + XBT_DEBUG("Received a %s message from %s", type_names[message->type], message->return_mailbox->get_cname()); auto known_peer = connected_peers.find(message->peer_id); Connection* remote_peer = (known_peer == connected_peers.end()) ? nullptr : known_peer->second;