-/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2012-2018. 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. */
+#include <algorithm>
#include <climits>
#include <xbt/ex.hpp>
#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
}
xbt_assert(deadline > 0, "Wrong deadline supplied");
- stream = simgrid::s4u::this_actor::getHost()->extension<HostBittorrent>()->getStream();
+ stream = simgrid::s4u::this_actor::get_host()->extension<HostBittorrent>()->getStream();
if (args.size() == 4 && args[3] == "1") {
bitfield_ = (1U << FILE_PIECES) - 1U;
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))
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();
}
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)
/* 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) {
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;