X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/aa67057cbae409c22a57e9dcf4d82a2859e97f45..61c32216a808376a5dbcf1fe166c14b6f7456af4:/examples/s4u/app-bittorrent/s4u-peer.hpp diff --git a/examples/s4u/app-bittorrent/s4u-peer.hpp b/examples/s4u/app-bittorrent/s4u-peer.hpp index c099e9c2e2..fa0418d799 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.hpp +++ b/examples/s4u/app-bittorrent/s4u-peer.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2018. The SimGrid Team. +/* Copyright (c) 2012-2019. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -13,9 +13,8 @@ class Connection { public: int id; // Peer id - simgrid::s4u::MailboxPtr mailbox_; + simgrid::s4u::Mailbox* mailbox_; unsigned int bitfield = 0U; // Fields - // int messages_count; double peer_speed = 0; double last_unchoke = 0; int current_piece = -1; @@ -25,7 +24,6 @@ public: bool choked_download = true; // Indicates if the peer has choked the current peer explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::by_name(std::to_string(id))){}; - ~Connection() = default; void addSpeedValue(double speed) { peer_speed = peer_speed * 0.6 + speed * 0.4; } bool hasPiece(unsigned int piece) { return bitfield & 1U << piece; } }; @@ -34,13 +32,13 @@ class Peer { int id; double deadline; RngStream stream; - simgrid::s4u::MailboxPtr mailbox_; - std::unordered_map connected_peers; + simgrid::s4u::Mailbox* mailbox_; + std::unordered_map connected_peers; std::set active_peers; // active peers list unsigned int bitfield_ = 0; // list of pieces the peer has. unsigned long long bitfield_blocks = 0; // list of blocks the peer has. - short* pieces_count = nullptr; // number of peers that have each piece. + std::vector pieces_count; // number of peers that have each piece. unsigned int current_pieces = 0; // current pieces the peer is downloading double begin_receive_time = 0; // time when the receiving communication has begun, useful for calculating host speed. int round_ = 0; // current round for the chocking algorithm. @@ -51,7 +49,6 @@ public: explicit Peer(std::vector args); Peer(const Peer&) = delete; Peer& operator=(const Peer&) = delete; - ~Peer(); void operator()(); std::string getStatus(); @@ -77,9 +74,9 @@ public: void requestNewPieceTo(Connection* remote_peer); bool getPeersFromTracker(); - void sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size); - void sendBitfield(simgrid::s4u::MailboxPtr mailbox); - void sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length); + void sendMessage(simgrid::s4u::Mailbox* mailbox, e_message_type type, uint64_t size); + void sendBitfield(simgrid::s4u::Mailbox* mailbox); + void sendPiece(simgrid::s4u::Mailbox* mailbox, unsigned int piece, int block_index, int block_length); void sendHandshakeToAllPeers(); void sendHaveToAllPeers(unsigned int piece); void sendRequestTo(Connection* remote_peer, unsigned int piece);