#define FILE_PIECES 10UL
#define PIECES_BLOCKS 5UL
#define BLOCK_SIZE 16384
-static const unsigned long int FILE_SIZE = FILE_PIECES * PIECES_BLOCKS * BLOCK_SIZE;
/** Number of blocks asked by each request */
#define BLOCKS_REQUESTED 2
{
simgrid::s4u::MailboxPtr tracker_mailbox = simgrid::s4u::Mailbox::byName(TRACKER_MAILBOX);
// Build the task to send to the tracker
- TrackerQuery* peer_request = new TrackerQuery(id, mailbox_, 0, 0, FILE_SIZE);
+ TrackerQuery* peer_request = new TrackerQuery(id, mailbox_);
try {
XBT_DEBUG("Sending a peer request to the tracker.");
tracker_mailbox->put(peer_request, TRACKER_COMM_SIZE, GET_PEERS_TIMEOUT);
round_ = (round_ + 1) % 3;
Connection* chosen_peer = nullptr;
// select first active peer and remove it from the set
- Connection* choked_peer = *(active_peers.begin());
- active_peers.erase(choked_peer);
+ Connection* choked_peer;
+ if (active_peers.empty()) {
+ choked_peer = nullptr;
+ } else {
+ choked_peer = *active_peers.begin();
+ active_peers.erase(choked_peer);
+ }
/**If we are currently seeding, we unchoke the peer which has been unchoked the last time.*/
if (hasFinished()) {
int Peer::getFirstMissingBlockFrom(int piece)
{
for (unsigned int i = 0; i < PIECES_BLOCKS; i++)
- if (!(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
+ if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
return i;
return -1;
}